changeset 13015:2d71d4081e06

[gaim-migrate @ 15368] Alright, no beta tonight, I need sleep :-( We'll do it soon. Here's my implementation for connection error reporting. It's currently ugly, but I think you'll get the idea. Is this acceptable to people? I might not have a lot of time to finish this up on Monday. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 23 Jan 2006 08:08:33 +0000
parents 5efbb0162f86
children 8acf409a2d5f
files src/gtkblist.c src/gtkblist.h src/gtkconn.c
diffstat 3 files changed, 102 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkblist.c	Mon Jan 23 06:54:29 2006 +0000
+++ b/src/gtkblist.c	Mon Jan 23 08:08:33 2006 +0000
@@ -3309,6 +3309,8 @@
 	GaimGtkBuddyList *gtkblist;
 
 	gtkblist = g_new0(GaimGtkBuddyList, 1);
+	gtkblist->connection_errors = g_hash_table_new_full(g_direct_hash,
+												g_direct_equal, NULL, g_free);
 	blist->ui_data = gtkblist;
 }
 
@@ -3460,6 +3462,78 @@
 	return FALSE;
 }
 
+/***********************************/
+/* Connection error handling stuff */
+/***********************************/
+
+static void
+connection_error_button_clicked_cb(GtkButton *widget, gpointer user_data)
+{
+	GaimAccount *account;
+	char *text;
+
+	account = user_data;
+	text = g_hash_table_lookup(gtkblist->connection_errors, account);
+	gaim_notify_formatted(NULL, _("Connection Error"),
+						  _("Connection Error"), NULL, text, NULL, NULL);
+	gtk_widget_destroy(GTK_WIDGET(widget));
+	g_hash_table_remove(gtkblist->connection_errors, account);
+}
+
+/* Add some buttons that show connection errors */
+static void
+create_connection_error_buttons(gpointer key, gpointer value, gpointer user_data)
+{
+	GaimAccount *account;
+	gchar *text;
+	GtkWidget *button;
+
+	account = key;
+	text = value;
+
+	/*
+	 * TODO: The text needs to be bold and red.  And it would probably
+	 *       be better if we displayed something like
+	 *       "MarkDoliner disconnected: Invalid passw..."
+	 *       And we DEFINITELY need to show an icon on the left side.
+	 *       It should be the PRPL icon overlayed with something that
+	 *       will signal to the user that the account had an error.
+	 */
+	button = gtk_button_new_with_label(text);
+	g_signal_connect(G_OBJECT(button), "clicked",
+					 G_CALLBACK(connection_error_button_clicked_cb),
+					 account);
+	gtk_widget_show(button);
+	gtk_box_pack_end(GTK_BOX(gtkblist->error_buttons), button, FALSE, FALSE, 0);
+}
+
+void
+gaim_gtk_blist_update_account_error_state(GaimAccount *account, const char *text)
+{
+	GList *l;
+
+	if (message == NULL)
+		g_hash_table_remove(gtkblist->connection_errors, account);
+	else
+		g_hash_table_insert(gtkblist->connection_errors, account, g_strdup(text));
+
+	/* Remove the old error buttons */
+	for (l = gtk_container_get_children(GTK_CONTAINER(gtkblist->error_buttons));
+			l != NULL;
+			l = l->next)
+	{
+		gtk_widget_destroy(GTK_WIDGET(l->data));
+	}
+
+	/* Add new error buttons */
+	g_hash_table_foreach(gtkblist->connection_errors,
+			create_connection_error_buttons, NULL);
+}
+
+/******************************************/
+/* End of connection error handling stuff */
+/******************************************/
+
 static void gaim_gtk_blist_show(GaimBuddyList *list)
 {
 	void *handle;
@@ -3610,6 +3684,11 @@
 	gtk_container_add(GTK_CONTAINER(sw), gtkblist->treeview);
 	gaim_gtk_blist_update_columns();
 
+	/* Create an empty vbox used for showing connection errors */
+	gtkblist->error_buttons = gtk_vbox_new(FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtkblist->error_buttons, FALSE, FALSE, 0);
+
+	/* Add the statusbox */
 	gtkblist->statusbox = gtk_gaim_status_box_new();
 	gtk_widget_set_name(gtkblist->statusbox, "gaim_gtkblist_statusbox");
 
@@ -4184,6 +4263,7 @@
 	if (gtkblist->drag_timeout)
 		g_source_remove(gtkblist->drag_timeout);
 
+	g_hash_table_destroy(gtkblist->connection_errors);
 	gtkblist->refresh_timer = 0;
 	gtkblist->timeout = 0;
 	gtkblist->drag_timeout = 0;
@@ -4192,6 +4272,7 @@
 	gtkblist->idle_column = NULL;
 	gtkblist->buddy_icon_column = NULL;
 	g_object_unref(G_OBJECT(gtkblist->ift));
+	g_free(gtkblist);
 	accountmenu = NULL;
 	gtkblist = NULL;
 
--- a/src/gtkblist.h	Mon Jan 23 06:54:29 2006 +0000
+++ b/src/gtkblist.h	Mon Jan 23 08:08:33 2006 +0000
@@ -71,6 +71,8 @@
 	GtkWidget *menutray;            /**< The menu tray widget. */
 	GtkWidget *menutrayicon;        /**< The menu tray icon. */
 
+	GHashTable *connection_errors;  /**< Caches connection error messages and accounts. */
+
 	guint refresh_timer;            /**< The timer for refreshing every 30 seconds */
 
 	guint      timeout;              /**< The timeout for the tooltip. */
@@ -86,8 +88,9 @@
 	GtkWidget *tipwindow;            /**< The window used by the tooltip */
 	GList *tooltipdata;              /**< The data for each "chunk" of the tooltip */
 
-	GaimBlistNode *selected_node;   /**< The currently selected node */
-        GtkWidget *statusbox;            /**< The status selector dropdown */
+	GaimBlistNode *selected_node;    /**< The currently selected node */
+	GtkWidget *error_buttons;        /**< Box containing the connection error buttons */
+	GtkWidget *statusbox;            /**< The status selector dropdown */
 	GdkPixbuf *east, *south;                 /**< Drop shadow stuff */
 	GdkWindow *east_shadow, *south_shadow;   /**< Drop shadow stuff */
 
@@ -283,12 +286,25 @@
 
 /**
  * Appends the protocol specific menu items for a GaimBlistNode
+ * TODO: Rename these.
  */
 void gaim_gtk_append_blist_node_proto_menu (GtkWidget *menu, GaimConnection *gc, GaimBlistNode *node);
 
 /**
  * Appends the extended menu items for a GaimBlistNode
+ * TODO: Rename these.
  */
 void gaim_gtk_append_blist_node_extended_menu(GtkWidget *menu, GaimBlistNode *node);
 
+/**
+ * Used by the connection API to tell the blist if an account
+ * has a connection error or no longer has a connection error.
+ *
+ * @param account The account that either has a connection error
+ *        or no longer has a connection error.
+ * @param message The connection error message, or NULL if this
+ *        account is no longer in an error state.
+ */
+void gaim_gtk_blist_update_account_error_state(GaimAccount *account, const char *message);
+
 #endif /* _GAIM_GTKBLIST_H_ */
--- a/src/gtkconn.c	Mon Jan 23 06:54:29 2006 +0000
+++ b/src/gtkconn.c	Mon Jan 23 08:08:33 2006 +0000
@@ -84,6 +84,7 @@
 	if (g_hash_table_size(errored_accounts) > 0)
 	{
 		g_hash_table_remove(errored_accounts, account);
+		gaim_gtk_blist_update_account_error_state(account, NULL);
 		if (g_hash_table_size(errored_accounts) == 0)
 			gtk_gaim_status_box_set_error(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), NULL);
 	}
@@ -155,6 +156,7 @@
 	errored_account = g_hash_table_lookup(errored_accounts, account);
 
 	if (!gc->wants_to_die) {
+		gaim_gtk_blist_update_account_error_state(account, text);
 		if (gtkblist != NULL)
 			gtk_gaim_status_box_set_error(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), text);
 
@@ -232,6 +234,7 @@
 	if (g_hash_table_size(errored_accounts) > 0)
 	{
 		g_hash_table_remove(errored_accounts, account);
+		gaim_gtk_blist_update_account_error_state(account, NULL);
 		if (g_hash_table_size(errored_accounts) == 0)
 		{
 			GaimGtkBuddyList *gtkblist;