cpw.masca.notify: d0352326: Merge every notify messages just as was ...

masca at cpw.pidgin.im masca at cpw.pidgin.im
Tue May 11 21:40:55 EDT 2010


-----------------------------------------------------------------
Revision: d0352326dd80bf0907b912692459a42467b61284
Ancestor: bb509af7361c70ecbd27e52ed4d4d89250c506bb
Author: masca at cpw.pidgin.im
Date: 2010-05-12T01:35:50
Branch: im.pidgin.cpw.masca.notify
URL: http://d.pidgin.im/viewmtn/revision/info/d0352326dd80bf0907b912692459a42467b61284

Modified files:
        pidgin/gtknotify.c

ChangeLog: 

Merge every notify messages just as was done with pounces and email
notifications.  It brings consistency to notifications beside the fact
that I hate when I get home to find 10000 pop-ups.


-------------- next part --------------
============================================================
--- pidgin/gtknotify.c	022aa5cf8649fc4b4e6d56d4bd2ff0feb62dcaf0
+++ pidgin/gtknotify.c	54dd15afcb829a207a5c01da07352c4f3ee6db6e
@@ -63,6 +63,14 @@ typedef struct
 	char *pouncee;
 } PidginNotifyPounceData;
 
+typedef struct
+{
+	PurpleNotifyMsgType type;
+	char *title;
+	char *primary;
+	char *secondary;
+	GdkPixbuf *pixbuf;
+} PidginNotifyMsgData;
 
 typedef struct
 {
@@ -101,6 +109,15 @@ enum
 	COLUMNS_PIDGIN_POUNCE
 };
 
