File: daemon_adaptor.cpp

package info (click to toggle)
lxqt-globalkeys 2.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,464 kB
  • sloc: cpp: 6,742; xml: 221; makefile: 10
file content (299 lines) | stat: -rw-r--r-- 8,238 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/* BEGIN_COMMON_COPYRIGHT_HEADER
 * (c)LGPL2+
 *
 * LXQt - a lightweight, Qt based, desktop toolset
 * https://lxqt.org
 *
 * Copyright: 2013 Razor team
 * Authors:
 *   Kuzma Shapran <kuzma.shapran@gmail.com>
 *
 * This program or library is free software; you can redistribute it
 * and/or modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 *
 * END_COMMON_COPYRIGHT_HEADER */

#include "daemon_adaptor.h"

#include "org.lxqt.global_key_shortcuts.daemon.h"


DaemonAdaptor::DaemonAdaptor(QObject *parent)
    : QObject(parent)
    , QDBusContext()
{
    new OrgLxqtGlobalActionDaemonAdaptor(this);
}

QString DaemonAdaptor::addMethodAction(const QString &shortcut, const QString &service, const QDBusObjectPath &path, const QString &interface, const QString &method, const QString &description, qulonglong &id)
{
    std::pair<QString, qulonglong> result;
    emit onAddMethodAction(result, shortcut, service, path, interface, method, description);
    QString usedShortcut = result.first;
    id = result.second;
    if (id)
    {
        emit actionAdded(id);
    }
    return usedShortcut;
}

QString DaemonAdaptor::addCommandAction(const QString &shortcut, const QString &command, const QStringList &arguments, const QString &description, qulonglong &id)
{
    std::pair<QString, qulonglong> result;
    emit onAddCommandAction(result, shortcut, command, arguments, description);
    QString usedShortcut = result.first;
    id = result.second;
    if (id)
    {
        emit actionAdded(id);
    }
    return usedShortcut;
}

bool DaemonAdaptor::modifyActionDescription(qulonglong id, const QString &description)
{
    bool result;
    emit onModifyActionDescription(result, id, description);
    if (result)
    {
        emit actionModified(id);
    }
    return result;
}

bool DaemonAdaptor::modifyMethodAction(qulonglong id, const QString &service, const QDBusObjectPath &path, const QString &interface, const QString &method, const QString &description)
{
    bool result;
    emit onModifyMethodAction(result, id, service, path, interface, method, description);
    if (result)
    {
        emit actionModified(id);
    }
    return result;
}

bool DaemonAdaptor::modifyCommandAction(qulonglong id, const QString &command, const QStringList &arguments, const QString &description)
{
    bool result;
    emit onModifyCommandAction(result, id, command, arguments, description);
    if (result)
    {
        emit actionModified(id);
    }
    return result;
}

bool DaemonAdaptor::enableAction(qulonglong id, bool enabled)
{
    bool result;
    emit onEnableAction(result, id, enabled);
    if (result)
    {
        emit actionEnabled(id, enabled);
    }
    return result;
}

bool DaemonAdaptor::isActionEnabled(qulonglong id)
{
    bool enabled;
    emit onIsActionEnabled(enabled, id);
    return enabled;
}

QString DaemonAdaptor::getClientActionSender(qulonglong id)
{
    QString sender;
    emit onGetClientActionSender(sender, id);
    return sender;
}

QString DaemonAdaptor::changeShortcut(qulonglong id, const QString &shortcut)
{
    QString result;
    emit onChangeShortcut(result, id, shortcut);
    if (!result.isEmpty())
    {
        emit actionShortcutChanged(id);
    }
    return result;
}

bool DaemonAdaptor::swapActions(qulonglong id1, qulonglong id2)
{
    bool result;
    emit onSwapActions(result, id1, id2);
    if (result)
    {
        emit actionsSwapped(id1, id2);
    }
    return result;
}

bool DaemonAdaptor::removeAction(qulonglong id)
{
    bool result;
    emit onRemoveAction(result, id);
    if (result)
    {
        emit actionRemoved(id);
    }
    return result;
}

