]> git.0d.be Git - empathy.git/blob - libempathy/empathy-contact-factory.c
Updated de 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,
45                                      g_object_ref (account),
46                                      tp_factory);
47         }
48
49         return tp_factory;
50 }
51
52 EmpathyContact *
53 empathy_contact_factory_get_user (EmpathyContactFactory *factory,
54                                   McAccount             *account)
55 {
56         EmpathyTpContactFactory *tp_factory;
57
58         tp_factory = empathy_contact_factory_get_tp_factory (factory, account);
59
60         return empathy_tp_contact_factory_get_user (tp_factory);
61 }
62
63 EmpathyContact *
64 empathy_contact_factory_get_from_id (EmpathyContactFactory *factory,
65                                      McAccount             *account,
66                                      const gchar           *id)
67 {
68         EmpathyTpContactFactory *tp_factory;
69
70         tp_factory = empathy_contact_factory_get_tp_factory (factory, account);
71
72         return empathy_tp_contact_factory_get_from_id (tp_factory, id);
73 }
74
75 EmpathyContact *
76 empathy_contact_factory_get_from_handle (EmpathyContactFactory *factory,
77                                          McAccount             *account,
78                                          guint                  handle)
79 {
80         EmpathyTpContactFactory *tp_factory;
81
82         tp_factory = empathy_contact_factory_get_tp_factory (factory, account);
83
84         return empathy_tp_contact_factory_get_from_handle (tp_factory, handle);
85 }
86
87 GList *
88 empathy_contact_factory_get_from_handles (EmpathyContactFactory *factory,
89                                           McAccount             *account,
90                                           const GArray          *handles)
91 {
92         EmpathyTpContactFactory *tp_factory;
93
94         tp_factory = empathy_contact_factory_get_tp_factory (factory, account);
95
96         return empathy_tp_contact_factory_get_from_handles (tp_factory, handles);
97 }
98
99 void
100 empathy_contact_factory_set_alias (EmpathyContactFactory *factory,
101                                    EmpathyContact        *contact,
102                                    const gchar           *alias)
103 {
104         EmpathyTpContactFactory *tp_factory;
105         McAccount               *account;
106
107         account = empathy_contact_get_account (contact);
108         tp_factory = empathy_contact_factory_get_tp_factory (factory, account);
109
110         return empathy_tp_contact_factory_set_alias (tp_factory, contact, alias);
111 }
112
113 void
114 empathy_contact_factory_set_avatar (EmpathyContactFactory *factory,
115                                     McAccount             *account,
116                                     const gchar           *data,
117                                     gsize                  size,
118                                     const gchar           *mime_type)
119 {
120         EmpathyTpContactFactory *tp_factory;
121
122         tp_factory = empathy_contact_factory_get_tp_factory (factory, account);
123
124         return empathy_tp_contact_factory_set_avatar (tp_factory,
125                                                       data, size, mime_type);
126 }
127
128 static void
129 contact_factory_finalize (GObject *object)
130 {
131         EmpathyContactFactoryPriv *priv = GET_PRIV (object);
132
133         g_hash_table_destroy (priv->accounts);
134
135         G_OBJECT_CLASS (empathy_contact_factory_parent_class)->finalize (object);
136 }
137
138 static void
139 empathy_contact_factory_class_init (EmpathyContactFactoryClass *klass)
140 {
141         GObjectClass *object_class = G_OBJECT_CLASS (klass);
142
143         object_class->finalize = contact_factory_finalize;
144
145         g_type_class_add_private (object_class, sizeof (EmpathyContactFactoryPriv));
146 }
147
148 static void
149 empathy_contact_factory_init (EmpathyContactFactory *factory)
150 {
151         EmpathyContactFactoryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (factory,
152                 EMPATHY_TYPE_CONTACT_FACTORY, EmpathyContactFactoryPriv);
153
154         factory->priv = priv;
155         priv->accounts = g_hash_table_new_full (empathy_account_hash,
156                                                 empathy_account_equal,
157                                                 g_object_unref,
158                                                 g_object_unref);
159 }
160
161 EmpathyContactFactory *
162 empathy_contact_factory_new (void)
163 {
164         static EmpathyContactFactory *factory = NULL;
165
166         if (!factory) {
167                 factory = g_object_new (EMPATHY_TYPE_CONTACT_FACTORY, NULL);
168                 g_object_add_weak_pointer (G_OBJECT (factory), (gpointer) &factory);
169         } else {
170                 g_object_ref (factory);
171         }
172
173         return factory;
174 }
175