Merge lp:~alecu/unity-lens-music/plan-b into lp:unity-lens-music

Proposed by Alejandro J. Cura
Status: Merged
Approved by: Alejandro J. Cura
Approved revision: 133
Merged at revision: 133
Proposed branch: lp:~alecu/unity-lens-music/plan-b
Merge into: lp:unity-lens-music
Diff against target: 140 lines (+44/-10)
3 files modified
src/musicstore-scope.vala (+26/-6)
src/ubuntuone-webservices.vala (+9/-3)
tests/unit/test-ubuntuone-purchases.vala (+9/-1)
To merge this branch: bzr merge lp:~alecu/unity-lens-music/plan-b
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+158419@code.launchpad.net

Commit message

Hint the credentials state, so the preview can show it

Description of the change

Hint the credentials state, so the preview can show it

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michal Hruby (mhr3) wrote :

Looks reasonable to me, but the UIFe has to be granted before merging this.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/musicstore-scope.vala'
2--- src/musicstore-scope.vala 2013-02-28 09:48:46 +0000
3+++ src/musicstore-scope.vala 2013-04-11 16:23:24 +0000
4@@ -18,15 +18,19 @@
5 */
6
7 using GLib;
8+using Ubuntuone.Webservice;
9
10 namespace Unity.MusicLens {
11
12 public class MusicStoreScopeProxy : SimpleScope
13 {
14+ const string NO_CREDENTIALS_LABEL_TEXT = _("Before you can purchase music you need to log in to the Ubuntu One app");
15 private MusicStoreCollection collection;
16 private Unity.Extras.PreviewPlayerController preview_player;
17 private Unity.MusicPreview? music_preview;
18 private PreferencesManager preferences = PreferencesManager.get_default ();
19+ private PurchaseService purchase_service;
20+ private bool have_credentials = false;
21
22 public MusicStoreScopeProxy ()
23 {
24@@ -41,6 +45,7 @@
25 base.initialize ();
26
27 collection = new MusicStoreCollection ();
28+ purchase_service = new PurchaseService ();
29
30 preferences.notify["remote-content-search"].connect((obj, pspec) => { scope.queue_search_changed(SearchType.DEFAULT); });
31
32@@ -111,12 +116,19 @@
33 }
34 }
35
36- GLib.Icon? icon = new GLib.FileIcon (File.new_for_path (Config.DATADIR + "/icons/unity-icon-theme/places/svg/service-u1.svg"));
37- var download_action = new Unity.PreviewAction ("download_album", _("Download"), icon);
38- if (album.formatted_price != null)
39- download_action.extra_text = album.formatted_price;
40- download_action.activated.connect (download_album);
41- music_preview.add_action (download_action);
42+ if (have_credentials) {
43+ GLib.Icon? icon = new GLib.FileIcon (File.new_for_path (Config.DATADIR + "/icons/unity-icon-theme/places/svg/service-u1.svg"));
44+ var download_action = new Unity.PreviewAction ("download_album", _("Download"), icon);
45+ if (album.formatted_price != null)
46+ download_action.extra_text = album.formatted_price;
47+ download_action.activated.connect (download_album);
48+ music_preview.add_action (download_action);
49+ } else {
50+ var data = new HashTable<string, Variant>(str_hash, str_equal);
51+ data["no_credentials_label"] = NO_CREDENTIALS_LABEL_TEXT;
52+ InfoHint info_hint = new InfoHint.with_variant("music_preview", "", null, data);
53+ music_preview.add_info(info_hint);
54+ }
55 }
56 return music_preview;
57 }
58@@ -142,6 +154,14 @@
59 }
60
61 try {
62+ yield purchase_service.fetch_credentials ();
63+ have_credentials = true;
64+ } catch (PurchaseError e) {
65+ // this is not a serious error, just missing credentials
66+ have_credentials = false;
67+ }
68+
69+ try {
70 debug ("model has %u rows before search", search.results_model.get_n_rows ());
71 yield collection.search (search, search_type, (owned) filters, max_results, cancellable);
72 debug ("model has %u rows after search", search.results_model.get_n_rows ());
73
74=== modified file 'src/ubuntuone-webservices.vala'
75--- src/ubuntuone-webservices.vala 2012-12-06 15:39:38 +0000
76+++ src/ubuntuone-webservices.vala 2013-04-11 16:23:24 +0000
77@@ -22,7 +22,8 @@
78 [DBus (name = "com.ubuntuone.CredentialsManagement")]
79 interface CredentialsManagement : GLib.Object {
80 public signal void credentials_found (HashTable <string, string> info);
81- public signal void credentials_error ();
82+ public signal void credentials_not_found ();
83+ public signal void credentials_error (HashTable <string, string> error_dict);
84
85 [DBus (name = "find_credentials")]
86 public abstract void find_credentials () throws IOError;
87@@ -146,7 +147,7 @@
88 return payload.get_string_member("open_url");
89 }
90
91- internal virtual async void fetch_credentials () throws PurchaseError
92+ public virtual async void fetch_credentials () throws PurchaseError
93 {
94 PurchaseError error = null;
95
96@@ -155,7 +156,11 @@
97 debug ("got credentials");
98 fetch_credentials.callback ();
99 });
100- ulong error_handler = credentials_management.credentials_error.connect (() => {
101+ ulong not_found_handler = credentials_management.credentials_not_found.connect (() => {
102+ error = new PurchaseError.PURCHASE_ERROR ("No Ubuntu One tokens.");
103+ fetch_credentials.callback ();
104+ });
105+ ulong error_handler = credentials_management.credentials_error.connect ((error_dict) => {
106 error = new PurchaseError.PURCHASE_ERROR ("Can't get Ubuntu One tokens.");
107 fetch_credentials.callback ();
108 });
109@@ -168,6 +173,7 @@
110 }
111
112 credentials_management.disconnect (found_handler);
113+ credentials_management.disconnect (not_found_handler);
114 credentials_management.disconnect (error_handler);
115
116 if (error != null) {
117
118=== modified file 'tests/unit/test-ubuntuone-purchases.vala'
119--- tests/unit/test-ubuntuone-purchases.vala 2012-12-06 15:39:38 +0000
120+++ tests/unit/test-ubuntuone-purchases.vala 2013-04-11 16:23:24 +0000
121@@ -210,10 +210,18 @@
122
123 class FailingCredentialsManagement : GLib.Object, CredentialsManagement
124 {
125+ private HashTable <string, string> fake_error_info;
126+
127+ construct
128+ {
129+ fake_error_info = new HashTable <string, string> (str_hash, str_equal);
130+ fake_error_info["error"] = "fake_error";
131+ }
132+
133 public void find_credentials () throws IOError
134 {
135 Idle.add (() => {
136- credentials_error ();
137+ credentials_error (fake_error_info);
138 return false;
139 });
140 }

Subscribers

People subscribed via source and target branches

to all changes: