]> git.0d.be Git - empathy.git/blob - src/empathy-filter-plugin.c
[darcs-to-svn @ many changes]
[empathy.git] / src / empathy-filter-plugin.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007 Collabora Ltd.
4  *
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.
9  *
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.
14  *
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.
19  * 
20  * Authors: Xavier Claessens <xclaesse@gmail.com>
21  */
22
23 #include <glib.h>
24
25 #include <dbus/dbus-glib.h>
26
27 #include <libtelepathy/tp-helpers.h>
28 #include <libtelepathy/tp-conn.h>
29
30 #include <mission-control/mcd-dispatcher.h>
31 #include <mission-control/mcd-dispatcher-context.h>
32 #include <mission-control/mcd-channel.h>
33
34 #include <libempathy/empathy-marshal-main.c>
35
36 #include "empathy-filter-gen.h"
37
38 static void filter_plugin_text_channel      (McdDispatcherContext *ctx);
39 static void filter_plugin_handle_channel_cb (DBusGProxy           *proxy,
40                                              GError               *error,
41                                              McdDispatcherContext *ctx);
42 static void filter_plugin_process_cb        (DBusGProxy           *filter,
43                                              guint                 context_handle,
44                                              gboolean              result,
45                                              McdDispatcher        *dispatcher);
46
47 static McdFilter text_in_filters[] = {
48         {filter_plugin_text_channel, MCD_FILTER_PRIORITY_USER},
49         {NULL, 0}
50 };
51
52 static DBusGProxy *filter = NULL;
53 static GHashTable *contexts = NULL;
54 static guint n_contexts = 0;
55
56 void
57 mcd_filters_init (McdDispatcher *dispatcher)
58 {
59         static gboolean initialized = FALSE;
60
61         if (initialized) {
62                 return;
63         }
64
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");
69
70         dbus_g_object_register_marshaller (
71                 empathy_marshal_VOID__UINT_BOOLEAN,
72                 G_TYPE_NONE,
73                 G_TYPE_UINT,
74                 G_TYPE_BOOLEAN,
75                 G_TYPE_INVALID);
76
77         dbus_g_proxy_add_signal (filter, "Process",
78                                  G_TYPE_UINT,
79                                  G_TYPE_BOOLEAN,
80                                  G_TYPE_INVALID);
81         dbus_g_proxy_connect_signal (filter, "Process",
82                                      G_CALLBACK (filter_plugin_process_cb),
83                                      dispatcher,
84                                      NULL);
85         contexts = g_hash_table_new_full (g_direct_hash,
86                                           g_direct_equal,
87                                           NULL,
88                                           (GDestroyNotify) g_object_unref);
89
90         mcd_dispatcher_register_filters (dispatcher,
91                                          text_in_filters,
92                                          TELEPATHY_CHAN_IFACE_TEXT_QUARK,
93                                          MCD_FILTER_IN);
94
95         initialized = TRUE;
96 }
97
98 static void
99 filter_plugin_text_channel (McdDispatcherContext *ctx)
100 {
101         const TpConn *tp_conn;
102         McdChannel   *channel;
103
104         tp_conn = mcd_dispatcher_context_get_connection_object (ctx);
105         channel = mcd_dispatcher_context_get_channel (ctx);
106
107         n_contexts++;
108         g_hash_table_insert (contexts,
109                              GUINT_TO_POINTER (n_contexts),
110                              ctx);
111
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),
119                                              n_contexts,
120                                              (empathy_filter_handle_channel_reply) filter_plugin_handle_channel_cb,
121                                              ctx);
122 }
123
124 static void
125 filter_plugin_handle_channel_cb (DBusGProxy           *proxy,
126                                  GError               *error,
127                                  McdDispatcherContext *ctx)
128 {
129 }
130
131 static void
132 filter_plugin_process_cb (DBusGProxy    *filter,
133                           guint          context_handle,
134                           gboolean       result,
135                           McdDispatcher *dispatcher)
136 {
137         McdDispatcherContext *ctx;
138
139         g_print ("****processing\n");
140         ctx = g_hash_table_lookup (contexts, GUINT_TO_POINTER (context_handle));
141         mcd_dispatcher_context_process (ctx, result);
142 }
143