]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Add dbus interface to dolphin
authorAshish Bansal <bansal.ashish096@gmail.com>
Wed, 22 Apr 2015 13:29:39 +0000 (18:59 +0530)
committerAshish Bansal <bansal.ashish096@gmail.com>
Wed, 22 Apr 2015 13:29:39 +0000 (18:59 +0530)
Implemented org.freedesktop.FileManager1 dbus interface in dolphin
http://www.freedesktop.org/wiki/Specifications/file-manager-interface/

REVIEW: 123313
BUG: 343016

CMakeLists.txt
cmake/DbusInterfaceMacros.cmake [new file with mode: 0644]
org.kde.dolphin.FileManager1.service.in [new file with mode: 0644]
src/CMakeLists.txt
src/dbusinterface.cpp [new file with mode: 0644]
src/dbusinterface.h [new file with mode: 0644]
src/global.cpp [new file with mode: 0644]
src/global.h [new file with mode: 0644]
src/main.cpp

index daf927197072cd297183c539d4788076af82aa8e..3575db5da2499ce734d4a8c63b9787f63de71681 100644 (file)
@@ -10,7 +10,7 @@ set(ECM_MIN_VERSION "1.6.0")
 
 # ECM setup
 find_package(ECM ${ECM_MIN_VERSION} CONFIG REQUIRED)
-set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
+set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
 
 include(ECMSetupVersion)
 include(ECMGenerateHeaders)
@@ -123,5 +123,10 @@ install(FILES
     COMPONENT Devel
 )
 
+configure_file(org.kde.dolphin.FileManager1.service.in
+               ${CMAKE_CURRENT_BINARY_DIR}/org.kde.dolphin.FileManager1.service)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.dolphin.FileManager1.service
+        DESTINATION ${DBUS_SERVICES_INSTALL_DIR})
+
 feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
 
diff --git a/cmake/DbusInterfaceMacros.cmake b/cmake/DbusInterfaceMacros.cmake
new file mode 100644 (file)
index 0000000..0fd2f4c
--- /dev/null
@@ -0,0 +1,18 @@
+macro (generate_and_install_dbus_interface main_project_target header_file output_xml_file)
+    qt5_generate_dbus_interface(
+        ${header_file}
+        ${output_xml_file}
+    )
+    add_custom_target(
+        ${output_xml_file}
+        SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${output_xml_file}
+       )
+    install(
+        FILES ${CMAKE_CURRENT_BINARY_DIR}/${output_xml_file}
+        DESTINATION ${DBUS_INTERFACES_INSTALL_DIR}
+    )
+    add_dependencies(
+        ${main_project_target}
+        ${output_xml_file}
+    )
+endmacro ()
diff --git a/org.kde.dolphin.FileManager1.service.in b/org.kde.dolphin.FileManager1.service.in
new file mode 100644 (file)
index 0000000..c1258bb
--- /dev/null
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.freedesktop.FileManager1
+Exec=@CMAKE_INSTALL_PREFIX@/bin/dolphin --daemon
index 89a4e431c46e1f26ab4250420e8a63f04f106f02..560545aed687c081fef50cf9fa5afa212ee0fb18 100644 (file)
@@ -247,6 +247,8 @@ set(dolphin_SRCS
     statusbar/statusbarspaceinfo.cpp
     views/zoomlevelinfo.cpp
     dolphindebug.cpp
+    dbusinterface.cpp
+    global.cpp
 )
 
 kconfig_add_kcfg_files(dolphin_SRCS GENERATE_MOC
@@ -291,6 +293,15 @@ if (KF5Activities_FOUND)
     )
 endif()
 
