Fully replaced KDED for autostart + dbus activation, so we work outside KDE
This commit is contained in:
parent
15745b2425
commit
18ba161f17
14 changed files with 107 additions and 222 deletions
|
@ -33,7 +33,7 @@ add_subdirectory(kio)
|
|||
add_subdirectory(icon)
|
||||
add_subdirectory(interfaces)
|
||||
|
||||
add_subdirectory(kded)
|
||||
add_subdirectory(daemon)
|
||||
add_subdirectory(plugins)
|
||||
add_subdirectory(plasmoid)
|
||||
add_subdirectory(cli)
|
||||
|
|
15
daemon/CMakeLists.txt
Normal file
15
daemon/CMakeLists.txt
Normal file
|
@ -0,0 +1,15 @@
|
|||
project(kdeconnectd)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR})
|
||||
|
||||
add_definitions(-DTRANSLATION_DOMAIN="kdeconnect-daemon")
|
||||
|
||||
add_executable(kdeconnectd kdeconnectd.cpp)
|
||||
target_link_libraries(kdeconnectd kdeconnectcore KF5::DBusAddons KF5::ConfigWidgets)
|
||||
|
||||
configure_file(kdeconnectd.desktop.cmake ${CMAKE_CURRENT_BINARY_DIR}/kdeconnectd.desktop)
|
||||
configure_file(org.kde.kdeconnect.service.in ${CMAKE_CURRENT_BINARY_DIR}/org.kde.kdeconnect.service)
|
||||
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kdeconnectd.desktop DESTINATION ${AUTOSTART_INSTALL_DIR})
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.kdeconnect.service DESTINATION ${DBUS_SERVICES_INSTALL_DIR})
|
||||
install(TARGETS kdeconnectd DESTINATION ${LIBEXEC_INSTALL_DIR})
|
77
daemon/kdeconnectd.cpp
Normal file
77
daemon/kdeconnectd.cpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
/**
|
||||
* Copyright 2014 Yuri Samoilenko <kinnalru@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) version 3 or any later version
|
||||
* accepted by the membership of KDE e.V. (or its successor approved
|
||||
* by the membership of KDE e.V.), which shall act as a proxy
|
||||
* defined in Section 14 of version 3 of the license.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <QSocketNotifier>
|
||||
#include <QApplication>
|
||||
|
||||
#include <KDBusService>
|
||||
|
||||
#include "core/daemon.h"
|
||||
|
||||
#include "../kdeconnect-version.h"
|
||||
|
||||
static int sigtermfd[2];
|
||||
const static char deadbeef = 1;
|
||||
struct sigaction action;
|
||||
|
||||
void sighandler(int signum)
|
||||
{
|
||||
if( signum == SIGTERM || signum == SIGINT)
|
||||
{
|
||||
ssize_t unused = ::write(sigtermfd[0], &deadbeef, sizeof(deadbeef));
|
||||
Q_UNUSED(unused);
|
||||
}
|
||||
}
|
||||
|
||||
void initializeTermHandlers(QCoreApplication* app, Daemon* daemon)
|
||||
{
|
||||
::socketpair(AF_UNIX, SOCK_STREAM, 0, sigtermfd);
|
||||
QSocketNotifier* snTerm = new QSocketNotifier(sigtermfd[1], QSocketNotifier::Read, app);
|
||||
QObject::connect(snTerm, SIGNAL(activated(int)), daemon, SLOT(deleteLater()));
|
||||
|
||||
action.sa_handler = sighandler;
|
||||
sigemptyset(&action.sa_mask);
|
||||
action.sa_flags = 0;
|
||||
|
||||
sigaction(SIGTERM, &action, NULL);
|
||||
sigaction(SIGINT, &action, NULL);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
app.setApplicationName("kdeconnectd");
|
||||
app.setApplicationVersion(QLatin1String(KDECONNECT_VERSION_STRING));
|
||||
app.setOrganizationDomain("kde.org");
|
||||
app.setQuitOnLastWindowClosed(false);
|
||||
|
||||
KDBusService dbusService(KDBusService::Unique);
|
||||
|
||||
Daemon* daemon = new Daemon(0);
|
||||
QObject::connect(daemon, SIGNAL(destroyed(QObject*)), &app, SLOT(quit()));
|
||||
initializeTermHandlers(&app, daemon);
|
||||
|
||||
return app.exec();
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
project(KDEConnectInterfaces)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
|
|
|
@ -18,11 +18,16 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "dbusinterfaces.h"
|
||||
|
||||
QString activatedService() {
|
||||
static const QString service = "org.kde.kdeconnect";
|
||||
QDBusConnection::sessionBus().interface()->startService(service);
|
||||
return service;
|
||||
}
|
||||
|
||||
DaemonDbusInterface::DaemonDbusInterface(QObject* parent)
|
||||
: OrgKdeKdeconnectDaemonInterface("org.kde.kdeconnect", "/modules/kdeconnect", QDBusConnection::sessionBus(), parent)
|
||||
: OrgKdeKdeconnectDaemonInterface(activatedService(), "/modules/kdeconnect", QDBusConnection::sessionBus(), parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -33,7 +38,7 @@ DaemonDbusInterface::~DaemonDbusInterface()
|
|||
}
|
||||
|
||||
DeviceDbusInterface::DeviceDbusInterface(const QString& id, QObject* parent)
|
||||
: OrgKdeKdeconnectDeviceInterface("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent)
|
||||
: OrgKdeKdeconnectDeviceInterface(activatedService(), "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -44,7 +49,7 @@ DeviceDbusInterface::~DeviceDbusInterface()
|
|||
}
|
||||
|
||||
DeviceBatteryDbusInterface::DeviceBatteryDbusInterface(const QString& id, QObject* parent)
|
||||
: OrgKdeKdeconnectDeviceBatteryInterface("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent)
|
||||
: OrgKdeKdeconnectDeviceBatteryInterface(activatedService(), "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -55,7 +60,7 @@ DeviceBatteryDbusInterface::~DeviceBatteryDbusInterface()
|
|||
}
|
||||
|
||||
DeviceNotificationsDbusInterface::DeviceNotificationsDbusInterface(const QString& id, QObject* parent)
|
||||
: OrgKdeKdeconnectDeviceNotificationsInterface("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent)
|
||||
: OrgKdeKdeconnectDeviceNotificationsInterface(activatedService(), "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -66,7 +71,7 @@ DeviceNotificationsDbusInterface::~DeviceNotificationsDbusInterface()
|
|||
}
|
||||
|
||||
NotificationDbusInterface::NotificationDbusInterface(const QString& deviceId, const QString& notificationId, QObject* parent)
|
||||
: OrgKdeKdeconnectDeviceNotificationsNotificationInterface("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+deviceId+"/notifications/"+notificationId, QDBusConnection::sessionBus(), parent)
|
||||
: OrgKdeKdeconnectDeviceNotificationsNotificationInterface(activatedService(), "/modules/kdeconnect/devices/"+deviceId+"/notifications/"+notificationId, QDBusConnection::sessionBus(), parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -77,7 +82,7 @@ NotificationDbusInterface::~NotificationDbusInterface()
|
|||
}
|
||||
|
||||
SftpDbusInterface::SftpDbusInterface(const QString& id, QObject* parent)
|
||||
: OrgKdeKdeconnectDeviceSftpInterface("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + id + "/sftp", QDBusConnection::sessionBus(), parent)
|
||||
: OrgKdeKdeconnectDeviceSftpInterface(activatedService(), "/modules/kdeconnect/devices/" + id + "/sftp", QDBusConnection::sessionBus(), parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -88,6 +88,4 @@ public:
|
|||
virtual ~SftpDbusInterface();
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // DEVICEINTERFACE_H
|
||||
#endif
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
include_directories(${CMAKE_SOURCE_DIR})
|
||||
|
||||
add_definitions(-DTRANSLATION_DOMAIN="kdeconnect-kded")
|
||||
|
||||
configure_file(config-kded.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kded.h)
|
||||
|
||||
add_executable(kdeconnectd kdeconnectd.cpp)
|
||||
target_link_libraries(kdeconnectd kdeconnectcore KF5::DBusAddons KF5::ConfigWidgets)
|
||||
|
||||
set(NEW_DAEMON_STARTUP_DESC "WIP: Start kdeconnectd without kded")
|
||||
option(WITH_AUTOSTART NEW_DAEMON_STARTUP_DESC Off)
|
||||
add_feature_info(WITH_AUTOSTART WITH_AUTOSTART NEW_DAEMON_STARTUP_DESC)
|
||||
|
||||
if (NOT WITH_AUTOSTART)
|
||||
add_library(kded_kdeconnect MODULE kded.cpp)
|
||||
target_link_libraries(kded_kdeconnect KF5::Service KF5::DBusAddons)
|
||||
install(TARGETS kded_kdeconnect DESTINATION ${PLUGIN_INSTALL_DIR})
|
||||
install(FILES kdeconnect.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kded)
|
||||
else()
|
||||
configure_file(kdeconnectd.desktop.cmake ${CMAKE_CURRENT_BINARY_DIR}/kdeconnectd.desktop)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kdeconnectd.desktop DESTINATION ${AUTOSTART_INSTALL_DIR})
|
||||
endif()
|
||||
|
||||
install(TARGETS kdeconnectd DESTINATION ${LIBEXEC_INSTALL_DIR})
|
||||
|
||||
configure_file(org.kde.kdeconnect.service.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/org.kde.kdeconnect.service)
|
||||
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.kdeconnect.service
|
||||
DESTINATION ${DBUS_SERVICES_INSTALL_DIR})
|
|
@ -1 +0,0 @@
|
|||
#define KDECONNECTD_BIN "${CMAKE_INSTALL_PREFIX}/${LIBEXEC_INSTALL_DIR}/kdeconnectd"
|
120
kded/kded.cpp
120
kded/kded.cpp
|
@ -1,120 +0,0 @@
|
|||
/**
|
||||
* Copyright 2014 Yuri Samoilenko <kinnalru@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) version 3 or any later version
|
||||
* accepted by the membership of KDE e.V. (or its successor approved
|
||||
* by the membership of KDE e.V.), which shall act as a proxy
|
||||
* defined in Section 14 of version 3 of the license.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "kded.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QDebug>
|
||||
|
||||
#include <KPluginFactory>
|
||||
|
||||
#include "config-kded.h"
|
||||
|
||||
K_PLUGIN_FACTORY(KdeConnectFactory, registerPlugin<Kded>();)
|
||||
|
||||
Q_LOGGING_CATEGORY(KDECONNECT_KDED, "kdeconnect.kded")
|
||||
|
||||
Kded::Kded(QObject *parent, const QList<QVariant>&)
|
||||
: KDEDModule(parent)
|
||||
, m_daemon(0)
|
||||
{
|
||||
QMetaObject::invokeMethod(this, "start", Qt::QueuedConnection);
|
||||
qDebug(KDECONNECT_KDED) << "kded_kdeconnect started";
|
||||
}
|
||||
|
||||
Kded::~Kded()
|
||||
{
|
||||
stop();
|
||||
qDebug(KDECONNECT_KDED) << "kded_kdeconnect stopped";
|
||||
}
|
||||
|
||||
void Kded::start()
|
||||
{
|
||||
if (m_daemon) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QString daemon = QStringLiteral(KDECONNECTD_BIN);
|
||||
qDebug(KDECONNECT_KDED) << "Starting daemon " << daemon;
|
||||
m_daemon = new QProcess(this);
|
||||
connect(m_daemon, SIGNAL(started()), SLOT(daemonStarted()));
|
||||
connect(m_daemon, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onError(QProcess::ProcessError)));
|
||||
connect(m_daemon, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(onFinished(int,QProcess::ExitStatus)));
|
||||
connect(m_daemon, SIGNAL(finished(int,QProcess::ExitStatus)), m_daemon, SLOT(deleteLater()));
|
||||
|
||||
m_daemon->setProgram(daemon);
|
||||
m_daemon->closeReadChannel(QProcess::StandardOutput);
|
||||
m_daemon->start();
|
||||
}
|
||||
|
||||
void Kded::stop()
|
||||
{
|
||||
if (!m_daemon) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_daemon->terminate();
|
||||
m_daemon->setProperty("terminate", true);
|
||||
QTimer::singleShot(10000, this, SLOT(checkIfDaemonTerminated()));
|
||||
}
|
||||
|
||||
void Kded::restart()
|
||||
{
|
||||
stop();
|
||||
return start();
|
||||
}
|
||||
|
||||
void Kded::onError(QProcess::ProcessError errorCode)
|
||||
{
|
||||
qCWarning(KDECONNECT_KDED) << "Process error code=" << errorCode;
|
||||
}
|
||||
|
||||
void Kded::daemonStarted()
|
||||
{
|
||||
qDebug(KDECONNECT_KDED) << "Daemon successfuly started";
|
||||
Q_EMIT started();
|
||||
}
|
||||
|
||||
void Kded::onFinished(int exitCode, QProcess::ExitStatus status)
|
||||
{
|
||||
if (status == QProcess::CrashExit) {
|
||||
qCWarning(KDECONNECT_KDED) << "Process crashed with code=" << exitCode;
|
||||
qCWarning(KDECONNECT_KDED) << m_daemon->readAllStandardError();
|
||||
qCWarning(KDECONNECT_KDED) << "Restarting in 5 sec...";
|
||||
QTimer::singleShot(5000, this, SLOT(start()));
|
||||
} else {
|
||||
qCWarning(KDECONNECT_KDED) << "Process finished with code=" << exitCode;
|
||||
}
|
||||
|
||||
Q_EMIT stopped();
|
||||
m_daemon = 0;
|
||||
}
|
||||
|
||||
void Kded::checkIfDaemonTerminated()
|
||||
{
|
||||
if (!m_daemon || !m_daemon->property("terminate").isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_daemon->kill();
|
||||
qCWarning(KDECONNECT_KDED) << "Daemon killed";
|
||||
}
|
||||
|
||||
#include "kded.moc"
|
60
kded/kded.h
60
kded/kded.h
|
@ -1,60 +0,0 @@
|
|||
/**
|
||||
* Copyright 2014 Yuri Samoilenko <kinnalru@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) version 3 or any later version
|
||||
* accepted by the membership of KDE e.V. (or its successor approved
|
||||
* by the membership of KDE e.V.), which shall act as a proxy
|
||||
* defined in Section 14 of version 3 of the license.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef KDECONNECT_KDED_H
|
||||
#define KDECONNECT_KDED_H
|
||||
|
||||
#include <KDEDModule>
|
||||
#include <QProcess>
|
||||
|
||||
#include <QLoggingCategory>
|
||||
|
||||
class Kded
|
||||
: public KDEDModule
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "org.kde.kded.kdeconnect")
|
||||
|
||||
public:
|
||||
Kded(QObject *parent, const QList<QVariant>&);
|
||||
~Kded();
|
||||
|
||||
public Q_SLOTS:
|
||||
|
||||
Q_SCRIPTABLE void start();
|
||||
Q_SCRIPTABLE void stop();
|
||||
Q_SCRIPTABLE void restart();
|
||||
|
||||
Q_SIGNALS:
|
||||
Q_SCRIPTABLE void started();
|
||||
Q_SCRIPTABLE void stopped();
|
||||
|
||||
private Q_SLOTS:
|
||||
void onError(QProcess::ProcessError);
|
||||
void onFinished(int, QProcess::ExitStatus);
|
||||
void daemonStarted();
|
||||
void checkIfDaemonTerminated();
|
||||
|
||||
private:
|
||||
QProcess* m_daemon;
|
||||
};
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_KDED)
|
||||
#endif
|
Loading…
Reference in a new issue