Changeset View
Changeset View
Standalone View
Standalone View
kioslave/desktop/kio_desktop.cpp
Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Line(s) | 73 | #ifndef Q_WS_WIN | |||
---|---|---|---|---|---|
74 | // We can't use QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) here, since it returns the home dir | 74 | // We can't use QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) here, since it returns the home dir | ||
75 | // if the desktop folder doesn't exist. | 75 | // if the desktop folder doesn't exist. | ||
76 | QString desktopPath = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation); | 76 | QString desktopPath = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation); | ||
77 | if (desktopPath.isEmpty()) | 77 | if (desktopPath.isEmpty()) | ||
78 | desktopPath = QDir::homePath() + "/Desktop"; | 78 | desktopPath = QDir::homePath() + "/Desktop"; | ||
79 | 79 | | |||
80 | const QDir desktopDir(desktopPath); | 80 | const QDir desktopDir(desktopPath); | ||
81 | bool desktopIsEmpty; | 81 | bool desktopIsEmpty; | ||
82 | bool newRelease; | | |||
83 | | ||||
84 | // Check if we have a new KDE release | | |||
85 | KConfig config(QStringLiteral("kio_desktoprc")); | | |||
86 | KConfigGroup cg(&config, "General"); | | |||
87 | QString version = cg.readEntry("Version", "0.0.0"); | | |||
88 | int major = version.section('.', 0, 0).toInt(); | | |||
89 | int minor = version.section('.', 1, 1).toInt(); | | |||
90 | int release = version.section('.', 2, 2).toInt(); | | |||
91 | | ||||
92 | if (KDE_MAKE_VERSION(major, minor, release) < KDE::version()) { | | |||
93 | const QString version = QString::number(KDE::versionMajor()) + '.' + | | |||
94 | QString::number(KDE::versionMinor()) + '.' + | | |||
95 | QString::number(KDE::versionRelease()); | | |||
96 | cg.writeEntry("Version", version); | | |||
97 | newRelease = true; | | |||
98 | } else | | |||
99 | newRelease = false; | | |||
100 | 82 | | |||
101 | // Create the desktop folder if it doesn't exist | 83 | // Create the desktop folder if it doesn't exist | ||
102 | if (!desktopDir.exists()) { | 84 | if (!desktopDir.exists()) { | ||
103 | ::mkdir(QFile::encodeName(desktopPath), S_IRWXU); | 85 | ::mkdir(QFile::encodeName(desktopPath), S_IRWXU); | ||
104 | desktopIsEmpty = true; | 86 | desktopIsEmpty = true; | ||
105 | } else | 87 | } else | ||
106 | desktopIsEmpty = desktopDir.entryList(QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot).isEmpty(); | 88 | desktopIsEmpty = desktopDir.entryList(QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot).isEmpty(); | ||
107 | 89 | | |||
Show All 9 Lines | 90 | if (desktopIsEmpty) { | |||
117 | // Copy the desktop links | 99 | // Copy the desktop links | ||
118 | const QStringList links = KGlobal::dirs()->findAllResources("data", QStringLiteral("kio_desktop/DesktopLinks/*"), | 100 | const QStringList links = KGlobal::dirs()->findAllResources("data", QStringLiteral("kio_desktop/DesktopLinks/*"), | ||
119 | KStandardDirs::NoDuplicates); | 101 | KStandardDirs::NoDuplicates); | ||
120 | foreach (const QString &link, links) { | 102 | foreach (const QString &link, links) { | ||
121 | KDesktopFile file(link); | 103 | KDesktopFile file(link); | ||
122 | if (!file.desktopGroup().readEntry("Hidden", false)) | 104 | if (!file.desktopGroup().readEntry("Hidden", false)) | ||
123 | QFile::copy(link, desktopPath + link.mid(link.lastIndexOf('/'))); | 105 | QFile::copy(link, desktopPath + link.mid(link.lastIndexOf('/'))); | ||
124 | } | 106 | } | ||
125 | } else if (newRelease) { | | |||
126 | // Update the icon name in the .directory file to the FDO naming spec | | |||
127 | const QString directoryFile = desktopPath + "/.directory"; | | |||
128 | if (QFile::exists(directoryFile)) { | | |||
129 | KDesktopFile file(directoryFile); | | |||
130 | if (file.readIcon() == QLatin1String("desktop")) | | |||
131 | file.desktopGroup().writeEntry("Icon", "user-desktop"); | | |||
132 | } else | | |||
133 | QFile::copy(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kio_desktop/directory.desktop")), directoryFile); | | |||
134 | | ||||
135 | // Update the home icon to the FDO naming spec | | |||
136 | const QString homeLink = desktopPath + "/Home.desktop"; | | |||
137 | if (QFile::exists(homeLink)) { | | |||
138 | KDesktopFile home(homeLink); | | |||
139 | const QString icon = home.readIcon(); | | |||
140 | if (icon == QLatin1String("kfm_home") || icon == QLatin1String("folder_home")) | | |||
141 | home.desktopGroup().writeEntry("Icon", "user-home"); | | |||
142 | } | | |||
143 | | ||||
144 | // Update the trash icon to the FDO naming spec | | |||
145 | const QString trashLink = desktopPath + "/trash.desktop"; | | |||
146 | if (QFile::exists(trashLink)) { | | |||
147 | KDesktopFile trash(trashLink); | | |||
148 | if (trash.readIcon() == QLatin1String("trashcan_full")) | | |||
149 | trash.desktopGroup().writeEntry("Icon", "user-trash-full"); | | |||
150 | if (trash.desktopGroup().readEntry("EmptyIcon") == QLatin1String("trashcan_empty")) | | |||
151 | trash.desktopGroup().writeEntry("EmptyIcon", "user-trash"); | | |||
152 | } | | |||
153 | } | 107 | } | ||
154 | #endif | 108 | #endif | ||
155 | } | 109 | } | ||
156 | 110 | | |||
157 | bool DesktopProtocol::rewriteUrl(const QUrl &url, QUrl &newUrl) | 111 | bool DesktopProtocol::rewriteUrl(const QUrl &url, QUrl &newUrl) | ||
158 | { | 112 | { | ||
159 | newUrl.setScheme(QStringLiteral("file")); | 113 | newUrl.setScheme(QStringLiteral("file")); | ||
160 | newUrl.setPath(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + url.path()); | 114 | newUrl.setPath(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + url.path()); | ||
▲ Show 20 Lines • Show All 105 Lines • Show Last 20 Lines |