File indexing completed on 2024-03-24 03:56:59

0001 /*
0002     SPDX-FileCopyrightText: 2008 Michael Jansen <kde@michael-jansen.biz>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "kglobalshortcutinfo.h"
0008 #include "kglobalshortcutinfo_p.h"
0009 
0010 QDBusArgument &operator<<(QDBusArgument &argument, const QKeySequence &sequence)
0011 {
0012     argument.beginStructure();
0013     argument.beginArray(qMetaTypeId<int>());
0014     for (int i = 0; i < maxSequenceLength; i++) {
0015         argument << (i < sequence.count() ? sequence[i].toCombined() : 0);
0016     }
0017     argument.endArray();
0018     argument.endStructure();
0019     return argument;
0020 }
0021 
0022 const QDBusArgument &operator>>(const QDBusArgument &argument, QKeySequence &sequence)
0023 {
0024     int s1;
0025     int s2;
0026     int s3;
0027     int s4;
0028     argument.beginStructure();
0029     argument.beginArray();
0030     argument >> s1 >> s2 >> s3 >> s4;
0031     sequence = QKeySequence(s1, s2, s3, s4);
0032     argument.endArray();
0033     argument.endStructure();
0034     return argument;
0035 }
0036 
0037 QDBusArgument &operator<<(QDBusArgument &argument, const KGlobalShortcutInfo &shortcut)
0038 {
0039     argument.beginStructure();
0040     /* clang-format off */
0041     argument << shortcut.uniqueName()
0042              << shortcut.friendlyName()
0043              << shortcut.componentUniqueName()
0044              << shortcut.componentFriendlyName()
0045              << shortcut.contextUniqueName()
0046              << shortcut.contextFriendlyName();
0047     /* clang-format on */
0048     argument.beginArray(qMetaTypeId<int>());
0049 
0050     const QList<QKeySequence> keys = shortcut.keys();
0051     for (const QKeySequence &key : keys) {
0052         argument << key[0].toCombined();
0053     }
0054     argument.endArray();
0055     argument.beginArray(qMetaTypeId<int>());
0056 
0057     const QList<QKeySequence> defaultKeys = shortcut.defaultKeys();
0058     for (const QKeySequence &key : defaultKeys) {
0059         argument << key[0].toCombined();
0060     }
0061     argument.endArray();
0062     argument.endStructure();
0063     return argument;
0064 }
0065 
0066 const QDBusArgument &operator>>(const QDBusArgument &argument, KGlobalShortcutInfo &shortcut)
0067 {
0068     argument.beginStructure();
0069     /* clang-format off */
0070     argument >> shortcut.d->uniqueName
0071              >> shortcut.d->friendlyName
0072              >> shortcut.d->componentUniqueName
0073              >> shortcut.d->componentFriendlyName
0074              >> shortcut.d->contextUniqueName
0075              >> shortcut.d->contextFriendlyName;
0076     /* clang-format on */
0077 
0078     argument.beginArray();
0079     while (!argument.atEnd()) {
0080         int key;
0081         argument >> key;
0082         shortcut.d->keys.append(QKeySequence(key));
0083     }
0084     argument.endArray();
0085     argument.beginArray();
0086     while (!argument.atEnd()) {
0087         int key;
0088         argument >> key;
0089         shortcut.d->defaultKeys.append(QKeySequence(key));
0090     }
0091     argument.endArray();
0092     argument.endStructure();
0093     return argument;
0094 }