Merge lp:~ken-vandine/libunity/social_preview into lp:libunity

Proposed by Ken VanDine
Status: Merged
Approved by: Paweł Stołowski
Approved revision: 178
Merged at revision: 176
Proposed branch: lp:~ken-vandine/libunity/social_preview
Merge into: lp:libunity
Diff against target: 258 lines (+177/-4)
4 files modified
protocol/protocol-previews.vala (+96/-0)
src/unity-previews.vala (+55/-0)
test/vala/test-previews.vala (+21/-0)
tools/preview-renderer.vala (+5/-4)
To merge this branch: bzr merge lp:~ken-vandine/libunity/social_preview
Reviewer Review Type Date Requested Status
Paweł Stołowski (community) Approve
Review via email: mp+124515@code.launchpad.net

Commit message

Added SocialPreview

Description of the change

Added SocialPreview

To post a comment you must log in.
Revision history for this message
Paweł Stołowski (stolowski) wrote :

Looking good overall. Two remarks:

1) Can you add a simple serialization test to test-previews.vala?

2) This should be removed?:
176 +
177 +/* KEN
178 + public SocialPreview (Comment[] comments, string selected_item_uri)
179 + {
180 + // careful current_item_uri will be set before items are
181 + Object (current_item_uri: selected_item_uri);
182 + foreach (unowned Comment comment in comments)
183 + {
184 + add_comment (comment);
185 + }
186 + }
187 +*/

review: Needs Fixing
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Those issues should be fined now.

Revision history for this message
Paweł Stołowski (stolowski) wrote :

Looks good now!

