┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAshish Bansal <[email protected]>2015-04-22 18:59:39 +0530
committerAshish Bansal <[email protected]>2015-04-22 18:59:39 +0530
commit7042c6c2899a4e46a095a38ee1481b63ca4b96d8 (patch)
tree9f4faa535285ec57cafa9ba6cf5173c089509f9d /src
parent807230882b0d68d6b24849aa79d69fb4df7e813a (diff)
Add dbus interface to dolphin
Implemented org.freedesktop.FileManager1 dbus interface in dolphin http://www.freedesktop.org/wiki/Specifications/file-manager-interface/ REVIEW: 123313 BUG: 343016
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt11
-rw-r--r--src/dbusinterface.cpp64
-rw-r--r--src/dbusinterface.h37
-rw-r--r--src/global.cpp35
-rw-r--r--src/global.h30
-rw-r--r--src/main.cpp17
6 files changed, 185 insertions, 9 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 89a4e431c..560545aed 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -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
index 000000000..b12347607
--- /dev/null
+++ b/src/dbusinterface.cpp
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2015 Ashish Bansal<[email protected]>
+ *
+ * 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
index 000000000..baf804f68
--- /dev/null
+++ b/src/dbusinterface.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2015 Ashish Bansal<[email protected]>
+ *
+ * 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
index 000000000..2f23ae4d4
--- /dev/null
+++ b/src/global.cpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2015 Ashish Bansal<[email protected]>
+ *
+ * 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
index 000000000..7f1931f0d
--- /dev/null
+++ b/src/global.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2015 Ashish Bansal<[email protected]>
+ *
+ * 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
diff --git a/src/main.cpp b/src/main.cpp
index 1c0fdab68..105330059 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -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()) {