/pidgin/main: c51c70f5545a: Add email notification in the dockle...

Jorge Villase?or salinasv at pidgin.im
Thu Nov 8 16:13:34 EST 2012


Changeset: c51c70f5545af77289a66058ce5ce77fa4aec49a
Author:	 Jorge Villase?or <salinasv at pidgin.im>
Date:	 2012-11-08 15:00 -0600
Branch:	 default
URL: http://hg.pidgin.im/pidgin/main/rev/c51c70f5545a

Description:

Add email notification in the docklet area.

Patch from Alexei Potashnik updated and adapted by me plus some bug fixes
(cleaning the dock when closing the headline in the blist)
Fixes #3571
Refs #780

diffstat:

 COPYRIGHT                       |   1 +
 ChangeLog                       |   1 +
 ChangeLog.API                   |   4 +++
 libpurple/notify.c              |   3 ++
 pidgin/gtkblist.c               |   4 +++
 pidgin/gtkdocklet.c             |  49 ++++++++++++++++++++++++++++------------
 pidgin/gtkdocklet.h             |   7 +++++
 pidgin/gtknotify.c              |  28 ++++++++++++++++++++++-
 pidgin/gtknotify.h              |  14 +++++++++++
 pidgin/win32/gtkdocklet-win32.c |  16 ++++++++-----
 10 files changed, 105 insertions(+), 22 deletions(-)

diffs (truncated from 357 to 300 lines):

diff --git a/COPYRIGHT b/COPYRIGHT
--- a/COPYRIGHT
+++ b/COPYRIGHT
@@ -416,6 +416,7 @@ Eric Polino <aluink at gmail.com>
 Ari Pollak
 Stephen Pope
 Cristi Posoiu
+Alexei Potashnik
 Nathan Poznick
 Jory A. Pratt
 David Preece
diff --git a/ChangeLog b/ChangeLog
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@ version 3.0.0 (??/??/????):
 	  either 2 or 3 will attempt to build with specifically 2.x or 3.x
 	  support.  The default is 'auto', which will first look for 3.x
 	  development headers and then 2.x development headers.
+	* Add email notification in the docklet area. (Alexei) (#3571)
 
 	Finch:
 	* Support the conversation-extended signal for extending the
diff --git a/ChangeLog.API b/ChangeLog.API
--- a/ChangeLog.API
+++ b/ChangeLog.API
@@ -3,6 +3,7 @@ Pidgin and Finch: The Pimpin' Penguin IM
 version 3.0.0 (??/??/????):
 	libpurple:
 		Added:
+		* displaying-emails-clear signal (notification signal)
 		* pidgin_create_webview
 		* purple_account_is_disconnecting
 		* purple_account_get_ui_data
@@ -23,6 +24,8 @@ version 3.0.0 (??/??/????):
 		* purple_conversation_message_get_alias
 		* purple_conversation_message_get_conv
 		* purple_contact_get_contact_size
+		* purple_notify_emails_pending
+		* purple_notify_emails_present
 		* purple_notify_searchresult_column_get_title
 		* purple_notify_searchresult_column_is_visible
 		* purple_notify_searchresult_column_set_visible
@@ -72,6 +75,7 @@ version 3.0.0 (??/??/????):
 		* Various WebKit-related functions in gtkwebview.h
 		* xmlnode_get_default_namespace
 		* xmlnode_strip_prefixes
+		* PidginDockletFlag
 
 		Changed:
 		* purple_account_add_buddy now takes an invite message as the last
diff --git a/libpurple/notify.c b/libpurple/notify.c
--- a/libpurple/notify.c
+++ b/libpurple/notify.c
@@ -818,6 +818,9 @@ purple_notify_init(void)
 						 purple_value_new(PURPLE_TYPE_POINTER),
 						 purple_value_new(PURPLE_TYPE_UINT));
 
