[smuxi: 175/179] Engine, Frontend-GNOME: use single remoting call for batched config changes



commit 2526aaa7e55e81a1bfad6693a6e2f39f32edf69e
Author: Mirco Bauer <meebey meebey net>
Date:   Sat Oct 7 14:30:35 2017 +0800

    Engine, Frontend-GNOME: use single remoting call for batched config changes
    
    The preference dialog is pushing each config key and value to the UserConfig
    class which then pushes each key to the remote engine. This was making the
    preference dialog not responding for a long time with remote engines.
    
    Now the preference dialog will collect all settings from the UI and then makes a
    single remoting call via the newly added UserConfig.SetAll() method. Since this
    is a new method exposed by the engine, the EngineProtocolVersion was bumped to
    0.14. With older remote engines the preference dialog still needs to push each
    key separately.

 src/Engine/Config/Config.cs                   |   13 +++++
 src/Engine/Config/UserConfig.cs               |   64 +++++++++++++++++++-----
 src/Engine/Engine.cs                          |   12 ++++-
 src/Frontend-GNOME/Views/PreferencesDialog.cs |   23 +++++++--
 4 files changed, 93 insertions(+), 19 deletions(-)
---
diff --git a/src/Engine/Config/Config.cs b/src/Engine/Config/Config.cs
index 59a91e6..dd9a410 100644
--- a/src/Engine/Config/Config.cs
+++ b/src/Engine/Config/Config.cs
@@ -686,6 +686,19 @@ namespace Smuxi.Engine
             }
         }
 
