From 32ed6c460d1476f05edd8cb392ff9815cd77180c Mon Sep 17 00:00:00 2001 From: Jussi Kuokkanen Date: Sun, 24 May 2020 17:45:01 +0300 Subject: [PATCH] add conversions from dbus types to AssignableInfo --- src/include/DBusTypes.hpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/include/DBusTypes.hpp b/src/include/DBusTypes.hpp index 0108327..02dd341 100644 --- a/src/include/DBusTypes.hpp +++ b/src/include/DBusTypes.hpp @@ -1,10 +1,13 @@ #pragma once +#include #include #include #include #include - + +namespace TC = TuxClocker; + namespace TuxClocker::DBus { template @@ -41,6 +44,17 @@ struct Range { arg.endStructure(); return arg; } + TC::Device::AssignableInfo toAssignableInfo() { + auto min_v = min.variant(); + auto max_v = max.variant(); + + if (min_v.type() == QMetaType::Int && max_v.type() == QMetaType::Int) + return TC::Device::Range(min_v.value(), max_v.value()); + if (min_v.type() == QMetaType::Double && max_v.type() == QMetaType::Double) + return TC::Device::Range(min_v.value(), max_v.value()); + // Should never reach here + return TC::Device::Range(0, 0); + } }; struct Enumeration { @@ -57,9 +71,18 @@ struct Enumeration { arg >> e.key >> e.name; arg.endStructure(); return arg; - } + } }; +/* MOC crap doubles this somewhere +TC::Device::AssignableInfo enumVecToAssignableInfo(QVector enums) { + TC::Device::EnumerationVec v; + for (const auto &e : enums) + v.push_back(TC::Device::Enumeration(e.name.toStdString(), e.key)); + return v; +} +*/ + struct DeviceNode { QString interface; QString path;