1 // -----------------------------------------------------------------------
2 // <copyright file="PreferencesViewModel.cs" company="Microsoft">
3 // TODO: Update copyright text.
5 // -----------------------------------------------------------------------
7 using System.Collections;
8 using System.ComponentModel.Composition;
9 using System.Diagnostics;
11 using System.IO.IsolatedStorage;
12 using System.Linq.Expressions;
14 using System.Reflection;
15 using System.Runtime.Serialization;
17 using System.Windows.Forms;
19 using Pithos.Client.WPF.Configuration;
21 using Pithos.Interfaces;
22 using Pithos.ShellExtensions;
23 using Screen = Caliburn.Micro.Screen;
25 namespace Pithos.Client.WPF
28 using System.Collections.Generic;
33 /// TODO: Update summary.
35 [Export(typeof(IShell))]
36 public class PreferencesViewModel : Screen, IShell
41 public IPithosSettings Settings { get; set; }
44 public PithosMonitor Monitor { get; private set; }
46 public TaskbarViewModel Taskbar { get; set; }
48 ShellExtensionController _extensionController=new ShellExtensionController();
50 [ImportingConstructor]
51 public PreferencesViewModel(TaskbarViewModel taskbar, IPithosSettings settings, PithosMonitor monitor)
53 DisplayName = "Pithos Preferences";
56 Taskbar.Parent = this;
62 Taskbar.UsageMessage = "Using 15% of 50 GB";
63 Taskbar.RecentFiles.AddRange(new[]
65 new FileEntry{FileName="Moo",FullPath=@"e:\Pithos\moo"} ,
66 new FileEntry{FileName="Mee",FullPath=@"e:\Pithos\mee"}
68 Taskbar.StatusMessage = "In Synch";
69 Taskbar.UpdateStatus();
72 protected override void OnViewAttached(object view, object context)
74 var window = (Window)view;
76 base.OnViewAttached(view, context);
80 protected override void OnViewLoaded(object view)
82 var window = (Window)view;
85 base.OnViewLoaded(view);
88 #region Preferences Properties
90 private bool _noProxy;
93 get { return _noProxy; }
97 NotifyOfPropertyChange(()=>NoProxy);
102 private bool _defaultProxy;
104 public bool DefaultProxy
106 get { return _defaultProxy; }
109 _defaultProxy = value;
110 NotifyOfPropertyChange(() => DefaultProxy);
115 private bool _manualProxy;
117 public bool ManualProxy
119 get { return _manualProxy; }
122 _manualProxy = value;
123 NotifyOfPropertyChange(() => ManualProxy);
133 public void SaveChanges()
139 public void RejectChanges()
145 public void ApplyChanges()
150 private void DoSave()
153 NotifyOfPropertyChange(()=>Settings);
157 public void ChangePithosFolder()
159 var browser = new FolderBrowserDialog();
160 browser.SelectedPath = Settings.PithosPath;
161 var result = browser.ShowDialog((IWin32Window)GetView());
162 if (result == DialogResult.OK)
164 var newPath = browser.SelectedPath;
165 Directory.Move(Settings.PithosPath, newPath);
166 Settings.PithosPath = newPath;
168 NotifyOfPropertyChange(() => Settings);
173 public void AddAccount()
175 var newAccount = new AccountSettings();
176 Settings.Accounts.Add(newAccount);
177 SelectedAccountIndex= Settings.Accounts.Count-1;
178 NotifyOfPropertyChange(()=>Settings);
181 public void RemoveAccount()
183 Settings.Accounts.RemoveAll(account => account.AccountName == CurrentAccount.AccountName);
185 NotifyOfPropertyChange(()=>CurrentAccount);
186 NotifyOfPropertyChange(()=>Settings);
187 //NotifyOfPropertyChange("Settings.Accounts");
190 public bool CanRemoveAccount
192 get { return (CurrentAccount != null); }
197 public bool ExtensionsActivated
199 get { return Settings.ExtensionsActivated; }
202 if (Settings.ExtensionsActivated == value)
205 Settings.ExtensionsActivated = value;
208 _extensionController.RegisterExtensions();
211 _extensionController.UnregisterExtensions();
213 NotifyOfPropertyChange(() => ExtensionsActivated);
217 public void RefreshOverlays()
219 this.Monitor.Workflow.RaiseChangeNotification(Settings.PithosPath);
223 private int _selectedAccountIndex;
224 public int SelectedAccountIndex
226 get { return _selectedAccountIndex; }
229 _selectedAccountIndex = value;
230 NotifyOfPropertyChange(() => CurrentAccount);
231 NotifyOfPropertyChange(() => CanRemoveAccount);
232 NotifyOfPropertyChange(()=>SelectedAccountIndex);
236 private AccountSettings _currentAccount;
237 public AccountSettings CurrentAccount
239 get { return Settings.Accounts[SelectedAccountIndex]; }
243 _currentAccount = value;