+include(DbusInterfaceMacros)
+
+generate_and_install_dbus_interface(
+    kdeinit_dolphin
+    dbusinterface.h
+    org.freedesktop.FileManager1.xml
+    OPTIONS -a
+)
+
 install(TARGETS kdeinit_dolphin ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
 install(TARGETS dolphin ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
 
diff --git a/src/dbusinterface.cpp b/src/dbusinterface.cpp
new file mode 100644 (file)
index 0000000..b123476
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2015 Ashish Bansal<bansal.ashish096@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "dbusinterface.h"
+#include "global.h"
+
+#include <QDBusConnection>
+#include <QList>
+#include <QUrl>
+#include <KPropertiesDialog>
+#include <KRun>
+
+DBusInterface::DBusInterface() :
+    QObject()
+{
+    QDBusConnection::sessionBus().registerService("org.freedesktop.FileManager1");
+    QDBusConnection::sessionBus().registerObject("/org/freedesktop/FileManager1", this,
+            QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors);
+}
+
+void DBusInterface::ShowFolders(const QStringList& uriList, const QString& startUpId)
+{
+    Q_UNUSED(startUpId);
+    const QList<QUrl> urls = Dolphin::validateUris(uriList);
+    if (urls.isEmpty()) {
+        return;
+    }
+    KRun::run("dolphin %u", urls, nullptr);
+}
+
+void DBusInterface::ShowItems(const QStringList& uriList, const QString& startUpId)
+{
+    Q_UNUSED(startUpId);
+    const QList<QUrl> urls = Dolphin::validateUris(uriList);
+    if (urls.isEmpty()) {
+        return;
+    }
+    KRun::run("dolphin --select %u", urls, nullptr);
+}
+
+void DBusInterface::ShowItemProperties(const QStringList& uriList, const QString& startUpId)
+{
+    Q_UNUSED(startUpId);
+    const QList<QUrl> urls = Dolphin::validateUris(uriList);
+    foreach (const QUrl& url, urls) {
+        KPropertiesDialog::showDialog(url);
+    }
+}
diff --git a/src/dbusinterface.h b/src/dbusinterface.h
new file mode 100644 (file)
index 0000000..baf804f
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2015 Ashish Bansal<bansal.ashish096@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef DBUSINTERFACE_H
+#define DBUSINTERFACE_H
+
+#include <QObject>
+
+class DBusInterface : QObject
+{
+    Q_OBJECT
+    Q_CLASSINFO("D-Bus Interface", "org.freedesktop.FileManager1")
+
+public:
+    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
diff --git a/src/global.cpp b/src/global.cpp
new file mode 100644 (file)
index 0000000..2f23ae4
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2015 Ashish Bansal<bansal.ashish096@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "global.h"
+#include "dolphindebug.h"
+
+QList<QUrl> Dolphin::validateUris(const QStringList& uriList)
+{
+    QList<QUrl> urls;
+    foreach (const QString& str, uriList) {
+        const QUrl url = QUrl::fromUserInput(str, QString(), QUrl::AssumeLocalFile);
+        if (url.isValid()) {
+            urls.append(url);
+        } else {
+            qCWarning(DolphinDebug) << "Invalid URL: " << str;
+        }
+    }
+    return urls;
+}
diff --git a/src/global.h b/src/global.h
new file mode 100644 (file)
index 0000000..7f1931f
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2015 Ashish Bansal<bansal.ashish096@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef GLOBAL_H
+#define GLOBAL_H
+
+#include <QList>
+#include <QUrl>
+
+namespace Dolphin {
+    QList<QUrl> validateUris(const QStringList& uriList);
+}
+
+#endif //GLOBAL_H
index 1c0fdab68832b05192ed0c5425187317f86ef659..105330059021c96172e85febcbe41985ba05608a 100644 (file)
@@ -21,6 +21,8 @@
 
 #include "dolphinmainwindow.h"
 #include "dolphin_generalsettings.h"
+#include "dbusinterface.h"
+#include "global.h"
 
 #include <KDBusService>
 #include <KAboutData>
@@ -84,6 +86,7 @@ extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
     KAboutData::setApplicationData(aboutData);
 
     KDBusService dolphinDBusService;
+    DBusInterface interface;
 
     QCommandLineParser parser;
     parser.addVersionOption();
@@ -94,25 +97,21 @@ extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
     parser.addOption(QCommandLineOption(QStringList() << QLatin1String("select"), i18nc("@info:shell", "The files and directories passed as arguments "
                                                                                         "will be selected.")));
     parser.addOption(QCommandLineOption(QStringList() << QLatin1String("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
+    parser.addOption(QCommandLineOption(QStringList() << QLatin1String("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface)")));
     parser.addPositionalArgument(QLatin1String("+[Url]"), i18nc("@info:shell", "Document to open"));
 
     parser.process(app);
     aboutData.processCommandLine(&parser);
 
+    if (parser.isSet("daemon")) {
+        return app.exec();
+    }
 
     DolphinMainWindow* m_mainWindow = new DolphinMainWindow();
     m_mainWindow->setAttribute(Qt::WA_DeleteOnClose);
 
-    QList<QUrl> urls;
     const QStringList args = parser.positionalArguments();
-    foreach (const QString& str,  args) {
-        const QUrl url = QUrl::fromUserInput(str, QString(), QUrl::AssumeLocalFile);
-        if (url.isValid()) {
-            urls.append(url);
-        } else {
-            qCWarning(DolphinDebug) << "Invalid URL: " << str;
-        }
-    }
+    QList<QUrl> urls = Dolphin::validateUris(args);
 
     bool resetSplitSettings = false;
     if (parser.isSet("split") && !GeneralSettings::splitView()) {