+        public void SetAll(IEnumerable<KeyValuePair<string, object>> settings)
+        {
+            if (settings == null) {
+                throw new ArgumentNullException("settings");
+            }
+
+            lock (m_Preferences) {
+                foreach (var setting in settings) {
+                    this[setting.Key] = setting.Value;
+                }
+            }
+        }
+
         public void Save()
         {
             Trace.Call();
diff --git a/src/Engine/Config/UserConfig.cs b/src/Engine/Config/UserConfig.cs
index 789e839..5f71a07 100644
--- a/src/Engine/Config/UserConfig.cs
+++ b/src/Engine/Config/UserConfig.cs
@@ -1,7 +1,7 @@
 /*
  * Smuxi - Smart MUltipleXed Irc
  *
- * Copyright (c) 2005-2006, 2010-2011, 2013, 2015 Mirco Bauer <meebey meebey net>
+ * Copyright (c) 2005-2006, 2010-2011, 2013, 2015, 2017 Mirco Bauer <meebey meebey net>
  *
  * Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
  *
@@ -98,18 +98,7 @@ namespace Smuxi.Engine
                 return obj;
             }
             set {
-                // ignore writing back overridden config keys
-                if (FrontendConfig != null && FrontendConfig[key] != null) {
-                    return;
-                }
-
-                // TODO: make remoting calls after a timeout and batch the update
-                _Config[_UserPrefix + key] = value;
-                
-                // update entry in cache
-                if (IsCaching) {
-                    _Cache[key] = value;
-                }
+                Set(key, value);
             }
         }
         
@@ -145,7 +134,54 @@ namespace Smuxi.Engine
                 _Cache.Clear();
             }
         }
-        
+
+        void Set(string key, object value)
+        {
+            if (key == null) {
+                throw new ArgumentNullException("key");
+            }
+            if (value == null) {
+                throw new ArgumentNullException("value");
+            }
+
+            // ignore writing back overridden config keys
+            if (FrontendConfig != null && FrontendConfig[key] != null) {
+                return;
+            }
+
+            // TODO: make remoting calls after a timeout and batch the update
+            _Config[_UserPrefix + key] = value;
+
+            // update entry in cache
+            if (IsCaching) {
+                _Cache[key] = value;
+            }
+        }
+
+        public void SetAll(IEnumerable<KeyValuePair<string, object>> settings)
+        {
+            if (settings == null) {
+                throw new ArgumentNullException("settings");
+            }
+
+            var filteredSettings = new Dictionary<string, object>();
+            foreach (var setting in settings) {
+                // ignore writing back overridden settings in the frontend config
+                if (FrontendConfig != null && FrontendConfig[setting.Key] != null) {
+                    continue;
+                }
+
+                filteredSettings.Add(setting.Key, setting.Value);
+                // update entry in cache
+                if (IsCaching) {
+                    _Cache[setting.Key] = setting.Value;
+                }
+            }
+
+            // REMOTING CALL
+            _Config.SetAll(filteredSettings);
+        }
+
         public void Remove(string key)
         {
             _Config.Remove(_UserPrefix + key);
diff --git a/src/Engine/Engine.cs b/src/Engine/Engine.cs
index 21f8063..ccc5313 100644
--- a/src/Engine/Engine.cs
+++ b/src/Engine/Engine.cs
@@ -67,7 +67,17 @@ namespace Smuxi.Engine
             get {
                 // major == compatibility
                 // minor == features
-                return new Version("0.13");
+                // in 0.11 added:
+                // ServerModel.Nickname
+                // ServerModel.Realname
+                // in 0.12 added:
+                // ChatModel.LastSeenMessage
+                // in 0.13 added:
+                // SessionManager.EngineAssemblyVersion
+                // SessionManager.EngineProtocolVersion
+                // in 0.14 added:
+                // Config.SetAll()
+                return new Version("0.14");
             }
         }
 
diff --git a/src/Frontend-GNOME/Views/PreferencesDialog.cs b/src/Frontend-GNOME/Views/PreferencesDialog.cs
index ec49b97..b171882 100644
--- a/src/Frontend-GNOME/Views/PreferencesDialog.cs
+++ b/src/Frontend-GNOME/Views/PreferencesDialog.cs
@@ -1,6 +1,6 @@
 // Smuxi - Smart MUltipleXed Irc
 //
-// Copyright (c) 2013 Mirco Bauer <meebey meebey net>
+// Copyright (c) 2013, 2016-2017 Mirco Bauer <meebey meebey net>
 //
 // Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
 //
@@ -144,6 +144,7 @@ namespace Smuxi.Frontend.Gnome
 
             // Filters
             FilterListWidget = new FilterListWidget(parent, Frontend.UserConfig);
+            // REMOTING CALL
             FilterListWidget.InitProtocols(Frontend.Session.GetSupportedProtocols());
             FilterListWidget.Load();
             f_FilterListBox.Add(FilterListWidget);
@@ -366,7 +367,8 @@ namespace Smuxi.Frontend.Gnome
         {
             Trace.Call();
 
-            var conf = Frontend.UserConfig;
+            var userConf = Frontend.UserConfig;
+            var conf = new Dictionary<string, object>();
 
             // manually handled widgets
             if (f_ProxySwitch.Active) {
@@ -396,7 +398,8 @@ namespace Smuxi.Frontend.Gnome
             // mapped widgets
             foreach (var confEntry in ConfigKeyToWidgetNameMap) {
                 var confKey = confEntry.Key;
-                var confValue = conf[confKey];
+                // get type from config value
+                var confValue = userConf[confKey];
                 var widgetId = confEntry.Value;
                 var widget = Builder.GetObject(widgetId);
                 if (widget is Gtk.SpinButton) {
@@ -444,7 +447,19 @@ namespace Smuxi.Frontend.Gnome
                 conf["Interface/Chat/BackgroundColor"] = String.Empty;
             }
 
-            conf.Save();
+            if (Frontend.EngineProtocolVersion >= new Version(0, 14)) {
+                // with >= 0.14 we can set many keys in a single call
+                // REMOTING CALL
+                userConf.SetAll(conf);
+            } else {
+                // < 0.14 we need to set key by key
+                foreach (var entry in conf) {
+                    // REMOTING CALL
+                    userConf[entry.Key] = entry.Value;
+                }
+            }
+            // REMOTING CALL
+            userConf.Save();
         }
 
         protected virtual void OnResponse(object sender, Gtk.ResponseArgs e)


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