1 // -----------------------------------------------------------------------
2 // <copyright file="StatusViewModel.cs" company="Microsoft">
3 // TODO: Update copyright text.
5 // -----------------------------------------------------------------------
7 using System.ComponentModel.Composition;
8 using System.Diagnostics;
12 using Pithos.Client.WPF.Properties;
14 using Pithos.Interfaces;
16 namespace Pithos.Client.WPF
19 using System.Collections.Generic;
24 /// TODO: Update summary.
27 public class TaskbarViewModel:ViewAware
29 private IStatusChecker _statusChecker;
31 public PithosMonitor Monitor { get; private set; }
33 public IPithosSettings Settings { get; private set; }
35 public IScreen Parent { get; set; }
37 [ImportingConstructor]
38 public TaskbarViewModel(IStatusChecker statusChecker,PithosMonitor monitor,IPithosSettings settings)
40 OpenPithosFolderCommand = new PithosCommand(OpenPithosFolder);
41 _statusChecker = statusChecker;
45 var account=settings.Accounts.FirstOrDefault(act => act.IsActive);
48 Monitor.UserName = account.AccountName;
49 Monitor.ApiKey = account.ApiKey;
50 Monitor.UsePithos = account.UsePithos;
51 var appSettings = Properties.Settings.Default;
52 Monitor.AuthenticationUrl = account.UsePithos
53 ? appSettings.PithosAuthenticationUrl
54 : appSettings.CloudfilesAuthenticationUrl;
55 Monitor.RootPath = Path.Combine(Settings.PithosPath, account.RootPath??"");
59 #region Status Properties
61 private string _statusMessage;
62 public string StatusMessage
64 get { return _statusMessage; }
67 _statusMessage = value;
68 NotifyOfPropertyChange(() => StatusMessage);
72 private string _usageMessage;
73 public string UsageMessage
75 get { return _usageMessage; }
78 _usageMessage = value;
79 NotifyOfPropertyChange(() => UsageMessage);
84 private string _pauseSyncCaption="Pause Syncing";
85 public string PauseSyncCaption
87 get { return _pauseSyncCaption; }
90 _pauseSyncCaption = value;
91 NotifyOfPropertyChange(() => PauseSyncCaption);
95 private readonly IObservableCollection<FileEntry> _recentFiles = new BindableCollection<FileEntry>();
96 public IObservableCollection<FileEntry> RecentFiles
98 get { return _recentFiles; }
102 private string _statusIcon;
103 public string StatusIcon
105 get { return _statusIcon; }
109 NotifyOfPropertyChange(() => StatusIcon);
117 public void ShowPreferences()
123 public PithosCommand OpenPithosFolderCommand { get; private set; }
125 public void OpenPithosFolder()
127 Process.Start(Settings.PithosPath);
130 public void GoToSite()
132 Process.Start(Properties.Settings.Default.PithosSite);
136 public void ToggleSynching()
138 Monitor.Pause = !Monitor.Pause;
139 PauseSyncCaption = Monitor.Pause ? "Resume syncing" : "Pause syncing";
140 var iconKey = Monitor.Pause ? "TraySyncPaused" : "TrayInSynch";
141 StatusIcon = String.Format(@"Images/{0}.ico", iconKey);
144 public void ExitPithos()
152 private Dictionary<PithosStatus, StatusInfo> iconNames = new List<StatusInfo>
154 new StatusInfo(PithosStatus.InSynch, "All files up to date", "TrayInSynch"),
155 new StatusInfo(PithosStatus.Syncing, "Syncing Files", "TraySynching"),
156 new StatusInfo(PithosStatus.SyncPaused, "Sync Paused", "TraySyncPaused")
157 }.ToDictionary(s => s.Status);
160 public void UpdateStatus()
162 var pithosStatus = _statusChecker.GetPithosStatus();
164 if (iconNames.ContainsKey(pithosStatus))
166 var info = iconNames[pithosStatus];
167 StatusIcon = String.Format(@"Images/{0}.ico", info.IconName);
168 StatusMessage = String.Format("Pithos 1.0\r\n{0}", info.StatusText);
170 if (!String.IsNullOrWhiteSpace(Monitor.UserName) &&
171 !String.IsNullOrWhiteSpace(Monitor.ApiKey))
176 catch (Exception exc)
178 MessageBox.Show("An exception occured. Can't start monitoring");