changeset 15184:a505577b6f4b

[gaim-migrate @ 17973] I realized doing Gmail notifications that mail notifications spawn dialogs that are non-user-initiated. I no longer like this, so I came up with "headlines," non-critical alerts that appear at the top of the buddy list until they're clicked or a new headline is set. Now, when you get a new mail notification, a headline will appear saying "You have 60 new e-mails." When you click it, the old mail notification will show up. Also, it looks wicked awesome: http://gaim.sf.net/sean/images/headline.png committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Tue, 12 Dec 2006 08:53:35 +0000
parents 8b726534b00d
children 5e7764d15345
files gtk/gtkblist.c gtk/gtkblist.h gtk/gtknotify.c gtk/gtkscrollbook.c gtk/gtkutils.c
diffstat 5 files changed, 56 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/gtk/gtkblist.c	Tue Dec 12 08:52:46 2006 +0000
+++ b/gtk/gtkblist.c	Tue Dec 12 08:53:35 2006 +0000
@@ -3686,9 +3686,11 @@
 }
 
 static gboolean
-headline_box_press_cb(GtkWidget *widget, GdkEventButton *event, GaimGtkBuddyList *box)
+headline_box_press_cb(GtkWidget *widget, GdkEventButton *event, GaimGtkBuddyList *gtkblist)
 {
 	gtk_widget_hide(gtkblist->headline_hbox);
+	if (gtkblist->headline_callback)
+		g_idle_add(G_CALLBACK(gtkblist->headline_callback), gtkblist->headline_data);
 }
 
 /***********************************/
@@ -3812,8 +3814,8 @@
 
 static gboolean
 paint_headline_hbox  (GtkWidget      *widget,
-			  GdkEventExpose *event,
-			  gpointer        user_data)
+		      GdkEventExpose *event,
+		      gpointer        user_data)
 {
   gtk_paint_flat_box (widget->style, 
 		      widget->window,
@@ -3830,6 +3832,29 @@
   return FALSE;		      
 }
 
+static void
+headline_style_set (GtkWidget *widget,
+		    GtkStyle  *prev_style)
+{
+	GtkTooltips *tooltips;
+	GtkStyle *style;
+	
+	if (gtkblist->changing_style)
+		return;
+	
+	tooltips = gtk_tooltips_new ();
+	g_object_ref_sink (tooltips);
+
+	gtk_tooltips_force_window (tooltips);
+	gtk_widget_ensure_style (tooltips->tip_window);
+	style = gtk_widget_get_style (tooltips->tip_window);
+	
+	gtkblist->changing_style = TRUE;
+	gtk_widget_set_style (gtkblist->headline_hbox, style);
+	gtkblist->changing_style = FALSE;	
+	
+	g_object_unref (tooltips);
+}
 
 /******************************************/
 /* End of connection error handling stuff */
@@ -3988,13 +4013,23 @@
 	gtk_container_set_border_width(GTK_CONTAINER(gtkblist->headline_hbox), 6);
 	gtk_container_add(GTK_CONTAINER(ebox), gtkblist->headline_hbox);
 	gtkblist->headline_image = gtk_image_new_from_pixbuf(NULL);
+	gtk_misc_set_alignment(GTK_MISC(gtkblist->headline_image), 0.0, 0);
 	gtkblist->headline_label = gtk_label_new(NULL);
+	gtk_widget_set_size_request(gtkblist->headline_label,
+				    gaim_prefs_get_int("/gaim/gtk/blist/width")-25,-1);
+	gtk_label_set_line_wrap(GTK_LABEL(gtkblist->headline_label), TRUE);
 	gtk_box_pack_start(GTK_BOX(gtkblist->headline_hbox), gtkblist->headline_image, FALSE, FALSE, 0);
 	gtk_box_pack_start(GTK_BOX(gtkblist->headline_hbox), gtkblist->headline_label, TRUE, TRUE, 0);
+	g_signal_connect(gtkblist->headline_hbox,
+			 "style-set",
+			 G_CALLBACK(headline_style_set),
+			 NULL);
 	g_signal_connect (gtkblist->headline_hbox,
 			  "expose_event",
 			  G_CALLBACK (paint_headline_hbox),
 			  NULL);
+	gtk_widget_set_name(gtkblist->headline_hbox, "gtk-tooltips");
+
 	gtkblist->hand_cursor = gdk_cursor_new (GDK_HAND2);
 	gtkblist->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR);
 	g_signal_connect(G_OBJECT(ebox), "enter-notify-event", G_CALLBACK(headline_box_enter_cb), gtkblist);
