1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007-2008 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library 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 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Authors: Xavier Claessens <xclaesse@gmail.com>
26 #include <glib/gi18n.h>
28 #include <telepathy-glib/enums.h>
29 #include <telepathy-glib/channel.h>
30 #include <telepathy-glib/connection.h>
31 #include <telepathy-glib/util.h>
32 #include <telepathy-glib/dbus.h>
33 #include <telepathy-glib/proxy-subclass.h>
35 #include <libmissioncontrol/mission-control.h>
36 #include <libmissioncontrol/mc-account.h>
38 #include <extensions/extensions.h>
40 #include <libempathy/empathy-tp-chat.h>
41 #include <libempathy/empathy-tp-call.h>
42 #include <libempathy/empathy-tp-group.h>
43 #include <libempathy/empathy-utils.h>
44 #include <libempathy/empathy-tube-handler.h>
45 #include <libempathy/empathy-contact-factory.h>
47 #include <libempathy-gtk/empathy-chat.h>
48 #include <libempathy-gtk/empathy-images.h>
49 #include <libempathy-gtk/empathy-contact-dialogs.h>
51 #include "empathy-filter.h"
52 #include "empathy-chat-window.h"
53 #include "empathy-call-window.h"
55 #define DEBUG_FLAG EMPATHY_DEBUG_FILTER
56 #include <libempathy/empathy-debug.h>
58 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
59 EMPATHY_TYPE_FILTER, EmpathyFilterPriv))
61 struct _EmpathyFilterPriv {
69 static void empathy_filter_class_init (EmpathyFilterClass *klass);
70 static void empathy_filter_init (EmpathyFilter *filter);
72 G_DEFINE_TYPE (EmpathyFilter, empathy_filter, G_TYPE_OBJECT);
79 typedef void (*FilterFunc) (EmpathyFilter *filter,
83 EmpathyFilterEvent public;
86 } EmpathyFilterEventExt;
89 filter_channel_hash (gconstpointer key)
91 TpProxy *channel = TP_PROXY (key);
93 return g_str_hash (channel->object_path);
97 filter_channel_equal (gconstpointer a,
100 TpProxy *channel_a = TP_PROXY (a);
101 TpProxy *channel_b = TP_PROXY (b);
103 return g_str_equal (channel_a->object_path, channel_b->object_path);
107 filter_event_free (EmpathyFilterEventExt *event)
109 g_free (event->public.icon_name);
110 g_free (event->public.message);
111 g_slice_free (EmpathyFilterEventExt, event);
115 filter_emit_event (EmpathyFilter *filter,
116 const gchar *icon_name,
117 const gchar *message,
121 EmpathyFilterPriv *priv = GET_PRIV (filter);
122 EmpathyFilterEventExt *event;
124 DEBUG ("Emit event, icon_name=%s message='%s'", icon_name, message);
126 event = g_slice_new0 (EmpathyFilterEventExt);
128 event->user_data = user_data;
129 event->public.icon_name = g_strdup (icon_name);
130 event->public.message = g_strdup (message);
132 priv->events = g_slist_append (priv->events, event);
133 if (priv->events->data == event) {
134 g_object_notify (G_OBJECT (filter), "top-event");
139 empathy_filter_activate_event (EmpathyFilter *filter,
140 EmpathyFilterEvent *event)
142 EmpathyFilterPriv *priv = GET_PRIV (filter);
143 EmpathyFilterEventExt *event_ext;
147 g_return_if_fail (EMPATHY_IS_FILTER (filter));
148 g_return_if_fail (event != NULL);
150 if (!(l = g_slist_find (priv->events, event))) {
154 DEBUG ("Activating event");
156 is_top = (l == priv->events);
157 priv->events = g_slist_delete_link (priv->events, l);
159 g_object_notify (G_OBJECT (filter), "top-event");
162 event_ext = (EmpathyFilterEventExt*) event;
163 if (event_ext->func) {
164 event_ext->func (filter, event_ext->user_data);
167 filter_event_free (event_ext);
171 empathy_filter_get_top_event (EmpathyFilter *filter)
173 EmpathyFilterPriv *priv = GET_PRIV (filter);
175 g_return_val_if_fail (EMPATHY_IS_FILTER (filter), NULL);
177 return priv->events ? priv->events->data : NULL;
181 filter_chat_dispatch (EmpathyFilter *filter,
184 EmpathyTpChat *tp_chat = EMPATHY_TP_CHAT (user_data);
185 EmpathyChat *chat = NULL;
188 id = empathy_tp_chat_get_id (tp_chat);
190 EmpathyContact *contact;
192 contact = empathy_tp_chat_get_remote_contact (tp_chat);
194 id = empathy_contact_get_id (contact);
201 account = empathy_tp_chat_get_account (tp_chat);
202 chat = empathy_chat_window_find_chat (account, id);
206 empathy_chat_set_tp_chat (chat, tp_chat);
208 chat = empathy_chat_new (tp_chat);
211 empathy_chat_window_present_chat (chat);
212 g_object_unref (tp_chat);
216 filter_chat_message_received_cb (EmpathyTpChat *tp_chat,
217 EmpathyMessage *message,
218 EmpathyFilter *filter)
220 EmpathyContact *sender;
223 g_signal_handlers_disconnect_by_func (tp_chat,
224 filter_chat_message_received_cb,
227 sender = empathy_message_get_sender (message);
228 msg = g_strdup_printf (_("New message from %s:\n%s"),
229 empathy_contact_get_name (sender),
230 empathy_message_get_body (message));
232 filter_emit_event (filter, EMPATHY_IMAGE_NEW_MESSAGE, msg,
233 filter_chat_dispatch, tp_chat);
239 filter_chat_handle_channel (EmpathyFilter *filter,
241 gboolean is_incoming)
243 EmpathyTpChat *tp_chat;
245 DEBUG ("New text channel to be filtered: %p", channel);
247 tp_chat = empathy_tp_chat_new (channel, FALSE);
248 empathy_run_until_ready (tp_chat);
250 filter_chat_dispatch (filter, tp_chat);
252 g_signal_connect (tp_chat, "message-received",
253 G_CALLBACK (filter_chat_message_received_cb),
259 filter_call_dispatch (EmpathyFilter *filter,
262 EmpathyTpCall *call = EMPATHY_TP_CALL (user_data);
264 empathy_call_window_new (call);
265 g_object_unref (call);
269 filter_call_contact_notify_cb (EmpathyTpCall *call,
271 EmpathyFilter *filter)
273 EmpathyContact *contact;
276 g_object_get (call, "contact", &contact, NULL);
281 empathy_contact_run_until_ready (contact,
282 EMPATHY_CONTACT_READY_NAME,
285 msg = g_strdup_printf (_("Incoming call from %s"),
286 empathy_contact_get_name (contact));
288 filter_emit_event (filter, EMPATHY_IMAGE_VOIP, msg,
289 filter_call_dispatch, call);
292 g_object_unref (contact);
296 filter_call_handle_channel (EmpathyFilter *filter,
298 gboolean is_incoming)
302 DEBUG ("New media channel to be filtered: %p", channel);
304 call = empathy_tp_call_new (channel);
306 filter_call_dispatch (filter, call);
308 g_signal_connect (call, "notify::contact",
309 G_CALLBACK (filter_call_contact_notify_cb),
315 filter_contact_list_subscribe (EmpathyFilter *filter,
318 EmpathyContact *contact = EMPATHY_CONTACT (user_data);
320 empathy_subscription_dialog_show (contact, NULL);
321 g_object_unref (contact);
325 filter_contact_list_local_pending_cb (EmpathyTpGroup *group,
326 EmpathyContact *contact,
327 EmpathyContact *actor,
330 EmpathyFilter *filter)
334 DEBUG ("New local pending contact");
336 empathy_contact_run_until_ready (contact,
337 EMPATHY_CONTACT_READY_NAME,
340 str = g_string_new (NULL);
341 g_string_printf (str, _("Subscription requested by %s"),
342 empathy_contact_get_name (contact));
343 if (!G_STR_EMPTY (message)) {
344 g_string_append_printf (str, _("\nMessage: %s"), message);
347 filter_emit_event (filter, GTK_STOCK_DIALOG_QUESTION, str->str,
348 filter_contact_list_subscribe,
349 g_object_ref (contact));
351 g_string_free (str, TRUE);
355 filter_contact_list_ready_cb (EmpathyTpGroup *group,
357 EmpathyFilter *filter)
361 if (tp_strdiff ("publish", empathy_tp_group_get_name (group))) {
362 g_object_unref (group);
366 DEBUG ("Publish contact list ready");
368 g_signal_connect (group, "local-pending",
369 G_CALLBACK (filter_contact_list_local_pending_cb),
372 pendings = empathy_tp_group_get_local_pendings (group);
373 for (l = pendings; l; l = l->next) {
374 EmpathyPendingInfo *info = l->data;
376 filter_contact_list_local_pending_cb (group, info->member,
377 info->actor, info->reason,
378 info->message, filter);
379 empathy_pending_info_free (info);
381 g_list_free (pendings);
385 filter_tubes_async_cb (TpProxy *channel,
391 DEBUG ("Error %s: %s", (gchar*) user_data, error->message);
396 EmpathyContactFactory *factory;
397 EmpathyContact *initiator;
402 gboolean activatable;
406 filter_tubes_dispatch (EmpathyFilter *filter,
409 FilterTubesData *data = user_data;
411 if (data->activatable) {
418 /* Create the proxy for the tube handler */
419 thandler = g_object_new (TP_TYPE_PROXY,
420 "dbus-connection", tp_get_bus (),
421 "bus-name", data->bus_name,
422 "object-path", data->object_path,
424 tp_proxy_add_interface_by_id (thandler, EMP_IFACE_QUARK_TUBE_HANDLER);
426 /* Give the tube to the handler */
427 g_object_get (data->channel,
428 "connection", &connection,
429 "object-path", &object_path,
430 "handle_type", &handle_type,
434 DEBUG ("Dispatching tube");
435 emp_cli_tube_handler_call_handle_tube (thandler, -1,
436 connection->bus_name,
437 connection->object_path,
438 object_path, handle_type,
440 filter_tubes_async_cb,
441 "handling tube", NULL,
444 g_object_unref (thandler);
445 g_object_unref (connection);
446 g_free (object_path);
451 /* Tell the user that the tube can't be handled */
452 str = g_strdup_printf (_("%s offered you an invitation, but "
453 "you don't have the needed external "
454 "application to handle it."),
455 empathy_contact_get_name (data->initiator));
457 dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
459 GTK_BUTTONS_OK, str);
460 gtk_window_set_title (GTK_WINDOW (dialog),
461 _("Invitation Error"));
464 gtk_widget_show (dialog);
465 g_signal_connect (dialog, "response",
466 G_CALLBACK (gtk_widget_destroy),
469 DEBUG ("Tube can't be handled, closing");
470 tp_cli_channel_type_tubes_call_close_tube (data->channel, -1,
476 g_free (data->bus_name);
477 g_free (data->object_path);
478 g_object_unref (data->channel);
479 g_object_unref (data->initiator);
480 g_object_unref (data->factory);
481 g_slice_free (FilterTubesData, data);
485 filter_tubes_new_tube_cb (TpChannel *channel,
489 const gchar *service,
490 GHashTable *parameters,
495 EmpathyFilterPriv *priv = GET_PRIV (filter);
496 static TpDBusDaemon *daemon = NULL;
497 FilterTubesData *data;
502 gboolean running = FALSE;
503 const gchar *icon_name;
504 GError *error = NULL;
506 /* Increase tube count */
507 number = GPOINTER_TO_UINT (g_hash_table_lookup (priv->tubes, channel));
508 g_hash_table_replace (priv->tubes, g_object_ref (channel),
509 GUINT_TO_POINTER (++number));
510 DEBUG ("Increased tube count for channel %p: %d", channel, number);
512 /* We dispatch only local pending tubes */
513 if (state != TP_TUBE_STATE_LOCAL_PENDING) {
518 daemon = tp_dbus_daemon_new (tp_get_bus ());
521 account = empathy_channel_get_account (channel);
522 data = g_slice_new (FilterTubesData);
523 data->activatable = FALSE;
525 data->channel = g_object_ref (channel);
526 data->factory = empathy_contact_factory_new ();
527 data->initiator = empathy_contact_factory_get_from_handle (data->factory,
530 data->bus_name = empathy_tube_handler_build_bus_name (type, service);
531 data->object_path = empathy_tube_handler_build_object_path (type, service);
532 g_object_unref (account);
534 /* Check if that bus-name has an owner, if it has one that means the
535 * app is already running and we can directly give the channel. */
536 tp_cli_dbus_daemon_run_name_has_owner (daemon, -1, data->bus_name,
537 &running, NULL, NULL);
539 DEBUG ("Tube handler running");
540 data->activatable = TRUE;
541 filter_tubes_dispatch (EMPATHY_FILTER (filter), data);
545 /* Check if that bus-name is activatable, if not that means the
546 * application needed to handle this tube isn't installed. */
547 if (!tp_cli_dbus_daemon_run_list_activatable_names (daemon, -1,
550 DEBUG ("Error listing activatable names: %s", error->message);
551 g_clear_error (&error);
555 for (name = names; *name; name++) {
556 if (!tp_strdiff (*name, data->bus_name)) {
557 data->activatable = TRUE;
564 empathy_contact_run_until_ready (data->initiator,
565 EMPATHY_CONTACT_READY_NAME, NULL);
567 if (data->activatable) {
568 icon_name = GTK_STOCK_EXECUTE;
569 msg = g_strdup_printf (_("%s is offering you an invitation. An external "
570 "application will be started to handle it."),
571 empathy_contact_get_name (data->initiator));
573 icon_name = GTK_STOCK_DIALOG_ERROR;
574 msg = g_strdup_printf (_("%s is offering you an invitation, but "
575 "you don't have the needed external "
576 "application to handle it."),
577 empathy_contact_get_name (data->initiator));
580 filter_emit_event (EMPATHY_FILTER (filter), icon_name, msg,
581 filter_tubes_dispatch, data);
587 filter_tubes_list_tubes_cb (TpChannel *channel,
588 const GPtrArray *tubes,
596 DEBUG ("Error listing tubes: %s", error->message);
600 for (i = 0; i < tubes->len; i++) {
603 values = g_ptr_array_index (tubes, i);
604 filter_tubes_new_tube_cb (channel,
605 g_value_get_uint (g_value_array_get_nth (values, 0)),
606 g_value_get_uint (g_value_array_get_nth (values, 1)),
607 g_value_get_uint (g_value_array_get_nth (values, 2)),
608 g_value_get_string (g_value_array_get_nth (values, 3)),
609 g_value_get_boxed (g_value_array_get_nth (values, 4)),
610 g_value_get_uint (g_value_array_get_nth (values, 5)),
616 filter_tubes_channel_invalidated_cb (TpProxy *proxy,
620 EmpathyFilter *filter)
622 EmpathyFilterPriv *priv = GET_PRIV (filter);
624 DEBUG ("Channel %p invalidated: %s", proxy, message);
626 g_hash_table_remove (priv->tubes, proxy);
630 filter_tubes_tube_closed_cb (TpChannel *channel,
635 EmpathyFilterPriv *priv = GET_PRIV (filter);
638 number = GPOINTER_TO_UINT (g_hash_table_lookup (priv->tubes, channel));
640 DEBUG ("Ended tube count for channel %p, closing channel",
642 tp_cli_channel_call_close (channel, -1, NULL, NULL, NULL, NULL);
644 else if (number > 1) {
645 DEBUG ("Decrease tube count for channel %p: %d", channel, number);
646 g_hash_table_replace (priv->tubes, g_object_ref (channel),
647 GUINT_TO_POINTER (--number));
652 filter_tubes_handle_channel (EmpathyFilter *filter,
654 gboolean is_incoming)
656 EmpathyFilterPriv *priv = GET_PRIV (filter);
658 if (g_hash_table_lookup (priv->tubes, channel)) {
662 DEBUG ("Handling new channel");
664 g_hash_table_insert (priv->tubes, g_object_ref (channel),
665 GUINT_TO_POINTER (0));
667 g_signal_connect (channel, "invalidated",
668 G_CALLBACK (filter_tubes_channel_invalidated_cb),
671 tp_cli_channel_type_tubes_connect_to_tube_closed (channel,
672 filter_tubes_tube_closed_cb,
674 G_OBJECT (filter), NULL);
675 tp_cli_channel_type_tubes_connect_to_new_tube (channel,
676 filter_tubes_new_tube_cb,
678 G_OBJECT (filter), NULL);
679 tp_cli_channel_type_tubes_call_list_tubes (channel, -1,
680 filter_tubes_list_tubes_cb,
686 filter_contact_list_destroy_cb (EmpathyTpGroup *group,
687 EmpathyFilter *filter)
689 g_object_unref (group);
693 filter_contact_list_handle_channel (EmpathyFilter *filter,
695 gboolean is_incoming)
697 EmpathyTpGroup *group;
699 group = empathy_tp_group_new (channel);
700 g_signal_connect (group, "notify::ready",
701 G_CALLBACK (filter_contact_list_ready_cb),
703 g_signal_connect (group, "destroy",
704 G_CALLBACK (filter_contact_list_destroy_cb),
709 filter_connection_invalidated_cb (TpConnection *connection,
713 EmpathyFilter *filter)
715 EmpathyFilterPriv *priv = GET_PRIV (filter);
719 DEBUG ("connection invalidated: %s", message);
721 g_hash_table_iter_init (&iter, priv->accounts);
722 while (g_hash_table_iter_next (&iter, &key, &value)) {
723 if (value == connection) {
724 g_hash_table_remove (priv->accounts, key);
730 typedef void (*HandleChannelFunc) (EmpathyFilter *filter,
732 gboolean is_incoming);
735 filter_conection_new_channel_cb (TpConnection *connection,
736 const gchar *object_path,
737 const gchar *channel_type,
740 gboolean suppress_handler,
744 HandleChannelFunc func = NULL;
746 gpointer had_channels;
748 had_channels = g_object_get_data (G_OBJECT (connection), "had-channels");
749 if (had_channels == NULL) {
753 if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_TEXT)) {
754 func = filter_chat_handle_channel;
756 else if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA)) {
757 func = filter_call_handle_channel;
759 else if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_CONTACT_LIST)) {
760 func = filter_contact_list_handle_channel;
762 else if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_TUBES)) {
763 func = filter_tubes_handle_channel;
765 DEBUG ("Unknown channel type %s", channel_type);
769 channel = tp_channel_new (connection, object_path, channel_type,
770 handle_type, handle, NULL);
771 tp_channel_run_until_ready (channel, NULL, NULL);
773 /* We abuse of suppress_handler, TRUE means OUTGOING */
774 func (EMPATHY_FILTER (filter), channel, suppress_handler);
776 g_object_unref (channel);
780 filter_connection_list_channels_cb (TpConnection *connection,
781 const GPtrArray *channels,
789 DEBUG ("Error listing channels: %s", error->message);
793 g_object_set_data (G_OBJECT (connection), "had-channels",
794 GUINT_TO_POINTER (1));
796 for (i = 0; i < channels->len; i++) {
799 values = g_ptr_array_index (channels, i);
800 filter_conection_new_channel_cb (connection,
801 g_value_get_boxed (g_value_array_get_nth (values, 0)),
802 g_value_get_string (g_value_array_get_nth (values, 1)),
803 g_value_get_uint (g_value_array_get_nth (values, 2)),
804 g_value_get_uint (g_value_array_get_nth (values, 3)),
805 TRUE, user_data, filter);
810 filter_connection_advertise_capabilities_cb (TpConnection *connection,
811 const GPtrArray *capabilities,
817 DEBUG ("Error advertising capabilities: %s", error->message);
822 filter_connection_ready_cb (TpConnection *connection,
824 EmpathyFilter *filter)
826 GPtrArray *capabilities;
829 const gchar *remove = NULL;
831 DEBUG ("Connection ready, accepting new channels");
833 tp_cli_connection_connect_to_new_channel (connection,
834 filter_conection_new_channel_cb,
836 G_OBJECT (filter), NULL);
837 tp_cli_connection_call_list_channels (connection, -1,
838 filter_connection_list_channels_cb,
842 /* Advertise VoIP capabilities */
843 capabilities = g_ptr_array_sized_new (1);
844 cap_type = dbus_g_type_get_struct ("GValueArray", G_TYPE_STRING,
845 G_TYPE_UINT, G_TYPE_INVALID);
846 g_value_init (&cap, cap_type);
847 g_value_take_boxed (&cap, dbus_g_type_specialized_construct (cap_type));
848 dbus_g_type_struct_set (&cap,
849 0, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
850 1, TP_CHANNEL_MEDIA_CAPABILITY_AUDIO |
851 TP_CHANNEL_MEDIA_CAPABILITY_VIDEO |
852 TP_CHANNEL_MEDIA_CAPABILITY_NAT_TRAVERSAL_STUN |
853 TP_CHANNEL_MEDIA_CAPABILITY_NAT_TRAVERSAL_GTALK_P2P,
855 g_ptr_array_add (capabilities, g_value_get_boxed (&cap));
857 tp_cli_connection_interface_capabilities_call_advertise_capabilities (
859 capabilities, &remove,
860 filter_connection_advertise_capabilities_cb,
861 NULL, NULL, G_OBJECT (filter));
865 filter_update_account (EmpathyFilter *filter,
868 EmpathyFilterPriv *priv = GET_PRIV (filter);
869 TpConnection *connection;
872 connection = g_hash_table_lookup (priv->accounts, account);
877 connection = mission_control_get_tpconnection (priv->mc, account, NULL);
882 g_hash_table_insert (priv->accounts, g_object_ref (account), connection);
883 g_signal_connect (connection, "invalidated",
884 G_CALLBACK (filter_connection_invalidated_cb),
887 g_object_get (connection, "connection-ready", &ready, NULL);
889 filter_connection_ready_cb (connection, NULL, filter);
891 g_signal_connect (connection, "notify::connection-ready",
892 G_CALLBACK (filter_connection_ready_cb),
898 filter_status_changed_cb (MissionControl *mc,
899 TpConnectionStatus status,
901 TpConnectionStatusReason reason,
902 const gchar *unique_name,
903 EmpathyFilter *filter)
907 account = mc_account_lookup (unique_name);
908 filter_update_account (filter, account);
909 g_object_unref (account);
913 filter_finalize (GObject *object)
915 EmpathyFilterPriv *priv = GET_PRIV (object);
917 empathy_disconnect_account_status_changed (priv->token);
918 g_object_unref (priv->mc);
920 g_slist_foreach (priv->events, (GFunc) filter_event_free, NULL);
921 g_slist_free (priv->events);
923 g_hash_table_destroy (priv->accounts);
924 g_hash_table_destroy (priv->tubes);
928 filter_get_property (GObject *object,
933 EmpathyFilterPriv *priv = GET_PRIV (object);
937 g_value_set_pointer (value, priv->events ? priv->events->data : NULL);
940 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
946 empathy_filter_class_init (EmpathyFilterClass *klass)
948 GObjectClass *object_class = G_OBJECT_CLASS (klass);
950 object_class->finalize = filter_finalize;
951 object_class->get_property = filter_get_property;
953 g_object_class_install_property (object_class,
955 g_param_spec_pointer ("top-event",
957 "The first event in the events list",
960 g_type_class_add_private (object_class, sizeof (EmpathyFilterPriv));
964 empathy_filter_init (EmpathyFilter *filter)
966 EmpathyFilterPriv *priv = GET_PRIV (filter);
969 priv->tubes = g_hash_table_new_full (filter_channel_hash,
970 filter_channel_equal,
971 g_object_unref, NULL);
973 priv->mc = empathy_mission_control_new ();
974 priv->token = empathy_connect_to_account_status_changed (priv->mc,
975 G_CALLBACK (filter_status_changed_cb),
978 priv->accounts = g_hash_table_new_full (empathy_account_hash,
979 empathy_account_equal,
982 accounts = mc_accounts_list_by_enabled (TRUE);
983 for (l = accounts; l; l = l->next) {
984 filter_update_account (filter, l->data);
985 g_object_unref (l->data);
987 g_list_free (accounts);
991 empathy_filter_new (void)
993 static EmpathyFilter *filter = NULL;
996 filter = g_object_new (EMPATHY_TYPE_FILTER, NULL);
997 g_object_add_weak_pointer (G_OBJECT (filter), (gpointer) &filter);
999 g_object_ref (filter);