[gnome-panel/wip/user-menu: 3/11] panel: Add presence items to System menu



commit d1b73a16c07df5f28f9360e7344ab68da51b7a08
Author: Vincent Untz <vuntz gnome org>
Date:   Thu Mar 31 14:22:22 2011 +0530

    panel: Add presence items to System menu
    
    This adds a new (optional) dependency on telepathy-glib.
    
    This breaks the string freeze, but I'll merge translations from
    gnome-shell later on.

 configure.ac                   |   12 ++++
 gnome-panel/Makefile.am        |    2 +
 gnome-panel/panel-icon-names.h |    2 +
 gnome-panel/panel-menu-items.c |  137 +++++++++++++++++++++++++++++++++++++++-
 4 files changed, 151 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 4278259..cac3dd7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -70,6 +70,7 @@ GTK_REQUIRED=3.0
 LIBWNCK_REQUIRED=2.91.0
 GCONF_REQUIRED=2.6.1
 LIBGNOME_MENU_REQUIRED=2.27.92
+TELEPATHY_GLIB_REQUIRED=0.14.0
 LIBECAL_REQUIRED=2.91.2
 LIBEDATASERVER_REQUIRED=2.91.2
 LIBEDATASERVERUI_REQUIRED=2.91.2
@@ -85,6 +86,16 @@ PKG_CHECK_MODULES(PANEL, gdk-pixbuf-2.0 >= $GDK_PIXBUF_REQUIRED pango >= $PANGO_
 AC_SUBST(PANEL_CFLAGS)
 AC_SUBST(PANEL_LIBS)
 
+AC_ARG_ENABLE(telepathy_glib, AS_HELP_STRING([--enable-telepathy-glib],[Enable telepathy-glib support (auto)]),enable_telepathy_glib=$enableval,enable_telepathy_glib=auto)
+if test "x$enable_telepathy_glib" = "xno" ; then
+  HAVE_TELEPATHY_GLIB=no
+else
+  PKG_CHECK_MODULES(TELEPATHY_GLIB, telepathy-glib >= $TELEPATHY_GLIB_REQUIRED, HAVE_TELEPATHY_GLIB=yes, HAVE_TELEPATHY_GLIB=no)
+fi
+if test "x$HAVE_TELEPATHY_GLIB" = "xyes" ; then
+    AC_DEFINE(HAVE_TELEPATHY_GLIB, 1, [Defined if telepathy-glib support is enabled])
+fi
+
 PKG_CHECK_MODULES(LIBPANEL_APPLET, gtk+-3.0 >= $GTK_REQUIRED cairo-xlib cairo-gobject gconf-2.0 >= $GCONF_REQUIRED gio-2.0 >= $GLIB_REQUIRED gio-unix-2.0 >= $GLIB_REQUIRED)
 AC_SUBST(LIBPANEL_APPLET_CFLAGS)
 AC_SUBST(LIBPANEL_APPLET_LIBS)
@@ -368,6 +379,7 @@ echo "
         Bonobo applets support:        ${HAVE_BONOBO}
         Applets to build in-process:   ${PANEL_INPROCESS_APPLETS}
         Evolution-Data-Server support: ${HAVE_EDS}
+        Telepathy-Glib support:        ${HAVE_TELEPATHY_GLIB}
         NetworkManager support:        ${HAVE_NETWORK_MANAGER}
         XRandr support:                ${have_randr}
         Build introspection support:   ${found_introspection}
diff --git a/gnome-panel/Makefile.am b/gnome-panel/Makefile.am
index 9e91b77..2102e4f 100644
--- a/gnome-panel/Makefile.am
+++ b/gnome-panel/Makefile.am
@@ -125,6 +125,7 @@ gnome_panel_SOURCES =			\
 
 gnome_panel_CPPFLAGS = 				\
 	$(AM_CPPFLAGS)				\
+	$(TELEPATHY_GLIB_CFLAGS)		\
 	$(XRANDR_CFLAGS)			\
 	-DPANEL_MODULES_DIR=\"$(modulesdir)\"	\
 	-DGMENU_I_KNOW_THIS_IS_UNSTABLE		\
@@ -135,6 +136,7 @@ gnome_panel_LDADD =		\
 	$(top_builddir)/gnome-panel/libpanel-applet-private/libpanel-applet-private.la	\
 	$(top_builddir)/gnome-panel/libpanel-util/libpanel-util.la			\
 	$(PANEL_LIBS)									\
+	$(TELEPATHY_GLIB_LIBS)								\
 	$(XRANDR_LIBS)									\
 	$(X_LIBS)
 
diff --git a/gnome-panel/panel-icon-names.h b/gnome-panel/panel-icon-names.h
index 0df99a4..c5d59a3 100644
--- a/gnome-panel/panel-icon-names.h
+++ b/gnome-panel/panel-icon-names.h
@@ -35,5 +35,7 @@
 #define PANEL_ICON_THEME		"preferences-desktop-theme"
 #define PANEL_ICON_TRASH		"user-trash"
 #define PANEL_ICON_UNKNOWN		"image-missing"
+#define PANEL_ICON_USER_AVAILABLE	"user-available-symbolic"
+#define PANEL_ICON_USER_BUSY		"user-busy-symbolic"
 
 #endif /* PANEL_ICON_NAMES_H */
diff --git a/gnome-panel/panel-menu-items.c b/gnome-panel/panel-menu-items.c
index 9fd6d4c..3995299 100644
--- a/gnome-panel/panel-menu-items.c
+++ b/gnome-panel/panel-menu-items.c
@@ -40,6 +40,10 @@
 #include <glib/gi18n.h>
 #include <gio/gio.h>
 
+#ifdef HAVE_TELEPATHY_GLIB
+#include <telepathy-glib/account-manager.h>
+#endif
+
 #include <libpanel-util/panel-error.h>
 #include <libpanel-util/panel-glib.h>
 #include <libpanel-util/panel-keyfile.h>
@@ -95,8 +99,89 @@ struct _PanelPlaceMenuItemPrivate {
 struct _PanelDesktopMenuItemPrivate {
 	GtkWidget   *menu;
 	PanelWidget *panel;
+
+#ifdef HAVE_TELEPATHY_GLIB
+	TpAccountManager *account_manager;
+#endif
 };
 
+#ifdef HAVE_TELEPATHY_GLIB
+static void
+panel_menu_item_activate_presence (GtkWidget        *menuitem,
+				   TpAccountManager *account_manager)
+{
+	PanelSessionManagerPresenceType  presence_type;
+	TpConnectionPresenceType         tp_presence_type;
+	const char                      *status;
+	char                            *message;
+
+	presence_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menuitem),
+							    "panel-menu-presence"));
+
+	panel_session_manager_set_presence (panel_session_manager_get (),
+					    presence_type);
+
+	tp_presence_type = tp_account_manager_get_most_available_presence (account_manager,
+									   NULL,
+									   &message);
+
+	if (tp_presence_type == TP_CONNECTION_PRESENCE_TYPE_UNSET ||
+	    tp_presence_type == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
+	    tp_presence_type == TP_CONNECTION_PRESENCE_TYPE_UNKNOWN ||
+	    tp_presence_type == TP_CONNECTION_PRESENCE_TYPE_ERROR)
+		goto free_message;
+
+	if (presence_type == PANEL_SESSION_MANAGER_PRESENCE_AVAILABLE) {
+		tp_presence_type = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
+		status = "available";
+	} else if (presence_type == PANEL_SESSION_MANAGER_PRESENCE_BUSY) {
+		tp_presence_type = TP_CONNECTION_PRESENCE_TYPE_BUSY;
+		status = "busy";
+	} else
+		goto free_message;
+
+	tp_account_manager_set_all_requested_presences (account_manager,
+							tp_presence_type,
+							status, message);
+
+free_message:
+	g_free (message);
+}
+
+static GtkWidget *
+panel_menu_item_presence_new (TpAccountManager                *account_manager,
+			      PanelSessionManagerPresenceType  presence_type,
+			      const char                      *name,
+			      const char                      *icon,
+			      gboolean                         use_icon)
+{
+	GtkWidget *item;
+
+	if (!account_manager)
+		return NULL;
+
+	if (use_icon) {
+		item = panel_image_menu_item_new ();
+        } else {
+		item = gtk_image_menu_item_new ();
+	}
+
+	setup_menu_item_with_icon (item, panel_menu_icon_get_size (),
+				   icon, NULL, NULL, name);
+
+	g_object_set_data (G_OBJECT (item), "panel-menu-presence",
+			   GINT_TO_POINTER (presence_type));
+
+	g_signal_connect (item, "activate",
+			  G_CALLBACK (panel_menu_item_activate_presence),
+			  account_manager);
+	g_signal_connect (G_OBJECT (item), "button_press_event",
+			  G_CALLBACK (menu_dummy_button_press_event), NULL);
+
+	return item;
+}
+#endif
+
 static void
 activate_uri_on_screen (const char *uri,
 			GdkScreen  *screen)
