root / trunk / Pithos.Client.WPF / Preferences / PreferencesViewModel.cs @ f2d88248
History | View | Annotate | Download (16.2 kB)
1 | 255f5f86 | Panagiotis Kanavos | #region |
---|---|---|---|
2 | 255f5f86 | Panagiotis Kanavos | /* ----------------------------------------------------------------------- |
3 | 255f5f86 | Panagiotis Kanavos | * <copyright file="PreferencesViewModel.cs" company="GRNet"> |
4 | 255f5f86 | Panagiotis Kanavos | * |
5 | 255f5f86 | Panagiotis Kanavos | * Copyright 2011-2012 GRNET S.A. All rights reserved. |
6 | 255f5f86 | Panagiotis Kanavos | * |
7 | 255f5f86 | Panagiotis Kanavos | * Redistribution and use in source and binary forms, with or |
8 | 255f5f86 | Panagiotis Kanavos | * without modification, are permitted provided that the following |
9 | 255f5f86 | Panagiotis Kanavos | * conditions are met: |
10 | 255f5f86 | Panagiotis Kanavos | * |
11 | 255f5f86 | Panagiotis Kanavos | * 1. Redistributions of source code must retain the above |
12 | 255f5f86 | Panagiotis Kanavos | * copyright notice, this list of conditions and the following |
13 | 255f5f86 | Panagiotis Kanavos | * disclaimer. |
14 | 255f5f86 | Panagiotis Kanavos | * |
15 | 255f5f86 | Panagiotis Kanavos | * 2. Redistributions in binary form must reproduce the above |
16 | 255f5f86 | Panagiotis Kanavos | * copyright notice, this list of conditions and the following |
17 | 255f5f86 | Panagiotis Kanavos | * disclaimer in the documentation and/or other materials |
18 | 255f5f86 | Panagiotis Kanavos | * provided with the distribution. |
19 | 255f5f86 | Panagiotis Kanavos | * |
20 | 255f5f86 | Panagiotis Kanavos | * |
21 | 255f5f86 | Panagiotis Kanavos | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
22 | 255f5f86 | Panagiotis Kanavos | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
23 | 255f5f86 | Panagiotis Kanavos | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
24 | 255f5f86 | Panagiotis Kanavos | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
25 | 255f5f86 | Panagiotis Kanavos | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
26 | 255f5f86 | Panagiotis Kanavos | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
27 | 255f5f86 | Panagiotis Kanavos | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
28 | 255f5f86 | Panagiotis Kanavos | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
29 | 255f5f86 | Panagiotis Kanavos | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
30 | 255f5f86 | Panagiotis Kanavos | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
31 | 255f5f86 | Panagiotis Kanavos | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
32 | 255f5f86 | Panagiotis Kanavos | * POSSIBILITY OF SUCH DAMAGE. |
33 | 255f5f86 | Panagiotis Kanavos | * |
34 | 255f5f86 | Panagiotis Kanavos | * The views and conclusions contained in the software and |
35 | 255f5f86 | Panagiotis Kanavos | * documentation are those of the authors and should not be |
36 | 255f5f86 | Panagiotis Kanavos | * interpreted as representing official policies, either expressed |
37 | 255f5f86 | Panagiotis Kanavos | * or implied, of GRNET S.A. |
38 | 255f5f86 | Panagiotis Kanavos | * </copyright> |
39 | 255f5f86 | Panagiotis Kanavos | * ----------------------------------------------------------------------- |
40 | 255f5f86 | Panagiotis Kanavos | */ |
41 | 255f5f86 | Panagiotis Kanavos | #endregion |
42 | f3d080df | Panagiotis Kanavos | |
43 | 9bae55d1 | Panagiotis Kanavos | // </copyright> |
44 | 9bae55d1 | Panagiotis Kanavos | // ----------------------------------------------------------------------- |
45 | 9bae55d1 | Panagiotis Kanavos | |
46 | 7e26c075 | Panagiotis Kanavos | using System.Collections.Concurrent; |
47 | 9bae55d1 | Panagiotis Kanavos | using System.ComponentModel.Composition; |
48 | 9bae55d1 | Panagiotis Kanavos | using System.IO; |
49 | 29a6b387 | Panagiotis Kanavos | using System.Net; |
50 | 2e3aee00 | Panagiotis Kanavos | using System.Threading.Tasks; |
51 | 9bae55d1 | Panagiotis Kanavos | using System.Windows; |
52 | 9bae55d1 | Panagiotis Kanavos | using System.Windows.Forms; |
53 | 9bae55d1 | Panagiotis Kanavos | using Caliburn.Micro; |
54 | 9bae55d1 | Panagiotis Kanavos | using Pithos.Client.WPF.Configuration; |
55 | d3a13891 | Panagiotis Kanavos | using Pithos.Client.WPF.SelectiveSynch; |
56 | 9bae55d1 | Panagiotis Kanavos | using Pithos.Core; |
57 | 9bae55d1 | Panagiotis Kanavos | using Pithos.Interfaces; |
58 | 4d70073b | Panagiotis Kanavos | using System; |
59 | 4d70073b | Panagiotis Kanavos | using System.Linq; |
60 | 9bae55d1 | Panagiotis Kanavos | using Screen = Caliburn.Micro.Screen; |
61 | 9bae55d1 | Panagiotis Kanavos | |
62 | 4d70073b | Panagiotis Kanavos | namespace Pithos.Client.WPF.Preferences |
63 | 9bae55d1 | Panagiotis Kanavos | { |
64 | 9bae55d1 | Panagiotis Kanavos | /// <summary> |
65 | 9bae55d1 | Panagiotis Kanavos | /// TODO: Update summary. |
66 | 9bae55d1 | Panagiotis Kanavos | /// </summary> |
67 | c53aa229 | Panagiotis Kanavos | [Export] |
68 | c53aa229 | Panagiotis Kanavos | public class PreferencesViewModel : Screen |
69 | 9bae55d1 | Panagiotis Kanavos | { |
70 | 0c02aa65 | Panagiotis Kanavos | private IEventAggregator _events; |
71 | 9bae55d1 | Panagiotis Kanavos | |
72 | 9bae55d1 | Panagiotis Kanavos | |
73 | 5120f3cb | Panagiotis Kanavos | private PithosSettings _settings; |
74 | 5120f3cb | Panagiotis Kanavos | public PithosSettings Settings |
75 | 5120f3cb | Panagiotis Kanavos | { |
76 | 5120f3cb | Panagiotis Kanavos | get { return _settings; } |
77 | 5120f3cb | Panagiotis Kanavos | set |
78 | 5120f3cb | Panagiotis Kanavos | { |
79 | 5120f3cb | Panagiotis Kanavos | _settings = value; |
80 | 5120f3cb | Panagiotis Kanavos | NotifyOfPropertyChange(()=>Settings); |
81 | 5120f3cb | Panagiotis Kanavos | } |
82 | 5120f3cb | Panagiotis Kanavos | } |
83 | 7e26c075 | Panagiotis Kanavos | |
84 | 7e26c075 | Panagiotis Kanavos | private ObservableConcurrentCollection<AccountSettings> _accounts; |
85 | 7e26c075 | Panagiotis Kanavos | public ObservableConcurrentCollection<AccountSettings> Accounts |
86 | 7e26c075 | Panagiotis Kanavos | { |
87 | 7e26c075 | Panagiotis Kanavos | get { return _accounts; } |
88 | 7e26c075 | Panagiotis Kanavos | set |
89 | 7e26c075 | Panagiotis Kanavos | { |
90 | 7e26c075 | Panagiotis Kanavos | _accounts = value; |
91 | 7e26c075 | Panagiotis Kanavos | NotifyOfPropertyChange(()=>Accounts); |
92 | 7e26c075 | Panagiotis Kanavos | } |
93 | 7e26c075 | Panagiotis Kanavos | } |
94 | c53aa229 | Panagiotis Kanavos | |
95 | 7e26c075 | Panagiotis Kanavos | public bool StartOnSystemStartup { get; set; } |
96 | 7e26c075 | Panagiotis Kanavos | |
97 | c53aa229 | Panagiotis Kanavos | public ShellViewModel Shell { get; set; } |
98 | 0c02aa65 | Panagiotis Kanavos | //ShellExtensionController _extensionController=new ShellExtensionController(); |
99 | d3a13891 | Panagiotis Kanavos | |
100 | f2d88248 | Panagiotis Kanavos | public PreferencesViewModel(IWindowManager windowManager, IEventAggregator events, ShellViewModel shell, PithosSettings settings, string currentTab) |
101 | 9bae55d1 | Panagiotis Kanavos | { |
102 | d3a13891 | Panagiotis Kanavos | _windowManager = windowManager; |
103 | 0c02aa65 | Panagiotis Kanavos | _events = events; |
104 | 0c02aa65 | Panagiotis Kanavos | |
105 | 9bae55d1 | Panagiotis Kanavos | DisplayName = "Pithos Preferences"; |
106 | c53aa229 | Panagiotis Kanavos | Shell = shell; |
107 | f2d88248 | Panagiotis Kanavos | |
108 | 7e26c075 | Panagiotis Kanavos | Settings=settings; |
109 | 7e26c075 | Panagiotis Kanavos | Accounts = new ObservableConcurrentCollection<AccountSettings>(); |
110 | f734ab5b | Panagiotis Kanavos | if (settings.Accounts == null) |
111 | f734ab5b | Panagiotis Kanavos | { |
112 | f734ab5b | Panagiotis Kanavos | settings.Accounts=new AccountsCollection(); |
113 | f734ab5b | Panagiotis Kanavos | settings.Save(); |
114 | f734ab5b | Panagiotis Kanavos | } |
115 | 7e26c075 | Panagiotis Kanavos | Accounts.AddFromEnumerable(settings.Accounts); |
116 | 7e26c075 | Panagiotis Kanavos | |
117 | 7e26c075 | Panagiotis Kanavos | var startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); |
118 | 7e26c075 | Panagiotis Kanavos | _shortcutPath = Path.Combine(startupPath, "Pithos.lnk"); |
119 | 9bae55d1 | Panagiotis Kanavos | |
120 | 9bae55d1 | Panagiotis Kanavos | |
121 | 7e26c075 | Panagiotis Kanavos | StartOnSystemStartup = File.Exists(_shortcutPath); |
122 | 7e26c075 | Panagiotis Kanavos | |
123 | f2d88248 | Panagiotis Kanavos | SelectedTab = currentTab; |
124 | f2d88248 | Panagiotis Kanavos | } |
125 | f2d88248 | Panagiotis Kanavos | |
126 | f2d88248 | Panagiotis Kanavos | private string _selectedTab="General"; |
127 | f2d88248 | Panagiotis Kanavos | public string SelectedTab |
128 | f2d88248 | Panagiotis Kanavos | { |
129 | f2d88248 | Panagiotis Kanavos | get { return _selectedTab; } |
130 | f2d88248 | Panagiotis Kanavos | set |
131 | f2d88248 | Panagiotis Kanavos | { |
132 | f2d88248 | Panagiotis Kanavos | _selectedTab = value??"General"; |
133 | f2d88248 | Panagiotis Kanavos | NotifyOfPropertyChange(()=>SelectedTab); |
134 | f2d88248 | Panagiotis Kanavos | NotifyOfPropertyChange(() => AccountTabSelected); |
135 | f2d88248 | Panagiotis Kanavos | } |
136 | 9bae55d1 | Panagiotis Kanavos | } |
137 | 0eea575a | Panagiotis Kanavos | |
138 | 9bae55d1 | Panagiotis Kanavos | |
139 | f2d88248 | Panagiotis Kanavos | public bool AccountTabSelected |
140 | f2d88248 | Panagiotis Kanavos | { |
141 | f2d88248 | Panagiotis Kanavos | get { return _selectedTab == "AccountTab"; } |
142 | f2d88248 | Panagiotis Kanavos | } |
143 | 5bcf6d70 | Panagiotis Kanavos | #region Preferences Properties |
144 | 9bae55d1 | Panagiotis Kanavos | |
145 | 5bcf6d70 | Panagiotis Kanavos | private bool _noProxy; |
146 | 5bcf6d70 | Panagiotis Kanavos | public bool NoProxy |
147 | 9bae55d1 | Panagiotis Kanavos | { |
148 | 5bcf6d70 | Panagiotis Kanavos | get { return _noProxy; } |
149 | 9bae55d1 | Panagiotis Kanavos | set |
150 | 9bae55d1 | Panagiotis Kanavos | { |
151 | 5bcf6d70 | Panagiotis Kanavos | _noProxy = value; |
152 | 5bcf6d70 | Panagiotis Kanavos | NotifyOfPropertyChange(()=>NoProxy); |
153 | 9bae55d1 | Panagiotis Kanavos | } |
154 | 9bae55d1 | Panagiotis Kanavos | } |
155 | 9bae55d1 | Panagiotis Kanavos | |
156 | 5bcf6d70 | Panagiotis Kanavos | |
157 | 5bcf6d70 | Panagiotis Kanavos | private bool _defaultProxy; |
158 | 5bcf6d70 | Panagiotis Kanavos | |
159 | 5bcf6d70 | Panagiotis Kanavos | public bool DefaultProxy |
160 | 9bae55d1 | Panagiotis Kanavos | { |
161 | 5bcf6d70 | Panagiotis Kanavos | get { return _defaultProxy; } |
162 | 9bae55d1 | Panagiotis Kanavos | set |
163 | 9bae55d1 | Panagiotis Kanavos | { |
164 | 5bcf6d70 | Panagiotis Kanavos | _defaultProxy = value; |
165 | 5bcf6d70 | Panagiotis Kanavos | NotifyOfPropertyChange(() => DefaultProxy); |
166 | 9bae55d1 | Panagiotis Kanavos | } |
167 | 9bae55d1 | Panagiotis Kanavos | } |
168 | 9bae55d1 | Panagiotis Kanavos | |
169 | 9bae55d1 | Panagiotis Kanavos | |
170 | 5bcf6d70 | Panagiotis Kanavos | private bool _manualProxy; |
171 | 9bae55d1 | Panagiotis Kanavos | |
172 | 5bcf6d70 | Panagiotis Kanavos | public bool ManualProxy |
173 | 9bae55d1 | Panagiotis Kanavos | { |
174 | 5bcf6d70 | Panagiotis Kanavos | get { return _manualProxy; } |
175 | 9bae55d1 | Panagiotis Kanavos | set |
176 | 9bae55d1 | Panagiotis Kanavos | { |
177 | 5bcf6d70 | Panagiotis Kanavos | _manualProxy = value; |
178 | 5bcf6d70 | Panagiotis Kanavos | NotifyOfPropertyChange(() => ManualProxy); |
179 | 9bae55d1 | Panagiotis Kanavos | } |
180 | 9bae55d1 | Panagiotis Kanavos | } |
181 | 9bae55d1 | Panagiotis Kanavos | #endregion |
182 | 9bae55d1 | Panagiotis Kanavos | |
183 | 759bd3c4 | Panagiotis Kanavos | |
184 | 759bd3c4 | Panagiotis Kanavos | public int StartupDelay |
185 | 759bd3c4 | Panagiotis Kanavos | { |
186 | 759bd3c4 | Panagiotis Kanavos | get { return (int) Settings.StartupDelay.TotalMinutes; } |
187 | 759bd3c4 | Panagiotis Kanavos | set |
188 | 759bd3c4 | Panagiotis Kanavos | { |
189 | 759bd3c4 | Panagiotis Kanavos | if (value<0) |
190 | 759bd3c4 | Panagiotis Kanavos | throw new ArgumentOutOfRangeException("value","The Startup Delay must be greater or equal to 0"); |
191 | 759bd3c4 | Panagiotis Kanavos | Settings.StartupDelay = TimeSpan.FromMinutes(value); |
192 | 759bd3c4 | Panagiotis Kanavos | NotifyOfPropertyChange(()=>StartupDelay); |
193 | 759bd3c4 | Panagiotis Kanavos | } |
194 | 759bd3c4 | Panagiotis Kanavos | } |
195 | 5bcf6d70 | Panagiotis Kanavos | |
196 | 9bae55d1 | Panagiotis Kanavos | #region Commands |
197 | 9bae55d1 | Panagiotis Kanavos | |
198 | aba9e6d9 | Panagiotis Kanavos | public bool CanSelectiveSyncFolders |
199 | aba9e6d9 | Panagiotis Kanavos | { |
200 | aba9e6d9 | Panagiotis Kanavos | get { return CurrentAccount != null; } |
201 | aba9e6d9 | Panagiotis Kanavos | } |
202 | aba9e6d9 | Panagiotis Kanavos | |
203 | d3a13891 | Panagiotis Kanavos | public void SelectiveSyncFolders() |
204 | d3a13891 | Panagiotis Kanavos | { |
205 | 7e26c075 | Panagiotis Kanavos | var monitor = Shell.Monitors[CurrentAccount.AccountName]; |
206 | 759bd3c4 | Panagiotis Kanavos | |
207 | 7e26c075 | Panagiotis Kanavos | |
208 | 759bd3c4 | Panagiotis Kanavos | var model = new SelectiveSynchViewModel(monitor,_events,CurrentAccount); |
209 | d3a13891 | Panagiotis Kanavos | if (_windowManager.ShowDialog(model) == true) |
210 | d3a13891 | Panagiotis Kanavos | { |
211 | d3a13891 | Panagiotis Kanavos | |
212 | d3a13891 | Panagiotis Kanavos | } |
213 | d3a13891 | Panagiotis Kanavos | } |
214 | 2e3aee00 | Panagiotis Kanavos | |
215 | 2e3aee00 | Panagiotis Kanavos | public async Task RefreshApiKey() |
216 | 2e3aee00 | Panagiotis Kanavos | { |
217 | 2e3aee00 | Panagiotis Kanavos | await Shell.TryAuthorize(CurrentAccount.AccountName, 3); |
218 | 2e3aee00 | Panagiotis Kanavos | NotifyOfPropertyChange(()=>CurrentAccount); |
219 | 2e3aee00 | Panagiotis Kanavos | } |
220 | 0eea575a | Panagiotis Kanavos | |
221 | 9bae55d1 | Panagiotis Kanavos | public void SaveChanges() |
222 | 9bae55d1 | Panagiotis Kanavos | { |
223 | 9bae55d1 | Panagiotis Kanavos | DoSave(); |
224 | c53aa229 | Panagiotis Kanavos | TryClose(true); |
225 | 9bae55d1 | Panagiotis Kanavos | } |
226 | 9bae55d1 | Panagiotis Kanavos | |
227 | 9bae55d1 | Panagiotis Kanavos | public void RejectChanges() |
228 | 9bae55d1 | Panagiotis Kanavos | { |
229 | 9bae55d1 | Panagiotis Kanavos | Settings.Reload(); |
230 | c53aa229 | Panagiotis Kanavos | TryClose(false); |
231 | 9bae55d1 | Panagiotis Kanavos | } |
232 | 9bae55d1 | Panagiotis Kanavos | |
233 | 9bae55d1 | Panagiotis Kanavos | public void ApplyChanges() |
234 | 9bae55d1 | Panagiotis Kanavos | { |
235 | 9bae55d1 | Panagiotis Kanavos | DoSave(); |
236 | 9bae55d1 | Panagiotis Kanavos | } |
237 | 9bae55d1 | Panagiotis Kanavos | |
238 | 9bae55d1 | Panagiotis Kanavos | private void DoSave() |
239 | 9bae55d1 | Panagiotis Kanavos | { |
240 | 9bae55d1 | Panagiotis Kanavos | Settings.Save(); |
241 | 34bdb91d | Panagiotis Kanavos | //SetStartupMode(); |
242 | 7e26c075 | Panagiotis Kanavos | |
243 | c53aa229 | Panagiotis Kanavos | foreach (var account in Settings.Accounts) |
244 | 7e26c075 | Panagiotis Kanavos | { |
245 | c53aa229 | Panagiotis Kanavos | Shell.MonitorAccount(account); |
246 | c53aa229 | Panagiotis Kanavos | } |
247 | 153975d0 | Panagiotis Kanavos | |
248 | c53aa229 | Panagiotis Kanavos | NotifyOfPropertyChange(()=>Settings); |
249 | 9bae55d1 | Panagiotis Kanavos | } |
250 | 9bae55d1 | Panagiotis Kanavos | |
251 | 7e26c075 | Panagiotis Kanavos | /* public void ChangePithosFolder() |
252 | 9bae55d1 | Panagiotis Kanavos | { |
253 | 9bae55d1 | Panagiotis Kanavos | var browser = new FolderBrowserDialog(); |
254 | 9bae55d1 | Panagiotis Kanavos | browser.SelectedPath = Settings.PithosPath; |
255 | 9bae55d1 | Panagiotis Kanavos | var result = browser.ShowDialog((IWin32Window)GetView()); |
256 | 9bae55d1 | Panagiotis Kanavos | if (result == DialogResult.OK) |
257 | 9bae55d1 | Panagiotis Kanavos | { |
258 | 9bae55d1 | Panagiotis Kanavos | var newPath = browser.SelectedPath; |
259 | 7e26c075 | Panagiotis Kanavos | var accountName = CurrentAccount.AccountName; |
260 | 7e26c075 | Panagiotis Kanavos | var monitor = Shell.Monitors[accountName]; |
261 | 7e26c075 | Panagiotis Kanavos | monitor.Stop(); |
262 | 7e26c075 | Panagiotis Kanavos | |
263 | 7e26c075 | Panagiotis Kanavos | Shell.Monitors.Remove(accountName); |
264 | 7e26c075 | Panagiotis Kanavos | |
265 | 9bae55d1 | Panagiotis Kanavos | Directory.Move(Settings.PithosPath, newPath); |
266 | 9bae55d1 | Panagiotis Kanavos | Settings.PithosPath = newPath; |
267 | 9bae55d1 | Panagiotis Kanavos | Settings.Save(); |
268 | 0eea575a | Panagiotis Kanavos | |
269 | 7e26c075 | Panagiotis Kanavos | Shell.MonitorAccount(CurrentAccount); |
270 | 7e26c075 | Panagiotis Kanavos | |
271 | 7e26c075 | Panagiotis Kanavos | NotifyOfPropertyChange(() => Settings); |
272 | 9bae55d1 | Panagiotis Kanavos | } |
273 | 9bae55d1 | Panagiotis Kanavos | } |
274 | 7e26c075 | Panagiotis Kanavos | */ |
275 | 29a6b387 | Panagiotis Kanavos | |
276 | 34bdb91d | Panagiotis Kanavos | |
277 | 29a6b387 | Panagiotis Kanavos | |
278 | 0eea575a | Panagiotis Kanavos | public void AddAccount() |
279 | 77f3c897 | Panagiotis Kanavos | { |
280 | 34bdb91d | Panagiotis Kanavos | var wizard = new AddAccountViewModel(); |
281 | 77f3c897 | Panagiotis Kanavos | if (_windowManager.ShowDialog(wizard) == true) |
282 | 77f3c897 | Panagiotis Kanavos | { |
283 | 29a6b387 | Panagiotis Kanavos | string selectedPath = wizard.AccountPath; |
284 | 29a6b387 | Panagiotis Kanavos | var initialRootPath = Path.Combine(selectedPath, "Okeanos"); |
285 | 29a6b387 | Panagiotis Kanavos | var actualRootPath= initialRootPath; |
286 | 29a6b387 | Panagiotis Kanavos | int attempt = 1; |
287 | 29a6b387 | Panagiotis Kanavos | while (Directory.Exists(actualRootPath) || File.Exists(actualRootPath)) |
288 | 29a6b387 | Panagiotis Kanavos | { |
289 | 29a6b387 | Panagiotis Kanavos | actualRootPath = String.Format("{0} {1}", initialRootPath,attempt++); |
290 | 29a6b387 | Panagiotis Kanavos | } |
291 | 29a6b387 | Panagiotis Kanavos | |
292 | 77f3c897 | Panagiotis Kanavos | var newAccount = new AccountSettings |
293 | 77f3c897 | Panagiotis Kanavos | { |
294 | 77f3c897 | Panagiotis Kanavos | AccountName = wizard.AccountName, |
295 | 74d78c90 | Panagiotis Kanavos | ServerUrl=wizard.CurrentServer, |
296 | 77f3c897 | Panagiotis Kanavos | ApiKey=wizard.Token, |
297 | 29a6b387 | Panagiotis Kanavos | RootPath = actualRootPath, |
298 | 74d78c90 | Panagiotis Kanavos | IsActive=wizard.IsAccountActive |
299 | 77f3c897 | Panagiotis Kanavos | }; |
300 | 77f3c897 | Panagiotis Kanavos | Settings.Accounts.Add(newAccount); |
301 | 77f3c897 | Panagiotis Kanavos | (Accounts as IProducerConsumerCollection<AccountSettings>).TryAdd(newAccount); |
302 | 77f3c897 | Panagiotis Kanavos | CurrentAccount = newAccount; |
303 | 77f3c897 | Panagiotis Kanavos | NotifyOfPropertyChange(() => Accounts); |
304 | 77f3c897 | Panagiotis Kanavos | NotifyOfPropertyChange(() => Settings); |
305 | 77f3c897 | Panagiotis Kanavos | } |
306 | 77f3c897 | Panagiotis Kanavos | |
307 | 77f3c897 | Panagiotis Kanavos | |
308 | 77f3c897 | Panagiotis Kanavos | |
309 | 77f3c897 | Panagiotis Kanavos | } |
310 | 9bae55d1 | Panagiotis Kanavos | |
311 | 437abfca | Panagiotis Kanavos | public async void AddPithosAccount() |
312 | 0c02aa65 | Panagiotis Kanavos | { |
313 | 03ee454f | Panagiotis Kanavos | var credentials=await PithosAccount.RetrieveCredentials(Settings.PithosLoginUrl); |
314 | 437abfca | Panagiotis Kanavos | var account = Settings.Accounts.FirstOrDefault(act => act.AccountName == credentials.UserName); |
315 | 437abfca | Panagiotis Kanavos | if (account == null) |
316 | 437abfca | Panagiotis Kanavos | { |
317 | 437abfca | Panagiotis Kanavos | account=new AccountSettings{ |
318 | 437abfca | Panagiotis Kanavos | AccountName=credentials.UserName, |
319 | 74d78c90 | Panagiotis Kanavos | ApiKey=credentials.Password |
320 | 437abfca | Panagiotis Kanavos | }; |
321 | 437abfca | Panagiotis Kanavos | Settings.Accounts.Add(account); |
322 | 437abfca | Panagiotis Kanavos | (Accounts as IProducerConsumerCollection<AccountSettings>).TryAdd(account); |
323 | 437abfca | Panagiotis Kanavos | } |
324 | 437abfca | Panagiotis Kanavos | else |
325 | 437abfca | Panagiotis Kanavos | { |
326 | 437abfca | Panagiotis Kanavos | account.ApiKey=credentials.Password; |
327 | 437abfca | Panagiotis Kanavos | } |
328 | 437abfca | Panagiotis Kanavos | //SelectedAccountIndex= Settings.Accounts.IndexOf(account); |
329 | 437abfca | Panagiotis Kanavos | CurrentAccount = account; |
330 | 437abfca | Panagiotis Kanavos | NotifyOfPropertyChange(() => Accounts); |
331 | 437abfca | Panagiotis Kanavos | NotifyOfPropertyChange(()=>Settings); |
332 | 0c02aa65 | Panagiotis Kanavos | } |
333 | 0c02aa65 | Panagiotis Kanavos | |
334 | 5bcf6d70 | Panagiotis Kanavos | public void RemoveAccount() |
335 | 5bcf6d70 | Panagiotis Kanavos | { |
336 | c53aa229 | Panagiotis Kanavos | var accountName = CurrentAccount.AccountName; |
337 | 7e26c075 | Panagiotis Kanavos | Settings.Accounts.Remove(CurrentAccount); |
338 | 7e26c075 | Panagiotis Kanavos | |
339 | 7e26c075 | Panagiotis Kanavos | Accounts.TryRemove(CurrentAccount); |
340 | 7e26c075 | Panagiotis Kanavos | |
341 | 7e26c075 | Panagiotis Kanavos | |
342 | 7e26c075 | Panagiotis Kanavos | CurrentAccount = null; |
343 | 7e26c075 | Panagiotis Kanavos | //Accounts = Settings.Accounts; |
344 | 7e26c075 | Panagiotis Kanavos | //Settings.Save(); |
345 | c53aa229 | Panagiotis Kanavos | Shell.RemoveMonitor(accountName); |
346 | 6aa29f4f | Panagiotis Kanavos | NotifyOfPropertyChange(() => Accounts); |
347 | 6aa29f4f | Panagiotis Kanavos | NotifyOfPropertyChange(() => Settings); |
348 | 7e26c075 | Panagiotis Kanavos | |
349 | 0eea575a | Panagiotis Kanavos | //NotifyOfPropertyChange("Settings.Accounts"); |
350 | 5bcf6d70 | Panagiotis Kanavos | } |
351 | 9bae55d1 | Panagiotis Kanavos | |
352 | 5bcf6d70 | Panagiotis Kanavos | public bool CanRemoveAccount |
353 | 9bae55d1 | Panagiotis Kanavos | { |
354 | 5bcf6d70 | Panagiotis Kanavos | get { return (CurrentAccount != null); } |
355 | 5bcf6d70 | Panagiotis Kanavos | } |
356 | 9bae55d1 | Panagiotis Kanavos | |
357 | 9bae55d1 | Panagiotis Kanavos | |
358 | 9bae55d1 | Panagiotis Kanavos | |
359 | 9bae55d1 | Panagiotis Kanavos | public bool ExtensionsActivated |
360 | 9bae55d1 | Panagiotis Kanavos | { |
361 | 9bae55d1 | Panagiotis Kanavos | get { return Settings.ExtensionsActivated; } |
362 | 9bae55d1 | Panagiotis Kanavos | set |
363 | 9bae55d1 | Panagiotis Kanavos | { |
364 | 9bae55d1 | Panagiotis Kanavos | if (Settings.ExtensionsActivated == value) |
365 | 5bcf6d70 | Panagiotis Kanavos | return; |
366 | 5bcf6d70 | Panagiotis Kanavos | |
367 | 9bae55d1 | Panagiotis Kanavos | Settings.ExtensionsActivated = value; |
368 | 9bae55d1 | Panagiotis Kanavos | |
369 | aba9e6d9 | Panagiotis Kanavos | /* |
370 | aba9e6d9 | Panagiotis Kanavos | if (value) |
371 | aba9e6d9 | Panagiotis Kanavos | _extensionController.RegisterExtensions(); |
372 | aba9e6d9 | Panagiotis Kanavos | else |
373 | aba9e6d9 | Panagiotis Kanavos | { |
374 | aba9e6d9 | Panagiotis Kanavos | _extensionController.UnregisterExtensions(); |
375 | aba9e6d9 | Panagiotis Kanavos | } |
376 | aba9e6d9 | Panagiotis Kanavos | */ |
377 | 5bcf6d70 | Panagiotis Kanavos | NotifyOfPropertyChange(() => ExtensionsActivated); |
378 | 9bae55d1 | Panagiotis Kanavos | } |
379 | 9bae55d1 | Panagiotis Kanavos | } |
380 | 9bae55d1 | Panagiotis Kanavos | |
381 | c53aa229 | Panagiotis Kanavos | |
382 | 5bcf6d70 | Panagiotis Kanavos | #endregion |
383 | 5bcf6d70 | Panagiotis Kanavos | |
384 | 7e26c075 | Panagiotis Kanavos | /* private int _selectedAccountIndex; |
385 | 0eea575a | Panagiotis Kanavos | public int SelectedAccountIndex |
386 | 5bcf6d70 | Panagiotis Kanavos | { |
387 | 0eea575a | Panagiotis Kanavos | get { return _selectedAccountIndex; } |
388 | 5bcf6d70 | Panagiotis Kanavos | set |
389 | 5bcf6d70 | Panagiotis Kanavos | { |
390 | 153975d0 | Panagiotis Kanavos | //var accountCount=Settings.Accounts.Count; |
391 | 153975d0 | Panagiotis Kanavos | //if (accountCount == 0) |
392 | 153975d0 | Panagiotis Kanavos | // return; |
393 | 153975d0 | Panagiotis Kanavos | //if (0 <= value && value < accountCount) |
394 | 153975d0 | Panagiotis Kanavos | // _selectedAccountIndex = value; |
395 | 153975d0 | Panagiotis Kanavos | //else |
396 | 153975d0 | Panagiotis Kanavos | // _selectedAccountIndex = 0; |
397 | 0c02aa65 | Panagiotis Kanavos | _selectedAccountIndex = value; |
398 | 0eea575a | Panagiotis Kanavos | NotifyOfPropertyChange(() => CurrentAccount); |
399 | 0eea575a | Panagiotis Kanavos | NotifyOfPropertyChange(() => CanRemoveAccount); |
400 | 0eea575a | Panagiotis Kanavos | NotifyOfPropertyChange(()=>SelectedAccountIndex); |
401 | 5bcf6d70 | Panagiotis Kanavos | } |
402 | 7e26c075 | Panagiotis Kanavos | }*/ |
403 | 5bcf6d70 | Panagiotis Kanavos | |
404 | 0eea575a | Panagiotis Kanavos | private AccountSettings _currentAccount; |
405 | d3a13891 | Panagiotis Kanavos | private IWindowManager _windowManager; |
406 | 7e26c075 | Panagiotis Kanavos | private string _shortcutPath; |
407 | 7e26c075 | Panagiotis Kanavos | |
408 | d3a13891 | Panagiotis Kanavos | |
409 | 7e26c075 | Panagiotis Kanavos | |
410 | 7e26c075 | Panagiotis Kanavos | public AccountSettings CurrentAccount |
411 | 7e26c075 | Panagiotis Kanavos | { |
412 | 7e26c075 | Panagiotis Kanavos | get { return _currentAccount; } |
413 | 7e26c075 | Panagiotis Kanavos | set |
414 | 7e26c075 | Panagiotis Kanavos | { |
415 | 7e26c075 | Panagiotis Kanavos | _currentAccount = value; |
416 | 7e26c075 | Panagiotis Kanavos | NotifyOfPropertyChange(()=>CurrentAccount); |
417 | 7e26c075 | Panagiotis Kanavos | NotifyOfPropertyChange(() => CanRemoveAccount); |
418 | aba9e6d9 | Panagiotis Kanavos | NotifyOfPropertyChange(() => CanSelectiveSyncFolders); |
419 | aba9e6d9 | Panagiotis Kanavos | NotifyOfPropertyChange(() => CanMoveAccountFolder); |
420 | 7e26c075 | Panagiotis Kanavos | } |
421 | 7e26c075 | Panagiotis Kanavos | } |
422 | 7e26c075 | Panagiotis Kanavos | |
423 | 7e26c075 | Panagiotis Kanavos | /* |
424 | 0eea575a | Panagiotis Kanavos | public AccountSettings CurrentAccount |
425 | 9bae55d1 | Panagiotis Kanavos | { |
426 | 153975d0 | Panagiotis Kanavos | get { |
427 | 153975d0 | Panagiotis Kanavos | if (0 <= SelectedAccountIndex && SelectedAccountIndex < Settings.Accounts.Count) |
428 | 153975d0 | Panagiotis Kanavos | return Settings.Accounts[SelectedAccountIndex]; |
429 | 153975d0 | Panagiotis Kanavos | return null; |
430 | 153975d0 | Panagiotis Kanavos | } |
431 | 5120f3cb | Panagiotis Kanavos | |
432 | 9bae55d1 | Panagiotis Kanavos | } |
433 | 7e26c075 | Panagiotis Kanavos | */ |
434 | 9bae55d1 | Panagiotis Kanavos | |
435 | 9bae55d1 | Panagiotis Kanavos | |
436 | aba9e6d9 | Panagiotis Kanavos | public bool CanMoveAccountFolder |
437 | aba9e6d9 | Panagiotis Kanavos | { |
438 | aba9e6d9 | Panagiotis Kanavos | get { return CurrentAccount != null; } |
439 | aba9e6d9 | Panagiotis Kanavos | } |
440 | 5120f3cb | Panagiotis Kanavos | |
441 | 5120f3cb | Panagiotis Kanavos | public void MoveAccountFolder() |
442 | 5120f3cb | Panagiotis Kanavos | { |
443 | 5120f3cb | Panagiotis Kanavos | |
444 | 5120f3cb | Panagiotis Kanavos | using (var dlg = new FolderBrowserDialog()) |
445 | 5120f3cb | Panagiotis Kanavos | { |
446 | 5120f3cb | Panagiotis Kanavos | var currentFolder = CurrentAccount.RootPath; |
447 | 5120f3cb | Panagiotis Kanavos | dlg.SelectedPath = currentFolder; |
448 | 5120f3cb | Panagiotis Kanavos | //Ask the user to select a folder |
449 | 5120f3cb | Panagiotis Kanavos | //Note: We need a parent window here, which we retrieve with GetView |
450 | 5120f3cb | Panagiotis Kanavos | var view = (Window)GetView(); |
451 | 5120f3cb | Panagiotis Kanavos | if (DialogResult.OK != dlg.ShowDialog(new Wpf32Window(view))) |
452 | 5120f3cb | Panagiotis Kanavos | return; |
453 | 5120f3cb | Panagiotis Kanavos | |
454 | 5120f3cb | Panagiotis Kanavos | var newPath= dlg.SelectedPath; |
455 | 5120f3cb | Panagiotis Kanavos | //Find the account's monitor and stop it |
456 | 7e26c075 | Panagiotis Kanavos | PithosMonitor monitor; |
457 | 7e26c075 | Panagiotis Kanavos | if (Shell.Monitors.TryGetValue(CurrentAccount.AccountName, out monitor)) |
458 | 5120f3cb | Panagiotis Kanavos | { |
459 | 7e26c075 | Panagiotis Kanavos | monitor.Stop(); |
460 | 7e26c075 | Panagiotis Kanavos | |
461 | 7e26c075 | Panagiotis Kanavos | |
462 | 7e26c075 | Panagiotis Kanavos | var oldPath = monitor.RootPath; |
463 | 7e26c075 | Panagiotis Kanavos | //The old directory may not exist eg. if we create an account for the first time |
464 | 7e26c075 | Panagiotis Kanavos | if (Directory.Exists(oldPath)) |
465 | 7e26c075 | Panagiotis Kanavos | { |
466 | 7e26c075 | Panagiotis Kanavos | //If it does, do the move |
467 | 5a99309c | Panagiotis Kanavos | |
468 | 5a99309c | Panagiotis Kanavos | //Now Create all of the directories |
469 | 5a99309c | Panagiotis Kanavos | foreach (string dirPath in Directory.EnumerateDirectories(oldPath, "*", |
470 | 5a99309c | Panagiotis Kanavos | SearchOption.AllDirectories)) |
471 | 5a99309c | Panagiotis Kanavos | Directory.CreateDirectory(dirPath.Replace(oldPath, newPath)); |
472 | 5a99309c | Panagiotis Kanavos | |
473 | 5a99309c | Panagiotis Kanavos | //Copy all the files |
474 | 5a99309c | Panagiotis Kanavos | foreach (string newFilePath in Directory.EnumerateFiles(oldPath, "*.*", |
475 | 5a99309c | Panagiotis Kanavos | SearchOption.AllDirectories)) |
476 | 5a99309c | Panagiotis Kanavos | File.Copy(newFilePath, newFilePath.Replace(oldPath, newPath)); |
477 | 5a99309c | Panagiotis Kanavos | |
478 | 5a99309c | Panagiotis Kanavos | Directory.Delete(oldPath, true); |
479 | 5a99309c | Panagiotis Kanavos | |
480 | 7e26c075 | Panagiotis Kanavos | //We also need to change the path of the existing file states |
481 | 7e26c075 | Panagiotis Kanavos | if (monitor != null) |
482 | 7e26c075 | Panagiotis Kanavos | monitor.MoveFileStates(oldPath, newPath); |
483 | 7e26c075 | Panagiotis Kanavos | } |
484 | 5120f3cb | Panagiotis Kanavos | } |
485 | 5120f3cb | Panagiotis Kanavos | //Replace the old rootpath with the new |
486 | 5120f3cb | Panagiotis Kanavos | CurrentAccount.RootPath = newPath; |
487 | 5120f3cb | Panagiotis Kanavos | //TODO: This will save all settings changes. Too coarse grained, need to fix at a later date |
488 | 5120f3cb | Panagiotis Kanavos | Settings.Save(); |
489 | 5120f3cb | Panagiotis Kanavos | //And start the monitor on the new RootPath |
490 | 7e26c075 | Panagiotis Kanavos | if (monitor != null) |
491 | 7e26c075 | Panagiotis Kanavos | { |
492 | 7e26c075 | Panagiotis Kanavos | monitor.RootPath = newPath; |
493 | 7e26c075 | Panagiotis Kanavos | if (CurrentAccount.IsActive) |
494 | 7e26c075 | Panagiotis Kanavos | monitor.Start(); |
495 | 7e26c075 | Panagiotis Kanavos | } |
496 | 7e26c075 | Panagiotis Kanavos | else |
497 | 7e26c075 | Panagiotis Kanavos | Shell.MonitorAccount(CurrentAccount); |
498 | 5120f3cb | Panagiotis Kanavos | //Finally, notify that the Settings, CurrentAccount have changed |
499 | 5120f3cb | Panagiotis Kanavos | NotifyOfPropertyChange(() => CurrentAccount); |
500 | 5120f3cb | Panagiotis Kanavos | NotifyOfPropertyChange(() => Settings); |
501 | 5120f3cb | Panagiotis Kanavos | |
502 | 5120f3cb | Panagiotis Kanavos | } |
503 | 5120f3cb | Panagiotis Kanavos | } |
504 | 9bae55d1 | Panagiotis Kanavos | } |
505 | 9bae55d1 | Panagiotis Kanavos | } |