Merge lp:~mhr3/unity-lens-music/new-libunity-api into lp:unity-lens-music/0.3

Proposed by Michal Hruby
Status: Merged
Approved by: Mikkel Kamstrup Erlandsen
Approved revision: 63
Merged at revision: 63
Proposed branch: lp:~mhr3/unity-lens-music/new-libunity-api
Merge into: lp:unity-lens-music/0.3
Diff against target: 216 lines (+31/-117)
2 files modified
configure.ac (+1/-1)
src/simple-scope.vala (+30/-116)
To merge this branch: bzr merge lp:~mhr3/unity-lens-music/new-libunity-api
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Mirco Müller (community) Approve
Review via email: mp+84738@code.launchpad.net

Description of the change

Use libunity-5.0 API.

To post a comment you must log in.
Revision history for this message
Mirco Müller (macslow) wrote :

Looking good to me. +1 from me, but I would suggest someone else, with more experience in dee/lenses takes a look at this too, before marking it as "Approved".

review: Approve
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'configure.ac'
--- configure.ac 2011-09-29 15:16:02 +0000
+++ configure.ac 2011-12-07 11:23:23 +0000
@@ -64,7 +64,7 @@
64 sqlite3 >= 3.7.764 sqlite3 >= 3.7.7
65 gee-1.065 gee-1.0
66 json-glib-1.066 json-glib-1.0
67 unity >= 4.0.2)67 unity >= 4.99.0)
6868
69AC_SUBST(LENS_DAEMON_CFLAGS)69AC_SUBST(LENS_DAEMON_CFLAGS)
70AC_SUBST(LENS_DAEMON_LIBS)70AC_SUBST(LENS_DAEMON_LIBS)
7171
=== modified file 'src/simple-scope.vala'
--- src/simple-scope.vala 2011-09-15 14:34:15 +0000
+++ src/simple-scope.vala 2011-12-07 11:23:23 +0000
@@ -31,63 +31,37 @@
3131
32 protected abstract void perform_search (LensSearch? search, Dee.Model results_model, List<FilterParser> filters, int max_results = -1);32 protected abstract void perform_search (LensSearch? search, Dee.Model results_model, List<FilterParser> filters, int max_results = -1);
33 33
34 protected bool is_dirty;
35 protected LensSearch? previous_search;
36
37 public SimpleScope ()34 public SimpleScope ()
38 {35 {
39 is_dirty = true;
40 previous_search = null;
41 }36 }
4237
43 protected void initialize ()38 protected void initialize ()
44 {39 {
45 /* Listen for filter changes */40 /* Listen for filter changes */
46 scope.filters_changed.connect(41 scope.filters_changed.connect (() => {
47 () => { 42 scope.queue_search_changed (SearchType.DEFAULT);
48 if (scope.active_search != null)43 });
49 {44
50 is_dirty = true;45 /* No need to search if only the whitespace changes */
51 scope.notify_property ("active-search");46 scope.generate_search_key.connect ((lens_search) => {
52 }47 return lens_search.search_string.strip ();
53 }48 });
54 );49
55
56 /* Listen for changes to the lens search entry */50 /* Listen for changes to the lens search entry */
57 scope.notify["active-search"].connect (51 scope.search_changed.connect ((search, search_type, cancellable) => {
58 (obj, pspec) => { 52 if (search_type == SearchType.DEFAULT)
59 var search = scope.active_search;53 update_search_async.begin (search);
60 if (!(is_dirty || search_has_really_changed (previous_search, search)))54 else
61 return;55 update_global_search_async.begin (search);
62 is_dirty = false;56 });
63 update_search_async.begin (search);
64 previous_search = search;
65 }
66 );
67
68 /* Listen for changes to the global search */
69 scope.notify["active-global-search"].connect (
70 (obj, pspec) => {
71 var search = scope.active_global_search;
72
73 if (search_is_invalid (search))
74 return;
75
76 if (!search_has_really_changed (previous_search, search))
77 return;
78
79 update_global_search_async.begin (search);
80 previous_search = search;
81 }
82 );
83 }57 }
8458
85 /* based on the filters(?) get the default results to show when the music lens is59 /* based on the filters(?) get the default results to show when the music lens is
86 * just opened without filters, like when someone hits Super+M60 * just opened without filters, like when someone hits Super+M
87 */61 */
88 private async void update_without_search_async (LensSearch search, Dee.Model results_model)62 private async void update_without_search_async (LensSearch search)
89 {63 {
90 perform_search_async.begin (search, results_model, num_results_without_search);64 yield perform_search_async (search, num_results_without_search);
91 }65 }
92 66
93 /**67 /**
@@ -96,15 +70,14 @@
96 */70 */
97 private async void update_global_search_async (LensSearch search)71 private async void update_global_search_async (LensSearch search)
98 {72 {
99 var results_model = scope.global_results_model;
100
101 if (search_is_invalid (search))73 if (search_is_invalid (search))
102 {74 {
103 results_model.clear ();75 search.results_model.clear ();
104 return;76 search.finished ();
105 }77 return;
106 78 }
107 perform_search_async.begin (search, scope.global_results_model, num_results_global_search);79
80 yield perform_search_async (search, num_results_global_search);
108 }81 }
109 82
110 private async void update_search_async (LensSearch search)83 private async void update_search_async (LensSearch search)
@@ -112,20 +85,17 @@
112 // just pretend like there's no search85 // just pretend like there's no search
113 if (search_is_invalid (search))86 if (search_is_invalid (search))
114 {87 {
115 update_without_search_async.begin (search, scope.results_model);88 yield update_without_search_async (search);
116 return;89 return;
117 }90 }
118 91
119 perform_search_async.begin (search, scope.results_model, num_results_lens_search);92 yield perform_search_async (search, num_results_lens_search);
120 }93 }
12194
122 private async void perform_search_async (LensSearch search, Dee.Model results_model, int max_results)95 private async void perform_search_async (LensSearch search, int max_results)
123 { 96 {
124 /* Prevent concurrent searches and concurrent updates of our models,97 var results_model = search.results_model;
125 * by preventing any notify signals from propagating to us.98
126 * Important: Remeber to thaw the notifys again! */
127 scope.freeze_notify ();
128
129 List<FilterParser> filters = new List<FilterParser> ();99 List<FilterParser> filters = new List<FilterParser> ();
130 Filter filter = scope.get_filter ("genre");100 Filter filter = scope.get_filter ("genre");
131 if (filter.filtering)101 if (filter.filtering)
@@ -138,15 +108,6 @@
138 results_model.clear ();108 results_model.clear ();
139 perform_search (search, results_model, filters, max_results);109 perform_search (search, results_model, filters, max_results);
140 110
141 /* Allow new searches once we enter an idle again.
142 * We don't do it directly from here as that could mean we start
143 * changing the model even before we had flushed out current changes
144 */
145 Idle.add (() => {
146 scope.thaw_notify ();
147 return false;
148 });
149
150 search.finished ();111 search.finished ();
151 }112 }
152113
@@ -161,52 +122,5 @@
161 122
162 return search.search_string.strip() == "";123 return search.search_string.strip() == "";
163 }124 }
164
165 private bool search_has_really_changed (LensSearch? old_search,
166 LensSearch? new_search)
167 {
168 if (old_search == null && new_search == null)
169 return false;
170
171 string s1, s2;
172
173 if (old_search == null)
174 {
175 s1 = new_search.search_string;
176 if (s1 == null || s1.strip() == "")
177 return false;
178 else
179 return true;
180 }
181 else if (new_search == null)
182 {
183 s2 = old_search.search_string;
184 if (s2 == null || s2.strip() == "")
185 return false;
186 else
187 return true;
188 }
189 else
190 {
191 s1 = new_search.search_string;
192 s2 = old_search.search_string;
193 if (s1 == null)
194 {
195 if (s2 == null || s2.strip() == "")
196 return false;
197 else
198 return true;
199 }
200 else if (s2 == null)
201 {
202 if (s1 == null || s1.strip() == "")
203 return false;
204 else
205 return true;
206 }
207 else
208 return s1.strip () != s2.strip ();
209 }
210 }
211 }125 }
212}126}

Subscribers

People subscribed via source and target branches

to all changes: