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 "empathy-filter.h"
31 #include "empathy-debug.h"
32 #include "empathy-utils.h"
33 #include "empathy-marshal.h"
35 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
36 EMPATHY_TYPE_FILTER, EmpathyFilterPriv))
38 #define DEBUG_DOMAIN "EmpathyFilter"
40 struct _EmpathyFilterPriv {
44 static void empathy_filter_class_init (EmpathyFilterClass *klass);
45 static void empathy_filter_init (EmpathyFilter *filter);
46 static void filter_finalize (GObject *object);
47 static gboolean empathy_filter_filter_channel (EmpathyFilter *filter,
48 const gchar *bus_name,
49 const gchar *connection,
50 const gchar *channel_type,
57 #include "empathy-filter-glue.h"
65 static guint signals[LAST_SIGNAL];
67 G_DEFINE_TYPE (EmpathyFilter, empathy_filter, G_TYPE_OBJECT)
70 empathy_filter_class_init (EmpathyFilterClass *klass)
72 GObjectClass *object_class = G_OBJECT_CLASS (klass);
74 object_class->finalize = filter_finalize;
76 signals[NEW_CHANNEL] =
77 g_signal_new ("new-channel",
78 G_OBJECT_CLASS_TYPE (klass),
82 empathy_marshal_VOID__OBJECT_OBJECT,
84 2, TELEPATHY_CONN_TYPE, TELEPATHY_CHAN_TYPE);
87 g_signal_new ("process",
88 G_OBJECT_CLASS_TYPE (klass),
92 empathy_marshal_VOID__UINT_BOOLEAN,
94 2, G_TYPE_UINT, G_TYPE_BOOLEAN);
96 g_type_class_add_private (object_class, sizeof (EmpathyFilterPriv));
100 empathy_filter_init (EmpathyFilter *filter)
102 EmpathyFilterPriv *priv;
104 priv = GET_PRIV (filter);
106 priv->table = g_hash_table_new_full (g_direct_hash, g_direct_equal,
107 (GDestroyNotify) g_object_unref,
112 filter_finalize (GObject *object)
114 EmpathyFilterPriv *priv;
116 priv = GET_PRIV (object);
118 g_hash_table_destroy (priv->table);
122 empathy_filter_new (const gchar *bus_name,
123 const gchar *object_path,
124 const gchar *channel_type,
128 static gboolean initialized = FALSE;
130 EmpathyFilter *filter;
133 GError *error = NULL;
136 dbus_g_object_type_install_info (EMPATHY_TYPE_FILTER,
137 &dbus_glib_empathy_filter_object_info);
141 proxy = dbus_g_proxy_new_for_name (tp_get_bus (),
144 DBUS_INTERFACE_DBUS);
146 if (!dbus_g_proxy_call (proxy, "RequestName", &error,
147 G_TYPE_STRING, bus_name,
148 G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE,
150 G_TYPE_UINT, &result,
152 empathy_debug (DEBUG_DOMAIN,
153 "Failed to request name: %s",
154 error ? error->message : "No error given");
155 g_clear_error (&error);
159 g_object_unref (proxy);
161 filter = g_object_new (EMPATHY_TYPE_FILTER, NULL);
162 dbus_g_connection_register_g_object (tp_get_bus (),
166 mc = empathy_mission_control_new ();
167 mission_control_register_filter (mc,
180 empathy_filter_process (EmpathyFilter *filter,
184 EmpathyFilterPriv *priv;
187 priv = GET_PRIV (filter);
189 id = GPOINTER_TO_UINT (g_hash_table_lookup (priv->table, tp_chan));
191 g_signal_emit (filter, signals[PROCESS], 0, id, process);
192 g_hash_table_remove (priv->table, tp_chan);
197 empathy_filter_filter_channel (EmpathyFilter *filter,
198 const gchar *bus_name,
199 const gchar *connection,
200 const gchar *channel_type,
201 const gchar *channel,
207 EmpathyFilterPriv *priv;
211 priv = GET_PRIV (filter);
213 tp_conn = tp_conn_new (tp_get_bus (),
217 tp_chan = tp_chan_new (tp_get_bus(),
224 g_hash_table_insert (priv->table, tp_chan, GUINT_TO_POINTER (id));
226 g_signal_emit (filter, signals[NEW_CHANNEL], 0, tp_conn, tp_chan);
228 g_object_unref (tp_conn);