diff --git a/CMakeLists.txt b/CMakeLists.txt index daf9271970..3575db5da2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 index 0000000000..0fd2f4c1fb --- /dev/null +++ b/cmake/DbusInterfaceMacros.cmake @@ -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 index 0000000000..c1258bb6bc --- /dev/null +++ b/org.kde.dolphin.FileManager1.service.in @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=org.freedesktop.FileManager1 +Exec=@CMAKE_INSTALL_PREFIX@/bin/dolphin --daemon diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 89a4e431c4..560545aed6 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 0000000000..b123476072 --- /dev/null +++ b/src/dbusinterface.cpp @@ -0,0 +1,64 @@ +/* + * Copyright 2015 Ashish Bansal + * + * 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 +#include +#include +#include +#include + +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 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 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 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 0000000000..baf804f68a --- /dev/null +++ b/src/dbusinterface.h @@ -0,0 +1,37 @@ +/* + * Copyright 2015 Ashish Bansal + * + * 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 + +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 0000000000..2f23ae4d4c --- /dev/null +++ b/src/global.cpp @@ -0,0 +1,35 @@ +/* + * Copyright 2015 Ashish Bansal + * + * 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 Dolphin::validateUris(const QStringList& uriList) +{ + QList 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 0000000000..7f1931f0d1 --- /dev/null +++ b/src/global.h @@ -0,0 +1,30 @@ +/* + * Copyright 2015 Ashish Bansal + * + * 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 +#include + +namespace Dolphin { + QList validateUris(const QStringList& uriList); +} + +#endif //GLOBAL_H diff --git a/src/main.cpp b/src/main.cpp index 1c0fdab688..1053300590 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 #include @@ -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 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 urls = Dolphin::validateUris(args); bool resetSplitSettings = false; if (parser.isSet("split") && !GeneralSettings::splitView()) {