[gnome-games/wip/exalm/desktop-in-flatpak: 61/64] desktop: Add DesktopTrackerAppInfo
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/desktop-in-flatpak: 61/64] desktop: Add DesktopTrackerAppInfo
- Date: Wed, 12 Sep 2018 11:55:39 +0000 (UTC)
commit c8a316b5b5fc9febdcf21215bcf1bd870b68f0b0
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Thu Aug 9 20:05:02 2018 +0500
desktop: Add DesktopTrackerAppInfo
This will allow to get desktop app metadata via tracker exclusively.
plugins/desktop/src/desktop-tracker-app-info.vala | 67 +++++++++++++++++++++++
plugins/desktop/src/meson.build | 1 +
2 files changed, 68 insertions(+)
---
diff --git a/plugins/desktop/src/desktop-tracker-app-info.vala
b/plugins/desktop/src/desktop-tracker-app-info.vala
new file mode 100644
index 00000000..d6702a36
--- /dev/null
+++ b/plugins/desktop/src/desktop-tracker-app-info.vala
@@ -0,0 +1,67 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+private class Games.DesktopTrackerAppInfo : Object {
+ private const string TRACKER_KEY_PREFIX_NFO =
"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#";
+ private const string TRACKER_KEY_PREFIX_NIE =
"http://www.semanticdesktop.org/ontologies/2007/01/19/nie#";
+ private const string TRACKER_KEY_CMDLINE = TRACKER_KEY_PREFIX_NFO + "softwareCmdLine";
+ private const string TRACKER_KEY_ICON = TRACKER_KEY_PREFIX_NFO + "softwareIcon";
+ private const string TRACKER_KEY_TITLE = TRACKER_KEY_PREFIX_NIE + "title";
+ private const string TRACKER_KEY_FILE_NAME = TRACKER_KEY_PREFIX_NFO + "fileName";
+ private const string TRACKER_KEY_CATEGORY = TRACKER_KEY_PREFIX_NIE + "isLogicalPartOf";
+
+ private TrackerMetadata metadata;
+
+ public DesktopTrackerAppInfo (Uri uri) throws Error {
+ var connection = Tracker.Sparql.Connection.@get ();
+ metadata = new TrackerMetadata (connection, uri);
+ }
+
+ public GLib.Icon? get_icon () {
+ var val = metadata.get_object (TRACKER_KEY_ICON);
+ var icon = val.replace ("urn:theme-icon:", "");
+
+ try {
+ return GLib.Icon.new_for_string (icon);
+ } catch (Error e) {
+ debug (e.message);
+ return null;
+ }
+ }
+
+ public string get_title () {
+ return metadata.get_object (TRACKER_KEY_TITLE);
+ }
+
+ public string get_filename () {
+ return metadata.get_object (TRACKER_KEY_FILE_NAME);
+ }
+
+ public string get_command () {
+ return metadata.get_object (TRACKER_KEY_CMDLINE);
+ }
+
+ public string[] get_categories () {
+ var categories = metadata.get_all_objects (TRACKER_KEY_CATEGORY);
+ string[] result = {};
+ foreach (var category in categories)
+ result += category.replace ("urn:software-category:", "");
+
+ return result;
+ }
+
+ public string get_executable () {
+ var cmdline = get_command ();
+ var args = cmdline.split(" ");
+
+ // FIXME
+ if (args[0].has_suffix ("flatpak")) {
+ var index = 1;
+ while (args[index].has_prefix ("-"))
+ index++;
+
+ return args[index];
+ }
+
+ return args[0];
+ }
+}
diff --git a/plugins/desktop/src/meson.build b/plugins/desktop/src/meson.build
index e139521e..0738dc78 100644
--- a/plugins/desktop/src/meson.build
+++ b/plugins/desktop/src/meson.build
@@ -3,6 +3,7 @@ vala_sources = [
'desktop-icon.vala',
'desktop-plugin.vala',
'desktop-title.vala',
+ 'desktop-tracker-app-info.vala',
'desktop-tracker-uri-query.vala',
'desktop-uid.vala',
]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]