diff options
Diffstat (limited to 'src/empathy-filter-plugin.c')
-rw-r--r-- | src/empathy-filter-plugin.c | 110 |
1 files changed, 96 insertions, 14 deletions
diff --git a/src/empathy-filter-plugin.c b/src/empathy-filter-plugin.c index dfd749160..ee90d974e 100644 --- a/src/empathy-filter-plugin.c +++ b/src/empathy-filter-plugin.c @@ -22,40 +22,122 @@ #include <glib.h> -#include <mcd-dispatcher.h> -#include <mcd-dispatcher-context.h> +#include <dbus/dbus-glib.h> -static void filter_plugin_text_channel (McdDispatcherContext *ctx); +#include <libtelepathy/tp-helpers.h> +#include <libtelepathy/tp-conn.h> + +#include <mission-control/mcd-dispatcher.h> +#include <mission-control/mcd-dispatcher-context.h> +#include <mission-control/mcd-channel.h> + +#include <libempathy/empathy-marshal-main.c> + +#include "empathy-filter-gen.h" + +static void filter_plugin_text_channel (McdDispatcherContext *ctx); +static void filter_plugin_handle_channel_cb (DBusGProxy *proxy, + GError *error, + McdDispatcherContext *ctx); +static void filter_plugin_process_cb (DBusGProxy *filter, + guint context_handle, + gboolean result, + McdDispatcher *dispatcher); static McdFilter text_in_filters[] = { - {filter_plugin_text_channel, MCD_FILTER_PRIORITY_USER}, - {NULL, 0} + {filter_plugin_text_channel, MCD_FILTER_PRIORITY_USER}, + {NULL, 0} }; +static DBusGProxy *filter = NULL; +static GHashTable *contexts = NULL; +static guint n_contexts = 0; + void mcd_filters_init (McdDispatcher *dispatcher) { + static gboolean initialized = FALSE; + + if (initialized) { + return; + } + + filter = dbus_g_proxy_new_for_name (tp_get_bus (), + "org.gnome.Empathy.Filter", + "/org/gnome/Empathy/Filter", + "org.gnome.Empathy.Filter"); + + dbus_g_object_register_marshaller ( + empathy_marshal_VOID__UINT_BOOLEAN, + G_TYPE_NONE, + G_TYPE_UINT, + G_TYPE_BOOLEAN, + G_TYPE_INVALID); + + dbus_g_proxy_add_signal (filter, "Process", + G_TYPE_UINT, + G_TYPE_BOOLEAN, + G_TYPE_INVALID); + dbus_g_proxy_connect_signal (filter, "Process", + G_CALLBACK (filter_plugin_process_cb), + dispatcher, + NULL); + contexts = g_hash_table_new_full (g_direct_hash, + g_direct_equal, + NULL, + (GDestroyNotify) g_object_unref); + mcd_dispatcher_register_filters (dispatcher, text_in_filters, TELEPATHY_CHAN_IFACE_TEXT_QUARK, MCD_FILTER_IN); + + initialized = TRUE; } static void filter_plugin_text_channel (McdDispatcherContext *ctx) { - McdChannel *channel; - const gchar *channel_name; + const TpConn *tp_conn; + McdChannel *channel; + tp_conn = mcd_dispatcher_context_get_connection_object (ctx); channel = mcd_dispatcher_context_get_channel (ctx); - channel_name = mcd_channel_get_name (channel); - if (strcmp (channel_name, "goerge.w.bush@whitehouse.com") == 0) { - g_debug ("Blocking contact"); - mcd_dispatcher_context_process (ctx, FALSE); - return; - } + n_contexts++; + g_hash_table_insert (contexts, + GUINT_TO_POINTER (n_contexts), + ctx); + + empathy_filter_handle_channel_async (filter, + dbus_g_proxy_get_bus_name (DBUS_G_PROXY (tp_conn)), + dbus_g_proxy_get_path (DBUS_G_PROXY (tp_conn)), + mcd_channel_get_channel_type (channel), + mcd_channel_get_object_path (channel), + mcd_channel_get_handle_type (channel), + mcd_channel_get_handle (channel), + n_contexts, + (empathy_filter_handle_channel_reply) filter_plugin_handle_channel_cb, + ctx); +} + +static void +filter_plugin_handle_channel_cb (DBusGProxy *proxy, + GError *error, + McdDispatcherContext *ctx) +{ +} + +static void +filter_plugin_process_cb (DBusGProxy *filter, + guint context_handle, + gboolean result, + McdDispatcher *dispatcher) +{ + McdDispatcherContext *ctx; - mcd_dispatcher_context_process (ctx, TRUE); + g_print ("****processing\n"); + ctx = g_hash_table_lookup (contexts, GUINT_TO_POINTER (context_handle)); + mcd_dispatcher_context_process (ctx, result); } |