Changed MonitorAccount to call StartMonitor which handles reauthentication
[pithos-ms-client] / trunk / Pithos.Client.WPF / Shell / ShellViewModel.cs
index 2099e38..da7cf3c 100644 (file)
@@ -105,6 +105,12 @@ namespace Pithos.Client.WPF {
 
                 StatusMessage = "In Synch";
 
+                _accounts.CollectionChanged += (sender, e) =>
+                                                   {
+                                                       NotifyOfPropertyChange(() => OpenFolderCaption);
+                                                       NotifyOfPropertyChange(() => HasAccounts);
+                                                   };
+
             }
             catch (Exception exc)
             {
@@ -113,6 +119,7 @@ namespace Pithos.Client.WPF {
             }
         }
 
+
         protected override void OnActivate()
         {
             base.OnActivate();
@@ -164,8 +171,8 @@ namespace Pithos.Client.WPF {
                     //If the account is active
                     if (account.IsActive)
                         //Start the monitor. It's OK to start an already started monitor,
-                        //it will just ignore the call
-                        monitor.Start();
+                        //it will just ignore the call                        
+                        StartMonitor(monitor).Wait();                        
                     else
                     {
                         //If the account is inactive
@@ -208,9 +215,9 @@ namespace Pithos.Client.WPF {
 
         protected override void OnViewLoaded(object view)
         {
-            var window = (Window)view;
-            window.Hide();
             UpdateStatus();
+            var window = (Window)view;            
+            TaskEx.Delay(1000).ContinueWith(t => Execute.OnUIThread(window.Hide));
             base.OnViewLoaded(view);
         }
 
@@ -228,14 +235,29 @@ namespace Pithos.Client.WPF {
             }
         }
 
-        private ObservableConcurrentCollection<AccountInfo> _accounts = new ObservableConcurrentCollection<AccountInfo>();
+        private readonly ObservableConcurrentCollection<AccountInfo> _accounts = new ObservableConcurrentCollection<AccountInfo>();
         public ObservableConcurrentCollection<AccountInfo> Accounts
         {
             get { return _accounts; }
         }
 
+           public bool HasAccounts
+           {
+            get { return _accounts.Count > 0; }
+           }
+
+
+        public string OpenFolderCaption
+        {
+            get
+            {
+                return (_accounts.Count == 0)
+                        ? "No Accounts Defined"
+                        : "Open Pithos Folder";
+            }
+        }
 
-        private string _pauseSyncCaption="Pause Syncing";
+        private string _pauseSyncCaption="Pause Synching";
         public string PauseSyncCaption
         {
             get { return _pauseSyncCaption; }
@@ -253,13 +275,13 @@ namespace Pithos.Client.WPF {
         }
 
 
-        private string _statusIcon="../Images/Tray.ico";
+        private string _statusIcon="../Images/Pithos.ico";
         public string StatusIcon
         {
             get { return _statusIcon; }
             set
             {
-                _statusIcon = value;
+                //_statusIcon = value;
                 NotifyOfPropertyChange(() => StatusIcon);
             }
         }
@@ -304,6 +326,12 @@ namespace Pithos.Client.WPF {
         }
 
         
+        public void GoToSite()
+        {            
+            var site = Properties.Settings.Default.PithosSite;
+            Process.Start(site);            
+        }
+
         public void GoToSite(AccountInfo account)
         {
             var site = String.Format("{0}/ui/?token={1}&user={2}",
@@ -621,6 +649,9 @@ namespace Pithos.Client.WPF {
             if (String.IsNullOrWhiteSpace(accountName))
                 return;
 
+            var accountInfo=_accounts.FirstOrDefault(account => account.UserName == accountName);
+            _accounts.TryRemove(accountInfo);
+
             PithosMonitor monitor;
             if (Monitors.TryGetValue(accountName, out monitor))
             {