root / trunk / Pithos.Client.WPF / Preferences / PreferencesViewModel.cs @ 3ddbb7b8
History | View | Annotate | Download (13.7 kB)
1 | 9bae55d1 | Panagiotis Kanavos | // ----------------------------------------------------------------------- |
---|---|---|---|
2 | 9bae55d1 | Panagiotis Kanavos | // <copyright file="PreferencesViewModel.cs" company="Microsoft"> |
3 | 9bae55d1 | Panagiotis Kanavos | // TODO: Update copyright text. |
4 | 9bae55d1 | Panagiotis Kanavos | // </copyright> |
5 | 9bae55d1 | Panagiotis Kanavos | // ----------------------------------------------------------------------- |
6 | 9bae55d1 | Panagiotis Kanavos | |
7 | 7e26c075 | Panagiotis Kanavos | using System.Collections.Concurrent; |
8 | 9bae55d1 | Panagiotis Kanavos | using System.ComponentModel.Composition; |
9 | 9bae55d1 | Panagiotis Kanavos | using System.IO; |
10 | 0eea575a | Panagiotis Kanavos | using System.Reflection; |
11 | 9bae55d1 | Panagiotis Kanavos | using System.Windows; |
12 | 9bae55d1 | Panagiotis Kanavos | using System.Windows.Forms; |
13 | 9bae55d1 | Panagiotis Kanavos | using Caliburn.Micro; |
14 | 7e26c075 | Panagiotis Kanavos | using IWshRuntimeLibrary; |
15 | 9bae55d1 | Panagiotis Kanavos | using Pithos.Client.WPF.Configuration; |
16 | 77f3c897 | Panagiotis Kanavos | using Pithos.Client.WPF.Preferences; |
17 | d3a13891 | Panagiotis Kanavos | using Pithos.Client.WPF.SelectiveSynch; |
18 | 9bae55d1 | Panagiotis Kanavos | using Pithos.Core; |
19 | 9bae55d1 | Panagiotis Kanavos | using Pithos.Interfaces; |
20 | 7e26c075 | Panagiotis Kanavos | using File = System.IO.File; |
21 | 9bae55d1 | Panagiotis Kanavos | using Screen = Caliburn.Micro.Screen; |
22 | 9bae55d1 | Panagiotis Kanavos | |
23 | 9bae55d1 | Panagiotis Kanavos | namespace Pithos.Client.WPF |
24 | 9bae55d1 | Panagiotis Kanavos | { |
25 | 9bae55d1 | Panagiotis Kanavos | using System; |
26 | 9bae55d1 | Panagiotis Kanavos | using System.Linq; |
27 | 0c02aa65 | Panagiotis Kanavos | using System.Threading.Tasks; |
28 | 9bae55d1 | Panagiotis Kanavos | |
29 | 9bae55d1 | Panagiotis Kanavos | /// <summary> |
30 | 9bae55d1 | Panagiotis Kanavos | /// TODO: Update summary. |
31 | 9bae55d1 | Panagiotis Kanavos | /// </summary> |
32 | c53aa229 | Panagiotis Kanavos | [Export] |
33 | c53aa229 | Panagiotis Kanavos | public class PreferencesViewModel : Screen |
34 | 9bae55d1 | Panagiotis Kanavos | { |
35 | 0c02aa65 | Panagiotis Kanavos | private IEventAggregator _events; |
36 | 9bae55d1 | Panagiotis Kanavos | |
37 | 9bae55d1 | Panagiotis Kanavos | |
38 | 5120f3cb | Panagiotis Kanavos | private PithosSettings _settings; |
39 | 5120f3cb | Panagiotis Kanavos | public PithosSettings Settings |
40 | 5120f3cb | Panagiotis Kanavos | { |
41 | 5120f3cb | Panagiotis Kanavos | get { return _settings; } |
42 | 5120f3cb | Panagiotis Kanavos | set |
43 | 5120f3cb | Panagiotis Kanavos | { |
44 | 5120f3cb | Panagiotis Kanavos | _settings = value; |
45 | 5120f3cb | Panagiotis Kanavos | NotifyOfPropertyChange(()=>Settings); |
46 | 5120f3cb | Panagiotis Kanavos | } |
47 | 5120f3cb | Panagiotis Kanavos | } |
48 | 7e26c075 | Panagiotis Kanavos | |
49 | 7e26c075 | Panagiotis Kanavos | private ObservableConcurrentCollection<AccountSettings> _accounts; |
50 | 7e26c075 | Panagiotis Kanavos | public ObservableConcurrentCollection<AccountSettings> Accounts |
51 | 7e26c075 | Panagiotis Kanavos | { |
52 | 7e26c075 | Panagiotis Kanavos | get { return _accounts; } |
53 | 7e26c075 | Panagiotis Kanavos | set |
54 | 7e26c075 | Panagiotis Kanavos | { |
55 | 7e26c075 | Panagiotis Kanavos | _accounts = value; |
56 | 7e26c075 | Panagiotis Kanavos | NotifyOfPropertyChange(()=>Accounts); |
57 | 7e26c075 | Panagiotis Kanavos | } |
58 | 7e26c075 | Panagiotis Kanavos | } |
59 | c53aa229 | Panagiotis Kanavos | |
60 | 7e26c075 | Panagiotis Kanavos | public bool StartOnSystemStartup { get; set; } |
61 | 7e26c075 | Panagiotis Kanavos | |
62 | 7e26c075 | Panagiotis Kanavos | private static void CreateShortcut(string shortcutPath) |
63 | 7e26c075 | Panagiotis Kanavos | { |
64 | 7e26c075 | Panagiotis Kanavos | var wshShell = new WshShellClass(); |
65 | 7e26c075 | Panagiotis Kanavos | var shortcut = (IWshRuntimeLibrary.IWshShortcut) wshShell.CreateShortcut( |
66 | 7e26c075 | Panagiotis Kanavos | shortcutPath); |
67 | 7e26c075 | Panagiotis Kanavos | |
68 | 7e26c075 | Panagiotis Kanavos | var exePath = Assembly.GetExecutingAssembly().Location; |
69 | 7e26c075 | Panagiotis Kanavos | shortcut.TargetPath = exePath; |
70 | 7e26c075 | Panagiotis Kanavos | shortcut.WorkingDirectory = Path.GetDirectoryName(exePath); |
71 | 7e26c075 | Panagiotis Kanavos | shortcut.Description = "Pithos"; |
72 | 7e26c075 | Panagiotis Kanavos | shortcut.Save(); |
73 | 7e26c075 | Panagiotis Kanavos | } |
74 | 7e26c075 | Panagiotis Kanavos | |
75 | c53aa229 | Panagiotis Kanavos | public ShellViewModel Shell { get; set; } |
76 | 0c02aa65 | Panagiotis Kanavos | //ShellExtensionController _extensionController=new ShellExtensionController(); |
77 | d3a13891 | Panagiotis Kanavos | |
78 | d3a13891 | Panagiotis Kanavos | public PreferencesViewModel(IWindowManager windowManager, IEventAggregator events, ShellViewModel shell, PithosSettings settings) |
79 | 9bae55d1 | Panagiotis Kanavos | { |
80 | d3a13891 | Panagiotis Kanavos | _windowManager = windowManager; |
81 | 0c02aa65 | Panagiotis Kanavos | _events = events; |
82 | 0c02aa65 | Panagiotis Kanavos | |
83 | 9bae55d1 | Panagiotis Kanavos | DisplayName = "Pithos Preferences"; |
84 | c53aa229 | Panagiotis Kanavos | Shell = shell; |
85 | 5bcf6d70 | Panagiotis Kanavos | |
86 | 7e26c075 | Panagiotis Kanavos | Settings=settings; |
87 | 7e26c075 | Panagiotis Kanavos | Accounts = new ObservableConcurrentCollection<AccountSettings>(); |
88 | 7e26c075 | Panagiotis Kanavos | Accounts.AddFromEnumerable(settings.Accounts); |
89 | 7e26c075 | Panagiotis Kanavos | |
90 | 7e26c075 | Panagiotis Kanavos | var startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); |
91 | 7e26c075 | Panagiotis Kanavos | _shortcutPath = Path.Combine(startupPath, "Pithos.lnk"); |
92 | 9bae55d1 | Panagiotis Kanavos | |
93 | 9bae55d1 | Panagiotis Kanavos | |
94 | 7e26c075 | Panagiotis Kanavos | StartOnSystemStartup = File.Exists(_shortcutPath); |
95 | 7e26c075 | Panagiotis Kanavos | |
96 | 9bae55d1 | Panagiotis Kanavos | } |
97 | 0eea575a | Panagiotis Kanavos | |
98 | 9bae55d1 | Panagiotis Kanavos | |
99 | 5bcf6d70 | Panagiotis Kanavos | #region Preferences Properties |
100 | 9bae55d1 | Panagiotis Kanavos | |
101 | 5bcf6d70 | Panagiotis Kanavos | private bool _noProxy; |
102 | 5bcf6d70 | Panagiotis Kanavos | public bool NoProxy |
103 | 9bae55d1 | Panagiotis Kanavos | { |
104 | 5bcf6d70 | Panagiotis Kanavos | get { return _noProxy; } |
105 | 9bae55d1 | Panagiotis Kanavos | set |
106 | 9bae55d1 | Panagiotis Kanavos | { |
107 | 5bcf6d70 | Panagiotis Kanavos | _noProxy = value; |
108 | 5bcf6d70 | Panagiotis Kanavos | NotifyOfPropertyChange(()=>NoProxy); |
109 | 9bae55d1 | Panagiotis Kanavos | } |
110 | 9bae55d1 | Panagiotis Kanavos | } |
111 | 9bae55d1 | Panagiotis Kanavos | |
112 | 5bcf6d70 | Panagiotis Kanavos | |
113 | 5bcf6d70 | Panagiotis Kanavos | private bool _defaultProxy; |
114 | 5bcf6d70 | Panagiotis Kanavos | |
115 | 5bcf6d70 | Panagiotis Kanavos | public bool DefaultProxy |
116 | 9bae55d1 | Panagiotis Kanavos | { |
117 | 5bcf6d70 | Panagiotis Kanavos | get { return _defaultProxy; } |
118 | 9bae55d1 | Panagiotis Kanavos | set |
119 | 9bae55d1 | Panagiotis Kanavos | { |
120 | 5bcf6d70 | Panagiotis Kanavos | _defaultProxy = value; |
121 | 5bcf6d70 | Panagiotis Kanavos | NotifyOfPropertyChange(() => DefaultProxy); |
122 | 9bae55d1 | Panagiotis Kanavos | } |
123 | 9bae55d1 | Panagiotis Kanavos | } |
124 | 9bae55d1 | Panagiotis Kanavos | |
125 | 9bae55d1 | Panagiotis Kanavos | |
126 | 5bcf6d70 | Panagiotis Kanavos | private bool _manualProxy; |
127 | 9bae55d1 | Panagiotis Kanavos | |
128 | 5bcf6d70 | Panagiotis Kanavos | public bool ManualProxy |
129 | 9bae55d1 | Panagiotis Kanavos | { |
130 | 5bcf6d70 | Panagiotis Kanavos | get { return _manualProxy; } |
131 | 9bae55d1 | Panagiotis Kanavos | set |
132 | 9bae55d1 | Panagiotis Kanavos | { |
133 | 5bcf6d70 | Panagiotis Kanavos | _manualProxy = value; |
134 | 5bcf6d70 | Panagiotis Kanavos | NotifyOfPropertyChange(() => ManualProxy); |
135 | 9bae55d1 | Panagiotis Kanavos | } |
136 | 9bae55d1 | Panagiotis Kanavos | } |
137 | 9bae55d1 | Panagiotis Kanavos | #endregion |
138 | 9bae55d1 | Panagiotis Kanavos | |
139 | 5bcf6d70 | Panagiotis Kanavos | |
140 | 9bae55d1 | Panagiotis Kanavos | #region Commands |
141 | 9bae55d1 | Panagiotis Kanavos | |
142 | aba9e6d9 | Panagiotis Kanavos | public bool CanSelectiveSyncFolders |
143 | aba9e6d9 | Panagiotis Kanavos | { |
144 | aba9e6d9 | Panagiotis Kanavos | get { return CurrentAccount != null; } |
145 | aba9e6d9 | Panagiotis Kanavos | } |
146 | aba9e6d9 | Panagiotis Kanavos | |
147 | d3a13891 | Panagiotis Kanavos | public void SelectiveSyncFolders() |
148 | d3a13891 | Panagiotis Kanavos | { |
149 | 7e26c075 | Panagiotis Kanavos | var monitor = Shell.Monitors[CurrentAccount.AccountName]; |
150 | 7e26c075 | Panagiotis Kanavos | var folders=monitor.GetRootFolders(); |
151 | 7e26c075 | Panagiotis Kanavos | |
152 | 7e26c075 | Panagiotis Kanavos | var model = new SelectiveSynchViewModel(folders,_events,CurrentAccount); |
153 | d3a13891 | Panagiotis Kanavos | if (_windowManager.ShowDialog(model) == true) |
154 | d3a13891 | Panagiotis Kanavos | { |
155 | d3a13891 | Panagiotis Kanavos | |
156 | d3a13891 | Panagiotis Kanavos | } |
157 | d3a13891 | Panagiotis Kanavos | } |
158 | 0eea575a | Panagiotis Kanavos | |
159 | 9bae55d1 | Panagiotis Kanavos | public void SaveChanges() |
160 | 9bae55d1 | Panagiotis Kanavos | { |
161 | 9bae55d1 | Panagiotis Kanavos | DoSave(); |
162 | c53aa229 | Panagiotis Kanavos | TryClose(true); |
163 | 9bae55d1 | Panagiotis Kanavos | } |
164 | 9bae55d1 | Panagiotis Kanavos | |
165 | 9bae55d1 | Panagiotis Kanavos | public void RejectChanges() |
166 | 9bae55d1 | Panagiotis Kanavos | { |
167 | 9bae55d1 | Panagiotis Kanavos | Settings.Reload(); |
168 | c53aa229 | Panagiotis Kanavos | TryClose(false); |
169 | 9bae55d1 | Panagiotis Kanavos | } |
170 | 9bae55d1 | Panagiotis Kanavos | |
171 | 9bae55d1 | Panagiotis Kanavos | public void ApplyChanges() |
172 | 9bae55d1 | Panagiotis Kanavos | { |
173 | 9bae55d1 | Panagiotis Kanavos | DoSave(); |
174 | 9bae55d1 | Panagiotis Kanavos | } |
175 | 9bae55d1 | Panagiotis Kanavos | |
176 | 9bae55d1 | Panagiotis Kanavos | private void DoSave() |
177 | 9bae55d1 | Panagiotis Kanavos | { |
178 | 9bae55d1 | Panagiotis Kanavos | Settings.Save(); |
179 | 7e26c075 | Panagiotis Kanavos | SetStartupMode(); |
180 | 7e26c075 | Panagiotis Kanavos | |
181 | 7e26c075 | Panagiotis Kanavos | |
182 | c53aa229 | Panagiotis Kanavos | foreach (var account in Settings.Accounts) |
183 | 7e26c075 | Panagiotis Kanavos | { |
184 | c53aa229 | Panagiotis Kanavos | Shell.MonitorAccount(account); |
185 | c53aa229 | Panagiotis Kanavos | } |
186 | 153975d0 | Panagiotis Kanavos | |
187 | c53aa229 | Panagiotis Kanavos | NotifyOfPropertyChange(()=>Settings); |
188 | 9bae55d1 | Panagiotis Kanavos | } |
189 | 9bae55d1 | Panagiotis Kanavos | |
190 | 7e26c075 | Panagiotis Kanavos | private void SetStartupMode() |
191 | 7e26c075 | Panagiotis Kanavos | { |
192 | 7e26c075 | Panagiotis Kanavos | if (StartOnSystemStartup && !File.Exists(_shortcutPath)) |
193 | 7e26c075 | Panagiotis Kanavos | { |
194 | 7e26c075 | Panagiotis Kanavos | CreateShortcut(_shortcutPath); |
195 | 7e26c075 | Panagiotis Kanavos | } |
196 | 7e26c075 | Panagiotis Kanavos | else if (!StartOnSystemStartup && File.Exists(_shortcutPath)) |
197 | 7e26c075 | Panagiotis Kanavos | { |
198 | 7e26c075 | Panagiotis Kanavos | if (File.Exists(_shortcutPath)) |
199 | 7e26c075 | Panagiotis Kanavos | File.Delete(_shortcutPath); |
200 | 7e26c075 | Panagiotis Kanavos | } |
201 | 7e26c075 | Panagiotis Kanavos | } |
202 | 7e26c075 | Panagiotis Kanavos | |
203 | 7e26c075 | Panagiotis Kanavos | /* public void ChangePithosFolder() |
204 | 9bae55d1 | Panagiotis Kanavos | { |
205 | 9bae55d1 | Panagiotis Kanavos | var browser = new FolderBrowserDialog(); |
206 | 9bae55d1 | Panagiotis Kanavos | browser.SelectedPath = Settings.PithosPath; |
207 | 9bae55d1 | Panagiotis Kanavos | var result = browser.ShowDialog((IWin32Window)GetView()); |
208 | 9bae55d1 | Panagiotis Kanavos | if (result == DialogResult.OK) |
209 | 9bae55d1 | Panagiotis Kanavos | { |
210 | 9bae55d1 | Panagiotis Kanavos | var newPath = browser.SelectedPath; |
211 | 7e26c075 | Panagiotis Kanavos | var accountName = CurrentAccount.AccountName; |
212 | 7e26c075 | Panagiotis Kanavos | var monitor = Shell.Monitors[accountName]; |
213 | 7e26c075 | Panagiotis Kanavos | monitor.Stop(); |
214 | 7e26c075 | Panagiotis Kanavos | |
215 | 7e26c075 | Panagiotis Kanavos | Shell.Monitors.Remove(accountName); |
216 | 7e26c075 | Panagiotis Kanavos | |
217 | 9bae55d1 | Panagiotis Kanavos | Directory.Move(Settings.PithosPath, newPath); |
218 | 9bae55d1 | Panagiotis Kanavos | Settings.PithosPath = newPath; |
219 | 9bae55d1 | Panagiotis Kanavos | Settings.Save(); |
220 | 0eea575a | Panagiotis Kanavos | |
221 | 7e26c075 | Panagiotis Kanavos | Shell.MonitorAccount(CurrentAccount); |
222 | 7e26c075 | Panagiotis Kanavos | |
223 | 7e26c075 | Panagiotis Kanavos | NotifyOfPropertyChange(() => Settings); |
224 | 9bae55d1 | Panagiotis Kanavos | } |
225 | 9bae55d1 | Panagiotis Kanavos | } |
226 | 7e26c075 | Panagiotis Kanavos | */ |
227 | 0eea575a | Panagiotis Kanavos | public void AddAccount() |
228 | 77f3c897 | Panagiotis Kanavos | { |
229 | 77f3c897 | Panagiotis Kanavos | var wizard = new AddAccountViewModel(); |
230 | 77f3c897 | Panagiotis Kanavos | if (_windowManager.ShowDialog(wizard) == true) |
231 | 77f3c897 | Panagiotis Kanavos | { |
232 | 77f3c897 | Panagiotis Kanavos | var newAccount = new AccountSettings |
233 | 77f3c897 | Panagiotis Kanavos | { |
234 | 77f3c897 | Panagiotis Kanavos | AccountName = wizard.AccountName, |
235 | 77f3c897 | Panagiotis Kanavos | ApiKey=wizard.Token, |
236 | 77f3c897 | Panagiotis Kanavos | RootPath=wizard.AccountPath, |
237 | 3ddbb7b8 | Panagiotis Kanavos | IsActive=wizard.IsAccountActive, |
238 | 77f3c897 | Panagiotis Kanavos | UsePithos=true |
239 | 77f3c897 | Panagiotis Kanavos | }; |
240 | 77f3c897 | Panagiotis Kanavos | Settings.Accounts.Add(newAccount); |
241 | 77f3c897 | Panagiotis Kanavos | (Accounts as IProducerConsumerCollection<AccountSettings>).TryAdd(newAccount); |
242 | 77f3c897 | Panagiotis Kanavos | CurrentAccount = newAccount; |
243 | 77f3c897 | Panagiotis Kanavos | NotifyOfPropertyChange(() => Accounts); |
244 | 77f3c897 | Panagiotis Kanavos | NotifyOfPropertyChange(() => Settings); |
245 | 77f3c897 | Panagiotis Kanavos | } |
246 | 77f3c897 | Panagiotis Kanavos | |
247 | 77f3c897 | Panagiotis Kanavos | |
248 | 77f3c897 | Panagiotis Kanavos | |
249 | 77f3c897 | Panagiotis Kanavos | } |
250 | 9bae55d1 | Panagiotis Kanavos | |
251 | 437abfca | Panagiotis Kanavos | public async void AddPithosAccount() |
252 | 0c02aa65 | Panagiotis Kanavos | { |
253 | 20e9a378 | Panagiotis Kanavos | var credentials=await PithosAccount.RetrieveCredentialsAsync(Settings.PithosLoginUrl); |
254 | 437abfca | Panagiotis Kanavos | var account = Settings.Accounts.FirstOrDefault(act => act.AccountName == credentials.UserName); |
255 | 437abfca | Panagiotis Kanavos | if (account == null) |
256 | 437abfca | Panagiotis Kanavos | { |
257 | 437abfca | Panagiotis Kanavos | account=new AccountSettings{ |
258 | 437abfca | Panagiotis Kanavos | AccountName=credentials.UserName, |
259 | 437abfca | Panagiotis Kanavos | ApiKey=credentials.Password, |
260 | 437abfca | Panagiotis Kanavos | UsePithos=true |
261 | 437abfca | Panagiotis Kanavos | }; |
262 | 437abfca | Panagiotis Kanavos | Settings.Accounts.Add(account); |
263 | 437abfca | Panagiotis Kanavos | (Accounts as IProducerConsumerCollection<AccountSettings>).TryAdd(account); |
264 | 437abfca | Panagiotis Kanavos | } |
265 | 437abfca | Panagiotis Kanavos | else |
266 | 437abfca | Panagiotis Kanavos | { |
267 | 437abfca | Panagiotis Kanavos | account.ApiKey=credentials.Password; |
268 | 437abfca | Panagiotis Kanavos | } |
269 | 437abfca | Panagiotis Kanavos | //SelectedAccountIndex= Settings.Accounts.IndexOf(account); |
270 | 437abfca | Panagiotis Kanavos | CurrentAccount = account; |
271 | 437abfca | Panagiotis Kanavos | NotifyOfPropertyChange(() => Accounts); |
272 | 437abfca | Panagiotis Kanavos | NotifyOfPropertyChange(()=>Settings); |
273 | 0c02aa65 | Panagiotis Kanavos | } |
274 | 0c02aa65 | Panagiotis Kanavos | |
275 | 5bcf6d70 | Panagiotis Kanavos | public void RemoveAccount() |
276 | 5bcf6d70 | Panagiotis Kanavos | { |
277 | c53aa229 | Panagiotis Kanavos | var accountName = CurrentAccount.AccountName; |
278 | 7e26c075 | Panagiotis Kanavos | Settings.Accounts.Remove(CurrentAccount); |
279 | 7e26c075 | Panagiotis Kanavos | |
280 | 7e26c075 | Panagiotis Kanavos | Accounts.TryRemove(CurrentAccount); |
281 | 7e26c075 | Panagiotis Kanavos | |
282 | 7e26c075 | Panagiotis Kanavos | |
283 | 7e26c075 | Panagiotis Kanavos | CurrentAccount = null; |
284 | 7e26c075 | Panagiotis Kanavos | //Accounts = Settings.Accounts; |
285 | 7e26c075 | Panagiotis Kanavos | //Settings.Save(); |
286 | c53aa229 | Panagiotis Kanavos | Shell.RemoveMonitor(accountName); |
287 | 7e26c075 | Panagiotis Kanavos | |
288 | 0eea575a | Panagiotis Kanavos | //NotifyOfPropertyChange("Settings.Accounts"); |
289 | 5bcf6d70 | Panagiotis Kanavos | } |
290 | 9bae55d1 | Panagiotis Kanavos | |
291 | 5bcf6d70 | Panagiotis Kanavos | public bool CanRemoveAccount |
292 | 9bae55d1 | Panagiotis Kanavos | { |
293 | 5bcf6d70 | Panagiotis Kanavos | get { return (CurrentAccount != null); } |
294 | 5bcf6d70 | Panagiotis Kanavos | } |
295 | 9bae55d1 | Panagiotis Kanavos | |
296 | 9bae55d1 | Panagiotis Kanavos | |
297 | 9bae55d1 | Panagiotis Kanavos | |
298 | 9bae55d1 | Panagiotis Kanavos | public bool ExtensionsActivated |
299 | 9bae55d1 | Panagiotis Kanavos | { |
300 | 9bae55d1 | Panagiotis Kanavos | get { return Settings.ExtensionsActivated; } |
301 | 9bae55d1 | Panagiotis Kanavos | set |
302 | 9bae55d1 | Panagiotis Kanavos | { |
303 | 9bae55d1 | Panagiotis Kanavos | if (Settings.ExtensionsActivated == value) |
304 | 5bcf6d70 | Panagiotis Kanavos | return; |
305 | 5bcf6d70 | Panagiotis Kanavos | |
306 | 9bae55d1 | Panagiotis Kanavos | Settings.ExtensionsActivated = value; |
307 | 9bae55d1 | Panagiotis Kanavos | |
308 | aba9e6d9 | Panagiotis Kanavos | /* |
309 | aba9e6d9 | Panagiotis Kanavos | if (value) |
310 | aba9e6d9 | Panagiotis Kanavos | _extensionController.RegisterExtensions(); |
311 | aba9e6d9 | Panagiotis Kanavos | else |
312 | aba9e6d9 | Panagiotis Kanavos | { |
313 | aba9e6d9 | Panagiotis Kanavos | _extensionController.UnregisterExtensions(); |
314 | aba9e6d9 | Panagiotis Kanavos | } |
315 | aba9e6d9 | Panagiotis Kanavos | */ |
316 | 5bcf6d70 | Panagiotis Kanavos | NotifyOfPropertyChange(() => ExtensionsActivated); |
317 | 9bae55d1 | Panagiotis Kanavos | } |
318 | 9bae55d1 | Panagiotis Kanavos | } |
319 | 9bae55d1 | Panagiotis Kanavos | |
320 | c53aa229 | Panagiotis Kanavos | |
321 | 5bcf6d70 | Panagiotis Kanavos | #endregion |
322 | 5bcf6d70 | Panagiotis Kanavos | |
323 | 7e26c075 | Panagiotis Kanavos | /* private int _selectedAccountIndex; |
324 | 0eea575a | Panagiotis Kanavos | public int SelectedAccountIndex |
325 | 5bcf6d70 | Panagiotis Kanavos | { |
326 | 0eea575a | Panagiotis Kanavos | get { return _selectedAccountIndex; } |
327 | 5bcf6d70 | Panagiotis Kanavos | set |
328 | 5bcf6d70 | Panagiotis Kanavos | { |
329 | 153975d0 | Panagiotis Kanavos | //var accountCount=Settings.Accounts.Count; |
330 | 153975d0 | Panagiotis Kanavos | //if (accountCount == 0) |
331 | 153975d0 | Panagiotis Kanavos | // return; |
332 | 153975d0 | Panagiotis Kanavos | //if (0 <= value && value < accountCount) |
333 | 153975d0 | Panagiotis Kanavos | // _selectedAccountIndex = value; |
334 | 153975d0 | Panagiotis Kanavos | //else |
335 | 153975d0 | Panagiotis Kanavos | // _selectedAccountIndex = 0; |
336 | 0c02aa65 | Panagiotis Kanavos | _selectedAccountIndex = value; |
337 | 0eea575a | Panagiotis Kanavos | NotifyOfPropertyChange(() => CurrentAccount); |
338 | 0eea575a | Panagiotis Kanavos | NotifyOfPropertyChange(() => CanRemoveAccount); |
339 | 0eea575a | Panagiotis Kanavos | NotifyOfPropertyChange(()=>SelectedAccountIndex); |
340 | 5bcf6d70 | Panagiotis Kanavos | } |
341 | 7e26c075 | Panagiotis Kanavos | }*/ |
342 | 5bcf6d70 | Panagiotis Kanavos | |
343 | 0eea575a | Panagiotis Kanavos | private AccountSettings _currentAccount; |
344 | d3a13891 | Panagiotis Kanavos | private IWindowManager _windowManager; |
345 | 7e26c075 | Panagiotis Kanavos | private string _shortcutPath; |
346 | 7e26c075 | Panagiotis Kanavos | |
347 | d3a13891 | Panagiotis Kanavos | |
348 | 7e26c075 | Panagiotis Kanavos | |
349 | 7e26c075 | Panagiotis Kanavos | public AccountSettings CurrentAccount |
350 | 7e26c075 | Panagiotis Kanavos | { |
351 | 7e26c075 | Panagiotis Kanavos | get { return _currentAccount; } |
352 | 7e26c075 | Panagiotis Kanavos | set |
353 | 7e26c075 | Panagiotis Kanavos | { |
354 | 7e26c075 | Panagiotis Kanavos | _currentAccount = value; |
355 | 7e26c075 | Panagiotis Kanavos | NotifyOfPropertyChange(()=>CurrentAccount); |
356 | 7e26c075 | Panagiotis Kanavos | NotifyOfPropertyChange(() => CanRemoveAccount); |
357 | aba9e6d9 | Panagiotis Kanavos | NotifyOfPropertyChange(() => CanSelectiveSyncFolders); |
358 | aba9e6d9 | Panagiotis Kanavos | NotifyOfPropertyChange(() => CanMoveAccountFolder); |
359 | 7e26c075 | Panagiotis Kanavos | } |
360 | 7e26c075 | Panagiotis Kanavos | } |
361 | 7e26c075 | Panagiotis Kanavos | |
362 | 7e26c075 | Panagiotis Kanavos | /* |
363 | 0eea575a | Panagiotis Kanavos | public AccountSettings CurrentAccount |
364 | 9bae55d1 | Panagiotis Kanavos | { |
365 | 153975d0 | Panagiotis Kanavos | get { |
366 | 153975d0 | Panagiotis Kanavos | if (0 <= SelectedAccountIndex && SelectedAccountIndex < Settings.Accounts.Count) |
367 | 153975d0 | Panagiotis Kanavos | return Settings.Accounts[SelectedAccountIndex]; |
368 | 153975d0 | Panagiotis Kanavos | return null; |
369 | 153975d0 | Panagiotis Kanavos | } |
370 | 5120f3cb | Panagiotis Kanavos | |
371 | 9bae55d1 | Panagiotis Kanavos | } |
372 | 7e26c075 | Panagiotis Kanavos | */ |
373 | 9bae55d1 | Panagiotis Kanavos | |
374 | 9bae55d1 | Panagiotis Kanavos | |
375 | aba9e6d9 | Panagiotis Kanavos | public bool CanMoveAccountFolder |
376 | aba9e6d9 | Panagiotis Kanavos | { |
377 | aba9e6d9 | Panagiotis Kanavos | get { return CurrentAccount != null; } |
378 | aba9e6d9 | Panagiotis Kanavos | } |
379 | 5120f3cb | Panagiotis Kanavos | |
380 | 5120f3cb | Panagiotis Kanavos | public void MoveAccountFolder() |
381 | 5120f3cb | Panagiotis Kanavos | { |
382 | 5120f3cb | Panagiotis Kanavos | |
383 | 5120f3cb | Panagiotis Kanavos | using (var dlg = new FolderBrowserDialog()) |
384 | 5120f3cb | Panagiotis Kanavos | { |
385 | 5120f3cb | Panagiotis Kanavos | var currentFolder = CurrentAccount.RootPath; |
386 | 5120f3cb | Panagiotis Kanavos | dlg.SelectedPath = currentFolder; |
387 | 5120f3cb | Panagiotis Kanavos | //Ask the user to select a folder |
388 | 5120f3cb | Panagiotis Kanavos | //Note: We need a parent window here, which we retrieve with GetView |
389 | 5120f3cb | Panagiotis Kanavos | var view = (Window)GetView(); |
390 | 5120f3cb | Panagiotis Kanavos | if (DialogResult.OK != dlg.ShowDialog(new Wpf32Window(view))) |
391 | 5120f3cb | Panagiotis Kanavos | return; |
392 | 5120f3cb | Panagiotis Kanavos | |
393 | 5120f3cb | Panagiotis Kanavos | var newPath= dlg.SelectedPath; |
394 | 5120f3cb | Panagiotis Kanavos | //Find the account's monitor and stop it |
395 | 7e26c075 | Panagiotis Kanavos | PithosMonitor monitor; |
396 | 7e26c075 | Panagiotis Kanavos | if (Shell.Monitors.TryGetValue(CurrentAccount.AccountName, out monitor)) |
397 | 5120f3cb | Panagiotis Kanavos | { |
398 | 7e26c075 | Panagiotis Kanavos | monitor.Stop(); |
399 | 7e26c075 | Panagiotis Kanavos | |
400 | 7e26c075 | Panagiotis Kanavos | |
401 | 7e26c075 | Panagiotis Kanavos | var oldPath = monitor.RootPath; |
402 | 7e26c075 | Panagiotis Kanavos | //The old directory may not exist eg. if we create an account for the first time |
403 | 7e26c075 | Panagiotis Kanavos | if (Directory.Exists(oldPath)) |
404 | 7e26c075 | Panagiotis Kanavos | { |
405 | 7e26c075 | Panagiotis Kanavos | //If it does, do the move |
406 | 5a99309c | Panagiotis Kanavos | |
407 | 5a99309c | Panagiotis Kanavos | //Now Create all of the directories |
408 | 5a99309c | Panagiotis Kanavos | foreach (string dirPath in Directory.EnumerateDirectories(oldPath, "*", |
409 | 5a99309c | Panagiotis Kanavos | SearchOption.AllDirectories)) |
410 | 5a99309c | Panagiotis Kanavos | Directory.CreateDirectory(dirPath.Replace(oldPath, newPath)); |
411 | 5a99309c | Panagiotis Kanavos | |
412 | 5a99309c | Panagiotis Kanavos | //Copy all the files |
413 | 5a99309c | Panagiotis Kanavos | foreach (string newFilePath in Directory.EnumerateFiles(oldPath, "*.*", |
414 | 5a99309c | Panagiotis Kanavos | SearchOption.AllDirectories)) |
415 | 5a99309c | Panagiotis Kanavos | File.Copy(newFilePath, newFilePath.Replace(oldPath, newPath)); |
416 | 5a99309c | Panagiotis Kanavos | |
417 | 5a99309c | Panagiotis Kanavos | Directory.Delete(oldPath, true); |
418 | 5a99309c | Panagiotis Kanavos | |
419 | 7e26c075 | Panagiotis Kanavos | //We also need to change the path of the existing file states |
420 | 7e26c075 | Panagiotis Kanavos | if (monitor != null) |
421 | 7e26c075 | Panagiotis Kanavos | monitor.MoveFileStates(oldPath, newPath); |
422 | 7e26c075 | Panagiotis Kanavos | } |
423 | 5120f3cb | Panagiotis Kanavos | } |
424 | 5120f3cb | Panagiotis Kanavos | //Replace the old rootpath with the new |
425 | 5120f3cb | Panagiotis Kanavos | CurrentAccount.RootPath = newPath; |
426 | 5120f3cb | Panagiotis Kanavos | //TODO: This will save all settings changes. Too coarse grained, need to fix at a later date |
427 | 5120f3cb | Panagiotis Kanavos | Settings.Save(); |
428 | 5120f3cb | Panagiotis Kanavos | //And start the monitor on the new RootPath |
429 | 7e26c075 | Panagiotis Kanavos | if (monitor != null) |
430 | 7e26c075 | Panagiotis Kanavos | { |
431 | 7e26c075 | Panagiotis Kanavos | monitor.RootPath = newPath; |
432 | 7e26c075 | Panagiotis Kanavos | if (CurrentAccount.IsActive) |
433 | 7e26c075 | Panagiotis Kanavos | monitor.Start(); |
434 | 7e26c075 | Panagiotis Kanavos | } |
435 | 7e26c075 | Panagiotis Kanavos | else |
436 | 7e26c075 | Panagiotis Kanavos | Shell.MonitorAccount(CurrentAccount); |
437 | 5120f3cb | Panagiotis Kanavos | //Finally, notify that the Settings, CurrentAccount have changed |
438 | 5120f3cb | Panagiotis Kanavos | NotifyOfPropertyChange(() => CurrentAccount); |
439 | 5120f3cb | Panagiotis Kanavos | NotifyOfPropertyChange(() => Settings); |
440 | 5120f3cb | Panagiotis Kanavos | |
441 | 5120f3cb | Panagiotis Kanavos | } |
442 | 5120f3cb | Panagiotis Kanavos | } |
443 | 9bae55d1 | Panagiotis Kanavos | } |
444 | 9bae55d1 | Panagiotis Kanavos | } |