← Back to team overview

ayatana-commits team mailing list archive

[Branch ~indicator-applet-developers/indicator-messages/trunk] Rev 222: Add a clear attention menu item and attach it to middle click

 

Merge authors:
  Ted Gould (ted)
  Treviño (Marco Trevisan) (3v1n0)
Related merge proposals:
  https://code.launchpad.net/~3v1n0/indicator-messages/clear-notifications/+merge/68438
  proposed by: Treviño (Marco Trevisan) (3v1n0)
------------------------------------------------------------
revno: 222 [merge]
committer: Ted Gould <ted@xxxxxxxx>
branch nick: trunk
timestamp: Fri 2011-07-22 12:15:29 -0500
message:
  Add a clear attention menu item and attach it to middle click
modified:
  configure.ac
  src/indicator-messages.c
  src/messages-service-dbus.c
  src/messages-service.c
  src/messages-service.xml


--
lp:indicator-messages
https://code.launchpad.net/~indicator-applet-developers/indicator-messages/trunk

Your team ayatana-commits is subscribed to branch lp:indicator-messages.
To unsubscribe from this branch go to https://code.launchpad.net/~indicator-applet-developers/indicator-messages/trunk/+edit-subscription
=== modified file 'configure.ac'
--- configure.ac	2011-07-14 18:01:07 +0000
+++ configure.ac	2011-07-19 17:23:07 +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-21 21:31:18 +0000
@@ -89,7 +89,10 @@
 static void indicator_messages_finalize   (GObject *object);
 static GtkImage * get_icon                (IndicatorObject * io);
 static GtkMenu * get_menu                 (IndicatorObject * io);
-static const gchar * get_accessible_desc      (IndicatorObject * io);
+static void indicator_messages_middle_click (IndicatorObject * io,
+                                             IndicatorObjectEntry * entry,
+                                             guint time, gpointer data);
+static const gchar * get_accessible_desc  (IndicatorObject * io);
 static void connection_change             (IndicatorServiceManager * sm,
                                            gboolean connected,
                                            gpointer user_data);
@@ -131,6 +134,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;
@@ -755,3 +759,24 @@
 {
 	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, gpointer data)
+{
+	if (icon_proxy == NULL) {
+		return;
+	}
+
+	g_dbus_proxy_call(icon_proxy,
+	                  "ClearAttention",
+	                  NULL, /* params */
+	                  G_DBUS_CALL_FLAGS_NONE,
+	                  -1, /* timeout */
+	                  NULL, /* cancel */
+	                  NULL,
+	                  NULL);
+
+	return;
+}

