Statistics
| Branch: | Revision:

root / trunk / Pithos.Client.WPF / Preferences / PreferencesViewModel.cs @ 8f44fd3a

History | View | Annotate | Download (22.7 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
44 7e26c075 Panagiotis Kanavos
using System.Collections.Concurrent;
45 7f5882da Panagiotis Kanavos
using System.Collections.Generic;
46 9bae55d1 Panagiotis Kanavos
using System.ComponentModel.Composition;
47 31c97141 Panagiotis Kanavos
using System.Diagnostics;
48 9bae55d1 Panagiotis Kanavos
using System.IO;
49 e394ef0f pkanavos
using System.Net;
50 db8a9589 Panagiotis Kanavos
using System.Reflection;
51 2e3aee00 Panagiotis Kanavos
using System.Threading.Tasks;
52 9bae55d1 Panagiotis Kanavos
using System.Windows;
53 9bae55d1 Panagiotis Kanavos
using System.Windows.Forms;
54 9bae55d1 Panagiotis Kanavos
using Caliburn.Micro;
55 9bae55d1 Panagiotis Kanavos
using Pithos.Client.WPF.Configuration;
56 c636df1f Panagiotis Kanavos
using Pithos.Client.WPF.Properties;
57 d3a13891 Panagiotis Kanavos
using Pithos.Client.WPF.SelectiveSynch;
58 9bae55d1 Panagiotis Kanavos
using Pithos.Core;
59 9bae55d1 Panagiotis Kanavos
using Pithos.Interfaces;
60 4d70073b Panagiotis Kanavos
using System;
61 4d70073b Panagiotis Kanavos
using System.Linq;
62 311d1cde Panagiotis Kanavos
using MessageBox = System.Windows.MessageBox;
63 9bae55d1 Panagiotis Kanavos
using Screen = Caliburn.Micro.Screen;
64 9bae55d1 Panagiotis Kanavos
65 4d70073b Panagiotis Kanavos
namespace Pithos.Client.WPF.Preferences
66 9bae55d1 Panagiotis Kanavos
{
67 9bae55d1 Panagiotis Kanavos
    /// <summary>
68 c636df1f Panagiotis Kanavos
    /// The preferences screen displays user and account settings and updates the PithosMonitor
69 c636df1f Panagiotis Kanavos
    /// classes when account settings change.
70 9bae55d1 Panagiotis Kanavos
    /// </summary>
71 c636df1f Panagiotis Kanavos
    /// <remarks>
72 c636df1f Panagiotis Kanavos
    /// The class is a single ViewModel for all Preferences tabs. It can be broken in separate
73 c636df1f Panagiotis Kanavos
    /// ViewModels, one for each tab.
74 c636df1f Panagiotis Kanavos
    /// </remarks>
75 ebc37b0d pkanavos
    [Export, PartCreationPolicy(CreationPolicy.Shared)]
76 c53aa229 Panagiotis Kanavos
    public class PreferencesViewModel : Screen
77 9bae55d1 Panagiotis Kanavos
    {
78 c636df1f Panagiotis Kanavos
        private readonly IEventAggregator _events;
79 9bae55d1 Panagiotis Kanavos
80 31c97141 Panagiotis Kanavos
        //Logging in the Pithos client is provided by log4net
81 db8a9589 Panagiotis Kanavos
        private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
82 9bae55d1 Panagiotis Kanavos
83 5120f3cb Panagiotis Kanavos
        private PithosSettings _settings;
84 5120f3cb Panagiotis Kanavos
        public PithosSettings Settings
85 5120f3cb Panagiotis Kanavos
        {
86 5120f3cb Panagiotis Kanavos
            get { return _settings; }
87 5120f3cb Panagiotis Kanavos
            set
88 5120f3cb Panagiotis Kanavos
            {
89 5120f3cb Panagiotis Kanavos
                _settings = value;
90 5120f3cb Panagiotis Kanavos
                NotifyOfPropertyChange(()=>Settings);
91 5120f3cb Panagiotis Kanavos
            }
92 5120f3cb Panagiotis Kanavos
        }
93 7e26c075 Panagiotis Kanavos
94 31c97141 Panagiotis Kanavos
        private ObservableConcurrentCollection<AccountViewModel> _accounts;
95 31c97141 Panagiotis Kanavos
        public ObservableConcurrentCollection<AccountViewModel> Accounts
96 7e26c075 Panagiotis Kanavos
        {
97 7e26c075 Panagiotis Kanavos
            get { return _accounts; }
98 7e26c075 Panagiotis Kanavos
            set 
99 7e26c075 Panagiotis Kanavos
            { 
100 7e26c075 Panagiotis Kanavos
                _accounts = value;
101 7e26c075 Panagiotis Kanavos
                NotifyOfPropertyChange(()=>Accounts);
102 7e26c075 Panagiotis Kanavos
            }
103 7e26c075 Panagiotis Kanavos
        }
104 c53aa229 Panagiotis Kanavos
        
105 7e26c075 Panagiotis Kanavos
        public bool StartOnSystemStartup { get; set; }
106 7e26c075 Panagiotis Kanavos
107 c53aa229 Panagiotis Kanavos
        public ShellViewModel Shell { get;  set; }
108 0c02aa65 Panagiotis Kanavos
        //ShellExtensionController _extensionController=new ShellExtensionController();
109 d3a13891 Panagiotis Kanavos
110 f2d88248 Panagiotis Kanavos
        public PreferencesViewModel(IWindowManager windowManager, IEventAggregator events, ShellViewModel shell, PithosSettings settings, string currentTab)
111 9bae55d1 Panagiotis Kanavos
        {
112 c636df1f Panagiotis Kanavos
            // ReSharper disable DoNotCallOverridableMethodsInConstructor
113 c636df1f Panagiotis Kanavos
            //Caliburn.Micro uses DisplayName for the view's title
114 6b0de454 Panagiotis Kanavos
            DisplayName = "Pithos+ Preferences";
115 c636df1f Panagiotis Kanavos
            // ReSharper restore DoNotCallOverridableMethodsInConstructor
116 c636df1f Panagiotis Kanavos
117 d3a13891 Panagiotis Kanavos
            _windowManager = windowManager;
118 0c02aa65 Panagiotis Kanavos
            _events = events;
119 0c02aa65 Panagiotis Kanavos
120 c53aa229 Panagiotis Kanavos
            Shell = shell;
121 f2d88248 Panagiotis Kanavos
            
122 7e26c075 Panagiotis Kanavos
            Settings=settings;
123 31c97141 Panagiotis Kanavos
            Accounts = new ObservableConcurrentCollection<AccountViewModel>();
124 f734ab5b Panagiotis Kanavos
            if (settings.Accounts == null)
125 f734ab5b Panagiotis Kanavos
            {
126 f734ab5b Panagiotis Kanavos
                settings.Accounts=new AccountsCollection();
127 f734ab5b Panagiotis Kanavos
                settings.Save();
128 f734ab5b Panagiotis Kanavos
            }
129 31c97141 Panagiotis Kanavos
            var accountVMs = from account in settings.Accounts
130 31c97141 Panagiotis Kanavos
                             select new AccountViewModel(account);
131 31c97141 Panagiotis Kanavos
132 31c97141 Panagiotis Kanavos
            Accounts.AddFromEnumerable(accountVMs);
133 7e26c075 Panagiotis Kanavos
            
134 7e26c075 Panagiotis Kanavos
            var startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
135 7e26c075 Panagiotis Kanavos
            _shortcutPath = Path.Combine(startupPath, "Pithos.lnk");
136 9bae55d1 Panagiotis Kanavos
137 9bae55d1 Panagiotis Kanavos
138 7e26c075 Panagiotis Kanavos
            StartOnSystemStartup = File.Exists(_shortcutPath);
139 7e26c075 Panagiotis Kanavos
140 f2d88248 Panagiotis Kanavos
            SelectedTab = currentTab;
141 f2d88248 Panagiotis Kanavos
        }
142 f2d88248 Panagiotis Kanavos
143 f2d88248 Panagiotis Kanavos
        private string _selectedTab="General";
144 f2d88248 Panagiotis Kanavos
        public string SelectedTab
145 f2d88248 Panagiotis Kanavos
        {
146 f2d88248 Panagiotis Kanavos
            get { return _selectedTab; }
147 f2d88248 Panagiotis Kanavos
            set
148 f2d88248 Panagiotis Kanavos
            {
149 f2d88248 Panagiotis Kanavos
                _selectedTab = value??"General";
150 f2d88248 Panagiotis Kanavos
                NotifyOfPropertyChange(()=>SelectedTab);
151 f2d88248 Panagiotis Kanavos
                NotifyOfPropertyChange(() => AccountTabSelected);
152 f2d88248 Panagiotis Kanavos
            }
153 9bae55d1 Panagiotis Kanavos
        }
154 0eea575a Panagiotis Kanavos
155 9bae55d1 Panagiotis Kanavos
156 f2d88248 Panagiotis Kanavos
        public bool AccountTabSelected
157 f2d88248 Panagiotis Kanavos
        {
158 f2d88248 Panagiotis Kanavos
            get { return _selectedTab == "AccountTab"; }
159 f2d88248 Panagiotis Kanavos
        }
160 5bcf6d70 Panagiotis Kanavos
        #region Preferences Properties
161 9bae55d1 Panagiotis Kanavos
162 5bcf6d70 Panagiotis Kanavos
        private bool _noProxy;
163 5bcf6d70 Panagiotis Kanavos
        public bool NoProxy
164 9bae55d1 Panagiotis Kanavos
        {
165 5bcf6d70 Panagiotis Kanavos
            get { return _noProxy; }
166 9bae55d1 Panagiotis Kanavos
            set
167 9bae55d1 Panagiotis Kanavos
            {
168 5bcf6d70 Panagiotis Kanavos
                _noProxy = value;
169 5bcf6d70 Panagiotis Kanavos
                NotifyOfPropertyChange(()=>NoProxy);
170 9bae55d1 Panagiotis Kanavos
            }
171 9bae55d1 Panagiotis Kanavos
        }
172 9bae55d1 Panagiotis Kanavos
173 5bcf6d70 Panagiotis Kanavos
174 5bcf6d70 Panagiotis Kanavos
        private bool _defaultProxy;
175 5bcf6d70 Panagiotis Kanavos
176 5bcf6d70 Panagiotis Kanavos
        public bool DefaultProxy
177 9bae55d1 Panagiotis Kanavos
        {
178 5bcf6d70 Panagiotis Kanavos
            get { return _defaultProxy; }
179 9bae55d1 Panagiotis Kanavos
            set
180 9bae55d1 Panagiotis Kanavos
            {
181 5bcf6d70 Panagiotis Kanavos
                _defaultProxy = value;
182 5bcf6d70 Panagiotis Kanavos
                NotifyOfPropertyChange(() => DefaultProxy);
183 9bae55d1 Panagiotis Kanavos
            }
184 9bae55d1 Panagiotis Kanavos
        }
185 9bae55d1 Panagiotis Kanavos
186 9bae55d1 Panagiotis Kanavos
187 5bcf6d70 Panagiotis Kanavos
        private bool _manualProxy;
188 9bae55d1 Panagiotis Kanavos
189 5bcf6d70 Panagiotis Kanavos
        public bool ManualProxy
190 9bae55d1 Panagiotis Kanavos
        {
191 5bcf6d70 Panagiotis Kanavos
            get { return _manualProxy; }
192 9bae55d1 Panagiotis Kanavos
            set
193 9bae55d1 Panagiotis Kanavos
            {
194 5bcf6d70 Panagiotis Kanavos
                _manualProxy = value;
195 5bcf6d70 Panagiotis Kanavos
                NotifyOfPropertyChange(() => ManualProxy);
196 9bae55d1 Panagiotis Kanavos
            }
197 9bae55d1 Panagiotis Kanavos
        }
198 9bae55d1 Panagiotis Kanavos
        #endregion
199 9bae55d1 Panagiotis Kanavos
200 759bd3c4 Panagiotis Kanavos
201 759bd3c4 Panagiotis Kanavos
        public int StartupDelay
202 759bd3c4 Panagiotis Kanavos
        {
203 759bd3c4 Panagiotis Kanavos
            get { return (int) Settings.StartupDelay.TotalMinutes; }
204 759bd3c4 Panagiotis Kanavos
            set
205 759bd3c4 Panagiotis Kanavos
            {
206 759bd3c4 Panagiotis Kanavos
                if (value<0)
207 c636df1f Panagiotis Kanavos
                    throw new ArgumentOutOfRangeException("value",Resources.PreferencesViewModel_StartupDelay_Greater_or_equal_to_0);
208 759bd3c4 Panagiotis Kanavos
                Settings.StartupDelay = TimeSpan.FromMinutes(value);
209 759bd3c4 Panagiotis Kanavos
                NotifyOfPropertyChange(()=>StartupDelay);
210 759bd3c4 Panagiotis Kanavos
            }
211 759bd3c4 Panagiotis Kanavos
        }
212 5bcf6d70 Panagiotis Kanavos
       
213 9bae55d1 Panagiotis Kanavos
        #region Commands
214 9bae55d1 Panagiotis Kanavos
        
215 aba9e6d9 Panagiotis Kanavos
        public bool CanSelectiveSyncFolders
216 aba9e6d9 Panagiotis Kanavos
        {
217 aba9e6d9 Panagiotis Kanavos
            get { return CurrentAccount != null; }
218 aba9e6d9 Panagiotis Kanavos
        }
219 aba9e6d9 Panagiotis Kanavos
220 d3a13891 Panagiotis Kanavos
        public void SelectiveSyncFolders()
221 d3a13891 Panagiotis Kanavos
        {
222 8f44fd3a pkanavos
            //var monitor = Shell.Monitors[CurrentAccount.AccountKey];
223 759bd3c4 Panagiotis Kanavos
            
224 7e26c075 Panagiotis Kanavos
225 8f44fd3a pkanavos
            var model = new SelectiveSynchViewModel(/*monitor,*/_events,CurrentAccount.Account,CurrentAccount.ApiKey);
226 d3a13891 Panagiotis Kanavos
            if (_windowManager.ShowDialog(model) == true)
227 d3a13891 Panagiotis Kanavos
            {
228 d3a13891 Panagiotis Kanavos
                
229 d3a13891 Panagiotis Kanavos
            }
230 d3a13891 Panagiotis Kanavos
        }
231 2e3aee00 Panagiotis Kanavos
232 badcef63 Panagiotis Kanavos
        public void RefreshApiKey()
233 31c97141 Panagiotis Kanavos
        {
234 badcef63 Panagiotis Kanavos
            //_events.Publish(new Notification { Title = "Authorization failed", Message = "Your API Key has probably expired. You will be directed to a page where you can renew it", Level = TraceLevel.Error });
235 81c5c310 pkanavos
            if (CurrentAccount == null)
236 81c5c310 pkanavos
                return;
237 31c97141 Panagiotis Kanavos
            try
238 31c97141 Panagiotis Kanavos
            {
239 31c97141 Panagiotis Kanavos
240 81c5c310 pkanavos
                var name = CurrentAccount.AccountName;
241 81c5c310 pkanavos
242 81c5c310 pkanavos
                var loginUri = new Uri(new Uri(CurrentAccount.ServerUrl), "login");
243 81c5c310 pkanavos
                var credentials = PithosAccount.RetrieveCredentials(loginUri.ToString(),name);
244 badcef63 Panagiotis Kanavos
                if (credentials==null)
245 badcef63 Panagiotis Kanavos
                    return;
246 c636df1f Panagiotis Kanavos
                //The server will return credentials for a different account, not just the current account
247 c636df1f Panagiotis Kanavos
                //We need to find the correct account first
248 311d1cde Panagiotis Kanavos
                var account = Accounts.First(act => act.AccountName == credentials.UserName && act.ServerUrl == CurrentAccount.ServerUrl);
249 c636df1f Panagiotis Kanavos
                account.ApiKey = credentials.Password;                
250 31c97141 Panagiotis Kanavos
                account.IsExpired = false;
251 31c97141 Panagiotis Kanavos
                Settings.Save();
252 31c97141 Panagiotis Kanavos
                TaskEx.Delay(10000).ContinueWith(_ =>Shell.MonitorAccount(account.Account));
253 31c97141 Panagiotis Kanavos
                NotifyOfPropertyChange(() => Accounts);
254 31c97141 Panagiotis Kanavos
            }
255 31c97141 Panagiotis Kanavos
            catch (AggregateException exc)
256 31c97141 Panagiotis Kanavos
            {
257 31c97141 Panagiotis Kanavos
                string message = String.Format("API Key retrieval failed");
258 31c97141 Panagiotis Kanavos
                Log.Error(message, exc.InnerException);
259 31c97141 Panagiotis Kanavos
                _events.Publish(new Notification { Title = "Authorization failed", Message = message, Level = TraceLevel.Error });
260 31c97141 Panagiotis Kanavos
            }
261 31c97141 Panagiotis Kanavos
            catch (Exception exc)
262 31c97141 Panagiotis Kanavos
            {
263 31c97141 Panagiotis Kanavos
                string message = String.Format("API Key retrieval failed");
264 31c97141 Panagiotis Kanavos
                Log.Error(message, exc);
265 31c97141 Panagiotis Kanavos
                _events.Publish(new Notification { Title = "Authorization failed", Message = message, Level = TraceLevel.Error });
266 31c97141 Panagiotis Kanavos
            }
267 31c97141 Panagiotis Kanavos
268 2e3aee00 Panagiotis Kanavos
        }
269 31c97141 Panagiotis Kanavos
270 0eea575a Panagiotis Kanavos
    
271 db8a9589 Panagiotis Kanavos
        public void OpenLogPath()
272 db8a9589 Panagiotis Kanavos
        {
273 db8a9589 Panagiotis Kanavos
            Shell.OpenLogPath();
274 db8a9589 Panagiotis Kanavos
        }
275 6f03d6e1 Panagiotis Kanavos
276 6f03d6e1 Panagiotis Kanavos
        public void OpenLogConsole()
277 6f03d6e1 Panagiotis Kanavos
        {
278 6f03d6e1 Panagiotis Kanavos
            var logView=IoC.Get<LogConsole.LogConsoleViewModel>();            
279 6f03d6e1 Panagiotis Kanavos
            _windowManager.ShowWindow(logView);
280 6f03d6e1 Panagiotis Kanavos
        }
281 6f03d6e1 Panagiotis Kanavos
282 9bae55d1 Panagiotis Kanavos
        public void SaveChanges()
283 9bae55d1 Panagiotis Kanavos
        {
284 9bae55d1 Panagiotis Kanavos
            DoSave();
285 c53aa229 Panagiotis Kanavos
            TryClose(true);
286 9bae55d1 Panagiotis Kanavos
        }
287 9bae55d1 Panagiotis Kanavos
288 9bae55d1 Panagiotis Kanavos
        public void RejectChanges()
289 9bae55d1 Panagiotis Kanavos
        {
290 9bae55d1 Panagiotis Kanavos
            Settings.Reload();
291 c53aa229 Panagiotis Kanavos
            TryClose(false);
292 9bae55d1 Panagiotis Kanavos
        }
293 9bae55d1 Panagiotis Kanavos
294 9bae55d1 Panagiotis Kanavos
        public void ApplyChanges()
295 9bae55d1 Panagiotis Kanavos
        {
296 9bae55d1 Panagiotis Kanavos
            DoSave();
297 9bae55d1 Panagiotis Kanavos
        }
298 9bae55d1 Panagiotis Kanavos
299 9bae55d1 Panagiotis Kanavos
        private void DoSave()
300 9bae55d1 Panagiotis Kanavos
        {
301 34bdb91d Panagiotis Kanavos
            //SetStartupMode();            
302 7e26c075 Panagiotis Kanavos
303 8e89b160 Panagiotis Kanavos
            //Ensure we save the settings changes first
304 7f5882da Panagiotis Kanavos
            foreach (var account in _accountsToRemove)
305 7f5882da Panagiotis Kanavos
            {
306 7f5882da Panagiotis Kanavos
                Settings.Accounts.Remove(account);
307 8e89b160 Panagiotis Kanavos
            }
308 8e89b160 Panagiotis Kanavos
309 8e89b160 Panagiotis Kanavos
            foreach (var account in _accountsToAdd)
310 8e89b160 Panagiotis Kanavos
            {
311 8e89b160 Panagiotis Kanavos
                Settings.Accounts.Add(account);    
312 8e89b160 Panagiotis Kanavos
            }
313 e9eab066 Panagiotis Kanavos
314 8e89b160 Panagiotis Kanavos
            Settings.Save();
315 8e89b160 Panagiotis Kanavos
316 8e89b160 Panagiotis Kanavos
317 e9eab066 Panagiotis Kanavos
            try
318 8e89b160 Panagiotis Kanavos
            {
319 e9eab066 Panagiotis Kanavos
                foreach (var account in _accountsToRemove)
320 e9eab066 Panagiotis Kanavos
                {
321 ebc37b0d pkanavos
                    Shell.RemoveMonitor(account.ServerUrl, account.AccountName);
322 e9eab066 Panagiotis Kanavos
                    Shell.RemoveAccountFromDatabase(account);
323 e9eab066 Panagiotis Kanavos
                }
324 e9eab066 Panagiotis Kanavos
325 e9eab066 Panagiotis Kanavos
                foreach (var account in Settings.Accounts)
326 e9eab066 Panagiotis Kanavos
                {
327 e9eab066 Panagiotis Kanavos
                    Shell.MonitorAccount(account);
328 e9eab066 Panagiotis Kanavos
                }
329 e9eab066 Panagiotis Kanavos
            }                
330 e9eab066 Panagiotis Kanavos
            finally
331 e9eab066 Panagiotis Kanavos
            {
332 e9eab066 Panagiotis Kanavos
                _accountsToRemove.Clear();
333 e9eab066 Panagiotis Kanavos
                _accountsToAdd.Clear();
334 c53aa229 Panagiotis Kanavos
            }
335 153975d0 Panagiotis Kanavos
336 c53aa229 Panagiotis Kanavos
            NotifyOfPropertyChange(()=>Settings);
337 e394ef0f pkanavos
338 e394ef0f pkanavos
            if (IgnoreCertificateErrors)
339 e394ef0f pkanavos
                ServicePointManager.ServerCertificateValidationCallback= (sender,certificate,chain,errors)=> true;
340 e394ef0f pkanavos
            else
341 e394ef0f pkanavos
            {
342 e394ef0f pkanavos
                ServicePointManager.ServerCertificateValidationCallback = null;
343 e394ef0f pkanavos
            }
344 9bae55d1 Panagiotis Kanavos
        }
345 9bae55d1 Panagiotis Kanavos
346 7e26c075 Panagiotis Kanavos
     /*   public void ChangePithosFolder()
347 9bae55d1 Panagiotis Kanavos
        {
348 9bae55d1 Panagiotis Kanavos
            var browser = new FolderBrowserDialog();
349 9bae55d1 Panagiotis Kanavos
            browser.SelectedPath = Settings.PithosPath;
350 9bae55d1 Panagiotis Kanavos
            var result = browser.ShowDialog((IWin32Window)GetView());
351 9bae55d1 Panagiotis Kanavos
            if (result == DialogResult.OK)
352 9bae55d1 Panagiotis Kanavos
            {
353 9bae55d1 Panagiotis Kanavos
                var newPath = browser.SelectedPath;
354 7e26c075 Panagiotis Kanavos
                var accountName = CurrentAccount.AccountName;
355 7e26c075 Panagiotis Kanavos
                var monitor = Shell.Monitors[accountName];
356 7e26c075 Panagiotis Kanavos
                monitor.Stop();
357 7e26c075 Panagiotis Kanavos
                
358 7e26c075 Panagiotis Kanavos
                Shell.Monitors.Remove(accountName);
359 7e26c075 Panagiotis Kanavos
360 9bae55d1 Panagiotis Kanavos
                Directory.Move(Settings.PithosPath, newPath);
361 9bae55d1 Panagiotis Kanavos
                Settings.PithosPath = newPath;
362 9bae55d1 Panagiotis Kanavos
                Settings.Save();
363 0eea575a Panagiotis Kanavos
364 7e26c075 Panagiotis Kanavos
                Shell.MonitorAccount(CurrentAccount);
365 7e26c075 Panagiotis Kanavos
366 7e26c075 Panagiotis Kanavos
                NotifyOfPropertyChange(() => Settings);                
367 9bae55d1 Panagiotis Kanavos
            }
368 9bae55d1 Panagiotis Kanavos
        }
369 7e26c075 Panagiotis Kanavos
*/
370 29a6b387 Panagiotis Kanavos
371 29a6b387 Panagiotis Kanavos
372 8e89b160 Panagiotis Kanavos
        readonly List<AccountSettings> _accountsToAdd=new List<AccountSettings>();
373 0eea575a Panagiotis Kanavos
       public void AddAccount()
374 77f3c897 Panagiotis Kanavos
       {
375 34bdb91d Panagiotis Kanavos
           var wizard = new AddAccountViewModel();
376 77f3c897 Panagiotis Kanavos
           if (_windowManager.ShowDialog(wizard) == true)
377 77f3c897 Panagiotis Kanavos
           {
378 29a6b387 Panagiotis Kanavos
               string selectedPath = wizard.AccountPath;
379 fe62b7f4 Panagiotis Kanavos
               var initialRootPath = wizard.ShouldCreateOkeanosFolder?
380 fe62b7f4 Panagiotis Kanavos
                   Path.Combine(selectedPath, "Okeanos")
381 fe62b7f4 Panagiotis Kanavos
                   :selectedPath;
382 29a6b387 Panagiotis Kanavos
               var actualRootPath= initialRootPath;
383 fe62b7f4 Panagiotis Kanavos
               if (wizard.ShouldCreateOkeanosFolder)
384 29a6b387 Panagiotis Kanavos
               {
385 fe62b7f4 Panagiotis Kanavos
                   int attempt = 1;
386 fe62b7f4 Panagiotis Kanavos
                   while (Directory.Exists(actualRootPath) || File.Exists(actualRootPath))
387 fe62b7f4 Panagiotis Kanavos
                   {
388 fe62b7f4 Panagiotis Kanavos
                       actualRootPath = String.Format("{0} {1}", initialRootPath, attempt++);
389 fe62b7f4 Panagiotis Kanavos
                   }
390 29a6b387 Panagiotis Kanavos
               }
391 311d1cde Panagiotis Kanavos
392 311d1cde Panagiotis Kanavos
393 311d1cde Panagiotis Kanavos
394 311d1cde Panagiotis Kanavos
               var account = Accounts.FirstOrDefault(act => act.AccountName == wizard.AccountName && act.ServerUrl == wizard.CurrentServer);
395 311d1cde Panagiotis Kanavos
               if (account != null)
396 311d1cde Panagiotis Kanavos
               {
397 311d1cde Panagiotis Kanavos
                   if (MessageBox.Show("The account you specified already exists. Do you want to update it?","The account exists") == MessageBoxResult.Yes)
398 311d1cde Panagiotis Kanavos
                   {
399 311d1cde Panagiotis Kanavos
                       account.ApiKey = wizard.Token;
400 311d1cde Panagiotis Kanavos
                       account.IsExpired = false;
401 311d1cde Panagiotis Kanavos
                       CurrentAccount = account;
402 311d1cde Panagiotis Kanavos
                   }
403 311d1cde Panagiotis Kanavos
               }
404 311d1cde Panagiotis Kanavos
               else
405 311d1cde Panagiotis Kanavos
               {
406 311d1cde Panagiotis Kanavos
                   var newAccount = new AccountSettings
407 311d1cde Panagiotis Kanavos
                                        {
408 311d1cde Panagiotis Kanavos
                                            AccountName = wizard.AccountName,
409 311d1cde Panagiotis Kanavos
                                            ServerUrl = wizard.CurrentServer,
410 311d1cde Panagiotis Kanavos
                                            ApiKey = wizard.Token,
411 311d1cde Panagiotis Kanavos
                                            RootPath = actualRootPath,
412 311d1cde Panagiotis Kanavos
                                            IsActive = wizard.IsAccountActive
413 311d1cde Panagiotis Kanavos
                                        };
414 311d1cde Panagiotis Kanavos
                   _accountsToAdd.Add(newAccount);
415 311d1cde Panagiotis Kanavos
                   var accountVm = new AccountViewModel(newAccount);
416 311d1cde Panagiotis Kanavos
                   (Accounts as IProducerConsumerCollection<AccountViewModel>).TryAdd(accountVm);
417 311d1cde Panagiotis Kanavos
                   CurrentAccount = accountVm;
418 311d1cde Panagiotis Kanavos
               }
419 77f3c897 Panagiotis Kanavos
               NotifyOfPropertyChange(() => Accounts);
420 77f3c897 Panagiotis Kanavos
               NotifyOfPropertyChange(() => Settings);   
421 77f3c897 Panagiotis Kanavos
           }
422 77f3c897 Panagiotis Kanavos
423 77f3c897 Panagiotis Kanavos
424 77f3c897 Panagiotis Kanavos
            
425 77f3c897 Panagiotis Kanavos
       }
426 9bae55d1 Panagiotis Kanavos
427 81c5c310 pkanavos
/*
428 badcef63 Panagiotis Kanavos
        public void AddPithosAccount()
429 0c02aa65 Panagiotis Kanavos
       {
430 81c5c310 pkanavos
            var credentials=PithosAccount.RetrieveCredentials(null);
431 badcef63 Panagiotis Kanavos
            if (credentials == null)
432 badcef63 Panagiotis Kanavos
                return;
433 437abfca Panagiotis Kanavos
            var account = Settings.Accounts.FirstOrDefault(act => act.AccountName == credentials.UserName);
434 31c97141 Panagiotis Kanavos
            var accountVM = new AccountViewModel(account);
435 437abfca Panagiotis Kanavos
            if (account == null)
436 437abfca Panagiotis Kanavos
            {
437 437abfca Panagiotis Kanavos
                account=new AccountSettings{
438 437abfca Panagiotis Kanavos
                    AccountName=credentials.UserName,
439 74d78c90 Panagiotis Kanavos
                    ApiKey=credentials.Password
440 437abfca Panagiotis Kanavos
                };
441 437abfca Panagiotis Kanavos
                Settings.Accounts.Add(account);
442 31c97141 Panagiotis Kanavos
                accountVM = new AccountViewModel(account);
443 31c97141 Panagiotis Kanavos
                (Accounts as IProducerConsumerCollection<AccountViewModel>).TryAdd(accountVM);
444 437abfca Panagiotis Kanavos
            }
445 437abfca Panagiotis Kanavos
            else
446 437abfca Panagiotis Kanavos
            {
447 437abfca Panagiotis Kanavos
                account.ApiKey=credentials.Password;
448 437abfca Panagiotis Kanavos
            }
449 437abfca Panagiotis Kanavos
            //SelectedAccountIndex= Settings.Accounts.IndexOf(account);
450 31c97141 Panagiotis Kanavos
            CurrentAccount = accountVM;
451 437abfca Panagiotis Kanavos
            NotifyOfPropertyChange(() => Accounts);
452 437abfca Panagiotis Kanavos
            NotifyOfPropertyChange(()=>Settings);                       
453 0c02aa65 Panagiotis Kanavos
       }
454 81c5c310 pkanavos
*/
455 0c02aa65 Panagiotis Kanavos
456 7f5882da Panagiotis Kanavos
457 7f5882da Panagiotis Kanavos
        readonly List<AccountSettings> _accountsToRemove = new List<AccountSettings>();
458 5bcf6d70 Panagiotis Kanavos
        public void RemoveAccount()
459 5bcf6d70 Panagiotis Kanavos
        {
460 7e26c075 Panagiotis Kanavos
            Accounts.TryRemove(CurrentAccount);
461 7f5882da Panagiotis Kanavos
            _accountsToRemove.Add(CurrentAccount.Account);
462 7f5882da Panagiotis Kanavos
463 7e26c075 Panagiotis Kanavos
            CurrentAccount = null;
464 6aa29f4f Panagiotis Kanavos
            NotifyOfPropertyChange(() => Accounts);
465 7f5882da Panagiotis Kanavos
466 7e26c075 Panagiotis Kanavos
            
467 0eea575a Panagiotis Kanavos
            //NotifyOfPropertyChange("Settings.Accounts");
468 5bcf6d70 Panagiotis Kanavos
        }
469 9bae55d1 Panagiotis Kanavos
470 5bcf6d70 Panagiotis Kanavos
        public bool CanRemoveAccount
471 9bae55d1 Panagiotis Kanavos
        {
472 5bcf6d70 Panagiotis Kanavos
            get { return (CurrentAccount != null); }
473 5bcf6d70 Panagiotis Kanavos
        }
474 9bae55d1 Panagiotis Kanavos
475 0a9d4d18 pkanavos
        public bool CanClearAccountCache
476 0a9d4d18 pkanavos
        {
477 0a9d4d18 pkanavos
            get { return (CurrentAccount != null); }
478 0a9d4d18 pkanavos
        }
479 0a9d4d18 pkanavos
480 0a9d4d18 pkanavos
        public void ClearAccountCache()
481 0a9d4d18 pkanavos
        {
482 0a9d4d18 pkanavos
            if (MessageBoxResult.Yes == MessageBox.Show("You are about to delete all partially downloaded files from the account's cache.\n" +
483 0a9d4d18 pkanavos
                            " You will have to download all partially downloaded data again\n" +
484 0a9d4d18 pkanavos
                            "This change can not be undone\n\n" +
485 0a9d4d18 pkanavos
            "Do you wish to delete all partially downloaded data?", "Warning! Clearing account cache",
486 0a9d4d18 pkanavos
                            MessageBoxButton.YesNo,MessageBoxImage.Question,MessageBoxResult.No))
487 0a9d4d18 pkanavos
            {
488 0a9d4d18 pkanavos
489 0a9d4d18 pkanavos
                var cachePath = Path.Combine(CurrentAccount.RootPath, FolderConstants.CacheFolder);
490 0a9d4d18 pkanavos
                var dir = new DirectoryInfo(cachePath);
491 0a9d4d18 pkanavos
                dir.EnumerateFiles().Apply(file=>file.Delete());
492 0a9d4d18 pkanavos
                dir.EnumerateDirectories().Apply(folder => folder.Delete(true));
493 0a9d4d18 pkanavos
            }
494 0a9d4d18 pkanavos
        }
495 9bae55d1 Panagiotis Kanavos
496 9bae55d1 Panagiotis Kanavos
497 9bae55d1 Panagiotis Kanavos
        public bool ExtensionsActivated
498 9bae55d1 Panagiotis Kanavos
        {
499 9bae55d1 Panagiotis Kanavos
            get { return Settings.ExtensionsActivated; }
500 9bae55d1 Panagiotis Kanavos
            set
501 9bae55d1 Panagiotis Kanavos
            {
502 9bae55d1 Panagiotis Kanavos
                if (Settings.ExtensionsActivated == value)
503 5bcf6d70 Panagiotis Kanavos
                    return;
504 5bcf6d70 Panagiotis Kanavos
505 9bae55d1 Panagiotis Kanavos
                Settings.ExtensionsActivated = value;
506 9bae55d1 Panagiotis Kanavos
507 aba9e6d9 Panagiotis Kanavos
/*
508 aba9e6d9 Panagiotis Kanavos
                if (value)
509 aba9e6d9 Panagiotis Kanavos
                    _extensionController.RegisterExtensions();
510 aba9e6d9 Panagiotis Kanavos
                else
511 aba9e6d9 Panagiotis Kanavos
                {
512 aba9e6d9 Panagiotis Kanavos
                    _extensionController.UnregisterExtensions();
513 aba9e6d9 Panagiotis Kanavos
                }
514 aba9e6d9 Panagiotis Kanavos
*/
515 5bcf6d70 Panagiotis Kanavos
                NotifyOfPropertyChange(() => ExtensionsActivated);
516 9bae55d1 Panagiotis Kanavos
            }
517 9bae55d1 Panagiotis Kanavos
        }
518 9bae55d1 Panagiotis Kanavos
519 6f03d6e1 Panagiotis Kanavos
        public bool DebugLoggingEnabled
520 6f03d6e1 Panagiotis Kanavos
        {
521 6f03d6e1 Panagiotis Kanavos
            get { return Settings.DebugLoggingEnabled; }
522 6f03d6e1 Panagiotis Kanavos
            set { 
523 6f03d6e1 Panagiotis Kanavos
                Settings.DebugLoggingEnabled = value;
524 6f03d6e1 Panagiotis Kanavos
                NotifyOfPropertyChange(()=>DebugLoggingEnabled);
525 6f03d6e1 Panagiotis Kanavos
            }
526 6f03d6e1 Panagiotis Kanavos
        }
527 e394ef0f pkanavos
528 e394ef0f pkanavos
        public bool IgnoreCertificateErrors
529 e394ef0f pkanavos
        {
530 e394ef0f pkanavos
            get { return Settings.IgnoreCertificateErrors; }
531 e394ef0f pkanavos
            set {
532 e394ef0f pkanavos
                Settings.IgnoreCertificateErrors = value;
533 e394ef0f pkanavos
                NotifyOfPropertyChange(() => IgnoreCertificateErrors);
534 e394ef0f pkanavos
            }
535 e394ef0f pkanavos
        }
536 c53aa229 Panagiotis Kanavos
       
537 5bcf6d70 Panagiotis Kanavos
        #endregion
538 5bcf6d70 Panagiotis Kanavos
539 7e26c075 Panagiotis Kanavos
       /* private int _selectedAccountIndex;
540 0eea575a Panagiotis Kanavos
        public int SelectedAccountIndex
541 5bcf6d70 Panagiotis Kanavos
        {
542 0eea575a Panagiotis Kanavos
            get { return _selectedAccountIndex; }
543 5bcf6d70 Panagiotis Kanavos
            set
544 5bcf6d70 Panagiotis Kanavos
            {
545 153975d0 Panagiotis Kanavos
                //var accountCount=Settings.Accounts.Count;
546 153975d0 Panagiotis Kanavos
                //if (accountCount == 0)
547 153975d0 Panagiotis Kanavos
                //    return;
548 153975d0 Panagiotis Kanavos
                //if (0 <= value && value < accountCount)
549 153975d0 Panagiotis Kanavos
                //    _selectedAccountIndex = value;
550 153975d0 Panagiotis Kanavos
                //else
551 153975d0 Panagiotis Kanavos
                //    _selectedAccountIndex = 0;
552 0c02aa65 Panagiotis Kanavos
                _selectedAccountIndex = value;
553 0eea575a Panagiotis Kanavos
                NotifyOfPropertyChange(() => CurrentAccount);
554 0eea575a Panagiotis Kanavos
                NotifyOfPropertyChange(() => CanRemoveAccount);
555 0eea575a Panagiotis Kanavos
                NotifyOfPropertyChange(()=>SelectedAccountIndex);
556 5bcf6d70 Panagiotis Kanavos
            }
557 7e26c075 Panagiotis Kanavos
        }*/
558 5bcf6d70 Panagiotis Kanavos
559 31c97141 Panagiotis Kanavos
        private AccountViewModel _currentAccount;
560 c636df1f Panagiotis Kanavos
        private readonly IWindowManager _windowManager;
561 c636df1f Panagiotis Kanavos
        private readonly string _shortcutPath;
562 7e26c075 Panagiotis Kanavos
563 d3a13891 Panagiotis Kanavos
564 7e26c075 Panagiotis Kanavos
        
565 31c97141 Panagiotis Kanavos
        public AccountViewModel CurrentAccount
566 7e26c075 Panagiotis Kanavos
        {
567 7e26c075 Panagiotis Kanavos
            get { return _currentAccount; }
568 7e26c075 Panagiotis Kanavos
            set
569 7e26c075 Panagiotis Kanavos
            {
570 7e26c075 Panagiotis Kanavos
                _currentAccount = value;
571 7e26c075 Panagiotis Kanavos
                NotifyOfPropertyChange(()=>CurrentAccount);
572 7e26c075 Panagiotis Kanavos
                NotifyOfPropertyChange(() => CanRemoveAccount);
573 aba9e6d9 Panagiotis Kanavos
                NotifyOfPropertyChange(() => CanSelectiveSyncFolders);
574 aba9e6d9 Panagiotis Kanavos
                NotifyOfPropertyChange(() => CanMoveAccountFolder);
575 0a9d4d18 pkanavos
                NotifyOfPropertyChange(() => CanClearAccountCache);
576 7e26c075 Panagiotis Kanavos
            }
577 7e26c075 Panagiotis Kanavos
        }
578 7e26c075 Panagiotis Kanavos
579 7e26c075 Panagiotis Kanavos
/*
580 0eea575a Panagiotis Kanavos
        public AccountSettings CurrentAccount
581 9bae55d1 Panagiotis Kanavos
        {
582 153975d0 Panagiotis Kanavos
            get {
583 153975d0 Panagiotis Kanavos
                if (0 <= SelectedAccountIndex && SelectedAccountIndex < Settings.Accounts.Count)                    
584 153975d0 Panagiotis Kanavos
                    return Settings.Accounts[SelectedAccountIndex];
585 153975d0 Panagiotis Kanavos
                return null;
586 153975d0 Panagiotis Kanavos
            }
587 5120f3cb Panagiotis Kanavos
588 9bae55d1 Panagiotis Kanavos
        }
589 7e26c075 Panagiotis Kanavos
*/
590 9bae55d1 Panagiotis Kanavos
591 9bae55d1 Panagiotis Kanavos
592 aba9e6d9 Panagiotis Kanavos
        public bool CanMoveAccountFolder
593 aba9e6d9 Panagiotis Kanavos
        {
594 aba9e6d9 Panagiotis Kanavos
            get { return CurrentAccount != null; }
595 aba9e6d9 Panagiotis Kanavos
        }
596 5120f3cb Panagiotis Kanavos
597 5120f3cb Panagiotis Kanavos
    public void MoveAccountFolder()
598 5120f3cb Panagiotis Kanavos
    {
599 5120f3cb Panagiotis Kanavos
600 5120f3cb Panagiotis Kanavos
        using (var dlg = new FolderBrowserDialog())
601 5120f3cb Panagiotis Kanavos
        {
602 5120f3cb Panagiotis Kanavos
            var currentFolder = CurrentAccount.RootPath;
603 5120f3cb Panagiotis Kanavos
            dlg.SelectedPath = currentFolder;
604 5120f3cb Panagiotis Kanavos
            //Ask the user to select a folder
605 5120f3cb Panagiotis Kanavos
            //Note: We need a parent window here, which we retrieve with GetView            
606 5120f3cb Panagiotis Kanavos
            var view = (Window)GetView();            
607 5120f3cb Panagiotis Kanavos
            if (DialogResult.OK != dlg.ShowDialog(new Wpf32Window(view)))
608 5120f3cb Panagiotis Kanavos
                return;            
609 5120f3cb Panagiotis Kanavos
610 5120f3cb Panagiotis Kanavos
            var newPath= dlg.SelectedPath;                
611 5120f3cb Panagiotis Kanavos
            //Find the account's monitor and stop it
612 7e26c075 Panagiotis Kanavos
            PithosMonitor monitor;
613 ebc37b0d pkanavos
            if (Shell.Monitors.TryGetValue(CurrentAccount.AccountKey, out monitor))
614 5120f3cb Panagiotis Kanavos
            {
615 7e26c075 Panagiotis Kanavos
                monitor.Stop();
616 7e26c075 Panagiotis Kanavos
617 7e26c075 Panagiotis Kanavos
618 7e26c075 Panagiotis Kanavos
                var oldPath = monitor.RootPath;
619 7e26c075 Panagiotis Kanavos
                //The old directory may not exist eg. if we create an account for the first time
620 7e26c075 Panagiotis Kanavos
                if (Directory.Exists(oldPath))
621 7e26c075 Panagiotis Kanavos
                {
622 7e26c075 Panagiotis Kanavos
                    //If it does, do the move
623 5a99309c Panagiotis Kanavos
624 5a99309c Panagiotis Kanavos
                    //Now Create all of the directories
625 5a99309c Panagiotis Kanavos
                    foreach (string dirPath in Directory.EnumerateDirectories(oldPath, "*",
626 5a99309c Panagiotis Kanavos
                                                           SearchOption.AllDirectories))
627 5a99309c Panagiotis Kanavos
                        Directory.CreateDirectory(dirPath.Replace(oldPath, newPath));
628 5a99309c Panagiotis Kanavos
629 5a99309c Panagiotis Kanavos
                    //Copy all the files
630 5a99309c Panagiotis Kanavos
                    foreach (string newFilePath in Directory.EnumerateFiles(oldPath, "*.*",
631 5a99309c Panagiotis Kanavos
                                                                            SearchOption.AllDirectories))
632 5a99309c Panagiotis Kanavos
                        File.Copy(newFilePath, newFilePath.Replace(oldPath, newPath));
633 5a99309c Panagiotis Kanavos
634 81c5c310 pkanavos
                    Log.InfoFormat("Deleting account folder {0}",oldPath);
635 5a99309c Panagiotis Kanavos
                    Directory.Delete(oldPath, true);
636 5a99309c Panagiotis Kanavos
637 7e26c075 Panagiotis Kanavos
                    //We also need to change the path of the existing file states
638 c636df1f Panagiotis Kanavos
                    monitor.MoveFileStates(oldPath, newPath);
639 7e26c075 Panagiotis Kanavos
                }
640 5120f3cb Panagiotis Kanavos
            }
641 5120f3cb Panagiotis Kanavos
            //Replace the old rootpath with the new
642 5120f3cb Panagiotis Kanavos
            CurrentAccount.RootPath = newPath;
643 5120f3cb Panagiotis Kanavos
            //TODO: This will save all settings changes. Too coarse grained, need to fix at a later date
644 5120f3cb Panagiotis Kanavos
            Settings.Save();            
645 5120f3cb Panagiotis Kanavos
            //And start the monitor on the new RootPath            
646 7e26c075 Panagiotis Kanavos
            if (monitor != null)
647 7e26c075 Panagiotis Kanavos
            {
648 7e26c075 Panagiotis Kanavos
                monitor.RootPath = newPath;
649 7e26c075 Panagiotis Kanavos
                if (CurrentAccount.IsActive)
650 7e26c075 Panagiotis Kanavos
                    monitor.Start();
651 7e26c075 Panagiotis Kanavos
            }
652 7e26c075 Panagiotis Kanavos
            else
653 31c97141 Panagiotis Kanavos
                Shell.MonitorAccount(CurrentAccount.Account);
654 5120f3cb Panagiotis Kanavos
            //Finally, notify that the Settings, CurrentAccount have changed
655 5120f3cb Panagiotis Kanavos
            NotifyOfPropertyChange(() => CurrentAccount);
656 5120f3cb Panagiotis Kanavos
            NotifyOfPropertyChange(() => Settings);
657 5120f3cb Panagiotis Kanavos
658 5120f3cb Panagiotis Kanavos
        }
659 5120f3cb Panagiotis Kanavos
    }
660 9bae55d1 Panagiotis Kanavos
    }
661 9bae55d1 Panagiotis Kanavos
}