Merge lp:~donadigo/slingshot/show-app-badges into lp:~elementary-pantheon/slingshot/trunk

Proposed by Adam Bieńkowski
Status: Rejected
Rejected by: Adam Bieńkowski
Proposed branch: lp:~donadigo/slingshot/show-app-badges
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 180 lines (+80/-7)
3 files modified
src/Backend/App.vala (+18/-0)
src/SlingshotView.vala (+32/-1)
src/Widgets/AppEntry.vala (+30/-6)
To merge this branch: bzr merge lp:~donadigo/slingshot/show-app-badges
Reviewer Review Type Date Requested Status
Adam Bieńkowski (community) Disapprove
Cody Garver (community) Needs Fixing
Review via email: mp+277172@code.launchpad.net

Commit message

* Fixes bug #710498.

Description of the change

This branch fixes bug #710498 Support Launcher API in order to show badges.

Although the implementation itself isn't based on Unity Launcher API (vapi), it uses DBus to know when and what app has changed it's info from "com.canonical.Unity.LauncherEntry" interface. This data is now included and used in Backend.App. For drawing this uses a Plank vapi in order to draw the same surface as the plank do.

To post a comment you must log in.
598. By Adam Bieńkowski

Use set_from_surface; margin_left to 12; use doubles for color

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

you might want to overthink implementing it that way
e.g. https://bugs.launchpad.net/plank/+bug/1514201 a DDoS-like scenario

you need to update only once when you open slingshot or switch an app page, so you don't need to listen all the time

maybe even plank could provide those values via dbusclient

Revision history for this message
Cody Garver (codygarver) wrote :

Conflicts with trunk

review: Needs Fixing
Revision history for this message
Adam Bieńkowski (donadigo) wrote :
review: Disapprove

Unmerged revisions

598. By Adam Bieńkowski

Use set_from_surface; margin_left to 12; use doubles for color

597. By Adam Bieńkowski

Private not public

596. By Adam Bieńkowski

