KGlobalAccel

main.cpp
1 /*
2  This file is part of the KDE project
3 
4  SPDX-FileCopyrightText: 2007 Andreas Hartmetz <[email protected]>
5  SPDX-FileCopyrightText: 2007 Michael Jansen <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-only
8 */
9 
10 #include "kglobalacceld.h"
11 #include "logging_p.h"
12 
13 #include <KAboutData>
14 #include <KCrash>
15 #include <KDBusService>
16 #include <QCommandLineParser>
17 #include <QGuiApplication>
18 
19 #ifdef Q_OS_UNIX
20 #include <unistd.h>
21 #endif
22 
23 static bool isEnabled()
24 {
25  // TODO: Check if kglobalaccel can be disabled
26  return true;
27 }
28 
29 extern "C" Q_DECL_EXPORT int main(int argc, char **argv)
30 {
31  // Disable Session Management the right way (C)
32  //
33  // ksmserver has global shortcuts. disableSessionManagement() does not prevent Qt from
34  // registering the app with the session manager. We remove the address to make sure we do not
35  // get a hang on kglobalaccel restart (kglobalaccel tries to register with ksmserver,
36  // ksmserver tries to register with kglobalaccel).
37  qunsetenv("SESSION_MANAGER");
38 
39  QGuiApplication app(argc, argv);
40  KAboutData aboutdata(QStringLiteral("kglobalaccel"),
41  QObject::tr("KDE Global Shortcuts Service"),
42  QStringLiteral("0.2"),
43  QObject::tr("KDE Global Shortcuts Service"),
44  KAboutLicense::LGPL,
45  "(C) 2007-2009 Andreas Hartmetz, Michael Jansen");
46  aboutdata.addAuthor("Andreas Hartmetz", QObject::tr("Maintainer"), "[email protected]");
47  aboutdata.addAuthor("Michael Jansen", QObject::tr("Maintainer"), "[email protected]");
48 
50 
51  {
52  QCommandLineParser parser;
53  aboutdata.setupCommandLine(&parser);
54  parser.process(app);
55  aboutdata.processCommandLine(&parser);
56  }
57 
58  // check if kglobalaccel is disabled
59  if (!isEnabled()) {
60  qCDebug(KGLOBALACCELD) << "kglobalaccel is disabled!";
61  return 0;
62  }
63 
64 #ifdef Q_OS_UNIX
65  // It's possible that kglobalaccel gets started as the wrong user by
66  // accident, e.g. kdesu dolphin leads to dbus activation. It then installs
67  // its grabs and the actions are run as the wrong user.
68  bool isUidset = false;
69  const int sessionuid = qEnvironmentVariableIntValue("KDE_SESSION_UID", &isUidset);
70  if(isUidset && static_cast<uid_t>(sessionuid) != getuid()) {
71  qCWarning(KGLOBALACCELD) << "kglobalaccel running as wrong user, exiting.";
72  return 0;
73  }
74 #endif
75 
77 
78  app.setQuitOnLastWindowClosed(false);
80 
81  // Restart on a crash
83 
84  KGlobalAccelD globalaccel;
85  if (!globalaccel.init()) {
86  return -1;
87  }
88 
89  return app.exec();
90 }
QString tr(const char *sourceText, const char *disambiguation, int n)
KCRASH_EXPORT void setFlags(KCrash::CrashFlags flags)
void setFallbackSessionManagementEnabled(bool enabled)
static void setApplicationData(const KAboutData &aboutData)
void process(const QStringList &arguments)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun May 16 2021 22:53:45 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.