1/* 2 * Copyright © 2017,2020 Michael Gratton <mike@vee.net> 3 * 4 * This software is licensed under the GNU Lesser General Public License 5 * (version 2.1 or later). See the COPYING file in this distribution. 6 */ 7 8/** 9 * Displays a Geary problem report as an info bar. 10 */ 11public class Components.ProblemReportInfoBar : InfoBar { 12 13 14 private enum ResponseType { DETAILS, RETRY; } 15 16 /** If reporting a problem, returns the problem report else null. */ 17 public Geary.ProblemReport report { get; private set; } 18 19 /** Emitted when the user clicks the Retry button, if any. */ 20 public signal void retry(); 21 22 23 public ProblemReportInfoBar(Geary.ProblemReport report) { 24 Gtk.MessageType type = Gtk.MessageType.WARNING; 25 string title = ""; 26 string descr = ""; 27 string? retry = null; 28 29 if (report is Geary.AccountProblemReport) { 30 Geary.AccountProblemReport account_report = 31 (Geary.AccountProblemReport) report; 32 string account_name = account_report.account.display_name; 33 34 // Translators: Info bar title for a generic account 35 // problem. 36 title = _("Account problem"); 37 // Translators: Info bar sub-title for a generic account 38 // problem. String substitution is the account name. 39 descr = _( 40 "Geary has encountered a problem with %s." 41 ).printf(account_name); 42 43 if (report is Geary.ServiceProblemReport) { 44 Geary.ServiceProblemReport service_report = 45 (Geary.ServiceProblemReport) report; 46 47 switch (service_report.service.protocol) { 48 case IMAP: 49 // Translators: Info bar sub-title for a generic 50 // account problem. String substitution is the 51 // account name. 52 descr = _( 53 "Geary encountered a problem checking mail for %s." 54 ).printf(account_name); 55 56 // Translators: Tooltip label for Retry button 57 retry = _("Try reconnecting"); 58 break; 59 60 case SMTP: 61 // Translators: Info bar title for an outgoing 62 // account problem. String substitution is the 63 // account name 64 descr = _( 65 "Geary encountered a problem sending email for %s." 66 ).printf(account_name); 67 68 // Translators: Tooltip label for Retry button 69 retry = _("Retry sending queued messages"); 70 break; 71 } 72 } 73 } else { 74 // Translators: Info bar title for a generic application 75 // problem. 76 title = _("Geary has encountered a problem"); 77 // Translators: Info bar sub-title for a generic 78 // application problem. 79 descr = _( 80 "Please report the details if it persists." 81 ); 82 } 83 84 base(title, descr); 85 this.message_type = type; 86 this.report = report; 87 this.show_close_button = (retry == null); 88 89 this.response.connect(on_info_bar_response); 90 91 if (this.report.error != null) { 92 // Translators: Button label for viewing technical details 93 // for a problem report. 94 Gtk.Button details = add_button(_("_Details"), ResponseType.DETAILS); 95 // Translators: Tooltip for viewing technical details for 96 // a problem report. 97 details.tooltip_text = _("View technical details about the error"); 98 } 99 100 if (retry != null) { 101 // Translators: Button label for retrying a server 102 // connection 103 Gtk.Button retry_btn = add_button(_("_Retry"), ResponseType.RETRY); 104 retry_btn.tooltip_text = retry; 105 } 106 } 107 108 private void show_details() { 109 var main = get_toplevel() as Application.MainWindow; 110 if (main != null) { 111 var dialog = new Dialogs.ProblemDetailsDialog( 112 main, 113 main.application, 114 this.report 115 ); 116 dialog.show(); 117 } 118 } 119 120 private void on_info_bar_response(int response) { 121 switch(response) { 122 case ResponseType.DETAILS: 123 show_details(); 124 break; 125 126 case ResponseType.RETRY: 127 retry(); 128 this.revealed = false; 129 break; 130 131 default: 132 this.revealed = false; 133 break; 134 } 135 } 136 137} 138