+enum
+{
+	PIDGIN_MSG_TYPE,
+	PIDGIN_MSG_TITLE,
+	PIDGIN_MSG_PRIMARY,
+	PIDGIN_MSG_SECONDARY,
+	PIDGIN_MSG_DATA,
+	COLUMNS_PIDGIN_MSG 
+};
 
 typedef struct _PidginNotifyDialog
 {
@@ -123,11 +140,13 @@ typedef enum
 {
 	PIDGIN_NOTIFY_MAIL,
 	PIDGIN_NOTIFY_POUNCE,
+	PIDGIN_NOTIFY_MESSAGE,
 	PIDGIN_NOTIFY_TYPES
 } PidginNotifyType;
 
 static PidginNotifyDialog *mail_dialog = NULL;
 static PidginNotifyDialog *pounce_dialog = NULL;
+static PidginNotifyDialog *message_dialog = NULL;
 
 static PidginNotifyDialog *pidgin_create_notification_dialog(PidginNotifyType type);
 static void *pidgin_notify_emails(PurpleConnection *gc, size_t count, gboolean detailed,
@@ -141,9 +160,47 @@ message_response_cb(GtkDialog *dialog, g
 message_response_cb(GtkDialog *dialog, gint id, GtkWidget *widget)
 {
 	purple_notify_close(PURPLE_NOTIFY_MESSAGE, widget);
+	gtk_widget_destroy(widget);
 }
 
 static void
+message_response_close(PidginNotifyDialog *dialog)
+{
+	GtkTreeIter iter;
+	PidginNotifyMsgData *data = NULL;
+
+	while (gtk_tree_model_get_iter_first(
+				GTK_TREE_MODEL(message_dialog->treemodel), &iter)) {
+		gtk_tree_model_get(GTK_TREE_MODEL(message_dialog->treemodel), &iter,
+				PIDGIN_MSG_DATA, &data,
+				-1);
+		gtk_tree_store_remove(message_dialog->treemodel, &iter);
+
+		g_object_unref(data->pixbuf);
+		g_free(data->title);
+		g_free(data->primary);
+		g_free(data->secondary);
+		g_free(data);
+	}
+
+	gtk_widget_destroy(message_dialog->dialog);
+	g_free(message_dialog);
+	message_dialog = NULL;
+}
+
+static void
+message_dialog_response_cb(GtkDialog *dialog, gint id, GtkWidget *widget)
+{
+	switch (id) {
+		case GTK_RESPONSE_CLOSE:
+		case GTK_RESPONSE_OK:
+		default:
+			message_response_close(message_dialog);
+
+	}
+}
+
+static void
 pounce_response_close(PidginNotifyDialog *dialog)
 {
 	GtkTreeIter iter;
@@ -486,17 +543,12 @@ searchresults_callback_wrapper_cb(GtkWid
 	g_list_free(row);
 }
 
-static void *
-pidgin_notify_message(PurpleNotifyMsgType type, const char *title,
-						const char *primary, const char *secondary)
+static GdkPixbuf *
+message_get_icon(PurpleNotifyMsgType type, const char *size)
 {
-	GtkWidget *dialog;
-	GtkWidget *hbox;
-	GtkWidget *label;
 	GtkWidget *img = NULL;
-	char label_text[2048];
+	GdkPixbuf *pixbuf = NULL;
 	const char *icon_name = NULL;
-	char *primary_esc, *secondary_esc;
 
 	switch (type)
 	{
@@ -516,13 +568,74 @@ pidgin_notify_message(PurpleNotifyMsgTyp
 			icon_name = NULL;
 			break;
 	}
+	
 
 	if (icon_name != NULL)
 	{
-		img = gtk_image_new_from_stock(icon_name, gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_HUGE));
-		gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
+		img = gtk_image_new();
+		pixbuf = gtk_widget_render_icon(img, icon_name, gtk_icon_size_from_name(size), NULL);
 	}
 
+	return pixbuf;
+}
+
+static void *
+pidgin_notify_message(PurpleNotifyMsgType type, const char *title,
+						const char *primary, const char *secondary)
+{
+	PidginNotifyMsgData *msg_data;
+	GtkTreeIter iter;
+	gboolean first;
+
+	first = (message_dialog == NULL);
+
+	if (first)
+		message_dialog = pidgin_create_notification_dialog(PIDGIN_NOTIFY_MESSAGE);
+
+	msg_data = g_new(PidginNotifyMsgData, 1);
+
+	msg_data->pixbuf = message_get_icon(type, PIDGIN_ICON_SIZE_TANGO_SMALL);
+	msg_data->type = type;
+	msg_data->title = g_strdup(title);
+	msg_data->primary = g_strdup(primary);
+	msg_data->secondary = g_strdup(secondary);
+
+	gtk_tree_store_append(message_dialog->treemodel, &iter, NULL);
+
+	gtk_tree_store_set(message_dialog->treemodel, &iter,
+			PIDGIN_MSG_TYPE, msg_data->pixbuf,
+			PIDGIN_MSG_TITLE, msg_data->title,
+			PIDGIN_MSG_PRIMARY, msg_data->primary,
+			PIDGIN_MSG_SECONDARY, msg_data->secondary,
+			PIDGIN_MSG_DATA, msg_data,
+			-1);
+
+	if (first) {
+		GtkTreeSelection *selection =
+				gtk_tree_view_get_selection(GTK_TREE_VIEW(message_dialog->treeview));
+		gtk_tree_selection_select_iter(selection, &iter);
+	}
+
+	gtk_widget_show_all(message_dialog->dialog);
+
+	return message_dialog->dialog;
+}
+
+static void *
+pidgin_notify_message_full(PurpleNotifyMsgType type, const char *title,
+						const char *primary, const char *secondary)
+{
+	GtkWidget *dialog;
+	GtkWidget *hbox;
+	GtkWidget *label;
+	GtkWidget *img = NULL;
+	GdkPixbuf *pixbuf;
+	char label_text[2048];
+	char *primary_esc, *secondary_esc;
+
+	pixbuf = message_get_icon(type, PIDGIN_ICON_SIZE_TANGO_HUGE);
+	img = gtk_image_new_from_pixbuf(pixbuf);
+
 	dialog = gtk_dialog_new_with_buttons(title ? title : PIDGIN_ALERT_TITLE,
 										 NULL, 0, GTK_STOCK_CLOSE,
 										 GTK_RESPONSE_CLOSE, NULL);
@@ -569,6 +682,28 @@ static void
 }
 
 static void
+message_row_activated_cb(GtkTreeView *tv, GtkTreePath *path,
+                       GtkTreeViewColumn *col, gpointer data)
+{
+	GtkTreeSelection *selection;
+	PidginNotifyMsgData *msg_data;
+	GtkTreeModel *model;
+	GtkTreeIter iter;
+
+	model = GTK_TREE_MODEL(message_dialog->treemodel);
+
+	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(message_dialog->treeview));
+
+	if (!gtk_tree_selection_get_selected(selection, &model, &iter) )
+		return;
+
+	gtk_tree_model_get(model, &iter, PIDGIN_MSG_DATA, &msg_data, -1);
+
+	pidgin_notify_message_full(msg_data->type, msg_data->title,
+			msg_data->primary, msg_data->secondary);
+}
+
+static void
 selection_changed_cb(GtkTreeSelection *sel, PidginNotifyDialog *dialog)
 {
 	GtkTreeIter iter;
@@ -1489,6 +1624,12 @@ pidgin_create_notification_dialog(Pidgin
 		model = gtk_tree_store_new(COLUMNS_PIDGIN_POUNCE,
 				GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
 				G_TYPE_STRING, G_TYPE_POINTER);
+
+	} else if (type == PIDGIN_NOTIFY_MESSAGE) {
+		g_return_val_if_fail(message_dialog == NULL, message_dialog);
+
+		model = gtk_tree_store_new(COLUMNS_PIDGIN_MSG,
+				GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
 	}
 
 	dialog = gtk_dialog_new();
@@ -1624,6 +1765,57 @@ pidgin_create_notification_dialog(Pidgin
 			G_CALLBACK(pounce_row_selected_cb), NULL);
 		g_signal_connect(G_OBJECT(spec_dialog->treeview), "row-activated",
 			G_CALLBACK(pounce_response_open_ims), NULL);
+
+	} else if (type == PIDGIN_NOTIFY_MESSAGE) {
+
+		gtk_window_set_title(GTK_WINDOW(dialog), _("New Message"));
+
+		button = gtk_dialog_add_button(GTK_DIALOG(dialog),
+				GTK_STOCK_OK, GTK_RESPONSE_OK);
+
+		g_signal_connect(G_OBJECT(dialog), "response",
+						 G_CALLBACK(message_dialog_response_cb), spec_dialog);
+
+		column = gtk_tree_view_column_new();
+		gtk_tree_view_column_set_title(column, _("Type"));
+		gtk_tree_view_column_set_resizable(column, TRUE);
+		rend = gtk_cell_renderer_pixbuf_new();
+		gtk_tree_view_column_pack_start(column, rend, FALSE);
+
+		gtk_tree_view_column_set_attributes(column, rend, "pixbuf", PIDGIN_MSG_TYPE, NULL);
+		gtk_tree_view_append_column(GTK_TREE_VIEW(spec_dialog->treeview), column);
+
+		column = gtk_tree_view_column_new();
+		gtk_tree_view_column_set_title(column, _("Title"));
+		gtk_tree_view_column_set_resizable(column, TRUE);
+		rend = gtk_cell_renderer_text_new();
+		gtk_tree_view_column_pack_start(column, rend, FALSE);
+		gtk_tree_view_column_add_attribute(column, rend, "text", PIDGIN_MSG_PRIMARY);
+		gtk_tree_view_append_column(GTK_TREE_VIEW(spec_dialog->treeview), column);
+
+		column = gtk_tree_view_column_new();
+		gtk_tree_view_column_set_title(column, _("Primary"));
+		gtk_tree_view_column_set_resizable(column, TRUE);
+		rend = gtk_cell_renderer_text_new();
+		gtk_tree_view_column_pack_start(column, rend, FALSE);
+		gtk_tree_view_column_add_attribute(column, rend, "text", PIDGIN_MSG_PRIMARY);
+		gtk_tree_view_append_column(GTK_TREE_VIEW(spec_dialog->treeview), column);
+
+		column = gtk_tree_view_column_new();
+		gtk_tree_view_column_set_title(column, _("Secondary"));
+		gtk_tree_view_column_set_resizable(column, TRUE);
+		rend = gtk_cell_renderer_text_new();
+		gtk_tree_view_column_pack_start(column, rend, FALSE);
+		gtk_tree_view_column_add_attribute(column, rend, "text", PIDGIN_MSG_SECONDARY);
+		gtk_tree_view_append_column(GTK_TREE_VIEW(spec_dialog->treeview), column);
+
+		label = gtk_label_new(NULL);
+		gtk_label_set_markup(GTK_LABEL(label), _("<span weight=\"bold\" size=\"larger\">You have a message!</span>"));
+
+		sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(spec_dialog->treeview));
+		gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
+		g_signal_connect(G_OBJECT(spec_dialog->treeview), "row-activated",
+			G_CALLBACK(message_row_activated_cb), NULL);
 	}
 
 	button = gtk_dialog_add_button(GTK_DIALOG(dialog),


More information about the Commits mailing list