~carifio/seahorse/seahorse-remove-broken-help-buttons

« back to all changes in this revision

Viewing changes to libseahorse/seahorse-servers.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-07-22 09:20:59 UTC
  • mto: (3.2.1 sid) (1.4.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 59.
  • Revision ID: james.westby@ubuntu.com-20080722092059-q336t49r9uaveij3
Tags: upstream-2.23.5
ImportĀ upstreamĀ versionĀ 2.23.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include <seahorse-servers.h>
 
3
#include <seahorse-gconf.h>
 
4
 
 
5
 
 
6
#define SEAHORSE_SERVERS_TYPE_SERVER_INFO (seahorse_servers_server_info_get_type ())
 
7
#define SEAHORSE_SERVERS_SERVER_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SEAHORSE_SERVERS_TYPE_SERVER_INFO, SeahorseServersServerInfo))
 
8
#define SEAHORSE_SERVERS_SERVER_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SEAHORSE_SERVERS_TYPE_SERVER_INFO, SeahorseServersServerInfoClass))
 
9
#define SEAHORSE_SERVERS_IS_SERVER_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SEAHORSE_SERVERS_TYPE_SERVER_INFO))
 
10
#define SEAHORSE_SERVERS_IS_SERVER_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SEAHORSE_SERVERS_TYPE_SERVER_INFO))
 
11
#define SEAHORSE_SERVERS_SERVER_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SEAHORSE_SERVERS_TYPE_SERVER_INFO, SeahorseServersServerInfoClass))
 
12
 
 
13
typedef struct _SeahorseServersServerInfo SeahorseServersServerInfo;
 
14
typedef struct _SeahorseServersServerInfoClass SeahorseServersServerInfoClass;
 
15
typedef struct _SeahorseServersServerInfoPrivate SeahorseServersServerInfoPrivate;
 
16
 
 
17
struct _SeahorseServersServerInfo {
 
18
        GTypeInstance parent_instance;
 
19
        volatile int ref_count;
 
20
        SeahorseServersServerInfoPrivate * priv;
 
21
        char* type;
 
22
        char* description;
 
23
        SeahorseValidUriFunc validator;
 
24
};
 
25
 
 
26
struct _SeahorseServersServerInfoClass {
 
27
        GTypeClass parent_class;
 
28
        void (*finalize) (SeahorseServersServerInfo *self);
 
29
};
 
30
 
 
31
 
 
32
 
 
33
enum  {
 
34
        SEAHORSE_SERVERS_DUMMY_PROPERTY
 
35
};
 
36
static GHashTable* seahorse_servers_types;
 
37
static void _g_slist_free_g_free (GSList* self);
 
38
enum  {
 
39
        SEAHORSE_SERVERS_SERVER_INFO_DUMMY_PROPERTY
 
40
};
 
41
static SeahorseServersServerInfo* seahorse_servers_server_info_new (void);
 
42
static gpointer seahorse_servers_server_info_parent_class = NULL;
 
43
static GType seahorse_servers_server_info_get_type (void);
 
44
static gpointer seahorse_servers_server_info_ref (gpointer instance);
 
45
static void seahorse_servers_server_info_unref (gpointer instance);
 
46
static gpointer seahorse_servers_parent_class = NULL;
 
47
static void seahorse_servers_dispose (GObject * obj);
 
48
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);
 
49
 
 
50
 
 
51
 
 
52
static void _g_slist_free_g_free (GSList* self) {
 
53
        g_slist_foreach (self, ((GFunc) (g_free)), NULL);
 
54
        g_slist_free (self);
 
55
}
 
56
 
 
57
 
 
58
GSList* seahorse_servers_get_types (void) {
 
59
        GSList* results;
 
60
        results = NULL;
 
61
        {
 
62
                GList* type_collection;
 
63
                GList* type_it;
 
64
                type_collection = g_hash_table_get_keys (seahorse_servers_types);
 
65
                for (type_it = type_collection; type_it != NULL; type_it = type_it->next) {
 
66
                        const char* type;
 
67
                        type = ((const char*) (type_it->data));
 
68
                        {
 
69
                                const char* _tmp0;
 
70
                                _tmp0 = NULL;
 
71
                                results = g_slist_append (results, (_tmp0 = type, (_tmp0 == NULL ? NULL : g_strdup (_tmp0))));
 
72
                        }
 
73
                }
 
74
                (type_collection == NULL ? NULL : (type_collection = (g_list_free (type_collection), NULL)));
 
75
        }
 
76
        return results;
 
77
}
 
