Merge lp:~jeremy-munsch/synapse-project/desktop-file-actions into lp:synapse-project

Proposed by Jeremy Munsch
Status: Merged
Merge reported by: Rico Tzschichholz
Merged at revision: not available
Proposed branch: lp:~jeremy-munsch/synapse-project/desktop-file-actions
Merge into: lp:synapse-project
Diff against target: 176 lines (+92/-19)
2 files modified
src/core/desktop-file-service.vala (+3/-0)
src/plugins/desktop-file-plugin.vala (+89/-19)
To merge this branch: bzr merge lp:~jeremy-munsch/synapse-project/desktop-file-actions
Reviewer Review Type Date Requested Status
Rico Tzschichholz Approve
Review via email: mp+273319@code.launchpad.net

Description of the change

Update Desktop File service and Desktop File Plugin to provide applications actions

To post a comment you must log in.
Revision history for this message
Rico Tzschichholz (ricotz) wrote :

Looks reasonable, but find_for_match() could use some more thinking to avoid this if-else-hell ;-)

Another issue here is the hidden bump to glib >= 2.38 (g_desktop_app_info_launch_action)

review: Needs Information
Revision history for this message
Rico Tzschichholz (ricotz) wrote :

Personally I am not a fan of the current code-style of synapse. Enclosing single-line scopes with brackets is overkill and just clutters the source. Similar thing with omitting a line-break for some single-if-statements.

Revision history for this message
Rico Tzschichholz (ricotz) wrote :

Would be nice to state the relation of this source to
https://code.launchpad.net/~donadigo/slingshot/search-quicklist/+merge/271755

review: Needs Information
Revision history for this message
Jeremy Munsch (jeremy-munsch) wrote :

Argh, dammit for the bump, wish some more info on versions could be provided on http://valadoc.org.
I guess this needs a workaround.
I'll try to make things cleaner on find_for_match.
As for you last comment about stating the relation of this source to the link provided, i am not sure to understand what you meant.
But i had a quick look i think the linked source is also adding the ability to search any action of any app, whereas this patch only add applications actions to their respective alternative panel.

I'll have a quick look tomorrow. I made a push with some code cleaning following your recommendations i believe.

Also i believe that i should not follow entirely the overall coding style of elementary-codestyle. I'm asking because the newbie that i am is a bit lost on that.

Revision history for this message
Rico Tzschichholz (ricotz) wrote :

> Argh, dammit for the bump, wish some more info on versions could be provided
> on http://valadoc.org.

Simply use devhelp which shows you versions besides nice documentations.

> I guess this needs a workaround.

I am not totally opposed to bump the glib requirements to 2.40.

> I'll try to make things cleaner on find_for_match.
> As for you last comment about stating the relation of this source to the link
> provided, i am not sure to understand what you meant.
> But i had a quick look i think the linked source is also adding the ability to
> search any action of any app, whereas this patch only add applications actions
> to their respective alternative panel.

You linked to the bug, so it is hard to believe you didnt notice the other merge-proposal. I just want to know if your work is based on it while using some parts. In this case you should reference it and mention its author.

> I'll have a quick look tomorrow. I made a push with some code cleaning
> following your recommendations i believe.

Do not touch code-parts which you didnt change. And if-else-clauses are either fully wrapped in brackets or none. So don't mix that.

> Also i believe that i should not follow entirely the overall coding style of
> elementary-codestyle. I'm asking because the newbie that i am is a bit lost on
> that.

Synapse has nothing to do with elementary so do not apply their codestyle in any way.

Revision history for this message
Jeremy Munsch (jeremy-munsch) wrote :

As for GLib, the bump would only leave precise (12.04LTS) unsupported since it is distributed with GLib 2.32.4. I only check Ubuntu because i believe the edge ppa of synapse has only releases to this distribution.

I used no code of the related commit, I originally linked the bug because that is the reason i made this fix and i got a mail notice of the bug.

I make my contributions on Synapse mostly by mimicking the original code for doing what i want since i'm definitely not a Vala expert. But i'll make sure if i use another code to make appropriate link to the original author.

Thank you for the devhelp tip, i'll use this from now :)

So what i'm going to fix are:
coding style for things I'have changed
cleaning find_for_match code

Revision history for this message
Jeremy Munsch (jeremy-munsch) wrote :

Hey just bumping the thread in case you have time to review, decided whether a bump for glib / merge is possibly going to happen.

Revision history for this message
Rico Tzschichholz (ricotz) wrote :

I have taken a look and came up with a bunch of changes
  https://paste.debian.net/plain/329998

DesktopActions can be translated so the user should see the translated string in the ui.

