aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@src.gnome.org>2008-04-20 05:04:29 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2008-04-20 05:04:29 +0800
commit76d322dac811789e535af7a990baaa23942f768e (patch)
tree9415dab4e370057d44b1bbcbab2beaabd6b0508d /src
parenta03d084c8c5884f498e36d4e0650dfa8ca2b1973 (diff)
downloadgsoc2013-empathy-76d322dac811789e535af7a990baaa23942f768e.tar
gsoc2013-empathy-76d322dac811789e535af7a990baaa23942f768e.tar.gz
gsoc2013-empathy-76d322dac811789e535af7a990baaa23942f768e.tar.bz2
gsoc2013-empathy-76d322dac811789e535af7a990baaa23942f768e.tar.lz
gsoc2013-empathy-76d322dac811789e535af7a990baaa23942f768e.tar.xz
gsoc2013-empathy-76d322dac811789e535af7a990baaa23942f768e.tar.zst
gsoc2013-empathy-76d322dac811789e535af7a990baaa23942f768e.zip
Move tube chandler to EmpathyFilter
svn path=/trunk/; revision=988
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/empathy-filter.c244
-rw-r--r--src/empathy-tubes-chandler.c267
-rw-r--r--src/empathy-tubes.chandler4
-rw-r--r--src/org.gnome.Empathy.Tubes.service.in3
5 files changed, 245 insertions, 274 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index d1e75e3f0..7c18efc24 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -12,6 +12,7 @@ AM_CPPFLAGS = \
LDADD = \
$(top_builddir)/libempathy-gtk/libempathy-gtk.la \
$(top_builddir)/libempathy/libempathy.la \
+ $(top_builddir)/extensions/libemp-extensions.la \
$(EMPATHY_LIBS)
bin_PROGRAMS = \
diff --git a/src/empathy-filter.c b/src/empathy-filter.c
index 113884022..e256502e2 100644
--- a/src/empathy-filter.c
+++ b/src/empathy-filter.c
@@ -29,15 +29,20 @@
#include <telepathy-glib/channel.h>
#include <telepathy-glib/connection.h>
#include <telepathy-glib/util.h>
+#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/proxy-subclass.h>
#include <libmissioncontrol/mission-control.h>
#include <libmissioncontrol/mc-account.h>
+#include <extensions/extensions.h>
+
#include <libempathy/empathy-tp-chat.h>
#include <libempathy/empathy-tp-call.h>
#include <libempathy/empathy-tp-group.h>
#include <libempathy/empathy-utils.h>
#include <libempathy/empathy-debug.h>
+#include <libempathy/empathy-tube-handler.h>
#include <libempathy-gtk/empathy-chat.h>
#include <libempathy-gtk/empathy-images.h>
@@ -57,6 +62,7 @@ struct _EmpathyFilterPriv {
GHashTable *accounts;
gpointer token;
MissionControl *mc;
+ GHashTable *tubes;
};
static void empathy_filter_class_init (EmpathyFilterClass *klass);
@@ -78,6 +84,24 @@ typedef struct {
gpointer user_data;
} EmpathyFilterEventExt;
+static guint
+filter_channel_hash (gconstpointer key)
+{
+ TpProxy *channel = TP_PROXY (key);
+
+ return g_str_hash (channel->object_path);
+}
+
+static gboolean
+filter_channel_equal (gconstpointer a,
+ gconstpointer b)
+{
+ TpProxy *channel_a = TP_PROXY (a);
+ TpProxy *channel_b = TP_PROXY (b);
+
+ return g_str_equal (channel_a->object_path, channel_b->object_path);
+}
+
static void
filter_event_free (EmpathyFilterEventExt *event)
{
@@ -347,6 +371,219 @@ filter_contact_list_ready_cb (EmpathyTpGroup *group,
}
static void
+filter_tubes_async_cb (TpProxy *channel,
+ const GError *error,
+ gpointer user_data,
+ GObject *filter)
+{
+ if (error) {
+ empathy_debug (DEBUG_DOMAIN, "Error %s: %s",
+ user_data, error->message);
+ }
+}
+
+typedef struct {
+ TpChannel *channel;
+ gchar *service;
+ guint type;
+ guint id;
+} FilterTubeData;
+
+static void
+filter_tubes_dispatch (EmpathyFilter *filter,
+ gpointer user_data)
+{
+ FilterTubeData *data = user_data;
+ TpProxy *connection;
+ gchar *object_path;
+ guint handle_type;
+ guint handle;
+ TpProxy *thandler;
+ gchar *thandler_bus_name;
+ gchar *thandler_object_path;
+
+ thandler_bus_name = empathy_tube_handler_build_bus_name (data->type, data->service);
+ thandler_object_path = empathy_tube_handler_build_object_path (data->type, data->service);
+
+ /* Create the proxy for the tube handler */
+ thandler = g_object_new (TP_TYPE_PROXY,
+ "dbus-connection", tp_get_bus (),
+ "bus-name", thandler_bus_name,
+ "object-path", thandler_object_path,
+ NULL);
+ tp_proxy_add_interface_by_id (thandler, EMP_IFACE_QUARK_TUBE_HANDLER);
+
+ /* Give the tube to the handler */
+ g_object_get (data->channel,
+ "connection", &connection,
+ "object-path", &object_path,
+ "handle_type", &handle_type,
+ "handle", &handle,
+ NULL);
+
+ emp_cli_tube_handler_call_handle_tube (thandler, -1,
+ connection->bus_name,
+ connection->object_path,
+ object_path, handle_type, handle,
+ data->id,
+ filter_tubes_async_cb,
+ "handling tube", NULL,
+ G_OBJECT (filter));
+
+ g_free (thandler_bus_name);
+ g_free (thandler_object_path);
+ g_object_unref (thandler);
+ g_object_unref (connection);
+ g_free (object_path);
+
+ g_free (data->service);
+ g_object_unref (data->channel);
+ g_slice_free (FilterTubeData, data);
+
+}
+
+static void
+filter_tubes_new_tube_cb (TpChannel *channel,
+ guint id,
+ guint initiator,
+ guint type,
+ const gchar *service,
+ GHashTable *parameters,
+ guint state,
+ gpointer user_data,
+ GObject *filter)
+{
+ EmpathyFilterPriv *priv = GET_PRIV (filter);
+ guint number;
+ gchar *msg;
+ FilterTubeData *data;
+
+ /* Increase tube count */
+ number = GPOINTER_TO_UINT (g_hash_table_lookup (priv->tubes, channel));
+ g_hash_table_replace (priv->tubes, g_object_ref (channel),
+ GUINT_TO_POINTER (++number));
+ empathy_debug (DEBUG_DOMAIN, "Increased tube count for channel %p: %d",
+ channel, number);
+
+ /* We dispatch only local pending tubes */
+ if (state != TP_TUBE_STATE_LOCAL_PENDING) {
+ return;
+ }
+
+ data = g_slice_new (FilterTubeData);
+ data->channel = g_object_ref (channel);
+ data->service = g_strdup (service);
+ data->type = type;
+ data->id = id;
+ msg = g_strdup_printf (_("Incoming tube for application %s"), service);
+ filter_emit_event (EMPATHY_FILTER (filter), GTK_STOCK_EXECUTE, msg,
+ filter_tubes_dispatch,
+ data);
+ g_free (msg);
+}
+
+static void
+filter_tubes_list_tubes_cb (TpChannel *channel,
+ const GPtrArray *tubes,
+ const GError *error,
+ gpointer user_data,
+ GObject *filter)
+{
+ guint i;
+
+ if (error) {
+ empathy_debug (DEBUG_DOMAIN, "Error listing tubes: %s",
+ error->message);
+ return;
+ }
+
+ for (i = 0; i < tubes->len; i++) {
+ GValueArray *values;
+
+ values = g_ptr_array_index (tubes, i);
+ filter_tubes_new_tube_cb (channel,
+ g_value_get_uint (g_value_array_get_nth (values, 0)),
+ g_value_get_uint (g_value_array_get_nth (values, 1)),
+ g_value_get_uint (g_value_array_get_nth (values, 2)),
+ g_value_get_string (g_value_array_get_nth (values, 3)),
+ g_value_get_boxed (g_value_array_get_nth (values, 4)),
+ g_value_get_uint (g_value_array_get_nth (values, 5)),
+ user_data, filter);
+ }
+}
+
+static void
+filter_tubes_channel_invalidated_cb (TpProxy *proxy,
+ guint domain,
+ gint code,
+ gchar *message,
+ EmpathyFilter *filter)
+{
+ EmpathyFilterPriv *priv = GET_PRIV (filter);
+
+ empathy_debug (DEBUG_DOMAIN, "Channel %p invalidated: %s", proxy, message);
+
+ g_hash_table_remove (priv->tubes, proxy);
+}
+
+static void
+filter_tubes_tube_closed_cb (TpChannel *channel,
+ guint id,
+ gpointer user_data,
+ GObject *filter)
+{
+ EmpathyFilterPriv *priv = GET_PRIV (filter);
+ guint number;
+
+ number = GPOINTER_TO_UINT (g_hash_table_lookup (priv->tubes, channel));
+ if (number == 1) {
+ empathy_debug (DEBUG_DOMAIN, "Ended tube count for channel %p, "
+ "closing channel", channel);
+ tp_cli_channel_call_close (channel, -1, NULL, NULL, NULL, NULL);
+ }
+ else if (number > 1) {
+ empathy_debug (DEBUG_DOMAIN, "Decrease tube count for channel %p: %d",
+ channel, number);
+ g_hash_table_replace (priv->tubes, g_object_ref (channel),
+ GUINT_TO_POINTER (--number));
+ }
+}
+
+static void
+filter_tubes_handle_channel (EmpathyFilter *filter,
+ TpChannel *channel,
+ gboolean is_incoming)
+{
+ EmpathyFilterPriv *priv = GET_PRIV (filter);
+
+ if (g_hash_table_lookup (priv->tubes, channel)) {
+ return;
+ }
+
+ empathy_debug (DEBUG_DOMAIN, "Handling new channel");
+
+ g_hash_table_insert (priv->tubes, g_object_ref (channel),
+ GUINT_TO_POINTER (0));
+
+ g_signal_connect (channel, "invalidated",
+ G_CALLBACK (filter_tubes_channel_invalidated_cb),
+ filter);
+
+ tp_cli_channel_type_tubes_connect_to_tube_closed (channel,
+ filter_tubes_tube_closed_cb,
+ NULL, NULL,
+ G_OBJECT (filter), NULL);
+ tp_cli_channel_type_tubes_connect_to_new_tube (channel,
+ filter_tubes_new_tube_cb,
+ NULL, NULL,
+ G_OBJECT (filter), NULL);
+ tp_cli_channel_type_tubes_call_list_tubes (channel, -1,
+ filter_tubes_list_tubes_cb,
+ NULL, NULL,
+ G_OBJECT (filter));
+}
+
+static void
filter_contact_list_destroy_cb (EmpathyTpGroup *group,
EmpathyFilter *filter)
{
@@ -422,6 +659,8 @@ filter_conection_new_channel_cb (TpConnection *connection,
}
else if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_CONTACT_LIST)) {
func = filter_contact_list_handle_channel;
+ } if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_TUBES)) {
+ func = filter_tubes_handle_channel;
} else {
empathy_debug (DEBUG_DOMAIN, "Unknown channel type %s",
channel_type);
@@ -540,6 +779,7 @@ filter_finalize (GObject *object)
g_slist_free (priv->events);
g_hash_table_destroy (priv->accounts);
+ g_hash_table_destroy (priv->tubes);
}
static void
@@ -584,6 +824,10 @@ empathy_filter_init (EmpathyFilter *filter)
EmpathyFilterPriv *priv = GET_PRIV (filter);
GList *accounts, *l;
+ priv->tubes = g_hash_table_new_full (filter_channel_hash,
+ filter_channel_equal,
+ g_object_unref, NULL);
+
priv->mc = empathy_mission_control_new ();
priv->token = empathy_connect_to_account_status_changed (priv->mc,
G_CALLBACK (filter_status_changed_cb),
diff --git a/src/empathy-tubes-chandler.c b/src/empathy-tubes-chandler.c
deleted file mode 100644
index 5745d8014..000000000
--- a/src/empathy-tubes-chandler.c
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * Copyright (C) 2008 Collabora Ltd.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Authors: Elliot Fairweather <elliot.fairweather@collabora.co.uk>
- */
-
-#include <config.h>
-
-#include <telepathy-glib/channel.h>
-#include <telepathy-glib/connection.h>
-#include <telepathy-glib/proxy-subclass.h>
-#include <telepathy-glib/dbus.h>
-
-#include <extensions/extensions.h>
-
-#include <libempathy/empathy-tube-handler.h>
-#include <libempathy/empathy-chandler.h>
-#include <libempathy/empathy-debug.h>
-#include <libempathy/empathy-utils.h>
-
-#define DEBUG_DOMAIN "TubesChandler"
-
-static GMainLoop *loop = NULL;
-
-
-static void
-async_cb (TpProxy *channel,
- const GError *error,
- gpointer user_data,
- GObject *weak_object)
-{
- if (error)
- empathy_debug (DEBUG_DOMAIN, "Error %s: %s", user_data, error->message);
-}
-
-static void
-new_tube_cb (TpChannel *channel,
- guint id,
- guint initiator,
- guint type,
- const gchar *service,
- GHashTable *parameters,
- guint state,
- gpointer user_data,
- GObject *weak_object)
-{
- GHashTable *channels = (GHashTable *) user_data;
- TpProxy *connection;
- gchar *object_path;
- guint handle_type;
- guint handle;
- gpointer value;
- guint number;
- TpProxy *thandler;
- gchar *thandler_bus_name;
- gchar *thandler_object_path;
-
- /* Increase tube count */
- value = g_hash_table_lookup (channels, channel);
- number = GPOINTER_TO_UINT (value);
- g_hash_table_replace (channels, g_object_ref (channel),
- GUINT_TO_POINTER (++number));
- empathy_debug (DEBUG_DOMAIN, "Increased tube count for channel %p: %d",
- channel, number);
-
- /* We dispatch only local pending tubes */
- if (state != TP_TUBE_STATE_LOCAL_PENDING)
- return;
-
- thandler_bus_name = empathy_tube_handler_build_bus_name (type, service);
- thandler_object_path = empathy_tube_handler_build_object_path (type, service);
-
- empathy_debug (DEBUG_DOMAIN, "Dispatching channel %p id=%d to tube handler: "
- "object_path=%s bus_name=%s", channel, id, thandler_object_path,
- thandler_bus_name);
-
- /* Create the proxy for the tube handler */
- thandler = g_object_new (TP_TYPE_PROXY,
- "dbus-connection", tp_get_bus (),
- "bus-name", thandler_bus_name,
- "object-path", thandler_object_path,
- NULL);
- tp_proxy_add_interface_by_id (thandler, EMP_IFACE_QUARK_TUBE_HANDLER);
-
- /* Give the tube to the handler */
- g_object_get (channel,
- "connection", &connection,
- "object-path", &object_path,
- "handle_type", &handle_type,
- "handle", &handle,
- NULL);
- emp_cli_tube_handler_call_handle_tube (thandler, -1,
- connection->bus_name,
- connection->object_path,
- object_path, handle_type, handle, id,
- async_cb, "handling tube", NULL, NULL);
-
- g_free (thandler_bus_name);
- g_free (thandler_object_path);
- g_object_unref (thandler);
- g_object_unref (connection);
- g_free (object_path);
-}
-
-static void
-list_tubes_cb (TpChannel *channel,
- const GPtrArray *tubes,
- const GError *error,
- gpointer user_data,
- GObject *weak_object)
-{
- guint i;
-
- if (error)
- {
- empathy_debug (DEBUG_DOMAIN, "Error listing tubes: %s", error->message);
- return;
- }
-
- for (i = 0; i < tubes->len; i++)
- {
- GValueArray *values;
-
- values = g_ptr_array_index (tubes, i);
- new_tube_cb (channel,
- g_value_get_uint (g_value_array_get_nth (values, 0)),
- g_value_get_uint (g_value_array_get_nth (values, 1)),
- g_value_get_uint (g_value_array_get_nth (values, 2)),
- g_value_get_string (g_value_array_get_nth (values, 3)),
- g_value_get_boxed (g_value_array_get_nth (values, 4)),
- g_value_get_uint (g_value_array_get_nth (values, 5)),
- user_data, weak_object);
- }
-}
-
-static void
-channel_invalidated_cb (TpProxy *proxy,
- guint domain,
- gint code,
- gchar *message,
- GHashTable *channels)
-{
- empathy_debug (DEBUG_DOMAIN, "Channel invalidated: %p", proxy);
- g_hash_table_remove (channels, proxy);
- if (g_hash_table_size (channels) == 0)
- {
- empathy_debug (DEBUG_DOMAIN, "All channels are closed, leaving");
- g_main_loop_quit (loop);
- }
-}
-
-static void
-tube_closed_cb (TpChannel *channel,
- guint id,
- gpointer user_data,
- GObject *weak_object)
-{
- gpointer value;
- guint number;
- GHashTable *channels = (GHashTable *) user_data;
-
- value = g_hash_table_lookup (channels, channel);
-
- if (value)
- {
- number = GPOINTER_TO_UINT (value);
-
- if (number == 1)
- {
- empathy_debug (DEBUG_DOMAIN, "Ended tube count for channel %p, "
- "closing channel", channel);
- tp_cli_channel_call_close (channel, -1, NULL, NULL, NULL, NULL);
- }
- else if (number > 1)
- {
- g_hash_table_replace (channels, channel, GUINT_TO_POINTER (--number));
- empathy_debug (DEBUG_DOMAIN, "Decreased tube count for channel %p: %d",
- channel, number);
- }
- }
-}
-
-static void
-new_channel_cb (EmpathyChandler *chandler,
- TpChannel *channel,
- GHashTable *channels)
-{
- if (g_hash_table_lookup (channels, channel))
- return;
-
- empathy_debug (DEBUG_DOMAIN, "Handling new channel");
-
- g_hash_table_insert (channels, g_object_ref (channel), GUINT_TO_POINTER (0));
-
- g_signal_connect (channel, "invalidated",
- G_CALLBACK (channel_invalidated_cb),
- channels);
-
- tp_cli_channel_type_tubes_connect_to_tube_closed (channel,
- tube_closed_cb, channels, NULL, NULL, NULL);
- tp_cli_channel_type_tubes_connect_to_new_tube (channel,
- new_tube_cb, channels, NULL, NULL, NULL);
- tp_cli_channel_type_tubes_call_list_tubes (channel, -1,
- list_tubes_cb, channels, NULL, NULL);
-}
-
-static guint
-channel_hash (gconstpointer key)
-{
- TpProxy *channel = TP_PROXY (key);
-
- return g_str_hash (channel->object_path);
-}
-
-static gboolean
-channel_equal (gconstpointer a,
- gconstpointer b)
-{
- TpProxy *channel_a = TP_PROXY (a);
- TpProxy *channel_b = TP_PROXY (b);
-
- return g_str_equal (channel_a->object_path, channel_b->object_path);
-}
-
-int
-main (int argc, char *argv[])
-{
- EmpathyChandler *chandler;
- GHashTable *channels;
-
- g_type_init ();
- emp_cli_init ();
-
- channels = g_hash_table_new_full (channel_hash, channel_equal,
- g_object_unref, NULL);
-
- chandler = empathy_chandler_new ("org.gnome.Empathy.TubesChandler",
- "/org/gnome/Empathy/TubesChandler");
- g_signal_connect (chandler, "new-channel",
- G_CALLBACK (new_channel_cb), channels);
-
- empathy_debug (DEBUG_DOMAIN, "Ready to handle new tubes channels");
-
- loop = g_main_loop_new (NULL, FALSE);
- g_main_loop_run (loop);
-
- g_main_loop_unref (loop);
- g_hash_table_destroy (channels);
- g_object_unref (chandler);
-
- return EXIT_SUCCESS;
-}
-
diff --git a/src/empathy-tubes.chandler b/src/empathy-tubes.chandler
deleted file mode 100644
index 97d5ba016..000000000
--- a/src/empathy-tubes.chandler
+++ /dev/null
@@ -1,4 +0,0 @@
-[ChannelHandler]
-BusName = org.gnome.Empathy.TubesChandler
-ObjectPath = /org/gnome/Empathy/TubesChandler
-ChannelType = org.freedesktop.Telepathy.Channel.Type.Tubes
diff --git a/src/org.gnome.Empathy.Tubes.service.in b/src/org.gnome.Empathy.Tubes.service.in
deleted file mode 100644
index 5a67cd9d1..000000000
--- a/src/org.gnome.Empathy.Tubes.service.in
+++ /dev/null
@@ -1,3 +0,0 @@
-[D-BUS Service]
-Name=org.gnome.Empathy.TubesChandler
-Exec=@libexecdir@/empathy-tubes-chandler