Revision 0c02aa65 trunk/Pithos.Client.WPF/PreferencesViewModel.cs
b/trunk/Pithos.Client.WPF/PreferencesViewModel.cs | ||
---|---|---|
16 | 16 |
using System.Windows; |
17 | 17 |
using System.Windows.Forms; |
18 | 18 |
using Caliburn.Micro; |
19 |
using Hardcodet.Wpf.TaskbarNotification; |
|
19 | 20 |
using Pithos.Client.WPF.Configuration; |
20 | 21 |
using Pithos.Core; |
21 | 22 |
using Pithos.Interfaces; |
22 |
using Pithos.ShellExtensions; |
|
23 |
|
|
23 | 24 |
using Screen = Caliburn.Micro.Screen; |
24 | 25 |
|
25 | 26 |
namespace Pithos.Client.WPF |
... | ... | |
28 | 29 |
using System.Collections.Generic; |
29 | 30 |
using System.Linq; |
30 | 31 |
using System.Text; |
32 |
using System.Threading.Tasks; |
|
31 | 33 |
|
32 | 34 |
/// <summary> |
33 | 35 |
/// TODO: Update summary. |
34 | 36 |
/// </summary> |
35 | 37 |
[Export(typeof(IShell))] |
36 |
public class PreferencesViewModel : Screen, IShell |
|
38 |
public class PreferencesViewModel : Screen, IShell, IHandle<Notification>
|
|
37 | 39 |
{ |
38 |
|
|
40 |
private IEventAggregator _events; |
|
39 | 41 |
|
40 | 42 |
|
41 |
public IPithosSettings Settings { get; set; }
|
|
43 |
public PithosSettings Settings { get; set; } |
|
42 | 44 |
|
43 | 45 |
|
44 | 46 |
public PithosMonitor Monitor { get; private set; } |
45 | 47 |
|
46 | 48 |
public TaskbarViewModel Taskbar { get; set; } |
47 | 49 |
|
48 |
ShellExtensionController _extensionController=new ShellExtensionController(); |
|
50 |
//ShellExtensionController _extensionController=new ShellExtensionController();
|
|
49 | 51 |
|
50 | 52 |
[ImportingConstructor] |
51 |
public PreferencesViewModel(TaskbarViewModel taskbar, IPithosSettings settings, PithosMonitor monitor)
|
|
53 |
public PreferencesViewModel(IEventAggregator events, TaskbarViewModel taskbar, PithosSettings settings, PithosMonitor monitor)
|
|
52 | 54 |
{ |
55 |
_events = events; |
|
56 |
_events.Subscribe(this); |
|
57 |
|
|
53 | 58 |
DisplayName = "Pithos Preferences"; |
54 | 59 |
|
55 | 60 |
Taskbar=taskbar; |
... | ... | |
65 | 70 |
new FileEntry{FileName="Moo",FullPath=@"e:\Pithos\moo"} , |
66 | 71 |
new FileEntry{FileName="Mee",FullPath=@"e:\Pithos\mee"} |
67 | 72 |
}); |
68 |
Taskbar.StatusMessage = "In Synch"; |
|
69 |
Taskbar.UpdateStatus(); |
|
73 |
Taskbar.StatusMessage = "In Synch"; |
|
70 | 74 |
} |
71 | 75 |
|
72 | 76 |
protected override void OnViewAttached(object view, object context) |
... | ... | |
81 | 85 |
{ |
82 | 86 |
var window = (Window)view; |
83 | 87 |
window.Hide(); |
84 |
|
|
88 |
Taskbar.UpdateStatus(); |
|
85 | 89 |
base.OnViewLoaded(view); |
86 | 90 |
} |
87 | 91 |
|
... | ... | |
189 | 193 |
NotifyOfPropertyChange(()=>Settings); |
190 | 194 |
} |
191 | 195 |
|
196 |
public void AddPithosAccount() |
|
197 |
{ |
|
198 |
var task=PithosAccount.RetrieveCredentialsAsync(Settings.PithosSite) |
|
199 |
.ContinueWith(t=> |
|
200 |
{ |
|
201 |
var credentials=t.Result; |
|
202 |
var account = Settings.Accounts.FirstOrDefault(act => act.AccountName == credentials.UserName); |
|
203 |
if (account == null) |
|
204 |
{ |
|
205 |
account=new AccountSettings{ |
|
206 |
AccountName=credentials.UserName, |
|
207 |
ApiKey=credentials.Password, |
|
208 |
UsePithos=true |
|
209 |
}; |
|
210 |
Settings.Accounts.Add(account); |
|
211 |
} |
|
212 |
else |
|
213 |
{ |
|
214 |
account.ApiKey=credentials.Password; |
|
215 |
} |
|
216 |
SelectedAccountIndex= Settings.Accounts.IndexOf(account); |
|
217 |
NotifyOfPropertyChange(()=>Settings); |
|
218 |
}); |
|
219 |
((Task)task).WaitWithPumping(); |
|
220 |
} |
|
221 |
|
|
192 | 222 |
public void RemoveAccount() |
193 | 223 |
{ |
194 | 224 |
Settings.Accounts.RemoveAll(account => account.AccountName == CurrentAccount.AccountName); |
... | ... | |
215 | 245 |
|
216 | 246 |
Settings.ExtensionsActivated = value; |
217 | 247 |
|
218 |
if (value) |
|
219 |
_extensionController.RegisterExtensions(); |
|
220 |
else |
|
221 |
{ |
|
222 |
_extensionController.UnregisterExtensions(); |
|
223 |
} |
|
248 |
//if (value)
|
|
249 |
// _extensionController.RegisterExtensions();
|
|
250 |
//else
|
|
251 |
//{
|
|
252 |
// _extensionController.UnregisterExtensions();
|
|
253 |
//}
|
|
224 | 254 |
NotifyOfPropertyChange(() => ExtensionsActivated); |
225 | 255 |
} |
226 | 256 |
} |
... | ... | |
244 | 274 |
// _selectedAccountIndex = value; |
245 | 275 |
//else |
246 | 276 |
// _selectedAccountIndex = 0; |
277 |
_selectedAccountIndex = value; |
|
247 | 278 |
NotifyOfPropertyChange(() => CurrentAccount); |
248 | 279 |
NotifyOfPropertyChange(() => CanRemoveAccount); |
249 | 280 |
NotifyOfPropertyChange(()=>SelectedAccountIndex); |
... | ... | |
267 | 298 |
} |
268 | 299 |
|
269 | 300 |
|
301 |
public void Handle(Notification notification) |
|
302 |
{ |
|
303 |
if (!Settings.ShowDesktopNotifications) |
|
304 |
return; |
|
305 |
BalloonIcon icon = BalloonIcon.None; |
|
306 |
switch (notification.Level) |
|
307 |
{ |
|
308 |
case TraceLevel.Error: |
|
309 |
icon = BalloonIcon.Error; |
|
310 |
break; |
|
311 |
case TraceLevel.Info: |
|
312 |
case TraceLevel.Verbose: |
|
313 |
icon = BalloonIcon.Info; |
|
314 |
break; |
|
315 |
case TraceLevel.Warning: |
|
316 |
icon = BalloonIcon.Warning; |
|
317 |
break; |
|
318 |
default: |
|
319 |
icon = BalloonIcon.None; |
|
320 |
break; |
|
321 |
} |
|
322 |
|
|
323 |
var tv = (PreferencesView)this.GetView(); |
|
324 |
tv.TaskbarView.ShowBalloonTip(notification.Title, notification.Message, icon); |
|
325 |
} |
|
326 |
|
|
270 | 327 |
} |
271 | 328 |
} |
Also available in: Unified diff