Merge lp:~mandel/ubuntuone-windows-installer/add_account_information into lp:ubuntuone-windows-installer/beta

Proposed by Manuel de la Peña
Status: Merged
Approved by: John Lenton
Approved revision: 180
Merged at revision: 139
Proposed branch: lp:~mandel/ubuntuone-windows-installer/add_account_information
Merge into: lp:ubuntuone-windows-installer/beta
Prerequisite: lp:~mandel/ubuntuone-windows-installer/manage_devices
Diff against target: 478 lines (+311/-43)
11 files modified
src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml (+4/-4)
src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml.cs (+14/-29)
src/Canonical.UbuntuOne.Client/Account.cs (+41/-0)
src/Canonical.UbuntuOne.Client/AccountException.cs (+57/-0)
src/Canonical.UbuntuOne.Client/AccountFactory.cs (+90/-0)
src/Canonical.UbuntuOne.Client/Canonical.UbuntuOne.Client.csproj (+5/-0)
src/Canonical.UbuntuOne.Client/DeviceManager.cs (+12/-9)
src/Canonical.UbuntuOne.Client/IAccount.cs (+41/-0)
src/Canonical.UbuntuOne.Client/IAccountFactory.cs (+32/-0)
src/Canonical.UbuntuOne.Client/Preferences/PreferencesDialogPresenter.cs (+11/-1)
src/Canonical.UbuntuOne.Client/objects.xml (+4/-0)
To merge this branch: bzr merge lp:~mandel/ubuntuone-windows-installer/add_account_information
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Review via email: mp+40822@code.launchpad.net

Description of the change

Re-activates the account tab and gets the account information from the rest service.

To post a comment you must log in.
180. By Manuel de la Peña

Added code to manage accounts

