From feece66c6e5f7eabfe54905ad63c78970b9b2a09 Mon Sep 17 00:00:00 2001 From: Michael Gratton Date: Mon, 16 Mar 2020 13:10:03 +1100 Subject: [PATCH] MainWindowInfobar: Rename and derive from common InfoBar widget Rename to Components.ProblemReportInfoBar to better describe what it does, and to fit with the code convention for package and file names. Derive from Components.InfoBar so we can drop the custom GTK Builder file for it. --- po/POTFILES.in | 3 +- .../application/application-controller.vala | 6 +- .../application/application-main-window.vala | 8 +- ...> components-problem-report-info-bar.vala} | 50 +++--------- src/client/meson.build | 2 +- ui/main-window-info-bar.ui | 80 ------------------- ui/org.gnome.Geary.gresource.xml | 1 - 7 files changed, 21 insertions(+), 129 deletions(-) rename src/client/components/{main-window-info-bar.vala => components-problem-report-info-bar.vala} (77%) delete mode 100644 ui/main-window-info-bar.ui diff --git a/po/POTFILES.in b/po/POTFILES.in index 4db962c4..2859b0c0 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -41,13 +41,13 @@ src/client/components/components-info-bar.vala src/client/components/components-inspector.vala src/client/components/components-placeholder-pane.vala src/client/components/components-preferences-window.vala +src/client/components/components-problem-report-info-bar.vala src/client/components/components-search-bar.vala src/client/components/components-validator.vala src/client/components/count-badge.vala src/client/components/folder-popover.vala src/client/components/icon-factory.vala src/client/components/main-toolbar.vala -src/client/components/main-window-info-bar.vala src/client/components/monitored-progress-bar.vala src/client/components/monitored-spinner.vala src/client/components/status-bar.vala @@ -449,7 +449,6 @@ ui/folder-popover.ui ui/gtk/help-overlay.ui ui/main-toolbar.ui ui/main-toolbar-menus.ui -ui/main-window-info-bar.ui ui/password-dialog.glade ui/problem-details-dialog.ui ui/upgrade_dialog.glade diff --git a/src/client/application/application-controller.vala b/src/client/application/application-controller.vala index 75ccb0cf..4a149596 100644 --- a/src/client/application/application-controller.vala +++ b/src/client/application/application-controller.vala @@ -444,9 +444,9 @@ internal class Application.Controller : Geary.BaseObject { if (report.error == null || !(report.error.thrown is IOError.CANCELLED)) { - MainWindowInfoBar info_bar = new MainWindowInfoBar.for_problem(report); + var info_bar = new Components.ProblemReportInfoBar(report); info_bar.retry.connect(on_retry_problem); - this.application.get_active_main_window().show_infobar(info_bar); + this.application.get_active_main_window().show_info_bar(info_bar); } Geary.ServiceProblemReport? service_report = @@ -1589,7 +1589,7 @@ internal class Application.Controller : Geary.BaseObject { report_problem(problem); } - private void on_retry_problem(MainWindowInfoBar info_bar) { + private void on_retry_problem(Components.ProblemReportInfoBar info_bar) { Geary.ServiceProblemReport? service_report = info_bar.report as Geary.ServiceProblemReport; if (service_report != null) { diff --git a/src/client/application/application-main-window.vala b/src/client/application/application-main-window.vala index 31d8ba8b..a2609eaa 100644 --- a/src/client/application/application-main-window.vala +++ b/src/client/application/application-main-window.vala @@ -348,7 +348,7 @@ public class Application.MainWindow : [GtkChild] private Gtk.InfoBar auth_problem_infobar; - private MainWindowInfoBar? service_problem_infobar = null; + private Components.ProblemReportInfoBar? service_problem_infobar = null; /** Fired when the user requests an account status be retried. */ public signal void retry_service_problem(Geary.ClientService.Status problem); @@ -607,7 +607,7 @@ public class Application.MainWindow : ? problem_source.incoming : problem_source.outgoing ); - this.service_problem_infobar = new MainWindowInfoBar.for_problem( + this.service_problem_infobar = new Components.ProblemReportInfoBar( new Geary.ServiceProblemReport( problem_source.information, service.configuration, @@ -616,7 +616,7 @@ public class Application.MainWindow : ); this.service_problem_infobar.retry.connect(on_service_problem_retry); - show_infobar(this.service_problem_infobar); + show_info_bar(this.service_problem_infobar); } this.offline_infobar.set_visible(show_offline); @@ -833,7 +833,7 @@ public class Application.MainWindow : } /** Displays an infobar in the window. */ - public void show_infobar(MainWindowInfoBar info_bar) { + public void show_info_bar(Gtk.InfoBar info_bar) { this.info_bar_container.add(info_bar); this.info_bar_frame.show(); } diff --git a/src/client/components/main-window-info-bar.vala b/src/client/components/components-problem-report-info-bar.vala similarity index 77% rename from src/client/components/main-window-info-bar.vala rename to src/client/components/components-problem-report-info-bar.vala index 5b20660c..63a6dfa1 100644 --- a/src/client/components/main-window-info-bar.vala +++ b/src/client/components/components-problem-report-info-bar.vala @@ -1,34 +1,26 @@ /* - * Copyright 2017 Michael Gratton + * Copyright © 2017,2020 Michael Gratton * * This software is licensed under the GNU Lesser General Public License * (version 2.1 or later). See the COPYING file in this distribution. */ /** - * Displays application-wide or important account-related messages. + * Displays a Geary problem report as an info bar. */ -[GtkTemplate (ui = "/org/gnome/Geary/main-window-info-bar.ui")] -public class MainWindowInfoBar : Gtk.InfoBar { +public class Components.ProblemReportInfoBar : InfoBar { private enum ResponseType { DETAILS, RETRY; } /** If reporting a problem, returns the problem report else null. */ - public Geary.ProblemReport? report { get; private set; default = null; } + public Geary.ProblemReport report { get; private set; } /** Emitted when the user clicks the Retry button, if any. */ public signal void retry(); - [GtkChild] - private Gtk.Label title; - - [GtkChild] - private Gtk.Label description; - - - public MainWindowInfoBar.for_problem(Geary.ProblemReport report) { + public ProblemReportInfoBar(Geary.ProblemReport report) { Gtk.MessageType type = Gtk.MessageType.WARNING; string title = ""; string descr = ""; @@ -89,9 +81,12 @@ public class MainWindowInfoBar : Gtk.InfoBar { ); } - // Only show a close button if retrying not possible - this(type, title, descr, (retry == null)); + base(title, descr); + this.message_type = type; this.report = report; + this.show_close_button = (retry == null); + + this.response.connect(on_info_bar_response); if (this.report.error != null) { // Translators: Button label for viewing technical details @@ -110,21 +105,6 @@ public class MainWindowInfoBar : Gtk.InfoBar { } } - protected MainWindowInfoBar(Gtk.MessageType type, - string title, - string description, - bool show_close) { - this.message_type = type; - this.title.label = title; - - // Set the label and tooltip for the description in case it is - // long enough to be ellipsized - this.description.label = description; - this.description.tooltip_text = description; - - this.show_close_button = show_close; - } - private void show_details() { var main = get_toplevel() as Application.MainWindow; if (main != null) { @@ -138,7 +118,6 @@ public class MainWindowInfoBar : Gtk.InfoBar { } } - [GtkCallback] private void on_info_bar_response(int response) { switch(response) { case ResponseType.DETAILS: @@ -147,18 +126,13 @@ public class MainWindowInfoBar : Gtk.InfoBar { case ResponseType.RETRY: retry(); - this.hide(); + this.revealed = false; break; default: - this.hide(); + this.revealed = false; break; } } - [GtkCallback] - private void on_hide() { - this.parent.remove(this); - } - } diff --git a/src/client/meson.build b/src/client/meson.build index de4c651e..1ab46740 100644 --- a/src/client/meson.build +++ b/src/client/meson.build @@ -42,6 +42,7 @@ geary_client_vala_sources = files( 'components/components-inspector-system-view.vala', 'components/components-placeholder-pane.vala', 'components/components-preferences-window.vala', + 'components/components-problem-report-info-bar.vala', 'components/components-reflow-box.c', 'components/components-search-bar.vala', 'components/components-validator.vala', @@ -49,7 +50,6 @@ geary_client_vala_sources = files( 'components/folder-popover.vala', 'components/icon-factory.vala', 'components/main-toolbar.vala', - 'components/main-window-info-bar.vala', 'components/monitored-progress-bar.vala', 'components/monitored-spinner.vala', 'components/status-bar.vala', diff --git a/ui/main-window-info-bar.ui b/ui/main-window-info-bar.ui deleted file mode 100644 index f649291d..00000000 --- a/ui/main-window-info-bar.ui +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - diff --git a/ui/org.gnome.Geary.gresource.xml b/ui/org.gnome.Geary.gresource.xml index f74a48e8..f0d5b32c 100644 --- a/ui/org.gnome.Geary.gresource.xml +++ b/ui/org.gnome.Geary.gresource.xml @@ -40,7 +40,6 @@ gtk/help-overlay.ui main-toolbar.ui main-toolbar-menus.ui - main-window-info-bar.ui password-dialog.glade problem-details-dialog.ui signature-web-view.js