File indexing completed on 2024-11-10 04:57:19
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2012 Martin Gräßlin <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #include "scriptingutils.h" 0010 #include "scripting_logging.h" 0011 0012 #include <QDBusArgument> 0013 #include <QDBusObjectPath> 0014 #include <QDBusSignature> 0015 0016 namespace KWin 0017 { 0018 0019 QVariant dbusToVariant(const QVariant &variant) 0020 { 0021 if (variant.canConvert<QDBusArgument>()) { 0022 const QDBusArgument argument = variant.value<QDBusArgument>(); 0023 switch (argument.currentType()) { 0024 case QDBusArgument::BasicType: 0025 return dbusToVariant(argument.asVariant()); 0026 case QDBusArgument::VariantType: 0027 return dbusToVariant(argument.asVariant().value<QDBusVariant>().variant()); 0028 case QDBusArgument::ArrayType: { 0029 QVariantList array; 0030 argument.beginArray(); 0031 while (!argument.atEnd()) { 0032 const QVariant value = argument.asVariant(); 0033 array.append(dbusToVariant(value)); 0034 } 0035 argument.endArray(); 0036 return array; 0037 } 0038 case QDBusArgument::StructureType: { 0039 QVariantList structure; 0040 argument.beginStructure(); 0041 while (!argument.atEnd()) { 0042 const QVariant value = argument.asVariant(); 0043 structure.append(dbusToVariant(value)); 0044 } 0045 argument.endStructure(); 0046 return structure; 0047 } 0048 case QDBusArgument::MapType: { 0049 QVariantMap map; 0050 argument.beginMap(); 0051 while (!argument.atEnd()) { 0052 argument.beginMapEntry(); 0053 const QVariant key = argument.asVariant(); 0054 const QVariant value = argument.asVariant(); 0055 argument.endMapEntry(); 0056 map.insert(key.toString(), dbusToVariant(value)); 0057 } 0058 argument.endMap(); 0059 return map; 0060 } 0061 default: 0062 qCWarning(KWIN_SCRIPTING) << "Couldn't unwrap QDBusArgument of type" << argument.currentType(); 0063 return variant; 0064 } 0065 } else if (variant.canConvert<QDBusObjectPath>()) { 0066 return variant.value<QDBusObjectPath>().path(); 0067 } else if (variant.canConvert<QDBusSignature>()) { 0068 return variant.value<QDBusSignature>().signature(); 0069 } else if (variant.canConvert<QDBusVariant>()) { 0070 return dbusToVariant(variant.value<QDBusVariant>().variant()); 0071 } 0072 0073 return variant; 0074 } 0075 0076 }