Revision history for this message
John Lenton (chipaca) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml'
2--- src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml 2010-11-15 02:17:01 +0000
3+++ src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml 2010-11-15 02:17:02 +0000
4@@ -45,8 +45,11 @@
5 <Label Name="StatusLabel" Grid.Row="1">Disconnected</Label>
6 </Grid>
7 <TabControl Margin="3" Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
8+ <TabItem Header="{x:Static resx:Resources.PreferencesDialogAccountTabHeader}" >
9+ <Views:AccountView x:Name="AccountsTab" Height="300" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
10+ </TabItem>
11 <TabItem Header="{x:Static resx:Resources.PreferencesDialogDevicesTabHeader}" >
12- <Views:DevicesView x:Name="DevicesTab" Height="300" HorizontalAlignment="Stretch"/>
13+ <Views:DevicesView x:Name="DevicesTab" Height="300" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
14 </TabItem>
15 <TabItem Header="{x:Static resx:Resources.PreferencesDialogWindowsTabHeader}">
16 <Views:WindowsSettingsView x:Name="WindowsTab" Height="300" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
17@@ -55,9 +58,6 @@
18 <Views:BetaView x:Name="BetaTab" Height="300" IsEnabled="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
19 </TabItem>
20 <!--
21- <TabItem Header="{x:Static resx:Resources.PreferencesDialogAccountTabHeader}" >
22- <Views:AccountView x:Name="AccountsTab" Height="300" IsEnabled="False"/>
23- </TabItem>
24
25 <TabItem Header="{x:Static resx:Resources.PreferencesDialogServicesTabHeader}" >
26 <Views:ServicesView x:Name="ServicesTab" Height="300" IsEnabled="False"/>
27
28=== modified file 'src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml.cs'
29--- src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml.cs 2010-11-15 02:17:01 +0000
30+++ src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml.cs 2010-11-15 02:17:02 +0000
31@@ -59,20 +59,20 @@
32 InitializeComponent();
33 }
34
35- //public string UserName
36- //{
37- // set { AccountsTab.UserName = value; }
38- //}
39-
40- //public string Email
41- //{
42- // set { AccountsTab.Email = value; }
43- //}
44-
45- //public string CurrentPlan
46- //{
47- // set { AccountsTab.CurrentPlan = value; }
48- //}
49+ public string UserName
50+ {
51+ set { AccountsTab.UserName = value; }
52+ }
53+
54+ public string Email
55+ {
56+ set { AccountsTab.Email = value; }
57+ }
58+
59+ public string CurrentPlan
60+ {
61+ set { AccountsTab.CurrentPlan = value; }
62+ }
63
64 //public bool IsBookmarksSynced
65 //{
66@@ -129,21 +129,6 @@
67 set { DevicesTab.Devices = value; }
68 }
69
70- public string UserName
71- {
72- set { }
73- }
74-
75- public string Email
76- {
77- set { }
78- }
79-
80- public string CurrentPlan
81- {
82- set { }
83- }
84-
85 public bool IsBookmarksSynced
86 {
87 get { return false; }
88
89=== added file 'src/Canonical.UbuntuOne.Client/Account.cs'
90--- src/Canonical.UbuntuOne.Client/Account.cs 1970-01-01 00:00:00 +0000
91+++ src/Canonical.UbuntuOne.Client/Account.cs 2010-11-15 02:17:02 +0000
92@@ -0,0 +1,41 @@
93+/* Copyright 2010 Canonical Ltd.
94+ *
95+ * This file is part of UbuntuOne on Windows.
96+ *
97+ * UbuntuOne on Windows is free software: you can redistribute it and/or modify
98+ * it under the terms of the GNU Lesser General Public License version
99+ * as published by the Free Software Foundation.
100+ *
101+ * Ubuntu One on Windows is distributed in the hope that it will be useful,
102+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
103+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
104+ * GNU Lesser General Public License for more details.
105+ *
106+ * You should have received a copy of the GNU Lesser General Public License
107+ * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
108+ *
109+ * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
110+ */
111+namespace Canonical.UbuntuOne.Client
112+{
113+ /// <summary>
114+ /// Represents the account information of the user in ubuntu one.
115+ /// </summary>
116+ public class Account : IAccount
117+ {
118+ /// <summary>
119+ /// Gets and sets the name of the user.
120+ /// </summary>
121+ public string Name { get; set; }
122+
123+ /// <summary>
124+ /// Gets and sets the email of the user.
125+ /// </summary>
126+ public string EmailAddress { get; set; }
127+
128+ /// <summary>
129+ /// Gets and sets a description of the user current plan.
130+ /// </summary>
131+ public string CurrentPlan { get; set; }
132+ }
133+}
134
135=== added file 'src/Canonical.UbuntuOne.Client/AccountException.cs'
136--- src/Canonical.UbuntuOne.Client/AccountException.cs 1970-01-01 00:00:00 +0000
137+++ src/Canonical.UbuntuOne.Client/AccountException.cs 2010-11-15 02:17:02 +0000
138@@ -0,0 +1,57 @@
139+/* Copyright 2010 Canonical Ltd.
140+ *
141+ * This file is part of UbuntuOne on Windows.
142+ *
143+ * UbuntuOne on Windows is free software: you can redistribute it and/or modify
144+ * it under the terms of the GNU Lesser General Public License version
145+ * as published by the Free Software Foundation.
146+ *
147+ * Ubuntu One on Windows is distributed in the hope that it will be useful,
148+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
149+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
150+ * GNU Lesser General Public License for more details.
151+ *
152+ * You should have received a copy of the GNU Lesser General Public License
153+ * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
154+ *
155+ * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
156+ */
157+using System;
158+
159+namespace Canonical.UbuntuOne.Client
160+{
161+ /// <summary>
162+ /// Exception thrown when there are issues retrieving the data of the users account.
163+ /// </summary>
164+ public class AccountException : Exception
165+ {
166+ /// <summary>
167+ /// Creates a new instace of the object.
168+ /// </summary>
169+ public AccountException()
170+ {
171+
172+ }
173+
174+ /// <summary>
175+ /// Creates a new instance that carries the given message.
176+ /// </summary>
177+ /// <param name="message">The message to be carried by the exception.</param>
178+ public AccountException(string message)
179+ : base(message)
180+ {
181+
182+ }
183+
184+ /// <summary>
185+ /// Creates a new exception with the given message and inner exception.
186+ /// </summary>
187+ /// <param name="message">The message to be carried by the exception.</param>
188+ /// <param name="inner">The inner exception that creatd the exception.</param>
189+ public AccountException(string message, Exception inner)
190+ : base(message, inner)
191+ {
192+
193+ }
194+ }
195+}
196
197=== added file 'src/Canonical.UbuntuOne.Client/AccountFactory.cs'
198--- src/Canonical.UbuntuOne.Client/AccountFactory.cs 1970-01-01 00:00:00 +0000
199+++ src/Canonical.UbuntuOne.Client/AccountFactory.cs 2010-11-15 02:17:02 +0000
200@@ -0,0 +1,90 @@
201+/* Copyright 2010 Canonical Ltd.
202+ *
203+ * This file is part of UbuntuOne on Windows.
204+ *
205+ * UbuntuOne on Windows is free software: you can redistribute it and/or modify
206+ * it under the terms of the GNU Lesser General Public License version
207+ * as published by the Free Software Foundation.
208+ *
209+ * Ubuntu One on Windows is distributed in the hope that it will be useful,
210+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
211+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
212+ * GNU Lesser General Public License for more details.
213+ *
214+ * You should have received a copy of the GNU Lesser General Public License
215+ * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
216+ *
217+ * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
218+ */
219+using System;
220+using System.IO;
221+using Canonical.Ubuntu.SSO;
222+using Canonical.UbuntuOne.Common.Net;
223+using Newtonsoft.Json.Linq;
224+
225+namespace Canonical.UbuntuOne.Client
226+{
227+ /// <summary>
228+ /// Factory that creates the account information of the user.
229+ /// </summary>
230+ internal class AccountFactory : IAccountFactory
231+ {
232+ #region Variables
233+
234+ internal const string AccountUri = "https://one.ubuntu.com/api/account/";
235+ #endregion
236+
237+ #region Di properties
238+
239+ /// <summary>
240+ /// Gets and sets the SSO provider that returns the credentials of the user.
241+ /// </summary>
242+ public ISSOCredentialsProvider SSOCredentialsProvider { get; set; }
243+
244+ /// <summary>
245+ /// Gets and sets the oauth object that can be used to sign the http requests.
246+ /// </summary>
247+ public IOAuth OAuth { get; set; }
248+
249+ #endregion
250+
251+ /// <summary>
252+ /// Creates the account information of the current user in ubuntu one.
253+ /// </summary>
254+ /// <returns>The account information of the user.</returns>
255+ public IAccount Create()
256+ {
257+ string token;
258+ string tokenSecret;
259+ string consumerKey;
260+ string consumerSecret;
261+
262+ // get the credentials
263+ SSOCredentialsProvider.LoginToGetCredentials("UbuntuOne", out token, out tokenSecret, out consumerKey,
264+ out consumerSecret);
265+ var request = OAuth.MakeRequest(AccountUri, "GET", consumerKey, consumerSecret, token, tokenSecret);
266+ try
267+ {
268+ var response = request.GetResponse();
269+ using(var stream = response.GetResponseStream())
270+ {
271+ var data = new StreamReader(stream).ReadToEnd();
272+ var jobject = JObject.Parse(data);
273+ var subscriptionObject = (JObject)jobject["subscription"];
274+ var account = new Account
275+ {
276+ Name = (string) jobject["nickname"],
277+ EmailAddress = (string) jobject["email"],
278+ CurrentPlan = (string) subscriptionObject["description"]
279+ };
280+
281+ return account;
282+ }
283+ }
284+ catch (Exception e)
285+ {
286+ throw new AccountException("The account information could not be retrieved.", e);
287+ }
288+ }
289+ }
290+}
291
292=== modified file 'src/Canonical.UbuntuOne.Client/Canonical.UbuntuOne.Client.csproj'
293--- src/Canonical.UbuntuOne.Client/Canonical.UbuntuOne.Client.csproj 2010-11-15 02:17:01 +0000
294+++ src/Canonical.UbuntuOne.Client/Canonical.UbuntuOne.Client.csproj 2010-11-15 02:17:02 +0000
295@@ -74,10 +74,15 @@
296 <Compile Include="..\Version.cs">
297 <Link>Properties\Version.cs</Link>
298 </Compile>
299+ <Compile Include="Account.cs" />
300+ <Compile Include="AccountException.cs" />
301+ <Compile Include="AccountFactory.cs" />
302 <Compile Include="Device.cs" />
303 <Compile Include="DeviceFactory.cs" />
304 <Compile Include="DeviceManager.cs" />
305 <Compile Include="DeviceManagerException.cs" />
306+ <Compile Include="IAccount.cs" />
307+ <Compile Include="IAccountFactory.cs" />
308 <Compile Include="IDevice.cs" />
309 <Compile Include="IDeviceFactory.cs" />
310 <Compile Include="IDeviceManager.cs" />
311
312=== modified file 'src/Canonical.UbuntuOne.Client/DeviceManager.cs'
313--- src/Canonical.UbuntuOne.Client/DeviceManager.cs 2010-11-15 02:17:01 +0000
314+++ src/Canonical.UbuntuOne.Client/DeviceManager.cs 2010-11-15 02:17:02 +0000
315@@ -114,7 +114,7 @@
316 var request = OAuth.MakeRequest(uri, "GET", consumerKey, consumerSecret, token, tokenSecret);
317 try
318 {
319- var response = request.GetResponse();
320+ request.GetResponse();
321 }
322 catch (Exception e)
323 {
324@@ -139,14 +139,17 @@
325 try
326 {
327 var response = request.GetResponse();
328- var data = new StreamReader(response.GetResponseStream()).ReadToEnd();
329- // parse the json string
330- var devicesArray = JArray.Parse(data);
331- return devicesArray.Select(currentJDevice =>
332- DeviceFactory.Create(
333- (string) currentJDevice["description"],
334- (string) currentJDevice["token"],
335- (string) currentJDevice["kind"])).ToList();
336+ using (var stream = response.GetResponseStream())
337+ {
338+ var data = new StreamReader(stream).ReadToEnd();
339+ // parse the json string
340+ var devicesArray = JArray.Parse(data);
341+ return devicesArray.Select(currentJDevice =>
342+ DeviceFactory.Create(
343+ (string) currentJDevice["description"],
344+ (string) currentJDevice["token"],
345+ (string) currentJDevice["kind"])).ToList();
346+ }
347 }
348 catch (Exception e)
349 {
350
351=== added file 'src/Canonical.UbuntuOne.Client/IAccount.cs'
352--- src/Canonical.UbuntuOne.Client/IAccount.cs 1970-01-01 00:00:00 +0000
353+++ src/Canonical.UbuntuOne.Client/IAccount.cs 2010-11-15 02:17:02 +0000
354@@ -0,0 +1,41 @@
355+/* Copyright 2010 Canonical Ltd.
356+ *
357+ * This file is part of UbuntuOne on Windows.
358+ *
359+ * UbuntuOne on Windows is free software: you can redistribute it and/or modify
360+ * it under the terms of the GNU Lesser General Public License version
361+ * as published by the Free Software Foundation.
362+ *
363+ * Ubuntu One on Windows is distributed in the hope that it will be useful,
364+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
365+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
366+ * GNU Lesser General Public License for more details.
367+ *
368+ * You should have received a copy of the GNU Lesser General Public License
369+ * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
370+ *
371+ * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
372+ */
373+namespace Canonical.UbuntuOne.Client
374+{
375+ /// <summary>
376+ /// Interface that represents the account information of a user.
377+ /// </summary>
378+ public interface IAccount
379+ {
380+ /// <summary>
381+ /// Gets and sets the name of the user.
382+ /// </summary>
383+ string Name { get; set; }
384+
385+ /// <summary>
386+ /// Gets and sets the email of the user.
387+ /// </summary>
388+ string EmailAddress { get; set; }
389+
390+ /// <summary>
391+ /// Gets and sets a description of the user current plan.
392+ /// </summary>
393+ string CurrentPlan { get; set; }
394+ }
395+}
396\ No newline at end of file
397
398=== added file 'src/Canonical.UbuntuOne.Client/IAccountFactory.cs'
399--- src/Canonical.UbuntuOne.Client/IAccountFactory.cs 1970-01-01 00:00:00 +0000
400+++ src/Canonical.UbuntuOne.Client/IAccountFactory.cs 2010-11-15 02:17:02 +0000
401@@ -0,0 +1,32 @@
402+/* Copyright 2010 Canonical Ltd.
403+ *
404+ * This file is part of UbuntuOne on Windows.
405+ *
406+ * UbuntuOne on Windows is free software: you can redistribute it and/or modify
407+ * it under the terms of the GNU Lesser General Public License version
408+ * as published by the Free Software Foundation.
409+ *
410+ * Ubuntu One on Windows is distributed in the hope that it will be useful,
411+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
412+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
413+ * GNU Lesser General Public License for more details.
414+ *
415+ * You should have received a copy of the GNU Lesser General Public License
416+ * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
417+ *
418+ * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
419+ */
420+namespace Canonical.UbuntuOne.Client
421+{
422+ /// <summary>
423+ /// Interface to be implemented by an object that knows how to get the account information of the current user.
424+ /// </summary>
425+ public interface IAccountFactory
426+ {
427+ /// <summary>
428+ /// Creates the account information of the current user in ubuntu one.
429+ /// </summary>
430+ /// <returns>The account information of the user.</returns>
431+ IAccount Create();
432+ }
433+}
434\ No newline at end of file
435
436=== modified file 'src/Canonical.UbuntuOne.Client/Preferences/PreferencesDialogPresenter.cs'
437--- src/Canonical.UbuntuOne.Client/Preferences/PreferencesDialogPresenter.cs 2010-11-15 02:17:01 +0000
438+++ src/Canonical.UbuntuOne.Client/Preferences/PreferencesDialogPresenter.cs 2010-11-15 02:17:02 +0000
439@@ -114,6 +114,11 @@
440 /// </summary>
441 public IOAuth OAuth { get; set; }
442
443+ /// <summary>
444+ /// Gets and sets the account factory used to get the account information.
445+ /// </summary>
446+ public IAccountFactory AccountFactory { get; set; }
447+
448 #endregion
449
450 #region Helpers
451@@ -196,7 +201,12 @@
452 PreferencesView.Consumption = consumption;
453 PreferencesView.ConsumptionText = string.Format("{0}% used", consumption);
454 PreferencesView.Devices = DeviceManager.GetSyncedDevices();
455-
456+ // set account info
457+ var accountInfo = AccountFactory.Create();
458+ PreferencesView.UserName = accountInfo.Name;
459+ PreferencesView.Email = accountInfo.EmailAddress;
460+ PreferencesView.CurrentPlan = accountInfo.CurrentPlan;
461+
462 if (PreferencesManager.IsAutoSyncEnable)
463 PreferencesView.AutoSyncFrequency = PreferencesManager.AutoSyncFrequency;
464 PreferencesView.ShowDialog();
465
466=== modified file 'src/Canonical.UbuntuOne.Client/objects.xml'
467--- src/Canonical.UbuntuOne.Client/objects.xml 2010-11-15 02:17:01 +0000
468+++ src/Canonical.UbuntuOne.Client/objects.xml 2010-11-15 02:17:02 +0000
469@@ -21,4 +21,8 @@
470 <object id="DeviceFactory"
471 type="Canonical.UbuntuOne.Client.DeviceFactory, Canonical.UbuntuOne.Client"
472 autowire="autodetect"/>
473+
474+ <object id="AccountFactory"
475+ type="Canonical.UbuntuOne.Client.AccountFactory, Canonical.UbuntuOne.Client"
476+ autowire="autodetect"/>
477 </objects>
478\ No newline at end of file

Subscribers

People subscribed via source and target branches

to all changes: