summaryrefslogtreecommitdiffstats
path: root/src/util.cpp
diff options
context:
space:
mode:
authorMavridis Philippe <[email protected]>2024-07-08 01:04:09 +0300
committerMavridis Philippe <[email protected]>2024-07-08 01:05:01 +0300
commit87769ed51d8087ddc4a02705f39fe4f21431b66f (patch)
treecf3d12a293a24868641d8c086206da87e3c57ed3 /src/util.cpp
parentc7b0c7b88c1bebb038bd70f4995fc35771fa83c0 (diff)
downloadxdg-desktop-portal-tde-87769ed51d8087ddc4a02705f39fe4f21431b66f.tar.gz
xdg-desktop-portal-tde-87769ed51d8087ddc4a02705f39fe4f21431b66f.zip
Added Email interface, minor refactoring
Signed-off-by: Mavridis Philippe <[email protected]>
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/util.cpp b/src/util.cpp
new file mode 100644
index 0000000..7474fa1
--- /dev/null
+++ b/src/util.cpp
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ XDG desktop portal implementation for TDE
+ Copyright © 2024 Mavridis Philippe <[email protected]>
+
+ This program or library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the License,
+ or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ Improvements and feedback are welcome!
+*******************************************************************************/
+
+// TDE
+#include <kdebug.h>
+
+// Portal
+#include "util.h"
+
+bool check_variant(TQT_DBusVariant variant, TQString signature)
+{
+ return !variant.signature.isNull() && variant.signature == signature;
+}
+
+TQString bytelist_to_string(TQT_DBusDataList list)
+{
+ if (list.type() != TQT_DBusData::Byte) return TQString::null;
+ TQCString bytes;
+ TQValueList<TQ_UINT8> vl = list.toByteList();
+ TQValueList<TQ_UINT8>::iterator vlit;
+ for (vlit = vl.begin(); vlit != vl.end(); ++vlit)
+ {
+ bytes += (*vlit);
+ }
+ return TQString::fromLocal8Bit(bytes.data(), bytes.size());
+}
+
+TQT_DBusDataList string_to_bytelist(TQString str)
+{
+ TQCString bytes = str.latin1();
+ TQValueList<TQ_UINT8> vl;
+ char *bit;
+ for (bit = bytes.begin(); bit != bytes.end(); ++bit)
+ {
+ vl << (TQ_UINT8)(*bit);
+ }
+ return TQT_DBusDataList(vl);
+}
+
+TQT_DBusDataList kurl_list_to_datalist(KURL::List urls)
+{
+ return TQT_DBusDataList(urls.toStringList());
+}
+
+bool make_variant(TQVariant variant, TQT_DBusVariant &other)
+{
+ TQString signature;
+ switch (variant.type()) {
+ case TQVariant::String:
+ case TQVariant::Color:
+ case TQVariant::Font:
+ case TQVariant::Date:
+ case TQVariant::DateTime:
+ case TQVariant::Time:
+ case TQVariant::KeySequence:
+ other.signature = "s";
+ other.value = TQT_DBusData::fromString(variant.toString());
+ break;
+
+ case TQVariant::Int:
+ other.signature = "i";
+ other.value = TQT_DBusData::fromInt32(variant.toInt());
+ break;
+
+ case TQVariant::UInt:
+ other.signature = "u";
+ other.value = TQT_DBusData::fromUInt32(variant.toUInt());
+ break;
+
+ case TQVariant::Double:
+ case TQVariant::LongLong:
+ case TQVariant::ULongLong:
+ other.signature = "d";
+ other.value = TQT_DBusData::fromDouble(variant.toDouble());
+ break;
+
+ case TQVariant::Bool:
+ other.signature = "b";
+ other.value = TQT_DBusData::fromBool(variant.toBool());
+ break;
+
+ case TQVariant::StringList:
+ other.signature = "as";
+ other.value = TQT_DBusData::fromList(TQT_DBusDataList(variant.toStringList()));
+ break;
+
+ default:
+ if (variant.canCast(TQVariant::String)) {
+ other.signature = "s";
+ other.value = TQT_DBusData::fromString(variant.toString());
+ }
+ else {
+ kdDebug() << "Cannot cast TQVariant of type " << variant.type()
+ << "to TQT_DBusVariant!" << endl;
+ return false;
+ }
+ }
+ return true;
+} \ No newline at end of file