~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kmenuedit/khotkeys.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright (C) 2000 Matthias Elter <elter@kde.org>
 
3
 *                      Lubos Lunak    <l.lunak@email.cz>
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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.
 
18
 *
 
19
 */
 
20
 
 
21
#include "khotkeys.h"
 
22
#include "khotkeys_interface.h"
 
23
 
 
24
 
 
25
#include "kdebug.h"
 
26
#include "kmessagebox.h"
 
27
 
 
28
static bool khotkeys_present = false;
 
29
static bool khotkeys_inited = false;
 
30
static OrgKdeKhotkeysInterface *khotkeysInterface = NULL;
 
31
 
 
32
 
 
33
bool KHotKeys::init()
 
34
{
 
35
    khotkeys_inited = true;
 
36
 
 
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);
 
44
 
 
45
    QDBusError err;
 
46
    if(!khotkeysInterface->isValid())
 
47
        {
 
48
        err = khotkeysInterface->lastError();
 
49
        if (err.isValid())
 
50
            {
 
51
            kError() << err.name() << ":" << err.message();
 
52
            }
 
53
        KMessageBox::error(
 
54
            NULL,
 
55
            "<qt>" + i18n("Unable to contact khotkeys. Your changes are saved, but they could not be activated.") + "</qt>" );
 
56
        }
 
57
 
 
58
    khotkeys_present = khotkeysInterface->isValid();
 
59
    return true;
 
60
}
 
61
 
 
62
void KHotKeys::cleanup()
 
63
{
 
64
    if( khotkeys_inited && khotkeys_present ) {
 
65
        // CleanUp ???
 
66
    }
 
67
    khotkeys_inited = false;
 
68
}
 
69
 
 
70
bool KHotKeys::present()
 
71
{
 
72
    if( !khotkeys_inited )
 
73
        init();
 
74
    return khotkeys_present;
 
75
}
 
76
 
 
77
QString KHotKeys::getMenuEntryShortcut( const QString& entry_P )
 
78
{
 
79
    kDebug();
 
80
 
 
81
    if( !khotkeys_inited )
 
82
        init();
 
83
 
 
84
    if( !khotkeys_present || !khotkeysInterface->isValid())
 
85
        return "";
 
86
 
 
87
    QDBusReply<QString> reply = khotkeysInterface->get_menuentry_shortcut(entry_P);
 
88
    if (!reply.isValid()) {
 
89
        kError() << reply.error();
 
90
        return "";
 
91
 
 
92
    } else {
 
93
        return reply;
 
94
    }
 
95
}
 
96
 
 
97
QString KHotKeys::changeMenuEntryShortcut(
 
98
        const QString& entry_P,
 
99
        const QString shortcut_P )
 
100
{
 
101
    kDebug();
 
102
 
 
103
    if( !khotkeys_inited )
 
104
        init();
 
105
 
 
106
    if( !khotkeys_present || !khotkeysInterface->isValid())
 
107
        return "";
 
108
 
 
109
    QDBusReply<QString> reply = khotkeysInterface->register_menuentry_shortcut(
 
110
            entry_P,
 
111
            shortcut_P);
 
112
 
 
113
    if (!reply.isValid()) {
 
114
        kError() << reply.error();
 
115
        return "";
 
116
 
 
117
    } else {
 
118
        return reply;
 
119
    }
 
120
}
 
121