]> git.0d.be Git - empathy.git/blob - libempathy/empathy-contact-factory.c
Updated Basque translation.
[empathy.git] / libempathy / empathy-contact-factory.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007-2008 Collabora Ltd.
4  *
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.
9  *
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.
14  *
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
18  * 
19  * Authors: Xavier Claessens <xclaesse@gmail.com>
20  */
21
22 #include <config.h>
23
24 #include "empathy-contact-factory.h"
25 #include "empathy-utils.h"
26
27 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyContactFactory)
28 typedef struct {
29         GHashTable *accounts;
30 } EmpathyContactFactoryPriv;
31
32 G_DEFINE_TYPE (EmpathyContactFactory, empathy_contact_factory, G_TYPE_OBJECT);
33
34 EmpathyTpContactFactory *
35 empathy_contact_factory_get_tp_factory (EmpathyContactFactory *factory,
36                                         McAccount             *account)
37 {
38         EmpathyContactFactoryPriv *priv = GET_PRIV (factory);
39         EmpathyTpContactFactory   *tp_factory;
40
41         tp_factory = g_hash_table_lookup (priv->accounts, account);
42         if (!tp_factory) {
43                 tp_factory = empathy_tp_contact_factory_new (account);
44                 g_hash_table_insert (priv->accounts, account, tp_factory);
45         }
46
47         return g_object_ref (tp_factory);
48 }
49
50 EmpathyContact *
51 empathy_contact_factory_get_user (EmpathyContactFactory *factory,
52                                   McAccount             *account)
53 {
54         EmpathyTpContactFactory *tp_factory;
55
56         tp_factory = empathy_contact_factory_get_tp_factory (factory, account);
57
58         return empathy_tp_contact_factory_get_user (tp_factory);
59 }
60
61 EmpathyContact *
62 empathy_contact_factory_get_from_id (EmpathyContactFactory *factory,
63                                      McAccount             *account,
64                                      const gchar           *id)
65 {
66         EmpathyTpContactFactory *tp_factory;
67
68         tp_factory = empathy_contact_factory_get_tp_factory (factory, account);
69
70         return empathy_tp_contact_factory_get_from_id (tp_factory, id);
71 }
72
73 EmpathyContact *
74 empathy_contact_factory_get_from_handle (EmpathyContactFactory *factory,
75                                          McAccount             *account,
76                                          guint                  handle)
77 {
78         EmpathyTpContactFactory *tp_factory;
79
80         tp_factory = empathy_contact_factory_get_tp_factory (factory, account);
81
82         return empathy_tp_contact_factory_get_from_handle (tp_factory, handle);
83 }
84
85 GList *
86 empathy_contact_factory_get_from_handles (EmpathyContactFactory *factory,
87                                           McAccount             *account,
88                                           const GArray          *handles)
89 {
90         EmpathyTpContactFactory *tp_factory;
91
92         tp_factory = empathy_contact_factory_get_tp_factory (factory, account);
93
94         return empathy_tp_contact_factory_get_from_handles (tp_factory, handles);
95 }
96
97 void
98 empathy_contact_factory_set_alias (EmpathyContactFactory *factory,
99                                    EmpathyContact        *contact,
100                                    const gchar           *alias)
101 {
102         EmpathyTpContactFactory *tp_factory;
103         McAccount               *account;
104
105         account = empathy_contact_get_account (contact);
106         tp_factory = empathy_contact_factory_get_tp_factory (factory, account);
107
108         return empathy_tp_contact_factory_set_alias (tp_factory, contact, alias);
109 }
110
111 void
112 empathy_contact_factory_set_avatar (EmpathyContactFactory *factory,
113                                     McAccount             *account,
114                                     const gchar           *data,
115                                     gsize                  size,
116                                     const gchar           *mime_type)
117 {
118         EmpathyTpContactFactory *tp_factory;
119
120         tp_factory = empathy_contact_factory_get_tp_factory (factory, account);
121
122         return empathy_tp_contact_factory_set_avatar (tp_factory,
123                                                       data, size, mime_type);
124 }
125
126 static void
127 contact_factory_finalize (GObject *object)
128 {
129         EmpathyContactFactoryPriv *priv = GET_PRIV (object);
130
131         g_hash_table_destroy (priv->accounts);
132
133         G_OBJECT_CLASS (empathy_contact_factory_parent_class)->finalize (object);
134 }
135
136 static void
137 empathy_contact_factory_class_init (EmpathyContactFactoryClass *klass)
138 {
139         GObjectClass *object_class = G_OBJECT_CLASS (klass);
140
141         object_class->finalize = contact_factory_finalize;
142
143         g_type_class_add_private (object_class, sizeof (EmpathyContactFactoryPriv));
144 }
145
146 static void
147 empathy_contact_factory_init (EmpathyContactFactory *factory)
148 {
149         EmpathyContactFactoryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (factory,
150                 EMPATHY_TYPE_CONTACT_FACTORY, EmpathyContactFactoryPriv);
151
152         factory->priv = priv;
153         priv->accounts = g_hash_table_new_full (empathy_account_hash,
154                                                 empathy_account_equal,
155                                                 g_object_unref,
156                                                 g_object_unref);
157 }
158
159 EmpathyContactFactory *
160 empathy_contact_factory_new (void)
161 {
162         static EmpathyContactFactory *factory = NULL;
163
164         if (!factory) {
165                 factory = g_object_new (EMPATHY_TYPE_CONTACT_FACTORY, NULL);
166                 g_object_add_weak_pointer (G_OBJECT (factory), (gpointer) &factory);
167         } else {
168                 g_object_ref (factory);
169         }
170
171         return factory;
172 }
173