[longomatch] Finishing the New Version Available dialog.



commit f3c9da7224f7122b4cdff1da771c9c2a26772a2b
Author: Xavi Artigas <xartigas fluendo com>
Date:   Mon Apr 13 12:41:22 2015 +0200

    Finishing the New Version Available dialog.
    
    Use the new IService interface entry points.
    Show the ChangeLog in the update dialog.
    Allow silencing some version updates.
    Add new NewVersionAvailable GUI message in the IGUIToolkit interface.
    Allow customizing MessageHelpers.PopupMessage's.
    Add an ignored version field in the configuration file.

 LongoMatch.Core/Config.cs                     |   14 ++++++++-
 LongoMatch.Core/Interfaces/GUI/IGUIToolkit.cs |    3 ++
 LongoMatch.GUI.Helpers/MessagesHelpers.cs     |   39 ++++++++++++++++++++++++-
 LongoMatch.GUI/Gui/GUIToolkit.cs              |    9 ++++++
 LongoMatch.Services/UpdatesNotifier.cs        |   26 +++++++++++------
 5 files changed, 80 insertions(+), 11 deletions(-)
---
diff --git a/LongoMatch.Core/Config.cs b/LongoMatch.Core/Config.cs
index c28f91a..f2abff0 100644
--- a/LongoMatch.Core/Config.cs
+++ b/LongoMatch.Core/Config.cs
@@ -115,7 +115,7 @@ namespace LongoMatch
                        try {
                                Serializer.Save (state, Config.ConfigFile); 
                        } catch (Exception ex) {
-                               Log.Error ("Errro saving config");
+                               Log.Error ("Error saving config");
                                Log.Exception (ex);
                        }
                }
@@ -535,6 +535,16 @@ namespace LongoMatch
                        }
                }
 
+               public static Version IgnoreUpdaterVersion {
+                       get {
+                               return state.ignoreUpdaterVersion;
+                       }
+                       set {
+                               state.ignoreUpdaterVersion = value;
+                               Save ();
+                       }
+               }
+
                #endregion
 
        }
@@ -565,6 +575,7 @@ namespace LongoMatch
                public string defaultTemplate;
                public Hotkeys hotkeys;
                public ProjectSortMethod projectSortMethod;
+               public Version ignoreUpdaterVersion;
 
                public ConfigState ()
                {
@@ -591,6 +602,7 @@ namespace LongoMatch
                        defaultTemplate = null;
                        hotkeys = new Hotkeys ();
                        projectSortMethod = ProjectSortMethod.Date;
+                       ignoreUpdaterVersion = null;
                }
        }
 }
diff --git a/LongoMatch.Core/Interfaces/GUI/IGUIToolkit.cs b/LongoMatch.Core/Interfaces/GUI/IGUIToolkit.cs
index 7e80171..db4fccd 100644
--- a/LongoMatch.Core/Interfaces/GUI/IGUIToolkit.cs
+++ b/LongoMatch.Core/Interfaces/GUI/IGUIToolkit.cs
@@ -56,6 +56,9 @@ namespace LongoMatch.Core.Interfaces.GUI
                bool QuestionMessage (string message, string title, object parent = null);
 
                string QueryMessage (string key, string title = null, string value = "", object parent = 
null);
+
+               bool NewVersionAvailable (Version currentVersion, Version latestVersion,
+                       string downloadURL, string changeLog, object parent = null);
                
                /* Files/Folders IO */
                string SaveFile (string title, string defaultName, string defaultFolder,
diff --git a/LongoMatch.GUI.Helpers/MessagesHelpers.cs b/LongoMatch.GUI.Helpers/MessagesHelpers.cs
index 458b246..ef2d9ff 100644
--- a/LongoMatch.GUI.Helpers/MessagesHelpers.cs
+++ b/LongoMatch.GUI.Helpers/MessagesHelpers.cs
@@ -28,6 +28,7 @@ namespace LongoMatch.Gui.Helpers
 
        public class MessagesHelpers
        {
+               public delegate void CustomizeDialog (MessageDialog Dialog);
        
                static public void InfoMessage (Widget parent, string message)
                {
@@ -64,7 +65,8 @@ namespace LongoMatch.Gui.Helpers
                        return (res == (int)ResponseType.Yes);
                }
 
-               public static int PopupMessage (Widget sender, MessageType type, String errorMessage)
+               public static int PopupMessage (Widget sender, MessageType type, String errorMessage,
+                       CustomizeDialog customize = null)
                {
                        Window toplevel;
                        int ret;
@@ -97,6 +99,9 @@ namespace LongoMatch.Gui.Helpers
                                        ex);
                        }
 
+                       if (customize != null)
+                               customize (md);
+
                        ret = md.Run ();
                        md.Destroy ();
                        return ret;
@@ -127,5 +132,37 @@ namespace LongoMatch.Gui.Helpers
                        dialog.Destroy ();
                        return ret;
                }
