Revision 5bcf6d70 trunk/Pithos.Client.WPF/PreferencesViewModel.cs
b/trunk/Pithos.Client.WPF/PreferencesViewModel.cs | ||
---|---|---|
9 | 9 |
using System.Diagnostics; |
10 | 10 |
using System.IO; |
11 | 11 |
using System.IO.IsolatedStorage; |
12 |
using System.Net; |
|
12 | 13 |
using System.Runtime.Serialization; |
13 | 14 |
using System.Windows; |
14 | 15 |
using System.Windows.Forms; |
... | ... | |
33 | 34 |
public class PreferencesViewModel : Screen, IShell |
34 | 35 |
{ |
35 | 36 |
|
36 |
private IStatusChecker _statusChecker; |
|
37 | 37 |
|
38 | 38 |
|
39 | 39 |
public IPithosSettings Settings { get; set; } |
... | ... | |
41 | 41 |
|
42 | 42 |
public PithosMonitor Monitor { get; private set; } |
43 | 43 |
|
44 |
public TaskbarViewModel Taskbar { get; set; } |
|
44 | 45 |
|
45 | 46 |
ShellExtensionController _extensionController=new ShellExtensionController(); |
46 | 47 |
|
47 | 48 |
[ImportingConstructor] |
48 |
public PreferencesViewModel(IStatusChecker statusChecker, IPithosSettings settings, PithosMonitor monitor)
|
|
49 |
public PreferencesViewModel(TaskbarViewModel taskbar, IPithosSettings settings, PithosMonitor monitor)
|
|
49 | 50 |
{ |
50 | 51 |
DisplayName = "Pithos Preferences"; |
51 |
_statusChecker = statusChecker; |
|
52 |
|
|
53 |
Taskbar=taskbar; |
|
54 |
Taskbar.Parent = this; |
|
55 |
|
|
52 | 56 |
Settings=settings; |
53 | 57 |
Monitor=monitor; |
54 | 58 |
|
55 |
OpenPithosFolderCommand=new PithosCommand(OpenPithosFolder); |
|
59 |
|
|
56 | 60 |
|
57 | 61 |
|
58 | 62 |
|
59 |
UsageMessage = "Using 15% of 50 GB"; |
|
60 |
RecentFiles.AddRange(new[] |
|
63 |
Taskbar.UsageMessage = "Using 15% of 50 GB";
|
|
64 |
Taskbar.RecentFiles.AddRange(new[]
|
|
61 | 65 |
{ |
62 | 66 |
new FileEntry{FileName="Moo",FullPath=@"e:\Pithos\moo"} , |
63 | 67 |
new FileEntry{FileName="Mee",FullPath=@"e:\Pithos\mee"} |
64 | 68 |
}); |
65 |
StatusMessage = "In Synch"; |
|
66 |
UpdateStatus(); |
|
69 |
Taskbar.StatusMessage = "In Synch";
|
|
70 |
Taskbar.UpdateStatus();
|
|
67 | 71 |
} |
68 | 72 |
protected override void OnViewAttached(object view, object context) |
69 | 73 |
{ |
70 | 74 |
var window = (Window)view; |
75 |
/* |
|
71 | 76 |
window.WindowStartupLocation = WindowStartupLocation.CenterScreen; |
72 | 77 |
window.ShowInTaskbar = false; |
78 |
*/ |
|
73 | 79 |
|
74 | 80 |
base.OnViewAttached(view, context); |
75 | 81 |
} |
... | ... | |
83 | 89 |
base.OnViewLoaded(view); |
84 | 90 |
} |
85 | 91 |
|
92 |
#region Preferences Properties |
|
86 | 93 |
|
87 |
#region Status Properties |
|
88 |
|
|
89 |
private string _statusMessage; |
|
90 |
public string StatusMessage |
|
94 |
private bool _noProxy; |
|
95 |
public bool NoProxy |
|
91 | 96 |
{ |
92 |
get { return _statusMessage; }
|
|
97 |
get { return _noProxy; }
|
|
93 | 98 |
set |
94 | 99 |
{ |
95 |
_statusMessage = value;
|
|
96 |
NotifyOfPropertyChange(() => StatusMessage);
|
|
100 |
_noProxy = value;
|
|
101 |
NotifyOfPropertyChange(()=>NoProxy);
|
|
97 | 102 |
} |
98 | 103 |
} |
99 | 104 |
|
100 |
private string _usageMessage; |
|
101 |
public string UsageMessage |
|
105 |
|
|
106 |
private bool _defaultProxy; |
|
107 |
|
|
108 |
public bool DefaultProxy |
|
102 | 109 |
{ |
103 |
get { return _usageMessage; }
|
|
110 |
get { return _defaultProxy; }
|
|
104 | 111 |
set |
105 | 112 |
{ |
106 |
_usageMessage = value;
|
|
107 |
NotifyOfPropertyChange(() => UsageMessage);
|
|
113 |
_defaultProxy = value;
|
|
114 |
NotifyOfPropertyChange(() => DefaultProxy);
|
|
108 | 115 |
} |
109 | 116 |
} |
110 | 117 |
|
111 |
private readonly IObservableCollection<FileEntry> _recentFiles = new BindableCollection<FileEntry>(); |
|
112 |
public IObservableCollection<FileEntry> RecentFiles |
|
113 |
{ |
|
114 |
get { return _recentFiles; } |
|
115 |
} |
|
116 | 118 |
|
119 |
private bool _manualProxy; |
|
117 | 120 |
|
118 |
private string _statusIcon; |
|
119 |
public string StatusIcon |
|
121 |
public bool ManualProxy |
|
120 | 122 |
{ |
121 |
get { return _statusIcon; }
|
|
123 |
get { return _manualProxy; }
|
|
122 | 124 |
set |
123 | 125 |
{ |
124 |
_statusIcon = value;
|
|
125 |
NotifyOfPropertyChange(()=>StatusIcon);
|
|
126 |
_manualProxy = value;
|
|
127 |
NotifyOfPropertyChange(() => ManualProxy);
|
|
126 | 128 |
} |
127 | 129 |
} |
128 |
|
|
129 | 130 |
#endregion |
130 | 131 |
|
131 |
//public PithosSettings Settings { get; set; } |
|
132 |
|
|
132 |
|
|
133 | 133 |
#region Commands |
134 | 134 |
|
135 | 135 |
|
136 |
public void ShowPreferences() |
|
136 |
/*public void ShowPreferences()
|
|
137 | 137 |
{ |
138 | 138 |
Settings.Reload(); |
139 | 139 |
|
140 | 140 |
var window = (Window)this.GetView(); |
141 | 141 |
window.Show(); |
142 |
} |
|
142 |
}*/
|
|
143 | 143 |
|
144 | 144 |
|
145 |
public PithosCommand OpenPithosFolderCommand { get; private set; } |
|
145 |
/*public PithosCommand OpenPithosFolderCommand { get; private set; }
|
|
146 | 146 |
|
147 | 147 |
public void OpenPithosFolder() |
148 | 148 |
{ |
... | ... | |
158 | 158 |
{ |
159 | 159 |
|
160 | 160 |
} |
161 |
|
|
161 |
*/ |
|
162 | 162 |
public void SaveChanges() |
163 | 163 |
{ |
164 | 164 |
DoSave(); |
... | ... | |
199 | 199 |
} |
200 | 200 |
} |
201 | 201 |
|
202 |
public void ExitPithos() |
|
202 |
/* public void ExitPithos()
|
|
203 | 203 |
{ |
204 | 204 |
Monitor.Stop(); |
205 | 205 |
this.TryClose(); |
206 | 206 |
} |
207 |
*/ |
|
207 | 208 |
|
208 |
#endregion |
|
209 |
|
|
210 |
private AccountSettings _currentAccount; |
|
211 |
public AccountSettings CurrentAccount |
|
209 |
public void AddAccount() |
|
212 | 210 |
{ |
213 |
get { return _currentAccount; } |
|
214 |
set |
|
215 |
{ |
|
216 |
_currentAccount = value; |
|
217 |
NotifyOfPropertyChange(()=>CurrentAccount); |
|
218 |
} |
|
211 |
var newAccount = new AccountSettings(); |
|
212 |
Settings.Accounts.Add(newAccount); |
|
213 |
CurrentAccount = newAccount; |
|
214 |
NotifyOfPropertyChange(()=>Settings); |
|
219 | 215 |
} |
220 | 216 |
|
217 |
public void RemoveAccount() |
|
218 |
{ |
|
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"); |
|
225 |
} |
|
221 | 226 |
|
222 |
private Dictionary<PithosStatus, StatusInfo> iconNames = new List<StatusInfo> |
|
223 |
{ |
|
224 |
new StatusInfo(PithosStatus.InSynch, "All files up to date", "TrayInSynch"), |
|
225 |
new StatusInfo(PithosStatus.Synching, "Synching Files", "TraySynching") |
|
226 |
}.ToDictionary(s => s.Status); |
|
227 |
|
|
228 |
public void UpdateStatus() |
|
227 |
public bool CanRemoveAccount |
|
229 | 228 |
{ |
230 |
var pithosStatus = _statusChecker.GetPithosStatus(); |
|
229 |
get { return (CurrentAccount != null); } |
|
230 |
} |
|
231 | 231 |
|
232 | 232 |
|
233 |
if (iconNames.ContainsKey(pithosStatus)) |
|
234 |
{ |
|
235 |
var info = iconNames[pithosStatus]; |
|
236 |
StatusIcon = String.Format(@"Images/{0}.ico",info.IconName); |
|
237 |
StatusMessage= String.Format("Pithos 1.0\r\n{0}", info.StatusText); |
|
238 |
} |
|
239 |
if (!String.IsNullOrWhiteSpace(Settings.UserName) && |
|
240 |
!String.IsNullOrWhiteSpace(Settings.ApiKey)) |
|
241 |
Monitor.Start(); |
|
242 |
} |
|
243 | 233 |
|
244 |
|
|
245 | 234 |
public bool ExtensionsActivated |
246 | 235 |
{ |
247 | 236 |
get { return Settings.ExtensionsActivated; } |
248 | 237 |
set |
249 | 238 |
{ |
250 | 239 |
if (Settings.ExtensionsActivated == value) |
251 |
return;
|
|
252 |
|
|
240 |
return; |
|
241 |
|
|
253 | 242 |
Settings.ExtensionsActivated = value; |
254 | 243 |
|
255 |
if(value) |
|
244 |
if (value)
|
|
256 | 245 |
_extensionController.RegisterExtensions(); |
257 | 246 |
else |
258 | 247 |
{ |
259 | 248 |
_extensionController.UnregisterExtensions(); |
260 | 249 |
} |
261 |
NotifyOfPropertyChange(()=>ExtensionsActivated);
|
|
250 |
NotifyOfPropertyChange(() => ExtensionsActivated);
|
|
262 | 251 |
} |
263 | 252 |
} |
264 | 253 |
|
254 |
public void RefreshOverlays() |
|
255 |
{ |
|
256 |
this.Monitor.Workflow.RaiseChangeNotification(Settings.PithosPath); |
|
257 |
} |
|
258 |
#endregion |
|
259 |
|
|
260 |
private AccountSettings _currentAccount; |
|
261 |
public AccountSettings CurrentAccount |
|
262 |
{ |
|
263 |
get { return _currentAccount; } |
|
264 |
set |
|
265 |
{ |
|
266 |
_currentAccount = value; |
|
267 |
NotifyOfPropertyChange(()=>CurrentAccount); |
|
268 |
NotifyOfPropertyChange(()=>CanRemoveAccount); |
|
269 |
} |
|
270 |
} |
|
271 |
|
|
272 |
|
|
273 |
|
|
265 | 274 |
/* private void UnregisterExtensions() |
266 | 275 |
{ |
267 | 276 |
using (var installer = new ProjectInstaller()) |
Also available in: Unified diff