aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@src.gnome.org>2007-05-10 04:02:10 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2007-05-10 04:02:10 +0800
commit653614a7d74bb9c68402dfb9cc323421c3deaef4 (patch)
treef63c163eaae633934efbb456a816fb878e76553c /libempathy-gtk
parent2d37182c552903037bbba5cf6df6a57fcdeca80b (diff)
downloadgsoc2013-empathy-653614a7d74bb9c68402dfb9cc323421c3deaef4.tar
gsoc2013-empathy-653614a7d74bb9c68402dfb9cc323421c3deaef4.tar.gz
gsoc2013-empathy-653614a7d74bb9c68402dfb9cc323421c3deaef4.tar.bz2
gsoc2013-empathy-653614a7d74bb9c68402dfb9cc323421c3deaef4.tar.lz
gsoc2013-empathy-653614a7d74bb9c68402dfb9cc323421c3deaef4.tar.xz
gsoc2013-empathy-653614a7d74bb9c68402dfb9cc323421c3deaef4.tar.zst
gsoc2013-empathy-653614a7d74bb9c68402dfb9cc323421c3deaef4.zip
[darcs-to-svn @ New object: EmpathyStatusIcon]
svn path=/trunk/; revision=41
Diffstat (limited to 'libempathy-gtk')
-rw-r--r--libempathy-gtk/Makefile.am1
-rw-r--r--libempathy-gtk/empathy-main-window.c32
-rw-r--r--libempathy-gtk/empathy-status-icon.c166
-rw-r--r--libempathy-gtk/empathy-status-icon.h54
4 files changed, 242 insertions, 11 deletions
diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am
index bd8abcc2b..d6d64905f 100644
--- a/libempathy-gtk/Makefile.am
+++ b/libempathy-gtk/Makefile.am
@@ -10,6 +10,7 @@ libempathy_gtk_la_SOURCES = \
ephy-spinner.c ephy-spinner.h \
empathy-images.h \
empathy-main-window.c empathy-main-window.h \
+ empathy-status-icon.c empathy-status-icon.h \
gossip-accounts-dialog.c gossip-accounts-dialog.h \
gossip-account-widget-generic.c gossip-account-widget-generic.h \
gossip-account-widget-jabber.c gossip-account-widget-jabber.h \
diff --git a/libempathy-gtk/empathy-main-window.c b/libempathy-gtk/empathy-main-window.c
index a34ad5bff..6394a6498 100644
--- a/libempathy-gtk/empathy-main-window.c
+++ b/libempathy-gtk/empathy-main-window.c
@@ -33,6 +33,7 @@
#include <libempathy/gossip-conf.h>
#include <libempathy/gossip-contact.h>
#include <libempathy/gossip-debug.h>
+#include <libempathy/gossip-utils.h>
#include "empathy-main-window.h"
#include "ephy-spinner.h"
@@ -132,7 +133,7 @@ static void main_window_accels_save (void);
static void main_window_connection_items_setup (EmpathyMainWindow *window,
GladeXML *glade);
//static void main_window_connection_items_update (void);
-static void main_window_presence_changed_cb (DBusGProxy *proxy,
+static void main_window_presence_changed_cb (MissionControl *mc,
McPresence state,
EmpathyMainWindow *window);
static void main_window_presence_chooser_changed_cb (GtkWidget *chooser,
@@ -228,26 +229,22 @@ empathy_main_window_show (void)
gtk_widget_hide (window->edit_context);
gtk_widget_hide (window->edit_context_separator);
- /* Set up presence chooser
- * FIXME: Update status message not yet supported by MC
- */
+ /* Set up presence chooser */
window->mc = mission_control_new (tp_get_bus ());
window->presence_chooser = gossip_presence_chooser_new ();
- gtk_widget_show (window->presence_chooser);
gossip_presence_chooser_set_flash_interval (GOSSIP_PRESENCE_CHOOSER (window->presence_chooser),
FLASH_TIMEOUT);
- state = mission_control_get_presence (window->mc, NULL);
- gossip_presence_chooser_set_state (GOSSIP_PRESENCE_CHOOSER (window->presence_chooser),
- state);
dbus_g_proxy_connect_signal (DBUS_G_PROXY (window->mc),
- "PresenceStatusRequested",
+ "PresenceStatusActual",
G_CALLBACK (main_window_presence_changed_cb),
window, NULL);
g_signal_connect (window->presence_chooser,
"changed",
G_CALLBACK (main_window_presence_chooser_changed_cb),
window);
-
+ state = mission_control_get_presence_actual (window->mc, NULL);
+ main_window_presence_changed_cb (window->mc, state, window);
+ gtk_widget_show (window->presence_chooser);
item = gtk_tool_item_new ();
gtk_widget_show (GTK_WIDGET (item));
@@ -762,13 +759,26 @@ main_window_connection_items_update (void)
#endif
static void
-main_window_presence_changed_cb (DBusGProxy *proxy,
+main_window_presence_changed_cb (MissionControl *mc,
McPresence state,
EmpathyMainWindow *window)
{
+ gchar *status;
+
gossip_debug (DEBUG_DOMAIN, "presence changed to %d", state);
+
+ status = mission_control_get_presence_message_actual (window->mc, NULL);
+
+ if (G_STR_EMPTY (status)) {
+ g_free (status);
+ status = g_strdup (gossip_presence_state_get_default_status (state));
+ }
+
gossip_presence_chooser_set_state (GOSSIP_PRESENCE_CHOOSER (window->presence_chooser),
state);
+ gossip_presence_chooser_set_status (GOSSIP_PRESENCE_CHOOSER (window->presence_chooser),
+ status);
+ g_free (status);
}
static void
diff --git a/libempathy-gtk/empathy-status-icon.c b/libempathy-gtk/empathy-status-icon.c
new file mode 100644
index 000000000..e46944e5b
--- /dev/null
+++ b/libempathy-gtk/empathy-status-icon.c
@@ -0,0 +1,166 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2007 Collabora Ltd.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Authors: Xavier Claessens <xclaesse@gmail.com>
+ */
+
+#include <config.h>
+
+#include <string.h>
+
+#include <glib.h>
+#include <gtk/gtk.h>
+
+#include <libtelepathy/tp-helpers.h>
+
+#include <libmissioncontrol/mission-control.h>
+
+#include <libempathy/gossip-debug.h>
+#include <libempathy/gossip-utils.h>
+
+#include "empathy-status-icon.h"
+#include "gossip-ui-utils.h"
+
+#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
+ EMPATHY_TYPE_STATUS_ICON, EmpathyStatusIconPriv))
+
+#define DEBUG_DOMAIN "StatusIcon"
+
+struct _EmpathyStatusIconPriv {
+ MissionControl *mc;
+ GtkStatusIcon *icon;
+};
+
+static void empathy_status_icon_class_init (EmpathyStatusIconClass *klass);
+static void empathy_status_icon_init (EmpathyStatusIcon *icon);
+static void status_icon_finalize (GObject *object);
+static void status_icon_presence_changed_cb (MissionControl *mc,
+ McPresence state,
+ EmpathyStatusIcon *icon);
+static void status_icon_activate_cb (GtkStatusIcon *status_icon,
+ EmpathyStatusIcon *icon);
+
+enum {
+ ACTIVATE,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
+G_DEFINE_TYPE (EmpathyStatusIcon, empathy_status_icon, G_TYPE_OBJECT);
+
+static void
+empathy_status_icon_class_init (EmpathyStatusIconClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = status_icon_finalize;
+
+ signals[ACTIVATE] =
+ g_signal_new ("activate",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
+ g_type_class_add_private (object_class, sizeof (EmpathyStatusIconPriv));
+}
+
+static void
+empathy_status_icon_init (EmpathyStatusIcon *icon)
+{
+ EmpathyStatusIconPriv *priv;
+ McPresence state;
+
+ priv = GET_PRIV (icon);
+
+ priv->mc = mission_control_new (tp_get_bus ());
+ priv->icon = gtk_status_icon_new ();
+
+ dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->mc),
+ "PresenceStatusActual",
+ G_CALLBACK (status_icon_presence_changed_cb),
+ icon, NULL);
+ g_signal_connect (priv->icon, "activate",
+ G_CALLBACK (status_icon_activate_cb),
+ icon);
+
+ state = mission_control_get_presence_actual (priv->mc, NULL);
+ status_icon_presence_changed_cb (priv->mc, state, icon);
+}
+
+static void
+status_icon_finalize (GObject *object)
+{
+ EmpathyStatusIconPriv *priv;
+
+ priv = GET_PRIV (object);
+
+ dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->mc),
+ "PresenceStatusActual",
+ G_CALLBACK (status_icon_presence_changed_cb),
+ object);
+ g_signal_handlers_disconnect_by_func (priv->icon,
+ status_icon_activate_cb,
+ object);
+
+ g_object_unref (priv->mc);
+ g_object_unref (priv->icon);
+}
+
+EmpathyStatusIcon *
+empathy_status_icon_new (void)
+{
+ return g_object_new (EMPATHY_TYPE_STATUS_ICON, NULL);
+}
+
+static void
+status_icon_presence_changed_cb (MissionControl *mc,
+ McPresence state,
+ EmpathyStatusIcon *icon)
+{
+ EmpathyStatusIconPriv *priv;
+ const gchar *icon_name;
+ gchar *status;
+
+ priv = GET_PRIV (icon);
+
+ icon_name = gossip_icon_name_for_presence_state (state);
+ status = mission_control_get_presence_message_actual (priv->mc, NULL);
+ if (G_STR_EMPTY (status)) {
+ g_free (status);
+ status = g_strdup (gossip_presence_state_get_default_status (state));
+ }
+
+ gtk_status_icon_set_from_icon_name (priv->icon, icon_name);
+ gtk_status_icon_set_tooltip (priv->icon, status);
+
+ g_free (status);
+}
+
+static void
+status_icon_activate_cb (GtkStatusIcon *status_icon,
+ EmpathyStatusIcon *icon)
+{
+ g_signal_emit (icon, signals[ACTIVATE], 0);
+}
+
diff --git a/libempathy-gtk/empathy-status-icon.h b/libempathy-gtk/empathy-status-icon.h
new file mode 100644
index 000000000..898e3514a
--- /dev/null
+++ b/libempathy-gtk/empathy-status-icon.h
@@ -0,0 +1,54 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2007 Collabora Ltd.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Authors: Xavier Claessens <xclaesse@gmail.com>
+ */
+
+#ifndef __EMPATHY_STATUS_ICON_H__
+#define __EMPATHY_STATUS_ICON_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+#define EMPATHY_TYPE_STATUS_ICON (empathy_status_icon_get_type ())
+#define EMPATHY_STATUS_ICON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_STATUS_ICON, EmpathyStatusIcon))
+#define EMPATHY_STATUS_ICON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EMPATHY_TYPE_STATUS_ICON, EmpathyStatusIconClass))
+#define EMPATHY_IS_STATUS_ICON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_STATUS_ICON))
+#define EMPATHY_IS_STATUS_ICON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_STATUS_ICON))
+#define EMPATHY_STATUS_ICON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_STATUS_ICON, EmpathyStatusIconClass))
+
+typedef struct _EmpathyStatusIcon EmpathyStatusIcon;
+typedef struct _EmpathyStatusIconClass EmpathyStatusIconClass;
+typedef struct _EmpathyStatusIconPriv EmpathyStatusIconPriv;
+
+struct _EmpathyStatusIcon {
+ GObject parent;
+};
+
+struct _EmpathyStatusIconClass {
+ GObjectClass parent_class;
+};
+
+GType empathy_status_icon_get_type (void) G_GNUC_CONST;
+EmpathyStatusIcon *empathy_status_icon_new (void);
+
+G_END_DECLS
+
+#endif /* __EMPATHY_STATUS_ICON_H__ */