pidgin/pidgin

b405b4eb38fa
Parents 613d42be784e
Children 98c20aec9aba
Display a dialog in Pidgin if purple_core_init returned FALSE

This also adds an environment variable so developers (or users for some reason)
can set a custom error message for purple_core_init to return. The intent is to
allow UI developers to control the message and make sure things display as they
expect them to.

Testing Done:
used the `PURPLE3_CORE_ERROR_MESSAGE` environment variable to test the dialog including one with multiple lines of `a`'s with no breaks and everything displayed fine.

Reviewed at https://reviews.imfreedom.org/r/2007/
--- a/libpurple/core.c Mon Oct 31 23:12:08 2022 -0500
+++ b/libpurple/core.c Tue Nov 01 00:03:51 2022 -0500
@@ -94,6 +94,7 @@
gboolean
purple_core_init(PurpleUi *ui, G_GNUC_UNUSED GError **error) {
PurpleCore *core;
+ const char *force_error_message = NULL;
g_return_val_if_fail(PURPLE_IS_UI(ui), FALSE);
g_return_val_if_fail(purple_get_core() == NULL, FALSE);
@@ -190,6 +191,22 @@
*/
purple_network_discover_my_ip();
+ /* Set this environment variable to anything to test the error reporting in
+ * the user interface.
+ */
+ force_error_message = g_getenv("PURPLE3_CORE_ERROR_MESSAGE");
+ if(force_error_message != NULL) {
+ if(force_error_message[0] == '\0') {
+ force_error_message = "This is a forced error for testing user "
+ "interfaces.";
+ }
+
+ g_set_error_literal(error, g_quark_from_static_string("purple"), 0,
+ force_error_message);
+
+ return FALSE;
+ }
+
purple_ui_start(core->ui);
/* Load the buddy list after UI init */
--- a/pidgin/pidginapplication.c Mon Oct 31 23:12:08 2022 -0500
+++ b/pidgin/pidginapplication.c Tue Nov 01 00:03:51 2022 -0500
@@ -712,6 +712,14 @@
}
}
+static void
+pidgin_application_error_reponse_cb(G_GNUC_UNUSED AdwMessageDialog *self,
+ G_GNUC_UNUSED char *response,
+ gpointer data)
+{
+ g_application_quit(data);
+}
+
/******************************************************************************
* GtkApplication Implementation
*****************************************************************************/
@@ -782,12 +790,30 @@
#endif
if(!purple_core_init(pidgin_ui_new(), &error)) {
- fprintf(stderr,
- _("Initialization of the libpurple core failed. %s\n"
- "Aborting!\nPlease report this!\n"),
- (error != NULL) ? error->message : "unknown error");
+ GtkWidget *message = NULL;
+ const char *error_message = "unknown error";
+
+ if(error != NULL) {
+ error_message = error->message;
+ }
+
+ message = adw_message_dialog_new(NULL,
+ _("Pidgin 3 failed to initialize"),
+ error_message);
g_clear_error(&error);
- g_abort();
+
+ adw_message_dialog_add_responses(ADW_MESSAGE_DIALOG(message),
+ "close", _("Close"), NULL);
+ adw_message_dialog_set_close_response(ADW_MESSAGE_DIALOG(message),
+ "close");
+
+ g_signal_connect(message, "response",
+ G_CALLBACK(pidgin_application_error_reponse_cb),
+ application);
+
+ gtk_window_present_with_time(GTK_WINDOW(message), GDK_CURRENT_TIME);
+
+ return;
}
pidgin_application_init_plugins();