Merge lp:~donadigo/appcenter/code-improvements into lp:~elementary-apps/appcenter/appcenter

Proposed by Adam Bieńkowski
Status: Rejected
Rejected by: Rico Tzschichholz
Proposed branch: lp:~donadigo/appcenter/code-improvements
Merge into: lp:~elementary-apps/appcenter/appcenter
Diff against target: 2407 lines (+543/-463)
23 files modified
src/AbstractAppContainer.vala (+28/-39)
src/AbstractAppList.vala (+26/-20)
src/Application.vala (+13/-12)
src/Core/ChangeInformation.vala (+4/-4)
src/Core/Client.vala (+113/-76)
src/Core/Package.vala (+52/-30)
src/Core/Task.vala (+1/-5)
src/MainWindow.vala (+71/-51)
src/Settings.vala (+5/-3)
src/Views/AppInfoView.vala (+50/-46)
src/Views/AppListView.vala (+23/-28)
src/Views/CategoryView.vala (+28/-9)
src/Views/FeaturedView.vala (+2/-2)
src/Views/InstalledView.vala (+17/-16)
src/Views/SearchView.vala (+20/-19)
src/Views/View.vala (+3/-2)
src/Widgets/AppActionButton.vala (+10/-13)
src/Widgets/AppCellRenderer.vala (+11/-9)
src/Widgets/AppListRow.vala (+6/-2)
src/Widgets/CategoryItem.vala (+1/-11)
src/Widgets/FeaturedButton.vala (+27/-22)
src/Widgets/PackageRow.vala (+7/-12)
src/Widgets/UpdateHeaderRow.vala (+25/-32)
To merge this branch: bzr merge lp:~donadigo/appcenter/code-improvements
Reviewer Review Type Date Requested Status
Rico Tzschichholz Disapprove
Review via email: mp+308460@code.launchpad.net

Commit message

* Fix code style issues
* Improve code readability
* Performance improvements (caching)
* Less hardcoded parts of the code
* Changed some of the member's naming to be simpler
* More GObject's construct {} oriented codebase

Description of the change

This branch makes some general improvements to all components of the code including:

* Fix code style issues
* Improve code readability
* Performance improvements (caching)
* Less hardcoded parts of the code
* Changed some of the member's naming to be simpler
* More GObject's construct {} oriented codebase

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

Split this is up in consistent commits/branches

review: Disapprove

Unmerged revisions

324. By Adam Bieńkowski

Some last minute changes

323. By Adam Bieńkowski

Bring back needed parts of activate method

322. By Adam Bieńkowski

Align if statement

321. By Adam Bieńkowski

