← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~3v1n0/indicator-messages/clear-notifications into lp:indicator-messages

 

Treviño (Marco Trevisan) has proposed merging lp:~3v1n0/indicator-messages/clear-notifications into lp:indicator-messages.

Requested reviews:
  Ted Gould (ted)

For more details, see:
https://code.launchpad.net/~3v1n0/indicator-messages/clear-notifications/+merge/68438

Reset the attention state of the messaging indicator on middle-click (requires libindicator from Bug #812933) and on menu-item click.

The menu item to clear the notifications is added directly to the indicator.
-- 
https://code.launchpad.net/~3v1n0/indicator-messages/clear-notifications/+merge/68438
Your team ayatana-commits is subscribed to branch lp:indicator-messages.
=== modified file 'configure.ac'
--- configure.ac	2011-07-14 18:01:07 +0000
+++ configure.ac	2011-07-19 17:46:35 +0000
@@ -43,20 +43,20 @@
 INDICATOR_REQUIRED_VERSION=0.3.19
 DBUSMENUGTK_REQUIRED_VERSION=0.3.94
 
-AC_ARG_WITH([indicator-gtk],
-  [AS_HELP_STRING([--with-indicator-gtk],
+AC_ARG_WITH([gtk],
+  [AS_HELP_STRING([--with-gtk],
     [Which version of gtk to use for the indicator @<:@default=3@:>@])],
   [],
-  [with_indicator_gtk=3])
+  [with_gtk=3])
 
-AS_IF([test "x$with_indicator_gtk" = x3],
+AS_IF([test "x$with_gtk" = x3],
         [PKG_CHECK_MODULES(APPLET, gtk+-3.0 >= $GTK3_REQUIRED_VERSION
                                    gio-unix-2.0 >= $GIO_UNIX_REQUIRED_VERSION
                                    indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION
                                    indicate-0.5 >= $INDICATE_REQUIRED_VERSION
                                    dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION)
         ],
-      [test "x$with_indicator_gtk" = x2],
+      [test "x$with_gtk" = x2],
         [PKG_CHECK_MODULES(APPLET, gtk+-2.0 >= $GTK_REQUIRED_VERSION
                                    gio-unix-2.0 >= $GIO_UNIX_REQUIRED_VERSION
                                    indicator-0.4 >= $INDICATOR_REQUIRED_VERSION
@@ -104,7 +104,7 @@
 if test "x$with_localinstall" = "xyes"; then
 	INDICATORDIR="${libdir}/indicators/2/"
 	INDICATORICONSDIR="${datadir}/libindicate/icons/"
-elif test "x$with_indicator_gtk" = x2; then
+elif test "x$with_gtk" = x2; then
 	INDICATORDIR=`$PKG_CONFIG --variable=indicatordir indicator-0.4`
 	INDICATORICONSDIR=`$PKG_CONFIG --variable=iconsdir indicator-0.4`
 else

=== modified file 'src/indicator-messages.c'
--- src/indicator-messages.c	2011-05-26 17:26:39 +0000
+++ src/indicator-messages.c	2011-07-19 17:46:35 +0000
@@ -75,12 +75,14 @@
 
 /* Globals */
 static GtkWidget * main_image = NULL;
+static GtkWidget * clear_notifications = NULL;
 static GDBusProxy * icon_proxy = NULL;
 static GtkSizeGroup * indicator_right_group = NULL;
 static GDBusNodeInfo *            bus_node_info = NULL;
 static GDBusInterfaceInfo *       bus_interface_info = NULL;
 static const gchar *              accessible_desc = NULL;
 static IndicatorObject *          indicator = NULL;
+static gboolean                   attention = FALSE;
 
 /* Prototypes */
 static void indicator_messages_class_init (IndicatorMessagesClass *klass);
@@ -89,6 +91,10 @@
 static void indicator_messages_finalize   (GObject *object);
 static GtkImage * get_icon                (IndicatorObject * io);
 static GtkMenu * get_menu                 (IndicatorObject * io);
+static void indicator_messages_middle_click (IndicatorObject * io,
+                                             IndicatorObjectEntry * entry,
+                                             guint time, gint x, gint y,
+                                             gpointer data);
 static const gchar * get_accessible_desc      (IndicatorObject * io);
 static void connection_change             (IndicatorServiceManager * sm,
                                            gboolean connected,
@@ -117,6 +123,33 @@
 	return;
 }
 
+static void
+clear_notifications_show(gboolean show)
+{
+	g_return_if_fail(clear_notifications);
+
+	GtkWidget *separator = g_object_get_data(G_OBJECT(clear_notifications), "separator");
+	g_return_if_fail(separator);
+
+	if (show) {
+		gtk_widget_show(separator);
+		gtk_widget_show(clear_notifications);
+	} else {
+		gtk_widget_hide(separator);
+		gtk_widget_hide(clear_notifications);
+	}
+}
+
+static void
+clear_attention(void) {
+	g_return_if_fail(attention);
+
+	indicator_image_helper_update(GTK_IMAGE(main_image), "indicator-messages");
+	accessible_desc = _("Messages");
+	clear_notifications_show(FALSE);
+	update_a11y_desc();
+}
+
 /* Initialize the one-timers */
 static void
 indicator_messages_class_init (IndicatorMessagesClass *klass)
@@ -131,6 +164,7 @@
 	io_class->get_image = get_icon;
 	io_class->get_menu = get_menu;
 	io_class->get_accessible_desc = get_accessible_desc;
+	io_class->secondary_activate = indicator_messages_middle_click;
 
 	if (bus_node_info == NULL) {
 		GError * error = NULL;
@@ -208,10 +242,13 @@
 		if (prop) {
 			indicator_image_helper_update(GTK_IMAGE(main_image), "indicator-messages-new");
 			accessible_desc = _("New Messages");
+			attention = TRUE;
 		} else {
 			indicator_image_helper_update(GTK_IMAGE(main_image), "indicator-messages");
 			accessible_desc = _("Messages");
+			attention = FALSE;
 		}
+		clear_notifications_show(attention);
 	} else if (g_strcmp0("IconChanged", signal) == 0) {
 		if (prop) {
 			gtk_widget_hide(main_image);
@@ -245,11 +282,15 @@
 	if (prop) {
 		indicator_image_helper_update(GTK_IMAGE(main_image), "indicator-messages-new");
 		accessible_desc = _("New Messages");
+		attention = TRUE;
 	} else {
 		indicator_image_helper_update(GTK_IMAGE(main_image), "indicator-messages");
 		accessible_desc = _("Messages");
+		attention = FALSE;
 	}
 
+	clear_notifications_show(attention);
+
 	update_a11y_desc();
 
 	return;
@@ -746,6 +787,18 @@
 	dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), INDICATOR_MENUITEM_TYPE, new_indicator_item);
 	dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), APPLICATION_MENUITEM_TYPE, new_application_item);
 
+	GtkWidget *sep = gtk_separator_menu_item_new();
+	gtk_widget_show(sep);
+	gtk_container_add (GTK_CONTAINER(menu), sep);
+
+	clear_notifications = gtk_menu_item_new_with_label(_("Clear Notifications"));
+	gtk_widget_show(clear_notifications);
+	gtk_container_add(GTK_CONTAINER(menu), clear_notifications);
+	g_object_set_data(G_OBJECT(clear_notifications), "separator", sep);
+	g_signal_connect(clear_notifications, "activate", G_CALLBACK(clear_attention), NULL);
+
+	clear_notifications_show(attention);
+
 	return GTK_MENU(menu);
 }
 
@@ -755,3 +808,13 @@
 {
 	return accessible_desc;
 }
+
+/* Hide the notifications on middle-click over the indicator-messages */
+static void
+indicator_messages_middle_click (IndicatorObject * io, IndicatorObjectEntry * entry,
+                                 guint time, gint x, gint y, gpointer data)
+{
+	g_return_if_fail(attention);
+
+	clear_attention();
+}


Follow ups