Merge lp:~donadigo/slingshot/use-glib-desktop-app-info into lp:~elementary-pantheon/slingshot/trunk

Proposed by Adam Bieńkowski on 2017-01-02
Status: Merged
Approved by: Daniel Fore on 2017-01-03
Approved revision: 712
Merged at revision: 714
Proposed branch: lp:~donadigo/slingshot/use-glib-desktop-app-info
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 155 lines (+5/-109)
2 files modified
src/Backend/App.vala (+0/-96)
src/Widgets/AppEntry.vala (+5/-13)
To merge this branch: bzr merge lp:~donadigo/slingshot/use-glib-desktop-app-info
Reviewer Review Type Date Requested Status
Daniel Fore 2017-01-02 Approve on 2017-01-03
Review via email: mp+313972@code.launchpad.net

Commit message

* Use DesktopAppInfo instead of KeyFile

Description of the change

This branch fixes bug #1528720: "Use built-in GLib functions for Desktop files".

We don't need everything actions related in the App class since this is already implemented in DesktopAppInfo itself.

To post a comment you must log in.
Daniel Fore (danrabbit) wrote :

I can confirm that this works as expected. Nice cleanup :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Backend/App.vala'
2--- src/Backend/App.vala 2016-02-17 19:06:52 +0000
3+++ src/Backend/App.vala 2017-01-02 23:05:37 +0000
4@@ -52,8 +52,6 @@
5
6 public Synapse.Match? match { get; private set; default = null; }
7 public Synapse.Match? target { get; private set; default = null; }
8- public Gee.ArrayList<string> actions { get; private set; default = null; }
9- public Gee.HashMap<string, string> actions_map { get; private set; default = null; }
10
11 public signal void launched (App app);
12
13@@ -61,18 +59,6 @@
14 public signal void unity_update_info ();
15 #endif
16
17- // for FDO Desktop Actions
18- // see http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#extra-actions
19- private const string DESKTOP_ACTION_KEY = "Actions";
20- private const string DESKTOP_ACTION_GROUP_NAME = "Desktop Action %s";
21- // for the Unity static quicklists
22- // see https://wiki.edubuntu.org/Unity/LauncherAPI#Static_Quicklist_entries
23- private const string UNITY_QUICKLISTS_KEY = "X-Ayatana-Desktop-Shortcuts";
24- private const string UNITY_QUICKLISTS_SHORTCUT_GROUP_NAME = "%s Shortcut Group";
25- private const string UNITY_QUICKLISTS_TARGET_KEY = "TargetEnvironment";
26- private const string UNITY_QUICKLISTS_TARGET_VALUE = "Unity";
27- private const string[] SUPPORTED_GETTEXT_DOMAINS_KEYS = {"X-Ubuntu-Gettext-Domain", "X-GNOME-Gettext-Domain"};
28-
29 public App (GMenu.TreeEntry entry) {
30 app_type = AppType.APP;
31
32@@ -160,88 +146,6 @@
33 return true;
34 }
35
36- // Quicklist code from Plank
37- public void init_actions () throws KeyFileError {
38- actions = new Gee.ArrayList<string> ();
39- actions_map = new Gee.HashMap<string, string> ();
40-
41- // get FDO Desktop Actions
42- // see http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#extra-actions
43- // get the Unity static quicklists
44- // see https://wiki.edubuntu.org/Unity/LauncherAPI#Static Quicklist entries
45- KeyFile file;
46- try {
47- file = new KeyFile ();
48- file.load_from_file (desktop_path, 0);
49- } catch (Error e) {
50- critical ("%s: %s", desktop_path, e.message);
51- }
52-
53- string? textdomain = null;
54- foreach (var domain_key in SUPPORTED_GETTEXT_DOMAINS_KEYS)
55- if (file.has_key (KeyFileDesktop.GROUP, domain_key)) {
56- textdomain = file.get_string (KeyFileDesktop.GROUP, domain_key);
57- break;
58- }
59- if (actions != null && actions_map != null) {
60- actions.clear ();
61- actions_map.clear ();
62- string[] keys = {DESKTOP_ACTION_KEY, UNITY_QUICKLISTS_KEY};
63-
64- foreach (var key in keys) {
65- if (!file.has_key (KeyFileDesktop.GROUP, key))
66- continue;
67-
68- foreach (var action in file.get_string_list (KeyFileDesktop.GROUP, key)) {
69- var group = DESKTOP_ACTION_GROUP_NAME.printf (action);
70- if (!file.has_group (group)) {
71- group = UNITY_QUICKLISTS_SHORTCUT_GROUP_NAME.printf (action);
72- if (!file.has_group (group))
73- continue;
74- }
75-
76- // check for TargetEnvironment
77- if (file.has_key (group, UNITY_QUICKLISTS_TARGET_KEY)) {
78- var target = file.get_string (group, UNITY_QUICKLISTS_TARGET_KEY);
79- if (target != UNITY_QUICKLISTS_TARGET_VALUE)
80- continue;
81- }
82-
83- // check for OnlyShowIn
84- if (file.has_key (group, KeyFileDesktop.KEY_ONLY_SHOW_IN)) {
85- var found = false;
86-
87- foreach (var s in file.get_string_list (group, KeyFileDesktop.KEY_ONLY_SHOW_IN))
88- if (s == UNITY_QUICKLISTS_TARGET_VALUE) {
89- found = true;
90- break;
91- }
92-
93- if (!found)
94- continue;
95- }
96-
97- var action_name = file.get_locale_string (group, KeyFileDesktop.KEY_NAME);
98-
99- var action_icon = "";
100- if (file.has_key (group, KeyFileDesktop.KEY_ICON))
101- action_icon = file.get_locale_string (group, KeyFileDesktop.KEY_ICON);
102-
103- var action_exec = "";
104- if (file.has_key (group, KeyFileDesktop.KEY_EXEC))
105- action_exec = file.get_string (group, KeyFileDesktop.KEY_EXEC);
106-
107- // apply given gettext-domain if available
108- if (textdomain != null)
109- action_name = GLib.dgettext (textdomain, action_name).dup ();
110-
111- actions.add (action_name);
112- actions_map.set (action_name, "%s;;%s".printf (action_exec, action_icon));
113- }
114- }
115- }
116- }
117-
118 #if HAS_PLANK_0_11
119 public void perform_unity_update (string sender_name, VariantIter prop_iter) {
120 unity_sender_name = sender_name;
121
122=== modified file 'src/Widgets/AppEntry.vala'
123--- src/Widgets/AppEntry.vala 2016-12-27 21:08:33 +0000
124+++ src/Widgets/AppEntry.vala 2017-01-02 23:05:37 +0000
125@@ -191,25 +191,17 @@
126 #endif
127
128 private void create_menu () {
129- // Display the apps static quicklist items in a popover menu
130- if (application.actions == null) {
131- try {
132- application.init_actions ();
133- } catch (KeyFileError e) {
134- critical ("%s: %s", desktop_path, e.message);
135- }
136- }
137-
138 menu = new Gtk.Menu ();
139
140- foreach (var action in application.actions) {
141- var menuitem = new Gtk.MenuItem.with_mnemonic (action);
142+ var app_info = new DesktopAppInfo (desktop_id);
143+ foreach (unowned string _action in app_info.list_actions ()) {
144+ string action = _action.dup ();
145+ var menuitem = new Gtk.MenuItem.with_mnemonic (app_info.get_action_name (action));
146 menu.add (menuitem);
147
148 menuitem.activate.connect (() => {
149 try {
150- var values = application.actions_map.get (action).split (";;");
151- AppInfo.create_from_commandline (values[0], null, AppInfoCreateFlags.NONE).launch (null, null);
152+ app_info.launch_action (action, new AppLaunchContext ());
153 app_launched ();
154 } catch (Error e) {
155 critical ("%s: %s", desktop_path, e.message);

Subscribers

People subscribed via source and target branches