Why did you drop this?
  /* If there's more than one application, fill the ow list */
  if (list_for_mimetype.size > 1)

review: Needs Fixing
Revision history for this message
Rico Tzschichholz (ricotz) wrote :

Do not change the codestyle and alter unrelated parts.

If really needed then such cleaning should be done in a separate task while not changing any behavior.

Revision history for this message
Jeremy Munsch (jeremy-munsch) wrote :

Ok, i understand your point, though it would have been more readable.
So i updated from your patch made a small fix, and added tranlations by using GLib.DesktopAppInfo.get_action_name.

As for
  /* If there's more than one application, fill the ow list */
  if (list_for_mimetype.size > 1)

I removed it because, whitout your recommendations, i felt like it was non sense to not display the option for the only program that can open the file type. But, yes, i should not have done that. It is just hard to not touch things when you fell it could be improved, never mind though.

Revision history for this message
Rico Tzschichholz (ricotz) wrote :

https://paste.debian.net/plain/330250

* Don't add those verbose outputs.
* No need to do "actions_map[app_match.filename]" three times. (I already removed that in my first patch)

review: Needs Fixing
Revision history for this message
Jeremy Munsch (jeremy-munsch) wrote :

I just applied the patch and pushed, nothing else.

Revision history for this message
Rico Tzschichholz (ricotz) wrote :

Look fine now. I will keep that in the queue until I thought about dropping support for Precise/12.04

review: Approve
614. By Jeremy Munsch

desktop-file-service: add desktop file actions gathering
desktop-file-plugin :
  add new action OpenAppAction with supported translations for display actions
  add ApplicationMatch handler in find_for_match

Revision history for this message
Jeremy Munsch (jeremy-munsch) wrote :

I just made very small changes where thing were done wrong:
http://paste.ubuntu.com/13265410/

Also i found a bug with ChromePlugin that makes exceptions in desktop files actions.
The problem is ChromePlugin extends UriMatch without assigning uri properly.
It still seems to be working, however i will make a PR to make proper corrections to ChromePlugin.

