changeset 27256:c245c583a1a6

Remove a few layers of evil abstraction.
author Paul Aurich <paul@darkrain42.org>
date Fri, 03 Jul 2009 02:33:30 +0000
parents 357405dc8b2c
children c7768f23f519
files pidgin/gtknotify.c
diffstat 1 files changed, 85 insertions(+), 91 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtknotify.c	Fri Jul 03 02:13:39 2009 +0000
+++ b/pidgin/gtknotify.c	Fri Jul 03 02:33:30 2009 +0000
@@ -105,6 +105,10 @@
 
 struct _PidginNotifyDialog
 {
+	/*
+	 * This must be first so PidginNotifyDialog can masquerade as the
+	 * dialog widget.
+	 */
 	GtkWidget *dialog;
 	GtkWidget *treeview;
 	GtkTreeStore *treemodel;
@@ -126,7 +130,7 @@
 static PidginNotifyDialog *mail_dialog = NULL;
 static PidginNotifyDialog *pounce_dialog = NULL;
 
-static GtkWidget *pidgin_get_notification_dialog(PidginNotifyType type);
+static PidginNotifyDialog *pidgin_get_notification_dialog(PidginNotifyType type);
 static void *pidgin_notify_emails(PurpleConnection *gc, size_t count, gboolean detailed,
 									const char **subjects,
 									const char **froms, const char **tos,
@@ -294,6 +298,16 @@
 }
 
 static void
+reset_mail_dialog(GtkDialog *unused)
+{
+	if (mail_dialog->in_use)
+		return;
+	gtk_widget_destroy(mail_dialog->dialog);
+	g_free(mail_dialog);
+	mail_dialog = NULL;
+}
+
+static void
 email_response_cb(GtkDialog *dlg, gint id, PidginMailDialog *dialog)
 {
 	PidginNotifyMailData *data = NULL;
@@ -342,25 +356,14 @@
 				pidgin_close_notify(PURPLE_NOTIFY_EMAILS, data);
 		}
 	}
-	gtk_widget_destroy(dialog->dialog);
-	g_free(dialog);
-	mail_dialog = NULL;
+
+	reset_mail_dialog(NULL);
 }
 
 static void email_row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data) {
 	email_response_cb(GTK_DIALOG(mail_dialog->dialog), GTK_RESPONSE_YES, mail_dialog);
 }
 
-static void
-reset_mail_dialog(GtkDialog *dialog)
-{
-	if (mail_dialog->in_use)
-		return;
-	gtk_widget_destroy(mail_dialog->dialog);
-	g_free(mail_dialog);
-	mail_dialog = NULL;
-}
-
 static gboolean
 formatted_close_cb(GtkWidget *win, GdkEvent *event, void *user_data)
 {
@@ -526,12 +529,6 @@
 	return 0;
 }
 
-static GtkWidget *
-pidgin_get_mail_dialog(void)
-{
-	return pidgin_get_notification_dialog(PIDGIN_NOTIFY_MAIL);
-}
-
 /* count == 0 means this is a detailed mail notification.
  * count > 0 mean non-detailed.
  */
