Merge lp:~stolowski/unity-scope-home/fix-1219911 into lp:unity-scope-home

Proposed by Paweł Stołowski
Status: Merged
Approved by: Michal Hruby
Approved revision: 160
Merged at revision: 159
Proposed branch: lp:~stolowski/unity-scope-home/fix-1219911
Merge into: lp:unity-scope-home
Diff against target: 85 lines (+36/-6)
1 file modified
src/smart-scopes-preview-parser.vala (+36/-6)
To merge this branch: bzr merge lp:~stolowski/unity-scope-home/fix-1219911
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Michal Hruby (community) Approve
Review via email: mp+183615@code.launchpad.net

Commit message

Properly handle info hints and subtitle when parsing previews from Smart Scopes Server. Don't print errors if 'attribution' is missing.

Description of the change

Properly handle info hints when parsing previews from Smart Scopes Server. Handle subtitle when parsing generic preview. Don't print errors if 'attribution' is missing.

To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote :

LGTM

review: Approve
160. By Paweł Stołowski

Fixed variable name.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/smart-scopes-preview-parser.vala'
2--- src/smart-scopes-preview-parser.vala 2013-06-06 15:28:32 +0000
3+++ src/smart-scopes-preview-parser.vala 2013-09-03 10:09:03 +0000
4@@ -45,7 +45,7 @@
5
6 public interface PreviewJsonParser: Object
7 {
8- internal void get_base_attributes (Json.Object obj, out string title, out string subtitle, out string description, out GLib.Icon? icon, out string? attribution) //TODO actions
9+ internal void get_base_attributes (Json.Object obj, out string title, out string subtitle, out string description, out GLib.Icon? icon, out string? attribution)
10 {
11 title = obj.get_string_member ("title");
12 subtitle = obj.get_string_member ("subtitle");
13@@ -57,9 +57,12 @@
14 if (description.length == 0 && obj.has_member ("description"))
15 description = obj.get_string_member ("description");
16
17- attribution = obj.get_string_member ("attribution");
18- if (attribution != null && attribution != "")
19- description += "\n──────────────\n<small>" + Markup.escape_text (attribution) + "</small>";
20+ if (obj.has_member ("attribution"))
21+ {
22+ attribution = obj.get_string_member ("attribution");
23+ if (attribution != null && attribution != "")
24+ description += "\n──────────────\n<small>" + Markup.escape_text (attribution) + "</small>";
25+ }
26
27 if (obj.has_member ("image_hint"))
28 {
29@@ -73,6 +76,30 @@
30 }
31 }
32
33+ internal void get_info_hints (Json.Object obj, Preview preview)
34+ {
35+ if (obj.has_member ("info"))
36+ {
37+ var info_array = obj.get_array_member ("info");
38+
39+ info_array.foreach_element ((_array, _index, _node) =>
40+ {
41+ var info_obj = _node.get_object ();
42+ var info_hint_id = info_obj.get_string_member ("id");
43+ var info_icon_hint = info_obj.get_string_member ("icon_hint");
44+ var info_name = info_obj.get_string_member ("display_name");
45+ var info_value = info_obj.get_string_member ("value");
46+
47+ var icon_file = GLib.File.new_for_uri (info_icon_hint);
48+ var info_icon = new GLib.FileIcon (icon_file);
49+
50+ var info = new Unity.InfoHint (info_hint_id, info_name, info_icon, info_value);
51+
52+ preview.add_info (info);
53+ });
54+ }
55+ }
56+
57 internal void get_actions (Json.Object obj, Preview preview)
58 {
59 if (obj.has_member ("actions"))
60@@ -105,13 +132,15 @@
61 {
62 public Preview? parse (Json.Object obj)
63 {
64- string title, description;
65+ string title, subtitle, description;
66 string? attribution;
67 GLib.Icon? icon;
68
69- get_base_attributes (obj, out title, null, out description, out icon, out attribution);
70+ get_base_attributes (obj, out title, out subtitle, out description, out icon, out attribution);
71 var preview = new GenericPreview (title, description, icon);
72+ preview.subtitle = subtitle;
73 get_actions (obj, preview);
74+ get_info_hints (obj, preview);
75
76 return preview;
77 }
78@@ -129,6 +158,7 @@
79
80 var preview = new MusicPreview (title, subtitle, icon);
81 get_actions (obj, preview);
82+ get_info_hints (obj, preview);
83
84 var tracks_array = obj.get_array_member ("tracks");
85 tracks_array.foreach_element ((_array, _index, _node) =>

Subscribers

People subscribed via source and target branches

to all changes: