Merge lp:~mandel/ubuntuone-windows-installer/smart_context_menu 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: 134
Proposed branch: lp:~mandel/ubuntuone-windows-installer/smart_context_menu
Merge into: lp:ubuntuone-windows-installer/beta
Prerequisite: lp:~mandel/ubuntuone-windows-installer/manual_sync_does_nothing
Diff against target: 438 lines (+149/-44) (has conflicts)
11 files modified
src/Canonical.Ubuntu.SSO/ISSOCredentialsProvider.cs (+7/-0)
src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs (+19/-4)
src/Canonical.UbuntuOne.Client.Views.Tests/NotifyIconFixture.cs (+2/-1)
src/Canonical.UbuntuOne.Client.Views/NotifyIcon.xaml (+9/-5)
src/Canonical.UbuntuOne.Client.Views/NotifyIcon.xaml.cs (+47/-20)
src/Canonical.UbuntuOne.Client.Views/Resources/Resources.resx (+3/-0)
src/Canonical.UbuntuOne.Client.Views/Resources/Resources1.Designer.cs (+9/-0)
src/Canonical.UbuntuOne.Client.Views/objects.xml (+2/-3)
src/Canonical.UbuntuOne.Client/Notification/INotificationIconPresenter.cs (+10/-0)
src/Canonical.UbuntuOne.Client/Notification/INotificationIconView.cs (+6/-0)
src/Canonical.UbuntuOne.Client/Notification/NotificationIconPresenter.cs (+35/-11)
Text conflict in src/Canonical.UbuntuOne.Client/Notification/NotificationIconPresenter.cs
To merge this branch: bzr merge lp:~mandel/ubuntuone-windows-installer/smart_context_menu
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Review via email: mp+40667@code.launchpad.net

Description of the change

Made the context menu smarter to show diff content according to the status of the user credentials.

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

Ensures that method is executed in the correct thread.

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/ISSOCredentialsProvider.cs'
2--- src/Canonical.Ubuntu.SSO/ISSOCredentialsProvider.cs 2010-10-18 10:53:55 +0000
3+++ src/Canonical.Ubuntu.SSO/ISSOCredentialsProvider.cs 2010-11-12 14:29:04 +0000
4@@ -72,6 +72,13 @@
5 /// </summary>
6 void LoginOrRegisterToGetCredentials();
7
8+ /// <summary>
9+ /// Gets if the credentials are present in the system.
10+ /// </summary>
11+ /// <param name="applicationName">The name of the applications whose credentials we want to
12+ /// get.</param>
13+ bool CredentialsArePresent(string applicationName);
14+
15 #endregion
16
17 }
18
19=== modified file 'src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs'
20--- src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs 2010-10-20 11:32:24 +0000
21+++ src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs 2010-11-12 14:29:04 +0000
22@@ -82,12 +82,12 @@
23 if (LoginView.ViewDispatcher.Dispatch(() => LoginView.IsShown))
24 return;
25
26- if (LoginView.ViewDispatcher.Dispatch( () => LoginView.ShowDialog() != MessageBoxResult.Cancel))
27+ if (LoginView.ViewDispatcher.Dispatch(() => LoginView.ShowDialog() != MessageBoxResult.Cancel))
28 {
29 var tokenName = string.Format(ApplicationTokenName, Environment.MachineName);
30 secret = SSOLoginProcessor.Login(
31 LoginView.ViewDispatcher.Dispatch(() => LoginView.EmailAddress),
32- LoginView.ViewDispatcher.Dispatch(() => LoginView.Password),
33+ LoginView.ViewDispatcher.Dispatch(() => LoginView.Password),
34 tokenName);
35 // save the credentials in the keyring
36 // TODO: We have an issue here since we have more than one listening for the same credntials of Ubuntu One
37@@ -101,10 +101,10 @@
38 }
39 return;
40 }
41-
42+
43 }
44 // we execute the credentials found event
45- if(!string.IsNullOrEmpty(secret) && OnCredentialsFound != null)
46+ if (!string.IsNullOrEmpty(secret) && OnCredentialsFound != null)
47 {
48 string token;
49 string tokenSecret;
50@@ -157,6 +157,21 @@
51 throw new NotImplementedException();
52 }
53
54+ /// <summary>
55+ /// Returns if the credentials of a given application are present.
56+ /// </summary>
57+ /// <param name="applicationName">The name of the application whose credentials we want
58+ /// to get.</param>
59+ /// <returns>A bool value stating if the credentials are present.</returns>
60+ public bool CredentialsArePresent(string applicationName)
61+ {
62+ //TODO: Currently application name is hardcoded!!!!
63+ // try to get the credentials from the keyring
64+ var secret = Keyring.GetSecretByName(KeyringName, ApplicationName);
65+ return secret != null;
66+
67+ }
68+
69 #endregion
70 }
71 }
72
73=== modified file 'src/Canonical.UbuntuOne.Client.Views.Tests/NotifyIconFixture.cs'
74--- src/Canonical.UbuntuOne.Client.Views.Tests/NotifyIconFixture.cs 2010-10-20 23:27:32 +0000
75+++ src/Canonical.UbuntuOne.Client.Views.Tests/NotifyIconFixture.cs 2010-11-12 14:29:04 +0000
76@@ -43,7 +43,8 @@
77 {
78 _moks = new MockRepository();
79 _presenter = _moks.StrictMock<INotificationIconPresenter>();
80- _icon = new UbuntuOneNotifyIcon {NotificationIconPresenter = _presenter};
81+ _icon = new UbuntuOneNotifyIcon (_presenter);
82+ _moks.BackToRecordAll();
83 }
84
85 #endregion
86
87=== modified file 'src/Canonical.UbuntuOne.Client.Views/NotifyIcon.xaml'
88--- src/Canonical.UbuntuOne.Client.Views/NotifyIcon.xaml 2010-10-21 11:41:25 +0000
89+++ src/Canonical.UbuntuOne.Client.Views/NotifyIcon.xaml 2010-11-12 14:29:04 +0000
90@@ -70,7 +70,11 @@
91 <av:NotifyIcon Name="NotifyIcon" Icon="/Canonical.UbuntuOne.Client.Views;component/Resources/ubuntu-logo-22x22.png"
92 Text="Ubuntu One"> <!-- TODO: Add icon Icon="/AvalonLibraryTestPages;component/Properties/App.ico" Open preferences when click -->
93 <FrameworkElement.ContextMenu >
94- <ContextMenu StaysOpen="False">
95+ <ContextMenu StaysOpen="False" >
96+ <MenuItem x:Uid="AddComputer"
97+ Name="AddComputer"
98+ Header="{x:Static resx:Resources.NotificationIconAddComputerLabel}"
99+ Click="OnAddComputerClick"/>
100 <MenuItem x:Uid="UbuntuOneManualSync"
101 Name="UbuntuOneManualSync"
102 Header="{x:Static resx:Resources.NotificationIconUbuntuOneManualSyncLabel}"
103@@ -87,10 +91,10 @@
104 Name="OpenSyncMenuItem"
105 Header="{x:Static resx:Resources.NotificationIconOpenSyncLabel}"
106 Click="OnOpenSyncMenuItemClick"/>
107- <Separator />
108- <MenuItem Name="StateMenuItem"
109- Header="State"/>
110- <Separator />
111+ <Separator Name="OptionsSeparator" />
112+ <Label Name="StateMenuItem"
113+ Content="State: Idle"/>
114+ <Separator Name="HelpSeparator" />
115 <MenuItem x:Uid="HelpMenuItem"
116 Name="HelpMenuItem"
117 Header="{x:Static resx:Resources.NotificationIconHelpLabel}"
118
119=== modified file 'src/Canonical.UbuntuOne.Client.Views/NotifyIcon.xaml.cs'
120--- src/Canonical.UbuntuOne.Client.Views/NotifyIcon.xaml.cs 2010-10-21 13:11:36 +0000
121+++ src/Canonical.UbuntuOne.Client.Views/NotifyIcon.xaml.cs 2010-11-12 14:29:04 +0000
122@@ -36,25 +36,18 @@
123 private IDispatcher _dispatcher;
124 private readonly object _dispatcherLock = new object();
125 private Storyboard _iconAnimation;
126-
127- #endregion
128-
129- #region DI Properties
130-
131- /// <summary>
132- /// Gets and sets the presenter that contains the logic that is used by the notification icon.
133- /// </summary>
134- public INotificationIconPresenter NotificationIconPresenter { get; set; }
135-
136+ private INotificationIconPresenter _presenter;
137 #endregion
138
139 /// <summary>
140 /// Initializes a new instance of the UbuntuOneNotifyIcon class.
141 /// </summary>
142- public UbuntuOneNotifyIcon()
143+ public UbuntuOneNotifyIcon(INotificationIconPresenter presenter)
144 {
145 InitializeComponent();
146 _iconAnimation = Resources["IconAnimation"] as Storyboard;
147+ _presenter = presenter;
148+ _presenter.InitializeView();
149 }
150
151 #region Implementation of INotificationIconView
152@@ -114,6 +107,34 @@
153 NotifyIcon.ShowBalloonTip(timeout, title, text, icon);
154 }
155
156+ public void ShowAsAddedComputer(bool isAddedComputer)
157+ {
158+ if(isAddedComputer)
159+ {
160+ // show all the menu items
161+ UbuntuOneManualSync.Visibility = System.Windows.Visibility.Visible;
162+ UbuntuOnePreferencesMenuItem.Visibility = System.Windows.Visibility.Visible;
163+ OpenShareManueItem.Visibility = System.Windows.Visibility.Visible;
164+ OpenSyncMenuItem.Visibility = System.Windows.Visibility.Visible;
165+ OptionsSeparator.Visibility = System.Windows.Visibility.Visible;
166+ HelpSeparator.Visibility = System.Windows.Visibility.Visible;
167+ // we do not need to add the computer
168+ AddComputer.Visibility = System.Windows.Visibility.Collapsed;
169+ }
170+ else
171+ {
172+ // Hide all the diff menu items
173+ UbuntuOneManualSync.Visibility = System.Windows.Visibility.Collapsed;
174+ UbuntuOnePreferencesMenuItem.Visibility = System.Windows.Visibility.Collapsed;
175+ OpenShareManueItem.Visibility = System.Windows.Visibility.Collapsed;
176+ OpenSyncMenuItem.Visibility = System.Windows.Visibility.Collapsed;
177+ OptionsSeparator.Visibility = System.Windows.Visibility.Collapsed;
178+ HelpSeparator.Visibility = System.Windows.Visibility.Collapsed;
179+ // provide the user a way to add the computer
180+ AddComputer.Visibility = System.Windows.Visibility.Visible;
181+ }
182+ }
183+
184 /// <summary>
185 /// Gets and sets the list of recently modified files.
186 /// </summary>
187@@ -128,10 +149,10 @@
188 /// </summary>
189 public string State
190 {
191- get { return (string)StateMenuItem.Header; }
192+ get { return (string)StateMenuItem.Content; }
193 set
194 {
195- StateMenuItem.Header = value;
196+ StateMenuItem.Content = value;
197 Title = value;
198 }
199 }
200@@ -169,34 +190,40 @@
201
202 internal void OnUbuntuOneManualSyncClick(object sender, System.Windows.RoutedEventArgs e)
203 {
204- var thread = new Thread(NotificationIconPresenter.ManualSync);
205+ var thread = new Thread(_presenter.ManualSync);
206 thread.Start();
207 }
208
209 internal void OnExitMenuItemClick(object sender, System.Windows.RoutedEventArgs e)
210 {
211- NotificationIconPresenter.Exit();
212+ _presenter.Exit();
213 }
214
215 internal void OnHelpMenuItemClick(object sender, System.Windows.RoutedEventArgs e)
216 {
217- NotificationIconPresenter.OpenHelp();
218+ _presenter.OpenHelp();
219 }
220
221 internal void OnMoreSpaceMenuItemClick(object sender, System.Windows.RoutedEventArgs e)
222 {
223- NotificationIconPresenter.OpenUpgradeOption();
224+ _presenter.OpenUpgradeOption();
225 }
226
227 internal void OnOpenSyncMenuItemClick(object sender, System.Windows.RoutedEventArgs e)
228 {
229- NotificationIconPresenter.OpenSyncsLocation();
230+ _presenter.OpenSyncsLocation();
231 }
232
233 internal void OnUbuntuOnePreferencesMenuItemClick(object sender, System.Windows.RoutedEventArgs e)
234 {
235- NotificationIconPresenter.OpenUbuntuOnePreferences();
236- }
237+ _presenter.OpenUbuntuOnePreferences();
238+ }
239+
240+ private void OnAddComputerClick(object sender, System.Windows.RoutedEventArgs e)
241+ {
242+ _presenter.AddComputer();
243+ }
244+
245
246 }
247 }
248
249=== modified file 'src/Canonical.UbuntuOne.Client.Views/Resources/Resources.resx'
250--- src/Canonical.UbuntuOne.Client.Views/Resources/Resources.resx 2010-10-13 09:56:20 +0000
251+++ src/Canonical.UbuntuOne.Client.Views/Resources/Resources.resx 2010-11-12 14:29:04 +0000
252@@ -155,6 +155,9 @@
253 <value>Downloading updates...</value>
254 <comment>The title of the downloading dialog.</comment>
255 </data>
256+ <data name="NotificationIconAddComputerLabel" xml:space="preserve">
257+ <value>Add this computer</value>
258+ </data>
259 <data name="NotificationIconExitLabel" xml:space="preserve">
260 <value>Exit</value>
261 <comment>The title of the exit menu item.</comment>
262
263=== modified file 'src/Canonical.UbuntuOne.Client.Views/Resources/Resources1.Designer.cs'
264--- src/Canonical.UbuntuOne.Client.Views/Resources/Resources1.Designer.cs 2010-10-13 09:56:20 +0000
265+++ src/Canonical.UbuntuOne.Client.Views/Resources/Resources1.Designer.cs 2010-11-12 14:29:04 +0000
266@@ -151,6 +151,15 @@
267 }
268
269 /// <summary>
270+ /// Looks up a localized string similar to Add this computer.
271+ /// </summary>
272+ public static string NotificationIconAddComputerLabel {
273+ get {
274+ return ResourceManager.GetString("NotificationIconAddComputerLabel", resourceCulture);
275+ }
276+ }
277+
278+ /// <summary>
279 /// Looks up a localized string similar to Exit.
280 /// </summary>
281 public static string NotificationIconExitLabel {
282
283=== modified file 'src/Canonical.UbuntuOne.Client.Views/objects.xml'
284--- src/Canonical.UbuntuOne.Client.Views/objects.xml 2010-10-13 10:38:57 +0000
285+++ src/Canonical.UbuntuOne.Client.Views/objects.xml 2010-11-12 14:29:04 +0000
286@@ -8,9 +8,8 @@
287 type="Canonical.UbuntuOne.Client.Views.Update.UpdatingView, Canonical.UbuntuOne.Client.Views" />
288
289 <object id="UbuntuOneNotifyIcon"
290- type="Canonical.UbuntuOne.Client.Views.UbuntuOneNotifyIcon, Canonical.UbuntuOne.Client.Views" >
291- <property name="NotificationIconPresenter"
292- ref="NotificationIconPresenter" />
293+ type="Canonical.UbuntuOne.Client.Views.UbuntuOneNotifyIcon, Canonical.UbuntuOne.Client.Views" depends-on="NotificationIconPresenter">
294+ <constructor-arg name="presenter" ref="NotificationIconPresenter"/>
295 </object>
296
297 <object id="PreferencesView"
298
299=== modified file 'src/Canonical.UbuntuOne.Client/Notification/INotificationIconPresenter.cs'
300--- src/Canonical.UbuntuOne.Client/Notification/INotificationIconPresenter.cs 2010-10-21 13:11:36 +0000
301+++ src/Canonical.UbuntuOne.Client/Notification/INotificationIconPresenter.cs 2010-11-12 14:29:04 +0000
302@@ -26,6 +26,16 @@
303 public interface INotificationIconPresenter
304 {
305 /// <summary>
306+ /// Initializes the view to ensure that shows the correct data.
307+ /// </summary>
308+ void InitializeView();
309+
310+ /// <summary>
311+ /// Action taken when the user wants to add the current computer to his machine.
312+ /// </summary>
313+ void AddComputer();
314+
315+ /// <summary>
316 /// When implemented this method should for the sync of the ubuntu one folder.
317 /// </summary>
318 void ManualSync();
319
320=== modified file 'src/Canonical.UbuntuOne.Client/Notification/INotificationIconView.cs'
321--- src/Canonical.UbuntuOne.Client/Notification/INotificationIconView.cs 2010-10-21 13:11:36 +0000
322+++ src/Canonical.UbuntuOne.Client/Notification/INotificationIconView.cs 2010-11-12 14:29:04 +0000
323@@ -50,6 +50,12 @@
324 void ShowNotification(int timeout, string title, string text, NotificationType type);
325
326 /// <summary>
327+ /// Tells the view to display as if the computer was already added to the service.
328+ /// </summary>
329+ /// <param name="isAddedComputer">States if the computer was added.</param>
330+ void ShowAsAddedComputer(bool isAddedComputer);
331+
332+ /// <summary>
333 /// Gets and sets the list of recently modified files.
334 /// </summary>
335 IList<string> RecentlyModifiedFiles { get; set; }
336
337=== modified file 'src/Canonical.UbuntuOne.Client/Notification/NotificationIconPresenter.cs'
338--- src/Canonical.UbuntuOne.Client/Notification/NotificationIconPresenter.cs 2010-11-11 11:43:38 +0000
339+++ src/Canonical.UbuntuOne.Client/Notification/NotificationIconPresenter.cs 2010-11-12 14:29:04 +0000
340@@ -51,9 +51,16 @@
341 private ISSOCredentialsProvider _ssoProvider;
342 private ILog _logger;
343 private readonly object _loggerLock = new object();
344+<<<<<<< TREE
345 private const string EventName = "UbuntuOneNotificationIconPresenter";
346 private const string ApplicationName = "UbuntuOne";
347
348+=======
349+ private static string ManualSyncEvent = "UbuntuOneNotificationIconPresenter.ManualSync";
350+ private static string AddComputerEvent = "UbuntuOneNotificationIconPresenter.AddComputer";
351+ private static string ApplicationName = "UbuntuOne";
352+ private INotificationIconView _view;
353+>>>>>>> MERGE-SOURCE
354 #endregion
355
356 #region Di properties
357@@ -107,6 +114,7 @@
358 _ssoProvider.OnCredentialsFound += OnCredentialsFound;
359 _ssoProvider.OnCredentialsError += OnCredentialsError;
360 _ssoProvider.OnCredetialsDenied += OnCredentialsDenied;
361+ InitializeView();
362 }
363 }
364
365@@ -229,16 +237,18 @@
366 [DebugLogged]
367 private void OnCredentialsFound(object sender, CredentialsFoundEventArgs args)
368 {
369- // check if the credentials are for us
370- if (args.ApplicationName != EventName) return;
371+ // we got credentials, no matter what we tell the ui to be ready
372+ NotificationIconView.ViewDispatcher.Dispatch(() => NotificationIconView.ShowAsAddedComputer(true));
373+ // check if the credentials are for us);
374+ if (args.ApplicationName != ManualSyncEvent) return;
375 NotificationIconView.ViewDispatcher.Dispatch(
376 () =>
377- {
378- NotificationIconView.IsManualSyncEnabled = false;
379- NotificationIconView.State = "Syncing";
380- }
381+ {
382+ NotificationIconView.IsManualSyncEnabled = false;
383+ NotificationIconView.State = "Syncing";
384+ }
385 );
386-
387+
388 Logger.Info("Got the UbuntuOne credentials!");
389 var oneDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
390 Resources.DefaulDirectoryName);
391@@ -262,14 +272,14 @@
392 [DebugLogged]
393 private void OnCredentialsDenied(object sender, CredentialsDeniedEventArgs args)
394 {
395- if (args.ApplicationName != EventName) return;
396+ if (args.ApplicationName != ManualSyncEvent) return;
397 MessageBox.ShowWarning("You need to login to be able to sync your files.");
398 }
399
400 [DebugLogged]
401 private void OnCredentialsError(object sender, CredentialsErrorEventArgs args)
402 {
403- if (args.ApplicationName != EventName) return;
404+ if (args.ApplicationName != ManualSyncEvent) return;
405 MessageBox.ShowError(string.Format("An error courred when trying to retrieve your credentials: {0}", args.ErrorMessage));
406 Logger.ErrorFormat("The error was {0}, {1}", args.ErrorMessage, args.DetailedErrorMessage);
407 }
408@@ -278,14 +288,28 @@
409
410 #region Implementation of INotificationIconPresenter
411
412+ public void InitializeView()
413+ {
414+ if (SSOCredentialsProvider != null)
415+ if (SSOCredentialsProvider.CredentialsArePresent(ApplicationName))
416+ NotificationIconView.ShowAsAddedComputer(true);
417+ else
418+ NotificationIconView.ShowAsAddedComputer(false);
419+ }
420+
421+ public void AddComputer()
422+ {
423+ // call the sso credentials provider but with a diff event so that we do not perform a manual sync
424+ SSOCredentialsProvider.LoginToGetCredentials(AddComputerEvent, ApplicationName);
425+ }
426+
427 /// <summary>
428 /// When implemented this method should for the sync of the ubuntu one folder.
429 /// </summary>
430 public void ManualSync()
431 {
432-
433 // we get the credentials, because we have register an action to the credetials aquired, we do nothing besides this
434- SSOCredentialsProvider.LoginToGetCredentials(EventName, ApplicationName);
435+ SSOCredentialsProvider.LoginToGetCredentials(ManualSyncEvent, ApplicationName);
436 }
437
438 /// <summary>

Subscribers

People subscribed via source and target branches

to all changes: