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>
29 #include <libtelepathy/tp-chan.h>
31 #include <libempathy/gossip-debug.h>
32 #include <libempathy/empathy-marshal.h>
34 #include "empathy-filter.h"
36 #define DEBUG_DOMAIN "EmpathyFilter"
38 static gboolean empathy_filter_handle_channel (EmpathyFilter *filter,
39 const gchar *bus_name,
40 const gchar *connection,
41 const gchar *channel_type,
48 #include "empathy-filter-glue.h"
56 static guint signals[LAST_SIGNAL];
58 G_DEFINE_TYPE (EmpathyFilter, empathy_filter, G_TYPE_OBJECT)
61 empathy_filter_class_init (EmpathyFilterClass *klass)
63 signals[NEW_CHANNEL] =
64 g_signal_new ("new-channel",
65 G_OBJECT_CLASS_TYPE (klass),
69 empathy_marshal_VOID__OBJECT_OBJECT_UINT,
71 3, TELEPATHY_CONN_TYPE, TELEPATHY_CHAN_TYPE, G_TYPE_UINT);
74 g_signal_new ("process",
75 G_OBJECT_CLASS_TYPE (klass),
79 empathy_marshal_VOID__UINT_BOOLEAN,
81 2, G_TYPE_UINT, G_TYPE_BOOLEAN);
85 empathy_filter_init (EmpathyFilter *filter)
90 empathy_filter_new (void)
92 static gboolean initialized = FALSE;
93 EmpathyFilter *filter;
99 dbus_g_object_type_install_info (EMPATHY_TYPE_FILTER,
100 &dbus_glib_empathy_filter_object_info);
104 proxy = dbus_g_proxy_new_for_name (tp_get_bus (),
107 DBUS_INTERFACE_DBUS);
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,
113 G_TYPE_UINT, &result,
115 gossip_debug (DEBUG_DOMAIN,
116 "Failed to request name: %s",
117 error ? error->message : "No error given");
118 g_clear_error (&error);
122 g_object_unref (proxy);
124 filter = g_object_new (EMPATHY_TYPE_FILTER, NULL);
125 dbus_g_connection_register_g_object (tp_get_bus (),
126 "/org/gnome/Empathy/Filter",
133 empathy_filter_process (EmpathyFilter *filter,
134 guint context_handle,
138 g_signal_emit (filter, signals[PROCESS], 0, context_handle, result);
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,
149 guint context_handle,
155 tp_conn = tp_conn_new (tp_get_bus (),
159 tp_chan = tp_chan_new (tp_get_bus(),
165 g_print ("new channel\n");
166 g_signal_emit (filter, signals[NEW_CHANNEL], 0, tp_conn, tp_chan, context_handle);
168 g_object_unref (tp_chan);
169 g_object_unref (tp_conn);