Changeset View
Changeset View
Standalone View
Standalone View
kioslave/desktop/kio_desktop.cpp
Show All 13 Lines | 1 | /* This file is part of the KDE project | |||
---|---|---|---|---|---|
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301, USA. | 17 | Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "kio_desktop.h" | 20 | #include "kio_desktop.h" | ||
21 | 21 | | |||
22 | #include <KApplication> | | |||
23 | #include <KCmdLineArgs> | | |||
24 | #include <KConfigGroup> | 22 | #include <KConfigGroup> | ||
25 | #include <KDesktopFile> | 23 | #include <KDesktopFile> | ||
26 | #include <KDirNotify> | 24 | #include <KDirNotify> | ||
27 | #include <KGlobalSettings> | | |||
28 | #include <KStandardDirs> | | |||
29 | #include <KGlobal> | | |||
30 | #include <KUrl> | | |||
31 | #include <kdeversion.h> | | |||
32 | 25 | | |||
33 | #include <kio/udsentry.h> | 26 | #include <kio/udsentry.h> | ||
34 | #include <kio_version.h> | 27 | #include <kio_version.h> | ||
35 | 28 | | |||
29 | #include <QCoreApplication> | ||||
36 | #include <QFile> | 30 | #include <QFile> | ||
37 | #include <QDBusInterface> | 31 | #include <QDBusInterface> | ||
38 | #include <QDesktopServices> | 32 | #include <QDesktopServices> | ||
39 | #include <QDir> | 33 | #include <QDir> | ||
40 | #include <QStandardPaths> | 34 | #include <QStandardPaths> | ||
41 | 35 | | |||
42 | extern "C" | 36 | extern "C" | ||
43 | { | 37 | { | ||
44 | int Q_DECL_EXPORT kdemain(int argc, char **argv) | 38 | int Q_DECL_EXPORT kdemain(int argc, char **argv) | ||
45 | { | 39 | { | ||
46 | // necessary to use other kio slaves | 40 | // necessary to use other kio slaves | ||
47 | QCoreApplication app(argc, argv); | 41 | QCoreApplication app(argc, argv); | ||
48 | KComponentData("kio_desktop", "kdelibs4"); | 42 | app.setApplicationName("kio_desktop"); | ||
49 | KLocale::global(); | | |||
50 | 43 | | |||
51 | // start the slave | 44 | // start the slave | ||
52 | DesktopProtocol slave(argv[1], argv[2], argv[3]); | 45 | DesktopProtocol slave(argv[1], argv[2], argv[3]); | ||
53 | slave.dispatchLoop(); | 46 | slave.dispatchLoop(); | ||
54 | return 0; | 47 | return 0; | ||
55 | } | 48 | } | ||
56 | } | 49 | } | ||
57 | 50 | | |||
Show All 34 Lines | 83 | if (desktopIsEmpty) { | |||
92 | QFile::copy(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kio_desktop/directory.desktop")), | 85 | QFile::copy(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kio_desktop/directory.desktop")), | ||
93 | desktopPath + "/.directory"); | 86 | desktopPath + "/.directory"); | ||
94 | 87 | | |||
95 | // Copy the trash link | 88 | // Copy the trash link | ||
96 | QFile::copy(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kio_desktop/directory.trash")), | 89 | QFile::copy(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kio_desktop/directory.trash")), | ||
97 | desktopPath + "/trash.desktop"); | 90 | desktopPath + "/trash.desktop"); | ||
98 | 91 | | |||
99 | // Copy the desktop links | 92 | // Copy the desktop links | ||
100 | const QStringList links = KGlobal::dirs()->findAllResources("data", QStringLiteral("kio_desktop/DesktopLinks/*"), | 93 | QSet<QString> links; | ||
101 | KStandardDirs::NoDuplicates); | 94 | const auto dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kio_desktop/DesktopLinks"), QStandardPaths::LocateDirectory); | ||
95 | for (const auto &dir : dirs) { | ||||
96 | const auto fileNames = QDir(dir).entryList({QStringLiteral("*.desktop")}); | ||||
97 | for (const auto &file : fileNames) { | ||||
98 | links += file; | ||||
99 | } | ||||
100 | } | ||||
101 | | ||||
102 | foreach (const QString &link, links) { | 102 | foreach (const QString &link, links) { | ||
103 | KDesktopFile file(link); | 103 | const auto fullPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kio_desktop/DesktopLinks/%1").arg(link)); | ||
104 | KDesktopFile file(fullPath); | ||||
104 | if (!file.desktopGroup().readEntry("Hidden", false)) | 105 | if (!file.desktopGroup().readEntry("Hidden", false)) | ||
105 | QFile::copy(link, desktopPath + link.mid(link.lastIndexOf('/'))); | 106 | QFile::copy(fullPath, QStringLiteral("%1/%2").arg(desktopPath, link)); | ||
106 | } | 107 | } | ||
107 | } | 108 | } | ||
108 | #endif | 109 | #endif | ||
109 | } | 110 | } | ||
110 | 111 | | |||
111 | bool DesktopProtocol::rewriteUrl(const QUrl &url, QUrl &newUrl) | 112 | bool DesktopProtocol::rewriteUrl(const QUrl &url, QUrl &newUrl) | ||
112 | { | 113 | { | ||
113 | newUrl.setScheme(QStringLiteral("file")); | 114 | newUrl.setScheme(QStringLiteral("file")); | ||
114 | newUrl.setPath(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + url.path()); | 115 | newUrl.setPath(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + url.path()); | ||
115 | return true; | 116 | return true; | ||
116 | } | 117 | } | ||
117 | 118 | | |||
118 | void DesktopProtocol::listDir(const QUrl &url) | 119 | void DesktopProtocol::listDir(const QUrl &url) | ||
119 | { | 120 | { | ||
120 | KIO::ForwardingSlaveBase::listDir(url); | 121 | KIO::ForwardingSlaveBase::listDir(url); | ||
121 | 122 | | |||
122 | KUrl actual; | 123 | QUrl actual; | ||
123 | rewriteUrl(url, actual); | 124 | rewriteUrl(url, actual); | ||
124 | 125 | | |||
125 | QDBusInterface kded(QStringLiteral("org.kde.kded5"), QStringLiteral("/modules/desktopnotifier"), QStringLiteral("org.kde.DesktopNotifier")); | 126 | QDBusInterface kded(QStringLiteral("org.kde.kded5"), QStringLiteral("/modules/desktopnotifier"), QStringLiteral("org.kde.DesktopNotifier")); | ||
126 | kded.call(QStringLiteral("watchDir"), actual.path()); | 127 | kded.call(QStringLiteral("watchDir"), actual.path()); | ||
127 | } | 128 | } | ||
128 | 129 | | |||
129 | QString DesktopProtocol::desktopFile(KIO::UDSEntry &entry) const | 130 | QString DesktopProtocol::desktopFile(KIO::UDSEntry &entry) const | ||
130 | { | 131 | { | ||
131 | const QString name = entry.stringValue(KIO::UDSEntry::UDS_NAME); | 132 | const QString name = entry.stringValue(KIO::UDSEntry::UDS_NAME); | ||
132 | if (name == QLatin1String(".") || name == QLatin1String("..")) | 133 | if (name == QLatin1String(".") || name == QLatin1String("..")) | ||
133 | return QString(); | 134 | return QString(); | ||
134 | 135 | | |||
135 | KUrl url = processedUrl(); | 136 | QUrl url = processedUrl(); | ||
136 | url.addPath(name); | 137 | url.setPath(QStringLiteral("%1/%2").arg(url.path(), name)); | ||
137 | 138 | | |||
138 | if (entry.isDir()) { | 139 | if (entry.isDir()) { | ||
139 | url.addPath(QStringLiteral(".directory")); | 140 | url.setPath(QStringLiteral("%1/.directory").arg(url.path())); | ||
140 | if (!KStandardDirs::exists(url.path())) | 141 | if (!QFileInfo::exists(url.path())) | ||
141 | return QString(); | 142 | return QString(); | ||
142 | 143 | | |||
143 | return url.path(); | 144 | return url.path(); | ||
144 | } | 145 | } | ||
145 | 146 | | |||
146 | if (KDesktopFile::isDesktopFile(url.path())) | 147 | if (KDesktopFile::isDesktopFile(url.path())) | ||
147 | return url.path(); | 148 | return url.path(); | ||
148 | 149 | | |||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |