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

« back to all changes in this revision

Viewing changes to libedataserverui/e-source-combo-box.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
        (G_TYPE_INSTANCE_GET_PRIVATE \
30
30
        ((obj), E_TYPE_SOURCE_COMBO_BOX, ESourceComboBoxPrivate))
31
31
 
 
32
G_DEFINE_TYPE (ESourceComboBox, e_source_combo_box, GTK_TYPE_COMBO_BOX)
 
33
 
32
34
struct _ESourceComboBoxPrivate {
33
35
        ESourceList *source_list;
34
36
        GHashTable *uid_index;
51
53
 
52
54
static gpointer parent_class = NULL;
53
55
 
54
 
/**
55
 
 * compare_source_names
56
 
 * Compares sources by name.
57
 
 **/
58
56
static gint
59
 
compare_source_names (gconstpointer a, gconstpointer b)
60
 
{
61
 
        g_return_val_if_fail (E_IS_SOURCE (a), -1);
62
 
        g_return_val_if_fail (E_IS_SOURCE (b),  1);
63
 
 
64
 
        return g_utf8_collate (e_source_peek_name (E_SOURCE (a)), e_source_peek_name (E_SOURCE (b)));
65
 
}
66
 
 
67
 
/**
68
 
 * get_sorted_sources
69
 
 * Creates copy of GSList of sources (do not increase reference count for data members),
70
 
 * and sorts this list alphabetically by source names.
71
 
 *
72
 
 * @param sources List of sources.
73
 
 * @return New GSList of sorted sources, should be freed by g_slist_free,
74
 
 *         but do not unref data members.
75
 
 **/
76
 
static GSList *
77
 
get_sorted_sources (GSList *sources)
78
 
{
79
 
        GSList *res = NULL, *p;
80
 
 
81
 
        if (!sources)
82
 
                return NULL;
83
 
 
84
 
        for (p = sources; p != NULL; p = p->next)
85
 
                res = g_slist_prepend (res, p->data);
86
 
 
87
 
        res = g_slist_sort (res, compare_source_names);
88
 
 
89
 
        return res;
 
57
compare_source_names (ESource *source_a,
 
58
                      ESource *source_b)
 
59
{
 
60
        const gchar *name_a;
 
61
        const gchar *name_b;
 
62
 
 
63
        g_return_val_if_fail (E_IS_SOURCE (source_a), -1);
 
64
        g_return_val_if_fail (E_IS_SOURCE (source_b),  1);
 
65
 
 
66
        name_a = e_source_peek_name (source_a);
 
67
        name_b = e_source_peek_name (source_b);
 
68
 
 
69
        return g_utf8_collate (name_a, name_b);
90
70
}
91
71
 
92
72
static void
114
94
        model = gtk_combo_box_get_model (combo_box);
115
95
        store = GTK_LIST_STORE (model);
116
96
 
 
97
        if (source_list == NULL) {
 
98
                gtk_list_store_clear (store);
 
99
                return;
 
100
        }
 
101
 
 
102
        /* XXX The algorithm below is needlessly complex.  Would be
 
103
         *     easier just to clear and rebuild the store.  There's
 
104
         *     hardly a performance issue here since source lists
 
105
         *     are short. */
 
106
 
117
107
        gtk_tree_model_get_iter_first (model, &iter);
118
108
 
119
109
        for (groups = e_source_list_peek_groups (source_list);
135
125
                        -1);
136
126
                gtk_tree_model_iter_next (model, &iter);
137
127
 
138
 
                sources = get_sorted_sources (e_source_group_peek_sources (groups->data));
 
128
                sources = e_source_group_peek_sources (groups->data);
 
129
 
 
130
                /* Create a shallow copy and sort by name. */
 
131
                sources = g_slist_sort (
 
132
                        g_slist_copy (sources),
 
133
                        (GCompareFunc) compare_source_names);
 
134
 
139
135
                for (s = sources; s != NULL; s = s->next) {
140
136
                        const gchar *color_spec;
141
137
                        GdkColor color;
241
237
 
242
238
        switch (property_id) {
243
239
                case PROP_SOURCE_LIST:
244
 
 
245
 
                        if (priv->source_list != NULL) {
246
 
                                g_signal_handler_disconnect (
247
 
                                        priv->source_list, priv->handler_id);
248
 
                                g_object_unref (priv->source_list);
249
 
                        }
250
 
 
251
 
                        priv->source_list = g_value_dup_object (value);
252
 
 
253
 
                        /* Reset the tree store. */
254
 
                        source_list_changed_cb (
255
 
                                priv->source_list,
256
 
                                E_SOURCE_COMBO_BOX (object));
257
 
 
258
 
                        /* Watch for source list changes. */
259
 
                        priv->handler_id = g_signal_connect_object (
260
 
                                priv->source_list, "changed",
261
 
                                G_CALLBACK (source_list_changed_cb),
262
 
                                object, 0);
263
 
 
 
240
                        e_source_combo_box_set_source_list (
 
241
                                E_SOURCE_COMBO_BOX (object),
 
242
                                g_value_get_object (value));
264
243
                        return;
265
244
        }
266
245
 
279
258
 
280
259
        switch (property_id) {
281
260
                case PROP_SOURCE_LIST:
282
 
                        g_value_set_object (value, priv->source_list);
 
261
                        g_value_set_object (
 
262
                                value, e_source_combo_box_get_source_list (
 
263
                                E_SOURCE_COMBO_BOX (object)));
283
264
                        return;
284
265
        }
285
266
 
294
275
        priv = E_SOURCE_COMBO_BOX_GET_PRIVATE (object);
295
276
 
296
277
        if (priv->source_list != NULL) {
 
278
                g_signal_handler_disconnect (
 
279
                        priv->source_list, priv->handler_id);
297
280
                g_object_unref (priv->source_list);
298
281
                priv->source_list = NULL;
299
282
        }
356
339
                        (GDestroyNotify) gtk_tree_row_reference_free);
357
340
}
358
341
 
359
 
GType
360
 
e_source_combo_box_get_type (void)
361
 
{
362
 
        static GType type = 0;
363
 
 
364
 
        if (G_UNLIKELY (type == 0)) {
365
 
                static const GTypeInfo type_info = {
366
 
                        sizeof (ESourceComboBoxClass),
367
 
                        (GBaseInitFunc) NULL,
368
 
                        (GBaseFinalizeFunc) NULL,
369
 
                        (GClassInitFunc) e_source_combo_box_class_init,
370
 
                        (GClassFinalizeFunc) NULL,
371
 
                        NULL,  /* class_data */
372
 
                        sizeof (ESourceComboBox),
373
 
                        0,     /* n_preallocs */
374
 
                        (GInstanceInitFunc) e_source_combo_box_init,
375
 
                        NULL   /* value_table */
376
 
                };
377
 
 
378
 
                type = g_type_register_static (
379
 
                        GTK_TYPE_COMBO_BOX, "ESourceComboBox", &type_info, 0);
380
 
        }
381
 
 
382
 
        return type;
383
 
}
384
 
 
385
342
/**
386
343
 * e_source_combo_box_new:
387
344
 * @source_list: an #ESourceList
390
347
 * from the provided #ESourceList.
391
348
 *
392
349
 * Returns: a new #ESourceComboBox
 
350
 *
 
351
 * Since: 2.22
393
352
 **/
394
353
GtkWidget *
395
354
e_source_combo_box_new (ESourceList *source_list)
409
368
 * @source_combo_box.
410
369
 *
411
370
 * Returns: an #ESourceList
 
371
 *
 
372
 * Since: 2.22
412
373
 **/
413
374
ESourceList *
414
375
e_source_combo_box_get_source_list (ESourceComboBox *source_combo_box)
415
376
{
416
 
        ESourceList *source_list;
417
 
 
418
377
        g_return_val_if_fail (E_IS_SOURCE_COMBO_BOX (source_combo_box), NULL);
419
378
 
420
 
        g_object_get (source_combo_box, "source-list", &source_list, NULL);
421
 
 
422
 
        return source_list;
 
379
        return source_combo_box->priv->source_list;
423
380
}
424
381
 
425
382
/**
429
386
 *
430
387
 * Sets the source list used by @source_combo_box to be @source_list.  This
431
388
 * causes the contents of @source_combo_box to be regenerated.
 
389
 *
 
390
 * Since: 2.22
432
391
 **/
433
392
void
434
393
e_source_combo_box_set_source_list (ESourceComboBox *source_combo_box,
435
394
                                    ESourceList *source_list)
436
395
{
437
396
        g_return_if_fail (E_IS_SOURCE_COMBO_BOX (source_combo_box));
438
 
        g_return_if_fail (E_IS_SOURCE_LIST (source_list));
439
 
 
440
 
        g_object_set (source_combo_box, "source-list", source_list, NULL);
 
397
 
 
398
        if (source_list != NULL) {
 
399
                g_return_if_fail (E_IS_SOURCE_LIST (source_list));
 
400
                g_object_ref (source_list);
 
401
        }
 
402
 
 
403
        if (source_combo_box->priv->source_list != NULL) {
 
404
                g_signal_handler_disconnect (
 
405
                        source_combo_box->priv->source_list,
 
406
                        source_combo_box->priv->handler_id);
 
407
                g_object_unref (source_combo_box->priv->source_list);
 
408
                source_combo_box->priv->handler_id = 0;
 
409
        }
 
410
 
 
411
        source_combo_box->priv->source_list = source_list;
 
412
 
 
413
        /* Reset the tree store. */
 
414
        source_list_changed_cb (source_list, source_combo_box);
 
415
 
 
416
        /* Watch for source list changes. */
 
417
        if (source_list != NULL) {
 
418
                source_combo_box->priv->handler_id =
 
419
                        g_signal_connect_object (
 
420
                                source_list, "changed",
 
421
                                G_CALLBACK (source_list_changed_cb),
 
422
                                source_combo_box, 0);
 
423
        }
 
424
 
 
425
        g_object_notify (G_OBJECT (source_combo_box), "source-list");
441
426
}
442
427
 
443
428
/**
448
433
 * if there is no active item.
449
434
 *
450
435
 * Returns: an #ESource or %NULL
 
436
 *
 
437
 * Since: 2.22
451
438
 **/
452
439
ESource *
453
440
e_source_combo_box_get_active (ESourceComboBox *source_combo_box)
476
463
 * @source: an #ESource
477
464
 *
478
465
 * Sets the active item to the one corresponding to @source.
 
466
 *
 
467
 * Since: 2.22
479
468
 **/
480
469
void
481
470
e_source_combo_box_set_active (ESourceComboBox *source_combo_box,
496
485
 * active item, or %NULL if there is no active item.
497
486
 *
498
487
 * Returns: a unique ID string or %NULL
 
488
 *
 
489
 * Since: 2.22
499
490
 **/
500
491
const gchar *
501
492
e_source_combo_box_get_active_uid (ESourceComboBox *source_combo_box)
517
508
 * @uid: a unique ID of an #ESource
518
509
 *
519
510
 * Sets the active item to the one corresponding to @uid.
 
511
 *
 
512
 * Since: 2.22
520
513
 **/
521
514
void
522
515
e_source_combo_box_set_active_uid (ESourceComboBox *source_combo_box,