[kioslave/desktop] Port away from kdelibs4support

Differential Revision: https://phabricator.kde.org/D3294
wilder-5.14
Elvis Angelaccio 9 years ago
parent 9e0839aebf
commit f81c843dcf
  1. 4
      kioslave/desktop/CMakeLists.txt
  2. 15
      kioslave/desktop/desktopnotifier.cpp
  3. 37
      kioslave/desktop/kio_desktop.cpp
  4. 2
      kioslave/desktop/tests/CMakeLists.txt
  5. 10
      kioslave/desktop/tests/kio_desktop_test.cpp

@ -2,7 +2,7 @@ add_subdirectory(tests)
add_library(kio_desktop MODULE kio_desktop.cpp)
target_link_libraries(kio_desktop KF5::KIOCore KF5::KDELibs4Support)
target_link_libraries(kio_desktop Qt5::DBus Qt5::Gui KF5::KIOCore)
set_target_properties(kio_desktop PROPERTIES OUTPUT_NAME "desktop")
@ -12,7 +12,7 @@ install(TARGETS kio_desktop DESTINATION ${PLUGIN_INSTALL_DIR}/kf5/kio)
add_library(desktopnotifier MODULE desktopnotifier.cpp)
kcoreaddons_desktop_to_json(desktopnotifier desktopnotifier.desktop)
target_link_libraries(desktopnotifier KF5::KIOCore KF5::DBusAddons KF5::KDELibs4Support)
target_link_libraries(desktopnotifier KF5::KIOCore KF5::DBusAddons)
install(TARGETS desktopnotifier DESTINATION ${PLUGIN_INSTALL_DIR}/kf5/kded)

@ -19,16 +19,13 @@
#include "desktopnotifier.h"
#include <KDirWatch>
#include <KGlobal>
#include <KGlobalSettings>
#include <KPluginFactory>
#include <KPluginLoader>
#include <KUrl>
#include <kdirnotify.h>
#include <QStandardPaths>
#include <QStandardPaths>
#include <QUrl>
K_PLUGIN_FACTORY_WITH_JSON(DesktopNotifierFactory,
"desktopnotifier.json",
@ -72,9 +69,11 @@ void DesktopNotifier::dirty(const QString &path)
checkDesktopLocation();
} else {
// Emitting FilesAdded forces a re-read of the dir
KUrl url("desktop:/");
url.addPath(KUrl::relativePath(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), path));
url.cleanPath();
QUrl url;
url.setScheme(QStringLiteral("desktop"));
const auto relativePath = QDir(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)).relativeFilePath(path);
url.setPath(QStringLiteral("%1/%2").arg(url.path(), relativePath));
url.setPath(QDir::cleanPath(url.path()));
org::kde::KDirNotify::emitFilesAdded(url);
}
}

@ -19,20 +19,14 @@
#include "kio_desktop.h"
#include <KApplication>
#include <KCmdLineArgs>
#include <KConfigGroup>
#include <KDesktopFile>
#include <KDirNotify>
#include <KGlobalSettings>
#include <KStandardDirs>
#include <KGlobal>
#include <KUrl>
#include <kdeversion.h>
#include <kio/udsentry.h>
#include <kio_version.h>
#include <QCoreApplication>
#include <QFile>
#include <QDBusInterface>
#include <QDesktopServices>
@ -45,8 +39,7 @@ extern "C"
{
// necessary to use other kio slaves
QCoreApplication app(argc, argv);
KComponentData("kio_desktop", "kdelibs4");
KLocale::global();
app.setApplicationName("kio_desktop");
// start the slave
DesktopProtocol slave(argv[1], argv[2], argv[3]);
@ -97,12 +90,20 @@ void DesktopProtocol::checkLocalInstall()
desktopPath + "/trash.desktop");
// Copy the desktop links
const QStringList links = KGlobal::dirs()->findAllResources("data", QStringLiteral("kio_desktop/DesktopLinks/*"),
KStandardDirs::NoDuplicates);
QSet<QString> links;
const auto dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kio_desktop/DesktopLinks"), QStandardPaths::LocateDirectory);
for (const auto &dir : dirs) {
const auto fileNames = QDir(dir).entryList({QStringLiteral("*.desktop")});
for (const auto &file : fileNames) {
links += file;
}
}
foreach (const QString &link, links) {
KDesktopFile file(link);
const auto fullPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kio_desktop/DesktopLinks/%1").arg(link));
KDesktopFile file(fullPath);
if (!file.desktopGroup().readEntry("Hidden", false))
QFile::copy(link, desktopPath + link.mid(link.lastIndexOf('/')));
QFile::copy(fullPath, QStringLiteral("%1/%2").arg(desktopPath, link));
}
}
#endif
@ -119,7 +120,7 @@ void DesktopProtocol::listDir(const QUrl &url)
{
KIO::ForwardingSlaveBase::listDir(url);
KUrl actual;
QUrl actual;
rewriteUrl(url, actual);
QDBusInterface kded(QStringLiteral("org.kde.kded5"), QStringLiteral("/modules/desktopnotifier"), QStringLiteral("org.kde.DesktopNotifier"));
@ -132,12 +133,12 @@ QString DesktopProtocol::desktopFile(KIO::UDSEntry &entry) const
if (name == QLatin1String(".") || name == QLatin1String(".."))
return QString();
KUrl url = processedUrl();
url.addPath(name);
QUrl url = processedUrl();
url.setPath(QStringLiteral("%1/%2").arg(url.path(), name));
if (entry.isDir()) {
url.addPath(QStringLiteral(".directory"));
if (!KStandardDirs::exists(url.path()))
url.setPath(QStringLiteral("%1/.directory").arg(url.path()));
if (!QFileInfo::exists(url.path()))
return QString();
return url.path();

@ -1,5 +1,5 @@
add_executable(testdesktop kio_desktop_test.cpp)
target_link_libraries(testdesktop KF5::KIOWidgets KF5::Solid Qt5::Test KF5::KDELibs4Support)
target_link_libraries(testdesktop KF5::KIOWidgets KF5::Solid Qt5::Test)
ecm_mark_as_test(testdesktop)
add_test(testdesktop testdesktop)

@ -18,12 +18,10 @@
*/
#include <kdirlister.h>
#include <ktemporaryfile.h>
#include <kdebug.h>
#include <QDesktopServices>
#include <QStandardPaths>
#include <QObject>
#include <qtest_kde.h>
#include <QTemporaryFile>
#include <QTest>
#include <kio/job.h>
#include <kio/copyjob.h>
@ -54,7 +52,7 @@ private Q_SLOTS:
void testCopyToDesktop()
{
KTemporaryFile tempFile;
QTemporaryFile tempFile;
QVERIFY(tempFile.open());
tempFile.write( "Hello world\n", 12 );
QString fileName = tempFile.fileName();
@ -128,6 +126,6 @@ private:
QString m_testFileName;
};
QTEST_KDEMAIN(TestDesktop, NoGUI)
QTEST_GUILESS_MAIN(TestDesktop)
#include "kio_desktop_test.moc"

Loading…
Cancel
Save