Commit 576d1020 authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

Fix app initialization order

Summary:
Patch inlines the code of the constructor and destructor of the old
QApplication subclass PolicyKitKDE and then reorders things as needed:
* KDBusService for singleton run should be started before any further init
* KLocalizedString::setApplicationDomain & i18n calls should be only done
  after the QApp instance has been created
* KAboutData::setApplicationData best done before doing any D-Bus activity
  as that relies on app metadata
* QCoreApplication::setOrganizationDomain duplicates app metadata
  setting from KAboutData::setApplicationData, only needed before due to
  latter done after first D-Bus activity
* m_listener->deleteLater() in app destructor does not make sense, as
  the listener object is deleted due to being QObject child of the
  QApplication instance

Reviewers: davidedmundson

Reviewed By: davidedmundson

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D11106
parent e672ed5a
......@@ -60,7 +60,6 @@ ki18n_wrap_ui(policykit_SRCS AuthDialog.ui authdetails.ui)
set(policykit_SRCS
${policykit_SRCS}
policykitkde.cpp
policykitlistener.cpp
main.cpp
AuthDialog.cpp
......
......@@ -18,17 +18,20 @@
*/
#include "policykitlistener.h"
#include "config.h"
// KF
#include <KAboutData>
#include <KLocalizedString>
#include <KCrash>
#include <KDBusService>
// PolkitQt1
#include <PolkitQt1/Subject>
// Qt
#include <QApplication>
#include <QSessionManager>
#include "policykitkde.h"
#include <QDebug>
// std
#if HAVE_SYS_PRCTL_H
#include <sys/prctl.h>
#endif
......@@ -37,6 +40,7 @@
#include <sys/procctl.h>
#endif
int main(int argc, char *argv[])
{
// disable ptrace
......@@ -48,7 +52,15 @@ int main(int argc, char *argv[])
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 @@ int main(int argc, char *argv[])
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();
}
/* This file is part of the KDE project
Copyright (C) 2009 Jaroslav Reznik <jreznik@redhat.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 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 <QDebug>
#include <QDBusMetaType>
#include <PolkitQt1/Subject>
#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();
}
/* This file is part of the KDE project
Copyright (C) 2009 Jaroslav Reznik <jreznik@redhat.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 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 <QApplication>
#include "policykitlistener.h"
class PolicyKitKDE : public QApplication
{
Q_OBJECT
public:
PolicyKitKDE(int &argc, char **argv);
~PolicyKitKDE() override;
private:
PolicyKitListener *m_listener;
};
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment