add more spacing
[personal-kdebase.git] / workspace / kmenuedit / khotkeys.cpp
blobb08371345cb4c5b304174ec417af04a2e295f2ae
1 /*
2 * Copyright (C) 2000 Matthias Elter <elter@kde.org>
3 * Lubos Lunak <l.lunak@email.cz>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "khotkeys.h"
22 #include "khotkeys_interface.h"
25 #include "kdebug.h"
26 #include "kmessagebox.h"
28 static bool khotkeys_present = false;
29 static bool khotkeys_inited = false;
30 static OrgKdeKhotkeysInterface *khotkeysInterface = NULL;
33 bool KHotKeys::init()
35 khotkeys_inited = true;
37 // Check if khotkeys is running
38 QDBusConnection bus = QDBusConnection::sessionBus();
39 khotkeysInterface = new OrgKdeKhotkeysInterface(
40 "org.kde.kded",
41 "/modules/khotkeys",
42 bus,
43 NULL);
45 QDBusError err;
46 if(!khotkeysInterface->isValid())
48 err = khotkeysInterface->lastError();
49 if (err.isValid())
51 kError() << err.name() << ":" << err.message();
53 KMessageBox::error(
54 NULL,
55 "<qt>" + i18n("Unable to contact khotkeys. Your changes are saved but i failed to activate them") + "</qt>" );
58 khotkeys_present = khotkeysInterface->isValid();
59 return true;
62 void KHotKeys::cleanup()
64 if( khotkeys_inited && khotkeys_present ) {
65 // CleanUp ???
67 khotkeys_inited = false;
70 bool KHotKeys::present()
72 if( !khotkeys_inited )
73 init();
74 return khotkeys_present;
77 QString KHotKeys::getMenuEntryShortcut( const QString& entry_P )
79 kDebug();
81 if( !khotkeys_inited )
82 init();
84 if( !khotkeys_present || !khotkeysInterface->isValid())
85 return "";
87 QDBusReply<QString> reply = khotkeysInterface->get_menuentry_shortcut(entry_P);
88 if (!reply.isValid()) {
89 kError() << reply.error();
90 return "";
92 } else {
93 return reply;
97 QString KHotKeys::changeMenuEntryShortcut(
98 const QString& entry_P,
99 const QString shortcut_P )
101 kDebug();
103 if( !khotkeys_inited )
104 init();
106 if( !khotkeys_present || !khotkeysInterface->isValid())
107 return "";
109 QDBusReply<QString> reply = khotkeysInterface->register_menuentry_shortcut(
110 entry_P,
111 shortcut_P);
113 if (!reply.isValid()) {
114 kError() << reply.error();
115 return "";
117 } else {
118 return reply;