From 5b748d35e7208fb6335d821c25202533dc9a783a Mon Sep 17 00:00:00 2001 From: reionwong Date: Sun, 26 Sep 2021 21:42:22 +0800 Subject: [PATCH] Add freedesktop interface https://github.com/cutefishos/filemanager/issues/16 --- CMakeLists.txt | 2 ++ application.cpp | 2 ++ dbusinterface.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ dbusinterface.h | 19 +++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 dbusinterface.cpp create mode 100644 dbusinterface.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a28e9a..539f457 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,8 @@ add_executable(cutefish-filemanager main.cpp application.cpp window.cpp + dbusinterface.cpp + model/foldermodel.cpp model/placesmodel.cpp model/placesitem.cpp diff --git a/application.cpp b/application.cpp index c9936e6..4eb94c2 100644 --- a/application.cpp +++ b/application.cpp @@ -18,6 +18,7 @@ */ #include "application.h" +#include "dbusinterface.h" #include "window.h" #include "desktop/desktop.h" #include "thumbnailer/thumbnailprovider.h" @@ -42,6 +43,7 @@ Application::Application(int& argc, char** argv) setWindowIcon(QIcon::fromTheme("file-manager")); new FileManagerAdaptor(this); + new DBusInterface; QDBusConnection::sessionBus().registerObject("/FileManager", this); // Translations diff --git a/dbusinterface.cpp b/dbusinterface.cpp new file mode 100644 index 0000000..5a83984 --- /dev/null +++ b/dbusinterface.cpp @@ -0,0 +1,41 @@ +#include "dbusinterface.h" + +#include +#include +#include +#include + +DBusInterface::DBusInterface() +{ + QDBusConnection::sessionBus().registerObject("/org/freedesktop/FileManager1", this, + QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors); + QDBusConnectionInterface *sessionInterface = QDBusConnection::sessionBus().interface(); + + if (sessionInterface) { + sessionInterface->registerService(QStringLiteral("org.freedesktop.FileManager1"), QDBusConnectionInterface::QueueService); + } +} + +void DBusInterface::ShowFolders(const QStringList &uriList, const QString &startUpId) +{ + Q_UNUSED(startUpId); + + qDebug() << uriList; + + QProcess::startDetached("cutefish-filemanager", uriList); +} + +void DBusInterface::ShowItems(const QStringList &uriList, const QString &startUpId) +{ + Q_UNUSED(startUpId); + + QProcess::startDetached("cutefish-filemanager", uriList); +} + +void DBusInterface::ShowItemProperties(const QStringList &uriList, const QString &startUpId) +{ + Q_UNUSED(uriList); + Q_UNUSED(startUpId); + + // TODO +} diff --git a/dbusinterface.h b/dbusinterface.h new file mode 100644 index 0000000..d9951ad --- /dev/null +++ b/dbusinterface.h @@ -0,0 +1,19 @@ +#ifndef DBUSINTERFACE_H +#define DBUSINTERFACE_H + +#include + +class DBusInterface : QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.freedesktop.FileManager1") + +public: + explicit DBusInterface(); + + Q_SCRIPTABLE void ShowFolders(const QStringList& uriList, const QString& startUpId); + Q_SCRIPTABLE void ShowItems(const QStringList& uriList, const QString& startUpId); + Q_SCRIPTABLE void ShowItemProperties(const QStringList& uriList, const QString& startUpId); +}; + +#endif // DBUSINTERFACE_H