~ubuntu-branches/ubuntu/precise/evolution-data-server/precise

« back to all changes in this revision

Viewing changes to camel/providers/imapx/camel-imapx-conn-manager.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2011-07-27 11:45:30 UTC
  • mfrom: (1.1.90 upstream)
  • Revision ID: james.westby@ubuntu.com-20110727114530-v4ntbu728os68b0b
Tags: 3.1.4-0ubuntu1
* New upstream version.
* debian/patches/999git_EDS_3_1_3_1_to_f94a069.patch: drop, included in
  the upstream 3.1.4 tarball.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#define CON_LOCK(x) (g_static_rec_mutex_lock(&(x)->priv->con_man_lock))
28
28
#define CON_UNLOCK(x) (g_static_rec_mutex_unlock(&(x)->priv->con_man_lock))
29
29
 
30
 
G_DEFINE_TYPE (CamelIMAPXConnManager, camel_imapx_conn_manager, CAMEL_TYPE_OBJECT)
 
30
#define CAMEL_IMAPX_CONN_MANAGER_GET_PRIVATE(obj) \
 
31
        (G_TYPE_INSTANCE_GET_PRIVATE \
 
32
        ((obj), CAMEL_TYPE_IMAPX_CONN_MANAGER, CamelIMAPXConnManagerPrivate))
 
33
 
 
34
G_DEFINE_TYPE (
 
35
        CamelIMAPXConnManager,
 
36
        camel_imapx_conn_manager,
 
37
        CAMEL_TYPE_OBJECT)
31
38
 
32
39
struct _CamelIMAPXConnManagerPrivate {
33
40
        GSList *connections;
34
41
        guint n_connections;
35
 
        CamelStore *store;
 
42
        gpointer store;  /* weak pointer */
36
43
        GStaticRecMutex con_man_lock;
37
44
        gboolean clearing_connections;
38
45
};
43
50
        gchar *selected_folder;
44
51
} ConnectionInfo;
45
52
 
 
53
enum {
 
54
        PROP_0,
 
55
        PROP_STORE
 
56
};
 
57
 
46
58
static void
47
59
free_connection (gpointer data, gpointer user_data)
48
60
{
72
84
}
73
85
 
74
86
static void
 
87
imapx_conn_manager_set_store (CamelIMAPXConnManager *con_man,
 
88
                              CamelStore *store)
 
89
{
 
90
        g_return_if_fail (CAMEL_IS_STORE (store));
 
91
        g_return_if_fail (con_man->priv->store == NULL);
 
92
 
 
93
        con_man->priv->store = store;
 
94
 
 
95
        g_object_add_weak_pointer (
 
96
                G_OBJECT (store), &con_man->priv->store);
 
97
}
 
98
 
 
99
static void
 
100
imapx_conn_manager_set_property (GObject *object,
 
101
                                 guint property_id,
 
102
                                 const GValue *value,
 
103
                                 GParamSpec *pspec)
 
104
{
 
105
        switch (property_id) {
 
106
                case PROP_STORE:
 
107
                        imapx_conn_manager_set_store (
 
108
                                CAMEL_IMAPX_CONN_MANAGER (object),
 
109
                                g_value_get_object (value));
 
110
                        return;
 
111
        }
 
112
 
 
113
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
114
}
 
115
 
 
116
static void
 
117
imapx_conn_manager_get_property (GObject *object,
 
118
                                 guint property_id,
 
119
                                 GValue *value,
 
120
                                 GParamSpec *pspec)
 
121
{
 
122
        switch (property_id) {
 
123
                case PROP_STORE:
 
124
                        g_value_set_object (
 
125
                                value,
 
126
                                camel_imapx_conn_manager_get_store (
 
127
                                CAMEL_IMAPX_CONN_MANAGER (object)));
 
128
                        return;
 
129
        }
 
130
 
 
131
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
132
}
 
133
 
 
134
static void
 
135
imapx_conn_manager_dispose (GObject *object)
 
