29
29
(G_TYPE_INSTANCE_GET_PRIVATE \
30
30
((obj), E_TYPE_SOURCE_COMBO_BOX, ESourceComboBoxPrivate))
32
G_DEFINE_TYPE (ESourceComboBox, e_source_combo_box, GTK_TYPE_COMBO_BOX)
32
34
struct _ESourceComboBoxPrivate {
33
35
ESourceList *source_list;
34
36
GHashTable *uid_index;
52
54
static gpointer parent_class = NULL;
55
* compare_source_names
56
* Compares sources by name.
59
compare_source_names (gconstpointer a, gconstpointer b)
61
g_return_val_if_fail (E_IS_SOURCE (a), -1);
62
g_return_val_if_fail (E_IS_SOURCE (b), 1);
64
return g_utf8_collate (e_source_peek_name (E_SOURCE (a)), e_source_peek_name (E_SOURCE (b)));
69
* Creates copy of GSList of sources (do not increase reference count for data members),
70
* and sorts this list alphabetically by source names.
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.
77
get_sorted_sources (GSList *sources)
79
GSList *res = NULL, *p;
84
for (p = sources; p != NULL; p = p->next)
85
res = g_slist_prepend (res, p->data);
87
res = g_slist_sort (res, compare_source_names);
57
compare_source_names (ESource *source_a,
63
g_return_val_if_fail (E_IS_SOURCE (source_a), -1);
64
g_return_val_if_fail (E_IS_SOURCE (source_b), 1);
66
name_a = e_source_peek_name (source_a);
67
name_b = e_source_peek_name (source_b);
69
return g_utf8_collate (name_a, name_b);
114
94
model = gtk_combo_box_get_model (combo_box);
115
95
store = GTK_LIST_STORE (model);
97
if (source_list == NULL) {
98
gtk_list_store_clear (store);
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
117
107
gtk_tree_model_get_iter_first (model, &iter);
119
109
for (groups = e_source_list_peek_groups (source_list);
136
126
gtk_tree_model_iter_next (model, &iter);
138
sources = get_sorted_sources (e_source_group_peek_sources (groups->data));
128
sources = e_source_group_peek_sources (groups->data);
130
/* Create a shallow copy and sort by name. */
131
sources = g_slist_sort (
132
g_slist_copy (sources),
133
(GCompareFunc) compare_source_names);
139
135
for (s = sources; s != NULL; s = s->next) {
140
136
const gchar *color_spec;
242
238
switch (property_id) {
243
239
case PROP_SOURCE_LIST:
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);
251
priv->source_list = g_value_dup_object (value);
253
/* Reset the tree store. */
254
source_list_changed_cb (
256
E_SOURCE_COMBO_BOX (object));
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),
240
e_source_combo_box_set_source_list (
241
E_SOURCE_COMBO_BOX (object),
242
g_value_get_object (value));
294
275
priv = E_SOURCE_COMBO_BOX_GET_PRIVATE (object);
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;
356
339
(GDestroyNotify) gtk_tree_row_reference_free);
360
e_source_combo_box_get_type (void)
362
static GType type = 0;
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),
374
(GInstanceInitFunc) e_source_combo_box_init,
375
NULL /* value_table */
378
type = g_type_register_static (
379
GTK_TYPE_COMBO_BOX, "ESourceComboBox", &type_info, 0);
386
343
* e_source_combo_box_new:
387
344
* @source_list: an #ESourceList
409
368
* @source_combo_box.
411
370
* Returns: an #ESourceList
414
375
e_source_combo_box_get_source_list (ESourceComboBox *source_combo_box)
416
ESourceList *source_list;
418
377
g_return_val_if_fail (E_IS_SOURCE_COMBO_BOX (source_combo_box), NULL);
420
g_object_get (source_combo_box, "source-list", &source_list, NULL);
379
return source_combo_box->priv->source_list;
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.
434
393
e_source_combo_box_set_source_list (ESourceComboBox *source_combo_box,
435
394
ESourceList *source_list)
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));
440
g_object_set (source_combo_box, "source-list", source_list, NULL);
398
if (source_list != NULL) {
399
g_return_if_fail (E_IS_SOURCE_LIST (source_list));
400
g_object_ref (source_list);
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;
411
source_combo_box->priv->source_list = source_list;
413
/* Reset the tree store. */
414
source_list_changed_cb (source_list, source_combo_box);
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);
425
g_object_notify (G_OBJECT (source_combo_box), "source-list");