78
 
 
79
 
 
80
char* seahorse_servers_get_description (const char* type) {
 
81
        SeahorseServersServerInfo* _tmp0;
 
82
        SeahorseServersServerInfo* server;
 
83
        const char* _tmp2;
 
84
        char* _tmp3;
 
85
        g_return_val_if_fail (type != NULL, NULL);
 
86
        _tmp0 = NULL;
 
87
        server = (_tmp0 = ((SeahorseServersServerInfo*) (g_hash_table_lookup (seahorse_servers_types, type))), (_tmp0 == NULL ? NULL : seahorse_servers_server_info_ref (_tmp0)));
 
88
        if (server == NULL) {
 
89
                char* _tmp1;
 
90
                _tmp1 = NULL;
 
91
                return (_tmp1 = NULL, (server == NULL ? NULL : (server = (seahorse_servers_server_info_unref (server), NULL))), _tmp1);
 
92
        }
 
93
        _tmp2 = NULL;
 
94
        _tmp3 = NULL;
 
95
        return (_tmp3 = (_tmp2 = server->description, (_tmp2 == NULL ? NULL : g_strdup (_tmp2))), (server == NULL ? NULL : (server = (seahorse_servers_server_info_unref (server), NULL))), _tmp3);
 
96
}
 
97
 
 
98
 
 
99
void seahorse_servers_register_type (const char* type, const char* description, SeahorseValidUriFunc validate) {
 
100
        SeahorseServers* dummy;
 
101
        SeahorseServersServerInfo* info;
 
102
        char* _tmp1;
 
103
        const char* _tmp0;
 
104
        char* _tmp3;
 
105
        const char* _tmp2;
 
106
        SeahorseServersServerInfo* _tmp5;
 
107
        const char* _tmp4;
 
108
        g_return_if_fail (type != NULL);
 
109
        g_return_if_fail (description != NULL);
 
110
        /* Work around for: http://bugzilla.gnome.org/show_bug.cgi?id=543190 */
 
111
        dummy = seahorse_servers_new ();
 
112
        info = seahorse_servers_server_info_new ();
 
113
        _tmp1 = NULL;
 
114
        _tmp0 = NULL;
 
115
        info->type = (_tmp1 = (_tmp0 = type, (_tmp0 == NULL ? NULL : g_strdup (_tmp0))), (info->type = (g_free (info->type), NULL)), _tmp1);
 
116
        _tmp3 = NULL;
 
117
        _tmp2 = NULL;
 
118
        info->description = (_tmp3 = (_tmp2 = description, (_tmp2 == NULL ? NULL : g_strdup (_tmp2))), (info->description = (g_free (info->description), NULL)), _tmp3);
 
119
        info->validator = validate;
 
120
        _tmp5 = NULL;
 
121
        _tmp4 = NULL;
 
122
        g_hash_table_replace (seahorse_servers_types, (_tmp4 = type, (_tmp4 == NULL ? NULL : g_strdup (_tmp4))), (_tmp5 = info, (_tmp5 == NULL ? NULL : seahorse_servers_server_info_ref (_tmp5))));
 
123
        (dummy == NULL ? NULL : (dummy = (g_object_unref (dummy), NULL)));
 
124
        (info == NULL ? NULL : (info = (seahorse_servers_server_info_unref (info), NULL)));
 
125
}
 
126
 
 
127
 
 
128
GSList* seahorse_servers_get_uris (void) {
 
129
        GSList* servers;
 
130
        GSList* results;
 
131
        GSList* _tmp3;
 
132
        servers = seahorse_gconf_get_string_list (KEYSERVER_KEY);
 
133
        results = NULL;
 
134
        /* The values are 'uri name', remove the name part */
 
135
        {
 
136
                GSList* value_collection;
 
137
                GSList* value_it;
 
138
                value_collection = servers;
 
139
                for (value_it = value_collection; value_it != NULL; value_it = value_it->next) {
 
140
                        const char* _tmp2;
 
141
                        char* value;
 
142
                        _tmp2 = NULL;
 
143
                        value = (_tmp2 = ((char*) (value_it->data)), (_tmp2 == NULL ? NULL : g_strdup (_tmp2)));
 
144
                        {
 
145
                                char** _tmp0;
 
146
                                gint parts_length1;
 
147
                                char** parts;
 
148
                                const char* _tmp1;
 
149
                                _tmp0 = NULL;
 
150
                                parts = (_tmp0 = g_strsplit (value, " ", 2), parts_length1 = -1, _tmp0);
 
151
                                _tmp1 = NULL;
 
152
                                results = g_slist_append (results, (_tmp1 = parts[0], (_tmp1 == NULL ? NULL : g_strdup (_tmp1))));
 
153
                                value = (g_free (value), NULL);
 
154
                                parts = (_vala_array_free (parts, parts_length1, ((GDestroyNotify) (g_free))), NULL);
 
155
                        }
 
156
                }
 
157
        }
 
158
        _tmp3 = NULL;
 
159
        return (_tmp3 = results, (servers == NULL ? NULL : (servers = (_g_slist_free_g_free (servers), NULL))), _tmp3);
 
160
}
 
