Merge lp:~mandel/libunity/libunity-add-music-payment into lp:libunity

Proposed by Manuel de la Peña on 2012-12-05
Status: Merged
Approved by: Michal Hruby on 2012-12-12
Approved revision: 212
Merged at revision: 205
Proposed branch: lp:~mandel/libunity/libunity-add-music-payment
Merge into: lp:libunity
Diff against target: 414 lines (+329/-1)
5 files modified
debian/libunity9.symbols (+24/-0)
po/POTFILES.skip (+1/-0)
protocol/protocol-previews.vala (+89/-1)
src/unity-previews.vala (+95/-0)
test/vala/test-previews.vala (+120/-0)
To merge this branch: bzr merge lp:~mandel/libunity/libunity-add-music-payment
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve on 2012-12-11
Michal Hruby (community) 2012-12-05 Approve on 2012-12-11
Review via email: mp+138214@code.launchpad.net

Commit Message

Added extra preview to be used by the music store scope.

Description of the Change

Added extra preview to be used by the music store scope.

To post a comment you must log in.
204. By Manuel de la Peña on 2012-12-07

Merged with trunk.

205. By Manuel de la Peña on 2012-12-07

Updated protocol to hide the fact that there is more than one type of payment preview.

206. By Manuel de la Peña on 2012-12-07

Updated symbols.

Michal Hruby (mhr3) wrote :

Looking good, but pls add a few more checks in the test_preview_*_payment (mostly that the serialization and deserialization works).

207. By Manuel de la Peña on 2012-12-10

Made changes in tests so that we test serialize and deserialize in all the diff payment preview types.

208. By Manuel de la Peña on 2012-12-10

Assert that the default type is music.

209. By Manuel de la Peña on 2012-12-10

Use the property to set the preview type and assert that everything works.

210. By Manuel de la Peña on 2012-12-10

Ignore tests in translations.

211. By Manuel de la Peña on 2012-12-10

Change the renderer name to payment preview.

212. By Manuel de la Peña on 2012-12-11

Do not hardcode symbols version.