Show app badges

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 2014-10-18 01:57:49 +0000
3+++ src/Backend/App.vala 2015-11-10 20:05:31 +0000
4@@ -45,6 +45,9 @@
5 public string generic_name { get; private set; default = ""; }
6 public AppType app_type { get; private set; default = AppType.APP; }
7
8+ public bool count_visible = false;
9+ public int64 current_count = 0;
10+
11 public Synapse.Match? match { get; private set; default = null; }
12 public Synapse.Match? target { get; private set; default = null; }
13 public Gee.ArrayList<string> actions { get; private set; default = null; }
14@@ -375,4 +378,19 @@
15 }
16 }
17 }
18+
19+ public void update_unity_info (string sender_name, VariantIter prop_iter) {
20+ string prop_key;
21+ Variant prop_value;
22+
23+ while (prop_iter.next ("{sv}", out prop_key, out prop_value)) {
24+ if (prop_key == "count") {
25+ current_count = prop_value.get_int64 ();
26+ } else if (prop_key == "count-visible") {
27+ count_visible = prop_value.get_boolean ();
28+ }
29+ }
30+
31+ icon_changed ();
32+ }
33 }
34\ No newline at end of file
35
36=== modified file 'src/SlingshotView.vala'
37--- src/SlingshotView.vala 2015-02-01 15:13:15 +0000
38+++ src/SlingshotView.vala 2015-11-10 20:05:31 +0000
39@@ -48,6 +48,7 @@
40 public Backend.AppSystem app_system;
41 private Gee.ArrayList<GMenu.TreeDirectory> categories;
42 public Gee.HashMap<string, Gee.ArrayList<Backend.App>> apps;
43+ private DBusConnection connection;
44
45 private Modality modality;
46 private bool can_trigger_hotcorner = true;
47@@ -98,6 +99,12 @@
48 categories = app_system.get_categories ();
49 apps = app_system.get_apps ();
50
51+ try {
52+ connection = Bus.get_sync (BusType.SESSION);
53+ } catch (IOError e) {
54+ warning ("%s\n", e.message);
55+ }
56+
57 primary_monitor = screen.get_primary_monitor ();
58 Gdk.Rectangle geometry;
59 screen.get_monitor_geometry (primary_monitor, out geometry);
60@@ -300,7 +307,6 @@
61 }
62
63 private void connect_signals () {
64-
65 this.focus_in_event.connect (() => {
66 search_entry.grab_focus ();
67 return false;
68@@ -373,6 +379,31 @@
69
70 // hotcorner management
71 motion_notify_event.connect (hotcorner_trigger);
72+
73+ connection.signal_subscribe (null, "com.canonical.Unity.LauncherEntry",
74+ null, null, null, DBusSignalFlags.NONE, handle_entry_signal);
75+ }
76+
77+ private void handle_entry_signal (DBusConnection connection, string sender_name, string object_path,
78+ string interface_name, string signal_name, Variant parameters) {
79+
80+ if (parameters == null
81+ || !parameters.is_of_type (new VariantType ("(sa{sv})"))
82+ || signal_name == null
83+ || sender_name == null
84+ || signal_name != "Update") {
85+ return;
86+ }
87+
88+ string app_uri;
89+ VariantIter prop_iter;
90+ parameters.get ("(sa{sv})", out app_uri, out prop_iter);
91+
92+ foreach (var app in app_system.get_apps_by_name ()) {
93+ if (app_uri == "application://" + app.desktop_id) {
94+ app.update_unity_info (sender_name, prop_iter);
95+ }
96+ }
97 }
98
99 private void gala_settings_changed () {
100
101=== modified file 'src/Widgets/AppEntry.vala'
102--- src/Widgets/AppEntry.vala 2015-11-03 15:36:28 +0000
103+++ src/Widgets/AppEntry.vala 2015-11-10 20:05:31 +0000
104@@ -22,6 +22,7 @@
105 public Gtk.Label app_label;
106 private Gdk.Pixbuf icon;
107 private new Gtk.Image image;
108+ private Gtk.Image count_image;
109
110 public string exec_name;
111 public string app_name;
112@@ -36,7 +37,11 @@
113 private Backend.App application;
114
115 #if HAS_PLANK
116+ private static Plank.DockTheme plank_theme;
117+
118 static construct {
119+ plank_theme = new Plank.DockTheme ("Gtk+");
120+
121 #if HAS_PLANK_0_11
122 plank_client = Plank.DBusClient.get_instance ();
123 #else
124@@ -85,12 +90,21 @@
125 image.icon_size = icon_size;
126 image.margin_top = 12;
127
128+ count_image = new Gtk.Image ();
129+ count_image.no_show_all = true;
130+ count_image.visible = false;
131+ count_image.margin_left = 12;
132+
133+ var overlay = new Gtk.Overlay ();
134+ overlay.add (image);
135+ overlay.add_overlay (count_image);
136+
137 var grid = new Gtk.Grid ();
138 grid.orientation = Gtk.Orientation.VERTICAL;
139 grid.row_spacing = 6;
140 grid.expand = true;
141 grid.halign = Gtk.Align.CENTER;
142- grid.add (image);
143+ grid.add (overlay);
144 grid.add (app_label);
145
146 add (grid);
147@@ -125,11 +139,8 @@
148 sel.set_uris ({File.new_for_path (desktop_path).get_uri ()});
149 });
150
151- app.icon_changed.connect (() => {
152- icon = app.icon;
153- image.set_from_pixbuf (icon);
154- });
155-
156+ app.icon_changed.connect (update_icon);
157+ update_icon ();
158 }
159
160 public override void get_preferred_width (out int minimum_width, out int natural_width) {
161@@ -147,6 +158,19 @@
162 app_launched ();
163 }
164
165+ private void update_icon () {
166+ icon = application.icon;
167+ image.set_from_pixbuf (icon);
168+
169+#if HAS_PLANK
170+ var surface = new Plank.Surface (icon_size, icon_size);
171+ plank_theme.draw_item_count (surface, 48, { 0.85, 0.23, 0.29, 0.89 }, application.current_count);
172+
173+ count_image.set_from_surface (surface.Internal);
174+ count_image.visible = application.count_visible;
175+#endif
176+ }
177+
178 private void create_menu () {
179 // Display the apps static quicklist items in a popover menu
180 if (application.actions == null) {

Subscribers

People subscribed via source and target branches