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

Proposed by Manuel de la Peña
Status: Merged
Approved by: John Lenton
Approved revision: 178
Merged at revision: 136
Proposed branch: lp:~mandel/ubuntuone-windows-installer/manage_devices
Merge into: lp:ubuntuone-windows-installer/beta
Diff against target: 1565 lines (+1025/-55)
33 files modified
src/Canonical.Ubuntu.SSO.Tests/SSOLoginProcessorFixture.cs (+0/-1)
src/Canonical.Ubuntu.SSO/Canonical.Ubuntu.SSO.csproj (+0/-2)
src/Canonical.Ubuntu.SSO/IKeyring.cs (+7/-0)
src/Canonical.Ubuntu.SSO/ISSOCredentialsProvider.cs (+16/-0)
src/Canonical.Ubuntu.SSO/Keyring.cs (+21/-0)
src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs (+65/-0)
src/Canonical.Ubuntu.SSO/SSOLoginProcessor.cs (+1/-30)
src/Canonical.Ubuntu.SSO/objects.xml (+0/-3)
src/Canonical.UbuntuOne.Client.Test/Canonical.UbuntuOne.Client.Test.csproj (+5/-0)
src/Canonical.UbuntuOne.Client.Test/DeviceFactoryFixture.cs (+92/-0)
src/Canonical.UbuntuOne.Client.Views/Canonical.UbuntuOne.Client.Views.csproj (+7/-0)
src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml (+23/-0)
src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml.cs (+51/-0)
src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml (+4/-4)
src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml.cs (+31/-0)
src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml (+11/-10)
src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml.cs (+42/-1)
src/Canonical.UbuntuOne.Client/Canonical.UbuntuOne.Client.csproj (+10/-0)
src/Canonical.UbuntuOne.Client/Device.cs (+38/-0)
src/Canonical.UbuntuOne.Client/DeviceFactory.cs (+57/-0)
src/Canonical.UbuntuOne.Client/DeviceManager.cs (+157/-0)
src/Canonical.UbuntuOne.Client/DeviceManagerException.cs (+57/-0)
src/Canonical.UbuntuOne.Client/IDevice.cs (+57/-0)
src/Canonical.UbuntuOne.Client/IDeviceFactory.cs (+35/-0)
src/Canonical.UbuntuOne.Client/IDeviceManager.cs (+48/-0)
src/Canonical.UbuntuOne.Client/Preferences/IPreferencesDialogPresenter.cs (+7/-0)
src/Canonical.UbuntuOne.Client/Preferences/IPreferencesView.cs (+22/-0)
src/Canonical.UbuntuOne.Client/Preferences/PreferencesDialogPresenter.cs (+78/-1)
src/Canonical.UbuntuOne.Client/objects.xml (+7/-0)
src/Canonical.UbuntuOne.Common/Canonical.UbuntuOne.Common.csproj (+3/-0)
src/Canonical.UbuntuOne.Common/Net/IOAuth.cs (+17/-1)
src/Canonical.UbuntuOne.Common/Net/OAuth.cs (+52/-2)
src/Canonical.UbuntuOne.Common/objects.xml (+4/-0)
To merge this branch: bzr merge lp:~mandel/ubuntuone-windows-installer/manage_devices
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Review via email: mp+40816@code.launchpad.net

Description of the change

Allows to remove the current machine from ubuntu one by adding a way to manage your devices.