@@ -4247,7 +4282,8 @@
 						gtkblist, GAIM_CALLBACK(conversation_deleting_cb),
 						gtkblist);
 
-	gtk_widget_hide(gtkblist->scrollbook);
+//	gtk_widget_hide(gtkblist->scrollbook);
+	gtk_widget_hide(gtkblist->headline_hbox);
 	
 	/* emit our created signal */
 	gaim_signal_emit(handle, "gtkblist-created", list);
@@ -5481,8 +5517,8 @@
 void
 gaim_gtk_blist_set_headline(const char *text, GdkPixbuf *pixbuf, GCallback callback, gpointer user_data)
 {
-	gtk_label_set_markup(gtkblist->headline_label, text);
-	gtk_image_set_from_pixbuf(gtkblist->headline_image, pixbuf);
+	gtk_label_set_markup(GTK_LABEL(gtkblist->headline_label), text);
+	gtk_image_set_from_pixbuf(GTK_IMAGE(gtkblist->headline_image), pixbuf);
 	
 	gtkblist->headline_callback = callback;
 	gtkblist->headline_data = user_data;
--- a/gtk/gtkblist.h	Tue Dec 12 08:52:46 2006 +0000
+++ b/gtk/gtkblist.h	Tue Dec 12 08:53:35 2006 +0000
@@ -105,6 +105,7 @@
 	GtkWidget *headline_image;      /**< Image for headline notifications */
 	GCallback headline_callback;    /**< Callback for headline notifications */
 	gpointer headline_data;         /**< User data for headline notifications */
+	gboolean changing_style;        /**< True when changing GTK+ theme style */
 	
 	GtkWidget *error_buttons;        /**< Box containing the connection error buttons */
 	GtkWidget *statusbox;            /**< The status selector dropdown */
--- a/gtk/gtknotify.c	Tue Dec 12 08:52:46 2006 +0000
+++ b/gtk/gtknotify.c	Tue Dec 12 08:53:35 2006 +0000
@@ -83,6 +83,7 @@
 	GtkTreeStore *treemodel;
 	GtkLabel *label;
 	GtkWidget *open_button;
+	int total_count;
 };
 
 static GaimMailDialog *mail_dialog = NULL;
@@ -426,6 +427,7 @@
 	if (detailed)
 	{
 		dialog = mail_dialog->dialog;
+		mail_dialog->total_count += count;
 		while (count--)
 		{
 			char *to_text = NULL;
@@ -500,7 +502,16 @@
 		g_free(detail_text);
 		gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
 	}
-	gtk_widget_show_all(dialog);
+	if (!GTK_WIDGET_VISIBLE(dialog)) {
+		GdkPixbuf *pixbuf = gtk_widget_render_icon(dialog, GAIM_STOCK_ICON_ONLINE_MSG,
+							   GTK_ICON_SIZE_BUTTON, NULL);
+		char *label_text = g_strdup_printf(ngettext("<b>You have %d new e-mail.</b>",
+							    "<b>You have %d new e-mails.</b>",
+							    mail_dialog->total_count), mail_dialog->total_count);
+		gaim_gtk_blist_set_headline(label_text, 
+					    pixbuf, G_CALLBACK(gtk_widget_show_all), dialog);
+		g_object_unref(pixbuf);
+	}
 
 	return data;
 }
--- a/gtk/gtkscrollbook.c	Tue Dec 12 08:52:46 2006 +0000
+++ b/gtk/gtkscrollbook.c	Tue Dec 12 08:53:35 2006 +0000
@@ -203,7 +203,6 @@
 	
 	g_signal_connect_swapped(G_OBJECT(scroll_book->notebook), "remove", G_CALLBACK(page_count_change_cb), scroll_book);
 	g_signal_connect(G_OBJECT(scroll_book->notebook), "switch-page", G_CALLBACK(switch_page_cb), scroll_book);
-	gtk_widget_show_all(scroll_book->hbox);
 	gtk_widget_show_all(scroll_book->notebook);
 }
 
--- a/gtk/gtkutils.c	Tue Dec 12 08:52:46 2006 +0000
+++ b/gtk/gtkutils.c	Tue Dec 12 08:53:35 2006 +0000
@@ -2928,8 +2928,7 @@
 	g_free(primary_esc);
 	label = gtk_label_new(NULL);
 	gtk_widget_set_size_request(label, gaim_prefs_get_int("/gaim/gtk/blist/width")-25,-1);
-        gtk_widget_modify_text(vbox, GTK_STATE_NORMAL, &(label->style->white));
-        gtk_label_set_markup(GTK_LABEL(label), label_text);
+	gtk_label_set_markup(GTK_LABEL(label), label_text);
         gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
         gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
         gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);