161
 
 
162
 
 
163
GSList* seahorse_servers_get_names (void) {
 
164
        GSList* servers;
 
165
        GSList* results;
 
166
        GSList* _tmp4;
 
167
        servers = seahorse_gconf_get_string_list (KEYSERVER_KEY);
 
168
        results = NULL;
 
169
        /* The values are 'uri name', remove the uri part */
 
170
        {
 
171
                GSList* value_collection;
 
172
                GSList* value_it;
 
173
                value_collection = servers;
 
174
                for (value_it = value_collection; value_it != NULL; value_it = value_it->next) {
 
175
                        const char* _tmp3;
 
176
                        char* value;
 
177
                        _tmp3 = NULL;
 
178
                        value = (_tmp3 = ((char*) (value_it->data)), (_tmp3 == NULL ? NULL : g_strdup (_tmp3)));
 
179
                        {
 
180
                                char** _tmp0;
 
181
                                gint parts_length1;
 
182
                                char** parts;
 
183
                                _tmp0 = NULL;
 
184
                                parts = (_tmp0 = g_strsplit (value, " ", 2), parts_length1 = -1, _tmp0);
 
185
                                if (parts_length1 == 2 && g_utf8_strlen (parts[1], -1) > 0) {
 
186
                                        const char* _tmp1;
 
187
                                        _tmp1 = NULL;
 
188
                                        results = g_slist_append (results, (_tmp1 = parts[1], (_tmp1 == NULL ? NULL : g_strdup (_tmp1))));
 
189
                                } else {
 
190
                                        const char* _tmp2;
 
191
                                        _tmp2 = NULL;
 
192
                                        results = g_slist_append (results, (_tmp2 = parts[0], (_tmp2 == NULL ? NULL : g_strdup (_tmp2))));
 
193
                                }
 
194
                                value = (g_free (value), NULL);
 
195
                                parts = (_vala_array_free (parts, parts_length1, ((GDestroyNotify) (g_free))), NULL);
 
196
                        }
 
197
                }
 
198
        }
 
199
        _tmp4 = NULL;
 
200
        return (_tmp4 = results, (servers == NULL ? NULL : (servers = (_g_slist_free_g_free (servers), NULL))), _tmp4);
 
201
}
 
202
 
 
203
 
 
204
/* Check to see if the passed uri is valid against registered validators */
 
205
gboolean seahorse_servers_is_valid_uri (const char* uri) {
 
206
        char** _tmp0;
 
207
        gint parts_length1;
 
208
        char** parts;
 
209
        SeahorseServersServerInfo* _tmp2;
 
210
        SeahorseServersServerInfo* info;
 
211
        gboolean _tmp4;
 
212
        g_return_val_if_fail (uri != NULL, FALSE);
 
213
        _tmp0 = NULL;
 
214
        parts = (_tmp0 = g_strsplit (uri, ":", 2), parts_length1 = -1, _tmp0);
 
215
        if (parts_length1 == 0) {
 
216
                gboolean _tmp1;
 
217
                return (_tmp1 = FALSE, (parts = (_vala_array_free (parts, parts_length1, ((GDestroyNotify) (g_free))), NULL)), _tmp1);
 
218
        }
 
219
        _tmp2 = NULL;
 
220
        info = (_tmp2 = ((SeahorseServersServerInfo*) (g_hash_table_lookup (seahorse_servers_types, parts[0]))), (_tmp2 == NULL ? NULL : seahorse_servers_server_info_ref (_tmp2)));
 
221
        if (info == NULL) {
 
222
                gboolean _tmp3;
 
223
                return (_tmp3 = FALSE, (parts = (_vala_array_free (parts, parts_length1, ((GDestroyNotify) (g_free))), NULL)), (info == NULL ? NULL : (info = (seahorse_servers_server_info_unref (info), NULL))), _tmp3);
 
224
        }
 
225
        return (_tmp4 = info->validator (uri), (parts = (_vala_array_free (parts, parts_length1, ((GDestroyNotify) (g_free))), NULL)), (info == NULL ? NULL : (info = (seahorse_servers_server_info_unref (info), NULL))), _tmp4);
 
226
}
 
227
 
 
228
 
 
229
SeahorseServers* seahorse_servers_new (void) {
 
230
        SeahorseServers * self;
 
231
        self = g_object_newv (SEAHORSE_TYPE_SERVERS, 0, NULL);
 
232
        return self;
 
233
}
 