To post a comment you must log in.
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.Ubuntu.SSO.Tests/SSOLoginProcessorFixture.cs'
2--- src/Canonical.Ubuntu.SSO.Tests/SSOLoginProcessorFixture.cs 2010-10-05 09:49:29 +0000
3+++ src/Canonical.Ubuntu.SSO.Tests/SSOLoginProcessorFixture.cs 2010-11-14 21:31:15 +0000
4@@ -54,7 +54,6 @@
5 _processor = new SSOLoginProcessor
6 {
7 Authentications = _auth,
8- HttpWebRequestFactory = _requestFactory,
9 Keyring = _keyring,
10 OAuth = _oauth,
11 SSOCredentialsEncoder = _encode
12
13=== modified file 'src/Canonical.Ubuntu.SSO/Canonical.Ubuntu.SSO.csproj'
14--- src/Canonical.Ubuntu.SSO/Canonical.Ubuntu.SSO.csproj 2010-10-12 13:07:02 +0000
15+++ src/Canonical.Ubuntu.SSO/Canonical.Ubuntu.SSO.csproj 2010-11-14 21:31:15 +0000
16@@ -89,13 +89,11 @@
17 <Compile Include="IDataProtector.cs" />
18 <Compile Include="ILoginOrRegisterView.cs" />
19 <Compile Include="ILoginView.cs" />
20- <Compile Include="IOAuth.cs" />
21 <Compile Include="ISSOCredentialsEncoder.cs" />
22 <Compile Include="ISSOLoginProcessor.cs" />
23 <Compile Include="JsonSSOCredentialsEncoder.cs" />
24 <Compile Include="Keyring.cs" />
25 <Compile Include="LoginCredentialsEventArgs.cs" />
26- <Compile Include="OAuth.cs" />
27 <Compile Include="Service\Account.cs" />
28 <Compile Include="Service\AccountDiff.cs" />
29 <Compile Include="Service\AccountFull.cs" />
30
31=== modified file 'src/Canonical.Ubuntu.SSO/IKeyring.cs'
32--- src/Canonical.Ubuntu.SSO/IKeyring.cs 2010-09-16 16:18:56 +0000
33+++ src/Canonical.Ubuntu.SSO/IKeyring.cs 2010-11-14 21:31:15 +0000
34@@ -37,6 +37,13 @@
35 void CreateSecret(string keyringName, string applicationName, string secret);
36
37 /// <summary>
38+ /// Removes the given secret from the keyring.
39+ /// </summary>
40+ /// <param name="keyring">The keyring where th esecret is found.</param>
41+ /// <param name="applicationName">The name of the application.</param>
42+ void RemoveSecret(string keyring, string applicationName);
43+
44+ /// <summary>
45 /// Gets the secret froma keyring using the name of the application that stored it.
46 /// </summary>
47 /// <param name="keyringName">The name of the keyring where the secret was stored.</param>
48
49=== modified file 'src/Canonical.Ubuntu.SSO/ISSOCredentialsProvider.cs'
50--- src/Canonical.Ubuntu.SSO/ISSOCredentialsProvider.cs 2010-10-18 10:53:55 +0000
51+++ src/Canonical.Ubuntu.SSO/ISSOCredentialsProvider.cs 2010-11-14 21:31:15 +0000
52@@ -72,6 +72,22 @@
53 /// </summary>
54 void LoginOrRegisterToGetCredentials();
55
56+ /// <summary>
57+ /// Returns the credentials of the user and requests a login if necesary.
58+ /// </summary>
59+ /// <param name="applicationName">The name of the application requesting the info.</param>
60+ /// <param name="token">The token part of the oauth.</param>
61+ /// <param name="tokenSecret">The token secret of the part of the oauth.</param>
62+ /// <param name="consumerKey">The consumer key of the oauth.</param>
63+ /// <param name="consumerSecret">The consumer secret of the oauth.</param>
64+ void LoginToGetCredentials(string applicationName, out string token, out string tokenSecret, out string consumerKey, out string consumerSecret);
65+
66+ /// <summary>
67+ /// Removes the credentials for the given application name in the machine.
68+ /// </summary>
69+ /// <param name="applicationName">The name of the applications whose credentials we want to remove.</param>
70+ void RemoveCredentials(string applicationName);
71+
72 #endregion
73
74 }
75
76=== modified file 'src/Canonical.Ubuntu.SSO/Keyring.cs'
77--- src/Canonical.Ubuntu.SSO/Keyring.cs 2010-10-06 18:29:07 +0000
78+++ src/Canonical.Ubuntu.SSO/Keyring.cs 2010-11-14 21:31:15 +0000
79@@ -17,6 +17,7 @@
80 *
81 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
82 */
83+using System;
84 using System.Collections.Generic;
85 using System.Linq;
86 using System.Security.Cryptography;
87@@ -272,6 +273,26 @@
88 }
89
90 /// <summary>
91+ /// Removes the given secret from the keyring.
92+ /// </summary>
93+ /// <param name="keyringName">The keyring where th esecret is found.</param>
94+ /// <param name="applicationName">The name of the application.</param>
95+ public void RemoveSecret(string keyringName, string applicationName)
96+ {
97+ ValidateArgs.Begin()
98+ .IsNotNullOrEmpty(keyringName, "keyringName")
99+ .IsNotNullOrEmpty(applicationName, "applicationName")
100+ .Check();
101+ if(KeyringExist(keyringName))
102+ {
103+ using(var keyring = OpenKeyring(keyringName))
104+ {
105+ keyring.DeleteValue(applicationName);
106+ }
107+ }
108+ }
109+
110+ /// <summary>
111 /// Gets the secret froma keyring using the name of the application that stored it.
112 /// </summary>
113 /// <param name="keyringName">The name of the keyring where the secret was stored.</param>
114
115=== modified file 'src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs'
116--- src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs 2010-10-20 11:32:24 +0000
117+++ src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs 2010-11-14 21:31:15 +0000
118@@ -157,6 +157,71 @@
119 throw new NotImplementedException();
120 }
121
122+ /// <summary>
123+ /// Returns the credentials of the user and requests a login if necesary.
124+ /// </summary>
125+ /// <param name="token">The token part of the oauth.</param>
126+ /// <param name="tokenSecret">The token secret of the part of the oauth.</param>
127+ /// <param name="consumerKey">The consumer key of the oauth.</param>
128+ /// <param name="consumerSecret">The consumer secret of the oauth.</param>
129+ public void LoginToGetCredentials(string applicationName, out string token, out string tokenSecret, out string consumerKey, out string consumerSecret)
130+ {
131+ token = null;
132+ tokenSecret = null;
133+ consumerKey = null;
134+ consumerSecret = null;
135+ try
136+ {
137+ // try to get the credentials from the keyring
138+ var secret = Keyring.GetSecretByName(KeyringName, ApplicationName);
139+ if (secret == null)
140+ {
141+ // we need to use the processor to get the login info
142+ if (LoginView.ViewDispatcher.Dispatch(() => LoginView.IsShown))
143+ return;
144+
145+ if (LoginView.ViewDispatcher.Dispatch(() => LoginView.ShowDialog() != MessageBoxResult.Cancel))
146+ {
147+ var tokenName = string.Format(ApplicationTokenName, Environment.MachineName);
148+ secret = SSOLoginProcessor.Login(
149+ LoginView.ViewDispatcher.Dispatch(() => LoginView.EmailAddress),
150+ LoginView.ViewDispatcher.Dispatch(() => LoginView.Password),
151+ tokenName);
152+ // save the credentials in the keyring
153+ // TODO: We have an issue here since we have more than one listening for the same credntials of Ubuntu One
154+ Keyring.CreateSecret(KeyringName, applicationName, secret);
155+ }
156+ else
157+ {
158+ return;
159+ }
160+ }
161+ // we execute the credentials found event
162+ if (!string.IsNullOrEmpty(secret) && OnCredentialsFound != null)
163+ {
164+ SSOLoginProcessor.SSOCredentialsEncoder.Decode(secret, out token, out tokenSecret, out consumerKey, out consumerSecret);
165+ }
166+ }
167+ catch (SSOLoginException e)
168+ {
169+ // TODO: Show message!
170+ }
171+ catch (Exception e)
172+ {
173+ // TODO: Show message!
174+ }
175+ }
176+
177+ /// <summary>
178+ /// Removes the credentials for the given application name in the machine.
179+ /// </summary>
180+ /// <param name="applicationName">The name of the applications whose credentials we want to remove.</param>
181+ public void RemoveCredentials(string applicationName)
182+ {
183+ // TODO: Currently the application name is hardcoded!
184+ Keyring.RemoveSecret(KeyringName, ApplicationName);
185+ }
186+
187 #endregion
188 }
189 }
190
191=== modified file 'src/Canonical.Ubuntu.SSO/SSOLoginProcessor.cs'
192--- src/Canonical.Ubuntu.SSO/SSOLoginProcessor.cs 2010-10-05 15:20:36 +0000
193+++ src/Canonical.Ubuntu.SSO/SSOLoginProcessor.cs 2010-11-14 21:31:15 +0000
194@@ -58,40 +58,11 @@
195 /// </summary>
196 public IOAuth OAuth { get; set; }
197
198- public IHttpWebRequestFactory HttpWebRequestFactory { get; set; }
199-
200 #endregion
201
202 #region Helper methods}
203
204 /// <summary>
205- /// Creates an oauth request that can access a protected web resource.
206- /// </summary>
207- /// <param name="uri">The uri where the resource is found.</param>
208- /// <param name="httpMethod">The request berb to be used.</param>
209- /// <param name="consumerKey">Consumer key from oauth.</param>
210- /// <param name="consumerSecret">Consumer secret from oauth.</param>
211- /// <param name="token">Token from oauth.</param>
212- /// <param name="tokenSecret">Token secret from oauth.</param>
213- /// <returns>A webrequest that can be used to access the resource.</returns>
214- public IHttpWebRequest MakeRequest(string uri, string httpMethod, string consumerKey, string consumerSecret, string token, string tokenSecret)
215- {
216- // Form the full REST request url
217- var url = new Uri(uri);
218- string normUrl;
219- string normParams;
220-
221- // get oauth header
222- var authHeader = OAuth.GenerateHeaderWithSignature(url, string.Empty, consumerKey, consumerSecret,
223- token, tokenSecret, httpMethod, OAuth.GenerateTimeStamp(), OAuth.GenerateNonce(), SSO.OAuth.SignatureTypes.HMACSHA1,
224- out normUrl, out normParams);
225-
226- var request = HttpWebRequestFactory.Create(url);
227- request.Headers.Add(authHeader.Key, authHeader.Value);
228- return request;
229- }
230-
231- /// <summary>
232 /// Pings the Ubuntu One server so that the SSO tokens are added to them and they know how to identify the user.
233 /// </summary>
234 /// <param name="email">The email used by the user to register to u1.</param>
235@@ -102,7 +73,7 @@
236 private void PingUbuntuOneServer(string email, string consumerKey, string consumerSecret, string token, string tokenSecret)
237 {
238 // ping the service to make it download the tokens
239- var pingRequest = MakeRequest(Constants.PingUrl + email, "GET", consumerKey, consumerSecret,
240+ var pingRequest = OAuth.MakeRequest(Constants.PingUrl + email, "GET", consumerKey, consumerSecret,
241 token, tokenSecret);
242 try
243 {
244
245=== modified file 'src/Canonical.Ubuntu.SSO/objects.xml'
246--- src/Canonical.Ubuntu.SSO/objects.xml 2010-10-05 15:20:36 +0000
247+++ src/Canonical.Ubuntu.SSO/objects.xml 2010-11-14 21:31:15 +0000
248@@ -19,9 +19,6 @@
249 type="Canonical.Ubuntu.SSO.JsonSSOCredentialsEncoder , Canonical.Ubuntu.SSO"
250 autowire="autodetect"/>
251
252- <object id="OAuth"
253- type="Canonical.Ubuntu.SSO.OAuth , Canonical.Ubuntu.SSO"
254- autowire="autodetect"/>
255
256 <!-- The actual interesting objects to perform the SSO -->
257
258
259=== modified file 'src/Canonical.UbuntuOne.Client.Test/Canonical.UbuntuOne.Client.Test.csproj'
260--- src/Canonical.UbuntuOne.Client.Test/Canonical.UbuntuOne.Client.Test.csproj 2010-10-12 13:07:02 +0000
261+++ src/Canonical.UbuntuOne.Client.Test/Canonical.UbuntuOne.Client.Test.csproj 2010-11-14 21:31:15 +0000
262@@ -82,6 +82,7 @@
263 <Compile Include="..\Version.cs">
264 <Link>Properties\Version.cs</Link>
265 </Compile>
266+ <Compile Include="DeviceFactoryFixture.cs" />
267 <Compile Include="Notification\NotificationEventArgsFixture.cs" />
268 <Compile Include="Notification\NotificationPresenterFixture.cs" />
269 <Compile Include="Notification\OperationCompletenessEventArgsFixture.cs" />
270@@ -90,6 +91,10 @@
271 <Compile Include="Properties\AssemblyInfo.cs" />
272 </ItemGroup>
273 <ItemGroup>
274+ <ProjectReference Include="..\Canonical.Ubuntu.SSO\Canonical.Ubuntu.SSO.csproj">
275+ <Project>{9460A771-2589-45DA-9618-9FE8BB7D16E8}</Project>
276+ <Name>Canonical.Ubuntu.SSO</Name>
277+ </ProjectReference>
278 <ProjectReference Include="..\Canonical.UbuntuOne.Client\Canonical.UbuntuOne.Client.csproj">
279 <Project>{7467483A-D6D5-4362-8DF4-57A7254EB569}</Project>
280 <Name>Canonical.UbuntuOne.Client</Name>
281
282=== added file 'src/Canonical.UbuntuOne.Client.Test/DeviceFactoryFixture.cs'
283--- src/Canonical.UbuntuOne.Client.Test/DeviceFactoryFixture.cs 1970-01-01 00:00:00 +0000
284+++ src/Canonical.UbuntuOne.Client.Test/DeviceFactoryFixture.cs 2010-11-14 21:31:15 +0000
285@@ -0,0 +1,92 @@
286+/* Copyright 2010 Canonical Ltd.
287+ *
288+ * This file is part of UbuntuOne on Windows.
289+ *
290+ * UbuntuOne on Windows is free software: you can redistribute it and/or modify
291+ * it under the terms of the GNU Lesser General Public License version
292+ * as published by the Free Software Foundation.
293+ *
294+ * Ubuntu One on Windows is distributed in the hope that it will be useful,
295+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
296+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
297+ * GNU Lesser General Public License for more details.
298+ *
299+ * You should have received a copy of the GNU Lesser General Public License
300+ * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
301+ *
302+ * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
303+ */
304+using NUnit.Framework;
305+using Rhino.Mocks;
306+
307+namespace Canonical.UbuntuOne.Client.Test
308+{
309+ [TestFixture]
310+ public class DeviceFactoryFixture
311+ {
312+ #region Variables
313+
314+ private IDeviceManager _deviceManager;
315+ private MockRepository _mocks;
316+ private DeviceFactory _factory;
317+
318+ #endregion
319+
320+ #region Setup
321+
322+ [SetUp]
323+ public void SetUp()
324+ {
325+ _mocks = new MockRepository();
326+ _deviceManager = _mocks.StrictMock<IDeviceManager>();
327+ _factory = new DeviceFactory {DeviceManager = _deviceManager};
328+ }
329+
330+ #endregion
331+
332+ #region Tests
333+
334+ [TestCase("firstToken", "batman", "computer")]
335+ [TestCase("secondToken", "robin", "computer")]
336+ [TestCase("thirdToken", "blah blah", "phone")]
337+ public void CreateCurrentDeviceTest(string token, string description, string kind)
338+ {
339+ using (_mocks.Record())
340+ {
341+ Expect.Call(_deviceManager.IsCurrentMachine(token))
342+ .Repeat.Once()
343+ .Return(true);
344+ }
345+ using(_mocks.Playback())
346+ {
347+ var device = _factory.Create(description, token, kind);
348+ Assert.AreEqual(token, device.Token);
349+ Assert.AreEqual(DeviceFactory.CurrentMachine, device.Description);
350+ Assert.AreEqual(kind == "computer" ? DeviceType.COMPUTER : DeviceType.PHONE, device.Type);
351+ }
352+ }
353+
354+ [TestCase("firstToken", "batman", "computer")]
355+ [TestCase("secondToken", "robin", "computer")]
356+ [TestCase("thirdToken", "blah blah", "phone")]
357+ public void CreateOtherDeviceTest(string token, string description, string kind)
358+ {
359+ using (_mocks.Record())
360+ {
361+ Expect.Call(_deviceManager.IsCurrentMachine(token))
362+ .Repeat.Once()
363+ .Return(false);
364+ }
365+ using (_mocks.Playback())
366+ {
367+ var device = _factory.Create(description, token, kind);
368+ Assert.AreEqual(token, device.Token);
369+ Assert.AreEqual(description, device.Description);
370+ Assert.AreEqual(kind == "computer" ? DeviceType.COMPUTER : DeviceType.PHONE, device.Type);
371+ }
372+ }
373+
374+ #endregion
375+
376+ }
377+}
378
379=== modified file 'src/Canonical.UbuntuOne.Client.Views/Canonical.UbuntuOne.Client.Views.csproj'
380--- src/Canonical.UbuntuOne.Client.Views/Canonical.UbuntuOne.Client.Views.csproj 2010-11-02 23:28:01 +0000
381+++ src/Canonical.UbuntuOne.Client.Views/Canonical.UbuntuOne.Client.Views.csproj 2010-11-14 21:31:15 +0000
382@@ -86,6 +86,9 @@
383 <Compile Include="BetaView.xaml.cs">
384 <DependentUpon>BetaView.xaml</DependentUpon>
385 </Compile>
386+ <Compile Include="DeviceControl.xaml.cs">
387+ <DependentUpon>DeviceControl.xaml</DependentUpon>
388+ </Compile>
389 <Compile Include="WindowsSettingsView.xaml.cs">
390 <DependentUpon>WindowsSettingsView.xaml</DependentUpon>
391 </Compile>
392@@ -97,6 +100,10 @@
393 <SubType>Designer</SubType>
394 <Generator>MSBuild:Compile</Generator>
395 </Page>
396+ <Page Include="DeviceControl.xaml">
397+ <SubType>Designer</SubType>
398+ <Generator>MSBuild:Compile</Generator>
399+ </Page>
400 <Page Include="DevicesView.xaml">
401 <SubType>Designer</SubType>
402 <Generator>MSBuild:Compile</Generator>
403
404=== added file 'src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml'
405--- src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml 1970-01-01 00:00:00 +0000
406+++ src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml 2010-11-14 21:31:15 +0000
407@@ -0,0 +1,23 @@
408+<UserControl x:Class="Canonical.UbuntuOne.Client.Views.DeviceControl"
409+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
410+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
411+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
412+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
413+ mc:Ignorable="d"
414+ d:DesignHeight="64" d:DesignWidth="300" BorderThickness="2 1 2 1">
415+ <Grid>
416+ <Grid.ColumnDefinitions>
417+ <ColumnDefinition Width="64"/>
418+ <ColumnDefinition Width="*"/>
419+ </Grid.ColumnDefinitions>
420+ <Image Name="DeviceTypeImage" Grid.Column="0" />
421+ <Grid Grid.Column="1">
422+ <Grid.RowDefinitions>
423+ <RowDefinition Height="Auto"/>
424+ <RowDefinition Height="Auto"/>
425+ </Grid.RowDefinitions>
426+ <Label Name="DescriptionLabel" Grid.Row="0" Margin="3" HorizontalAlignment="Center">Description</Label>
427+ <Button Name="RemoveButton" Grid.Row="1" Margin="3" Width="Auto" HorizontalAlignment="Center" Click="OnRemoveButtonClick">Remove</Button>
428+ </Grid>
429+ </Grid>
430+</UserControl>
431
432=== added file 'src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml.cs'
433--- src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml.cs 1970-01-01 00:00:00 +0000
434+++ src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml.cs 2010-11-14 21:31:15 +0000
435@@ -0,0 +1,51 @@
436+using System.Windows.Input;
437+using Canonical.UbuntuOne.Client.Preferences;
438+
439+namespace Canonical.UbuntuOne.Client.Views
440+{
441+ /// <summary>
442+ /// Interaction logic for DeviceControl.xaml
443+ /// </summary>
444+ public partial class DeviceControl
445+ {
446+ #region Variables
447+
448+ private IDevice _device;
449+
450+ #endregion
451+
452+ #region Properties
453+
454+ public IDevice Device
455+ {
456+ get { return _device; }
457+ set
458+ {
459+ _device = value;
460+ DescriptionLabel.Content = _device.Description;
461+ }
462+ }
463+
464+ /// <summary>
465+ /// Gets and sets the presenter used to manage the user preferences.
466+ /// </summary>
467+ public IPreferencesDialogPresenter PreferencesDialogPresenter { get; set; }
468+
469+ #endregion
470+
471+ public DeviceControl()
472+ {
473+ InitializeComponent();
474+ }
475+
476+ private void OnRemoveButtonClick(object sender, System.Windows.RoutedEventArgs e)
477+ {
478+ if (PreferencesDialogPresenter == null) return;
479+ Mouse.OverrideCursor = Cursors.Wait;
480+ var removed = PreferencesDialogPresenter.RemoveDevice(Device.Type, Device.Token);
481+ Mouse.OverrideCursor = null;
482+ if(removed)
483+ Visibility = System.Windows.Visibility.Collapsed;
484+ }
485+ }
486+}
487
488=== modified file 'src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml'
489--- src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml 2010-10-13 09:56:20 +0000
490+++ src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml 2010-11-14 21:31:15 +0000
491@@ -24,15 +24,15 @@
492 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
493 xmlns:resx="clr-namespace:Canonical.UbuntuOne.Client.Views.Resources"
494 mc:Ignorable="d"
495- d:DesignHeight="300" d:DesignWidth="300">
496+ d:DesignHeight="298" d:DesignWidth="300">
497 <Grid>
498 <Grid.RowDefinitions>
499- <RowDefinition Height="75" />
500+ <RowDefinition Height="Auto" />
501 <RowDefinition Height="*" />
502 </Grid.RowDefinitions>
503 <TextBlock Name="MessageText" Grid.Row="0" Margin="3" TextWrapping="Wrap" Text="{x:Static resx:Resources.DevicesViewMessageTextBlock}"/>
504- <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
505- <StackPanel Name="MachinesContent">
506+ <ScrollViewer Grid.Row="1" Height="Auto" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="6" BorderThickness="3" BorderBrush="Black">
507+ <StackPanel Name="MachinesContent" Margin="3">
508
509 </StackPanel>
510 </ScrollViewer>
511
512=== modified file 'src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml.cs'
513--- src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml.cs 2010-10-20 23:09:36 +0000
514+++ src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml.cs 2010-11-14 21:31:15 +0000
515@@ -17,7 +17,9 @@
516 *
517 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
518 */
519+using System.Collections.Generic;
520 using System.Windows.Controls;
521+using Canonical.UbuntuOne.Client.Preferences;
522
523 namespace Canonical.UbuntuOne.Client.Views
524 {
525@@ -28,6 +30,34 @@
526 {
527 #region Properties
528
529+ private IList<IDevice> _devices;
530+
531+ #endregion
532+
533+ #region Properties
534+
535+ /// <summary>
536+ /// Gets and sets the presenter used to manage the user preferences.
537+ /// </summary>
538+ public IPreferencesDialogPresenter PreferencesDialogPresenter { get; set; }
539+
540+ ///<summary>
541+ /// Gets and sets the devices shown in the dialog.
542+ ///</summary>
543+ public IList<IDevice> Devices
544+ {
545+ get { return _devices; }
546+ set
547+ {
548+ _devices = value;
549+ MachinesContent.Children.RemoveRange(0, MachinesContent.Children.Count);
550+ foreach (var currentDevice in value)
551+ {
552+ var newControl = new DeviceControl {Device = currentDevice, PreferencesDialogPresenter = PreferencesDialogPresenter};
553+ MachinesContent.Children.Add(newControl);
554+ }
555+ }
556+ }
557
558 #endregion
559
560@@ -38,5 +68,6 @@
561 {
562 InitializeComponent();
563 }
564+
565 }
566 }
567
568=== modified file 'src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml'
569--- src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml 2010-11-02 23:28:01 +0000
570+++ src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml 2010-11-14 21:31:15 +0000
571@@ -22,7 +22,7 @@
572 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
573 xmlns:Views="clr-namespace:Canonical.UbuntuOne.Client.Views"
574 xmlns:resx="clr-namespace:Canonical.UbuntuOne.Client.Views.Resources"
575- Title="{x:Static resx:Resources.PreferencesDialogTitle}" Height="450" Width="400">
576+ Title="{x:Static resx:Resources.PreferencesDialogTitle}" Height="450" Width="400" ResizeMode="NoResize">
577 <Grid Margin="3">
578 <Grid.RowDefinitions>
579 <RowDefinition Height="50" />
580@@ -39,25 +39,26 @@
581 <ColumnDefinition Width="*" />
582 <ColumnDefinition Width="*" />
583 </Grid.ColumnDefinitions>
584- <ProgressBar Name="Progressbar" Grid.Column="0" HorizontalAlignment="Stretch" Margin="3" />
585+ <ProgressBar Name="ConsumptionProgressbar" Grid.Column="0" HorizontalAlignment="Stretch" Margin="3" Minimum="0" Maximum="100"/>
586 <Label Name="ConsumptionLabel" Grid.Column="1">Unknown</Label>
587 </Grid>
588 <Label Name="StatusLabel" Grid.Row="1">Disconnected</Label>
589 </Grid>
590- <TabControl Margin="3" Grid.Row="1">
591+ <TabControl Margin="3" Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
592+ <TabItem Header="{x:Static resx:Resources.PreferencesDialogDevicesTabHeader}" >
593+ <Views:DevicesView x:Name="DevicesTab" Height="300" HorizontalAlignment="Stretch"/>
594+ </TabItem>
595+ <TabItem Header="{x:Static resx:Resources.PreferencesDialogWindowsTabHeader}">
596+ <Views:WindowsSettingsView x:Name="WindowsTab" Height="300" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
597+ </TabItem>
598 <TabItem Header="Beta" >
599- <Views:BetaView x:Name="BetaTab" Height="300" IsEnabled="False"/>
600- </TabItem>
601- <TabItem Header="{x:Static resx:Resources.PreferencesDialogWindowsTabHeader}">
602- <Views:WindowsSettingsView x:Name="WindowsTab" Height="300" />
603+ <Views:BetaView x:Name="BetaTab" Height="300" IsEnabled="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
604 </TabItem>
605 <!--
606 <TabItem Header="{x:Static resx:Resources.PreferencesDialogAccountTabHeader}" >
607 <Views:AccountView x:Name="AccountsTab" Height="300" IsEnabled="False"/>
608 </TabItem>
609- <TabItem Header="{x:Static resx:Resources.PreferencesDialogDevicesTabHeader}" >
610- <Views:DevicesView x:Name="DevicesTab" Height="300" IsEnabled="False"/>
611- </TabItem>
612+
613 <TabItem Header="{x:Static resx:Resources.PreferencesDialogServicesTabHeader}" >
614 <Views:ServicesView x:Name="ServicesTab" Height="300" IsEnabled="False"/>
615 </TabItem>
616
617=== modified file 'src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml.cs'
618--- src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml.cs 2010-11-02 23:28:01 +0000
619+++ src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml.cs 2010-11-14 21:31:15 +0000
620@@ -16,6 +16,8 @@
621 *
622 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
623 */
624+using System;
625+using System.Collections.Generic;
626 using System.Windows;
627 using Canonical.UbuntuOne.Client.Preferences;
628
629@@ -26,12 +28,26 @@
630 /// </summary>
631 public partial class PreferencesDialog : Window, IPreferencesView
632 {
633+ #region Variables
634+
635+ private IPreferencesDialogPresenter _presenter;
636+
637+ #endregion
638+
639 #region DI properties
640
641 /// <summary>
642 /// Gets and sets the presenter that will be used by the view.
643 /// </summary>
644- public IPreferencesDialogPresenter PreferencesDialogPresenter { get; set; }
645+ public IPreferencesDialogPresenter PreferencesDialogPresenter
646+ {
647+ get { return _presenter; }
648+ set
649+ {
650+ _presenter = value;
651+ DevicesTab.PreferencesDialogPresenter = value;
652+ }
653+ }
654
655 #endregion
656
657@@ -88,6 +104,31 @@
658 // set { ServicesTab.IsMusicSynced = value; }
659 //}
660
661+ /// <summary>
662+ /// Sets the consumption of the plan so far. The value should be between 0 and 100.
663+ /// </summary>
664+ public double Consumption
665+ {
666+ set { ConsumptionProgressbar.Value = value; }
667+ }
668+
669+ /// <summary>
670+ /// Sets the text used next the consumption.
671+ /// </summary>
672+ public string ConsumptionText
673+ {
674+ set { ConsumptionLabel.Content = value; }
675+ }
676+
677+ /// <summary>
678+ /// Gets and sets the devices shown in the app.
679+ /// </summary>
680+ public IList<IDevice> Devices
681+ {
682+ get { return DevicesTab.Devices; }
683+ set { DevicesTab.Devices = value; }
684+ }
685+
686 public string UserName
687 {
688 set { }
689
690=== modified file 'src/Canonical.UbuntuOne.Client/Canonical.UbuntuOne.Client.csproj'
691--- src/Canonical.UbuntuOne.Client/Canonical.UbuntuOne.Client.csproj 2010-11-11 11:44:38 +0000
692+++ src/Canonical.UbuntuOne.Client/Canonical.UbuntuOne.Client.csproj 2010-11-14 21:31:15 +0000
693@@ -74,6 +74,13 @@
694 <Compile Include="..\Version.cs">
695 <Link>Properties\Version.cs</Link>
696 </Compile>
697+ <Compile Include="Device.cs" />
698+ <Compile Include="DeviceFactory.cs" />
699+ <Compile Include="DeviceManager.cs" />
700+ <Compile Include="DeviceManagerException.cs" />
701+ <Compile Include="IDevice.cs" />
702+ <Compile Include="IDeviceFactory.cs" />
703+ <Compile Include="IDeviceManager.cs" />
704 <Compile Include="Notification\Enums.cs" />
705 <Compile Include="Notification\INotificationIconView.cs" />
706 <Compile Include="Notification\IStateMapper.cs" />
707@@ -176,5 +183,8 @@
708 <Install>true</Install>
709 </BootstrapperPackage>
710 </ItemGroup>
711+ <ItemGroup>
712+ <Folder Include="Devices\" />
713+ </ItemGroup>
714 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
715 </Project>
716\ No newline at end of file
717
718=== added file 'src/Canonical.UbuntuOne.Client/Device.cs'
719--- src/Canonical.UbuntuOne.Client/Device.cs 1970-01-01 00:00:00 +0000
720+++ src/Canonical.UbuntuOne.Client/Device.cs 2010-11-14 21:31:15 +0000
721@@ -0,0 +1,38 @@
722+/* Copyright 2010 Canonical Ltd.
723+ *
724+ * This file is part of UbuntuOne on Windows.
725+ *
726+ * UbuntuOne on Windows is free software: you can redistribute it and/or modify
727+ * it under the terms of the GNU Lesser General Public License version
728+ * as published by the Free Software Foundation.
729+ *
730+ * Ubuntu One on Windows is distributed in the hope that it will be useful,
731+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
732+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
733+ * GNU Lesser General Public License for more details.
734+ *
735+ * You should have received a copy of the GNU Lesser General Public License
736+ * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
737+ *
738+ * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
739+ */
740+namespace Canonical.UbuntuOne.Client
741+{
742+ internal class Device : IDevice
743+ {
744+ /// <summary>
745+ /// Gets and sets a descriptin of the device.
746+ /// </summary>
747+ public string Description { get; set; }
748+
749+ /// <summary>
750+ /// The token that identifies the device.
751+ /// </summary>
752+ public string Token { get; set; }
753+
754+ /// <summary>
755+ /// Gets and sets the type of device.
756+ /// </summary>
757+ public DeviceType Type { get; set; }
758+ }
759+}
760
761=== added file 'src/Canonical.UbuntuOne.Client/DeviceFactory.cs'
762--- src/Canonical.UbuntuOne.Client/DeviceFactory.cs 1970-01-01 00:00:00 +0000
763+++ src/Canonical.UbuntuOne.Client/DeviceFactory.cs 2010-11-14 21:31:15 +0000
764@@ -0,0 +1,57 @@
765+/* Copyright 2010 Canonical Ltd.
766+ *
767+ * This file is part of UbuntuOne on Windows.
768+ *
769+ * UbuntuOne on Windows is free software: you can redistribute it and/or modify
770+ * it under the terms of the GNU Lesser General Public License version
771+ * as published by the Free Software Foundation.
772+ *
773+ * Ubuntu One on Windows is distributed in the hope that it will be useful,
774+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
775+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
776+ * GNU Lesser General Public License for more details.
777+ *
778+ * You should have received a copy of the GNU Lesser General Public License
779+ * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
780+ *
781+ * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
782+ */
783+namespace Canonical.UbuntuOne.Client
784+{
785+ internal class DeviceFactory : IDeviceFactory
786+ {
787+ #region Variables
788+
789+ internal const string ComputerType = "computer";
790+ internal const string PhoneType = "phone";
791+ internal const string CurrentMachine = "Current machine";
792+
793+ #endregion
794+
795+ #region Di Properties
796+
797+ /// <summary>
798+ /// Gets and sets the device manager used to access device info.
799+ /// </summary>
800+ public IDeviceManager DeviceManager { get; set; }
801+
802+ #endregion
803+
804+ /// <summary>
805+ /// Creates a new device from the given data.
806+ /// </summary>
807+ /// <param name="description">A string with the description of the machine.</param>
808+ /// <param name="token">The token that identifies the device.</param>
809+ /// <param name="type">The type of device.</param>
810+ /// <returns>A device with the given data.</returns>
811+ public IDevice Create(string description, string token, string type)
812+ {
813+ return new Device
814+ {
815+ Description = (DeviceManager.IsCurrentMachine(token))?CurrentMachine:description,
816+ Token = token,
817+ Type = string.Compare(type, ComputerType, true) == 0 ? DeviceType.COMPUTER : DeviceType.PHONE
818+ };
819+ }
820+ }
821+}
822
823=== added file 'src/Canonical.UbuntuOne.Client/DeviceManager.cs'
824--- src/Canonical.UbuntuOne.Client/DeviceManager.cs 1970-01-01 00:00:00 +0000
825+++ src/Canonical.UbuntuOne.Client/DeviceManager.cs 2010-11-14 21:31:15 +0000
826@@ -0,0 +1,157 @@
827+/* Copyright 2010 Canonical Ltd.
828+ *
829+ * This file is part of UbuntuOne on Windows.
830+ *
831+ * UbuntuOne on Windows is free software: you can redistribute it and/or modify
832+ * it under the terms of the GNU Lesser General Public License version
833+ * as published by the Free Software Foundation.
834+ *
835+ * Ubuntu One on Windows is distributed in the hope that it will be useful,
836+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
837+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
838+ * GNU Lesser General Public License for more details.
839+ *
840+ * You should have received a copy of the GNU Lesser General Public License
841+ * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
842+ *
843+ * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
844+ */
845+using System;
846+using System.Collections.Generic;
847+using System.IO;
848+using System.Linq;
849+using Canonical.Ubuntu.SSO;
850+using Canonical.UbuntuOne.Common.Net;
851+using log4net;
852+using Newtonsoft.Json.Linq;
853+
854+namespace Canonical.UbuntuOne.Client
855+{
856+ internal class DeviceManager : IDeviceManager
857+ {
858+
859+ #region Variables
860+
861+ private const string DevicesUrl = "https://one.ubuntu.com/api/1.0/devices/";
862+ private const string RemoveUrl = "https://one.ubuntu.com/api/1.0/devices/remove/{0}/{1}";
863+ private ILog _logger;
864+ private readonly object _loggerLock = new object();
865+
866+ #endregion
867+
868+ #region Di properties
869+
870+ /// <summary>
871+ /// Gets and sets the object used to perform the secure requests.
872+ /// </summary>
873+ public IOAuth OAuth { get; set; }
874+
875+ /// <summary>
876+ /// Gets and sets the credentials provider used to get the user credentials.
877+ /// </summary>
878+ public ISSOCredentialsProvider SSOCredentialsProvider { get; set; }
879+
880+ /// <summary>
881+ /// Gets and sets the factory that creates devices.
882+ /// </summary>
883+ public IDeviceFactory DeviceFactory { get; set; }
884+
885+ /// <summary>
886+ /// Gets and sets the logger used by the class.
887+ /// </summary>
888+ internal ILog Logger
889+ {
890+ get
891+ {
892+ if (_logger == null)
893+ {
894+ lock (_loggerLock)
895+ {
896+ _logger = LogManager.GetLogger(typeof(DeviceManager));
897+ }
898+ }
899+ return _logger;
900+ }
901+ set { _logger = value; }
902+ }
903+
904+ #endregion
905+
906+ /// <summary>
907+ /// Returns if the machine with the given token is th current machine.
908+ /// </summary>
909+ /// <param name="token">The token of the machine.</param>
910+ /// <returns>A bool stating if th token represents the current machine.</returns>
911+ public bool IsCurrentMachine(string token)
912+ {
913+ string currentToken;
914+ string currentTokenSecret;
915+ string currentConsumerKey;
916+ string currentConsumerSecret;
917+
918+ // get the credentials
919+ SSOCredentialsProvider.LoginToGetCredentials("UbuntuOne", out currentToken, out currentTokenSecret, out currentConsumerKey,
920+ out currentConsumerSecret);
921+ return string.Compare(currentToken, token) == 0;
922+ }
923+
924+ /// <summary>
925+ /// Removes a machine with the given token from the machines synced with ubuntu one.
926+ /// </summary>
927+ /// <param name="kind"></param>
928+ /// <param name="tokenToRemove"></param>
929+ public void RemoveDevice(string kind, string tokenToRemove)
930+ {
931+ string token;
932+ string tokenSecret;
933+ string consumerKey;
934+ string consumerSecret;
935+
936+ // get the credentials
937+ SSOCredentialsProvider.LoginToGetCredentials("UbuntuOne", out token, out tokenSecret, out consumerKey,
938+ out consumerSecret);
939+ var uri = string.Format(RemoveUrl, kind, tokenToRemove);
940+ var request = OAuth.MakeRequest(uri, "GET", consumerKey, consumerSecret, token, tokenSecret);
941+ try
942+ {
943+ var response = request.GetResponse();
944+ }
945+ catch (Exception e)
946+ {
947+ throw new DeviceManagerException("Machine could not be removed.", e);
948+ }
949+ }
950+
951+ /// <summary>
952+ /// Returns a list with the current machines synced in the account.
953+ /// </summary>
954+ public IList<IDevice> GetSyncedDevices()
955+ {
956+ string token;
957+ string tokenSecret;
958+ string consumerKey;
959+ string consumerSecret;
960+
961+ // get the credentials
962+ SSOCredentialsProvider.LoginToGetCredentials("UbuntuOne", out token, out tokenSecret, out consumerKey,
963+ out consumerSecret);
964+ var request = OAuth.MakeRequest(DevicesUrl, "GET", consumerKey, consumerSecret, token, tokenSecret);
965+ try
966+ {
967+ var response = request.GetResponse();
968+ var data = new StreamReader(response.GetResponseStream()).ReadToEnd();
969+ // parse the json string
970+ var devicesArray = JArray.Parse(data);
971+ return devicesArray.Select(currentJDevice =>
972+ DeviceFactory.Create(
973+ (string) currentJDevice["description"],
974+ (string) currentJDevice["token"],
975+ (string) currentJDevice["kind"])).ToList();
976+ }
977+ catch (Exception e)
978+ {
979+ throw new DeviceManagerException("Machine could not be removed.", e);
980+ }
981+ }
982+ }
983+}
984
985=== added file 'src/Canonical.UbuntuOne.Client/DeviceManagerException.cs'
986--- src/Canonical.UbuntuOne.Client/DeviceManagerException.cs 1970-01-01 00:00:00 +0000
987+++ src/Canonical.UbuntuOne.Client/DeviceManagerException.cs 2010-11-14 21:31:15 +0000
988@@ -0,0 +1,57 @@
989+/* Copyright 2010 Canonical Ltd.
990+ *
991+ * This file is part of UbuntuOne on Windows.
992+ *
993+ * UbuntuOne on Windows is free software: you can redistribute it and/or modify
994+ * it under the terms of the GNU Lesser General Public License version
995+ * as published by the Free Software Foundation.
996+ *
997+ * Ubuntu One on Windows is distributed in the hope that it will be useful,
998+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
999+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1000+ * GNU Lesser General Public License for more details.
1001+ *
1002+ * You should have received a copy of the GNU Lesser General Public License
1003+ * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
1004+ *
1005+ * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
1006+ */
1007+using System;
1008+
1009+namespace Canonical.UbuntuOne.Client
1010+{
1011+ ///<summary>
1012+ /// Exception thrown when there was an issue managing the devices of the account.
1013+ ///</summary>
1014+ public class DeviceManagerException : Exception
1015+ {
1016+ ///<summary>
1017+ /// Creates a new instance of the class.
1018+ ///</summary>
1019+ public DeviceManagerException()
1020+ {
1021+
1022+ }
1023+
1024+ /// <summary>
1025+ /// Creates a new instance of the exception.
1026+ /// </summary>
1027+ /// <param name="message">The message to be carried by the exception.</param>
1028+ public DeviceManagerException(string message)
1029+ : base(message)
1030+ {
1031+
1032+ }
1033+
1034+ /// <summary>
1035+ /// Creates a new instance of the exception.
1036+ /// </summary>
1037+ /// <param name="message">The message to be carried by the exception.</param>
1038+ /// <param name="inner">The inner exception to be carried by the exception.</param>
1039+ public DeviceManagerException(string message, Exception inner)
1040+ : base(message, inner)
1041+ {
1042+
1043+ }
1044+ }
1045+}
1046
1047=== added file 'src/Canonical.UbuntuOne.Client/IDevice.cs'
1048--- src/Canonical.UbuntuOne.Client/IDevice.cs 1970-01-01 00:00:00 +0000
1049+++ src/Canonical.UbuntuOne.Client/IDevice.cs 2010-11-14 21:31:15 +0000
1050@@ -0,0 +1,57 @@
1051+/* Copyright 2010 Canonical Ltd.
1052+ *
1053+ * This file is part of UbuntuOne on Windows.
1054+ *
1055+ * UbuntuOne on Windows is free software: you can redistribute it and/or modify
1056+ * it under the terms of the GNU Lesser General Public License version
1057+ * as published by the Free Software Foundation.
1058+ *
1059+ * Ubuntu One on Windows is distributed in the hope that it will be useful,
1060+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1061+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1062+ * GNU Lesser General Public License for more details.
1063+ *
1064+ * You should have received a copy of the GNU Lesser General Public License
1065+ * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
1066+ *
1067+ * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
1068+ */
1069+namespace Canonical.UbuntuOne.Client
1070+{
1071+ /// <summary>
1072+ /// Enumerator that describes the different types of devices.
1073+ /// </summary>
1074+ public enum DeviceType
1075+ {
1076+ ///<summary>
1077+ /// The device is a computer.
1078+ ///</summary>
1079+ COMPUTER,
1080+ ///<summary>
1081+ /// The device is a phone.
1082+ ///</summary>
1083+ PHONE
1084+ }
1085+
1086+ /// <summary>
1087+ /// Interface that represents a device in the system.
1088+ /// </summary>
1089+ public interface IDevice
1090+ {
1091+ /// <summary>
1092+ /// Gets and sets a descriptin of the device.
1093+ /// </summary>
1094+ string Description { get; set; }
1095+
1096+ /// <summary>
1097+ /// The token that identifies the device.
1098+ /// </summary>
1099+ string Token { get; set; }
1100+
1101+ /// <summary>
1102+ /// Gets and sets the type of device.
1103+ /// </summary>
1104+ DeviceType Type { get; set; }
1105+
1106+ }
1107+}
1108
1109=== added file 'src/Canonical.UbuntuOne.Client/IDeviceFactory.cs'
1110--- src/Canonical.UbuntuOne.Client/IDeviceFactory.cs 1970-01-01 00:00:00 +0000
1111+++ src/Canonical.UbuntuOne.Client/IDeviceFactory.cs 2010-11-14 21:31:15 +0000
1112@@ -0,0 +1,35 @@
1113+/* Copyright 2010 Canonical Ltd.
1114+ *
1115+ * This file is part of UbuntuOne on Windows.
1116+ *
1117+ * UbuntuOne on Windows is free software: you can redistribute it and/or modify
1118+ * it under the terms of the GNU Lesser General Public License version
1119+ * as published by the Free Software Foundation.
1120+ *
1121+ * Ubuntu One on Windows is distributed in the hope that it will be useful,
1122+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1123+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1124+ * GNU Lesser General Public License for more details.
1125+ *
1126+ * You should have received a copy of the GNU Lesser General Public License
1127+ * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
1128+ *
1129+ * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
1130+ */
1131+namespace Canonical.UbuntuOne.Client
1132+{
1133+ /// <summary>
1134+ /// A factory that can create devices.
1135+ /// </summary>
1136+ public interface IDeviceFactory
1137+ {
1138+ /// <summary>
1139+ /// Creates a new device from the given data.
1140+ /// </summary>
1141+ /// <param name="description">A string with the description of the machine.</param>
1142+ /// <param name="token">The token that identifies the device.</param>
1143+ /// <param name="type">The type of device.</param>
1144+ /// <returns>A device with the given data.</returns>
1145+ IDevice Create(string description, string token, string type);
1146+ }
1147+}
1148
1149=== added file 'src/Canonical.UbuntuOne.Client/IDeviceManager.cs'
1150--- src/Canonical.UbuntuOne.Client/IDeviceManager.cs 1970-01-01 00:00:00 +0000
1151+++ src/Canonical.UbuntuOne.Client/IDeviceManager.cs 2010-11-14 21:31:15 +0000
1152@@ -0,0 +1,48 @@
1153+/* Copyright 2010 Canonical Ltd.
1154+ *
1155+ * This file is part of UbuntuOne on Windows.
1156+ *
1157+ * UbuntuOne on Windows is free software: you can redistribute it and/or modify
1158+ * it under the terms of the GNU Lesser General Public License version
1159+ * as published by the Free Software Foundation.
1160+ *
1161+ * Ubuntu One on Windows is distributed in the hope that it will be useful,
1162+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1163+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1164+ * GNU Lesser General Public License for more details.
1165+ *
1166+ * You should have received a copy of the GNU Lesser General Public License
1167+ * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
1168+ *
1169+ * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
1170+ */
1171+using System.Collections.Generic;
1172+
1173+namespace Canonical.UbuntuOne.Client
1174+{
1175+ /// <summary>
1176+ /// Interface to be implemented by those objects that can manage the different devices
1177+ /// found in the Ubuntu One account.
1178+ /// </summary>
1179+ public interface IDeviceManager
1180+ {
1181+ /// <summary>
1182+ /// Returns if the machine with the given token is th current machine.
1183+ /// </summary>
1184+ /// <param name="token">The token of the machine.</param>
1185+ /// <returns>A bool stating if th token represents the current machine.</returns>
1186+ bool IsCurrentMachine(string token);
1187+
1188+ /// <summary>
1189+ /// Removes a machine with the given token from the machines synced with ubuntu one.
1190+ /// </summary>
1191+ /// <param name="king"></param>
1192+ /// <param name="token"></param>
1193+ void RemoveDevice(string king, string token);
1194+
1195+ /// <summary>
1196+ /// Returns a list with the current machines synced in the account.
1197+ /// </summary>
1198+ IList<IDevice> GetSyncedDevices();
1199+ }
1200+}
1201
1202=== modified file 'src/Canonical.UbuntuOne.Client/Notification/NotificationIconPresenter.cs'
1203=== modified file 'src/Canonical.UbuntuOne.Client/Preferences/IPreferencesDialogPresenter.cs'
1204--- src/Canonical.UbuntuOne.Client/Preferences/IPreferencesDialogPresenter.cs 2010-10-19 12:34:50 +0000
1205+++ src/Canonical.UbuntuOne.Client/Preferences/IPreferencesDialogPresenter.cs 2010-11-14 21:31:15 +0000
1206@@ -31,5 +31,12 @@
1207 /// Updates the preferences that the user will use in the application.
1208 /// </summary>
1209 void UpdatePreferences();
1210+
1211+ /// <summary>
1212+ /// Removes the device with the given token from the system.
1213+ /// </summary>
1214+ /// <param name="deviceType">The type of the device to remove.</param>
1215+ /// <param name="token">The token of the device to remove.</param>
1216+ bool RemoveDevice(DeviceType deviceType, string token);
1217 }
1218 }
1219
1220=== modified file 'src/Canonical.UbuntuOne.Client/Preferences/IPreferencesView.cs'
1221--- src/Canonical.UbuntuOne.Client/Preferences/IPreferencesView.cs 2010-10-13 10:38:57 +0000
1222+++ src/Canonical.UbuntuOne.Client/Preferences/IPreferencesView.cs 2010-11-14 21:31:15 +0000
1223@@ -17,6 +17,8 @@
1224 *
1225 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
1226 */
1227+using System.Collections.Generic;
1228+
1229 namespace Canonical.UbuntuOne.Client.Preferences
1230 {
1231 /// <summary>
1232@@ -26,6 +28,21 @@
1233 public interface IPreferencesView
1234 {
1235 /// <summary>
1236+ /// Sets the consumption of the plan so far. The value should be between 0 and 100.
1237+ /// </summary>
1238+ double Consumption { set; }
1239+
1240+ /// <summary>
1241+ /// Sets the text used next the consumption.
1242+ /// </summary>
1243+ string ConsumptionText { set; }
1244+
1245+ /// <summary>
1246+ /// Gets and sets the devices shown in the app.
1247+ /// </summary>
1248+ IList<IDevice> Devices { get; set; }
1249+
1250+ /// <summary>
1251 /// Allows to set the name that will be displayed in the UI.
1252 /// </summary>
1253 string UserName { set; }
1254@@ -79,5 +96,10 @@
1255 /// Tell the view to show itself as a dialog.
1256 /// </summary>
1257 void ShowDialog();
1258+
1259+ /// <summary>
1260+ /// Hides the dialog.
1261+ /// </summary>
1262+ void Hide();
1263 }
1264 }
1265
1266=== modified file 'src/Canonical.UbuntuOne.Client/Preferences/PreferencesDialogPresenter.cs'
1267--- src/Canonical.UbuntuOne.Client/Preferences/PreferencesDialogPresenter.cs 2010-11-11 11:43:38 +0000
1268+++ src/Canonical.UbuntuOne.Client/Preferences/PreferencesDialogPresenter.cs 2010-11-14 21:31:15 +0000
1269@@ -18,9 +18,12 @@
1270 */
1271 using System;
1272 using System.IO;
1273+using System.Windows;
1274 using Canonical.Ubuntu.SSO;
1275 using Canonical.UbuntuOne.Common;
1276+using Canonical.UbuntuOne.Common.Net;
1277 using log4net;
1278+using Newtonsoft.Json.Linq;
1279
1280 namespace Canonical.UbuntuOne.Client.Preferences
1281 {
1282@@ -36,6 +39,7 @@
1283 private readonly object _loggerLock = new object();
1284 private const string EventName = "UbuntuOneAutoManualSync";
1285 private const string ApplicationName = "UbuntuOne";
1286+ private const string ConsumptionUrl = "https://one.ubuntu.com/api/quota/";
1287
1288 #endregion
1289
1290@@ -64,6 +68,11 @@
1291 #region DI Properties
1292
1293 /// <summary>
1294+ /// Gets and sets the object that allows to mange the devices of the Ubuntu One.
1295+ /// </summary>
1296+ public IDeviceManager DeviceManager { get; set; }
1297+
1298+ /// <summary>
1299 /// Gets and sets the view used by this presenter.
1300 /// </summary>
1301 public IPreferencesView PreferencesView { get; set; }
1302@@ -100,6 +109,11 @@
1303 /// </summary>
1304 public IMessageBox MessageBox { get; set; }
1305
1306+ /// <summary>
1307+ /// Gets and sets the oauth used to access secure resources.
1308+ /// </summary>
1309+ public IOAuth OAuth { get; set; }
1310+
1311 #endregion
1312
1313 #region Helpers
1314@@ -142,14 +156,49 @@
1315 MessageBox.ShowError("An error courred when trying to retrieve your credentials.");
1316 }
1317
1318+ /// <summary>
1319+ /// Returns the comsumption so far.
1320+ /// </summary>
1321+ /// <returns></returns>
1322+ private double GetConsumption()
1323+ {
1324+ string token;
1325+ string tokenSecret;
1326+ string consumerKey;
1327+ string consumerSecret;
1328+
1329+ // get the credentials
1330+ SSOCredentialsProvider.LoginToGetCredentials("UbuntuOne", out token, out tokenSecret, out consumerKey,
1331+ out consumerSecret);
1332+ var request = OAuth.MakeRequest(ConsumptionUrl, "GET", consumerKey, consumerSecret, token, tokenSecret);
1333+ try
1334+ {
1335+ var response = request.GetResponse();
1336+ var data = new StreamReader(response.GetResponseStream()).ReadToEnd();
1337+ // parse the json string
1338+ var consumption = JObject.Parse(data);
1339+ return ((Int64)consumption["used"] * 100) / (Int64)consumption["total"];
1340+ }
1341+ catch (Exception e)
1342+ {
1343+ throw new DeviceManagerException("Machine could not be listed.", e);
1344+ }
1345+ }
1346+
1347 #endregion
1348
1349 public void Show()
1350 {
1351 // set the preferences to be shown in the UI.
1352 PreferencesView.IsAutoSyncEnable = PreferencesManager.IsAutoSyncEnable;
1353+ // set consumption
1354+ var consumption = GetConsumption();
1355+ PreferencesView.Consumption = consumption;
1356+ PreferencesView.ConsumptionText = string.Format("{0}% used", consumption);
1357+ PreferencesView.Devices = DeviceManager.GetSyncedDevices();
1358+
1359 if (PreferencesManager.IsAutoSyncEnable)
1360- PreferencesView.AutoSyncFrequency = PreferencesManager.AutoSyncFrequency;
1361+ PreferencesView.AutoSyncFrequency = PreferencesManager.AutoSyncFrequency;
1362 PreferencesView.ShowDialog();
1363 }
1364
1365@@ -170,5 +219,33 @@
1366 PreferencesManager.Save();
1367 }
1368
1369+ /// <summary>
1370+ /// Removes the device with the given token from the system.
1371+ /// </summary>
1372+ /// <param name="deviceType">The type of the device to remove.</param>
1373+ /// <param name="token">The token of the device to remove.</param>
1374+ public bool RemoveDevice(DeviceType deviceType, string token)
1375+ {
1376+ var currentMachine = DeviceManager.IsCurrentMachine(token);
1377+ if(currentMachine)
1378+ {
1379+ // we need to remove the current machine, we should tell the user
1380+ if(MessageBox.ShowYesNo("Are you sure you want to remove this machine?",MessageBoxImage.Question) == MessageBoxResult.No)
1381+ {
1382+ return false;
1383+ }
1384+ }
1385+ // just use the device manager for thise
1386+ DeviceManager.RemoveDevice(deviceType == DeviceType.COMPUTER ? "computer" : "phone", token);
1387+ // we remove the tokens in our machine
1388+ if (currentMachine)
1389+ {
1390+ SSOCredentialsProvider.RemoveCredentials("UbuntuOne");
1391+ // we tell the user we will close the preferences since the
1392+ MessageBox.ShowInformation("Preferences dialog will be closed because your removed the machine.");
1393+ PreferencesView.Hide();
1394+ }
1395+ return true;
1396+ }
1397 }
1398 }
1399
1400=== modified file 'src/Canonical.UbuntuOne.Client/objects.xml'
1401--- src/Canonical.UbuntuOne.Client/objects.xml 2010-10-19 12:34:50 +0000
1402+++ src/Canonical.UbuntuOne.Client/objects.xml 2010-11-14 21:31:15 +0000
1403@@ -14,4 +14,11 @@
1404 type="Canonical.UbuntuOne.Client.Preferences.LoadPreferencesStartupTask, Canonical.UbuntuOne.Client"
1405 autowire="autodetect"/>
1406
1407+ <object id="DeviceManager"
1408+ type="Canonical.UbuntuOne.Client.DeviceManager, Canonical.UbuntuOne.Client"
1409+ autowire="autodetect"/>
1410+
1411+ <object id="DeviceFactory"
1412+ type="Canonical.UbuntuOne.Client.DeviceFactory, Canonical.UbuntuOne.Client"
1413+ autowire="autodetect"/>
1414 </objects>
1415\ No newline at end of file
1416
1417=== modified file 'src/Canonical.UbuntuOne.Common/Canonical.UbuntuOne.Common.csproj'
1418--- src/Canonical.UbuntuOne.Common/Canonical.UbuntuOne.Common.csproj 2010-10-21 10:17:18 +0000
1419+++ src/Canonical.UbuntuOne.Common/Canonical.UbuntuOne.Common.csproj 2010-11-14 21:31:15 +0000
1420@@ -106,7 +106,9 @@
1421 <Compile Include="Net\HttpWebRequestFactory.cs" />
1422 <Compile Include="Net\IHttpWebRequestFactory.cs" />
1423 <Compile Include="Net\IHttpWebRequest.cs" />
1424+ <Compile Include="Net\IOAuth.cs" />
1425 <Compile Include="Net\IServiceCaller.cs" />
1426+ <Compile Include="Net\OAuth.cs" />
1427 <Compile Include="Net\ServiceCaller.cs" />
1428 <Compile Include="OperationContracts\IEventNotifier.cs" />
1429 <Compile Include="OperationContracts\IPostInitDirectoryTask.cs" />
1430@@ -213,6 +215,7 @@
1431 <Reference Include="System" />
1432 <Reference Include="System.Runtime.Serialization">
1433 </Reference>
1434+ <Reference Include="System.Web" />
1435 <Reference Include="System.Xaml" />
1436 <Reference Include="System.Xml" />
1437 <Reference Include="WindowsBase">
1438
1439=== renamed file 'src/Canonical.Ubuntu.SSO/IOAuth.cs' => 'src/Canonical.UbuntuOne.Common/Net/IOAuth.cs'
1440--- src/Canonical.Ubuntu.SSO/IOAuth.cs 2010-10-05 09:49:29 +0000
1441+++ src/Canonical.UbuntuOne.Common/Net/IOAuth.cs 2010-11-14 21:31:15 +0000
1442@@ -20,8 +20,11 @@
1443 using System.Collections.Generic;
1444 using System.Security.Cryptography;
1445
1446-namespace Canonical.Ubuntu.SSO
1447+namespace Canonical.UbuntuOne.Common.Net
1448 {
1449+ ///<summary>
1450+ /// Interface to be implemented by those objects that allows to perform Oauth operations.
1451+ ///</summary>
1452 public interface IOAuth
1453 {
1454 /// <summary>
1455@@ -118,5 +121,18 @@
1456 /// </summary>
1457 /// <returns></returns>
1458 string GenerateNonce();
1459+
1460+ /// <summary>
1461+ /// Returns a request with an Oauth header that can be used to acess a secured resource.
1462+ /// </summary>
1463+ /// <param name="uri">The uri to be accessed.</param>
1464+ /// <param name="httpMethod">The http method of the request.</param>
1465+ /// <param name="consumerKey">The consumer key of the oauth.</param>
1466+ /// <param name="consumerSecret">The consumer secret of the oauth.</param>
1467+ /// <param name="token">The token of the oauth,</param>
1468+ /// <param name="tokenSecret">The token secret of the oauth.</param>
1469+ /// <returns>Returns a request that can be used to access a secure resource.</returns>
1470+ IHttpWebRequest MakeRequest(string uri, string httpMethod, string consumerKey, string consumerSecret,
1471+ string token, string tokenSecret);
1472 }
1473 }
1474\ No newline at end of file
1475
1476=== renamed file 'src/Canonical.Ubuntu.SSO/OAuth.cs' => 'src/Canonical.UbuntuOne.Common/Net/OAuth.cs'
1477--- src/Canonical.Ubuntu.SSO/OAuth.cs 2010-10-05 09:49:29 +0000
1478+++ src/Canonical.UbuntuOne.Common/Net/OAuth.cs 2010-11-14 21:31:15 +0000
1479@@ -1,13 +1,36 @@
1480-using System;
1481+/* Copyright 2010 Canonical Ltd.
1482+ *
1483+ * This file is part of UbuntuOne on Windows.
1484+ *
1485+ * UbuntuOne on Windows is free software: you can redistribute it and/or modify
1486+ * it under the terms of the GNU Lesser General Public License version
1487+ * as published by the Free Software Foundation.
1488+ *
1489+ * Ubuntu One on Windows is distributed in the hope that it will be useful,
1490+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1491+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1492+ * GNU Lesser General Public License for more details.
1493+ *
1494+ * You should have received a copy of the GNU Lesser General Public License
1495+ * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
1496+ *
1497+ * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
1498+ */
1499+using System;
1500 using System.Security.Cryptography;
1501 using System.Collections.Generic;
1502 using System.Text;
1503 using System.Web;
1504
1505-namespace Canonical.Ubuntu.SSO
1506+namespace Canonical.UbuntuOne.Common.Net
1507 {
1508 public class OAuth : IOAuth
1509 {
1510+ #region Di properties
1511+
1512+ public IHttpWebRequestFactory HttpWebRequestFactory { get; set; }
1513+
1514+ #endregion
1515
1516 /// <summary>
1517 /// Provides a predefined set of algorithms that are supported officially by the protocol
1518@@ -387,5 +410,32 @@
1519 return Random.Next(123400, 9999999).ToString();
1520 }
1521
1522+
1523+ /// <summary>
1524+ /// Creates an oauth request that can access a protected web resource.
1525+ /// </summary>
1526+ /// <param name="uri">The uri where the resource is found.</param>
1527+ /// <param name="httpMethod">The request berb to be used.</param>
1528+ /// <param name="consumerKey">Consumer key from oauth.</param>
1529+ /// <param name="consumerSecret">Consumer secret from oauth.</param>
1530+ /// <param name="token">Token from oauth.</param>
1531+ /// <param name="tokenSecret">Token secret from oauth.</param>
1532+ /// <returns>A webrequest that can be used to access the resource.</returns>
1533+ public IHttpWebRequest MakeRequest(string uri, string httpMethod, string consumerKey, string consumerSecret, string token, string tokenSecret)
1534+ {
1535+ // Form the full REST request url
1536+ var url = new Uri(uri);
1537+ string normUrl;
1538+ string normParams;
1539+
1540+ // get oauth header
1541+ var authHeader = GenerateHeaderWithSignature(url, string.Empty, consumerKey, consumerSecret,
1542+ token, tokenSecret, httpMethod, GenerateTimeStamp(), GenerateNonce(), SignatureTypes.HMACSHA1,
1543+ out normUrl, out normParams);
1544+
1545+ var request = HttpWebRequestFactory.Create(url);
1546+ request.Headers.Add(authHeader.Key, authHeader.Value);
1547+ return request;
1548+ }
1549 }
1550 }
1551\ No newline at end of file
1552
1553=== modified file 'src/Canonical.UbuntuOne.Common/objects.xml'
1554--- src/Canonical.UbuntuOne.Common/objects.xml 2010-10-21 10:17:18 +0000
1555+++ src/Canonical.UbuntuOne.Common/objects.xml 2010-11-14 21:31:15 +0000
1556@@ -56,6 +56,10 @@
1557 <!-- Net Objects -->
1558 <!-- ######################################################################################## -->
1559
1560+ <object id="OAuth"
1561+ type="Canonical.UbuntuOne.Common.Net.OAuth , Canonical.UbuntuOne.Common"
1562+ autowire="autodetect"/>
1563+
1564 <object id="HttpWebRequestFactory"
1565 type="Canonical.UbuntuOne.Common.Net.HttpWebRequestFactory, Canonical.UbuntuOne.Common" />
1566

Subscribers

People subscribed via source and target branches

to all changes: