[geary/mjog/info-bar-cleanup: 49/50] Application.MainWindow: Convert to using InfoBarStack



commit 19fcf79957e1cd7f708ec9597a519063c36adbaa
Author: Michael Gratton <mike vee net>
Date:   Tue Mar 17 16:56:55 2020 +1100

    Application.MainWindow: Convert to using InfoBarStack
    
    Use an info bar stack to display info bars, so that at most one is ever
    shown. This will prioritise status messages (offline, service/auth/cert
    problems) over other misc errors, which means we might miss some, but
    I guess that's better than huge stacks of bars?
    
    Fixes #697
    
    May help with #406 as well in cases where there was a service error
    prior to going offline.

 .../application/application-main-window.vala       | 82 +++++++---------------
 1 file changed, 25 insertions(+), 57 deletions(-)
---
diff --git a/src/client/application/application-main-window.vala 
b/src/client/application/application-main-window.vala
index d337be10..160d5103 100644
--- a/src/client/application/application-main-window.vala
+++ b/src/client/application/application-main-window.vala
@@ -332,12 +332,8 @@ public class Application.MainWindow :
     [GtkChild]
     private Gtk.Overlay overlay;
 
-    // This is a frame so users can use F6/Shift-F6 to get to it
-    [GtkChild]
-    private Gtk.Frame info_bar_frame;
-
-    [GtkChild]
-    private Gtk.Grid info_bar_container;
+    private Components.InfoBarStack info_bars =
+        new Components.InfoBarStack.exclusive();
 
     private Gtk.InfoBar offline_infobar;
 
@@ -617,27 +613,15 @@ public class Application.MainWindow :
                                       bool has_auth_error,
                                       bool has_cert_error,
                                       Geary.Account? problem_source) {
-        // Only ever show one at a time. Offline is primary since
-        // nothing else can happen when offline. Service problems are
-        // secondary since auth and cert problems can't be resolved
-        // when the service isn't talking to the server. Cert problems
-        // are tertiary since you can't auth if you can't connect.
-        bool show_offline = false;
-        bool show_service = false;
-        bool show_cert = false;
-        bool show_auth = false;
-
+        // Only ever show one info bar at a time. Offline is primary
+        // since nothing else can happen when offline. Service
+        // problems are secondary since auth and cert problems can't
+        // be resolved when the service isn't talking to the
+        // server. Cert problems are tertiary since you can't auth if
+        // you can't connect.
         if (!status.is_online()) {
-            show_offline = true;
+            this.info_bars.add(this.offline_infobar);
         } else if (status.has_service_problem()) {
-            show_service = true;
-        } else if (has_cert_error) {
-            show_cert = true;
-        } else if (has_auth_error) {
-            show_auth = true;
-        }
-
-        if (show_service && this.service_problem_infobar == null) {
             Geary.ClientService? service = (
                 problem_source.incoming.last_error != null
                 ? problem_source.incoming
@@ -651,14 +635,14 @@ public class Application.MainWindow :
                 )
             );
             this.service_problem_infobar.retry.connect(on_service_problem_retry);
-
-            show_info_bar(this.service_problem_infobar);
+            this.info_bars.add(this.service_problem_infobar);
+        } else if (has_cert_error) {
+            this.info_bars.add(this.cert_problem_infobar);
+        } else if (has_auth_error) {
+            this.info_bars.add(this.auth_problem_infobar);
+        } else {
+            this.info_bars.remove_all();
         }
-
-        this.offline_infobar.set_visible(show_offline);
-        this.cert_problem_infobar.set_visible(show_cert);
-        this.auth_problem_infobar.set_visible(show_auth);
-        update_infobar_frame();
     }
 
     /**
@@ -870,8 +854,9 @@ public class Application.MainWindow :
 
     /** Displays an infobar in the window. */
     public void show_info_bar(Gtk.InfoBar info_bar) {
-        this.info_bar_container.add(info_bar);
-        this.info_bar_frame.show();
+        if (!this.info_bars.has_current) {
+            this.info_bars.add(info_bar);
+        }
     }
 
     /** Displays a composer addressed to a specific email address. */
@@ -1267,6 +1252,8 @@ public class Application.MainWindow :
             set_titlebar(titlebar);
         }
 
+        this.main_layout.pack_start(this.info_bars, false, true, 0);
+
         // Status bar
         this.status_bar.set_size_request(-1, STATUS_BAR_HEIGHT);
         this.status_bar.set_border_width(2);
@@ -1705,18 +1692,6 @@ public class Application.MainWindow :
             this.main_toolbar.folder = this.selected_folder.get_display_name();
     }
 
-    private void update_infobar_frame() {
-        // Ensure the info bar frame is shown only when it has visible
-        // children
-        bool show_frame = false;
-        this.info_bar_container.foreach((child) => {
-                if (child.visible) {
-                    show_frame = true;
-                }
-            });
-        this.info_bar_frame.set_visible(show_frame);
-    }
-
     private void update_conversation_actions(ConversationCount count) {
         bool sensitive = (count != NONE);
         bool multiple = (count == MULTIPLE);
@@ -1956,32 +1931,25 @@ public class Application.MainWindow :
     }
 
     private void on_offline_infobar_response() {
-        this.offline_infobar.hide();
-        update_infobar_frame();
+        this.info_bars.remove(this.offline_infobar);
     }
 
     private void on_service_problem_retry() {
+        this.info_bars.remove(this.service_problem_infobar);
         this.service_problem_infobar = null;
         retry_service_problem(Geary.ClientService.Status.CONNECTION_FAILED);
     }
 
     private void on_cert_problem_retry() {
-        this.cert_problem_infobar.hide();
-        update_infobar_frame();
+        this.info_bars.remove(this.cert_problem_infobar);
         retry_service_problem(Geary.ClientService.Status.TLS_VALIDATION_FAILED);
     }
 
     private void on_auth_problem_retry() {
-        this.auth_problem_infobar.hide();
-        update_infobar_frame();
+        this.info_bars.remove(this.auth_problem_infobar);
         retry_service_problem(Geary.ClientService.Status.AUTHENTICATION_FAILED);
     }
 
-    [GtkCallback]
-    private void on_info_bar_container_remove() {
-        update_infobar_frame();
-    }
-
     private void on_update_ui_timeout() {
         update_ui();
     }


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