1 | /* |
2 | This file is part of the KDE project |
3 | |
4 | Copyright (c) 2007 Andreas Hartmetz <ahartmetz@gmail.com> |
5 | Copyright (c) 2007 Michael Jansen <kde@michael-jansen.biz> |
6 | |
7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public |
9 | License version 2 as published by the Free Software Foundation. |
10 | |
11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | Boston, MA 02110-1301, USA. |
20 | */ |
21 | |
22 | #include "kglobalacceld.h" |
23 | |
24 | #include <kuniqueapplication.h> |
25 | #include <kaboutdata.h> |
26 | #include <kcmdlineargs.h> |
27 | #include <kcrash.h> |
28 | #include <kde_file.h> |
29 | #include <kdebug.h> |
30 | #include <klocale.h> |
31 | |
32 | #include <signal.h> |
33 | |
34 | static bool isEnabled() |
35 | { |
36 | // TODO: Check if kglobalaccel can be disabled |
37 | return true; |
38 | } |
39 | |
40 | |
41 | static void sighandler(int /*sig*/) |
42 | { |
43 | if (qApp) |
44 | qApp->quit(); |
45 | } |
46 | |
47 | |
48 | extern "C" KDE_EXPORT int kdemain(int argc, char **argv) |
49 | { |
50 | // Disable Session Management the right way (C) |
51 | // |
52 | // ksmserver has global shortcuts. disableSessionManagement() does not prevent Qt from |
53 | // registering the app with the session manager. We remove the address to make sure we do not |
54 | // get a hang on kglobalaccel restart (kglobalaccel tries to register with ksmserver, |
55 | // ksmserver tries to register with kglobalaccel). |
56 | unsetenv( "SESSION_MANAGER" ); |
57 | |
58 | KAboutData aboutdata( |
59 | "kglobalaccel" , |
60 | 0, |
61 | ki18n("KDE Global Shortcuts Service" ), |
62 | "0.2" , |
63 | ki18n("KDE Global Shortcuts Service" ), |
64 | KAboutData::License_LGPL, |
65 | ki18n("(C) 2007-2009 Andreas Hartmetz, Michael Jansen" )); |
66 | aboutdata.addAuthor(ki18n("Andreas Hartmetz" ),ki18n("Maintainer" ),"ahartmetz@gmail.com" ); |
67 | aboutdata.addAuthor(ki18n("Michael Jansen" ),ki18n("Maintainer" ),"kde@michael-jansen.biz" ); |
68 | |
69 | aboutdata.setProgramIconName("kglobalaccel" ); |
70 | |
71 | KCmdLineArgs::init( argc, argv, &aboutdata ); |
72 | KUniqueApplication::addCmdLineOptions(); |
73 | |
74 | // check if kglobalaccel is disabled |
75 | if (!isEnabled()) |
76 | { |
77 | kDebug() << "kglobalaccel is disabled!" ; |
78 | return 0; |
79 | } |
80 | |
81 | if (!KUniqueApplication::start()) |
82 | { |
83 | kDebug() << "kglobalaccel is already running!" ; |
84 | return (0); |
85 | } |
86 | |
87 | // As in the KUniqueApplication example only create a instance AFTER |
88 | // calling KUniqueApplication::start() |
89 | KUniqueApplication app; |
90 | |
91 | // This app is started automatically, no need for session management |
92 | app.disableSessionManagement(); |
93 | app.setQuitOnLastWindowClosed( false ); |
94 | |
95 | // Stop gracefully |
96 | //There is no SIGINT and SIGTERM under wince |
97 | #ifndef _WIN32_WCE |
98 | KDE_signal(SIGINT, sighandler); |
99 | KDE_signal(SIGTERM, sighandler); |
100 | #endif |
101 | KDE_signal(SIGHUP, sighandler); |
102 | |
103 | // Restart on a crash |
104 | KCrash::setFlags(KCrash::AutoRestart); |
105 | |
106 | KGlobalAccelD globalaccel; |
107 | if (!globalaccel.init()) { |
108 | return -1; |
109 | } |
110 | |
111 | return app.exec(); |
112 | } |
113 | |