+
+               static public bool NewVersionAvailable (Version currentVersion, Version latestVersion,
+                       string downloadURL, string changeLog, Widget parent = null)
+               {
+                       string message = string.Format (
+                               Catalog.GetString("Version {0} is available!\n" +
+                                       "(You are using version {1})\n" +
+                                       "<a href=\"{2}\">Click here to get it.</a>"),
+                               latestVersion, currentVersion, downloadURL);
+
+                       bool checkState = false;
+
+                       PopupMessage (parent, MessageType.Info, message, (dialog) =>
+                               {
+                                       dialog.Title = Catalog.GetString ("New version available");
+                                       VBox vbox = dialog.MessageDialogGetMessageArea ();
+
+                                       var expander = new Gtk.Expander (Catalog.GetString ("Changes:"));
+                                       expander.Add (new Label (changeLog));
+                                       vbox.Add (expander);
+
+                                       var check = new CheckButton (Catalog.GetString ("Do not notify me 
again until next version"));
+                                       check.Toggled += delegate {
+                                               checkState = check.Active;
+                                       };
+                                       vbox.Add (check);
+
+                                       vbox.ShowAll ();
+                               });
+
+                       return checkState;
+               }
        }
 }
diff --git a/LongoMatch.GUI/Gui/GUIToolkit.cs b/LongoMatch.GUI/Gui/GUIToolkit.cs
index 5699e90..393482a 100644
--- a/LongoMatch.GUI/Gui/GUIToolkit.cs
+++ b/LongoMatch.GUI/Gui/GUIToolkit.cs
@@ -128,6 +128,15 @@ namespace LongoMatch.Gui
                        return MessagesHelpers.QueryMessage (parent as Widget, key, title, value);
                }
 
+               public bool NewVersionAvailable (Version currentVersion, Version latestVersion,
+                       string downloadURL, string changeLog, object parent = null)
+               {
+                       if (parent == null)
+                               parent = mainWindow;
+                       return MessagesHelpers.NewVersionAvailable (currentVersion, latestVersion, 
downloadURL,
+                               changeLog, parent as Widget);
+               }
+
                public string SaveFile (string title, string defaultName, string defaultFolder,
                                        string filterName, string[] extensionFilter)
                {
diff --git a/LongoMatch.Services/UpdatesNotifier.cs b/LongoMatch.Services/UpdatesNotifier.cs
index c8cbb04..e025492 100644
--- a/LongoMatch.Services/UpdatesNotifier.cs
+++ b/LongoMatch.Services/UpdatesNotifier.cs
@@ -24,6 +24,7 @@ namespace LongoMatch.Services
 
                string tempFile;
                string downloadURL;
+               string changeLog;
 
                #region Constructors
 
@@ -31,9 +32,6 @@ namespace LongoMatch.Services
                {
                        currentVersion = Assembly.GetExecutingAssembly ().GetName ().Version;
                        tempFile = Path.Combine (Config.HomeDir, "latest.json");
-
-                       var thread = new Thread (new ThreadStart (CheckForUpdates));
-                       thread.Start ();
                }
 
                #endregion
@@ -54,6 +52,7 @@ namespace LongoMatch.Services
 
                                latestVersion = new Version (latestObject ["version"].Value<string> ());
                                downloadURL = latestObject ["url"].Value<string> ();
+                               changeLog = latestObject["changes"].Value<string> ();
                        } catch (Exception ex) {
                                Log.Warning ("Error processing version file: " + Config.LatestVersionURL);
                                Log.Exception (ex);
@@ -77,14 +76,20 @@ namespace LongoMatch.Services
                        FetchNewVersion ();
                        Log.InformationFormat ("UpdatesNotifier: Current version is {0} and latest available 
is {1}",
                                currentVersion, latestVersion);
+                       if (latestVersion == Config.IgnoreUpdaterVersion) {
+                               Log.InformationFormat ("UpdatesNotifier: Version {0} has been silenced. Not 
warning user about update.",
+                                       latestVersion);
+                               return;
+                       }
                        if (IsOutDated ()) {
                                Config.GUIToolkit.Invoke (delegate {
-                                       Config.GUIToolkit.InfoMessage (
-                                               string.Format (
-                                                       Catalog.GetString ("Version {0} is available!\n" +
-                                                       "(You are using version {1})\n" +
-                                                       "<a href=\"{2}\">Click here to get it.</a>"),
-                                                       latestVersion, currentVersion, downloadURL));
+                                       bool ignore = Config.GUIToolkit.NewVersionAvailable (currentVersion, 
latestVersion,
+                                               downloadURL, changeLog, null);
+                                       if (ignore) {
+                                               /* User requested to ignore this version */
+                                               Log.InformationFormat ("UpdatesNotifier: Marking version {0} 
as silenced.", latestVersion);
+                                               Config.IgnoreUpdaterVersion = latestVersion;
+                                       }
                                });
                        }
                }
@@ -107,6 +112,9 @@ namespace LongoMatch.Services
 
                public bool Start ()
                {
+                       var thread = new Thread (new ThreadStart (CheckForUpdates));
+                       thread.Start ();
+
                        return true;
                }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]