136
{
 
137
        CamelIMAPXConnManagerPrivate *priv;
 
138
 
 
139
        priv = CAMEL_IMAPX_CONN_MANAGER_GET_PRIVATE (object);
 
140
 
 
141
        imapx_prune_connections (CAMEL_IMAPX_CONN_MANAGER (object));
 
142
 
 
143
        if (priv->store != NULL) {
 
144
                g_object_remove_weak_pointer (
 
145
                        G_OBJECT (priv->store), &priv->store);
 
146
                priv->store = NULL;
 
147
        }
 
148
 
 
149
        /* Chain up to parent's dispose() method. */
 
150
        G_OBJECT_CLASS (camel_imapx_conn_manager_parent_class)->dispose (object);
 
151
}
 
152
 
 
153
static void
75
154
imapx_conn_manager_finalize (GObject *object)
76
155
{
77
 
        CamelIMAPXConnManager *con_man = CAMEL_IMAPX_CONN_MANAGER (object);
78
 
 
79
 
        imapx_prune_connections (con_man);
80
 
        g_static_rec_mutex_free (&con_man->priv->con_man_lock);
81
 
        g_object_unref (con_man->priv->store);
 
156
        CamelIMAPXConnManagerPrivate *priv;
 
157
 
 
158
        priv = CAMEL_IMAPX_CONN_MANAGER_GET_PRIVATE (object);
 
159
 
 
160
        g_static_rec_mutex_free (&priv->con_man_lock);
 
161
 
 
162
        /* Chain up to parent's finalize() method. */
 
163
        G_OBJECT_CLASS (camel_imapx_conn_manager_parent_class)->finalize (object);
82
164
}
83
165
 
84
166
static void
89
171
        g_type_class_add_private (class, sizeof (CamelIMAPXConnManagerPrivate));
90
172
 
91
173
        object_class = G_OBJECT_CLASS (class);
 
174
        object_class->set_property = imapx_conn_manager_set_property;
 
175
        object_class->get_property = imapx_conn_manager_get_property;
 
176
        object_class->dispose = imapx_conn_manager_dispose;
92
177
        object_class->finalize = imapx_conn_manager_finalize;
 
178
 
 
179
        g_object_class_install_property (
 
180
                object_class,
 
181
                PROP_STORE,
 
182
                g_param_spec_object (
 
183
                        "store",
 
184
                        "Store",
 
185
                        "The CamelStore to which we belong",
 
186
                        CAMEL_TYPE_STORE,
 
187
                        G_PARAM_READWRITE |
 
188
                        G_PARAM_CONSTRUCT_ONLY |
 
189
                        G_PARAM_STATIC_STRINGS));
93
190
}
94
191
 
95
192
static void
96
193
camel_imapx_conn_manager_init (CamelIMAPXConnManager *con_man)
97
194
{
98
 
        con_man->priv = G_TYPE_INSTANCE_GET_PRIVATE (
99
 
                con_man, CAMEL_TYPE_OBJECT, CamelIMAPXConnManagerPrivate);
 
195
        con_man->priv = CAMEL_IMAPX_CONN_MANAGER_GET_PRIVATE (con_man);
100
196
 
101
197
        /* default is 1 connection */
102
198
        con_man->priv->n_connections = 1;
291
387
CamelIMAPXConnManager *
292
388
camel_imapx_conn_manager_new (CamelStore *store)
293
389
{
294
 
        CamelIMAPXConnManager *con_man;
295
 
 
296
 
        con_man = g_object_new (CAMEL_TYPE_IMAPX_CONN_MANAGER, NULL);
297
 
        con_man->priv->store = g_object_ref (store);
298
 
 
299
 
        return con_man;
 
390
        g_return_val_if_fail (CAMEL_IS_STORE (store), NULL);
 
391
 
 
392
        return g_object_new (
 
393
                CAMEL_TYPE_IMAPX_CONN_MANAGER, "store", store, NULL);
 
394
}
 
395
 
 
396
CamelStore *
 
397
camel_imapx_conn_manager_get_store (CamelIMAPXConnManager *con_man)
 
398
{
 
399
        g_return_val_if_fail (CAMEL_IS_IMAPX_CONN_MANAGER (con_man), NULL);
 
400
 
 
401
        return CAMEL_STORE (con_man->priv->store);
300
402
}
301
403
 
302
404
void