1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Authors: Xavier Claessens <xclaesse@gmail.com>
25 #include <dbus/dbus-glib.h>
27 #include <libtelepathy/tp-helpers.h>
28 #include <libtelepathy/tp-conn.h>
30 #include <mission-control/mcd-dispatcher.h>
31 #include <mission-control/mcd-dispatcher-context.h>
32 #include <mission-control/mcd-channel.h>
34 #include <libempathy/empathy-marshal-main.c>
36 #include "empathy-filter-gen.h"
38 static void filter_plugin_text_channel (McdDispatcherContext *ctx);
39 static void filter_plugin_handle_channel_cb (DBusGProxy *proxy,
41 McdDispatcherContext *ctx);
42 static void filter_plugin_process_cb (DBusGProxy *filter,
45 McdDispatcher *dispatcher);
47 static McdFilter text_in_filters[] = {
48 {filter_plugin_text_channel, MCD_FILTER_PRIORITY_USER},
52 static DBusGProxy *filter = NULL;
53 static GHashTable *contexts = NULL;
54 static guint n_contexts = 0;
57 mcd_filters_init (McdDispatcher *dispatcher)
59 static gboolean initialized = FALSE;
65 filter = dbus_g_proxy_new_for_name (tp_get_bus (),
66 "org.gnome.Empathy.Filter",
67 "/org/gnome/Empathy/Filter",
68 "org.gnome.Empathy.Filter");
70 dbus_g_object_register_marshaller (
71 empathy_marshal_VOID__UINT_BOOLEAN,
77 dbus_g_proxy_add_signal (filter, "Process",
81 dbus_g_proxy_connect_signal (filter, "Process",
82 G_CALLBACK (filter_plugin_process_cb),
85 contexts = g_hash_table_new_full (g_direct_hash,
88 (GDestroyNotify) g_object_unref);
90 mcd_dispatcher_register_filters (dispatcher,
92 TELEPATHY_CHAN_IFACE_TEXT_QUARK,
99 filter_plugin_text_channel (McdDispatcherContext *ctx)
101 const TpConn *tp_conn;
104 tp_conn = mcd_dispatcher_context_get_connection_object (ctx);
105 channel = mcd_dispatcher_context_get_channel (ctx);
108 g_hash_table_insert (contexts,
109 GUINT_TO_POINTER (n_contexts),
112 empathy_filter_handle_channel_async (filter,
113 dbus_g_proxy_get_bus_name (DBUS_G_PROXY (tp_conn)),
114 dbus_g_proxy_get_path (DBUS_G_PROXY (tp_conn)),
115 mcd_channel_get_channel_type (channel),
116 mcd_channel_get_object_path (channel),
117 mcd_channel_get_handle_type (channel),
118 mcd_channel_get_handle (channel),
120 (empathy_filter_handle_channel_reply) filter_plugin_handle_channel_cb,
125 filter_plugin_handle_channel_cb (DBusGProxy *proxy,
127 McdDispatcherContext *ctx)
132 filter_plugin_process_cb (DBusGProxy *filter,
133 guint context_handle,
135 McdDispatcher *dispatcher)
137 McdDispatcherContext *ctx;
139 g_print ("****processing\n");
140 ctx = g_hash_table_lookup (contexts, GUINT_TO_POINTER (context_handle));
141 mcd_dispatcher_context_process (ctx, result);