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
=== modified file 'src/musicstore-scope.vala'
--- src/musicstore-scope.vala 2013-02-28 09:48:46 +0000
+++ src/musicstore-scope.vala 2013-04-11 16:23:24 +0000
@@ -18,15 +18,19 @@
18 */18 */
1919
20using GLib;20using GLib;
21using Ubuntuone.Webservice;
2122
22namespace Unity.MusicLens {23namespace Unity.MusicLens {
2324
24 public class MusicStoreScopeProxy : SimpleScope25 public class MusicStoreScopeProxy : SimpleScope
25 {26 {
27 const string NO_CREDENTIALS_LABEL_TEXT = _("Before you can purchase music you need to log in to the Ubuntu One app");
26 private MusicStoreCollection collection;28 private MusicStoreCollection collection;
27 private Unity.Extras.PreviewPlayerController preview_player;29 private Unity.Extras.PreviewPlayerController preview_player;
28 private Unity.MusicPreview? music_preview;30 private Unity.MusicPreview? music_preview;
29 private PreferencesManager preferences = PreferencesManager.get_default ();31 private PreferencesManager preferences = PreferencesManager.get_default ();
32 private PurchaseService purchase_service;
33 private bool have_credentials = false;
3034
31 public MusicStoreScopeProxy ()35 public MusicStoreScopeProxy ()
32 {36 {
@@ -41,6 +45,7 @@
41 base.initialize ();45 base.initialize ();
4246
43 collection = new MusicStoreCollection ();47 collection = new MusicStoreCollection ();
48 purchase_service = new PurchaseService ();
4449
45 preferences.notify["remote-content-search"].connect((obj, pspec) => { scope.queue_search_changed(SearchType.DEFAULT); });50 preferences.notify["remote-content-search"].connect((obj, pspec) => { scope.queue_search_changed(SearchType.DEFAULT); });
4651
@@ -111,12 +116,19 @@
111 }116 }
112 }117 }
113118
114 GLib.Icon? icon = new GLib.FileIcon (File.new_for_path (Config.DATADIR + "/icons/unity-icon-theme/places/svg/service-u1.svg"));119 if (have_credentials) {
115 var download_action = new Unity.PreviewAction ("download_album", _("Download"), icon);120 GLib.Icon? icon = new GLib.FileIcon (File.new_for_path (Config.DATADIR + "/icons/unity-icon-theme/places/svg/service-u1.svg"));
116 if (album.formatted_price != null)121 var download_action = new Unity.PreviewAction ("download_album", _("Download"), icon);
117 download_action.extra_text = album.formatted_price;122 if (album.formatted_price != null)
118 download_action.activated.connect (download_album);123 download_action.extra_text = album.formatted_price;
119 music_preview.add_action (download_action);124 download_action.activated.connect (download_album);
125 music_preview.add_action (download_action);
126 } else {
127 var data = new HashTable<string, Variant>(str_hash, str_equal);
128 data["no_credentials_label"] = NO_CREDENTIALS_LABEL_TEXT;
129 InfoHint info_hint = new InfoHint.with_variant("music_preview", "", null, data);
130 music_preview.add_info(info_hint);
131 }
120 }132 }
121 return music_preview;133 return music_preview;
122 }134 }
@@ -142,6 +154,14 @@
142 }154 }
143155
144 try {156 try {
157 yield purchase_service.fetch_credentials ();
158 have_credentials = true;
159 } catch (PurchaseError e) {
160 // this is not a serious error, just missing credentials
161 have_credentials = false;
162 }
163
164 try {
145 debug ("model has %u rows before search", search.results_model.get_n_rows ());165 debug ("model has %u rows before search", search.results_model.get_n_rows ());
146 yield collection.search (search, search_type, (owned) filters, max_results, cancellable);166 yield collection.search (search, search_type, (owned) filters, max_results, cancellable);
147 debug ("model has %u rows after search", search.results_model.get_n_rows ());167 debug ("model has %u rows after search", search.results_model.get_n_rows ());
148168
=== modified file 'src/ubuntuone-webservices.vala'
--- src/ubuntuone-webservices.vala 2012-12-06 15:39:38 +0000
+++ src/ubuntuone-webservices.vala 2013-04-11 16:23:24 +0000
@@ -22,7 +22,8 @@
22[DBus (name = "com.ubuntuone.CredentialsManagement")]22[DBus (name = "com.ubuntuone.CredentialsManagement")]
23interface CredentialsManagement : GLib.Object {23interface CredentialsManagement : GLib.Object {
24 public signal void credentials_found (HashTable <string, string> info);24 public signal void credentials_found (HashTable <string, string> info);
25 public signal void credentials_error ();25 public signal void credentials_not_found ();
26 public signal void credentials_error (HashTable <string, string> error_dict);
2627
27 [DBus (name = "find_credentials")]28 [DBus (name = "find_credentials")]
28 public abstract void find_credentials () throws IOError;29 public abstract void find_credentials () throws IOError;
@@ -146,7 +147,7 @@
146 return payload.get_string_member("open_url");147 return payload.get_string_member("open_url");
147 }148 }
148149
149 internal virtual async void fetch_credentials () throws PurchaseError150 public virtual async void fetch_credentials () throws PurchaseError
150 {151 {
151 PurchaseError error = null;152 PurchaseError error = null;
152153
@@ -155,7 +156,11 @@
155 debug ("got credentials");156 debug ("got credentials");
156 fetch_credentials.callback ();157 fetch_credentials.callback ();
157 });158 });
158 ulong error_handler = credentials_management.credentials_error.connect (() => {159 ulong not_found_handler = credentials_management.credentials_not_found.connect (() => {
160 error = new PurchaseError.PURCHASE_ERROR ("No Ubuntu One tokens.");
161 fetch_credentials.callback ();
162 });
163 ulong error_handler = credentials_management.credentials_error.connect ((error_dict) => {
159 error = new PurchaseError.PURCHASE_ERROR ("Can't get Ubuntu One tokens.");164 error = new PurchaseError.PURCHASE_ERROR ("Can't get Ubuntu One tokens.");
160 fetch_credentials.callback ();165 fetch_credentials.callback ();
161 });166 });
@@ -168,6 +173,7 @@
168 }173 }
169174
170 credentials_management.disconnect (found_handler);175 credentials_management.disconnect (found_handler);
176 credentials_management.disconnect (not_found_handler);
171 credentials_management.disconnect (error_handler);177 credentials_management.disconnect (error_handler);
172178
173 if (error != null) {179 if (error != null) {
174180
=== modified file 'tests/unit/test-ubuntuone-purchases.vala'
--- tests/unit/test-ubuntuone-purchases.vala 2012-12-06 15:39:38 +0000
+++ tests/unit/test-ubuntuone-purchases.vala 2013-04-11 16:23:24 +0000
@@ -210,10 +210,18 @@
210210
211 class FailingCredentialsManagement : GLib.Object, CredentialsManagement211 class FailingCredentialsManagement : GLib.Object, CredentialsManagement
212 {212 {
213 private HashTable <string, string> fake_error_info;
214
215 construct
216 {
217 fake_error_info = new HashTable <string, string> (str_hash, str_equal);
218 fake_error_info["error"] = "fake_error";
219 }
220
213 public void find_credentials () throws IOError221 public void find_credentials () throws IOError
214 {222 {
215 Idle.add (() => {223 Idle.add (() => {
216 credentials_error ();224 credentials_error (fake_error_info);
217 return false;225 return false;
218 });226 });
219 }227 }

Subscribers

People subscribed via source and target branches

to all changes: