Added fixes for v.0.7.20311
[pithos-ms-client] / trunk / Pithos.Client.WPF / Shell / ShellViewModel.cs
index 44be087..ce2eb94 100644 (file)
@@ -122,12 +122,28 @@ namespace Pithos.Client.WPF {
                //Logging in the Pithos client is provided by log4net
         private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
 
-               //Lazily initialized File Version info. This is done once and lazily to avoid blocking the UI
-               private readonly Lazy<FileVersionInfo> _fileVersion;
-
            private readonly PollAgent _pollAgent;
 
-               ///<summary>
+
+           private MiniStatusViewModel _miniStatus;
+
+           [Import]
+        public MiniStatusViewModel MiniStatus
+           {
+               get { return _miniStatus; }
+               set
+               {
+                   _miniStatus = value;
+                   _miniStatus.Shell = this;
+                   _miniStatus.Deactivated += (sender, arg) =>
+                                                  {
+                                                      _statusVisible = false;
+                                                   NotifyOfPropertyChange(()=>MiniStatusCaption);
+                                                  };
+               }
+           }
+
+           ///<summary>
                /// The Shell depends on MEF to provide implementations for windowManager, events, the status checker service and the settings
                ///</summary>
                ///<remarks>
@@ -152,20 +168,17 @@ namespace Pithos.Client.WPF {
 
                                Proxy.SetFromSettings(settings);
 
-                               StatusMessage = "In Synch";
+                StatusMessage = Settings.Accounts.Count==0 
+                    ? "No Accounts added\r\nPlease add an account" 
+                    : "Starting";
 
-                               _fileVersion=  new Lazy<FileVersionInfo>(() =>
-                               {
-                                       Assembly assembly = Assembly.GetExecutingAssembly();
-                                       var fileVersion = FileVersionInfo.GetVersionInfo(assembly.Location);
-                                       return fileVersion;
-                               });
                                _accounts.CollectionChanged += (sender, e) =>
                                                                                                   {
                                                                                                           NotifyOfPropertyChange(() => OpenFolderCaption);
                                                                                                           NotifyOfPropertyChange(() => HasAccounts);
                                                                                                   };
 
+                SetVersionMessage();
                        }
                        catch (Exception exc)
                        {
@@ -175,16 +188,27 @@ namespace Pithos.Client.WPF {
 
                }
 
+           private void SetVersionMessage()
+           {
+               Assembly assembly = Assembly.GetExecutingAssembly();
+               var fileVersion = FileVersionInfo.GetVersionInfo(assembly.Location);
+               VersionMessage = String.Format("Pithos+ {0}", fileVersion.FileVersion);
+           }
 
-               protected override void OnActivate()
+        public void OnStatusAction()
+        {
+            if (Accounts.Count==0)
+            {
+                ShowPreferences("AccountTab");
+            }
+        }
+           protected override void OnActivate()
                {
                        base.OnActivate();
 
-            _sparkle = new Sparkle(Settings.UpdateUrl);
-            _sparkle.updateDetected += OnUpgradeDetected;
-            _sparkle.ShowDiagnosticWindow = Settings.UpdateDiagnostics;
+            InitializeSparkle();
 
-            //Must delay opening the upgrade window
+               //Must delay opening the upgrade window
             //to avoid Windows Messages sent by the TaskbarIcon
             TaskEx.Delay(5000).ContinueWith(_=>
                 Execute.OnUIThread(()=> _sparkle.StartLoop(true,Settings.UpdateForceCheck,Settings.UpdateCheckInterval)));
@@ -193,19 +217,48 @@ namespace Pithos.Client.WPF {
                        StartMonitoring();                    
                }
 
-           private void OnUpgradeDetected(object sender, UpdateDetectedEventArgs e)
+
+           private void OnCheckFinished(object sender, bool updaterequired)
            {
+            
+            Log.InfoFormat("Upgrade check finished. Need Upgrade: {0}", updaterequired);
+            if (_manualUpgradeCheck)
+            {
+                _manualUpgradeCheck = false;
+                if (!updaterequired)
+                    //Sparkle raises events on a background thread
+                    Execute.OnUIThread(()=>
+                        ShowBalloonFor(new Notification{Title="Pithos+ is up to date",Message="You have the latest Pitsos+ version. No update is required"}));
+            }
+           }
+
+           private void OnUpgradeDetected(object sender, UpdateDetectedEventArgs e)
+           {            
                Log.InfoFormat("Update detected {0}",e.LatestVersion);
            }
 
         public void CheckForUpgrade()
         {
+            ShowBalloonFor(new Notification{Title="Checking for upgrades",Message="Contacting the server to retrieve the latest Pithos+ version."});
+            Log.Error("Test Error message");
             _sparkle.StopLoop();
+            _sparkle.updateDetected -= OnUpgradeDetected;
+            _sparkle.checkLoopFinished -= OnCheckFinished;
             _sparkle.Dispose();
-            _sparkle=new Sparkle(Settings.UpdateUrl);
+
+            _manualUpgradeCheck = true;
+            InitializeSparkle();
             _sparkle.StartLoop(true,true,Settings.UpdateCheckInterval);
         }
 
+        private void InitializeSparkle()
+        {
+            _sparkle = new Sparkle(Settings.UpdateUrl);
+            _sparkle.updateDetected += OnUpgradeDetected;
+            _sparkle.checkLoopFinished += OnCheckFinished;
+            _sparkle.ShowDiagnosticWindow = Settings.UpdateDiagnostics;
+        }
+
            private async void StartMonitoring()
                {
                        try
@@ -319,10 +372,22 @@ namespace Pithos.Client.WPF {
                        {
                                _statusMessage = value;
                                NotifyOfPropertyChange(() => StatusMessage);
+                NotifyOfPropertyChange(() => TooltipMessage);
                        }
                }
 
-               private readonly ObservableConcurrentCollection<AccountInfo> _accounts = new ObservableConcurrentCollection<AccountInfo>();
+        public string VersionMessage { get; set; }
+
+           private string _tooltipMessage;
+           public string TooltipMessage
+           {
+               get
+               {
+                   return String.Format("{0}\r\n{1}",VersionMessage,StatusMessage);
+               }
+           }
+
+           private readonly ObservableConcurrentCollection<AccountInfo> _accounts = new ObservableConcurrentCollection<AccountInfo>();
                public ObservableConcurrentCollection<AccountInfo> Accounts
                {
                        get { return _accounts; }
@@ -393,7 +458,8 @@ namespace Pithos.Client.WPF {
 
                public void AboutPithos()
                {
-                       var about = new AboutViewModel();
+                       var about = IoC.Get<AboutViewModel>();
+                   about.LatestVersion=_sparkle.LatestVersion;
                        _windowManager.ShowWindow(about);
                }
 
@@ -433,6 +499,30 @@ namespace Pithos.Client.WPF {
                    Process.Start(uri);
                }
 
+           private bool _statusVisible;
+
+           public string MiniStatusCaption
+           {
+               get
+               {
+                   return  _statusVisible ? "Hide Status Window" : "Show Status Window";
+               }
+           }
+
+           public void ShowMiniStatus()
+        {            
+            if (!_statusVisible)
+                _windowManager.ShowWindow(MiniStatus);
+            else
+            {           
+                if (MiniStatus.IsActive)
+                    MiniStatus.TryClose();
+            }
+            _statusVisible=!_statusVisible;
+
+               NotifyOfPropertyChange(()=>MiniStatusCaption);
+        }
+
            /// <summary>
         /// Open an explorer window to the target path's directory
         /// and select the file
@@ -448,8 +538,7 @@ namespace Pithos.Client.WPF {
 
         public void OpenLogPath()
         {
-            var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
-            var pithosDataPath = Path.Combine(appDataPath, "GRNET");
+            var pithosDataPath = PithosSettings.PithosDataPath;
 
             Process.Start(pithosDataPath);
         }
@@ -722,7 +811,7 @@ namespace Pithos.Client.WPF {
                {
                        StatusMessage = status;
                        
-                       _events.Publish(new Notification { Title = "Pithos", Message = status, Level = level });
+                       _events.Publish(new Notification { Title = "Pithos+", Message = status, Level = level });
                }
 
                public void NotifyChangedFile(string filePath)
@@ -776,7 +865,7 @@ namespace Pithos.Client.WPF {
 
                        StatusMessage = message;
 
-                       _events.Publish(new Notification { Title = "Pithos", Message = message, Level = level});
+                       _events.Publish(new Notification { Title = "Pithos+", Message = message, Level = level});
                }
 
                public void Notify(Notification notification)
@@ -852,6 +941,7 @@ namespace Pithos.Client.WPF {
 
                private bool _pollStarted;
            private Sparkle _sparkle;
+           private bool _manualUpgradeCheck;
 
            //SMELL: Doing so much work for notifications in the shell is wrong
                //The notifications should be moved to their own view/viewmodel pair
@@ -875,15 +965,23 @@ namespace Pithos.Client.WPF {
                                if (!_pollStarted) 
                                        return;
                                _pollStarted= false;
-                               notification.Title = "Pithos";
+                               notification.Title = "Pithos+";
                                notification.Message = "Start Synchronisation";
                        }
 
+                   var deleteNotification = notification as CloudDeleteNotification;
+            if (deleteNotification != null)
+            {
+                StatusMessage = String.Format("Deleted {0}", deleteNotification.Data.Name);
+                return;
+            }
+
                    var progress = notification as ProgressNotification;
-                   if (progress != null)
+                   
+                   
+            if (progress != null)
                    {
-                       StatusMessage = String.Format("Pithos {0}\r\n{1} {2:p2} of {3} - {4}",
-                                                     _fileVersion.Value.FileVersion, 
+                       StatusMessage = String.Format("{0} {1:p2} of {2} - {3}",                                                      
                                               progress.Action,
                                                      progress.Block/(double)progress.TotalBlocks,
                                                      progress.FileSize.ToByteSize(),
@@ -894,15 +992,14 @@ namespace Pithos.Client.WPF {
                    var info = notification as StatusNotification;
             if (info != null)
             {
-                StatusMessage = String.Format("Pithos {0}\r\n{1}",
-                                              _fileVersion.Value.FileVersion,
-                                              info.Title);
+                StatusMessage = info.Title;
                 return;
             }
                        if (String.IsNullOrWhiteSpace(notification.Message) && String.IsNullOrWhiteSpace(notification.Title))
                                return;
 
-                       ShowBalloonFor(notification);
+            if (notification.Level <= TraceLevel.Warning)
+                           ShowBalloonFor(notification);
                }
 
            private void ShowBalloonFor(Notification notification)
@@ -915,9 +1012,11 @@ namespace Pithos.Client.WPF {
             BalloonIcon icon;
                switch (notification.Level)
                {
-                   case TraceLevel.Info:
-                   case TraceLevel.Verbose:
+                case TraceLevel.Verbose:
                        return;
+                   case TraceLevel.Info:                   
+                       icon = BalloonIcon.Info;
+                       break;
                 case TraceLevel.Error:
                     icon = BalloonIcon.Error;
                     break;