diff options
author | Gary Kramlich <grim@reaperworld.com> | 2023-03-30 22:55:10 -0500 |
---|---|---|
committer | Gary Kramlich <grim@reaperworld.com> | 2023-03-30 22:55:10 -0500 |
commit | 59bc819ed04fcb9b9a55d56d7a6473f9fddf9f7c (patch) | |
tree | 835917837d55afad855a3f85dc2c8e8835a20e9f | |
parent | f6965499277f8b18b3a6f157919359bfa033a11e (diff) | |
download | pidgin-59bc819ed04fcb9b9a55d56d7a6473f9fddf9f7c.tar.gz |
Add notifications when a saved plugin fails to load
I also did a first run at generic notifications.
Testing Done:
Forced some saved plugins to fail to load and verified in the notification list.
Bugs closed: PIDGIN-17711
Reviewed at https://reviews.imfreedom.org/r/2401/
-rw-r--r-- | libpurple/plugins.c | 39 | ||||
-rw-r--r-- | pidgin/pidginnotificationlist.c | 33 |
2 files changed, 68 insertions, 4 deletions
diff --git a/libpurple/plugins.c b/libpurple/plugins.c index e5fa71de3f..9afb9d2fb1 100644 --- a/libpurple/plugins.c +++ b/libpurple/plugins.c @@ -30,6 +30,8 @@ #include "debug.h" #include "plugins.h" #include "purpleenums.h" +#include "purplenotification.h" +#include "purplenotificationmanager.h" #include "signals.h" #include "util.h" #ifdef _WIN32 @@ -424,8 +426,9 @@ purple_plugins_load_saved(const char *key) for (l = files; l; l = l->next) { - char *file; PurplePlugin *plugin; + GError *error = NULL; + char *file; if (l->data == NULL) continue; @@ -434,10 +437,38 @@ purple_plugins_load_saved(const char *key) plugin = purple_plugins_find_by_filename(file); if (plugin) { - purple_debug_info("plugins", "Loading saved plugin %s\n", file); - purple_plugin_load(plugin, NULL); + purple_debug_info("plugins", "Loading saved plugin %s", file); + purple_plugin_load(plugin, &error); } else { - purple_debug_error("plugins", "Unable to find saved plugin %s\n", file); + error = g_error_new(PURPLE_PLUGINS_DOMAIN, 0, + _("Unable to find saved plugin %s"), file); + purple_debug_error("plugins", "Unable to find saved plugin %s", file); + } + + if(error != NULL) { + PurpleNotification *notification = NULL; + PurpleNotificationManager *manager = NULL; + char *msg = NULL; + char *title = NULL; + + if(error->message != NULL) { + msg = g_strdup(error->message); + } else { + msg = g_strdup(_("Unknown error")); + } + g_clear_error(&error); + + notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_GENERIC, + NULL, msg, g_free); + + purple_notification_set_icon_name(notification, + "dialog-error-symbolic"); + title = g_strdup_printf(_("Failed to load saved plugin %s"), file); + purple_notification_set_title(notification, title); + g_free(title); + + manager = purple_notification_manager_get_default(); + purple_notification_manager_add(manager, notification); } g_free(l->data); diff --git a/pidgin/pidginnotificationlist.c b/pidgin/pidginnotificationlist.c index 3df6100404..c9db9e04f4 100644 --- a/pidgin/pidginnotificationlist.c +++ b/pidgin/pidginnotificationlist.c @@ -41,6 +41,17 @@ G_DEFINE_TYPE(PidginNotificationList, pidgin_notification_list, GTK_TYPE_BOX) /****************************************************************************** * Helpers *****************************************************************************/ +static gboolean +pidgin_notification_gpointer_to_char(G_GNUC_UNUSED GBinding *binding, + const GValue *from_value, + GValue *to_value, + G_GNUC_UNUSED gpointer user_data) +{ + g_value_set_string(to_value, (char *)g_value_get_pointer(from_value)); + + return TRUE; +} + static GtkWidget * pidgin_notification_list_unknown_notification(PurpleNotification *notification) { GtkWidget *widget = NULL; @@ -65,6 +76,25 @@ pidgin_notification_list_unknown_notification(PurpleNotification *notification) } static GtkWidget * +pidgin_notification_generic_new(PurpleNotification *notification) { + GtkWidget *row = NULL; + + row = adw_action_row_new(); + g_object_bind_property(notification, "title", row, "title", + G_BINDING_SYNC_CREATE); + g_object_bind_property(notification, "icon-name", row, "icon-name", + G_BINDING_SYNC_CREATE); + g_object_bind_property_full(notification, "data", row, "subtitle", + G_BINDING_SYNC_CREATE, + pidgin_notification_gpointer_to_char, + NULL, + NULL, + NULL); + + return row; +} + +static GtkWidget * pidgin_notification_list_create_widget_func(gpointer item, G_GNUC_UNUSED gpointer data) { @@ -72,6 +102,9 @@ pidgin_notification_list_create_widget_func(gpointer item, GtkWidget *widget = NULL; switch(purple_notification_get_notification_type(notification)) { + case PURPLE_NOTIFICATION_TYPE_GENERIC: + widget = pidgin_notification_generic_new(notification); + break; case PURPLE_NOTIFICATION_TYPE_CONNECTION_ERROR: widget = pidgin_notification_connection_error_new(notification); break; |