@@ -1192,9 +1277,37 @@ panel_desktop_menu_item_create_menu (PanelDesktopMenuItem *desktop_item,
 {
 	GtkWidget *desktop_menu;
 	GtkWidget *item;
+#ifdef HAVE_TELEPATHY_GLIB
+	gboolean   added;
+#endif
 
 	desktop_menu = panel_create_menu ();
 
+#ifdef HAVE_TELEPATHY_GLIB
+	desktop_item->priv->account_manager = tp_account_manager_dup ();
+
+	item = panel_menu_item_presence_new (desktop_item->priv->account_manager,
+					     PANEL_SESSION_MANAGER_PRESENCE_AVAILABLE,
+					     _("Available"),
+					     PANEL_ICON_USER_AVAILABLE, TRUE);
+	if (item) {
+		gtk_menu_shell_append (GTK_MENU_SHELL (desktop_menu), item);
+		added = TRUE;
+	}
+
+	item = panel_menu_item_presence_new (desktop_item->priv->account_manager,
+					     PANEL_SESSION_MANAGER_PRESENCE_BUSY,
+					     _("Busy"),
+					     PANEL_ICON_USER_BUSY, TRUE);
+	if (item) {
+		gtk_menu_shell_append (GTK_MENU_SHELL (desktop_menu), item);
+		added = TRUE;
+	}
+
+	if (added)
+		add_menu_separator (desktop_menu);
+#endif
+
 	item = panel_menu_item_desktop_new ("gnome-user-accounts-panel.desktop",
 					    _("My Account"), FALSE);
 	if (item)
@@ -1284,6 +1397,20 @@ panel_place_menu_item_finalize (GObject *object)
 }
 
 static void
+panel_desktop_menu_item_finalize (GObject *object)
+{
+	PanelDesktopMenuItem *menuitem = (PanelDesktopMenuItem *) object;
+
+#ifdef HAVE_TELEPATHY_GLIB
+	if (menuitem->priv->account_manager != NULL)
+		g_object_unref (menuitem->priv->account_manager);
+	menuitem->priv->account_manager = NULL;
+#endif
+
+	G_OBJECT_CLASS (panel_desktop_menu_item_parent_class)->finalize (object);
+}
+
+static void
 panel_place_menu_item_init (PanelPlaceMenuItem *menuitem)
 {
 	GFile *bookmark;
@@ -1382,14 +1509,16 @@ static void
 panel_desktop_menu_item_init (PanelDesktopMenuItem *menuitem)
 {
 	menuitem->priv = PANEL_DESKTOP_MENU_ITEM_GET_PRIVATE (menuitem);
+
+	menuitem->priv->account_manager = NULL;
 }
 
 static void
 panel_place_menu_item_class_init (PanelPlaceMenuItemClass *klass)
 {
-	GObjectClass *gobject_class = (GObjectClass   *) klass;
+	GObjectClass *gobject_class = (GObjectClass *) klass;
 
-	gobject_class->finalize  = panel_place_menu_item_finalize;
+	gobject_class->finalize = panel_place_menu_item_finalize;
 
 	g_type_class_add_private (klass, sizeof (PanelPlaceMenuItemPrivate));
 }
@@ -1397,6 +1526,10 @@ panel_place_menu_item_class_init (PanelPlaceMenuItemClass *klass)
 static void
 panel_desktop_menu_item_class_init (PanelDesktopMenuItemClass *klass)
 {
+	GObjectClass *gobject_class = (GObjectClass *) klass;
+
+	gobject_class->finalize = panel_desktop_menu_item_finalize;
+
 	g_type_class_add_private (klass, sizeof (PanelDesktopMenuItemPrivate));
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]