@@ -613,7 +610,8 @@
 					   const char **subjects, const char **froms,
 					   const char **tos, const char **urls)
 {
-	GtkWidget *dialog = NULL;
+	PidginNotifyDialog *notification_dialog;
+	GtkWidget *dialog;
 	char *notification;
 	PurpleAccount *account;
 	PidginNotifyMailData *data = NULL, *data2;
@@ -624,7 +622,9 @@
 		return NULL;
 
 	account = purple_connection_get_account(gc);
-	dialog = pidgin_get_mail_dialog();  /* This creates mail_dialog if necessary */
+	/* This creates the mail dialog (mail_dialog) if necessary */
+	notification_dialog = pidgin_get_notification_dialog(PIDGIN_NOTIFY_MAIL);
+	dialog = notification_dialog->dialog;
 
 	mail_dialog->total_count += count;
 	if (detailed) {
@@ -1344,9 +1344,49 @@
 	return NULL;
 }
 
-static GtkWidget *
-pidgin_get_dialog(PidginNotifyType type, GtkTreeStore *treemodel)
+void
+pidgin_notify_pounce_add(PurpleAccount *account, PurplePounce *pounce,
+		const char *alias, const char *event, const char *message, const char *date)
 {
+	PidginNotifyDialog *notification_dialog;
+	GtkWidget *dialog;
+	GdkPixbuf *icon;
+	GtkTreeIter iter;
+	PidginNotifyPounceData *pounce_data;
+
+	notification_dialog = pidgin_get_notification_dialog(PIDGIN_NOTIFY_POUNCE);
+	dialog = notification_dialog->dialog;
+
+	icon = pidgin_create_prpl_icon(account, PIDGIN_PRPL_ICON_SMALL);
+
+	pounce_data = g_new(PidginNotifyPounceData, 1);
+
+	pounce_data->account = account;
+	pounce_data->pounce = pounce;
+
+	gtk_tree_store_append(pounce_dialog->treemodel, &iter, NULL);
+
+	gtk_tree_store_set(pounce_dialog->treemodel, &iter,
+			PIDGIN_POUNCE_ICON, icon,
+			PIDGIN_POUNCE_ALIAS, alias,
+			PIDGIN_POUNCE_EVENT, event,
+			PIDGIN_POUNCE_TEXT, (message != NULL)? message : _("No message"),
+			PIDGIN_POUNCE_DATE, date,
+			PIDGIN_POUNCE_DATA, pounce_data,
+			-1);
+
+	if (icon)
+		g_object_unref(icon);
+
+	gtk_widget_show_all(dialog);
+
+	return;
+}
+
+static PidginNotifyDialog *
+pidgin_get_notification_dialog(PidginNotifyType type)
+{
+	GtkTreeStore *model = NULL;
 	GtkWidget *dialog = NULL;
 	GtkWidget *label = NULL;
 	GtkWidget *sw;
@@ -1359,6 +1399,23 @@
 
 	g_return_val_if_fail(type < PIDGIN_NOTIFY_TYPES, NULL);
 
+	if (type == PIDGIN_NOTIFY_MAIL) {
+		if (mail_dialog != NULL)
+			return mail_dialog;
+
+		model = gtk_tree_store_new(COLUMNS_PIDGIN_MAIL,
+						GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER);
+
+	} else if (type == PIDGIN_NOTIFY_POUNCE) {
+
+		if (pounce_dialog != NULL)
+			return pounce_dialog;
+
+		model = gtk_tree_store_new(PIDGIN_POUNCE_COLUMNS,
+				GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
+				G_TYPE_STRING, G_TYPE_POINTER);
+	}
+
 	dialog = gtk_dialog_new_with_buttons(NULL, NULL, 0,
 			GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
 			NULL);
@@ -1382,9 +1439,9 @@
 	spec_dialog = g_new0(PidginNotifyDialog, 1);
 	spec_dialog->dialog = dialog;
 
-	spec_dialog->treemodel = treemodel;
-	spec_dialog->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(spec_dialog->treemodel));
-	g_object_unref(G_OBJECT(spec_dialog->treemodel));
+	spec_dialog->treemodel = model;
+	spec_dialog->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
+	g_object_unref(G_OBJECT(model));
 
 	gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(spec_dialog->treeview), TRUE);
 	gtk_container_add(GTK_CONTAINER(sw), spec_dialog->treeview);
@@ -1500,70 +1557,7 @@
 		pounce_dialog = spec_dialog;
 	}
 
-	return spec_dialog->dialog;
-
-}
-
-void
-pidgin_notify_pounce_add(PurpleAccount *account, PurplePounce *pounce,
-		const char *alias, const char *event, const char *message, const char *date)
-{
-	GtkWidget *dialog;
-	GdkPixbuf *icon;
-	GtkTreeIter iter;
-	PidginNotifyPounceData *pounce_data;
-
-	dialog = pidgin_get_notification_dialog(PIDGIN_NOTIFY_POUNCE);
-
-	icon = pidgin_create_prpl_icon(account, PIDGIN_PRPL_ICON_SMALL);
-
-	pounce_data = g_new(PidginNotifyPounceData, 1);
-
-	pounce_data->account = account;
-	pounce_data->pounce = pounce;
-
-	gtk_tree_store_append(pounce_dialog->treemodel, &iter, NULL);
-
-	gtk_tree_store_set(pounce_dialog->treemodel, &iter,
-			PIDGIN_POUNCE_ICON, icon,
-			PIDGIN_POUNCE_ALIAS, alias,
-			PIDGIN_POUNCE_EVENT, event,
-			PIDGIN_POUNCE_TEXT, (message != NULL)? message : _("No message"),
-			PIDGIN_POUNCE_DATE, date,
-			PIDGIN_POUNCE_DATA, pounce_data,
-			-1);
-
-	if (icon)
-		g_object_unref(icon);
-
-	gtk_widget_show_all(dialog);
-
-	return;
-}
-
-static GtkWidget *
-pidgin_get_notification_dialog(PidginNotifyType type)
-{
-	GtkTreeStore *model = NULL;
-
-	if (type == PIDGIN_NOTIFY_MAIL) {
-		if (mail_dialog != NULL)
-			return mail_dialog->dialog;
-
-		model = gtk_tree_store_new(COLUMNS_PIDGIN_MAIL,
-						GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER);
-
-	} else if (type == PIDGIN_NOTIFY_POUNCE) {
-
-		if (pounce_dialog != NULL)
-			return pounce_dialog->dialog;
-
-		model = gtk_tree_store_new(PIDGIN_POUNCE_COLUMNS,
-				GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
-				G_TYPE_STRING, G_TYPE_POINTER);
-	}
-
-	return pidgin_get_dialog(type, model);
+	return spec_dialog;
 }
 
 static void