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 <libmissioncontrol/mission-control.h>
27 #include "empathy-tp-chatroom.h"
28 #include "empathy-tp-contact-list.h"
29 #include "empathy-contact-list.h"
30 #include "empathy-contact-manager.h"
31 #include "gossip-telepathy-group.h"
32 #include "gossip-utils.h"
34 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
35 EMPATHY_TYPE_TP_CHATROOM, EmpathyTpChatroomPriv))
37 #define DEBUG_DOMAIN "TpChatroom"
39 struct _EmpathyTpChatroomPriv {
40 EmpathyContactManager *manager;
41 EmpathyTpContactList *list;
42 GossipTelepathyGroup *group;
45 static void empathy_tp_chatroom_class_init (EmpathyTpChatroomClass *klass);
46 static void tp_chatroom_iface_init (EmpathyContactListIface *iface);
47 static void empathy_tp_chatroom_init (EmpathyTpChatroom *chatroom);
48 static void tp_chatroom_finalize (GObject *object);
49 static void tp_chatroom_setup (EmpathyContactList *list);
50 static GossipContact * tp_chatroom_find (EmpathyContactList *list,
52 static void tp_chatroom_add (EmpathyContactList *list,
53 GossipContact *contact,
54 const gchar *message);
55 static void tp_chatroom_remove (EmpathyContactList *list,
56 GossipContact *contact,
57 const gchar *message);
58 static GList * tp_chatroom_get_contacts (EmpathyContactList *list);
60 G_DEFINE_TYPE_WITH_CODE (EmpathyTpChatroom, empathy_tp_chatroom, EMPATHY_TYPE_TP_CHAT,
61 G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_CONTACT_LIST,
62 tp_chatroom_iface_init));
65 empathy_tp_chatroom_class_init (EmpathyTpChatroomClass *klass)
67 GObjectClass *object_class = G_OBJECT_CLASS (klass);
69 object_class->finalize = tp_chatroom_finalize;
71 g_type_class_add_private (object_class, sizeof (EmpathyTpChatroomPriv));
75 tp_chatroom_iface_init (EmpathyContactListIface *iface)
77 iface->setup = tp_chatroom_setup;
78 iface->find = tp_chatroom_find;
79 iface->add = tp_chatroom_add;
80 iface->remove = tp_chatroom_remove;
81 iface->get_contacts = tp_chatroom_get_contacts;
85 empathy_tp_chatroom_init (EmpathyTpChatroom *chatroom)
90 tp_chatroom_finalize (GObject *object)
92 EmpathyTpChatroomPriv *priv;
93 EmpathyTpChatroom *chatroom;
95 chatroom = EMPATHY_TP_CHATROOM (object);
96 priv = GET_PRIV (chatroom);
98 g_object_unref (priv->group);
99 g_object_unref (priv->manager);
100 g_object_unref (priv->list);
102 G_OBJECT_CLASS (empathy_tp_chatroom_parent_class)->finalize (object);
106 empathy_tp_chatroom_new (McAccount *account,
109 EmpathyTpChatroomPriv *priv;
110 EmpathyTpChatroom *chatroom;
114 g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
115 g_return_val_if_fail (TELEPATHY_IS_CHAN (tp_chan), NULL);
117 chatroom = g_object_new (EMPATHY_TYPE_TP_CHATROOM,
122 priv = GET_PRIV (chatroom);
124 mc = gossip_mission_control_new ();
125 tp_conn = mission_control_get_connection (mc, account, NULL);
126 priv->manager = empathy_contact_manager_new ();
127 priv->group = gossip_telepathy_group_new (tp_chan, tp_conn);
128 priv->list = empathy_contact_manager_get_list (priv->manager, account);
131 g_object_unref (tp_conn);
137 tp_chatroom_setup (EmpathyContactList *list)
141 static GossipContact *
142 tp_chatroom_find (EmpathyContactList *list,
149 tp_chatroom_add (EmpathyContactList *list,
150 GossipContact *contact,
151 const gchar *message)
156 tp_chatroom_remove (EmpathyContactList *list,
157 GossipContact *contact,
158 const gchar *message)
163 tp_chatroom_get_contacts (EmpathyContactList *list)