Some improvements made to the entire code of appcenter

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/AbstractAppContainer.vala'
2--- src/AbstractAppContainer.vala 2016-09-17 18:18:04 +0000
3+++ src/AbstractAppContainer.vala 2016-10-13 21:30:22 +0000
4@@ -1,6 +1,7 @@
5 namespace AppCenter {
6 public abstract class AbstractAppContainer : Gtk.Grid {
7- public AppCenterCore.Package package;
8+ public AppCenterCore.Package package { get; construct; }
9+ public uint icon_size { get; construct; default = 48; }
10
11 protected Gtk.Image image;
12 protected Gtk.Label package_name;
13@@ -46,16 +47,14 @@
14 }
15
16 construct {
17- image = new Gtk.Image ();
18-
19 progress_bar = new Gtk.ProgressBar ();
20 progress_bar.show_text = true;
21 progress_bar.valign = Gtk.Align.CENTER;
22+
23 /* Request a width large enough for the longest text to stop width of
24 * progress bar jumping around */
25 progress_bar.width_request = 350;
26- progress_bar.no_show_all = true;
27- progress_bar.hide ();
28+ set_widget_visible (progress_bar, false);
29
30 action_button_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.BOTH);
31
32@@ -65,7 +64,7 @@
33 action_button = new Widgets.AppActionButton (_("Install"));
34 action_button.clicked.connect (() => action_clicked.begin ());
35
36- uninstall_button = new Widgets.AppActionButton (_("Uninstall"));
37+ uninstall_button = new Widgets.AppActionButton (_("Uninstall"), Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
38 uninstall_button.clicked.connect (() => uninstall_clicked.begin ());
39
40 var button_grid = new Gtk.Grid ();
41@@ -92,17 +91,20 @@
42
43 action_stack.add_named (button_grid, "buttons");
44 action_stack.add_named (progress_grid, "progress");
45- }
46
47- protected virtual void set_up_package (uint icon_size = 48) {
48+ package_name = new Gtk.Label (null);
49 package_name.label = package.get_name ();
50+
51+ package_summary = new Gtk.Label (null);
52 package_summary.label = package.get_summary ();
53 package_summary.ellipsize = Pango.EllipsizeMode.END;
54+
55+ image = new Gtk.Image ();
56 image.gicon = package.get_icon (icon_size);
57
58+ package.change_information.bind_property ("can-cancel", cancel_button, "sensitive", GLib.BindingFlags.SYNC_CREATE);
59+
60 package.notify["state"].connect (update_state);
61-
62- package.change_information.bind_property ("can-cancel", cancel_button, "sensitive", GLib.BindingFlags.SYNC_CREATE);
63 package.change_information.progress_changed.connect (update_progress);
64 package.change_information.status_changed.connect (update_progress_status);
65
66@@ -116,36 +118,23 @@
67 }
68
69 protected void update_action (bool show_uninstall = true) {
70- uninstall_button.no_show_all = true;
71- uninstall_button.hide ();
72- progress_bar.no_show_all = true;
73- progress_bar.hide ();
74- action_stack.no_show_all = false;
75- action_stack.show_all ();
76+ set_widget_visible (uninstall_button, false);
77+ set_widget_visible (progress_bar, false);
78+ set_widget_visible (action_stack, true);
79 action_stack.set_visible_child_name ("buttons");
80
81 switch (package.state) {
82 case AppCenterCore.Package.State.NOT_INSTALLED:
83 action_button.label = _("Install");
84- action_button.no_show_all = false;
85- action_button.show ();
86+ set_widget_visible (action_button, true);
87 break;
88
89 case AppCenterCore.Package.State.INSTALLED:
90 if (show_uninstall) {
91- /* Uninstall button will show */
92- action_button.label = "Not visible";
93- action_button.no_show_all = true;
94- action_button.hide ();
95-
96- if (!is_os_updates) {
97- uninstall_button.no_show_all = false;
98- uninstall_button.show_all ();
99- }
100+ set_widget_visible (action_button, false);
101+ set_widget_visible (uninstall_button, !is_os_updates);
102 } else {
103- /* No Uninstall action in list view */
104- action_stack.no_show_all = true;
105- action_stack.hide ();
106+ set_widget_visible (action_stack, false);
107 }
108
109 break;
110@@ -157,22 +146,22 @@
111 case AppCenterCore.Package.State.INSTALLING:
112 case AppCenterCore.Package.State.UPDATING:
113 case AppCenterCore.Package.State.REMOVING:
114- progress_bar.no_show_all = false;
115- progress_bar.show ();
116+ set_widget_visible (progress_bar, true);
117 action_stack.set_visible_child_name ("progress");
118 break;
119
120 default:
121- assert_not_reached ();
122+ break;
123 }
124 }
125
126 protected void update_progress () {
127- progress_bar.fraction = package.progress;
128- }
129+ progress_bar.fraction = package.progress;
130+ }
131
132 protected void update_progress_status () {
133 progress_bar.text = package.get_progress_description ();
134+
135 /* Ensure progress bar shows complete to match status (lp:1606902) */
136 if (package.changes_finished) {
137 progress_bar.fraction = 1.0f;
138@@ -185,11 +174,11 @@
139 }
140
141 private async void action_clicked () {
142- if (package.update_available) {
143- yield package.update ();
144+ if (package.update_available) {
145+ yield package.update ();
146 } else if (yield package.install ()) {
147- // Add this app to the Installed Apps View
148- MainWindow.installed_view.add_app.begin (package);
149+ // Add this app to the Installed Apps View
150+ MainWindow.installed_view.add_app.begin (package);
151 update_state ();
152 }
153 }
154
155=== modified file 'src/AbstractAppList.vala'
156--- src/AbstractAppList.vala 2016-09-14 16:58:13 +0000
157+++ src/AbstractAppList.vala 2016-10-13 21:30:22 +0000
158@@ -27,6 +27,7 @@
159
160 construct {
161 hscrollbar_policy = Gtk.PolicyType.NEVER;
162+
163 var alert_view = new Granite.Widgets.AlertView (_("No Results"), _("No apps could be found. Try changing search terms."), "edit-find-symbolic");
164 alert_view.show_all ();
165 list_box = new Gtk.ListBox ();
166@@ -38,15 +39,18 @@
167 var row = (Widgets.AppListRow)r;
168 show_app (row.get_package ());
169 });
170+
171 add (list_box);
172
173 action_button_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.BOTH);
174 }
175
176 public virtual void add_package (AppCenterCore.Package package) {
177- var row = make_row (package);
178- set_up_row (row);
179- after_add_remove_change_row ();
180+ var row = create_row (package);
181+ row.show_all ();
182+ list_box.add (row);
183+ row.get_package ().changing.connect (on_package_changing);
184+ list_changed ();
185 }
186
187 public void remove_package (AppCenterCore.Package package) {
188@@ -56,12 +60,14 @@
189 if (!row.has_package ()) {
190 continue;
191 }
192+
193 if (row.get_package () == package) {
194 row.destroy ();
195 break;
196 }
197 }
198- after_add_remove_change_row ();
199+
200+ list_changed ();
201 }
202
203 public void clear () {
204@@ -72,33 +78,33 @@
205 package.changing.disconnect (on_package_changing);
206 row.destroy ();
207 }
208- };
209- }
210-
211- protected abstract Widgets.AppListRow make_row (AppCenterCore.Package package); // {
212-
213- protected virtual void set_up_row (Widgets.AppListRow row) {
214- row.show_all ();
215- list_box.add (row);
216- row.get_package ().changing.connect (on_package_changing);
217- }
218-
219- protected virtual void after_add_remove_change_row () {}
220+ }
221+ }
222+
223+ protected abstract Widgets.AppListRow create_row (AppCenterCore.Package package);
224+
225+ protected virtual void list_changed () {
226+
227+ }
228
229 protected Gee.Collection<AppCenterCore.Package> get_packages () {
230 var tree_set = new Gee.TreeSet<AppCenterCore.Package> ();
231 foreach (var r in list_box.get_children ()) {
232 var row = (Widgets.AppListRow)r;
233- if (row.has_package ()) {
234+ if (row.get_package () != null) {
235 tree_set.add (row.get_package ());
236 }
237- };
238+ }
239
240 return tree_set;
241 }
242
243 [CCode (instance_pos = -1)]
244 protected virtual int package_row_compare (Widgets.AppListRow row1, Widgets.AppListRow row2) {
245+ if (row1.get_name_label () == null || row2.get_name_label () == null) {
246+ return 0;
247+ }
248+
249 return row1.get_name_label ().collate (row2.get_name_label ());
250 }
251
252@@ -109,9 +115,9 @@
253 packages_changing--;
254 }
255
256- assert (packages_changing >=0);
257+ assert (packages_changing >= 0);
258 if (packages_changing == 0) {
259- after_add_remove_change_row ();
260+ list_changed ();
261 }
262 }
263 }
264
265=== modified file 'src/Application.vala'
266--- src/Application.vala 2016-08-23 14:35:57 +0000
267+++ src/Application.vala 2016-10-13 21:30:22 +0000
268@@ -25,10 +25,13 @@
269
270 public static bool show_updates;
271 public static bool silent;
272- MainWindow main_window;
273+
274+ public MainWindow? main_window { public get; private set; default = null; }
275+
276 construct {
277 application_id = "org.pantheon.appcenter";
278 flags = ApplicationFlags.FLAGS_NONE;
279+
280 Intl.setlocale (LocaleCategory.ALL, "");
281 Intl.textdomain (Build.GETTEXT_PACKAGE);
282
283@@ -55,6 +58,11 @@
284 add_main_option_entries (appcenter_options);
285 }
286
287+ public static int main (string[] args) {
288+ var application = new App ();
289+ return application.run (args);
290+ }
291+
292 public override void activate () {
293 var client = AppCenterCore.Client.get_default ();
294 if (silent) {
295@@ -72,27 +80,20 @@
296 }
297
298 if (main_window == null) {
299- client.update_cache.begin (true);
300-
301 main_window = new MainWindow (this);
302 main_window.destroy.connect (() => {
303 main_window = null;
304 });
305
306 add_window (main_window);
307- main_window.show_all ();
308 if (show_updates) {
309 main_window.go_to_installed ();
310 }
311+
312+ main_window.show_all ();
313 } else {
314 client.interface_cancellable.reset ();
315+ main_window.present ();
316 }
317-
318- main_window.present ();
319 }
320-}
321-
322-public static int main (string[] args) {
323- var application = new AppCenter.App ();
324- return application.run (args);
325-}
326+}
327\ No newline at end of file
328
329=== modified file 'src/Core/ChangeInformation.vala'
330--- src/Core/ChangeInformation.vala 2016-10-07 17:44:50 +0000
331+++ src/Core/ChangeInformation.vala 2016-10-13 21:30:22 +0000
332@@ -169,7 +169,7 @@
333 progress_denom = 200.0f;
334 }
335
336- public void ProgressCallback (Pk.Progress progress, Pk.ProgressType type) {
337+ public void progress_callback (Pk.Progress progress, Pk.ProgressType type) {
338 switch (type) {
339 case Pk.ProgressType.ALLOW_CANCEL:
340 can_cancel = progress.allow_cancel;
341@@ -181,14 +181,14 @@
342 if (current_status != Pk.Status.DOWNLOAD) {
343 progress_denom = 100.0f;
344 }
345- }
346- /* transaction changed so progress count is starting over */
347- else if ((Pk.Status) progress.status != current_status) {
348+ } else if ((Pk.Status) progress.status != current_status) {
349+ /* transaction changed so progress count is starting over */
350 current_status = (Pk.Status) progress.status;
351 current_progress = last_progress;
352 }
353
354 last_progress = progress.percentage;
355+
356 double progress_sum = current_progress + last_progress;
357 this.progress = progress_sum / progress_denom;
358 progress_changed ();
359
360=== modified file 'src/Core/Client.vala'
361--- src/Core/Client.vala 2016-10-09 15:09:46 +0000
362+++ src/Core/Client.vala 2016-10-13 21:30:22 +0000
363@@ -22,37 +22,38 @@
364 public bool updating_cache { public get; private set; }
365
366 public AppCenterCore.Package os_updates { public get; private set; }
367+ public GLib.Cancellable interface_cancellable;
368
369- private Gee.LinkedList<AppCenter.Task> task_list;
370- private Gee.LinkedList<AppCenter.Task> task_with_agreement_list;
371+ private Gee.LinkedList<AppCenterCore.Task> task_list;
372+ private Gee.LinkedList<AppCenterCore.Task> task_with_agreement_list;
373 private Gee.HashMap<string, AppCenterCore.Package> package_list;
374 private AppStream.Database appstream_database;
375- public GLib.Cancellable interface_cancellable;
376 private GLib.DateTime last_cache_update;
377 private uint updates_number = 0U;
378
379+ private SuspendControl sc;
380+
381 private Client () {
382- try {
383- appstream_database.get_all_components ().foreach ((comp) => {
384- var package = new AppCenterCore.Package (comp);
385- foreach (var pkg_name in comp.get_pkgnames ()) {
386- package_list.set (pkg_name, package);
387- }
388- });
389- } catch (Error e) {
390- error (e.message);
391- }
392+
393 }
394
395 construct {
396- task_list = new Gee.LinkedList<AppCenter.Task> ();
397- task_with_agreement_list = new Gee.LinkedList<AppCenter.Task> ();
398+ task_list = new Gee.LinkedList<AppCenterCore.Task> ();
399+ task_with_agreement_list = new Gee.LinkedList<AppCenterCore.Task> ();
400 package_list = new Gee.HashMap<string, AppCenterCore.Package> (null, null);
401 interface_cancellable = new GLib.Cancellable ();
402+ sc = new SuspendControl ();
403
404 appstream_database = new AppStream.Database ();
405+
406 try {
407 appstream_database.open ();
408+ appstream_database.get_all_components ().foreach ((comp) => {
409+ var package = new AppCenterCore.Package (comp);
410+ foreach (var pkg_name in comp.get_pkgnames ()) {
411+ package_list.set (pkg_name, package);
412+ }
413+ });
414 } catch (Error e) {
415 error (e.message);
416 }
417@@ -61,6 +62,7 @@
418 os_updates_component.id = AppCenterCore.Package.OS_UPDATES_ID;
419 os_updates_component.name = _("Operating System Updates");
420 os_updates_component.summary = _("Updates to system components");
421+
422 var icon = new AppStream.Icon ();
423 icon.set_name ("distributor-logo");
424 icon.set_kind (AppStream.IconKind.STOCK);
425@@ -72,28 +74,33 @@
426 return !task_list.is_empty;
427 }
428
429- private AppCenter.Task request_task (bool requires_user_agreement = true) {
430- AppCenter.Task task = new AppCenter.Task ();
431- task_list.add (task);
432+ private AppCenterCore.Task request_task (bool requires_user_agreement = true) {
433+ AppCenterCore.Task task = new AppCenterCore.Task ();
434 if (requires_user_agreement) {
435 if (task_with_agreement_list.size == 0) {
436 Pk.polkit_agent_open ();
437 }
438+
439 task_with_agreement_list.add (task);
440+ } else {
441+ task_list.add (task);
442 }
443+
444 return task;
445 }
446
447- private void release_task (AppCenter.Task task) {
448- task_list.remove (task);
449- if (task_list.is_empty) {
450+ private void release_task (AppCenterCore.Task task) {
451+ if (task in task_with_agreement_list) {
452+ task_with_agreement_list.remove (task);
453+ if (task_with_agreement_list.size == 0) {
454+ Pk.polkit_agent_close ();
455+ }
456+ } else if (task in task_list) {
457+ task_list.remove (task);
458+ }
459+
460+ if (task_list.is_empty && task_with_agreement_list.is_empty) {
461 tasks_finished ();
462- if (task in task_with_agreement_list) {
463- task_with_agreement_list.remove (task);
464- if (task_with_agreement_list.size == 0) {
465- Pk.polkit_agent_close ();
466- }
467- }
468 }
469 }
470
471@@ -102,15 +109,16 @@
472 return appstream_database.get_component_by_id (extension);
473 } catch (Error e) {
474 warning ("%s\n", e.message);
475+ throw e;
476 }
477-
478- return null;
479 }
480
481 public async Pk.Exit install_package (Package package, Pk.ProgressCallback cb, GLib.Cancellable cancellable) throws GLib.Error {
482 Pk.Exit exit_status = Pk.Exit.UNKNOWN;
483- AppCenter.Task install_task = request_task ();
484- AppCenter.Task search_task = request_task ();
485+
486+ AppCenterCore.Task install_task = request_task ();
487+ AppCenterCore.Task search_task = request_task ();
488+
489 string[] packages_ids = {};
490 foreach (var pkg_name in package.component.get_pkgnames ()) {
491 packages_ids += pkg_name;
492@@ -119,7 +127,7 @@
493 packages_ids += null;
494
495 try {
496- var results = yield search_task.resolve_async (Pk.Bitfield.from_enums (Pk.Filter.NEWEST, Pk.Filter.ARCH), packages_ids, cancellable, () => {});
497+ Pk.Results results = yield search_task.resolve_async (Pk.Bitfield.from_enums (Pk.Filter.NEWEST, Pk.Filter.ARCH), packages_ids, cancellable, () => {});
498 packages_ids = {};
499
500 results.get_package_array ().foreach ((package) => {
501@@ -143,13 +151,15 @@
502
503 release_task (search_task);
504 release_task (install_task);
505+
506 return exit_status;
507 }
508
509 public async Pk.Exit update_package (Package package, Pk.ProgressCallback cb, GLib.Cancellable cancellable) throws GLib.Error {
510 Pk.Exit exit_status = Pk.Exit.UNKNOWN;
511- SuspendControl sc = new SuspendControl ();
512- AppCenter.Task update_task = request_task ();
513+
514+ AppCenterCore.Task update_task = request_task ();
515+
516 string[] packages_ids = {};
517 foreach (var pk_package in package.change_information.changes) {
518 packages_ids += pk_package.get_id ();
519@@ -159,15 +169,17 @@
520
521 try {
522 sc.inhibit ();
523- var results = yield update_task.update_packages_async (packages_ids, cancellable, cb);
524+
525+ Pk.Results results = yield update_task.update_packages_async (packages_ids, cancellable, cb);
526 exit_status = results.get_exit_code ();
527 } catch (Error e) {
528- throw e;
529- } finally {
530 sc.uninhibit ();
531- release_task (update_task);
532+ throw e;
533 }
534
535+ sc.uninhibit ();
536+ release_task (update_task);
537+
538 if (exit_status != Pk.Exit.SUCCESS) {
539 throw new GLib.IOError.FAILED (Pk.Exit.enum_to_string (exit_status));
540 } else {
541@@ -181,17 +193,21 @@
542
543 public async Pk.Exit remove_package (Package package, Pk.ProgressCallback cb, GLib.Cancellable cancellable) throws GLib.Error {
544 Pk.Exit exit_status = Pk.Exit.UNKNOWN;
545- AppCenter.Task remove_task = request_task ();
546- AppCenter.Task search_task = request_task ();
547+
548+ AppCenterCore.Task remove_task = request_task ();
549+ AppCenterCore.Task search_task = request_task ();
550+
551 string[] packages_ids = {};
552 foreach (var pkg_name in package.component.get_pkgnames ()) {
553 packages_ids += pkg_name;
554 }
555+
556 packages_ids += null;
557
558 try {
559- var results = yield search_task.resolve_async (Pk.Bitfield.from_enums (Pk.Filter.INSTALLED, Pk.Filter.NEWEST), packages_ids, cancellable, () => {});
560+ Pk.Results results = yield search_task.resolve_async (Pk.Bitfield.from_enums (Pk.Filter.INSTALLED, Pk.Filter.NEWEST), packages_ids, cancellable, () => {});
561 packages_ids = {};
562+
563 results.get_package_array ().foreach ((package) => {
564 packages_ids += package.package_id;
565 });
566@@ -204,34 +220,40 @@
567 throw e;
568 }
569
570+ release_task (search_task);
571+ release_task (remove_task);
572 yield refresh_updates ();
573- release_task (search_task);
574- release_task (remove_task);
575+
576 return exit_status;
577 }
578
579 public async void get_updates () {
580- AppCenter.Task update_task = request_task (false);
581- AppCenter.Task details_task = request_task (false);
582+ AppCenterCore.Task update_task = request_task (false);
583+ AppCenterCore.Task details_task = request_task (false);
584+
585 try {
586- Pk.Results result = yield update_task.get_updates_async (0, interface_cancellable, (t, p) => { });
587+ Pk.Results results = yield update_task.get_updates_async (0, interface_cancellable, (t, p) => {});
588+
589 string[] packages_array = {};
590- result.get_package_array ().foreach ((pk_package) => {
591+ results.get_package_array ().foreach ((pk_package) => {
592 packages_array += pk_package.get_id ();
593 });
594
595 // We need a null to show to PackageKit that it's then end of the array.
596 packages_array += null;
597
598- Pk.Results result2 = yield details_task.get_details_async (packages_array , interface_cancellable, (t, p) => { });
599- result2.get_details_array ().foreach ((pk_detail) => {
600+ results = yield details_task.get_details_async (packages_array , interface_cancellable, (t, p) => {});
601+ results.get_details_array ().foreach ((pk_detail) => {
602 var pk_package = new Pk.Package ();
603+
604 try {
605 pk_package.set_id (pk_detail.get_package_id ());
606+
607 unowned string pkg_name = pk_package.get_name ();
608 var package = package_list.get (pkg_name);
609 if (package == null) {
610 package = os_updates;
611+
612 var pkgnames = os_updates.component.pkgnames;
613 pkgnames += pkg_name;
614 os_updates.component.pkgnames = pkgnames;
615@@ -241,46 +263,51 @@
616 package.change_information.details.add (pk_detail);
617 package.update_state ();
618 } catch (Error e) {
619- critical (e.message);
620+ warning (e.message);
621 }
622 });
623 } catch (Error e) {
624 // Error code 19 is for operation canceled.
625 if (e.code != 19) {
626- critical (e.message);
627+ warning (e.message);
628 }
629+ } finally {
630+ updates_available ();
631 }
632
633 release_task (details_task);
634- release_task (update_task);
635- updates_available ();
636+ release_task (update_task);
637 }
638
639 public async Gee.Collection<AppCenterCore.Package> get_installed_applications () {
640- var packages = new Gee.TreeSet<AppCenterCore.Package> ();
641- var packages_list = yield get_installed_packages ();
642- foreach (var pk_package in packages_list) {
643+ var applications = new Gee.TreeSet<AppCenterCore.Package> ();
644+ var installed_packages = yield get_installed_packages ();
645+ foreach (var pk_package in installed_packages) {
646 var package = package_list.get (pk_package.get_name ());
647 if (package != null) {
648 package.installed_packages.add (pk_package);
649 package.update_state ();
650- packages.add (package);
651+ applications.add (package);
652 }
653 }
654
655- return packages;
656+ return applications;
657 }
658
659 public Gee.Collection<AppCenterCore.Package> search_applications (string? query, AppStream.Category? category) {
660 var apps = new Gee.TreeSet<AppCenterCore.Package> ();
661- string categories = category == null ? null : get_string_from_categories (category);
662+ string? categories = category == null ? null : get_string_from_categories (category);
663 try {
664 var comps = appstream_database.find_components (query, categories);
665 comps.foreach ((comp) => {
666+ if (comp.get_pkgnames ().length == 0) {
667+ return;
668+ }
669+
670 apps.add (package_list.get (comp.get_pkgnames ()[0]));
671 });
672 } catch (Error e) {
673- critical (e.message);
674+ warning (e.message);
675 }
676
677 return apps;
678@@ -307,12 +334,15 @@
679 }
680
681 public Pk.Package? get_app_package (string application, Pk.Bitfield additional_filters = 0) throws GLib.Error {
682- AppCenter.Task packages_task = request_task (false);
683 Pk.Package? package = null;
684+
685+ AppCenterCore.Task packages_task = request_task (false);
686+
687 var filter = Pk.Bitfield.from_enums (Pk.Filter.NEWEST);
688 filter |= additional_filters;
689+
690 try {
691- var results = packages_task.search_names_sync (filter, { application, null }, interface_cancellable, () => {});
692+ Pk.Results results = packages_task.search_names_sync (filter, { application, null }, interface_cancellable, () => {});
693 var array = results.get_package_array ();
694 if (array.length > 0) {
695 package = array.get (0);
696@@ -327,23 +357,26 @@
697 }
698
699 public async void refresh_updates () {
700- var update_task = new AppCenter.Task ();
701+ AppCenterCore.Task update_task = request_task (false);
702 updating_cache = true;
703
704 try {
705- Pk.Results result = yield update_task.get_updates_async (0, null, (t, p) => {});
706+ Pk.Results results = yield update_task.get_updates_async (0, null, (t, p) => {});
707 bool was_empty = updates_number == 0U;
708- updates_number = get_package_count (result.get_package_array ());
709+ updates_number = get_package_count (results.get_package_array ());
710+
711+ var application = (AppCenter.App)GLib.Application.get_default ();
712 if (was_empty && updates_number != 0U) {
713 string title = ngettext ("Update Available", "Updates Available", updates_number);
714 string body = ngettext ("%u update is available for your system", "%u updates are available for your system", updates_number).printf (updates_number);
715+
716 var notification = new Notification (title);
717 notification.set_body (body);
718 notification.set_icon (new ThemedIcon ("system-software-install"));
719 notification.set_default_action ("app.open-application");
720- Application.get_default ().send_notification ("updates", notification);
721+ application.send_notification ("updates", notification);
722 } else {
723- Application.get_default ().withdraw_notification ("updates");
724+ application.withdraw_notification ("updates");
725 }
726
727 #if HAVE_UNITY
728@@ -354,12 +387,14 @@
729 } catch (Error e) {
730 critical (e.message);
731 }
732+
733 updating_cache = false;
734 }
735
736 public uint get_package_count (GLib.GenericArray<weak Pk.Package> package_array) {
737 bool os_update_found = false;
738 var result_comp = new Gee.TreeSet<AppStream.Component> ();
739+
740 package_array.foreach ((pk_package) => {
741 var comp = package_list.get (pk_package.get_name ());
742 if (comp != null) {
743@@ -380,7 +415,7 @@
744 public async void update_cache (bool force = false) {
745 // One cache update a day, keeps the doctor away!
746 if (force || last_cache_update == null || (new DateTime.now_local ()).difference (last_cache_update) >= GLib.TimeSpan.DAY) {
747- var refresh_task = new AppCenter.Task ();
748+ AppCenterCore.Task refresh_task = request_task (false);
749 try {
750 yield refresh_task.refresh_cache_async (false, null, (t, p) => { });
751 last_cache_update = new DateTime.now_local ();
752@@ -389,30 +424,32 @@
753 }
754
755 refresh_updates.begin ();
756+ release_task (refresh_task);
757 }
758
759- GLib.Timeout.add_seconds (60*60*24, () => {
760+ GLib.Timeout.add_seconds (60 * 60 * 24, () => {
761 update_cache.begin ();
762 return GLib.Source.REMOVE;
763 });
764 }
765
766 public async Gee.TreeSet<Pk.Package> get_installed_packages () {
767- var packages_task = request_task ();
768+ AppCenterCore.Task packages_task = request_task ();
769+
770 var filter = Pk.Bitfield.from_enums (Pk.Filter.INSTALLED, Pk.Filter.NEWEST);
771 var installed = new Gee.TreeSet<Pk.Package> ();
772+
773 try {
774- Pk.Results result = yield packages_task.get_packages_async (filter, null, (prog, type) => {});
775- result.get_package_array ().foreach ((pk_package) => {
776+ Pk.Results results = yield packages_task.get_packages_async (filter, null, (t, p) => {});
777+ results.get_package_array ().foreach ((pk_package) => {
778 installed.add (pk_package);
779 });
780-
781- release_task (packages_task);
782 } catch (Error e) {
783- critical (e.message);
784- release_task (packages_task);
785+ warning (e.message);
786 }
787
788+ release_task (packages_task);
789+
790 return installed;
791 }
792
793
794=== modified file 'src/Core/Package.vala'
795--- src/Core/Package.vala 2016-09-14 16:58:13 +0000
796+++ src/Core/Package.vala 2016-10-13 21:30:22 +0000
797@@ -33,7 +33,7 @@
798
799 public const string OS_UPDATES_ID = "xxx-os-updates";
800
801- public AppStream.Component component { public get; private set; }
802+ public AppStream.Component component { get; construct; }
803 public ChangeInformation change_information { public get; private set; }
804 public Gee.TreeSet<Pk.Package> installed_packages { public get; private set; }
805 public GLib.Cancellable action_cancellable { public get; private set; }
806@@ -72,20 +72,25 @@
807 public bool is_os_updates {
808 get {
809 return component.id == "xxx-os-updates";
810- }
811- }
812-
813- public Package (AppStream.Component component) {
814- this.component = component;
815+ }
816+ }
817+
818+ private string? name = null;
819+ private string? summary = null;
820+ private string? version = null;
821+
822+ construct {
823 installed_packages = new Gee.TreeSet<Pk.Package> ();
824 change_information = new ChangeInformation ();
825- change_information.status_changed.connect (() => {
826- info_changed (change_information.status);
827- });
828+ change_information.status_changed.connect (() => info_changed (change_information.status));
829
830 action_cancellable = new GLib.Cancellable ();
831 }
832
833+ public Package (AppStream.Component component) {
834+ Object (component: component);
835+ }
836+
837 public void update_state () {
838 if (installed) {
839 if (change_information.has_changes ()) {
840@@ -102,6 +107,7 @@
841 if (state != State.UPDATE_AVAILABLE) {
842 return false;
843 }
844+
845 return yield perform_operation (State.UPDATING, State.INSTALLED, State.UPDATE_AVAILABLE);
846 }
847
848@@ -109,11 +115,12 @@
849 if (state != State.NOT_INSTALLED) {
850 return false;
851 }
852+
853 if (yield perform_operation (State.INSTALLING, State.INSTALLED, State.NOT_INSTALLED)) {
854 /* TODO: Move this to a higher level */
855- var application = (Gtk.Application)Application.get_default ();
856- var window = application.get_active_window ().get_window ();
857- if ((window.get_state () & Gdk.WindowState.FOCUSED) == 0) {
858+ var application = (AppCenter.App)GLib.Application.get_default ();
859+ var window = application.main_window;
860+ if (window == null || !(Gdk.WindowState.FOCUSED in window.get_window ().get_state ())) {
861 var notification = new Notification (_("Application installed"));
862 notification.set_body (_("%s has been successfully installed").printf (get_name ()));
863 notification.set_icon (new ThemedIcon ("system-software-install"));
864@@ -121,6 +128,7 @@
865
866 application.send_notification ("installed", notification);
867 }
868+
869 return true;
870 }
871
872@@ -131,6 +139,7 @@
873 if (state != State.INSTALLED) {
874 return false;
875 }
876+
877 return yield perform_operation (State.REMOVING, State.NOT_INSTALLED, State.INSTALLED);
878 }
879
880@@ -144,6 +153,7 @@
881 } finally {
882 clean_up_package_operation (exit_status, after_success, after_fail);
883 }
884+
885 return (exit_status == Pk.Exit.SUCCESS);
886 }
887
888@@ -156,7 +166,7 @@
889 }
890
891 private async Pk.Exit perform_package_operation () throws GLib.Error {
892- Pk.ProgressCallback cb = change_information.ProgressCallback;
893+ Pk.ProgressCallback cb = change_information.progress_callback;
894 var client = AppCenterCore.Client.get_default ();
895 switch (state) {
896 case State.UPDATING:
897@@ -184,31 +194,39 @@
898 }
899
900 public string? get_name () {
901+ if (name != null) {
902+ return name;
903+ }
904+
905 var _name = component.get_name ();
906 if (_name != null) {
907- return _name;
908- }
909-
910- var package = find_package ();
911- if (package != null) {
912- return package.get_name ();
913- }
914-
915- return null;
916+ name = _name;
917+ } else {
918+ var package = find_package ();
919+ if (package != null) {
920+ name = package.get_name ();
921+ }
922+ }
923+
924+ return name;
925 }
926
927 public string? get_summary () {
928- var summary = component.get_summary ();
929 if (summary != null) {
930 return summary;
931 }
932
933- var package = find_package ();
934- if (package != null) {
935- return package.get_summary ();
936+ var _summary = component.get_summary ();
937+ if (_summary != null) {
938+ summary = _summary;
939+ } else {
940+ var package = find_package ();
941+ if (package != null) {
942+ summary = package.get_summary ();
943+ }
944 }
945
946- return null;
947+ return summary;
948 }
949
950 public string get_progress_description () {
951@@ -265,6 +283,10 @@
952 }
953
954 public string? get_version () {
955+ if (version != null) {
956+ return version;
957+ }
958+
959 var package = find_package ();
960 if (package != null) {
961 string returned = package.get_version ();
962@@ -275,10 +297,10 @@
963 returned = returned.split (":", 2)[1];
964 }
965
966- return returned;
967+ version = returned;
968 }
969
970- return null;
971+ return version;
972 }
973
974 private Pk.Package? find_package (bool installed = false) {
975@@ -294,7 +316,7 @@
976
977 return AppCenterCore.Client.get_default ().get_app_package (component.get_pkgnames ()[0], filter);
978 } catch (Error e) {
979- critical (e.message);
980+ warning (e.message);
981 return null;
982 }
983 }
984
985=== modified file 'src/Core/Task.vala'
986--- src/Core/Task.vala 2016-07-18 21:16:57 +0000
987+++ src/Core/Task.vala 2016-10-13 21:30:22 +0000
988@@ -18,11 +18,7 @@
989 * Authored by: Corentin Noël <corentin@elementary.io>
990 */
991
992-public class AppCenter.Task : Pk.Task {
993- public Task () {
994-
995- }
996-
997+public class AppCenterCore.Task : Pk.Task {
998 public override void untrusted_question (uint request, Pk.Results results) {
999 user_accepted (request);
1000 }
1001
1002=== modified file 'src/MainWindow.vala'
1003--- src/MainWindow.vala 2016-10-07 19:18:16 +0000
1004+++ src/MainWindow.vala 2016-10-13 21:30:22 +0000
1005@@ -14,7 +14,20 @@
1006 * with this program. If not, see http://www.gnu.org/licenses/.
1007 */
1008
1009+
1010+// Helper method for easier code reading
1011+public static void set_widget_visible (Gtk.Widget widget, bool visible) {
1012+ widget.no_show_all = !visible;
1013+ if (visible) {
1014+ widget.show_all ();
1015+ } else {
1016+ widget.hide ();
1017+ }
1018+}
1019+
1020 public class AppCenter.MainWindow : Gtk.ApplicationWindow {
1021+ public static Views.InstalledView installed_view { get; private set; }
1022+
1023 private Gtk.Revealer view_mode_revealer;
1024 private Gtk.Stack custom_title_stack;
1025 private Gtk.Label category_header;
1026@@ -29,16 +42,25 @@
1027 private Gtk.Stack button_stack;
1028 private ulong task_finished_connection = 0U;
1029 private Gee.Deque<string> return_button_history;
1030-
1031- public static Views.InstalledView installed_view { get; private set; }
1032
1033 public MainWindow (Gtk.Application app) {
1034 Object (application: app);
1035+ app.set_accels_for_action ("win.go-back", {"<Alt>Left"});
1036+ }
1037+
1038+ construct {
1039+ icon_name = "system-software-install";
1040+ title = _("AppCenter");
1041+ window_position = Gtk.WindowPosition.CENTER;
1042+
1043+ var go_back = new SimpleAction ("go-back", null);
1044+ go_back.activate.connect (view_return);
1045+ add_action (go_back);
1046
1047 weak Gtk.IconTheme default_theme = Gtk.IconTheme.get_default ();
1048 default_theme.add_resource_path ("/org/pantheon/appcenter/icons");
1049
1050- unowned Settings saved_state = Settings.get_default ();
1051+ unowned AppCenter.Settings saved_state = AppCenter.Settings.get_default ();
1052 set_default_size (saved_state.window_width, saved_state.window_height);
1053
1054 // Maximize window if necessary
1055@@ -50,60 +72,17 @@
1056 break;
1057 }
1058
1059- view_mode.selected = 0;
1060- search_entry.grab_focus_without_selecting ();
1061-
1062- var go_back = new SimpleAction ("go-back", null);
1063- go_back.activate.connect (view_return);
1064- add_action (go_back);
1065- app.set_accels_for_action ("win.go-back", {"<Alt>Left"});
1066-
1067- search_entry.search_changed.connect (() => trigger_search ());
1068-
1069- view_mode.notify["selected"].connect (() => {
1070- switch (view_mode.selected) {
1071- case 0:
1072- stack.set_visible_child (category_view);
1073- break;
1074- default:
1075- stack.set_visible_child (installed_view);
1076- break;
1077- }
1078- });
1079-
1080- search_entry.key_press_event.connect ((event) => {
1081- if (event.keyval == Gdk.Key.Escape) {
1082- search_entry.text = "";
1083- return true;
1084- }
1085-
1086- return false;
1087- });
1088-
1089- return_button.clicked.connect (view_return);
1090- search_all_button.clicked.connect (search_all_apps);
1091-
1092- installed_view.get_apps.begin ();
1093-
1094- category_view.subview_entered.connect (view_opened);
1095- installed_view.subview_entered.connect (view_opened);
1096- search_view.subview_entered.connect (view_opened);
1097- }
1098-
1099- construct {
1100- icon_name = "system-software-install";
1101- title = _("AppCenter");
1102- window_position = Gtk.WindowPosition.CENTER;
1103-
1104 return_button = new Gtk.Button ();
1105 return_button.no_show_all = true;
1106 return_button.get_style_context ().add_class ("back-button");
1107 return_button_history = new Gee.LinkedList<string> ();
1108-
1109+ return_button.clicked.connect (view_return);
1110+
1111 search_all_button = new Gtk.Button.with_label (_("Search Apps"));
1112 search_all_button.no_show_all = true;
1113 search_all_button.get_style_context ().add_class ("back-button");
1114-
1115+ search_all_button.clicked.connect (search_all_apps);
1116+
1117 button_stack = new Gtk.Stack ();
1118 button_stack.add (return_button);
1119 button_stack.add (search_all_button);
1120@@ -112,6 +91,17 @@
1121 view_mode = new Granite.Widgets.ModeButton ();
1122 view_mode.append_text (_("Categories"));
1123 view_mode.append_text (C_("view", "Updates"));
1124+ view_mode.selected = 0;
1125+ view_mode.notify["selected"].connect (() => {
1126+ switch (view_mode.selected) {
1127+ case 0:
1128+ stack.set_visible_child (category_view);
1129+ break;
1130+ default:
1131+ stack.set_visible_child (installed_view);
1132+ break;
1133+ }
1134+ });
1135
1136 view_mode_revealer = new Gtk.Revealer ();
1137 view_mode_revealer.reveal_child = true;
1138@@ -128,6 +118,15 @@
1139
1140 search_entry = new Gtk.SearchEntry ();
1141 search_entry.placeholder_text = _("Search Apps");
1142+ search_entry.search_changed.connect (() => trigger_search ());
1143+ search_entry.key_press_event.connect ((event) => {
1144+ if (event.keyval == Gdk.Key.Escape) {
1145+ search_entry.text = "";
1146+ return true;
1147+ }
1148+
1149+ return false;
1150+ });
1151
1152 /* HeaderBar */
1153 headerbar = new Gtk.HeaderBar ();
1154@@ -139,8 +138,13 @@
1155 set_titlebar (headerbar);
1156
1157 category_view = new Views.CategoryView ();
1158+ category_view.subview_entered.connect (view_opened);
1159+
1160 installed_view = new Views.InstalledView ();
1161+ installed_view.subview_entered.connect (view_opened);
1162+
1163 search_view = new Views.SearchView ();
1164+ search_view.subview_entered.connect (view_opened);
1165
1166 stack = new Gtk.Stack ();
1167 stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT;
1168@@ -148,6 +152,17 @@
1169 stack.add (installed_view);
1170 stack.add (search_view);
1171
1172+ var provider = new Gtk.CssProvider ();
1173+ try {
1174+ provider.load_from_data (CATEGORIES_STYLE_CSS, CATEGORIES_STYLE_CSS.length);
1175+ Gtk.StyleContext.add_provider_for_screen (get_screen (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
1176+ } catch (Error e) {
1177+ critical (e.message);
1178+ }
1179+
1180+ search_entry.grab_focus_without_selecting ();
1181+ installed_view.get_apps.begin ();
1182+
1183 add (stack);
1184 }
1185
1186@@ -155,9 +170,11 @@
1187 int window_width;
1188 int window_height;
1189 get_size (out window_width, out window_height);
1190- unowned Settings saved_state = Settings.get_default ();
1191+
1192+ unowned AppCenter.Settings saved_state = AppCenter.Settings.get_default ();
1193 saved_state.window_width = window_width;
1194 saved_state.window_height = window_height;
1195+
1196 if (is_maximized) {
1197 saved_state.window_state = Settings.WindowState.MAXIMIZED;
1198 } else {
1199@@ -237,6 +254,7 @@
1200 if (return_button_history.is_empty || return_button_history.peek_head () != return_name) {
1201 return_button_history.offer_head (return_name);
1202 }
1203+
1204 return_button.label = return_name;
1205 return_button.no_show_all = false;
1206 return_button.show_all ();
1207@@ -249,6 +267,7 @@
1208
1209 search_entry.sensitive = allow_search;
1210 search_entry.grab_focus_without_selecting ();
1211+
1212 if (stack.visible_child == category_view && category_view.currently_viewed_category != null) {
1213 search_entry.placeholder_text = _("Search %s").printf (category_view.currently_viewed_category.get_name ());
1214 }
1215@@ -270,6 +289,7 @@
1216 if (stack.visible_child == category_view) {
1217 search_entry.placeholder_text = _("Search Apps");
1218 }
1219+
1220 search_entry.sensitive = true;
1221 search_entry.grab_focus_without_selecting ();
1222
1223
1224=== modified file 'src/Settings.vala'
1225--- src/Settings.vala 2015-11-05 16:52:40 +0000
1226+++ src/Settings.vala 2016-10-13 21:30:22 +0000
1227@@ -40,10 +40,12 @@
1228 public WindowState window_state { get; set; }
1229 public bool developer_mode { get; set; }
1230
1231- private static Settings main_settings;
1232- public static unowned Settings get_default () {
1233- if (main_settings == null)
1234+ private static Settings? main_settings;
1235+ public static unowned Settings? get_default () {
1236+ if (main_settings == null) {
1237 main_settings = new Settings ();
1238+ }
1239+
1240 return main_settings;
1241 }
1242
1243
1244=== modified file 'src/Views/AppInfoView.vala'
1245--- src/Views/AppInfoView.vala 2016-09-08 09:52:03 +0000
1246+++ src/Views/AppInfoView.vala 2016-10-13 21:30:22 +0000
1247@@ -20,14 +20,14 @@
1248
1249 namespace AppCenter.Views {
1250 public class AppInfoView : AppCenter.AbstractAppContainer {
1251- Gtk.Image app_screenshot;
1252- Gtk.Stack screenshot_stack;
1253- Gtk.Label app_screenshot_not_found;
1254- Gtk.Label app_version;
1255- Gtk.TextView app_description;
1256- Gtk.ListBox extension_box;
1257- Gtk.Label extension_label;
1258- Gtk.Grid content_grid;
1259+ private Gtk.Image app_screenshot;
1260+ private Gtk.Stack screenshot_stack;
1261+ private Gtk.Label app_screenshot_not_found;
1262+ private Gtk.Label app_version;
1263+ private Gtk.TextView app_description;
1264+ private Gtk.ListBox extension_box;
1265+ private Gtk.Label extension_label;
1266+ private Gtk.Grid content_grid;
1267
1268 construct {
1269 image.margin_top = 12;
1270@@ -46,9 +46,11 @@
1271 app_screenshot_spinner.active = true;
1272
1273 app_screenshot_not_found = new Gtk.Label (_("Screenshot Not Available"));
1274- app_screenshot_not_found.get_style_context ().add_class (Gtk.STYLE_CLASS_BACKGROUND);
1275- app_screenshot_not_found.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL);
1276- app_screenshot_not_found.get_style_context ().add_class ("h2");
1277+
1278+ var style_context = app_screenshot_not_found.get_style_context ();
1279+ style_context.add_class (Gtk.STYLE_CLASS_BACKGROUND);
1280+ style_context.add_class (Gtk.STYLE_CLASS_DIM_LABEL);
1281+ style_context.add_class ("h2");
1282
1283 screenshot_stack = new Gtk.Stack ();
1284 screenshot_stack.margin_bottom = 24;
1285@@ -57,7 +59,6 @@
1286 screenshot_stack.add (app_screenshot);
1287 screenshot_stack.add (app_screenshot_not_found);
1288
1289- package_name = new Gtk.Label (null);
1290 package_name.margin_top = 12;
1291 package_name.xalign = 0;
1292 package_name.get_style_context ().add_class ("h1");
1293@@ -68,14 +69,18 @@
1294 app_version.xalign = 0;
1295 app_version.hexpand = true;
1296 app_version.valign = Gtk.Align.CENTER;
1297- app_version.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL);
1298- app_version.get_style_context ().add_class ("h3");
1299-
1300- package_summary = new Gtk.Label (null);
1301+
1302+ style_context = app_version.get_style_context ();
1303+ style_context.add_class (Gtk.STYLE_CLASS_DIM_LABEL);
1304+ style_context.add_class ("h3");
1305+
1306 package_summary.xalign = 0;
1307 package_summary.valign = Gtk.Align.START;
1308- package_summary.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL);
1309- package_summary.get_style_context ().add_class ("h2");
1310+
1311+ style_context = package_summary.get_style_context ();
1312+ style_context.add_class (Gtk.STYLE_CLASS_DIM_LABEL);
1313+ style_context.add_class ("h2");
1314+
1315 package_summary.wrap = true;
1316 package_summary.set_lines (3);
1317 package_summary.wrap_mode = Pango.WrapMode.WORD_CHAR;
1318@@ -96,6 +101,23 @@
1319 content_grid.add (screenshot_stack);
1320 content_grid.add (app_description);
1321
1322+ parse_description (package.component.get_description ());
1323+
1324+ if (package.component.get_extensions ().length > 0) {
1325+ extension_box = new Gtk.ListBox ();
1326+ extension_box.selection_mode = Gtk.SelectionMode.NONE;
1327+
1328+ extension_label = new Gtk.Label ("<b>" + _("Extensions:") + "</b>");
1329+ extension_label.margin_top = 12;
1330+ extension_label.use_markup = true;
1331+ extension_label.get_style_context ().add_class ("h3");
1332+ extension_label.halign = Gtk.Align.START;
1333+
1334+ content_grid.add (extension_label);
1335+ content_grid.add (extension_box);
1336+ load_extensions.begin ();
1337+ }
1338+
1339 var scrolled = new Gtk.ScrolledWindow (null, null);
1340 scrolled.hscrollbar_policy = Gtk.PolicyType.NEVER;
1341 scrolled.expand = true;
1342@@ -116,28 +138,7 @@
1343 }
1344
1345 public AppInfoView (AppCenterCore.Package package) {
1346- this.package = package;
1347- set_up_package (128);
1348-
1349- parse_description (package.component.get_description ());
1350-
1351- if (package.component.get_extensions ().length > 0) {
1352- extension_box = new Gtk.ListBox ();
1353- extension_box.selection_mode = Gtk.SelectionMode.NONE;
1354-
1355- extension_label = new Gtk.Label ("<b>" + _("Extensions:") + "</b>");
1356- extension_label.margin_top = 12;
1357- extension_label.use_markup = true;
1358- extension_label.get_style_context ().add_class ("h3");
1359- extension_label.halign = Gtk.Align.START;
1360-
1361- content_grid.add (extension_label);
1362- content_grid.add (extension_box);
1363- load_extensions.begin ();
1364- }
1365-
1366- action_button.set_suggested_action_header ();
1367- uninstall_button.set_destructive_action_header ();
1368+ Object (package: package, icon_size: 128);
1369 }
1370
1371 private async void load_extensions () {
1372@@ -187,12 +188,15 @@
1373
1374 // We need to first download the screenshot locally so that it doesn't freeze the interface.
1375 private void set_screenshot (string url) {
1376- var ret = GLib.DirUtils.create_with_parents (GLib.Environment.get_tmp_dir () + Path.DIR_SEPARATOR_S + ".appcenter", 0755);
1377+ string tmp_dir = GLib.Environment.get_tmp_dir ();
1378+ string tmp_path = Path.build_filename (tmp_dir, ".appcenter");
1379+
1380+ var ret = GLib.DirUtils.create_with_parents (tmp_path, 0755);
1381 if (ret == -1) {
1382- critical ("Error creating the temporary folder: GFileError #%d", GLib.FileUtils.error_from_errno (GLib.errno));
1383+ warning ("Error creating the temporary folder: GFileError #%d", GLib.FileUtils.error_from_errno (GLib.errno));
1384 }
1385
1386- string path = Path.build_path (Path.DIR_SEPARATOR_S, GLib.Environment.get_tmp_dir (), ".appcenter", "XXXXXX");
1387+ string path = Path.build_filename (tmp_dir, ".appcenter", "XXXXXX");
1388 File fileimage;
1389 var fd = GLib.FileUtils.mkstemp (path);
1390 if (fd != -1) {
1391@@ -201,7 +205,7 @@
1392 try {
1393 source.copy (fileimage, GLib.FileCopyFlags.OVERWRITE);
1394 } catch (Error e) {
1395- debug (e.message);
1396+ warning (e.message);
1397 // The file is likely to not being found.
1398 screenshot_stack.visible_child = app_screenshot_not_found;
1399 return;
1400@@ -209,9 +213,9 @@
1401
1402 GLib.FileUtils.close (fd);
1403 } else {
1404- critical ("Error create the temporary file: GFileError #%d", GLib.FileUtils.error_from_errno (GLib.errno));
1405+ warning ("Error create the temporary file: GFileError #%d", GLib.FileUtils.error_from_errno (GLib.errno));
1406 fileimage = File.new_for_uri (url);
1407- if (fileimage.query_exists () == false) {
1408+ if (!fileimage.query_exists ()) {
1409 screenshot_stack.visible_child = app_screenshot_not_found;
1410 return;
1411 }
1412
1413=== modified file 'src/Views/AppListView.vala'
1414--- src/Views/AppListView.vala 2016-09-17 19:28:03 +0000
1415+++ src/Views/AppListView.vala 2016-10-13 21:30:22 +0000
1416@@ -22,11 +22,8 @@
1417 namespace AppCenter.Views {
1418 /** AppList for Category and Search Views. Sorts by name and does not show Uninstall Button **/
1419 public class AppListView : AbstractAppList {
1420-
1421- public AppListView () {}
1422-
1423- protected override Widgets.AppListRow make_row (AppCenterCore.Package package) {
1424- return (Widgets.AppListRow)(new Widgets.PackageRow (package, action_button_group, false));
1425+ protected override Widgets.AppListRow create_row (AppCenterCore.Package package) {
1426+ return new Widgets.PackageRow (package, action_button_group, false);
1427 }
1428 }
1429
1430@@ -41,6 +38,7 @@
1431 private bool apps_remaining_started = false;
1432 private GLib.Mutex update_mutex;
1433 private uint apps_done = 0;
1434+ private uint grid_timeout_id = 0;
1435 private Gee.LinkedList<AppCenterCore.Package> apps_to_update;
1436 private AppCenterCore.Package first_package;
1437 private SuspendControl sc;
1438@@ -50,6 +48,7 @@
1439 get {
1440 return _updating_cache;
1441 }
1442+
1443 set {
1444 if (_updating_cache != value) {
1445 _updating_cache = value;
1446@@ -60,9 +59,9 @@
1447
1448 construct {
1449 updates_on_top = true;
1450+ _updating_cache = true;
1451
1452- update_all_button = new Widgets.AppActionButton (_("Update All"));
1453- update_all_button.set_suggested_action_header ();
1454+ update_all_button = new Widgets.AppActionButton (_("Update All"), Gtk.STYLE_CLASS_SUGGESTED_ACTION);
1455 update_all_button.clicked.connect (on_update_all);
1456 update_all_button.no_show_all = true;
1457 action_button_group.add_widget (update_all_button);
1458@@ -81,14 +80,12 @@
1459 sc = new SuspendControl ();
1460 }
1461
1462- public AppListUpdateView () {
1463- _updating_cache = true;
1464+ protected override void list_changed () {
1465+ update_headers ();
1466 }
1467
1468- protected override void after_add_remove_change_row () {update_headers ();}
1469-
1470- protected override Widgets.AppListRow make_row (AppCenterCore.Package package) {
1471- return (Widgets.AppListRow)(new Widgets.PackageRow (package, action_button_group, false));
1472+ protected override Widgets.AppListRow create_row (AppCenterCore.Package package) {
1473+ return new Widgets.PackageRow (package, action_button_group, false);
1474 }
1475
1476 protected override void on_package_changing (AppCenterCore.Package package, bool is_changing) {
1477@@ -146,7 +143,7 @@
1478 if (row is Widgets.PackageRow) {
1479 ((Widgets.PackageRow) row).set_action_sensitive (false);
1480 }
1481- };
1482+ }
1483
1484 // Update all updateable apps
1485 if (apps_to_update.size > 0) {
1486@@ -155,9 +152,7 @@
1487
1488 first_package = apps_to_update[0];
1489 first_package.info_changed.connect_after (after_first_package_info_changed);
1490- first_package.update.begin (() => {
1491- on_app_update_end ();
1492- });
1493+ first_package.update.begin (() => on_app_update_end ());
1494 } else {
1495 updating_all_apps = false;
1496 }
1497@@ -177,11 +172,10 @@
1498 if (status != Pk.Status.CANCEL) { /* must be running */
1499 apps_remaining_started = true;
1500 for (int i = 1; i < apps_to_update.size; i++) {
1501- apps_to_update[i].update.begin (() => {
1502- on_app_update_end ();
1503- });
1504+ apps_to_update[i].update.begin (() => on_app_update_end ());
1505 }
1506- } else { /* it was aborted - do not start updating the rest */
1507+ } else {
1508+ /* it was aborted - do not start updating the rest */
1509 finish_updating_all_apps ();
1510 }
1511 }
1512@@ -195,6 +189,7 @@
1513 finish_updating_all_apps ();
1514 }
1515 }
1516+
1517 update_mutex.unlock ();
1518 }
1519
1520@@ -209,20 +204,21 @@
1521 Idle.add_full (GLib.Priority.LOW, () => {
1522 foreach (var row in list_box.get_children ()) {
1523 if (row is Widgets.PackageRow) {
1524- var pkg_row = ((Widgets.PackageRow)(row));
1525- var pkg = pkg_row.get_package ();
1526+ var package_row = (Widgets.PackageRow) row;
1527+ var package = package_row.get_package ();
1528
1529 /* clear update information if the package was successfully updated */
1530 /* This information is refreshed by Client on start up (log in) or at daily intervals */
1531 /* TODO: Implement refresh on demand (or on list display?) */
1532- if (pkg.state == AppCenterCore.Package.State.INSTALLED) {
1533- pkg.change_information.clear_update_info ();
1534+ if (package.state == AppCenterCore.Package.State.INSTALLED) {
1535+ package.change_information.clear_update_info ();
1536 }
1537
1538- pkg_row.set_action_sensitive (true);
1539- pkg_row.changed ();
1540+ package_row.set_action_sensitive (true);
1541+ package_row.changed ();
1542 }
1543 }
1544+
1545 return GLib.Source.REMOVE;
1546 });
1547 }
1548@@ -232,7 +228,6 @@
1549 schedule_header_update ();
1550 }
1551
1552- uint grid_timeout_id = 0;
1553 private void schedule_header_update () {
1554 if (grid_timeout_id > 0) {
1555 return;
1556
1557=== modified file 'src/Views/CategoryView.vala'
1558--- src/Views/CategoryView.vala 2016-09-24 21:35:11 +0000
1559+++ src/Views/CategoryView.vala 2016-10-13 21:30:22 +0000
1560@@ -21,16 +21,12 @@
1561 using AppCenterCore;
1562
1563 public class AppCenter.Views.CategoryView : View {
1564+ public AppStream.Category? currently_viewed_category;
1565+
1566 private Gtk.FlowBox category_flow;
1567 private Gtk.ScrolledWindow category_scrolled;
1568 private string current_category;
1569
1570- public AppStream.Category currently_viewed_category;
1571-
1572- public CategoryView () {
1573-
1574- }
1575-
1576 construct {
1577 category_flow = new Gtk.FlowBox ();
1578 category_flow.margin = 12;
1579@@ -50,8 +46,8 @@
1580 });
1581
1582 category_flow.set_sort_func ((child1, child2) => {
1583- var item1 = child1 as Widgets.CategoryItem;
1584- var item2 = child2 as Widgets.CategoryItem;
1585+ var item1 = (Widgets.CategoryItem) child1;
1586+ var item2 = (Widgets.CategoryItem) child2;
1587 if (item1 != null && item2 != null) {
1588 return item1.app_category.name.collate (item2.app_category.name);
1589 }
1590@@ -99,7 +95,6 @@
1591 foreach (var app in apps) {
1592 app_list_view.add_package (app);
1593 }
1594-
1595 }
1596
1597 private void get_app_categories () {
1598@@ -121,9 +116,11 @@
1599 var category = new AppStream.Category ();
1600 category.set_name (_("Audio"));
1601 category.set_icon ("applications-audio-symbolic");
1602+
1603 var categories = new Gee.LinkedList<string> ();
1604 categories.add ("Audio");
1605 category.set_data<Gee.LinkedList> ("categories", categories);
1606+
1607 var item = new Widgets.CategoryItem (category);
1608 item.add_category_class ("audio");
1609
1610@@ -133,10 +130,12 @@
1611 private Widgets.CategoryItem get_development_category () {
1612 var category = new AppStream.Category ();
1613 category.set_name (_("Development"));
1614+
1615 var categories = new Gee.LinkedList<string> ();
1616 categories.add ("Development");
1617 categories.add ("IDE");
1618 category.set_data<Gee.LinkedList> ("categories", categories);
1619+
1620 var item = new Widgets.CategoryItem (category);
1621 item.add_category_class ("development");
1622
1623@@ -147,9 +146,11 @@
1624 var category = new AppStream.Category ();
1625 category.set_name (_("Accessories"));
1626 category.set_icon ("applications-accessories");
1627+
1628 var categories = new Gee.LinkedList<string> ();
1629 categories.add ("Utility");
1630 category.set_data<Gee.LinkedList> ("categories", categories);
1631+
1632 var item = new Widgets.CategoryItem (category);
1633 item.add_category_class ("accessories");
1634
1635@@ -160,9 +161,11 @@
1636 var category = new AppStream.Category ();
1637 category.set_name (_("Office"));
1638 category.set_icon ("applications-office-symbolic");
1639+
1640 var categories = new Gee.LinkedList<string> ();
1641 categories.add ("Office");
1642 category.set_data<Gee.LinkedList> ("categories", categories);
1643+
1644 var item = new Widgets.CategoryItem (category);
1645 item.add_category_class ("office");
1646
1647@@ -173,9 +176,11 @@
1648 var category = new AppStream.Category ();
1649 category.set_name (_("System"));
1650 category.set_icon ("applications-system");
1651+
1652 var categories = new Gee.LinkedList<string> ();
1653 categories.add ("System");
1654 category.set_data<Gee.LinkedList> ("categories", categories);
1655+
1656 var item = new Widgets.CategoryItem (category);
1657 item.add_category_class ("system");
1658
1659@@ -186,9 +191,11 @@
1660 var category = new AppStream.Category ();
1661 category.set_name (_("Video"));
1662 category.set_icon ("applications-video-symbolic");
1663+
1664 var categories = new Gee.LinkedList<string> ();
1665 categories.add ("Video");
1666 category.set_data<Gee.LinkedList> ("categories", categories);
1667+
1668 var item = new Widgets.CategoryItem (category);
1669 item.add_category_class ("video");
1670
1671@@ -198,9 +205,11 @@
1672 private Widgets.CategoryItem get_graphics_category () {
1673 var category = new AppStream.Category ();
1674 category.set_name (_("Graphics"));
1675+
1676 var categories = new Gee.LinkedList<string> ();
1677 categories.add ("Graphics");
1678 category.set_data<Gee.LinkedList> ("categories", categories);
1679+
1680 var item = new Widgets.CategoryItem (category);
1681 item.add_category_class ("graphics");
1682
1683@@ -210,10 +219,12 @@
1684 private Widgets.CategoryItem get_games_category () {
1685 var category = new AppStream.Category ();
1686 category.set_name (_("Games"));
1687+
1688 var categories = new Gee.LinkedList<string> ();
1689 categories.add ("Game");
1690 category.set_data<Gee.LinkedList> ("categories", categories);
1691 category.set_icon ("applications-games-symbolic");
1692+
1693 var item = new Widgets.CategoryItem (category);
1694 item.add_category_class ("games");
1695
1696@@ -223,9 +234,11 @@
1697 private Widgets.CategoryItem get_education_category () {
1698 var category = new AppStream.Category ();
1699 category.set_name (_("Education"));
1700+
1701 var categories = new Gee.LinkedList<string> ();
1702 categories.add ("Education");
1703 category.set_data<Gee.LinkedList> ("categories", categories);
1704+
1705 var item = new Widgets.CategoryItem (category);
1706 item.add_category_class ("education");
1707
1708@@ -236,9 +249,11 @@
1709 var category = new AppStream.Category ();
1710 category.set_name (_("Internet"));
1711 category.set_icon ("applications-internet");
1712+
1713 var categories = new Gee.LinkedList<string> ();
1714 categories.add ("Network");
1715 category.set_data<Gee.LinkedList> ("categories", categories);
1716+
1717 var item = new Widgets.CategoryItem (category);
1718 item.add_category_class ("internet");
1719
1720@@ -248,9 +263,11 @@
1721 private Widgets.CategoryItem get_science_category () {
1722 var category = new AppStream.Category ();
1723 category.set_name (_("Science & Engineering"));
1724+
1725 var categories = new Gee.LinkedList<string> ();
1726 categories.add ("Science");
1727 category.set_data<Gee.LinkedList> ("categories", categories);
1728+
1729 var item = new Widgets.CategoryItem (category);
1730 item.add_category_class ("science");
1731
1732@@ -261,9 +278,11 @@
1733 var category = new AppStream.Category ();
1734 category.set_name (_("Universal Access"));
1735 category.set_icon ("applications-accessibility-symbolic");
1736+
1737 var categories = new Gee.LinkedList<string> ();
1738 categories.add ("Accessibility");
1739 category.set_data<Gee.LinkedList> ("categories", categories);
1740+
1741 var item = new Widgets.CategoryItem (category);
1742 item.add_category_class ("accessibility");
1743
1744
1745=== modified file 'src/Views/FeaturedView.vala'
1746--- src/Views/FeaturedView.vala 2015-10-30 17:53:09 +0000
1747+++ src/Views/FeaturedView.vala 2016-10-13 21:30:22 +0000
1748@@ -21,7 +21,7 @@
1749 using AppCenterCore;
1750
1751 public class AppCenter.Views.FeaturedView : Gtk.Grid {
1752- public FeaturedView () {
1753+ construct {
1754 halign = Gtk.Align.CENTER;
1755 column_homogeneous = true;
1756 column_spacing = 6;
1757@@ -39,7 +39,7 @@
1758 attach (left_featured, 0, 0, 1, 1);
1759 attach (right_featured, 1, 0, 1, 1);
1760 attach (rated_label, 0, 1, 1, 1);
1761- attach (latest_label, 1, 1, 1, 1);
1762+ attach (latest_label, 1, 1, 1, 1);
1763 }
1764
1765 private Gtk.Widget get_left_placeholder () {
1766
1767=== modified file 'src/Views/InstalledView.vala'
1768--- src/Views/InstalledView.vala 2016-09-22 14:10:06 +0000
1769+++ src/Views/InstalledView.vala 2016-10-13 21:30:22 +0000
1770@@ -21,22 +21,7 @@
1771 using AppCenterCore;
1772
1773 public class AppCenter.Views.InstalledView : View {
1774- AppListUpdateView app_list_view;
1775-
1776- public InstalledView () {
1777- var client = Client.get_default ();
1778- // We need this line in order to show the No Update view.
1779- client.updates_available.connect (() => {
1780- var package = Client.get_default ().os_updates;
1781- if (package.update_available) {
1782- app_list_view.add_package (package);
1783- }
1784-
1785- app_list_view.updating_cache = false;
1786- });
1787-
1788- client.bind_property ("updating-cache", app_list_view, "updating-cache", GLib.BindingFlags.DEFAULT);
1789- }
1790+ private AppListUpdateView app_list_view;
1791
1792 construct {
1793 app_list_view = new AppListUpdateView ();
1794@@ -45,6 +30,21 @@
1795 subview_entered (C_("view", "Updates"), false);
1796 show_package (package);
1797 });
1798+
1799+ unowned AppCenterCore.Client client = Client.get_default ();
1800+ client.bind_property ("updating-cache", app_list_view, "updating-cache", GLib.BindingFlags.DEFAULT);
1801+
1802+ // We need this line in order to show the No Update view.
1803+ client.updates_available.connect (on_updates_available);
1804+ }
1805+
1806+ private void on_updates_available (AppCenterCore.Client client) {
1807+ var package = client.os_updates;
1808+ if (package.update_available) {
1809+ app_list_view.add_package (package);
1810+ }
1811+
1812+ app_list_view.updating_cache = false;
1813 }
1814
1815 public override void return_clicked () {
1816@@ -64,6 +64,7 @@
1817
1818 public async void add_app (AppCenterCore.Package package) {
1819 unowned Client client = Client.get_default ();
1820+
1821 var installed_apps = yield client.get_installed_applications ();
1822 foreach (var app in installed_apps) {
1823 if (app == package) {
1824
1825=== modified file 'src/Views/SearchView.vala'
1826--- src/Views/SearchView.vala 2016-10-07 17:58:37 +0000
1827+++ src/Views/SearchView.vala 2016-10-13 21:30:22 +0000
1828@@ -21,21 +21,19 @@
1829 using AppCenterCore;
1830
1831 public class AppCenter.Views.SearchView : View {
1832- const int MAX_NUMBER_OF_SEARCH_RESULTS = 100;
1833- AppListView app_list_view;
1834-
1835- public SearchView () {
1836-
1837- }
1838+ private const int MAX_NUMBER_OF_SEARCH_RESULTS = 100;
1839+ private AppListView app_list_view;
1840
1841 construct {
1842 app_list_view = new AppListView ();
1843 add (app_list_view);
1844- app_list_view.show_app.connect ((package) => {
1845- /// TRANSLATORS: the name of the Search view
1846- subview_entered (C_("view", "Search"), false);
1847- show_package (package);
1848- });
1849+ app_list_view.show_app.connect (on_show_app);
1850+ }
1851+
1852+ private void on_show_app (AppCenterCore.Package package) {
1853+ /// TRANSLATORS: the name of the Search view
1854+ subview_entered (C_("view", "Search"), false);
1855+ show_package (package);
1856 }
1857
1858 public override void return_clicked () {
1859@@ -44,17 +42,20 @@
1860
1861 public async void search (string search_term, AppStream.Category? category) {
1862 app_list_view.clear ();
1863+
1864 unowned Client client = Client.get_default ();
1865 var found_apps = client.search_applications (search_term, category);
1866
1867- if (found_apps.size > 0) {
1868- var apps_array = found_apps.to_array ();
1869- int i = 0;
1870- while (i < apps_array.length && i < MAX_NUMBER_OF_SEARCH_RESULTS) {
1871- var app = apps_array[i];
1872- app_list_view.add_package (app);
1873- i++;
1874- }
1875+ if (found_apps.size <= 0) {
1876+ return;
1877+ }
1878+
1879+ var apps_array = found_apps.to_array ();
1880+ int i = 0;
1881+ while (i < apps_array.length && i < MAX_NUMBER_OF_SEARCH_RESULTS) {
1882+ var app = apps_array[i];
1883+ app_list_view.add_package (app);
1884+ i++;
1885 }
1886 }
1887 }
1888
1889=== modified file 'src/Views/View.vala'
1890--- src/Views/View.vala 2016-09-22 14:10:06 +0000
1891+++ src/Views/View.vala 2016-10-13 21:30:22 +0000
1892@@ -30,14 +30,15 @@
1893 public void show_package (AppCenterCore.Package package) {
1894 var pk_child = get_child_by_name (package.component.id);
1895 if (pk_child != null) {
1896- set_visible_child (pk_child);
1897+ visible_child = pk_child;
1898 return;
1899 }
1900
1901 var app_info_view = new Views.AppInfoView (package);
1902 app_info_view.show_all ();
1903 add_named (app_info_view, package.component.id);
1904- set_visible_child (app_info_view);
1905+ visible_child = app_info_view;
1906+
1907 Timeout.add (transition_duration, () => {
1908 app_info_view.load_more_content ();
1909 return Source.REMOVE;
1910
1911=== modified file 'src/Widgets/AppActionButton.vala'
1912--- src/Widgets/AppActionButton.vala 2016-09-01 09:30:52 +0000
1913+++ src/Widgets/AppActionButton.vala 2016-10-13 21:30:22 +0000
1914@@ -20,21 +20,18 @@
1915
1916 namespace AppCenter.Widgets {
1917 public class AppActionButton : Gtk.Button {
1918- public AppActionButton (string? _label) {
1919+ construct {
1920 valign = Gtk.Align.CENTER;
1921+ }
1922+
1923+ public AppActionButton (string? _label, string? style_class = null) {
1924 label = _label;
1925- }
1926-
1927- public void set_suggested_action_header () {
1928- var style_ctx = get_style_context ();
1929- style_ctx.add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
1930- style_ctx.add_class ("h3");
1931- }
1932-
1933- public void set_destructive_action_header () {
1934- var style_ctx = get_style_context ();
1935- style_ctx.add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
1936- style_ctx.add_class ("h3");
1937+
1938+ if (style_class != null) {
1939+ var style_context = get_style_context ();
1940+ style_context.add_class (style_class);
1941+ style_context.add_class ("h3");
1942+ }
1943 }
1944 }
1945 }
1946
1947=== modified file 'src/Widgets/AppCellRenderer.vala'
1948--- src/Widgets/AppCellRenderer.vala 2015-11-17 18:35:04 +0000
1949+++ src/Widgets/AppCellRenderer.vala 2016-10-13 21:30:22 +0000
1950@@ -21,37 +21,35 @@
1951 using AppCenterCore;
1952
1953 public class AppCenter.Widgets.AppCellRenderer : Gtk.CellRenderer {
1954+ private const int MARGIN = 6;
1955+ private const int ICON_SIZE = 48;
1956+ private const int ACTION_ICON_SIZE = 24;
1957
1958 /* icon property set by the tree column */
1959 public AppCenterCore.Package package { get; set; }
1960 public Gdk.Pixbuf icon { get; set; }
1961
1962 private Gdk.Pixbuf update_icon;
1963- private const int MARGIN = 6;
1964- private const int ICON_SIZE = 48;
1965- private const int ACTION_ICON_SIZE = 24;
1966 private Gtk.Label title_label;
1967 private Gtk.Label summary_label;
1968
1969- public AppCellRenderer () {
1970-
1971- }
1972-
1973 construct {
1974 title_label = new Gtk.Label (null);
1975 title_label.get_style_context ().add_class ("h3");
1976+
1977 summary_label = new Gtk.Label (null);
1978+
1979 try {
1980 update_icon = Gtk.IconTheme.get_default ().load_icon ("software-update-available-symbolic", ACTION_ICON_SIZE, Gtk.IconLookupFlags.GENERIC_FALLBACK);
1981 } catch (Error e) {
1982- critical (e.message);
1983+ warning (e.message);
1984 }
1985 }
1986
1987 public override void get_size (Gtk.Widget widget, Gdk.Rectangle? cell_area, out int x_offset, out int y_offset, out int width, out int height) {
1988 x_offset = 0;
1989 y_offset = 0;
1990- width = 50;
1991+ width = ICON_SIZE + 2;
1992 height = ICON_SIZE + 2 * MARGIN;
1993 }
1994
1995@@ -104,13 +102,16 @@
1996
1997 private void draw_label (Cairo.Context cr, Gtk.Widget widget, Gtk.Label label, int x, int y, string title, int width, out int height) {
1998 cr.save ();
1999+
2000 var style_context = widget.get_style_context ();
2001+
2002 var label_style_context = label.get_style_context ();
2003 label_style_context.parent = style_context.parent;
2004 label_style_context.set_state (style_context.get_state ());
2005
2006 var label_layout = label.create_pango_layout (title);
2007 label_layout.set_width (width * Pango.SCALE);
2008+
2009 if (style_context.direction == Gtk.TextDirection.RTL) {
2010 label_layout.set_ellipsize (Pango.EllipsizeMode.START);
2011 label_layout.set_alignment (Pango.Alignment.RIGHT);
2012@@ -122,6 +123,7 @@
2013 int label_width;
2014 label_layout.get_pixel_size (out label_width, out height);
2015 label_style_context.render_layout (cr, x, y, label_layout);
2016+
2017 cr.restore ();
2018 }
2019
2020
2021=== modified file 'src/Widgets/AppListRow.vala'
2022--- src/Widgets/AppListRow.vala 2016-09-17 19:28:03 +0000
2023+++ src/Widgets/AppListRow.vala 2016-10-13 21:30:22 +0000
2024@@ -24,8 +24,12 @@
2025 public interface AppListRow : Gtk.ListBoxRow {
2026 public abstract bool get_update_available ();
2027 public abstract bool get_is_os_updates ();
2028- public abstract string get_name_label ();
2029- public abstract bool has_package ();
2030+ public abstract string? get_name_label ();
2031+
2032+ public bool has_package () {
2033+ return get_package () != null;
2034+ }
2035+
2036 public abstract AppCenterCore.Package? get_package ();
2037 }
2038 }
2039
2040=== modified file 'src/Widgets/CategoryItem.vala'
2041--- src/Widgets/CategoryItem.vala 2016-07-11 19:13:28 +0000
2042+++ src/Widgets/CategoryItem.vala 2016-10-13 21:30:22 +0000
2043@@ -18,7 +18,7 @@
2044 * Authored by: Corentin Noël <corentin@elementary.io>
2045 */
2046
2047-const string CATEGORIES_STYLE_CSS = """
2048+public const string CATEGORIES_STYLE_CSS = """
2049 .category {
2050 background-image: linear-gradient(to bottom,
2051 #fafafa,
2052@@ -233,16 +233,6 @@
2053 show_all ();
2054 }
2055
2056- static construct {
2057- var provider = new Gtk.CssProvider ();
2058- try {
2059- provider.load_from_data (CATEGORIES_STYLE_CSS, CATEGORIES_STYLE_CSS.length);
2060- Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
2061- } catch (Error e) {
2062- critical (e.message);
2063- }
2064- }
2065-
2066 construct {
2067 grid = new Gtk.Grid ();
2068 grid.orientation = Gtk.Orientation.HORIZONTAL;
2069
2070=== modified file 'src/Widgets/FeaturedButton.vala'
2071--- src/Widgets/FeaturedButton.vala 2015-11-13 02:43:52 +0000
2072+++ src/Widgets/FeaturedButton.vala 2016-10-13 21:30:22 +0000
2073@@ -37,22 +37,22 @@
2074 .featured:dir(rtl) {
2075 background: linear-gradient(to right,rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0));
2076 }
2077- """;
2078+""";
2079
2080 const string COLORED_STYLE_CSS = """
2081 .colored {
2082 color: %s;
2083 }
2084- """;
2085+""";
2086
2087 public class AppCenter.Widgets.FeaturedButton : Gtk.Grid {
2088 public signal void clicked ();
2089- Gdk.RGBA background_color;
2090+ private Gdk.RGBA background_color;
2091
2092- Gtk.Label title_label;
2093- Gtk.Label summary_label;
2094- Gtk.Image icon_image;
2095- const int MARGIN = 6;
2096+ private Gtk.Label title_label;
2097+ private Gtk.Label summary_label;
2098+ private Gtk.Image icon_image;
2099+ private const int MARGIN = 6;
2100
2101 public FeaturedButton (Gdk.RGBA background_color, Gdk.RGBA text_color, string title, string summary, GLib.Icon icon) {
2102 this.background_color = background_color;
2103@@ -61,17 +61,20 @@
2104 icon_image.gicon = icon;
2105
2106 var provider = new Gtk.CssProvider ();
2107+
2108 try {
2109 var colored_css = COLORED_STYLE_CSS.printf (text_color.to_string ());
2110 provider.load_from_data (colored_css, colored_css.length);
2111- var context = title_label.get_style_context ();
2112- context.add_provider (provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
2113- context.add_class ("colored");
2114- context = summary_label.get_style_context ();
2115- context.add_provider (provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
2116- context.add_class ("colored");
2117+
2118+ var style_context = title_label.get_style_context ();
2119+ style_context.add_provider (provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
2120+ style_context.add_class ("colored");
2121+
2122+ style_context = summary_label.get_style_context ();
2123+ style_context.add_provider (provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
2124+ style_context.add_class ("colored");
2125 } catch (GLib.Error e) {
2126- critical (e.message);
2127+ warning (e.message);
2128 }
2129 }
2130
2131@@ -104,12 +107,13 @@
2132 attach (title_label, 1, 0, 1, 1);
2133 attach (summary_label, 1, 1, 1, 1);
2134
2135- var context = get_style_context ();
2136+ var style_context = get_style_context ();
2137 var provider = new Gtk.CssProvider ();
2138+
2139 try {
2140 provider.load_from_data (FEATURED_STYLE_CSS, FEATURED_STYLE_CSS.length);
2141- context.add_provider(provider, Gtk.STYLE_PROVIDER_PRIORITY_FALLBACK);
2142- context.add_class ("featured");
2143+ style_context.add_provider (provider, Gtk.STYLE_PROVIDER_PRIORITY_FALLBACK);
2144+ style_context.add_class ("featured");
2145 } catch (GLib.Error e) {
2146 critical (e.message);
2147 }
2148@@ -117,8 +121,8 @@
2149
2150 public override void get_preferred_height (out int minimum_height, out int natural_height) {
2151 base.get_preferred_height (out minimum_height, out natural_height);
2152- minimum_height += 2*MARGIN;
2153- natural_height += 2*MARGIN;
2154+ minimum_height += 2 * MARGIN;
2155+ natural_height += 2 * MARGIN;
2156 if (natural_height < 100) {
2157 natural_height = 100;
2158 }
2159@@ -126,8 +130,8 @@
2160
2161 public override void get_preferred_width (out int minimum_width, out int natural_width) {
2162 base.get_preferred_width (out minimum_width, out natural_width);
2163- minimum_width += 2*MARGIN;
2164- natural_width += 2*MARGIN;
2165+ minimum_width += 2 * MARGIN;
2166+ natural_width += 2 * MARGIN;
2167 if (natural_width < 350) {
2168 natural_width = 350;
2169 }
2170@@ -138,16 +142,17 @@
2171 return false;
2172 }
2173
2174-
2175 public override bool draw (Cairo.Context cr) {
2176 int width = get_allocated_width ();
2177 int height = get_allocated_height ();
2178
2179 cr.save ();
2180 cr.set_source_rgba (background_color.red, background_color.green, background_color.blue, background_color.alpha);
2181+
2182 int x = 0;
2183 int y = 0;
2184 double radius = 3;
2185+
2186 cr.move_to (x + radius, y);
2187 cr.arc (x + width - radius, y + radius, radius, Math.PI * 1.5, Math.PI * 2);
2188 cr.arc (x + width - radius, y + height - radius, radius, 0, Math.PI_2);
2189
2190=== modified file 'src/Widgets/PackageRow.vala'
2191--- src/Widgets/PackageRow.vala 2016-09-17 19:28:03 +0000
2192+++ src/Widgets/PackageRow.vala 2016-10-13 21:30:22 +0000
2193@@ -20,14 +20,13 @@
2194
2195 namespace AppCenter.Widgets {
2196 public class PackageRow : Gtk.ListBoxRow, AppListRow {
2197- PackageRowGrid grid;
2198+ private PackageRowGrid grid;
2199
2200 public PackageRow (AppCenterCore.Package package, Gtk.SizeGroup? size_group, bool show_uninstall = true) {
2201 grid = new PackageRowGrid (package, size_group, show_uninstall);
2202+ grid.changed.connect (() => changed ());
2203+
2204 add (grid);
2205- grid.changed.connect (() => {
2206- changed ();
2207- });
2208 }
2209
2210 public bool get_update_available () {
2211@@ -42,7 +41,7 @@
2212 return grid.is_os_updates;
2213 }
2214
2215- public string get_name_label () {
2216+ public string? get_name_label () {
2217 return grid.name_label;
2218 }
2219
2220@@ -55,7 +54,7 @@
2221 }
2222
2223 public bool has_package () {
2224- return true;
2225+ return grid.package != null;
2226 }
2227
2228 private class PackageRowGrid : AbstractAppContainer {
2229@@ -68,24 +67,21 @@
2230 column_spacing = 12;
2231 row_spacing = 6;
2232
2233- image = new Gtk.Image ();
2234 image.icon_size = Gtk.IconSize.DIALOG;
2235+
2236 /* Needed to enforce size on icons from Filesystem/Remote */
2237 image.pixel_size = 48;
2238
2239- package_name = new Gtk.Label (null);
2240 package_name.get_style_context ().add_class ("h3");
2241 package_name.hexpand = true;
2242 package_name.valign = Gtk.Align.END;
2243 ((Gtk.Misc) package_name).xalign = 0;
2244
2245- package_summary = new Gtk.Label (null);
2246 package_summary.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL);
2247 package_summary.hexpand = true;
2248 package_summary.valign = Gtk.Align.START;
2249 ((Gtk.Misc) package_summary).xalign = 0;
2250
2251-
2252 attach (image, 0, 0, 1, 2);
2253 attach (package_name, 1, 0, 1, 1);
2254 attach (package_summary, 1, 1, 1, 1);
2255@@ -93,9 +89,8 @@
2256 }
2257
2258 public PackageRowGrid (AppCenterCore.Package package, Gtk.SizeGroup? size_group, bool show_uninstall = true) {
2259- this.package = package;
2260+ Object (package: package);
2261 this.show_uninstall = show_uninstall;
2262- set_up_package ();
2263
2264 if (size_group != null) {
2265 size_group.add_widget (action_button);
2266
2267=== modified file 'src/Widgets/UpdateHeaderRow.vala'
2268--- src/Widgets/UpdateHeaderRow.vala 2016-09-17 19:28:03 +0000
2269+++ src/Widgets/UpdateHeaderRow.vala 2016-10-13 21:30:22 +0000
2270@@ -20,24 +20,26 @@
2271
2272 namespace AppCenter.Widgets {
2273 public class UpdateHeaderRow : Gtk.ListBoxRow, AppListRow {
2274- AbstractHeaderGrid grid;
2275- public bool is_updates_header {get; private set;}
2276+ public bool is_updates_header { get; private set; }
2277+ private AbstractHeaderGrid grid;
2278
2279 construct {
2280- set_activatable (false);
2281- set_selectable (false);
2282+ activatable = false;
2283+ selectable = false;
2284 }
2285
2286 public UpdateHeaderRow.updates () {
2287+ is_updates_header = true;
2288+
2289 grid = new UpdatesGrid ();
2290 add (grid);
2291- is_updates_header = true;
2292 }
2293
2294 public UpdateHeaderRow.updated () {
2295+ is_updates_header = false;
2296+
2297 grid = new UpdatedGrid ();
2298 add (grid);
2299- is_updates_header = false;
2300 }
2301
2302 /** AppListRow Interface methods **/
2303@@ -49,21 +51,17 @@
2304 }
2305
2306 public bool get_is_os_updates () {
2307- critical ("Must not attempt to get is_os_update from header row");
2308- assert_not_reached ();
2309+ warning ("Must not attempt to get is_os_update from header row");
2310+ return false;
2311 }
2312
2313- /* This indicates it is a header row, not a package row */
2314- public bool has_package () {return false;}
2315-
2316 public AppCenterCore.Package? get_package () {
2317- critical ("Must not attempt to get package from header row");
2318- assert_not_reached ();
2319+ return null;
2320 }
2321
2322- public string get_name_label () {
2323- critical ("Must not attempt to get package name from header row");
2324- assert_not_reached ();
2325+ public string? get_name_label () {
2326+ warning ("Must not attempt to get package name from header row");
2327+ return null;
2328 }
2329
2330 public void add_widget (Gtk.Widget widget) {
2331@@ -74,26 +72,23 @@
2332 grid.update (_update_numbers, _update_real_size, _is_updating);
2333 changed (); /* Triggers resort */
2334 }
2335- /** ---------------- **/
2336
2337 /** Base class for Grids in Header Rows **/
2338 private abstract class AbstractHeaderGrid : Gtk.Grid {
2339- public uint update_numbers {get; protected set; default = 0;}
2340- public uint64 update_real_size {get; protected set; default = 0;}
2341- public bool is_updating {get; protected set; default = false;}
2342+ public uint update_numbers { get; set; default = 0; }
2343+ public uint64 update_real_size { get; set; default = 0; }
2344+ public bool is_updating { get; set; default = false; }
2345
2346 construct {
2347 margin = 12;
2348 column_spacing = 12;
2349 }
2350
2351- protected void store_data (uint _update_numbers, uint64 _update_real_size, bool _is_updating) {
2352+ public virtual void update (uint _update_numbers, uint64 _update_real_size, bool _is_updating) {
2353 update_numbers = _update_numbers;
2354 update_real_size = _update_real_size;
2355 is_updating = _is_updating;
2356 }
2357-
2358- public abstract void update (uint _update_numbers, uint64 _update_real_size, bool _is_updating);
2359 }
2360
2361 /** Header to show at top of list if there are updates available **/
2362@@ -115,7 +110,7 @@
2363 }
2364
2365 public override void update (uint _update_numbers, uint64 _update_real_size, bool _is_updating) {
2366- store_data (_update_numbers, _update_real_size, _is_updating);
2367+ base.update (_update_numbers, _update_real_size, _is_updating);
2368
2369 if (!is_updating) {
2370 updates_label.label = ngettext ("%u Update Available", "%u Updates Available", update_numbers).printf (update_numbers);
2371@@ -137,9 +132,9 @@
2372 private Gtk.Spinner spinner;
2373
2374 construct {
2375- label = new Gtk.Label (""); /* Should not be displayed before being updated */
2376+ label = new Gtk.Label (null); /* Should not be displayed before being updated */
2377 label.hexpand = true;
2378- ((Gtk.Misc)label).xalign = 0;
2379+ ((Gtk.Misc) label).xalign = 0;
2380
2381 spinner = new Gtk.Spinner ();
2382
2383@@ -148,20 +143,18 @@
2384 }
2385
2386 public override void update (uint _update_numbers, uint64 _update_real_size, bool _is_updating) {
2387- store_data (_update_numbers, _update_real_size, _is_updating);
2388-
2389+ base.update (_update_numbers, _update_real_size, _is_updating);
2390+
2391 if (is_updating) {
2392 halign = Gtk.Align.CENTER;
2393 spinner.start ();
2394- spinner.no_show_all = false;
2395- spinner.show ();
2396+ set_widget_visible (spinner, true);
2397 label.label = _("Searching for updates…");
2398 label.get_style_context ().remove_class ("h4");
2399 } else {
2400 halign = Gtk.Align.START;
2401 spinner.stop ();
2402- spinner.no_show_all = true;
2403- spinner.hide ();
2404+ set_widget_visible (spinner, false);
2405 label.label = _("Up to Date");
2406 label.get_style_context ().add_class ("h4");
2407 }

Subscribers

People subscribed via source and target branches