File indexing completed on 2024-05-12 17:08:51

0001 /*
0002     SPDX-FileCopyrightText: 2009 Marco Martin <notmart@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "systemtraytypes.h"
0008 
0009 // Marshall the ImageStruct data into a D-BUS argument
0010 const QDBusArgument &operator<<(QDBusArgument &argument, const KDbusImageStruct &icon)
0011 {
0012     argument.beginStructure();
0013     argument << icon.width;
0014     argument << icon.height;
0015     argument << icon.data;
0016     argument.endStructure();
0017     return argument;
0018 }
0019 #include <QDebug>
0020 
0021 // Retrieve the ImageStruct data from the D-BUS argument
0022 const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusImageStruct &icon)
0023 {
0024     qint32 width = 0;
0025     qint32 height = 0;
0026     QByteArray data;
0027 
0028     if (argument.currentType() == QDBusArgument::StructureType) {
0029         argument.beginStructure();
0030         // qCDebug(DATAENGINE_SNI)() << "begun structure";
0031         argument >> width;
0032         // qCDebug(DATAENGINE_SNI)() << width;
0033         argument >> height;
0034         // qCDebug(DATAENGINE_SNI)() << height;
0035         argument >> data;
0036         // qCDebug(DATAENGINE_SNI)() << data.size();
0037         argument.endStructure();
0038     }
0039 
0040     icon.width = width;
0041     icon.height = height;
0042     icon.data = data;
0043 
0044     return argument;
0045 }
0046 
0047 // Marshall the ImageVector data into a D-BUS argument
0048 const QDBusArgument &operator<<(QDBusArgument &argument, const KDbusImageVector &iconVector)
0049 {
0050     argument.beginArray(qMetaTypeId<KDbusImageStruct>());
0051     for (int i = 0; i < iconVector.size(); ++i) {
0052         argument << iconVector[i];
0053     }
0054     argument.endArray();
0055     return argument;
0056 }
0057 
0058 // Retrieve the ImageVector data from the D-BUS argument
0059 const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusImageVector &iconVector)
0060 {
0061     iconVector.clear();
0062 
0063     if (argument.currentType() == QDBusArgument::ArrayType) {
0064         argument.beginArray();
0065 
0066         while (!argument.atEnd()) {
0067             KDbusImageStruct element;
0068             argument >> element;
0069             iconVector.append(element);
0070         }
0071 
0072         argument.endArray();
0073     }
0074 
0075     return argument;
0076 }
0077 
0078 // Marshall the ToolTipStruct data into a D-BUS argument
0079 const QDBusArgument &operator<<(QDBusArgument &argument, const KDbusToolTipStruct &toolTip)
0080 {
0081     argument.beginStructure();
0082     argument << toolTip.icon;
0083     argument << toolTip.image;
0084     argument << toolTip.title;
0085     argument << toolTip.subTitle;
0086     argument.endStructure();
0087 
0088     return argument;
0089 }
0090 
0091 // Retrieve the ToolTipStruct data from the D-BUS argument
0092 const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusToolTipStruct &toolTip)
0093 {
0094     QString icon;
0095     KDbusImageVector image;
0096     QString title;
0097     QString subTitle;
0098 
0099     if (argument.currentType() == QDBusArgument::StructureType) {
0100         argument.beginStructure();
0101         argument >> icon;
0102         argument >> image;
0103         argument >> title;
0104         argument >> subTitle;
0105         argument.endStructure();
0106     }
0107 
0108     toolTip.icon = icon;
0109     toolTip.image = image;
0110     toolTip.title = title;
0111     toolTip.subTitle = subTitle;
0112 
0113     return argument;
0114 }