[smuxi: 148/179] Frontend-GNOME: handle unsuppported protocols nicely in ServerWidget



commit 7473ca049c979fa9082d6b927fbd5b68de809c1f
Author: Mirco Bauer <meebey meebey net>
Date:   Mon May 29 20:34:40 2017 +0800

    Frontend-GNOME: handle unsuppported protocols nicely in ServerWidget
    
    When older protocols get removed from Smuxi but they are still stored in the
    config and thus available in the UI. The frontend should not throw an
    ArgumentOutOfRangeException as that will lead to a forced shutdown of the
    frontend after the user has closed the crash dialog. Instead just show that
    the protocol is unsupported without any exceptions.

 po-Frontend-GNOME/POTFILES.in            |    1 +
 src/Frontend-GNOME/Views/ServerWidget.cs |   27 ++++++++++++++++++++-------
 2 files changed, 21 insertions(+), 7 deletions(-)
---
diff --git a/po-Frontend-GNOME/POTFILES.in b/po-Frontend-GNOME/POTFILES.in
index 4ab29fe..42c7eb2 100644
--- a/po-Frontend-GNOME/POTFILES.in
+++ b/po-Frontend-GNOME/POTFILES.in
@@ -22,6 +22,7 @@ src/Frontend-GNOME/Views/MessageTextView.cs
 src/Frontend-GNOME/Views/FilterListWidget.cs
 src/Frontend-GNOME/Views/PreferencesDialog.cs
 src/Frontend-GNOME/Views/ServerDialog.cs
+src/Frontend-GNOME/Views/ServerWidget.cs
 src/Frontend-GNOME/Views/Chats/ChatView.cs
 src/Frontend-GNOME/Views/Chats/GroupChatView.cs
 src/Frontend-GNOME/Views/Chats/ProtocolChatView.cs
diff --git a/src/Frontend-GNOME/Views/ServerWidget.cs b/src/Frontend-GNOME/Views/ServerWidget.cs
index dc30d01..f0d273b 100644
--- a/src/Frontend-GNOME/Views/ServerWidget.cs
+++ b/src/Frontend-GNOME/Views/ServerWidget.cs
@@ -1,6 +1,6 @@
 // Smuxi - Smart MUltipleXed Irc
 // 
-// Copyright (c) 2010-2014 Mirco Bauer <meebey meebey net>
+// Copyright (c) 2010-2015, 2017 Mirco Bauer <meebey meebey net>
 // 
 // Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
 // 
@@ -51,17 +51,24 @@ namespace Smuxi.Frontend.Gnome
                 int protocolPosition = -1;
                 int j = 0;
                 foreach (object[] row in store) {
-                    string protocolName = (string) row[0];
-                    if (protocolName == value) {
+                    var protocolId = (string) row[1];
+                    if (protocolId == value) {
                         protocolPosition = j;
                         break;
                     }
                     j++;
                 }
                 if (protocolPosition == -1) {
-                    throw new ArgumentOutOfRangeException(
-                        "Unsupported protocol: " + value
+                    var iter = store.AppendValues(
+                        String.Format(
+                            "{0} ({1})",
+                            value,
+                            _("Unsupported")
+                        ),
+                        value
                     );
+                    f_ProtocolComboBox.SetActiveIter(iter);
+                    return;
                 }
                 f_ProtocolComboBox.Active = protocolPosition;
             }
@@ -256,10 +263,11 @@ namespace Smuxi.Frontend.Gnome
             f_ProtocolComboBox.PackStart(cell, false);
             f_ProtocolComboBox.AddAttribute(cell, "text", 0);
 
-            Gtk.ListStore store = new Gtk.ListStore(typeof(string));
+            var store = new Gtk.ListStore(typeof(string),
+                                          typeof(string));
             // fill protocols in ListStore
             foreach (string protocol in protocols) {
-                store.AppendValues(protocol);
+                store.AppendValues(protocol, protocol);
             }
             store.SetSortColumnId(0, Gtk.SortType.Ascending);
             f_ProtocolComboBox.Model = store;
@@ -487,5 +495,10 @@ namespace Smuxi.Frontend.Gnome
                     break;
             }
         }
+
+        private static string _(string msg)
+        {
+            return Mono.Unix.Catalog.GetString(msg);
+        }
     }
 }


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