Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (4.5 kB)

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

    
7
using System.ComponentModel.Composition;
8
using System.Diagnostics;
9
using System.Windows;
10
using Caliburn.Micro;
11
using Pithos.Client.WPF.Properties;
12
using Pithos.Core;
13
using Pithos.Interfaces;
14

    
15
namespace Pithos.Client.WPF
16
{
17
    using System;
18
    using System.Collections.Generic;
19
    using System.Linq;
20
    using System.Text;
21

    
22
    /// <summary>
23
    /// TODO: Update summary.
24
    /// </summary>
25
    [Export]
26
    public class TaskbarViewModel:ViewAware
27
    {
28
        private IStatusChecker _statusChecker;
29

    
30
        public PithosMonitor Monitor { get; private set; }
31

    
32
        public IPithosSettings Settings { get; private set; }
33

    
34
        public IScreen Parent { get; set; }
35

    
36
        [ImportingConstructor]
37
        public TaskbarViewModel(IStatusChecker statusChecker,PithosMonitor monitor,IPithosSettings settings)
38
        {
39
            OpenPithosFolderCommand = new PithosCommand(OpenPithosFolder);
40
            _statusChecker = statusChecker;
41
            Settings = settings;
42
            Monitor = monitor;
43

    
44
        }
45
        #region Status Properties
46

    
47
        private string _statusMessage;
48
        public string StatusMessage
49
        {
50
            get { return _statusMessage; }
51
            set
52
            {
53
                _statusMessage = value;
54
                NotifyOfPropertyChange(() => StatusMessage);
55
            }
56
        }
57

    
58
        private string _usageMessage;
59
        public string UsageMessage
60
        {
61
            get { return _usageMessage; }
62
            set
63
            {
64
                _usageMessage = value;
65
                NotifyOfPropertyChange(() => UsageMessage);
66
            }
67
        }
68

    
69

    
70
        private string _pauseSyncCaption="Pause Syncing";
71
        public string PauseSyncCaption
72
        {
73
            get { return _pauseSyncCaption; }
74
            set
75
            {
76
                _pauseSyncCaption = value;
77
                NotifyOfPropertyChange(() => PauseSyncCaption);
78
            }
79
        }
80

    
81
        private readonly IObservableCollection<FileEntry> _recentFiles = new BindableCollection<FileEntry>();
82
        public IObservableCollection<FileEntry> RecentFiles
83
        {
84
            get { return _recentFiles; }
85
        }
86

    
87

    
88
        private string _statusIcon;
89
        public string StatusIcon
90
        {
91
            get { return _statusIcon; }
92
            set
93
            {
94
                _statusIcon = value;
95
                NotifyOfPropertyChange(() => StatusIcon);
96
            }
97
        }
98

    
99
        #endregion
100

    
101
        #region Commands
102

    
103
        public void ShowPreferences()
104
        {
105
            Settings.Reload();
106
        }
107

    
108

    
109
        public PithosCommand OpenPithosFolderCommand { get; private set; }
110

    
111
        public void OpenPithosFolder()
112
        {
113
            Process.Start(Settings.PithosPath);
114
        }
115

    
116
        public void GoToSite()
117
        {
118
            Process.Start(Properties.Settings.Default.PithosSite);
119
        }
120

    
121

    
122
        public void ToggleSynching()
123
        {
124
            Monitor.Pause = !Monitor.Pause;
125
            PauseSyncCaption = Monitor.Pause ? "Resume syncing" : "Pause syncing";
126
            var iconKey = Monitor.Pause ? "TraySyncPaused" : "TrayInSynch";
127
            StatusIcon = String.Format(@"Images/{0}.ico", iconKey);
128
        }
129

    
130
        public void ExitPithos()
131
        {
132
            Monitor.Stop();
133
            Parent.TryClose();
134
        }
135
        #endregion
136

    
137

    
138
        private Dictionary<PithosStatus, StatusInfo> iconNames = new List<StatusInfo>
139
            {
140
                new StatusInfo(PithosStatus.InSynch, "All files up to date", "TrayInSynch"),
141
                new StatusInfo(PithosStatus.Syncing, "Syncing Files", "TraySynching"),
142
                new StatusInfo(PithosStatus.SyncPaused, "Sync Paused", "TraySyncPaused")
143
            }.ToDictionary(s => s.Status);
144

    
145
        
146
        public void UpdateStatus()
147
        {
148
            var pithosStatus = _statusChecker.GetPithosStatus();
149

    
150
            if (iconNames.ContainsKey(pithosStatus))
151
            {
152
                var info = iconNames[pithosStatus];
153
                StatusIcon = String.Format(@"Images/{0}.ico", info.IconName);
154
                StatusMessage = String.Format("Pithos 1.0\r\n{0}", info.StatusText);
155
            }
156
            if (!String.IsNullOrWhiteSpace(Settings.UserName) &&
157
                !String.IsNullOrWhiteSpace(Settings.ApiKey))
158
                Monitor.Start();
159
        }
160
    }
161
}