Merge lp:~donadigo/appcenter/prefer-stock into lp:~elementary-apps/appcenter/appcenter

Proposed by Adam Bieńkowski
Status: Merged
Approved by: Danielle Foré
Approved revision: 209
Merged at revision: 210
Proposed branch: lp:~donadigo/appcenter/prefer-stock
Merge into: lp:~elementary-apps/appcenter/appcenter
Diff against target: 129 lines (+43/-54)
3 files modified
src/Core/Package.vala (+41/-0)
src/Views/AppInfoView.vala (+1/-32)
src/Widgets/PackageRow.vala (+1/-22)
To merge this branch: bzr merge lp:~donadigo/appcenter/prefer-stock
Reviewer Review Type Date Requested Status
Corentin Noël code Approve
Danielle Foré testing Approve
Review via email: mp+297967@code.launchpad.net

Commit message

Use icons from the theme when available

Description of the change

Fixes bug #1525037: "Use icons from the theme when available".

Prefer the stock icons, if there is no icon found in the icon theme, fallback to URLs / filenames.

* Instead of duplicating the code, the icon code has been moved to the Package class for consistency.

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote :

I can confirm that this works and in all views :)

review: Approve (testing)
Revision history for this message
Corentin Noël (tintou) wrote :

We discussed about some changes to do

review: Needs Fixing (code)
lp:~donadigo/appcenter/prefer-stock updated
209. By Adam Bieńkowski

Prefer stock icons

Revision history for this message
Corentin Noël (tintou) wrote :

Nice, now working as intended

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Core/Package.vala'
2--- src/Core/Package.vala 2016-05-01 22:39:22 +0000
3+++ src/Core/Package.vala 2016-06-21 17:44:46 +0000
4@@ -141,6 +141,47 @@
5 return null;
6 }
7
8+ public GLib.Icon get_icon (uint size = 32) {
9+ GLib.Icon icon = new ThemedIcon ("application-default-icon");
10+ uint current_size = 0;
11+
12+ bool is_stock = false;
13+ component.get_icons ().foreach ((_icon) => {
14+ if (is_stock) {
15+ return;
16+ }
17+
18+ switch (_icon.get_kind ()) {
19+ case AppStream.IconKind.STOCK:
20+ if (Gtk.IconTheme.get_default ().has_icon (_icon.get_name ())) {
21+ is_stock = true;
22+ icon = new ThemedIcon (_icon.get_name ());
23+ }
24+
25+ break;
26+ case AppStream.IconKind.CACHED:
27+ case AppStream.IconKind.LOCAL:
28+ if (_icon.get_width () > current_size && current_size < size) {
29+ var file = File.new_for_path (_icon.get_filename ());
30+ icon = new FileIcon (file);
31+ current_size = _icon.get_width ();
32+ }
33+
34+ break;
35+ case AppStream.IconKind.REMOTE:
36+ if (_icon.get_width () > current_size && current_size < size) {
37+ var file = File.new_for_uri (_icon.get_url ());
38+ icon = new FileIcon (file);
39+ current_size = _icon.get_width ();
40+ }
41+
42+ break;
43+ }
44+ });
45+
46+ return icon;
47+ }
48+
49 public string? get_version () {
50 var package = find_package ();
51 if (package != null) {
52
53=== modified file 'src/Views/AppInfoView.vala'
54--- src/Views/AppInfoView.vala 2016-06-12 22:00:29 +0000
55+++ src/Views/AppInfoView.vala 2016-06-21 17:44:46 +0000
56@@ -43,38 +43,7 @@
57 app_name.label = package.get_name ();
58 app_summary.label = package.get_summary ();
59 parse_description (package.component.get_description ());
60- uint size = 0;
61- string icon_name = "application-default-icon";
62- package.component.get_icons ().foreach ((icon) => {
63- switch (icon.get_kind ()) {
64- case AppStream.IconKind.STOCK:
65- icon_name = icon.get_name ();
66- break;
67- case AppStream.IconKind.CACHED:
68- case AppStream.IconKind.LOCAL:
69- var current_size = icon.get_width ();
70- if (current_size > size) {
71- size = current_size;
72- var file = File.new_for_path (icon.get_filename ());
73- app_icon.gicon = new FileIcon (file);
74- }
75-
76- break;
77- case AppStream.IconKind.REMOTE:
78- var current_size = icon.get_width ();
79- if (current_size > size) {
80- size = current_size;
81- var file = File.new_for_uri (icon.get_url ());
82- app_icon.gicon = new FileIcon (file);
83- }
84-
85- break;
86- }
87- });
88-
89- if (app_icon.gicon == null) {
90- app_icon.gicon = new ThemedIcon (icon_name);
91- }
92+ app_icon.gicon = package.get_icon (128);
93
94 if (package.update_available) {
95 action_button.label = _("Update");
96
97=== modified file 'src/Widgets/PackageRow.vala'
98--- src/Widgets/PackageRow.vala 2016-06-15 17:07:50 +0000
99+++ src/Widgets/PackageRow.vala 2016-06-21 17:44:46 +0000
100@@ -39,28 +39,7 @@
101 package_name.label = package.get_name ();
102 package_summary.label = package.get_summary ();
103 package_summary.ellipsize = Pango.EllipsizeMode.END;
104-
105- string icon_name = "application-default-icon";
106- package.component.get_icons ().foreach ((icon) => {
107- switch (icon.get_kind ()) {
108- case AppStream.IconKind.STOCK:
109- icon_name = icon.get_name ();
110- break;
111- case AppStream.IconKind.CACHED:
112- case AppStream.IconKind.LOCAL:
113- var file = File.new_for_path (icon.get_filename ());
114- image.gicon = new FileIcon (file);
115- break;
116- case AppStream.IconKind.REMOTE:
117- var file = File.new_for_uri (icon.get_url ());
118- image.gicon = new FileIcon (file);
119- break;
120- }
121- });
122-
123- if (image.gicon == null) {
124- image.gicon = new ThemedIcon (icon_name);
125- }
126+ image.gicon = package.get_icon ();
127
128 package.notify["installed"].connect (() => {
129 changed ();

Subscribers

People subscribed via source and target branches