Revision 5120f3cb trunk/Pithos.Client.WPF/PreferencesViewModel.cs

b/trunk/Pithos.Client.WPF/PreferencesViewModel.cs
16 16
using System.Runtime.Serialization;
17 17
using System.Windows;
18 18
using System.Windows.Forms;
19
using System.Windows.Interop;
19 20
using Caliburn.Micro;
20 21
using Hardcodet.Wpf.TaskbarNotification;
21 22
using Pithos.Client.WPF.Configuration;
22 23
using Pithos.Core;
23 24
using Pithos.Interfaces;
24

  
25
using IWin32Window = System.Windows.Forms.IWin32Window;
25 26
using Screen = Caliburn.Micro.Screen;
26 27

  
27 28
namespace Pithos.Client.WPF
......
41 42
        private IEventAggregator _events;
42 43

  
43 44

  
44
        public PithosSettings Settings { get; set; }
45
        private PithosSettings _settings;
46
        public PithosSettings Settings
47
        {
48
            get { return _settings; }
49
            set
50
            {
51
                _settings = value;
52
                foreach (var account in _settings.Accounts.Where(account=>account.IsActive))
53
                {
54
                    if (String.IsNullOrWhiteSpace(account.RootPath))
55
                    {
56
                        account.RootPath = _settings.PithosPath;
57
                        _settings.Save();
58
                    }
59
                }
60
                NotifyOfPropertyChange(()=>Settings);
61
            }
62
        }
45 63

  
46 64

  
47
        public PithosMonitor Monitor { get; private set; }
65
        private Dictionary<string,PithosMonitor> _monitors=new Dictionary<string, PithosMonitor>();
66
        public Dictionary<string, PithosMonitor> Monitors
67
        {
68
            get { return _monitors; }            
69
        }
48 70

  
49 71
        private TaskbarViewModel _taskbar;
50 72
        public TaskbarViewModel Taskbar
......
59 81
        //ShellExtensionController _extensionController=new ShellExtensionController();
60 82

  
61 83
        [ImportingConstructor]
62
        public PreferencesViewModel(IEventAggregator events, TaskbarViewModel taskbar, PithosSettings settings, PithosMonitor monitor)
84
        public PreferencesViewModel(IEventAggregator events, TaskbarViewModel taskbar, PithosSettings settings)
63 85
        {
64 86
            _events = events;
65 87
            _events.Subscribe(this);
......
69 91
            Taskbar=taskbar;
70 92
            Taskbar.Parent = this;
71 93
            
72
            Settings=settings;
73
            Monitor=monitor;
94
            Settings=settings;            
74 95

  
75 96

  
76 97
            Taskbar.UsageMessage = "Using 15% of 50 GB";
......
166 187
            if (String.IsNullOrWhiteSpace(activeAccount.AccountName))
167 188
                return;
168 189

  
169
            Monitor.ApiKey = activeAccount.ApiKey;
170
            Monitor.UserName = activeAccount.AccountName;
171
            Monitor.UsePithos = activeAccount.UsePithos;
190
            var monitor = Monitors[activeAccount.AccountName];
191
            monitor.ApiKey = activeAccount.ApiKey;
192
            monitor.UserName = activeAccount.AccountName;
193
            monitor.UsePithos = activeAccount.UsePithos;
172 194

  
173
            Monitor.Start();
195
            monitor.Start();
174 196
        }
175 197

  
176 198
        public void ChangePithosFolder()
......
313 335
                    return Settings.Accounts[SelectedAccountIndex];
314 336
                return null;
315 337
            }
316
/*
317
            set
318
            {
319
                _currentAccount = value;
320
            }
321
*/
338

  
322 339
        }
323 340

  
324 341

  
......
348 365
            tv.TaskbarView.ShowBalloonTip(notification.Title, notification.Message, icon);
349 366
        }
350 367

  
368

  
369
    public void MoveAccountFolder()
370
    {
371

  
372
        using (var dlg = new FolderBrowserDialog())
373
        {
374
            var currentFolder = CurrentAccount.RootPath;
375
            dlg.SelectedPath = currentFolder;
376
            //Ask the user to select a folder
377
            //Note: We need a parent window here, which we retrieve with GetView            
378
            var view = (Window)GetView();            
379
            if (DialogResult.OK != dlg.ShowDialog(new Wpf32Window(view)))
380
                return;            
381

  
382
            var newPath= dlg.SelectedPath;                
383
            //Find the account's monitor and stop it
384
            var monitor = Monitors[CurrentAccount.AccountName];            
385
            monitor.Stop();
386
                            
387
            var oldPath = monitor.RootPath;                
388
            //The old directory may not exist eg. if we create an account for the first time
389
            if (Directory.Exists(oldPath))
390
            {
391
                //If it does, do the move
392
                Directory.Move(oldPath, newPath);
393
                //We also need to change the path of the existing file states
394
                monitor.MoveFileStates(oldPath, newPath);
395
            }
396
            //Replace the old rootpath with the new
397
            CurrentAccount.RootPath = newPath;
398
            //TODO: This will save all settings changes. Too coarse grained, need to fix at a later date
399
            Settings.Save();            
400
            //And start the monitor on the new RootPath            
401
            monitor.RootPath = newPath;
402
            monitor.Start();
403
            //Finally, notify that the Settings, CurrentAccount have changed
404
            NotifyOfPropertyChange(() => CurrentAccount);
405
            NotifyOfPropertyChange(() => Settings);
406

  
407
        }
408
    }
351 409
    }
352 410
}

Also available in: Unified diff