Merge lp:~vikoadi/switchboard-plug-notifications/async-load-applist into lp:~elementary-pantheon/switchboard-plug-notifications/trunk

Proposed by Viko Adi Rahmawan
Status: Merged
Approved by: xapantu
Approved revision: 125
Merged at revision: 124
Proposed branch: lp:~vikoadi/switchboard-plug-notifications/async-load-applist
Merge into: lp:~elementary-pantheon/switchboard-plug-notifications/trunk
Diff against target: 112 lines (+35/-26)
3 files modified
src/Plug.vala (+0/-5)
src/Widgets/AppList.vala (+35/-19)
src/Widgets/AppsView.vala (+0/-2)
To merge this branch: bzr merge lp:~vikoadi/switchboard-plug-notifications/async-load-applist
Reviewer Review Type Date Requested Status
xapantu (community) Approve
Review via email: mp+270886@code.launchpad.net

Commit message

asynchronously load AppList

Description of the change

asynchronously load AppList

To post a comment you must log in.
122. By Viko Adi Rahmawan

remove first row selection

Revision history for this message
xapantu (xapantu) wrote :

Hey, thanks :) See inline comments below.

It works better here :) Maybe they could be loaded by groups of three (for instance) apps, but I am not sure.

review: Needs Fixing
123. By Viko Adi Rahmawan

cache apps, use foreach

124. By Viko Adi Rahmawan

use cancellable just in case notifications updated frequently

125. By Viko Adi Rahmawan

rename list_app to queue_reload and make it private

Revision history for this message
Viko Adi Rahmawan (vikoadi) wrote :

- cache apps, use foreach
- use cancellable just in case notifications updated frequently
- rename list_app to queue_reload and make it private

Revision history for this message
xapantu (xapantu) wrote :

Looks fine, thanks :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Plug.vala'
2--- src/Plug.vala 2014-11-15 22:39:16 +0000
3+++ src/Plug.vala 2015-09-19 06:12:01 +0000
4@@ -57,11 +57,6 @@
5 }
6 });
7
8- appsview.applist.list_apps ();
9-
10- if (NotifySettings.get_default ().do_not_disturb == false)
11- appsview.applist.select_first ();
12-
13 stack.show_all ();
14
15 return stack;
16
17=== modified file 'src/Widgets/AppList.vala'
18--- src/Widgets/AppList.vala 2015-08-30 20:33:33 +0000
19+++ src/Widgets/AppList.vala 2015-09-19 06:12:01 +0000
20@@ -21,6 +21,7 @@
21
22 public class Widgets.AppList : Gtk.ListBox {
23 private int item_count;
24+ private Cancellable list_apps_cancellable;
25
26 public signal void item_changed (AppItem item);
27 public signal void list_loaded (int length);
28@@ -36,25 +37,38 @@
29 }
30 });
31
32+ list_apps_cancellable = new Cancellable ();
33 NotifySettings.get_default ().apps_changed.connect (() => {
34 if (NotifySettings.get_default ().apps.length != item_count) {
35- this.get_children ().foreach ((row) => {
36- this.remove (row);
37- });
38-
39- list_apps ();
40-
41- if (NotifySettings.get_default ().do_not_disturb == false)
42- select_first ();
43+ queue_reload ();
44 }
45 });
46- }
47-
48- public void list_apps () {
49- item_count = NotifySettings.get_default ().apps.length;
50-
51- for (int i = 0; i < item_count; i++) {
52- var parameters = NotifySettings.get_default ().apps[i].split (":");
53+
54+ queue_reload ();
55+ }
56+
57+ private void queue_reload () {
58+ list_apps_cancellable.cancel ();
59+ this.get_children ().foreach ((row) => {
60+ this.remove (row);
61+ });
62+ list_apps_cancellable.reset ();
63+ list_apps_async.begin ();
64+ }
65+
66+ private async void list_apps_async () {
67+ var apps = NotifySettings.get_default ().apps;
68+ item_count = apps.length;
69+
70+ foreach (var app in apps) {
71+ var idle_handler = Idle.add (list_apps_async.callback);
72+ var cancellable_handler = list_apps_cancellable.connect (() => {
73+ Source.remove(idle_handler);
74+ });
75+ yield;
76+ list_apps_cancellable.disconnect (cancellable_handler);
77+
78+ var parameters = app.split (":");
79
80 if (parameters.length == 2) {
81 var properties = parameters[1].split (",");
82@@ -64,11 +78,13 @@
83 this.add (item);
84 }
85 }
86+
87+ if (selected_row == null && NotifySettings.get_default ().do_not_disturb == false)
88+ select_first ();
89+
90+ this.show_all ();
91+ list_loaded (item_count);
92 }
93-
94- this.show_all ();
95-
96- list_loaded (item_count);
97 }
98
99 public void select_first () {
100
101=== modified file 'src/Widgets/AppsView.vala'
102--- src/Widgets/AppsView.vala 2014-12-11 16:30:53 +0000
103+++ src/Widgets/AppsView.vala 2015-09-19 06:12:01 +0000
104@@ -59,8 +59,6 @@
105 this.pack2 (content, true, false);
106 this.set_position (240);
107
108- select_app (applist.selected_row);
109-
110 applist.item_changed.connect (select_app);
111
112 appsettings.bubbles_changed.connect ((bubbles) => {

Subscribers

People subscribed via source and target branches

to all changes: