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

Proposed by Adam Bieńkowski
Status: Merged
Approved by: Danielle Foré
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
Danielle Foré Approve
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.
Revision history for this message
Danielle Foré (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
=== modified file 'src/Backend/App.vala'
--- src/Backend/App.vala 2016-02-17 19:06:52 +0000
+++ src/Backend/App.vala 2017-01-02 23:05:37 +0000
@@ -52,8 +52,6 @@
5252
53 public Synapse.Match? match { get; private set; default = null; }53 public Synapse.Match? match { get; private set; default = null; }
54 public Synapse.Match? target { get; private set; default = null; }54 public Synapse.Match? target { get; private set; default = null; }
55 public Gee.ArrayList<string> actions { get; private set; default = null; }
56 public Gee.HashMap<string, string> actions_map { get; private set; default = null; }
5755
58 public signal void launched (App app);56 public signal void launched (App app);
5957
@@ -61,18 +59,6 @@
61 public signal void unity_update_info ();59 public signal void unity_update_info ();
62#endif60#endif
6361
64 // for FDO Desktop Actions
65 // see http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#extra-actions
66 private const string DESKTOP_ACTION_KEY = "Actions";
67 private const string DESKTOP_ACTION_GROUP_NAME = "Desktop Action %s";
68 // for the Unity static quicklists
69 // see https://wiki.edubuntu.org/Unity/LauncherAPI#Static_Quicklist_entries
70 private const string UNITY_QUICKLISTS_KEY = "X-Ayatana-Desktop-Shortcuts";
71 private const string UNITY_QUICKLISTS_SHORTCUT_GROUP_NAME = "%s Shortcut Group";
72 private const string UNITY_QUICKLISTS_TARGET_KEY = "TargetEnvironment";
73 private const string UNITY_QUICKLISTS_TARGET_VALUE = "Unity";
74 private const string[] SUPPORTED_GETTEXT_DOMAINS_KEYS = {"X-Ubuntu-Gettext-Domain", "X-GNOME-Gettext-Domain"};
75
76 public App (GMenu.TreeEntry entry) {62 public App (GMenu.TreeEntry entry) {
77 app_type = AppType.APP;63 app_type = AppType.APP;
7864
@@ -160,88 +146,6 @@
160 return true;146 return true;
161 }147 }
162148
163 // Quicklist code from Plank
164 public void init_actions () throws KeyFileError {
165 actions = new Gee.ArrayList<string> ();
166 actions_map = new Gee.HashMap<string, string> ();
167
168 // get FDO Desktop Actions
169 // see http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#extra-actions
170 // get the Unity static quicklists
171 // see https://wiki.edubuntu.org/Unity/LauncherAPI#Static Quicklist entries
172 KeyFile file;
173 try {
174 file = new KeyFile ();
175 file.load_from_file (desktop_path, 0);
176 } catch (Error e) {
177 critical ("%s: %s", desktop_path, e.message);
178 }
179
180 string? textdomain = null;
181 foreach (var domain_key in SUPPORTED_GETTEXT_DOMAINS_KEYS)
182 if (file.has_key (KeyFileDesktop.GROUP, domain_key)) {
183 textdomain = file.get_string (KeyFileDesktop.GROUP, domain_key);
184 break;
185 }
186 if (actions != null && actions_map != null) {
187 actions.clear ();
188 actions_map.clear ();
189 string[] keys = {DESKTOP_ACTION_KEY, UNITY_QUICKLISTS_KEY};
190
191 foreach (var key in keys) {
192 if (!file.has_key (KeyFileDesktop.GROUP, key))
193 continue;
194
195 foreach (var action in file.get_string_list (KeyFileDesktop.GROUP, key)) {
196 var group = DESKTOP_ACTION_GROUP_NAME.printf (action);
197 if (!file.has_group (group)) {
198 group = UNITY_QUICKLISTS_SHORTCUT_GROUP_NAME.printf (action);
199 if (!file.has_group (group))
200 continue;
201 }
202
203 // check for TargetEnvironment
204 if (file.has_key (group, UNITY_QUICKLISTS_TARGET_KEY)) {
205 var target = file.get_string (group, UNITY_QUICKLISTS_TARGET_KEY);
206 if (target != UNITY_QUICKLISTS_TARGET_VALUE)
207 continue;
208 }
209
210 // check for OnlyShowIn
211 if (file.has_key (group, KeyFileDesktop.KEY_ONLY_SHOW_IN)) {
212 var found = false;
213
214 foreach (var s in file.get_string_list (group, KeyFileDesktop.KEY_ONLY_SHOW_IN))
215 if (s == UNITY_QUICKLISTS_TARGET_VALUE) {
216 found = true;
217 break;
218 }
219
220 if (!found)
221 continue;
222 }
223
224 var action_name = file.get_locale_string (group, KeyFileDesktop.KEY_NAME);
225
226 var action_icon = "";
227 if (file.has_key (group, KeyFileDesktop.KEY_ICON))
228 action_icon = file.get_locale_string (group, KeyFileDesktop.KEY_ICON);
229
230 var action_exec = "";
231 if (file.has_key (group, KeyFileDesktop.KEY_EXEC))
232 action_exec = file.get_string (group, KeyFileDesktop.KEY_EXEC);
233
234 // apply given gettext-domain if available
235 if (textdomain != null)
236 action_name = GLib.dgettext (textdomain, action_name).dup ();
237
238 actions.add (action_name);
239 actions_map.set (action_name, "%s;;%s".printf (action_exec, action_icon));
240 }
241 }
242 }
243 }
244
245#if HAS_PLANK_0_11149#if HAS_PLANK_0_11
246 public void perform_unity_update (string sender_name, VariantIter prop_iter) {150 public void perform_unity_update (string sender_name, VariantIter prop_iter) {
247 unity_sender_name = sender_name;151 unity_sender_name = sender_name;
248152
=== modified file 'src/Widgets/AppEntry.vala'
--- src/Widgets/AppEntry.vala 2016-12-27 21:08:33 +0000
+++ src/Widgets/AppEntry.vala 2017-01-02 23:05:37 +0000
@@ -191,25 +191,17 @@
191#endif191#endif
192192
193 private void create_menu () {193 private void create_menu () {
194 // Display the apps static quicklist items in a popover menu
195 if (application.actions == null) {
196 try {
197 application.init_actions ();
198 } catch (KeyFileError e) {
199 critical ("%s: %s", desktop_path, e.message);
200 }
201 }
202
203 menu = new Gtk.Menu ();194 menu = new Gtk.Menu ();
204195
205 foreach (var action in application.actions) {196 var app_info = new DesktopAppInfo (desktop_id);
206 var menuitem = new Gtk.MenuItem.with_mnemonic (action);197 foreach (unowned string _action in app_info.list_actions ()) {
198 string action = _action.dup ();
199 var menuitem = new Gtk.MenuItem.with_mnemonic (app_info.get_action_name (action));
207 menu.add (menuitem);200 menu.add (menuitem);
208201
209 menuitem.activate.connect (() => {202 menuitem.activate.connect (() => {
210 try {203 try {
211 var values = application.actions_map.get (action).split (";;");204 app_info.launch_action (action, new AppLaunchContext ());
212 AppInfo.create_from_commandline (values[0], null, AppInfoCreateFlags.NONE).launch (null, null);
213 app_launched ();205 app_launched ();
214 } catch (Error e) {206 } catch (Error e) {
215 critical ("%s: %s", desktop_path, e.message);207 critical ("%s: %s", desktop_path, e.message);

Subscribers

People subscribed via source and target branches