Merge lp:~alecu/unity-scope-click/prevent-non-removable into lp:unity-scope-click

Proposed by Alejandro J. Cura
Status: Merged
Approved by: Alejandro J. Cura
Approved revision: 62
Merged at revision: 63
Proposed branch: lp:~alecu/unity-scope-click/prevent-non-removable
Merge into: lp:unity-scope-click
Diff against target: 84 lines (+30/-5)
2 files modified
src/click-interface.vala (+24/-1)
src/click-scope.vala (+6/-4)
To merge this branch: bzr merge lp:~alecu/unity-scope-click/prevent-non-removable
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
dobey (community) Approve
Review via email: mp+188616@code.launchpad.net

Commit message

Don't show Uninstall button if manifest has _removable:0, and remove pin-to-launcher

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

48 + // Pin to launcher is descoped for 13.10
49 + //preview.add_action (new Unity.PreviewAction (ACTION_PIN_TO_LAUNCHER, ("Pin to launcher"), null));

It's better to just delete code, rather than commenting it out. We have a great version control system, and can easily find old code if necessary. And if/when we add something back, it could be done in a completely different way, necessitating the removal of the commented code, anyway.

review: Needs Fixing
62. By Alejandro J. Cura

remove commented code, better handle manifest errors

Revision history for this message
dobey (dobey) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/click-interface.vala'
2--- src/click-interface.vala 2013-09-26 12:54:37 +0000
3+++ src/click-interface.vala 2013-10-01 15:29:32 +0000
4@@ -21,7 +21,6 @@
5
6 public class ClickInterface : GLib.Object {
7 const string ARG_DESKTOP_FILE_HINT = "--desktop_file_hint";
8- delegate void ProcessManifestFunc (Json.Object manifest);
9
10 public string get_click_id (string full_app_id) {
11 return full_app_id.split("_")[0];
12@@ -110,6 +109,30 @@
13 throw new ClickError.EXEC_FAILURE(msg);
14 }
15
16+ public async bool can_uninstall (string app_id) {
17+ const string REMOVABLE_FIELD = "_removable";
18+ GLib.List<weak Json.Node> manifests;
19+ try {
20+ manifests = yield get_manifests();
21+ } catch (ClickError e) {
22+ debug ("Can't get _removable for %s, ignoring", app_id);
23+ return true;
24+ }
25+ foreach (var element in manifests) {
26+ var manifest = element.get_object();
27+ var pkg_name = manifest.get_string_member("name");
28+ if (pkg_name == app_id) {
29+ if (manifest.has_member(REMOVABLE_FIELD)) {
30+ var removable = manifest.get_int_member(REMOVABLE_FIELD);
31+ return removable != 0;
32+ } else {
33+ return true;
34+ }
35+ }
36+ }
37+ return true;
38+ }
39+
40 public async void uninstall (string app_id) throws ClickError {
41 string version = null;
42 try {
43
44=== modified file 'src/click-scope.vala'
45--- src/click-scope.vala 2013-09-30 20:39:27 +0000
46+++ src/click-scope.vala 2013-10-01 15:29:32 +0000
47@@ -69,6 +69,8 @@
48 const string LABEL_REVIEWS = "Reviews";
49 const string LABEL_COMMENTS = "Comments";
50
51+ ClickInterface click_if = new ClickInterface ();
52+
53 public ClickScope ()
54 {
55 }
56@@ -111,8 +113,10 @@
57 async Unity.Preview build_installed_preview (string app_id, string application_uri) {
58 Unity.Preview preview = yield build_app_preview (app_id);
59 preview.add_action (new Unity.PreviewAction (ACTION_OPEN_CLICK + ":" + application_uri, ("Open"), null));
60- preview.add_action (new Unity.PreviewAction (ACTION_PIN_TO_LAUNCHER, ("Pin to launcher"), null));
61- preview.add_action (new Unity.PreviewAction (ACTION_UNINSTALL_CLICK, ("Uninstall"), null));
62+
63+ if (yield click_if.can_uninstall (app_id)) {
64+ preview.add_action (new Unity.PreviewAction (ACTION_UNINSTALL_CLICK, ("Uninstall"), null));
65+ }
66 return preview;
67 }
68
69@@ -153,7 +157,6 @@
70 } else if (action_id == ACTION_DOWNLOAD_COMPLETED) {
71 results_invalidated(Unity.SearchType.GLOBAL);
72 results_invalidated(Unity.SearchType.DEFAULT);
73- var click_if = new ClickInterface ();
74 var dotdesktop = yield click_if.get_dotdesktop(app_id);
75 // application name *must* be in path part of URL as host part
76 // might get lowercased
77@@ -164,7 +167,6 @@
78 debug ("Let the dash launch the app: %s", application_uri);
79 return new Unity.ActivationResponse(Unity.HandledType.NOT_HANDLED, application_uri);
80 } else if (action_id == ACTION_UNINSTALL_CLICK) {
81- var click_if = new ClickInterface ();
82 yield click_if.uninstall(app_id);
83 results_invalidated(Unity.SearchType.GLOBAL);
84 results_invalidated(Unity.SearchType.DEFAULT);

Subscribers

People subscribed via source and target branches