review: Approve
Revision history for this message
Unity Merger (unity-merger) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'protocol/protocol-previews.vala'
2--- protocol/protocol-previews.vala 2012-09-13 15:09:15 +0000
3+++ protocol/protocol-previews.vala 2012-09-17 18:01:37 +0000
4@@ -279,6 +279,7 @@
5 typeof (ApplicationPreview).class_ref ();
6 typeof (MusicPreview).class_ref ();
7 typeof (MoviePreview).class_ref ();
8+ typeof (SocialPreview).class_ref ();
9 typeof (SeriesPreview).class_ref ();
10 }
11
12@@ -306,6 +307,9 @@
13 case MoviePreview.RENDERER_NAME:
14 result_obj = Dee.Serializable.parse (data, typeof (MoviePreview));
15 break;
16+ case SocialPreview.RENDERER_NAME:
17+ result_obj = Dee.Serializable.parse (data, typeof (SocialPreview));
18+ break;
19 case SeriesPreview.RENDERER_NAME:
20 result_obj = Dee.Serializable.parse (data, typeof (SeriesPreview));
21 break;
22@@ -580,6 +584,98 @@
23 }
24 }
25
26+public class SocialPreview : Preview
27+{
28+ internal const string RENDERER_NAME = "preview-social";
29+
30+ public Icon avatar { get; set; }
31+ public string content { get; set; }
32+ public string sender { get; set; }
33+ public CommentRaw[] comments;
34+ private CommentRaw[] _comments = null;
35+
36+ public struct CommentRaw
37+ {
38+ public string id;
39+ public string display_name;
40+ public string content;
41+ public string time;
42+ }
43+
44+ public SocialPreview ()
45+ {
46+ Object ();
47+ }
48+
49+ internal override unowned string get_renderer_name ()
50+ {
51+ return RENDERER_NAME;
52+ }
53+
54+ internal override void add_properties (HashTable<string, Variant> properties)
55+ {
56+ base.add_properties (properties);
57+
58+ if (_comments.length > 0)
59+ properties["comments"] = _comments;
60+ if (avatar != null)
61+ properties["avatar"] = avatar.to_string ();
62+ if (content != null)
63+ properties["content"] = content;
64+ if (sender != null)
65+ properties["sender"] = sender;
66+ }
67+
68+ static construct
69+ {
70+ Dee.Serializable.register_parser (typeof (SocialPreview),
71+ new VariantType (PreviewRaw.SIGNATURE),
72+ (data) =>
73+ {
74+ unowned string renderer = data.get_child_value (0).get_string ();
75+ warn_if_fail (renderer == RENDERER_NAME);
76+
77+ HashTable<string, Variant> properties;
78+ SocialPreview result = Preview.deserialize<SocialPreview> (
79+ data, out properties);
80+
81+ Preview.checked_set (properties["avatar"],
82+ (v) => { result.avatar = Preview.variant_to_icon (v); });
83+ Preview.checked_set (properties["content"],
84+ (v) => { result.content = v.get_string (); });
85+ Preview.checked_set (properties["sender"],
86+ (v) => { result.sender = v.get_string (); });
87+
88+ Preview.checked_set (properties["comments"], (v) =>
89+ {
90+ CommentRaw[] comments = (CommentRaw[]) v;
91+ result._comments = (owned) comments;
92+ });
93+
94+ return result;
95+ });
96+ }
97+
98+ public void add_comment (string id,
99+ string display_name,
100+ string content,
101+ string time)
102+ {
103+ CommentRaw? comment = CommentRaw ();
104+ comment.id = id;
105+ comment.display_name = display_name;
106+ comment.content = content;
107+ comment.time = time;
108+
109+ _comments += (owned) comment;
110+ }
111+
112+ public unowned CommentRaw[] get_comments ()
113+ {
114+ return _comments;
115+ }
116+}
117+
118 public struct SeriesItemRaw
119 {
120 public string uri;
121
122=== modified file 'src/unity-previews.vala'
123--- src/unity-previews.vala 2012-09-03 14:38:59 +0000
124+++ src/unity-previews.vala 2012-09-17 18:01:37 +0000
125@@ -497,6 +497,61 @@
126 }
127 }
128
129+public class SocialPreview : Preview
130+{
131+ public class Comment : InitiallyUnowned
132+ {
133+ public string id { get; construct; }
134+ public string name { get; construct; }
135+ public string text { get; construct; }
136+ public string time { get; construct; }
137+
138+ public Comment (string id, string name, string text, string time)
139+ {
140+ Object (id: id, name: name, text: text, time: time);
141+ }
142+ }
143+
144+ public Icon avatar
145+ {
146+ get { return _raw.avatar; }
147+ set { _raw.avatar = value; }
148+ }
149+ public string content
150+ {
151+ get { return _raw.description; }
152+ set { _raw.description = value; }
153+ }
154+ public string sender
155+ {
156+ get { return _raw.sender; }
157+ set { _raw.sender = value; }
158+ }
159+
160+ public SocialPreview (string sender,
161+ string title,
162+ string content,
163+ Icon? avatar)
164+ {
165+ Object (sender: sender, title: title, content: content,
166+ avatar: avatar);
167+ }
168+
169+ private unowned Protocol.SocialPreview _raw;
170+ internal override Object create_raw ()
171+ {
172+ var raw = new Protocol.SocialPreview ();
173+ _raw = raw;
174+ return _raw;
175+ }
176+
177+ public void add_comment (Comment comment)
178+ {
179+ _raw.add_comment (comment.id, comment.name, comment.text, comment.time);
180+ }
181+
182+}
183+
184 /* No support for SeriesPreview yet */
185 internal class SeriesItem : Object
186 {
187
188=== modified file 'test/vala/test-previews.vala'
189--- test/vala/test-previews.vala 2012-08-20 14:57:40 +0000
190+++ test/vala/test-previews.vala 2012-09-17 18:01:37 +0000
191@@ -35,6 +35,8 @@
192 test_preview_generic_no_details);
193 GLib.Test.add_data_func ("/Unit/Preview/ApplicationPreview",
194 test_preview_application);
195+ GLib.Test.add_data_func ("/Unit/Preview/SocialPreview",
196+ test_preview_social);
197 GLib.Test.add_data_func ("/Unit/Preview/MusicPreview",
198 test_preview_music);
199 GLib.Test.add_data_func ("/Unit/Preview/MusicPreview/WithTracks",
200@@ -220,6 +222,25 @@
201 assert (previews_equal (data, reconstructed.serialize ()));
202 }
203
204+ static void test_preview_social ()
205+ {
206+ var avatar = new ThemedIcon ("gwibber");
207+ var preview = new SocialPreview ("sender", "title",
208+ "content", avatar);
209+
210+ // check if serialization works properly
211+ var data = preview.serialize ();
212+ var reconstructed = Protocol.Preview.parse (data) as Protocol.SocialPreview;
213+
214+ assert (preview.sender == reconstructed.sender);
215+ assert (preview.title == reconstructed.title);
216+ assert (preview.content == reconstructed.description);
217+ assert (avatar.equal (reconstructed.avatar));
218+
219+ assert (previews_equal (data, reconstructed.serialize ()));
220+ }
221+
222+
223 static void test_preview_music ()
224 {
225 var artwork = new FileIcon (File.new_for_path ("/usr/share/icons/beatles.jpg"));
226
227=== modified file 'tools/preview-renderer.vala'
228--- tools/preview-renderer.vala 2012-08-15 09:02:44 +0000
229+++ tools/preview-renderer.vala 2012-09-17 18:01:37 +0000
230@@ -50,7 +50,8 @@
231 if (preview is Unity.Protocol.SeriesPreview) {
232 return new SeriesPreviewRenderer(preview as Unity.Protocol.SeriesPreview, scope_uri);
233 }
234- return null;
235+ /* fallback - a generic preview renderer */
236+ return new GenericPreviewRenderer(preview, scope_uri);
237 }
238
239 public Unity.Protocol.Preview preview { get; construct; }
240@@ -232,7 +233,7 @@
241
242 public class GenericPreviewRenderer: GridRenderer
243 {
244- public GenericPreviewRenderer(Unity.Protocol.GenericPreview preview, string scope_uri)
245+ public GenericPreviewRenderer(Unity.Protocol.Preview preview, string scope_uri)
246 {
247 Object(preview: preview, scope_uri: scope_uri);
248 }
249@@ -241,8 +242,8 @@
250 {
251 assert(preview != null);
252
253- base.add_standard_attributes(preview as Unity.Protocol.GenericPreview);
254- base.add_info_hints(preview as Unity.Protocol.GenericPreview);
255+ base.add_standard_attributes(preview as Unity.Protocol.Preview);
256+ base.add_info_hints(preview as Unity.Protocol.Preview);
257 }
258 }
259

Subscribers

People subscribed via source and target branches