bool DaemonAdaptor::setMultipleActionsBehaviour(uint behaviour)
{
    if (behaviour >= MULTIPLE_ACTIONS_BEHAVIOUR__COUNT)
    {
        return false;
    }
    emit onSetMultipleActionsBehaviour(static_cast<MultipleActionsBehaviour>(behaviour));
    emit multipleActionsBehaviourChanged(behaviour);
    return true;
}

uint DaemonAdaptor::getMultipleActionsBehaviour()
{
    MultipleActionsBehaviour result;
    emit onGetMultipleActionsBehaviour(result);
    return result;
}

QList<qulonglong> DaemonAdaptor::getAllActionIds()
{
    QList<qulonglong> result;
    emit onGetAllActionIds(result);
    return result;
}

bool DaemonAdaptor::getActionById(qulonglong id, QString &shortcut, QString &description, bool &enabled, QString &type, QString &info)
{
    std::pair<bool, GeneralActionInfo> result;
    emit onGetActionById(result, id);
    bool success = result.first;
    if (success)
    {
        shortcut = result.second.shortcut;
        description = result.second.description;
        enabled = result.second.enabled;
        type = result.second.type;
        info = result.second.info;
    }
    return success;
}

QMap<qulonglong, GeneralActionInfo> DaemonAdaptor::getAllActions()
{
    QMap<qulonglong, GeneralActionInfo> result;
    emit onGetAllActions(result);
    return result;
}

bool DaemonAdaptor::getClientActionInfoById(qulonglong id, QString &shortcut, QString &description, bool &enabled, QDBusObjectPath &path)
{
    std::pair<bool, ClientActionInfo> result;
    emit onGetClientActionInfoById(result, id);
    bool success = result.first;
    if (success)
    {
        shortcut = result.second.shortcut;
        description = result.second.description;
        enabled = result.second.enabled;
        path = result.second.path;
    }
    return success;
}

bool DaemonAdaptor::getMethodActionInfoById(qulonglong id, QString &shortcut, QString &description, bool &enabled, QString &service, QDBusObjectPath &path, QString &interface, QString &method)
{
    std::pair<bool, MethodActionInfo> result;
    emit onGetMethodActionInfoById(result, id);
    bool success = result.first;
    if (success)
    {
        shortcut = result.second.shortcut;
        description = result.second.description;
        enabled = result.second.enabled;
        service = result.second.service;
        path = result.second.path;
        interface = result.second.interface;
        method = result.second.method;
    }
    return success;
}

bool DaemonAdaptor::getCommandActionInfoById(qulonglong id, QString &shortcut, QString &description, bool &enabled, QString &command, QStringList &arguments)
{
    std::pair<bool, CommandActionInfo> result;
    emit onGetCommandActionInfoById(result, id);
    bool success = result.first;
    if (success)
    {
        shortcut = result.second.shortcut;
        description = result.second.description;
        enabled = result.second.enabled;
        command = result.second.command;
        arguments = result.second.arguments;
    }
    return success;
}

QString DaemonAdaptor::grabShortcut(uint timeout, bool &failed, bool &cancelled, bool &timedout)
{
    QString shortcut;
    emit onGrabShortcut(timeout, shortcut, failed, cancelled, timedout, message());
    return shortcut;
}

void DaemonAdaptor::cancelShortcutGrab()
{
    emit onCancelShortcutGrab();
}

void DaemonAdaptor::quit()
{
    emit onQuit();
}

void DaemonAdaptor::emit_actionAdded(qulonglong id)
{
    emit actionAdded(id);
}

void DaemonAdaptor::emit_actionModified(qulonglong id)
{
    emit actionModified(id);
}

void DaemonAdaptor::emit_actionRemoved(qulonglong id)
{
    emit actionRemoved(id);
}

void DaemonAdaptor::emit_actionShortcutChanged(qulonglong id)
{
    emit actionShortcutChanged(id);
}

void DaemonAdaptor::emit_actionEnabled(qulonglong id, bool enabled)
{
    emit actionEnabled(id, enabled);
}

void DaemonAdaptor::emit_clientActionSenderChanged(qulonglong id, const QString &sender)
{
    emit clientActionSenderChanged(id, sender);
}