Merge lp:~donadigo/slingshot/uninstall-apps into lp:~elementary-pantheon/slingshot/trunk

Proposed by Adam Bieńkowski on 2016-12-29
Status: Work in progress
Proposed branch: lp:~donadigo/slingshot/uninstall-apps
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 117 lines (+49/-2)
3 files modified
CMakeLists.txt (+1/-1)
src/CMakeLists.txt (+1/-0)
src/Widgets/AppEntry.vala (+47/-1)
To merge this branch: bzr merge lp:~donadigo/slingshot/uninstall-apps
Reviewer Review Type Date Requested Status
Daniel Fore 2016-12-29 Needs Fixing on 2017-03-26
Jung-Kyu Park (community) Approve on 2017-03-25
Neal Gompa (community) Needs Information on 2016-12-29
Review via email: mp+313915@code.launchpad.net

Commit message

* Add uninstall item to app right-click menu to uninstall apps

Description of the change

This branch fixes bug #1211570: "Uninstall apps from context menu in Slingshot".

The implementation is done with appstream, altough on Slack we also talked about a possible implementation depending on Contractor / appstream-glib in the future.

The Gtk.show_uri error is only handeled internally, so there is no warning message shown to the user when the app handling appstream URI couldn't be launched for some reason (definitely should be shown in the future).

Please test, if launching wingpanel doesn't take too much time, because this branch uses heavy AppStream.Pool.load () which could make impact on loading times on logging in first time or launching wingpanel from terminal.

To post a comment you must log in.
714. By Adam Bieńkowski on 2016-12-29

Remove unneded return line; check if component id is already assigned

Neal Gompa (ngompa13) wrote :

If you're going to use AppStream instead of appstream-glib, be sure to target AppStream 0.10 or newer only. There's an API break between 0.9.x and 0.10.x.

review: Needs Fixing
Neal Gompa (ngompa13) wrote :

Also, I'm curious why you moved the #ifdef for HAS_PLANK. There doesn't seem to be an obvious reason for it.

review: Needs Information
715. By Adam Bieńkowski on 2016-12-30

Bump appstream version to 0.10.0

Jung-Kyu Park (bagjunggyu) wrote :

It works good with AppCenter.

review: Approve
Daniel Fore (danrabbit) wrote :

This is not working for David and me. But even if it were working, I would not merge because it doesn't do what it says it does. It says "Uninstall" but it doesn't actually perform an uninstall.

review: Needs Fixing
Rico Tzschichholz (ricotz) wrote :

This is already merged!

Adam Bieńkowski (donadigo) wrote :

ricotz: We discussed this on Slack, it will be just reverted, hence the review.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2016-08-14 19:55:27 +0000
3+++ CMakeLists.txt 2016-12-30 12:20:39 +0000
4@@ -77,7 +77,7 @@
5 endif ()
6 endif ()
7
8-set (CORE_DEPS "gobject-2.0;glib-2.0;gio-2.0;gio-unix-2.0;libsoup-2.4;gee-0.8;libgnome-menu-3.0;json-glib-1.0;${UNITY_DEPS};${PLANK_DEPS};")
9+set (CORE_DEPS "gobject-2.0;glib-2.0;gio-2.0;gio-unix-2.0;libsoup-2.4;gee-0.8;libgnome-menu-3.0;json-glib-1.0;${UNITY_DEPS};${PLANK_DEPS};appstream>=0.10.0;")
10 set (UI_DEPS "wingpanel-2.0;gtk+-3.0>=3.12.0;granite;${ZEITGEIST_DEPS};")
11
12 pkg_check_modules (DEPS REQUIRED "${CORE_DEPS}${UI_DEPS}" gthread-2.0)
13
14=== modified file 'src/CMakeLists.txt'
15--- src/CMakeLists.txt 2015-11-21 11:47:57 +0000
16+++ src/CMakeLists.txt 2016-12-30 12:20:39 +0000
17@@ -29,6 +29,7 @@
18 ${UI_DEPS}
19 synapse-core
20 synapse-plugins
21+ appstream
22 CUSTOM_VAPIS
23 ../vapi/config.vapi
24 OPTIONS
25
26=== modified file 'src/Widgets/AppEntry.vala'
27--- src/Widgets/AppEntry.vala 2016-12-27 21:08:33 +0000
28+++ src/Widgets/AppEntry.vala 2016-12-30 12:20:39 +0000
29@@ -50,9 +50,10 @@
30 private Gtk.Image count_image;
31 private bool dragging = false; //prevent launching
32 private Backend.App application;
33+ private string? appstream_comp_id = null;
34
35-#if HAS_PLANK
36 static construct {
37+#if HAS_PLANK
38 Plank.Paths.initialize ("plank", Build.PKGDATADIR);
39 plank_theme = new Plank.DockTheme (Plank.Theme.GTK_THEME_NAME);
40 #if HAS_PLANK_0_11
41@@ -60,10 +61,23 @@
42 #else
43 plank_client = Plank.DBus.Client.get_instance ();
44 #endif
45+#endif
46+
47+ has_appstream_handler = AppInfo.get_default_for_uri_scheme ("appstream") != null;
48+ appstream_pool = new AppStream.Pool ();
49+ try {
50+ appstream_pool.load ();
51+ } catch (Error e) {
52+ warning (e.message);
53+ }
54 }
55
56 private const int ICON_SIZE = 64;
57
58+ private static AppStream.Pool appstream_pool;
59+ private static bool has_appstream_handler = false;
60+
61+#if HAS_PLANK
62 #if HAS_PLANK_0_11
63 private const int SURFACE_SIZE = 48;
64 private static Plank.DockTheme plank_theme;
65@@ -88,6 +102,12 @@
66 application = app;
67 tooltip_text = app.description;
68
69+ appstream_pool.get_components ().foreach ((comp) => {
70+ if (appstream_comp_id == null && desktop_id == comp.get_desktop_id () && comp.get_pkgname () != null) {
71+ appstream_comp_id = comp.get_id ();
72+ }
73+ });
74+
75 get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);
76
77 app_label = new Gtk.Label (app_name);
78@@ -217,6 +237,14 @@
79 });
80 }
81
82+ if (has_appstream_handler && appstream_comp_id != null) {
83+ if (menu.get_children ().length () > 0) {
84+ menu.add (new Gtk.SeparatorMenuItem ());
85+ }
86+
87+ menu.add (get_uninstall_menuitem ());
88+ }
89+
90 #if HAS_PLANK
91 if (plank_client != null && plank_client.is_connected) {
92 if (menu.get_children ().length () > 0)
93@@ -229,6 +257,24 @@
94 menu.show_all ();
95 }
96
97+ private Gtk.MenuItem get_uninstall_menuitem () {
98+ var uninstall_menuitem = new Gtk.MenuItem ();
99+ uninstall_menuitem.set_label (_("Uninstall"));
100+ uninstall_menuitem.activate.connect (uninstall_menuitem_activate);
101+
102+ return uninstall_menuitem;
103+ }
104+
105+ private void uninstall_menuitem_activate () {
106+ try {
107+ Gtk.show_uri (null, "appstream://%s".printf (appstream_comp_id), Gdk.CURRENT_TIME);
108+ } catch (Error e) {
109+ warning (e.message);
110+ }
111+
112+ app_launched ();
113+ }
114+
115 #if HAS_PLANK
116 private Gtk.MenuItem get_plank_menuitem () {
117 docked = (desktop_uri in plank_client.get_persistent_applications ());

Subscribers

People subscribed via source and target branches