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;
13 using System.Runtime.Serialization;
15 using System.Windows.Forms;
17 using Pithos.Client.WPF.Configuration;
19 using Pithos.Interfaces;
20 using Pithos.ShellExtensions;
21 using Screen = Caliburn.Micro.Screen;
23 namespace Pithos.Client.WPF
26 using System.Collections.Generic;
31 /// TODO: Update summary.
33 [Export(typeof(IShell))]
34 public class PreferencesViewModel : Screen, IShell
39 public IPithosSettings Settings { get; set; }
42 public PithosMonitor Monitor { get; private set; }
44 public TaskbarViewModel Taskbar { get; set; }
46 ShellExtensionController _extensionController=new ShellExtensionController();
48 [ImportingConstructor]
49 public PreferencesViewModel(TaskbarViewModel taskbar, IPithosSettings settings, PithosMonitor monitor)
51 DisplayName = "Pithos Preferences";
54 Taskbar.Parent = this;
63 Taskbar.UsageMessage = "Using 15% of 50 GB";
64 Taskbar.RecentFiles.AddRange(new[]
66 new FileEntry{FileName="Moo",FullPath=@"e:\Pithos\moo"} ,
67 new FileEntry{FileName="Mee",FullPath=@"e:\Pithos\mee"}
69 Taskbar.StatusMessage = "In Synch";
70 Taskbar.UpdateStatus();
72 protected override void OnViewAttached(object view, object context)
74 var window = (Window)view;
76 window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
77 window.ShowInTaskbar = false;
80 base.OnViewAttached(view, context);
84 protected override void OnViewLoaded(object view)
86 var window = (Window)view;
89 base.OnViewLoaded(view);
92 #region Preferences Properties
94 private bool _noProxy;
97 get { return _noProxy; }
101 NotifyOfPropertyChange(()=>NoProxy);
106 private bool _defaultProxy;
108 public bool DefaultProxy
110 get { return _defaultProxy; }
113 _defaultProxy = value;
114 NotifyOfPropertyChange(() => DefaultProxy);
119 private bool _manualProxy;
121 public bool ManualProxy
123 get { return _manualProxy; }
126 _manualProxy = value;
127 NotifyOfPropertyChange(() => ManualProxy);
136 /*public void ShowPreferences()
140 var window = (Window)this.GetView();
145 /*public PithosCommand OpenPithosFolderCommand { get; private set; }
147 public void OpenPithosFolder()
149 Process.Start(Settings.PithosPath);
152 public void GoToSite()
157 public void ToggleSynching()
162 public void SaveChanges()
165 /*var window = (Window)GetView();
169 public void RejectChanges()
172 /* var window = (Window)GetView();
176 public void ApplyChanges()
181 private void DoSave()
187 public void ChangePithosFolder()
189 var browser = new FolderBrowserDialog();
190 browser.SelectedPath = Settings.PithosPath;
191 var result = browser.ShowDialog((IWin32Window)GetView());
192 if (result == DialogResult.OK)
194 var newPath = browser.SelectedPath;
195 Directory.Move(Settings.PithosPath, newPath);
196 Settings.PithosPath = newPath;
198 NotifyOfPropertyChange(() => Settings);
202 /* public void ExitPithos()
209 public void AddAccount()
211 var newAccount = new AccountSettings();
212 Settings.Accounts.Add(newAccount);
213 CurrentAccount = newAccount;
214 NotifyOfPropertyChange(()=>Settings);
217 public void RemoveAccount()
219 // var idx = Settings.Accounts.IndexOf(CurrentAccount);
220 Settings.Accounts.RemoveAll(account => account.AccountName == CurrentAccount.AccountName);
221 // Settings.Accounts.RemoveAt(idx);
222 CurrentAccount = null;
223 NotifyOfPropertyChange(()=>Settings);
224 NotifyOfPropertyChange("Settings.Accounts");
227 public bool CanRemoveAccount
229 get { return (CurrentAccount != null); }
234 public bool ExtensionsActivated
236 get { return Settings.ExtensionsActivated; }
239 if (Settings.ExtensionsActivated == value)
242 Settings.ExtensionsActivated = value;
245 _extensionController.RegisterExtensions();
248 _extensionController.UnregisterExtensions();
250 NotifyOfPropertyChange(() => ExtensionsActivated);
254 public void RefreshOverlays()
256 this.Monitor.Workflow.RaiseChangeNotification(Settings.PithosPath);
260 private AccountSettings _currentAccount;
261 public AccountSettings CurrentAccount
263 get { return _currentAccount; }
266 _currentAccount = value;
267 NotifyOfPropertyChange(()=>CurrentAccount);
268 NotifyOfPropertyChange(()=>CanRemoveAccount);
274 /* private void UnregisterExtensions()
276 using (var installer = new ProjectInstaller())
278 IDictionary state = ShellExtensionController.LoadState();
279 installer.Uninstall(state);
283 private void RegisterExtensions()
285 using (var installer = new ProjectInstaller())
287 IDictionary state = new Dictionary<object, object>();
288 installer.Install(state);
289 ShellExtensionController.SaveState(state);