~ubuntu-branches/ubuntu/wily/kmenuedit/wily

« back to all changes in this revision

Viewing changes to khotkeys.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-10-14 13:48:27 UTC
  • Revision ID: package-import@ubuntu.com-20141014134827-c4gvv92bbv7zww8j
Tags: upstream-5.1.0.1
ImportĀ upstreamĀ versionĀ 5.1.0.1

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
#include <KDebug>
 
25
#include <KLocalizedString>
 
26
#include <KMessageBox>
 
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.kded5",
 
41
        "/modules/khotkeys",
 
42
        bus,
 
43
        NULL);
 
44
 
 
45
    if(!khotkeysInterface->isValid()) {
 
46
        QDBusError err = khotkeysInterface->lastError();
 
47
        if (err.isValid()) {
 
48
            kError() << err.name() << ":" << err.message();
 
49
        }
 
50
        KMessageBox::error(
 
51
            NULL,
 
52
            "<qt>" + i18n("Unable to contact khotkeys. Your changes are saved, but they could not be activated.") + "</qt>" );
 
53
    }
 
54
 
 
55
    khotkeys_present = khotkeysInterface->isValid();
 
56
    return true;
 
57
}
 
58
 
 
59
void KHotKeys::cleanup()
 
60
{
 
61
    if( khotkeys_inited && khotkeys_present ) {
 
62
        // CleanUp ???
 
63
    }
 
64
 
 
65
    khotkeys_inited = false;
 
66
}
 
67
 
 
68
bool KHotKeys::present()
 
69
{
 
70
    if( !khotkeys_inited )
 
71
        init();
 
72
 
 
73
    return khotkeys_present;
 
74
}
 
75
 
 
76
QString KHotKeys::getMenuEntryShortcut( const QString& entry_P )
 
77
{
 
78
    if( !khotkeys_inited )
 
79
        init();
 
80
 
 
81
    if( !khotkeys_present || !khotkeysInterface->isValid())
 
82
        return "";
 
83
 
 
84
    QDBusReply<QString> reply = khotkeysInterface->get_menuentry_shortcut(entry_P);
 
85
    if (!reply.isValid()) {
 
86
        kError() << reply.error();
 
87
        return "";
 
88
 
 
89
    } else {
 
90
        return reply;
 
91
    }
 
92
}
 
93
 
 
94
QString KHotKeys::changeMenuEntryShortcut(
 
95
        const QString& entry_P,
 
96
        const QString shortcut_P )
 
97
{
 
98
    if( !khotkeys_inited )
 
99
        init();
 
100
 
 
101
    if( !khotkeys_present || !khotkeysInterface->isValid())
 
102
        return "";
 
103
 
 
104
    QDBusReply<QString> reply = khotkeysInterface->register_menuentry_shortcut(
 
105
            entry_P,
 
106
            shortcut_P);
 
107
 
 
108
    if (!reply.isValid()) {
 
109
        kError() << reply.error();
 
110
        return "";
 
111
    } else {
 
112
        return reply;
 
113
    }
 
114
}
 
115