Statistics
| Branch: | Revision:

root / trunk / Pithos.Client.WPF / PreferencesViewModel.cs @ 5bcf6d70

History | View | Annotate | Download (7.5 kB)

1
// -----------------------------------------------------------------------
2
// <copyright file="PreferencesViewModel.cs" company="Microsoft">
3
// TODO: Update copyright text.
4
// </copyright>
5
// -----------------------------------------------------------------------
6

    
7
using System.Collections;
8
using System.ComponentModel.Composition;
9
using System.Diagnostics;
10
using System.IO;
11
using System.IO.IsolatedStorage;
12
using System.Net;
13
using System.Runtime.Serialization;
14
using System.Windows;
15
using System.Windows.Forms;
16
using Caliburn.Micro;
17
using Pithos.Client.WPF.Configuration;
18
using Pithos.Core;
19
using Pithos.Interfaces;
20
using Pithos.ShellExtensions;
21
using Screen = Caliburn.Micro.Screen;
22

    
23
namespace Pithos.Client.WPF
24
{
25
    using System;
26
    using System.Collections.Generic;
27
    using System.Linq;
28
    using System.Text;
29

    
30
    /// <summary>
31
    /// TODO: Update summary.
32
    /// </summary>
33
    [Export(typeof(IShell))]
34
    public class PreferencesViewModel : Screen, IShell
35
    {
36
        
37

    
38

    
39
        public IPithosSettings Settings { get; set; }
40

    
41

    
42
        public PithosMonitor Monitor { get; private set; }
43

    
44
        public TaskbarViewModel Taskbar { get; set; }
45

    
46
        ShellExtensionController _extensionController=new ShellExtensionController();
47

    
48
        [ImportingConstructor]
49
        public PreferencesViewModel(TaskbarViewModel taskbar, IPithosSettings settings, PithosMonitor monitor)
50
        {
51
            DisplayName = "Pithos Preferences";
52

    
53
            Taskbar=taskbar;
54
            Taskbar.Parent = this;
55
            
56
            Settings=settings;
57
            Monitor=monitor;
58

    
59
            
60

    
61
            
62

    
63
            Taskbar.UsageMessage = "Using 15% of 50 GB";
64
            Taskbar.RecentFiles.AddRange(new[]
65
                                     {
66
                                      new FileEntry{FileName="Moo",FullPath=@"e:\Pithos\moo"}   ,
67
                                      new FileEntry{FileName="Mee",FullPath=@"e:\Pithos\mee"}   
68
                                     });
69
            Taskbar.StatusMessage = "In Synch";
70
            Taskbar.UpdateStatus();
71
        }
72
        protected override void OnViewAttached(object view, object context)
73
        {
74
            var window = (Window)view;
75
/*
76
            window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
77
            window.ShowInTaskbar = false;
78
*/
79

    
80
            base.OnViewAttached(view, context);
81
        }
82

    
83

    
84
        protected override void OnViewLoaded(object view)
85
        {
86
            var window = (Window)view;
87
            window.Hide();
88

    
89
            base.OnViewLoaded(view);
90
        }
91

    
92
        #region Preferences Properties
93

    
94
        private bool _noProxy;
95
        public bool NoProxy
96
        {
97
            get { return _noProxy; }
98
            set
99
            {
100
                _noProxy = value;
101
                NotifyOfPropertyChange(()=>NoProxy);
102
            }
103
        }
104

    
105

    
106
        private bool _defaultProxy;
107

    
108
        public bool DefaultProxy
109
        {
110
            get { return _defaultProxy; }
111
            set
112
            {
113
                _defaultProxy = value;
114
                NotifyOfPropertyChange(() => DefaultProxy);
115
            }
116
        }
117

    
118

    
119
        private bool _manualProxy;
120

    
121
        public bool ManualProxy
122
        {
123
            get { return _manualProxy; }
124
            set
125
            {
126
                _manualProxy = value;
127
                NotifyOfPropertyChange(() => ManualProxy);
128
            }
129
        }
130
        #endregion
131

    
132
       
133
        #region Commands
134
        
135

    
136
        /*public void ShowPreferences()
137
        {
138
            Settings.Reload();
139

    
140
            var window = (Window)this.GetView();
141
            window.Show();
142
        }*/
143

    
144

    
145
        /*public PithosCommand OpenPithosFolderCommand { get; private set; }
146

    
147
        public void OpenPithosFolder()
148
        {
149
            Process.Start(Settings.PithosPath);
150
        }
151

    
152
        public void GoToSite()
153
        {
154

    
155
        }
156

    
157
        public void ToggleSynching()
158
        {
159

    
160
        }
161
*/
162
        public void SaveChanges()
163
        {
164
            DoSave();
165
            /*var window = (Window)GetView();
166
            window.Hide();*/
167
        }
168

    
169
        public void RejectChanges()
170
        {
171
            Settings.Reload();
172
           /* var window = (Window)GetView();
173
            window.Hide();*/
174
        }
175

    
176
        public void ApplyChanges()
177
        {
178
            DoSave();
179
        }
180

    
181
        private void DoSave()
182
        {
183
            Settings.Save();
184
            Monitor.Start();
185
        }
186

    
187
        public void ChangePithosFolder()
188
        {
189
            var browser = new FolderBrowserDialog();
190
            browser.SelectedPath = Settings.PithosPath;
191
            var result = browser.ShowDialog((IWin32Window)GetView());
192
            if (result == DialogResult.OK)
193
            {
194
                var newPath = browser.SelectedPath;
195
                Directory.Move(Settings.PithosPath, newPath);
196
                Settings.PithosPath = newPath;
197
                Settings.Save();
198
                NotifyOfPropertyChange(() => Settings);
199
            }
200
        }
201

    
202
       /* public void ExitPithos()
203
        {
204
            Monitor.Stop();
205
            this.TryClose();            
206
        }
207
*/
208

    
209
        public void AddAccount()
210
        {
211
            var newAccount = new AccountSettings();
212
            Settings.Accounts.Add(newAccount);
213
            CurrentAccount = newAccount;
214
            NotifyOfPropertyChange(()=>Settings);
215
        }
216

    
217
        public void RemoveAccount()
218
        {
219
//            var idx = Settings.Accounts.IndexOf(CurrentAccount);
220
            Settings.Accounts.RemoveAll(account => account.AccountName == CurrentAccount.AccountName);
221
//            Settings.Accounts.RemoveAt(idx);            
222
            CurrentAccount = null;
223
            NotifyOfPropertyChange(()=>Settings);
224
            NotifyOfPropertyChange("Settings.Accounts");
225
        }
226

    
227
        public bool CanRemoveAccount
228
        {
229
            get { return (CurrentAccount != null); }
230
        }
231

    
232

    
233

    
234
        public bool ExtensionsActivated
235
        {
236
            get { return Settings.ExtensionsActivated; }
237
            set
238
            {
239
                if (Settings.ExtensionsActivated == value)
240
                    return;
241

    
242
                Settings.ExtensionsActivated = value;
243

    
244
                if (value)
245
                    _extensionController.RegisterExtensions();
246
                else
247
                {
248
                    _extensionController.UnregisterExtensions();
249
                }
250
                NotifyOfPropertyChange(() => ExtensionsActivated);
251
            }
252
        }
253

    
254
        public void RefreshOverlays()
255
        {
256
            this.Monitor.Workflow.RaiseChangeNotification(Settings.PithosPath);
257
        }
258
        #endregion
259

    
260
        private AccountSettings _currentAccount;
261
        public AccountSettings CurrentAccount
262
        {
263
            get { return _currentAccount; }
264
            set
265
            {
266
                _currentAccount = value;
267
                NotifyOfPropertyChange(()=>CurrentAccount);
268
                NotifyOfPropertyChange(()=>CanRemoveAccount);
269
            }
270
        }
271

    
272

    
273

    
274
        /* private void UnregisterExtensions()
275
        {
276
            using (var installer = new ProjectInstaller())
277
            {
278
                IDictionary state = ShellExtensionController.LoadState();
279
                installer.Uninstall(state);
280
            }
281
        }
282

    
283
        private void RegisterExtensions()
284
        {
285
            using (var installer = new ProjectInstaller())
286
            {
287
                IDictionary state = new Dictionary<object, object>();
288
                installer.Install(state);
289
                ShellExtensionController.SaveState(state);
290

    
291
            }
292
        }*/
293
    }
294
}