mirror of
https://invent.kde.org/system/dolphin
synced 2024-07-04 17:30:55 +00:00
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
This commit is contained in:
parent
807230882b
commit
7042c6c289
|
@ -10,7 +10,7 @@ set(ECM_MIN_VERSION "1.6.0")
|
||||||
|
|
||||||
# ECM setup
|
# ECM setup
|
||||||
find_package(ECM ${ECM_MIN_VERSION} CONFIG REQUIRED)
|
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(ECMSetupVersion)
|
||||||
include(ECMGenerateHeaders)
|
include(ECMGenerateHeaders)
|
||||||
|
@ -123,5 +123,10 @@ install(FILES
|
||||||
COMPONENT Devel
|
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)
|
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
|
||||||
|
|
||||||
|
|
18
cmake/DbusInterfaceMacros.cmake
Normal file
18
cmake/DbusInterfaceMacros.cmake
Normal file
|
@ -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 ()
|
3
org.kde.dolphin.FileManager1.service.in
Normal file
3
org.kde.dolphin.FileManager1.service.in
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
[D-BUS Service]
|
||||||
|
Name=org.freedesktop.FileManager1
|
||||||
|
Exec=@CMAKE_INSTALL_PREFIX@/bin/dolphin --daemon
|
|
@ -247,6 +247,8 @@ set(dolphin_SRCS
|
||||||
statusbar/statusbarspaceinfo.cpp
|
statusbar/statusbarspaceinfo.cpp
|
||||||
views/zoomlevelinfo.cpp
|
views/zoomlevelinfo.cpp
|
||||||
dolphindebug.cpp
|
dolphindebug.cpp
|
||||||
|
dbusinterface.cpp
|
||||||
|
global.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
kconfig_add_kcfg_files(dolphin_SRCS GENERATE_MOC
|
kconfig_add_kcfg_files(dolphin_SRCS GENERATE_MOC
|
||||||
|
@ -291,6 +293,15 @@ if (KF5Activities_FOUND)
|
||||||
)
|
)
|
||||||
endif()
|
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 kdeinit_dolphin ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
|
||||||
install(TARGETS dolphin ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
|
install(TARGETS dolphin ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
|
||||||
|
|
||||||
|
|
64
src/dbusinterface.cpp
Normal file
64
src/dbusinterface.cpp
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
37
src/dbusinterface.h
Normal file
37
src/dbusinterface.h
Normal file
|
@ -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
|
35
src/global.cpp
Normal file
35
src/global.cpp
Normal file
|
@ -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;
|
||||||
|
}
|
30
src/global.h
Normal file
30
src/global.h
Normal file
|
@ -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
|
17
src/main.cpp
17
src/main.cpp
|
@ -21,6 +21,8 @@
|
||||||
|
|
||||||
#include "dolphinmainwindow.h"
|
#include "dolphinmainwindow.h"
|
||||||
#include "dolphin_generalsettings.h"
|
#include "dolphin_generalsettings.h"
|
||||||
|
#include "dbusinterface.h"
|
||||||
|
#include "global.h"
|
||||||
|
|
||||||
#include <KDBusService>
|
#include <KDBusService>
|
||||||
#include <KAboutData>
|
#include <KAboutData>
|
||||||
|
@ -84,6 +86,7 @@ extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
|
||||||
KAboutData::setApplicationData(aboutData);
|
KAboutData::setApplicationData(aboutData);
|
||||||
|
|
||||||
KDBusService dolphinDBusService;
|
KDBusService dolphinDBusService;
|
||||||
|
DBusInterface interface;
|
||||||
|
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.addVersionOption();
|
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 "
|
parser.addOption(QCommandLineOption(QStringList() << QLatin1String("select"), i18nc("@info:shell", "The files and directories passed as arguments "
|
||||||
"will be selected.")));
|
"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("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.addPositionalArgument(QLatin1String("+[Url]"), i18nc("@info:shell", "Document to open"));
|
||||||
|
|
||||||
parser.process(app);
|
parser.process(app);
|
||||||
aboutData.processCommandLine(&parser);
|
aboutData.processCommandLine(&parser);
|
||||||
|
|
||||||
|
if (parser.isSet("daemon")) {
|
||||||
|
return app.exec();
|
||||||
|
}
|
||||||
|
|
||||||
DolphinMainWindow* m_mainWindow = new DolphinMainWindow();
|
DolphinMainWindow* m_mainWindow = new DolphinMainWindow();
|
||||||
m_mainWindow->setAttribute(Qt::WA_DeleteOnClose);
|
m_mainWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
QList<QUrl> urls;
|
|
||||||
const QStringList args = parser.positionalArguments();
|
const QStringList args = parser.positionalArguments();
|
||||||
foreach (const QString& str, args) {
|
QList<QUrl> urls = Dolphin::validateUris(args);
|
||||||
const QUrl url = QUrl::fromUserInput(str, QString(), QUrl::AssumeLocalFile);
|
|
||||||
if (url.isValid()) {
|
|
||||||
urls.append(url);
|
|
||||||
} else {
|
|
||||||
qCWarning(DolphinDebug) << "Invalid URL: " << str;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool resetSplitSettings = false;
|
bool resetSplitSettings = false;
|
||||||
if (parser.isSet("split") && !GeneralSettings::splitView()) {
|
if (parser.isSet("split") && !GeneralSettings::splitView()) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user