pidgin: 1a425172: Remove a few layers of evil abstraction.

darkrain42 at pidgin.im darkrain42 at pidgin.im
Fri Jul 3 00:31:29 EDT 2009


-----------------------------------------------------------------
Revision: 1a425172514642f29633fdbae59b27b9931c47b4
Ancestor: 3d3979a3d6063d90682623139bc165f0673bd262
Author: darkrain42 at pidgin.im
Date: 2009-07-03T02:33:30
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/1a425172514642f29633fdbae59b27b9931c47b4

Modified files:
        pidgin/gtknotify.c

ChangeLog: 

Remove a few layers of evil abstraction.

-------------- next part --------------
============================================================
--- pidgin/gtknotify.c	a4affe72d7f48e27820c20d54d5e6cdf3e978f69
+++ pidgin/gtknotify.c	d743a83b04160e32c7f94a51c9dc5ea39180d6e5
@@ -105,6 +105,10 @@ struct _PidginNotifyDialog
 
 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 *pounce_dialog
 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
 }
 
 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 @@ email_response_cb(GtkDialog *dlg, gint i
 				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 @@ mail_window_focus_cb(GtkWidget *widget, 
 	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 @@ pidgin_notify_emails(PurpleConnection *g
 					   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 @@ pidgin_notify_emails(PurpleConnection *g
 		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 @@ pidgin_notify_uri(const char *uri)
 	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 @@ pidgin_get_dialog(PidginNotifyType type,
 
 	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 @@ pidgin_get_dialog(PidginNotifyType type,
 	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,72 +1557,9 @@ pidgin_get_dialog(PidginNotifyType type,
 		pounce_dialog = spec_dialog;
 	}
 
-	return spec_dialog->dialog;
-
+	return spec_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);
-}
-
 static void
 signed_off_cb(PurpleConnection *gc, gpointer unused)
 {


More information about the Commits mailing list