I hope I'm not harassing you Rico, i know you have a tons of other projects to maintain to have time to spend in here, and on my noobish mystakes, since you seem to be the only maintainer left active.
If you feel that i'm making too much changes that are not necessary, please tell me.
I wish to contribute to this software even it seems pretty dead (no offence i have to say you're doing great job maintaining this), how ever if this is inappropriate, i can stop contributing to this project. I'm just not sure if these are welcome.

Best regards.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/core/desktop-file-service.vala'
2--- src/core/desktop-file-service.vala 2015-07-23 08:18:50 +0000
3+++ src/core/desktop-file-service.vala 2015-11-14 18:39:51 +0000
4@@ -91,6 +91,7 @@
5 public bool is_hidden { get; private set; default = false; }
6 public bool is_valid { get; private set; default = true; }
7
8+ public string[] actions = null;
9 public string[] mime_types = null;
10
11 private string? name_folded = null;
12@@ -179,6 +180,8 @@
13 KeyFileDesktop.KEY_NOT_SHOW_IN));
14 show_in = DesktopEnvironmentType.ALL ^ not_show;
15 }
16+ if (keyfile.has_key (KeyFileDesktop.GROUP, KeyFileDesktop.KEY_ACTIONS))
17+ actions = keyfile.get_string_list (KeyFileDesktop.GROUP, KeyFileDesktop.KEY_ACTIONS);
18
19 // special case these, people are using them quite often and wonder
20 // why they don't appear
21
22=== modified file 'src/plugins/desktop-file-plugin.vala'
23--- src/plugins/desktop-file-plugin.vala 2014-07-10 11:39:28 +0000
24+++ src/plugins/desktop-file-plugin.vala 2015-11-14 18:39:51 +0000
25@@ -84,6 +84,7 @@
26 {
27 desktop_files = new Gee.ArrayList<DesktopFileMatch> ();
28 mimetype_map = new Gee.HashMap<string, OpenWithAction> ();
29+ actions_map = new Gee.HashMap<string, OpenAppAction> ();
30
31 var dfs = DesktopFileService.get_default ();
32 dfs.reload_started.connect (() => {
33@@ -244,7 +245,8 @@
34 var app_info = new DesktopAppInfo.from_filename (desktop_info.filename);
35 List<File> files = new List<File> ();
36 files.prepend (f);
37- app_info.launch (files, null);
38+ var display = Gdk.Display.get_default ();
39+ app_info.launch (files, display.get_app_launch_context ());
40 }
41 catch (Error err)
42 {
43@@ -258,39 +260,107 @@
44 }
45 }
46
47+ private class OpenAppAction : Action
48+ {
49+ public DesktopFileInfo desktop_info { get; construct; }
50+ public string action { get; construct; }
51+
52+ DesktopAppInfo app_info;
53+
54+ public OpenAppAction (DesktopFileInfo info, string action)
55+ {
56+ Object (desktop_info : info, action : action);
57+ }
58+
59+ construct
60+ {
61+ app_info = new DesktopAppInfo.from_filename (desktop_info.filename);
62+ var display_action = app_info.get_action_name (action);
63+ title = display_action;
64+ icon_name = desktop_info.icon_name;
65+ description = _("Launch action '%s'").printf (display_action);
66+ }
67+
68+ public override void do_execute (Match match, Match? target = null)
69+ {
70+ var display = Gdk.Display.get_default ();
71+ app_info.launch_action (action, display.get_app_launch_context ());
72+ RelevancyService.get_default ().application_launched (app_info);
73+ }
74+
75+ public override bool valid_for_match (Match match)
76+ {
77+ return (match is ApplicationMatch);
78+ }
79+ }
80+
81 private Gee.Map<string, Gee.List<OpenWithAction>> mimetype_map;
82+ private Gee.Map<string, Gee.List<OpenAppAction>> actions_map;
83
84 public ResultSet? find_for_match (ref Query query, Match match)
85 {
86- unowned UriMatch? uri_match = match as UriMatch;
87- if (uri_match == null || uri_match.mime_type == null) return null;
88+ unowned UriMatch? uri_match = null;
89+ unowned ApplicationMatch? app_match = null;
90+ Gee.List<Action>? any_list = null;
91
92- Gee.List<OpenWithAction> ow_list = mimetype_map[uri_match.mime_type];
93- /* Query DesktopFileService only if is necessary */
94- if (ow_list == null)
95+ if ((uri_match = match as UriMatch) != null)
96 {
97- /* Initialize ow_list */
98- ow_list = new Gee.LinkedList<OpenWithAction> ();
99- mimetype_map[uri_match.mime_type] = ow_list;
100 var dfs = DesktopFileService.get_default ();
101 var list_for_mimetype = dfs.get_desktop_files_for_type (uri_match.mime_type);
102 /* If there's more than one application, fill the ow list */
103 if (list_for_mimetype.size > 1)
104 {
105- foreach (var entry in list_for_mimetype)
106- {
107- ow_list.add (new OpenWithAction (entry));
108- }
109- }
110- else return null;
111- }
112- else if (ow_list.size == 0) return null;
113+ /* Query DesktopFileService only if is necessary */
114+ Gee.List<OpenWithAction>? ow_list = mimetype_map[uri_match.mime_type];
115+ if (ow_list == null)
116+ {
117+ ow_list = new Gee.LinkedList<OpenWithAction> ();
118+ mimetype_map[uri_match.mime_type] = ow_list;
119+
120+ foreach (var entry in list_for_mimetype)
121+ {
122+ ow_list.add (new OpenWithAction (entry));
123+ }
124+ }
125+
126+ any_list = ow_list;
127+ }
128+ }
129+ else if ((app_match = match as ApplicationMatch) != null)
130+ {
131+ Gee.List<OpenAppAction>? oa_list = actions_map[app_match.filename];
132+ if (oa_list == null)
133+ {
134+ oa_list = new Gee.LinkedList<OpenAppAction> ();
135+ actions_map[app_match.filename] = oa_list;
136+
137+ var dfs = DesktopFileService.get_default ();
138+ var desktop_file_info = dfs.get_desktop_file_for_id (Path.get_basename (app_match.filename));
139+
140+ /* There should at a result here */
141+ if (desktop_file_info != null)
142+ {
143+ foreach (var action in desktop_file_info.actions)
144+ {
145+ oa_list.add (new OpenAppAction (desktop_file_info, action));
146+ }
147+ }
148+ else
149+ {
150+ warning ("No DesktopInfoFile for %s", app_match.filename);
151+ }
152+ }
153+
154+ any_list = oa_list;
155+ }
156+
157+ if (any_list == null || any_list.size == 0) return null;
158
159 var rs = new ResultSet ();
160
161 if (query.query_string == "")
162 {
163- foreach (var action in ow_list)
164+ foreach (var action in any_list)
165 {
166 rs.add (action, MatchScore.POOR);
167 }
168@@ -299,7 +369,7 @@
169 {
170 var matchers = Query.get_matchers_for_query (query.query_string, 0,
171 RegexCompileFlags.OPTIMIZE | RegexCompileFlags.CASELESS);
172- foreach (var action in ow_list)
173+ foreach (var action in any_list)
174 {
175 foreach (var matcher in matchers)
176 {