234
 
 
235
 
 
236
static SeahorseServersServerInfo* seahorse_servers_server_info_new (void) {
 
237
        SeahorseServersServerInfo* self;
 
238
        self = ((SeahorseServersServerInfo*) (g_type_create_instance (SEAHORSE_SERVERS_TYPE_SERVER_INFO)));
 
239
        return self;
 
240
}
 
241
 
 
242
 
 
243
static void seahorse_servers_server_info_class_init (SeahorseServersServerInfoClass * klass) {
 
244
        seahorse_servers_server_info_parent_class = g_type_class_peek_parent (klass);
 
245
}
 
246
 
 
247
 
 
248
static void seahorse_servers_server_info_instance_init (SeahorseServersServerInfo * self) {
 
249
        self->ref_count = 1;
 
250
}
 
251
 
 
252
 
 
253
static GType seahorse_servers_server_info_get_type (void) {
 
254
        static GType seahorse_servers_server_info_type_id = 0;
 
255
        if (G_UNLIKELY (seahorse_servers_server_info_type_id == 0)) {
 
256
                static const GTypeInfo g_define_type_info = { sizeof (SeahorseServersServerInfoClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) seahorse_servers_server_info_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SeahorseServersServerInfo), 0, (GInstanceInitFunc) seahorse_servers_server_info_instance_init };
 
257
                static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
 
258
                seahorse_servers_server_info_type_id = g_type_register_fundamental (g_type_fundamental_next (), "SeahorseServersServerInfo", &g_define_type_info, &g_define_type_fundamental_info, 0);
 
259
        }
 
260
        return seahorse_servers_server_info_type_id;
 
261
}
 
262
 
 
263
 
 
264
static gpointer seahorse_servers_server_info_ref (gpointer instance) {
 
265
        SeahorseServersServerInfo* self;
 
266
        self = instance;
 
267
        g_atomic_int_inc (&self->ref_count);
 
268
        return instance;
 
269
}
 
270
 
 
271
 
 
272
static void seahorse_servers_server_info_unref (gpointer instance) {
 
273
        SeahorseServersServerInfo* self;
 
274
        self = instance;
 
275
        if (g_atomic_int_dec_and_test (&self->ref_count)) {
 
276
                g_type_free_instance (((GTypeInstance *) (self)));
 
277
        }
 
278
}
 
279
 
 
280
 
 
281
static void seahorse_servers_class_init (SeahorseServersClass * klass) {
 
282
        seahorse_servers_parent_class = g_type_class_peek_parent (klass);
 
283
        G_OBJECT_CLASS (klass)->dispose = seahorse_servers_dispose;
 
284
        {
 
285
                GHashTable* _tmp0;
 
286
                /* TODO: What do we specify to free ServerInfo? */
 
287
                _tmp0 = NULL;
 
288
                seahorse_servers_types = (_tmp0 = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL), (seahorse_servers_types == NULL ? NULL : (seahorse_servers_types = (g_hash_table_unref (seahorse_servers_types), NULL))), _tmp0);
 
289
        }
 
290
}
 
291
 
 
292
 
 
293
static void seahorse_servers_instance_init (SeahorseServers * self) {
 
294
}
 
295
 
 
296
 
 
297
static void seahorse_servers_dispose (GObject * obj) {
 
298
        SeahorseServers * self;
 
299
        self = SEAHORSE_SERVERS (obj);
 
300
        G_OBJECT_CLASS (seahorse_servers_parent_class)->dispose (obj);
 
301
}
 
302
 
 
303
 
 
304
GType seahorse_servers_get_type (void) {
 
305
        static GType seahorse_servers_type_id = 0;
 
306
        if (G_UNLIKELY (seahorse_servers_type_id == 0)) {
 
307
                static const GTypeInfo g_define_type_info = { sizeof (SeahorseServersClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) seahorse_servers_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SeahorseServers), 0, (GInstanceInitFunc) seahorse_servers_instance_init };
 
308
                seahorse_servers_type_id = g_type_register_static (G_TYPE_OBJECT, "SeahorseServers", &g_define_type_info, 0);
 
309
        }
 
310
        return seahorse_servers_type_id;
 
311
}
 
312
 
 
313
 
 
314
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
 
315
        if (array != NULL && destroy_func != NULL) {
 
316
                int i;
 
317
                if (array_length >= 0)
 
318
                for (i = 0; i < array_length; i = i + 1) {
 
319
                        if (((gpointer*) (array))[i] != NULL)
 
320
                        destroy_func (((gpointer*) (array))[i]);
 
321
                }
 
322
                else
 
323
                for (i = 0; ((gpointer*) (array))[i] != NULL; i = i + 1) {
 
324
                        destroy_func (((gpointer*) (array))[i]);
 
325
                }
 
326
        }
 
327
        g_free (array);
 
328
}
 
329
 
 
330
 
 
331
 
 
332