diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,7 +60,6 @@ set(policykit_SRCS ${policykit_SRCS} - policykitkde.cpp policykitlistener.cpp main.cpp AuthDialog.cpp diff --git a/main.cpp b/main.cpp --- a/main.cpp +++ b/main.cpp @@ -18,25 +18,29 @@ */ +#include "policykitlistener.h" #include "config.h" - +// KF #include #include #include #include - +// PolkitQt1 +#include +// Qt +#include #include - -#include "policykitkde.h" - +#include +// std #if HAVE_SYS_PRCTL_H #include #endif #if HAVE_SYS_PROCCTL_H #include #include #endif + int main(int argc, char *argv[]) { // disable ptrace @@ -48,7 +52,15 @@ procctl(P_PID, getpid(), PROC_TRACE_CTL, &mode); #endif + QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true); + + KCrash::setFlags(KCrash::AutoRestart); + + QApplication app(argc, argv); + app.setQuitOnLastWindowClosed(false); + KLocalizedString::setApplicationDomain("polkit-kde-authentication-agent-1"); + KAboutData aboutData("polkit-kde-authentication-agent-1", i18n("PolicyKit1 KDE Agent"), POLKIT_KDE_1_VERSION); aboutData.addLicense(KAboutLicense::GPL); aboutData.addCredit(i18n("(c) 2009 Red Hat, Inc.")); @@ -58,20 +70,30 @@ KAboutData::setApplicationData(aboutData); - QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org")); - QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true); - - KCrash::setFlags(KCrash::AutoRestart); - - PolicyKitKDE agent(argc, argv); + // ensure singleton run KDBusService service(KDBusService::Unique); + // disable session management auto disableSessionManagement = [](QSessionManager &sm) { sm.setRestartHint(QSessionManager::RestartNever); }; - QObject::connect(&agent, &QGuiApplication::commitDataRequest, disableSessionManagement); - QObject::connect(&agent, &QGuiApplication::saveStateRequest, disableSessionManagement); + QObject::connect(&app, &QGuiApplication::commitDataRequest, disableSessionManagement); + QObject::connect(&app, &QGuiApplication::saveStateRequest, disableSessionManagement); + + // register agent + PolicyKitListener *listener = new PolicyKitListener(&app); + + PolkitQt1::UnixSessionSubject session(getpid()); + + const bool result = listener->registerListener(session, "/org/kde/PolicyKit1/AuthenticationAgent"); + + qDebug() << "Authentication agent result:" << result; + + if (!result) { + qWarning() << "Couldn't register listener!"; + exit(1); + } - agent.exec(); + app.exec(); } diff --git a/policykitkde.h b/policykitkde.h deleted file mode 100644 --- a/policykitkde.h +++ /dev/null @@ -1,38 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2009 Jaroslav Reznik - - 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 library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#ifndef POLICYKITKDE_H -#define POLICYKITKDE_H - -#include - -#include "policykitlistener.h" - -class PolicyKitKDE : public QApplication -{ - Q_OBJECT -public: - PolicyKitKDE(int &argc, char **argv); - ~PolicyKitKDE() override; -private: - PolicyKitListener *m_listener; -}; - -#endif diff --git a/policykitkde.cpp b/policykitkde.cpp deleted file mode 100644 --- a/policykitkde.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2009 Jaroslav Reznik - - 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 library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#include -#include - -#include - -#include "policykitkde.h" - -PolicyKitKDE::PolicyKitKDE(int &argc,char **argv): - QApplication(argc, argv), - m_listener(new PolicyKitListener(this)) -{ - setQuitOnLastWindowClosed(false); - - PolkitQt1::UnixSessionSubject session(getpid()); - - bool result = m_listener->registerListener(session, "/org/kde/PolicyKit1/AuthenticationAgent"); - - qDebug() << "Authentication agent result:" << result; - - if (!result) { - qWarning() << "Couldn't register listener!"; - exit(1); - } -} - -PolicyKitKDE::~PolicyKitKDE() -{ - m_listener->deleteLater(); -}