]> git.0d.be Git - empathy.git/blob - src/empathy-filter.c
[darcs-to-svn @ many changes]
[empathy.git] / src / empathy-filter.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 <config.h>
24
25 #include <dbus/dbus-glib.h>
26
27 #include <libtelepathy/tp-helpers.h>
28 #include <libtelepathy/tp-conn.h>
29 #include <libtelepathy/tp-chan.h>
30
31 #include <libempathy/gossip-debug.h>
32 #include <libempathy/empathy-marshal.h>
33
34 #include "empathy-filter.h"
35
36 #define DEBUG_DOMAIN "EmpathyFilter"
37
38 static gboolean empathy_filter_handle_channel (EmpathyFilter  *filter,
39                                                const gchar    *bus_name,
40                                                const gchar    *connection,
41                                                const gchar    *channel_type,
42                                                const gchar    *channel,
43                                                guint           handle_type,
44                                                guint           handle,
45                                                guint           context_handle,
46                                                GError        **error);
47
48 #include "empathy-filter-glue.h"
49
50 enum {
51         NEW_CHANNEL,
52         PROCESS,
53         LAST_SIGNAL
54 };
55
56 static guint signals[LAST_SIGNAL];
57
58 G_DEFINE_TYPE (EmpathyFilter, empathy_filter, G_TYPE_OBJECT)
59
60 static void
61 empathy_filter_class_init (EmpathyFilterClass *klass)
62 {
63         signals[NEW_CHANNEL] =
64                 g_signal_new ("new-channel",
65                               G_OBJECT_CLASS_TYPE (klass),
66                               G_SIGNAL_RUN_LAST,
67                               0,
68                               NULL, NULL,
69                               empathy_marshal_VOID__OBJECT_OBJECT_UINT,
70                               G_TYPE_NONE,
71                               3, TELEPATHY_CONN_TYPE, TELEPATHY_CHAN_TYPE, G_TYPE_UINT);
72
73         signals[PROCESS] =
74                 g_signal_new ("process",
75                               G_OBJECT_CLASS_TYPE (klass),
76                               G_SIGNAL_RUN_LAST,
77                               0,
78                               NULL, NULL,
79                               empathy_marshal_VOID__UINT_BOOLEAN,
80                               G_TYPE_NONE,
81                               2, G_TYPE_UINT, G_TYPE_BOOLEAN);
82 }
83
84 static void
85 empathy_filter_init (EmpathyFilter *filter)
86 {
87 }
88
89 EmpathyFilter *
90 empathy_filter_new (void)
91 {
92         static gboolean  initialized = FALSE;
93         EmpathyFilter   *filter;
94         DBusGProxy      *proxy;
95         guint            result;
96         GError          *error = NULL;
97
98         if (!initialized) {
99                 dbus_g_object_type_install_info (EMPATHY_TYPE_FILTER,
100                                                  &dbus_glib_empathy_filter_object_info);
101                 initialized = TRUE;
102         }
103
104         proxy = dbus_g_proxy_new_for_name (tp_get_bus (),
105                                            DBUS_SERVICE_DBUS,
106                                            DBUS_PATH_DBUS,
107                                            DBUS_INTERFACE_DBUS);
108
109         if (!dbus_g_proxy_call (proxy, "RequestName", &error,
110                                 G_TYPE_STRING, "org.gnome.Empathy.Filter",
111                                 G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE,
112                                 G_TYPE_INVALID,
113                                 G_TYPE_UINT, &result,
114                                 G_TYPE_INVALID)) {
115                 gossip_debug (DEBUG_DOMAIN,
116                               "Failed to request name: %s",
117                               error ? error->message : "No error given");
118                 g_clear_error (&error);
119
120                 return NULL;
121         }
122         g_object_unref (proxy);
123
124         filter = g_object_new (EMPATHY_TYPE_FILTER, NULL);
125         dbus_g_connection_register_g_object (tp_get_bus (),
126                                              "/org/gnome/Empathy/Filter",
127                                              G_OBJECT (filter));
128
129         return filter;
130 }
131
132 void
133 empathy_filter_process (EmpathyFilter *filter,
134                         guint          context_handle,
135                         gboolean       result)
136 {
137         g_print ("hello\n");
138         g_signal_emit (filter, signals[PROCESS], 0, context_handle, result);
139 }
140
141 static gboolean
142 empathy_filter_handle_channel (EmpathyFilter  *filter,
143                                  const gchar  *bus_name,
144                                  const gchar  *connection,
145                                  const gchar  *channel_type,
146                                  const gchar  *channel,
147                                  guint         handle_type,
148                                  guint         handle,
149                                  guint         context_handle,
150                                  GError      **error)
151 {
152         TpChan *tp_chan;
153         TpConn *tp_conn;
154
155         tp_conn = tp_conn_new (tp_get_bus (),
156                                bus_name,
157                                connection);
158
159         tp_chan = tp_chan_new (tp_get_bus(),
160                                bus_name,
161                                channel,
162                                channel_type,
163                                handle_type,
164                                handle);
165 g_print ("new channel\n");
166         g_signal_emit (filter, signals[NEW_CHANNEL], 0, tp_conn, tp_chan, context_handle);
167
168         g_object_unref (tp_chan);
169         g_object_unref (tp_conn);
170
171         return TRUE;
172 }
173