=== modified file 'src/messages-service-dbus.c'
--- src/messages-service-dbus.c	2011-01-14 19:32:24 +0000
+++ src/messages-service-dbus.c	2011-07-21 21:25:58 +0000
@@ -200,7 +200,10 @@
 static void
 bus_method_call (GDBusConnection * connection, const gchar * sender, const gchar * path, const gchar * interface, const gchar * method, GVariant * params, GDBusMethodInvocation * invocation, gpointer user_data)
 {
-	MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(user_data);
+	MessageServiceDbus * ms = MESSAGE_SERVICE_DBUS(user_data);
+	if (ms == NULL) { return; }
+
+	MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(ms);
 
 	if (g_strcmp0("AttentionRequested", method) == 0) {
 		g_dbus_method_invocation_return_value(invocation, g_variant_new("(b)", priv->dot));
@@ -208,6 +211,10 @@
 	} else if (g_strcmp0("IconShown", method) == 0) {
 		g_dbus_method_invocation_return_value(invocation, g_variant_new("(b)", priv->hidden));
 		return;
+	} else if (g_strcmp0("ClearAttention", method) == 0) {
+		message_service_dbus_set_attention(ms, FALSE);
+		g_dbus_method_invocation_return_value(invocation, NULL);
+		return;
 	} else {
 		g_warning("Unknown function call '%s'", method);
 	}

=== modified file 'src/messages-service.c'
--- src/messages-service.c	2011-07-22 09:32:23 +0000
+++ src/messages-service.c	2011-07-22 17:15:29 +0000
@@ -28,6 +28,7 @@
 #include <libindicate/listener.h>
 #include <libindicator/indicator-service.h>
 #include <gio/gio.h>
+#include <glib/gi18n.h>
 
 #include <libdbusmenu-glib/client.h>
 #include <libdbusmenu-glib/server.h>
@@ -49,6 +50,7 @@
 
 static DbusmenuMenuitem * root_menuitem = NULL;
 static DbusmenuMenuitem * status_separator = NULL;
+static DbusmenuMenuitem * clear_attention = NULL;
 static GMainLoop * mainloop = NULL;
 
 static MessageServiceDbus * dbus_interface = NULL;
@@ -837,7 +839,6 @@
 	guint position = 0;
 	GList * serverentry;
 	GList * launcherentry = launcherList;
-	DbusmenuMenuitem * last_separator = NULL;
 
 	g_debug("Reordering Menu:");
 	
@@ -874,7 +875,6 @@
 				if (!launcher_menu_item_get_eclipsed(li->menuitem)) {
 					/* Only clear the visiblity if we're not eclipsed */
 					dbusmenu_menuitem_property_set_bool(li->separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
-					last_separator = li->separator;
 				}
 				position++;
 
@@ -930,7 +930,6 @@
 				/* Note, this isn't the last if we can't see it */
 			} else {
 				dbusmenu_menuitem_property_set_bool(si->separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
-				last_separator = si->separator;
 			}
 
 			dbusmenu_menuitem_child_reorder(DBUSMENU_MENUITEM(menushell), DBUSMENU_MENUITEM(si->separator), position);
@@ -962,17 +961,15 @@
 		if (!launcher_menu_item_get_eclipsed(li->menuitem)) {
 			/* Only clear the visiblity if we're not eclipsed */
 			dbusmenu_menuitem_property_set_bool(li->separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
-			last_separator = li->separator;
 		}
 		position++;
 
 		launcherentry = launcherentry->next;
 	}
 
-	if (last_separator != NULL) {
-		dbusmenu_menuitem_property_set_bool(last_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
-	} else {
-		g_warning("No last separator on resort");
+	if (clear_attention != NULL) {
+		dbusmenu_menuitem_child_reorder(DBUSMENU_MENUITEM(menushell), clear_attention, position);
+		position++; /* Not needed, but reduce bugs on code tacked on here, compiler will remove */
 	}
 
 	return;
@@ -1441,12 +1438,31 @@
 	return;
 }
 
+/* Respond to changing status by updating the icon that
+   is on the panel */
 static void
 status_update_callback (void)
 {
 	return;
 }
 
+/* The clear attention item has been clicked on, what to do? */
+static void
+clear_attention_activate (DbusmenuMenuitem * mi, guint timestamp, MessageServiceDbus * dbus)
+{
+	message_service_dbus_set_attention(dbus, FALSE);
+	return;
+}
+
+/* Handle an update of the active state to ensure that we're
+   only enabled when we could do something. */
+static void
+clear_attention_handler (MessageServiceDbus * msd, gboolean attention, DbusmenuMenuitem * clearitem)
+{
+	dbusmenu_menuitem_property_set_bool(clearitem, DBUSMENU_MENUITEM_PROP_ENABLED, attention);
+	return;
+}
+
 /* Oh, if you don't know what main() is for
    we really shouldn't be talking. */
 int
@@ -1486,6 +1502,13 @@
 	dbusmenu_menuitem_property_set(status_separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR);
 	dbusmenu_menuitem_child_append(root_menuitem, status_separator);
 
+	/* Add in the clear attention item */
+	clear_attention = dbusmenu_menuitem_new();
+	dbusmenu_menuitem_property_set(clear_attention, DBUSMENU_MENUITEM_PROP_LABEL, _("Clear Attention"));
+	dbusmenu_menuitem_child_append(root_menuitem, clear_attention);
+	g_signal_connect(G_OBJECT(dbus_interface), MESSAGE_SERVICE_DBUS_SIGNAL_ATTENTION_CHANGED, G_CALLBACK(clear_attention_handler), clear_attention);
+	g_signal_connect(G_OBJECT(clear_attention), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(clear_attention_activate), dbus_interface);
+
 	/* Start up the libindicate listener */
 	listener = indicate_listener_ref_default();
 	serverList = NULL;

=== modified file 'src/messages-service.xml'
--- src/messages-service.xml	2011-01-14 20:19:48 +0000
+++ src/messages-service.xml	2011-07-21 21:17:09 +0000
@@ -3,15 +3,13 @@
 	<interface name="com.canonical.indicator.messages.service">
 
 <!-- Methods -->
-		<method name="Watch">
-			<annotation name="org.freedesktop.DBus.GLib.Async" value="true" />
-		</method>
 		<method name="AttentionRequested">
 			<arg type="b" name="dot" direction="out" />
 		</method>
 		<method name="IconShown">
 			<arg type="b" name="hidden" direction="out" />
 		</method>
+		<method name="ClearAttention" />
 
 <!-- Signals -->
 		<signal name="AttentionChanged">