+	purple_signal_register(handle, "displaying-emails-clear",
+						 purple_marshal_VOID, NULL, 0);
+
 	purple_signal_register(handle, "displaying-userinfo",
 						 purple_marshal_VOID__POINTER_POINTER_POINTER, NULL, 3,
 						 purple_value_new(PURPLE_TYPE_SUBTYPE,
diff --git a/pidgin/gtkblist.c b/pidgin/gtkblist.c
--- a/pidgin/gtkblist.c
+++ b/pidgin/gtkblist.c
@@ -5145,6 +5145,10 @@ headline_response_cb(GtkInfoBar *infobar
 				gtkblist->headline_destroy(gtkblist->headline_data);
 			reset_headline(gtkblist);
 		}
+	} else {
+		if (gtkblist->headline_destroy)
+			gtkblist->headline_destroy(gtkblist->headline_data);
+		reset_headline(gtkblist);
 	}
 
 	return FALSE;
diff --git a/pidgin/gtkdocklet.c b/pidgin/gtkdocklet.c
--- a/pidgin/gtkdocklet.c
+++ b/pidgin/gtkdocklet.c
@@ -44,6 +44,7 @@
 #include "pidginstock.h"
 #include "gtkdocklet.h"
 #include "gtkdialogs.h"
+#include "gtknotify.h"
 
 #include "gtk3compat.h"
 
@@ -58,8 +59,7 @@
 static GtkStatusIcon *docklet = NULL;
 static guint embed_timeout = 0;
 static PurpleStatusPrimitive status = PURPLE_STATUS_OFFLINE;
-static gboolean pending = FALSE;
-static gboolean connecting = FALSE;
+static PidginDockletFlag flags = 0;
 static gboolean enable_join_chat = FALSE;
 static gboolean visible = FALSE;
 static gboolean visibility_manager = FALSE;
@@ -71,8 +71,14 @@ static void docklet_gtk_status_destroy(v
 /**************************************************************************
  * docklet status and utility functions
  **************************************************************************/
+static inline gboolean
+docklet_is_blinking()
+{
+	return flags && !(flags & PIDGIN_DOCKLET_CONNECTING);
+}
+
 static void
-docklet_gtk_status_update_icon(PurpleStatusPrimitive status, gboolean connecting, gboolean pending)
+docklet_gtk_status_update_icon(PurpleStatusPrimitive status, PidginDockletFlag newflag)
 {
 	const gchar *icon_name = NULL;
 
@@ -97,9 +103,11 @@ docklet_gtk_status_update_icon(PurpleSta
 			break;
 	}
 
-	if (pending)
+	if (newflag & PIDGIN_DOCKLET_EMAIL_PENDING)
+		icon_name = PIDGIN_STOCK_TRAY_EMAIL;
+	if (newflag & PIDGIN_DOCKLET_CONV_PENDING)
 		icon_name = PIDGIN_STOCK_TRAY_PENDING;
-	if (connecting)
+	if (newflag & PIDGIN_DOCKLET_CONNECTING)
 		icon_name = PIDGIN_STOCK_TRAY_CONNECT;
 
 	if (icon_name) {
@@ -147,7 +155,7 @@ docklet_update_status(void)
 	int count;
 	PurpleSavedStatus *saved_status;
 	PurpleStatusPrimitive newstatus = PURPLE_STATUS_OFFLINE;
-	gboolean newpending = FALSE, newconnecting = FALSE;
+	PidginDockletFlag newflags = 0;
 
 	/* get the current savedstatus */
 	saved_status = purple_savedstatus_get_current();
@@ -174,7 +182,7 @@ docklet_update_status(void)
 	if (convs != NULL) {
 		/* set tooltip if messages are pending */
 		GString *tooltip_text = g_string_new("");
-		newpending = TRUE;
+		newflags |= PIDGIN_DOCKLET_CONV_PENDING;
 
 		for (l = convs, count = 0 ; l != NULL ; l = l->next, count++) {
 			PurpleConversation *conv = (PurpleConversation *)l->data;
@@ -223,18 +231,20 @@ docklet_update_status(void)
 			continue;
 
 		if (purple_account_is_connecting(account))
-			newconnecting = TRUE;
+			newflags |= PIDGIN_DOCKLET_CONNECTING;
+
+		if (pidgin_notify_emails_pending())
+			newflags |= PIDGIN_DOCKLET_EMAIL_PENDING;
 	}
 
 	newstatus = purple_savedstatus_get_type(saved_status);
 
 	/* update the icon if we changed status */
-	if (status != newstatus || pending!=newpending || connecting!=newconnecting) {
+	if (status != newstatus || flags != newflags) {
 		status = newstatus;
-		pending = newpending;
-		connecting = newconnecting;
+		flags = newflags;
 
-		docklet_gtk_status_update_icon(status, connecting, pending);
+		docklet_gtk_status_update_icon(status, flags);
 	}
 
 	return FALSE; /* for when we're called by the glib idle handler */
@@ -709,7 +719,7 @@ docklet_menu(void)
 
 	menuitem = gtk_menu_item_new_with_mnemonic(_("_Unread Messages"));
 
-	if (pending) {
+	if (flags & PIDGIN_DOCKLET_CONV_PENDING) {
 		GtkWidget *submenu = gtk_menu_new();
 		GList *l = get_pending_list(0);
 		if (l == NULL) {
@@ -785,7 +795,9 @@ pidgin_docklet_clicked(int button_type)
 {
 	switch (button_type) {
 		case 1:
-			if (pending) {
+			if (flags & PIDGIN_DOCKLET_EMAIL_PENDING) {
+				pidgin_notify_emails_present(NULL);
+			} else if (flags & PIDGIN_DOCKLET_CONV_PENDING) {
 				GList *l = get_pending_list(1);
 				if (l != NULL) {
 					pidgin_conv_present_conversation((PurpleConversation *)l->data);
@@ -811,7 +823,7 @@ pidgin_docklet_embedded(void)
 	}
 	visible = TRUE;
 	docklet_update_status();
-	docklet_gtk_status_update_icon(status, connecting, pending);
+	docklet_gtk_status_update_icon(status, flags);
 }
 
 static void
@@ -1002,6 +1014,7 @@ pidgin_docklet_init()
 	void *accounts_handle = purple_accounts_get_handle();
 	void *status_handle = purple_savedstatuses_get_handle();
 	void *docklet_handle = pidgin_docklet_get_handle();
+	void *notify_handle = purple_notify_get_handle();
 	gchar *tmp;
 
 	purple_prefs_add_none(PIDGIN_PREFS_ROOT "/docklet");
@@ -1041,6 +1054,12 @@ pidgin_docklet_init()
 			    docklet_handle, PURPLE_CALLBACK(docklet_conv_updated_cb), NULL);
 	purple_signal_connect(status_handle, "savedstatus-changed",
 			    docklet_handle, PURPLE_CALLBACK(docklet_update_status_cb), NULL);
+	purple_signal_connect(notify_handle, "displaying-email-notification",
+			    docklet_handle, PURPLE_CALLBACK(docklet_update_status_cb), NULL);
+	purple_signal_connect(notify_handle, "displaying-emails-notification",
+			    docklet_handle, PURPLE_CALLBACK(docklet_update_status_cb), NULL);
+	purple_signal_connect(notify_handle, "displaying-emails-clear",
+			    docklet_handle, PURPLE_CALLBACK(docklet_update_status_cb), NULL);
 #if 0
 	purple_signal_connect(purple_get_core(), "quitting",
 			    docklet_handle, PURPLE_CALLBACK(purple_quit_cb), NULL);
diff --git a/pidgin/gtkdocklet.h b/pidgin/gtkdocklet.h
--- a/pidgin/gtkdocklet.h
+++ b/pidgin/gtkdocklet.h
@@ -27,6 +27,13 @@
 
 G_BEGIN_DECLS
 
+typedef enum
+{
+	PIDGIN_DOCKLET_CONNECTING 	= 0x1,
+	PIDGIN_DOCKLET_CONV_PENDING 	= 0x2,
+	PIDGIN_DOCKLET_EMAIL_PENDING 	= 0x4
+} PidginDockletFlag;
+
 /**
  * Returns the GtkStatusIcon used for the docklet.
  */
diff --git a/pidgin/gtknotify.c b/pidgin/gtknotify.c
--- a/pidgin/gtknotify.c
+++ b/pidgin/gtknotify.c
@@ -375,11 +375,37 @@ pounce_row_selected_cb(GtkTreeView *tv, 
 static void
 reset_mail_dialog(GtkDialog *unused)
 {
+	g_return_if_fail(mail_dialog != NULL);
+
 	if (mail_dialog->in_use)
 		return;
 	gtk_widget_destroy(mail_dialog->dialog);
 	g_free(mail_dialog);
 	mail_dialog = NULL;
+	purple_signal_emit(purple_notify_get_handle(), "displaying-emails-clear");
+}
+
+gboolean
+pidgin_notify_emails_pending()
+{
+#if GTK_CHECK_VERSION(2,18,0)
+	return mail_dialog != NULL
+		&& !gtk_widget_get_visible(mail_dialog->dialog);
+#else
+	return mail_dialog != NULL
+		&& !GTK_WIDGET_VISIBLE(mail_dialog->dialog);
+#endif
+}
+
+void pidgin_notify_emails_present(void *data)
+{
+    if (pidgin_notify_emails_pending()) {
+		gtk_widget_show_all(mail_dialog->dialog);
+		mail_dialog->in_use = TRUE;
+		pidgin_blist_set_headline(NULL, NULL, NULL, NULL, NULL);
+		mail_dialog->in_use = FALSE;
+	}
+	purple_signal_emit(purple_notify_get_handle(), "displaying-emails-clear");
 }
 
 static void
@@ -796,7 +822,7 @@ pidgin_notify_emails(PurpleConnection *g
 										   remove the notifications when replacing an
 										   old notification. */
 		pidgin_blist_set_headline(label_text,
-					    pixbuf, G_CALLBACK(gtk_widget_show_all), mail_dialog->dialog,
+					    pixbuf, G_CALLBACK(pidgin_notify_emails_present), mail_dialog->dialog,
 					    (GDestroyNotify)reset_mail_dialog);
 		mail_dialog->in_use = FALSE;
 		g_free(label_text);
diff --git a/pidgin/gtknotify.h b/pidgin/gtknotify.h
--- a/pidgin/gtknotify.h
+++ b/pidgin/gtknotify.h
@@ -63,4 +63,18 @@ void pidgin_notify_uninit(void);
 
 G_END_DECLS
 
+/**
+ * Returns TRUE if there are unseen emails, FALSE otherwise.
+ *
+ * @return TRUE if there are unseen emails, FALSE otherwise.



More information about the Commits mailing list