diff options
author | Mavridis Philippe <mavridisf@gmail.com> | 2024-07-08 18:58:28 +0300 |
---|---|---|
committer | Mavridis Philippe <mavridisf@gmail.com> | 2024-07-08 18:59:14 +0300 |
commit | a5eb53fcbc12342f0a12ef4819146b2d0bb14652 (patch) | |
tree | 0d7bd718644ded44e69b6a6102173d699131c0b2 /src/util.cpp | |
parent | 87769ed51d8087ddc4a02705f39fe4f21431b66f (diff) | |
download | xdg-desktop-portal-tde-a5eb53fcbc12342f0a12ef4819146b2d0bb14652.tar.gz xdg-desktop-portal-tde-a5eb53fcbc12342f0a12ef4819146b2d0bb14652.zip |
Added Account portal, permission dialog class, moved some code to util
Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/util.cpp b/src/util.cpp index 7474fa1..4975663 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -19,12 +19,66 @@ Improvements and feedback are welcome! *******************************************************************************/ +// TQt +#include <tqfileinfo.h> + // TDE +#include <kservice.h> #include <kdebug.h> // Portal #include "util.h" +WId parse_window_id(const TQString data) +{ + if (!data.startsWith("x11:")) + { + kdWarning() << "[FileChooser] Window Identifiers are currently only " + << "supported for X11. Created dialog will be parentless." + << endl; + return 0; + } + + bool ok; + WId wid = data.mid(4).toInt(&ok, 16); + return ok ? wid : 0; +} + +ApplicationInfo application_info_from_wid(WId wid) +{ + ApplicationInfo app; + if (wid) + { + // we need to get the pid but only deprecated KWin::Info has it + KWin::Info info = KWin::info(wid); + TQFileInfo fi(TQString("/proc/%1/exe").arg(info.pid)); + if (fi.exists() && fi.isSymLink()) { + fi = TQFileInfo(fi.readLink()); + + app.path = fi.filePath(); + + // try to find corresponding desktop file + KService::List all = KService::allServices(); + KService::List::ConstIterator svc; + for (svc = all.begin(); svc != all.end(); ++svc) { + TQString exec((*svc)->exec()); + if (exec.startsWith(fi.filePath()) || + exec.startsWith(fi.fileName())) + { + app.desktopFile = (*svc)->desktopEntryPath(); + app.name = (*svc)->name(); + break; + } + } + + // Last resort + if (app.name.isEmpty()) + app.name = fi.fileName(); + } + } + return app; +} + bool check_variant(TQT_DBusVariant variant, TQString signature) { return !variant.signature.isNull() && variant.signature == signature; |