-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDBusTypes.cxx
More file actions
163 lines (132 loc) · 4.29 KB
/
Copy pathDBusTypes.cxx
File metadata and controls
163 lines (132 loc) · 4.29 KB
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
/*
This file is part of liquidshell.
SPDX-FileCopyrightText: 2017 - 2024 Martin Koller <martin@kollix.at>
SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <DBusTypes.hxx>
#include <QtEndian>
//--------------------------------------------------------------------------------
const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusImageStruct &pixmap)
{
pixmap = QPixmap();
if ( argument.currentType() == QDBusArgument::StructureType )
{
qint32 w = 0, h = 0;
QByteArray data;
argument.beginStructure();
argument >> w;
argument >> h;
argument >> data;
argument.endStructure();
// convert data to QPixmap
if ( w && h && !data.isEmpty() )
{
if ( QSysInfo::ByteOrder == QSysInfo::LittleEndian )
{
quint32 *uintBuf = reinterpret_cast<quint32 *>(data.data());
for (uint i = 0; i < data.size() / sizeof(quint32); ++i)
{
*uintBuf = qToBigEndian(*uintBuf);
++uintBuf;
}
}
pixmap = QPixmap::fromImage(QImage(reinterpret_cast<const uchar *>(data.constData()), w, h, QImage::Format_ARGB32));
}
}
return argument;
}
//--------------------------------------------------------------------------------
const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusImageVector &icon)
{
icon = QIcon();
if ( argument.currentType() == QDBusArgument::ArrayType )
{
argument.beginArray();
while ( !argument.atEnd() )
{
KDbusImageStruct pixmap;
argument >> pixmap;
if ( !pixmap.isNull() )
icon.addPixmap(pixmap);
}
argument.endArray();
}
return argument;
}
//--------------------------------------------------------------------------------
const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusToolTipStruct &tip)
{
tip = KDbusToolTipStruct();
if ( argument.currentType() == QDBusArgument::StructureType )
{
argument.beginStructure();
argument >> tip.icon;
argument >> tip.image;
argument >> tip.title;
argument >> tip.subTitle;
argument.endStructure();
}
return argument;
}
//--------------------------------------------------------------------------------
// add "dummy" operators we never need since we'll never send icons, but qDBusRegisterMetaType needs them
// But we must correctly create the structure information
QDBusArgument &operator<<(QDBusArgument &argument, const KDbusImageStruct &pixmap)
{
argument.beginStructure();
argument << qint32(pixmap.width());
argument << qint32(pixmap.height());
argument << QByteArray();
argument.endStructure();
return argument;
}
//--------------------------------------------------------------------------------
QDBusArgument &operator<<(QDBusArgument &argument, const KDbusImageVector &)
{
argument.beginArray(qMetaTypeId<KDbusImageStruct>());
argument.endArray();
return argument;
}
//--------------------------------------------------------------------------------
QDBusArgument &operator<<(QDBusArgument &argument, const KDbusToolTipStruct &tip)
{
argument.beginStructure();
argument << tip.icon;
argument << tip.image;
argument << tip.title;
argument << tip.subTitle;
argument.endStructure();
return argument;
}
//--------------------------------------------------------------------------------
const QDBusArgument &operator<<(QDBusArgument &arg, const DBusMenuLayoutItem &item)
{
arg.beginStructure();
arg << item.m_id << item.m_properties;
arg.beginArray(qMetaTypeId<QDBusVariant>());
for (const DBusMenuLayoutItem &child : item.m_children)
arg << QDBusVariant(QVariant::fromValue<DBusMenuLayoutItem>(child));
arg.endArray();
arg.endStructure();
return arg;
}
//--------------------------------------------------------------------------------
const QDBusArgument &operator>>(const QDBusArgument &arg, DBusMenuLayoutItem &item)
{
arg.beginStructure();
arg >> item.m_id >> item.m_properties;
arg.beginArray();
while ( !arg.atEnd() )
{
QDBusVariant dbusVariant;
arg >> dbusVariant;
QDBusArgument childArgument = qvariant_cast<QDBusArgument>(dbusVariant.variant());
DBusMenuLayoutItem child;
childArgument >> child;
item.m_children.append(child);
}
arg.endArray();
arg.endStructure();
return arg;
}
//--------------------------------------------------------------------------------