Michal Hruby (mhr3) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/libunity9.symbols'
2--- debian/libunity9.symbols 2012-12-05 09:26:30 +0000
3+++ debian/libunity9.symbols 2012-12-11 11:21:24 +0000
4@@ -399,6 +399,30 @@
5 unity_options_filter_sort_type_get_type@Base 4.0.4
6 unity_param_spec_string_array_wrapper@Base 3.4.6
7 unity_param_spec_tools@Base 4.0.0
8+ unity_payment_preview_construct@Base 0replaceme
9+ unity_payment_preview_construct_for_application@Base 0replaceme
10+ unity_payment_preview_construct_for_error@Base 0replaceme
11+ unity_payment_preview_construct_for_music@Base 0replaceme
12+ unity_payment_preview_construct_for_type@Base 0replaceme
13+ unity_payment_preview_get_email@Base 0replaceme
14+ unity_payment_preview_get_header@Base 0replaceme
15+ unity_payment_preview_get_payment_method@Base 0replaceme
16+ unity_payment_preview_get_preview_type@Base 0replaceme
17+ unity_payment_preview_get_purchase_prize@Base 0replaceme
18+ unity_payment_preview_get_purchase_type@Base 0replaceme
19+ unity_payment_preview_get_type@Base 0replaceme
20+ unity_payment_preview_new@Base 0replaceme
21+ unity_payment_preview_new_for_application@Base 0replaceme
22+ unity_payment_preview_new_for_error@Base 0replaceme
23+ unity_payment_preview_new_for_music@Base 0replaceme
24+ unity_payment_preview_new_for_type@Base 0replaceme
25+ unity_payment_preview_set_email@Base 0replaceme
26+ unity_payment_preview_set_header@Base 0replaceme
27+ unity_payment_preview_set_payment_method@Base 0replaceme
28+ unity_payment_preview_set_preview_type@Base 0replaceme
29+ unity_payment_preview_set_purchase_prize@Base 0replaceme
30+ unity_payment_preview_set_purchase_type@Base 0replaceme
31+ unity_payment_preview_type_get_type@Base 0replaceme
32 unity_playback_state_get_type@Base 4.0.0
33 unity_playlist_construct@Base 4.0.0
34 unity_playlist_details_copy@Base 4.0.0
35
36=== modified file 'po/POTFILES.skip'
37--- po/POTFILES.skip 2012-09-26 07:34:03 +0000
38+++ po/POTFILES.skip 2012-12-11 11:21:24 +0000
39@@ -1,1 +1,2 @@
40 tools/unity-tool.c
41+test/vala/test-previews.c
42
43=== modified file 'protocol/protocol-previews.vala'
44--- protocol/protocol-previews.vala 2012-10-01 14:25:07 +0000
45+++ protocol/protocol-previews.vala 2012-12-11 11:21:24 +0000
46@@ -46,7 +46,7 @@
47 {
48 hints = new HashTable<string, Variant> (str_hash, str_equal);
49 }
50-
51+
52 public static PreviewRaw? from_variant (Variant v)
53 {
54 return (PreviewRaw) v;
55@@ -278,6 +278,7 @@
56 typeof (GenericPreview).class_ref ();
57 typeof (ApplicationPreview).class_ref ();
58 typeof (MusicPreview).class_ref ();
59+ typeof (PaymentPreview).class_ref ();
60 typeof (MoviePreview).class_ref ();
61 typeof (SocialPreview).class_ref ();
62 typeof (SeriesPreview).class_ref ();
63@@ -304,6 +305,9 @@
64 case MusicPreview.RENDERER_NAME:
65 result_obj = Dee.Serializable.parse (data, typeof (MusicPreview));
66 break;
67+ case PaymentPreview.RENDERER_NAME:
68+ result_obj = Dee.Serializable.parse (data, typeof (PaymentPreview));
69+ break;
70 case MoviePreview.RENDERER_NAME:
71 result_obj = Dee.Serializable.parse (data, typeof (MoviePreview));
72 break;
73@@ -529,6 +533,90 @@
74 }
75 }
76
77+public enum PreviewPaymentType {
78+ APPLICATION,
79+ MUSIC,
80+ ERROR,
81+}
82+
83+public class PaymentPreview : Preview
84+{
85+ internal const string RENDERER_NAME = "preview-payment";
86+
87+ public string header { get; set; }
88+ public string email { get; set; }
89+ public string payment_method { get; set; }
90+ public string purchase_prize { get; set; }
91+ public string purchase_type { get; set; }
92+ public PreviewPaymentType preview_type { get; set; default = PreviewPaymentType.MUSIC; }
93+
94+ public PaymentPreview ()
95+ {
96+ Object ();
97+ }
98+
99+ internal override unowned string get_renderer_name ()
100+ {
101+ return RENDERER_NAME;
102+ }
103+
104+ internal override void add_properties (HashTable<string, Variant> properties)
105+ {
106+ base.add_properties (properties);
107+
108+ if (header != null)
109+ properties["header"] = header;
110+
111+ if (email != null)
112+ properties["email"] = email;
113+
114+ if (payment_method != null)
115+ properties["payment-method"] = payment_method;
116+
117+ if (purchase_prize != null)
118+ properties["purchase-prize"] = purchase_prize;
119+
120+ if (purchase_type != null)
121+ properties["purchase-type"] = purchase_type;
122+
123+ properties["preview-type"] = preview_type;
124+ }
125+
126+ static construct
127+ {
128+ Dee.Serializable.register_parser (typeof (PaymentPreview),
129+ new VariantType (PreviewRaw.SIGNATURE),
130+ (data) =>
131+ {
132+ unowned string renderer = data.get_child_value (0).get_string ();
133+ warn_if_fail (renderer == RENDERER_NAME);
134+
135+ HashTable<string, Variant> properties;
136+ PaymentPreview result = Preview.deserialize<PaymentPreview> (
137+ data, out properties);
138+
139+ Preview.checked_set (properties["title"],
140+ (v) => { result.title = v.get_string (); });
141+ Preview.checked_set (properties["subtitle"],
142+ (v) => { result.subtitle = v.get_string (); });
143+ Preview.checked_set (properties["header"],
144+ (v) => { result.header = v.get_string (); });
145+ Preview.checked_set (properties["email"],
146+ (v) => { result.email = v.get_string (); });
147+ Preview.checked_set (properties["payment-method"],
148+ (v) => { result.payment_method = v.get_string (); });
149+ Preview.checked_set (properties["purchase-prize"],
150+ (v) => { result.purchase_prize = v.get_string (); });
151+ Preview.checked_set (properties["purchase-type"],
152+ (v) => { result.purchase_type = v.get_string (); });
153+ Preview.checked_set (properties["preview-type"],
154+ (v) => { result.preview_type = (PreviewPaymentType) v.get_int32 (); });
155+
156+ return result;
157+ });
158+ }
159+}
160+
161 public class MoviePreview : Preview
162 {
163 internal const string RENDERER_NAME = "preview-movie";
164
165=== modified file 'src/unity-previews.vala'
166--- src/unity-previews.vala 2012-10-05 15:15:54 +0000
167+++ src/unity-previews.vala 2012-12-11 11:21:24 +0000
168@@ -467,6 +467,100 @@
169 }
170
171
172+public class PaymentPreview : Preview
173+{
174+ public enum Type {
175+ APPLICATION,
176+ MUSIC,
177+ ERROR
178+ }
179+
180+ public string header
181+ {
182+ get { return _raw.header; }
183+ set { _raw.header = value;}
184+ }
185+
186+ public string email
187+ {
188+ get { return _raw.email; }
189+ set { _raw.email = value; }
190+ }
191+
192+ public string payment_method
193+ {
194+ get { return _raw.payment_method; }
195+ set { _raw.payment_method = value; }
196+ }
197+
198+ public string purchase_prize
199+ {
200+ get { return _raw.purchase_prize; }
201+ set { _raw.purchase_prize = value; }
202+ }
203+
204+ public string purchase_type
205+ {
206+ get { return _raw.purchase_type; }
207+ set { _raw.purchase_type = value; }
208+ }
209+
210+ public Type preview_type
211+ {
212+ get { return (Type) _raw.preview_type; }
213+ set { _raw.preview_type = (Unity.Protocol.PreviewPaymentType) value; }
214+ }
215+
216+ public PaymentPreview (string title, string subtitle, Icon? image)
217+ {
218+ Object (title: title, subtitle: subtitle, image: image);
219+ }
220+
221+ public PaymentPreview.for_type (string title, string subtitle, Icon? image,
222+ Type type)
223+ {
224+ this (title, subtitle, image);
225+ preview_type = type;
226+ }
227+
228+ public PaymentPreview.for_application (string title, string subtitle,
229+ Icon? image)
230+ {
231+ this.for_type (title, subtitle, image, Type.APPLICATION);
232+ }
233+
234+ public PaymentPreview.for_music (string title, string subtitle, Icon? image)
235+ {
236+ this.for_type (title, subtitle, image, Type.MUSIC);
237+ }
238+
239+ public PaymentPreview.for_error (string title, string subtitle, Icon? image)
240+ {
241+ this.for_type (title, subtitle, image, Type.ERROR);
242+ }
243+
244+ static construct
245+ {
246+ // perform assertion so that we do not have bad castings if
247+ // someone forgot to keep the enums synced
248+ static_assert ((int) Protocol.PreviewPaymentType.APPLICATION ==
249+ (int) Type.APPLICATION);
250+ static_assert ((int) Protocol.PreviewPaymentType.MUSIC ==
251+ (int) Type.MUSIC);
252+ static_assert ((int) Protocol.PreviewPaymentType.ERROR ==
253+ (int) Type.ERROR);
254+ }
255+
256+ private unowned Protocol.PaymentPreview _raw;
257+ internal override Object create_raw ()
258+ {
259+ var raw = new Protocol.PaymentPreview ();
260+ _raw = raw;
261+ return _raw;
262+ }
263+}
264+
265+
266 public class MoviePreview : Preview
267 {
268 public string year
269@@ -497,6 +591,7 @@
270 }
271 }
272
273+
274 public class SocialPreview : Preview
275 {
276 public class Comment : InitiallyUnowned
277
278=== modified file 'test/vala/test-previews.vala'
279--- test/vala/test-previews.vala 2012-09-24 13:53:47 +0000
280+++ test/vala/test-previews.vala 2012-12-11 11:21:24 +0000
281@@ -39,6 +39,14 @@
282 test_preview_social);
283 GLib.Test.add_data_func ("/Unit/Preview/MusicPreview",
284 test_preview_music);
285+ GLib.Test.add_data_func ("/Unit/Preview/PaymentPreview",
286+ test_preview_payment);
287+ GLib.Test.add_data_func ("/Unit/Preview/MusicPaymentPreview",
288+ test_preview_music_payment);
289+ GLib.Test.add_data_func ("/Unit/Preview/ApplicationPaymentPreview",
290+ test_preview_app_payment);
291+ GLib.Test.add_data_func ("/Unit/Preview/ErrorPaymentPreview",
292+ test_preview_error_payment);
293 GLib.Test.add_data_func ("/Unit/Preview/MusicPreview/WithTracks",
294 test_preview_music_with_tracks);
295 GLib.Test.add_data_func ("/Unit/Preview/MoviePreview",
296@@ -290,6 +298,118 @@
297 assert (previews_equal (data, reconstructed.serialize ()));
298 }
299
300+ delegate PaymentPreview PreviewConstructor (string title, string subtitle,
301+ FileIcon icon);
302+
303+ static void assert_payment_deserialization(PreviewConstructor constructor,
304+ string artwork_path)
305+ {
306+ var artwork = new FileIcon (File.new_for_path (artwork_path));
307+ var preview = constructor ("Beatles", "Help", artwork);
308+
309+ // set the diff data for the preview
310+ preview.header = "Hi %s, you purchased in the past from Ubuntu One,"
311+ + " would you like to use the same payment details?"
312+ + " Please review your order.";
313+ preview.email = "test@canonical.com";
314+ preview.payment_method = "****** ** *** ***34";
315+ preview.purchase_prize = "2 eur";
316+ preview.purchase_type = "Digital CD";
317+
318+ // check if serialization works properly
319+ var data = preview.serialize ();
320+ var reconstructed =
321+ Protocol.Preview.parse (data) as Protocol.PaymentPreview;
322+
323+ assert (preview.title == reconstructed.title);
324+ assert (preview.subtitle == reconstructed.subtitle);
325+ assert (preview.header == reconstructed.header);
326+ assert (preview.email == reconstructed.email);
327+ assert (preview.payment_method == reconstructed.payment_method);
328+ assert (preview.purchase_prize == reconstructed.purchase_prize);
329+ assert (preview.purchase_type == reconstructed.purchase_type);
330+ assert ((int) preview.preview_type == (int) reconstructed.preview_type);
331+ assert (preview.image.equal (reconstructed.image));
332+ assert (artwork.equal (reconstructed.image));
333+
334+ assert (previews_equal (data, reconstructed.serialize ()));
335+ }
336+
337+ static void test_preview_payment ()
338+ {
339+ assert_payment_deserialization (
340+ (title, subtitle, artwork) => {
341+ var preview = new PaymentPreview (title, subtitle, artwork);
342+ assert (preview.preview_type == PaymentPreview.Type.MUSIC);
343+ return preview;
344+ },
345+ "/usr/share/icons/beatles.jpg");
346+ }
347+
348+ static void test_preview_music_payment ()
349+ {
350+ assert_payment_deserialization (
351+ (title, subtitle, artwork) => {
352+ var preview = new PaymentPreview.for_music (title, subtitle, artwork);
353+ assert (preview.preview_type == PaymentPreview.Type.MUSIC);
354+ return preview;
355+ },
356+ "/usr/share/icons/beatles.jpg");
357+
358+ // same assert but using the property
359+ assert_payment_deserialization (
360+ (title, subtitle, artwork) => {
361+ var preview = new PaymentPreview (title, subtitle, artwork);
362+ preview.preview_type = PaymentPreview.Type.MUSIC;
363+ assert (preview.preview_type == PaymentPreview.Type.MUSIC);
364+ return preview;
365+ },
366+ "/usr/share/icons/beatles.jpg");
367+ }
368+
369+ static void test_preview_app_payment ()
370+ {
371+ assert_payment_deserialization (
372+ (title, subtitle, artwork) => {
373+ var preview = new PaymentPreview.for_application (title, subtitle,
374+ artwork);
375+ assert (preview.preview_type == PaymentPreview.Type.APPLICATION);
376+ return preview;
377+ },
378+ "/usr/share/icons/beatles.jpg");
379+
380+ // same assert but using the property
381+ assert_payment_deserialization (
382+ (title, subtitle, artwork) => {
383+ var preview = new PaymentPreview (title, subtitle, artwork);
384+ preview.preview_type = PaymentPreview.Type.APPLICATION;
385+ assert (preview.preview_type == PaymentPreview.Type.APPLICATION);
386+ return preview;
387+ },
388+ "/usr/share/icons/beatles.jpg");
389+ }
390+
391+ static void test_preview_error_payment ()
392+ {
393+ assert_payment_deserialization (
394+ (title, subtitle, artwork) => {
395+ var preview = new PaymentPreview.for_error (title, subtitle, artwork);
396+ assert (preview.preview_type == PaymentPreview.Type.ERROR);
397+ return preview;
398+ },
399+ "/usr/share/icons/beatles.jpg");
400+
401+ // same assert but using the property
402+ assert_payment_deserialization (
403+ (title, subtitle, artwork) => {
404+ var preview = new PaymentPreview (title, subtitle, artwork);
405+ preview.preview_type = PaymentPreview.Type.ERROR;
406+ assert (preview.preview_type == PaymentPreview.Type.ERROR);
407+ return preview;
408+ },
409+ "/usr/share/icons/beatles.jpg");
410+ }
411+
412 static void test_preview_movie ()
413 {
414 var artwork = new FileIcon (File.new_for_path ("/usr/share/icons/my_favourite_movie.png"));

Subscribers

People subscribed via source and target branches