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.
This commit is contained in:
Michael Gratton 2020-03-16 13:10:03 +11:00 committed by Michael James Gratton
parent 88516377ca
commit feece66c6e
7 changed files with 21 additions and 129 deletions

View file

@ -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

View file

@ -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) {

View file

@ -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();
}

View file

@ -1,34 +1,26 @@
/*
* Copyright 2017 Michael Gratton <mike@vee.net>
* Copyright © 2017,2020 Michael Gratton <mike@vee.net>
*
* 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);
}
}

View file

@ -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',

View file

@ -1,80 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<template class="MainWindowInfoBar" parent="GtkInfoBar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<signal name="hide" handler="on_hide" after="yes" swapped="no"/>
<signal name="response" handler="on_info_bar_response" swapped="no"/>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can_focus">False</property>
<property name="spacing">6</property>
<property name="layout_style">end</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child internal-child="content_area">
<object class="GtkBox">
<property name="can_focus">False</property>
<property name="spacing">16</property>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="title">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label">Title</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="description">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label">Description.</property>
<property name="ellipsize">end</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<style>
<class name="sigh"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
</template>
</interface>

View file

@ -40,7 +40,6 @@
<file compressed="true" preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
<file compressed="true" preprocess="xml-stripblanks">main-toolbar.ui</file>
<file compressed="true" preprocess="xml-stripblanks">main-toolbar-menus.ui</file>
<file compressed="true" preprocess="xml-stripblanks">main-window-info-bar.ui</file>
<file compressed="true" preprocess="xml-stripblanks">password-dialog.glade</file>
<file compressed="true" preprocess="xml-stripblanks">problem-details-dialog.ui</file>
<file compressed="true">signature-web-view.js</file>