aboutsummaryrefslogtreecommitdiffstats
path: root/mail/e-mail-label-list-store.c
blob: f00a0ec56ed68928aea937b81109c6b536d47222 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
/*
 * e-mail-label-list-store.c
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with the program; if not, see <http://www.gnu.org/licenses/>
 *
 *
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "e-mail-label-list-store.h"

#include <glib/gi18n.h>
#include <camel/camel.h>

#define E_MAIL_LABEL_LIST_STORE_GET_PRIVATE(obj) \
    (G_TYPE_INSTANCE_GET_PRIVATE \
    ((obj), E_TYPE_MAIL_LABEL_LIST_STORE, EMailLabelListStorePrivate))

#define E_MAIL_LABEL_LIST_STORE_GET_PRIVATE(obj) \
    (G_TYPE_INSTANCE_GET_PRIVATE \
    ((obj), E_TYPE_MAIL_LABEL_LIST_STORE, EMailLabelListStorePrivate))

enum {
    CHANGED,
    LAST_SIGNAL
};

static guint signals[LAST_SIGNAL];

struct _EMailLabelListStorePrivate {
    GHashTable *tag_index;
    GSettings *mail_settings;
    guint idle_changed_id;
};

static struct {
    const gchar *label_name;
    const gchar *label_color;
    const gchar *label_tag;
} label_defaults[] = {
    { N_("I_mportant"), "#EF2929", "$Labelimportant" }, /* red */
    { N_("_Work"),      "#F57900", "$Labelwork" },      /* orange */
    { N_("_Personal"),  "#4E9A06", "$Labelpersonal" },  /* green */
    { N_("_To Do"),     "#3465A4", "$Labeltodo" },      /* blue */
    { N_("_Later"),     "#75507B", "$Labellater" }      /* purple */
};

/* Forward Declarations */
static void e_mail_label_list_store_interface_init
                        (GtkTreeModelIface *interface);
static void labels_settings_changed_cb  (GSettings *settings,
                         const gchar *key,
                         gpointer user_data);

G_DEFINE_TYPE_WITH_CODE (
    EMailLabelListStore,
    e_mail_label_list_store,
    GTK_TYPE_LIST_STORE,
    G_IMPLEMENT_INTERFACE (
        GTK_TYPE_TREE_MODEL,
        e_mail_label_list_store_interface_init))

static gchar *
mail_label_list_store_tag_from_name (const gchar *label_name)
{
    gchar *label_tag;
    gchar *temp;

    /* Thunderbird compatible */
    temp = g_ascii_strdown (label_name, -1);
    g_strdelimit (temp, " ()/{%*<>\\\"", '_');
    label_tag = camel_utf8_utf7 (temp);
    g_free (temp);

    return label_tag;
}

static gchar *
mail_label_list_store_encode_label (const gchar *label_name,
                                      const gchar *label_color,
                                      const gchar *label_tag)
{
    GString *string;

    /* Encoded Form: <name> ':' <color> [ '|' <tag> ] */

    string = g_string_new (label_name);
    g_string_append_printf (string, ":%s", label_color);

    if (label_tag != NULL)
        g_string_append_printf (string, "|%s", label_tag);

    return g_string_free (string, FALSE);
}

static void
mail_label_list_store_ensure_defaults (EMailLabelListStore *store)
{
    gint ii;

    for (ii = 0; ii < G_N_ELEMENTS (label_defaults); ii++) {
        GtkTreeIter iter;
        const gchar *label_name;
        const gchar *label_color;
        const gchar *label_tag;
        gchar *encoded;

        label_name = gettext (label_defaults[ii].label_name);
        label_color = label_defaults[ii].label_color;
        label_tag = label_defaults[ii].label_tag;

        if (e_mail_label_list_store_lookup (store, label_tag, &iter))
            continue;

        encoded = mail_label_list_store_encode_label (
            label_name, label_color, label_tag);

        gtk_list_store_insert_with_values (
            GTK_LIST_STORE (store),
            NULL, -1, 0, encoded, -1);

        g_free (encoded);
    }
}

static gchar *
mail_label_list_store_get_stock_id (EMailLabelListStore *store,
                                    const gchar *color_spec)
{
    EMailLabelListStoreClass *class;
    GtkIconFactory *icon_factory;
    GdkColor color;
    gchar *stock_id;

    class = E_MAIL_LABEL_LIST_STORE_GET_CLASS (store);
    icon_factory = class->icon_factory;

    if (!gdk_color_parse (color_spec, &color))
        return NULL;

    stock_id = g_strdup_printf ("evolution-label-%s", color_spec);

    /* Themes need not be taken into account here.
     * It's just a solid block of a user-chosen color. */
    if (gtk_icon_factory_lookup (icon_factory, stock_id) == NULL) {
        GtkIconSet *icon_set;
        GdkPixbuf *pixbuf;
        guint32 pixel;

        pixel = ((color.red & 0xFF00) << 16) +
            ((color.green & 0xFF00) << 8) +
            (color.blue & 0xFF00);

        pixbuf = gdk_pixbuf_new (
            GDK_COLORSPACE_RGB, FALSE, 8, 16, 16);
        gdk_pixbuf_fill (pixbuf, pixel);

        icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
        gtk_icon_factory_add (icon_factory, stock_id, icon_set);
        gtk_icon_set_unref (icon_set);

        g_object_unref (pixbuf);
    }

    return stock_id;
}

static void
mail_label_list_store_dispose (GObject *object)
{
    EMailLabelListStorePrivate *priv;

    priv = E_MAIL_LABEL_LIST_STORE_GET_PRIVATE (object);

    if (priv->idle_changed_id) {
        g_source_remove (priv->idle_changed_id);
        priv->idle_changed_id = 0;
    }

    if (priv->mail_settings != NULL) {
        g_object_unref (priv->mail_settings);
        priv->mail_settings = NULL;
    }

    /* Chain up to parent's dispose() method. */
    G_OBJECT_CLASS (e_mail_label_list_store_parent_class)->
        dispose (object);
}

static void
mail_label_list_store_finalize (GObject *object)
{
    EMailLabelListStorePrivate *priv;

    priv = E_MAIL_LABEL_LIST_STORE_GET_PRIVATE (object);

    g_hash_table_destroy (priv->tag_index);

    /* Chain up to parent's finalize() method. */
    G_OBJECT_CLASS (e_mail_label_list_store_parent_class)->
        finalize (object);
}

static gboolean
labels_model_changed_idle_cb (gpointer user_data)
{
    EMailLabelListStore *store = user_data;
    GPtrArray *array;
    GtkTreeIter tmp_iter;
    gboolean iter_set;

    g_return_val_if_fail (E_IS_MAIL_LABEL_LIST_STORE (store), FALSE);

    store->priv->idle_changed_id = 0;

    /* Make sure we don't enter an infinite synchronizing loop */
    g_signal_handlers_block_by_func (
        store->priv->mail_settings,
        labels_settings_changed_cb, store);

    /* Build list to store in GSettings */

    array = g_ptr_array_new ();

    iter_set = gtk_tree_model_get_iter_first (
        GTK_TREE_MODEL (store), &tmp_iter);

    while (iter_set) {
        gchar *string;

        gtk_tree_model_get (
            GTK_TREE_MODEL (store), &tmp_iter,
            0, &string, -1);
        g_ptr_array_add (array, string);

        iter_set = gtk_tree_model_iter_next (
            GTK_TREE_MODEL (store), &tmp_iter);
    }

    g_ptr_array_add (array, NULL);

    g_settings_set_strv (
        store->priv->mail_settings, "labels",
        (const gchar * const *) array->pdata);

    g_ptr_array_foreach (array, (GFunc) g_free, NULL);
    g_ptr_array_free (array, TRUE);

    g_signal_handlers_unblock_by_func (
        store->priv->mail_settings,
        labels_settings_changed_cb, store);

    g_signal_emit (store, signals[CHANGED], 0);

    return FALSE;
}

static void
labels_model_changed_cb (EMailLabelListStore *store)
{
    g_return_if_fail (E_IS_MAIL_LABEL_LIST_STORE (store));

    /* do the actual save and signal emission on idle,
     * to accumulate as many changes as possible */
    if (!store->priv->idle_changed_id)
        store->priv->idle_changed_id = g_idle_add (labels_model_changed_idle_cb, store);
}

static void
labels_settings_changed_cb (GSettings *settings,
                            const gchar *key,
                            gpointer user_data)
{
    EMailLabelListStore *store;
    GtkTreeModel *model;
    GtkTreeIter iter;
    GHashTable *changed_labels;
    gchar **strv;
    gint i;

    store = E_MAIL_LABEL_LIST_STORE (user_data);
    model = GTK_TREE_MODEL (store);

    strv = g_settings_get_strv (store->priv->mail_settings, "labels");

    /* Check if any label changed first, because GSettings can claim
     * change when nothing changed at all */
    changed_labels = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
    if (gtk_tree_model_get_iter_first (model, &iter)) {
        do {
            gchar *label_str = NULL;

            gtk_tree_model_get (model, &iter, 0, &label_str, -1);

            if (label_str)
                g_hash_table_insert (changed_labels, label_str, NULL);
        } while (gtk_tree_model_iter_next (model, &iter));

        for (i = 0; strv[i] != NULL; i++) {
            if (!g_hash_table_remove (changed_labels, strv[i])) {
                g_hash_table_insert (changed_labels, g_strdup (""), NULL);
                break;
            }
        }
    } else {
        /* nothing in the store, thus fill it (pretend change) */
        g_hash_table_insert (changed_labels, g_strdup (""), NULL);
    }

    /* Nothing changed */
    if (g_hash_table_size (changed_labels) == 0) {
        g_hash_table_destroy (changed_labels);
        g_strfreev (strv);
        return;
    }

    g_hash_table_destroy (changed_labels);

    /* Make sure we don't enter an infinite synchronizing loop */
    g_signal_handlers_block_by_func (
        store, labels_model_changed_cb, store);

    gtk_list_store_clear (GTK_LIST_STORE (store));

    for (i = 0; strv[i] != NULL; i++) {
        GtkTreeIter iter;

        gtk_list_store_insert_with_values (
            GTK_LIST_STORE (store), &iter, -1, 0, strv[i], -1);
    }

    g_strfreev (strv);

    g_signal_handlers_unblock_by_func (
        store, labels_model_changed_cb, store);
}

static void
mail_label_list_store_constructed (GObject *object)
{
    EMailLabelListStore *store;

    store = E_MAIL_LABEL_LIST_STORE (object);

    /* Connect to GSettings' change notifications */
    store->priv->mail_settings = g_settings_new ("org.gnome.evolution.mail");
    g_signal_connect (
        store->priv->mail_settings, "changed::labels",
        G_CALLBACK (labels_settings_changed_cb), store);
    labels_settings_changed_cb (
        store->priv->mail_settings, "labels", store);

    /* Connect to ListStore change notifications */
    g_signal_connect_swapped (
        store, "row-inserted",
        G_CALLBACK (labels_model_changed_cb), store);
    g_signal_connect_swapped (
        store, "row-changed",
        G_CALLBACK (labels_model_changed_cb), store);
    g_signal_connect_swapped (
        store, "row-deleted",
        G_CALLBACK (labels_model_changed_cb), store);
    g_signal_connect_swapped (
        store, "rows-reordered",
        G_CALLBACK (labels_model_changed_cb), store);

    mail_label_list_store_ensure_defaults (store);

    /* Chain up to parent's constructed() method. */
    G_OBJECT_CLASS (e_mail_label_list_store_parent_class)->
        constructed (object);
}

static void
mail_label_list_store_row_inserted (GtkTreeModel *model,
                                    GtkTreePath *path,
                                    GtkTreeIter *iter)
{
    EMailLabelListStore *store;
    GtkTreeRowReference *reference;
    GHashTable *tag_index;
    gchar *tag;

    store = E_MAIL_LABEL_LIST_STORE (model);
    tag = e_mail_label_list_store_get_tag (store, iter);
    g_return_if_fail (tag != NULL);

    /* Hash table takes ownership of both tag and reference. */
    tag_index = store->priv->tag_index;
    reference = gtk_tree_row_reference_new (model, path);
    g_hash_table_insert (tag_index, tag, reference);

    /* We don't need to do anything special for row deletion.
     * The reference will automatically become invalid (that's
     * why we're storing references and not iterators or paths),
     * so garbage collection is not important.  We'll do it
     * lazily. */
}

static void
e_mail_label_list_store_class_init (EMailLabelListStoreClass *class)
{
    GObjectClass *object_class;

    g_type_class_add_private (class, sizeof (EMailLabelListStorePrivate));

    object_class = G_OBJECT_CLASS (class);
    object_class->dispose = mail_label_list_store_dispose;
    object_class->finalize = mail_label_list_store_finalize;
    object_class->constructed = mail_label_list_store_constructed;

    class->icon_factory = gtk_icon_factory_new ();
    gtk_icon_factory_add_default (class->icon_factory);

    signals[CHANGED] = g_signal_new (
        "changed",
        G_OBJECT_CLASS_TYPE (class),
        G_SIGNAL_RUN_FIRST,
        0, NULL, NULL,
        g_cclosure_marshal_VOID__VOID,
        G_TYPE_NONE, 0);
}

static void
e_mail_label_list_store_interface_init (GtkTreeModelIface *interface)
{
    interface->row_inserted = mail_label_list_store_row_inserted;
}

static void
e_mail_label_list_store_init (EMailLabelListStore *store)
{
    GHashTable *tag_index;
    GType type = G_TYPE_STRING;

    tag_index = g_hash_table_new_full (
        g_str_hash, g_str_equal,
        (GDestroyNotify) g_free,
        (GDestroyNotify) gtk_tree_row_reference_free);

    store->priv = E_MAIL_LABEL_LIST_STORE_GET_PRIVATE (store);
    store->priv->tag_index = tag_index;

    /* XXX While it may seem awkward to cram the label name and color
     *     into a single string column, we do it for the benefit of
     *     letting GSettings keep the model in sync.
     *
     * XXX There's a valid argument to be made that this information
     *     doesn't belong in GSettings in the first place.  A key file
     *     under $(user_data_dir)/mail would work better. */
    gtk_list_store_set_column_types (GTK_LIST_STORE (store), 1, &type);
}

EMailLabelListStore *
e_mail_label_list_store_new (void)
{
    return g_object_new (E_TYPE_MAIL_LABEL_LIST_STORE, NULL);
}

gchar *
e_mail_label_list_store_get_name (EMailLabelListStore *store,
                                  GtkTreeIter *iter)
{
    gchar *encoded;
    gchar *result;
    gchar **strv;

    /* Encoded Form: <name> ':' <color> [ '|' <tag> ] */

    g_return_val_if_fail (E_IS_MAIL_LABEL_LIST_STORE (store), NULL);
    g_return_val_if_fail (iter != NULL, NULL);

    gtk_tree_model_get (GTK_TREE_MODEL (store), iter, 0, &encoded, -1);

    strv = g_strsplit_set (encoded, ":|", 3);

    if (g_strv_length (strv) >= 2)
        result = g_strdup (gettext (strv[0]));
    else
        result = NULL;

    g_strfreev (strv);
    g_free (encoded);

    return result;
}

gboolean
e_mail_label_list_store_get_color (EMailLabelListStore *store,
                                   GtkTreeIter *iter,
                                   GdkColor *color)
{
    gchar *encoded;
    gchar **strv;
    gboolean valid;

    /* Encoded Form: <name> ':' <color> [ '|' <tag> ] */

    g_return_val_if_fail (E_IS_MAIL_LABEL_LIST_STORE (store), FALSE);
    g_return_val_if_fail (iter != NULL, FALSE);
    g_return_val_if_fail (color != NULL, FALSE);

    gtk_tree_model_get (GTK_TREE_MODEL (store), iter, 0, &encoded, -1);

    strv = g_strsplit_set (encoded, ":|", 3);

    if (g_strv_length (strv) >= 2)
        valid = gdk_color_parse (strv[1], color);
    else
        valid = FALSE;

    g_strfreev (strv);
    g_free (encoded);

    return valid;
}

gchar *
e_mail_label_list_store_get_stock_id (EMailLabelListStore *store,
                                      GtkTreeIter *iter)
{
    gchar *encoded;
    gchar *result;
    gchar **strv;

    /* Encoded Form: <name> ':' <color> [ '|' <tag> ] */

    g_return_val_if_fail (E_IS_MAIL_LABEL_LIST_STORE (store), NULL);
    g_return_val_if_fail (iter != NULL, NULL);
    gtk_tree_model_get (GTK_TREE_MODEL (store), iter, 0, &encoded, -1);

    strv = g_strsplit_set (encoded, ":|", 3);

    if (g_strv_length (strv) >= 2)
        result = mail_label_list_store_get_stock_id (store, strv[1]);
    else
        result = NULL;

    g_strfreev (strv);
    g_free (encoded);

    return result;
}

gchar *
e_mail_label_list_store_get_tag (EMailLabelListStore *store,
                                 GtkTreeIter *iter)
{
    gchar *encoded;
    gchar *result;
    gchar **strv;

    /* Encoded Form: <name> ':' <color> [ '|' <tag> ] */

    g_return_val_if_fail (E_IS_MAIL_LABEL_LIST_STORE (store), NULL);
    g_return_val_if_fail (iter != NULL, NULL);

    gtk_tree_model_get (GTK_TREE_MODEL (store), iter, 0, &encoded, -1);

    strv = g_strsplit_set (encoded, ":|", 3);

    /* XXX I guess for historical reasons the default label tags have
     *     a "$Label" prefix, but the default list in GSettings doesn't
     *     include tags.  That's why the <tag> part is optional.
     *     So if we're missing the <tag> part, look it up in the
     *     hard-coded default list above.
     *
     *     Not sure I got my facts straight here.  Double check. */
    if (g_strv_length (strv) >= 3)
        result = g_strdup (strv[2]);
    else {
        gint ii;

        result = NULL;

        for (ii = 0; ii < G_N_ELEMENTS (label_defaults); ii++) {
            const gchar *label_name;
            const gchar *label_tag;

            label_name = label_defaults[ii].label_name;
            label_tag = label_defaults[ii].label_tag;

            if (strcmp (strv[0], label_name) == 0) {
                result = g_strdup (label_tag);
                break;
            }
        }
    }

    /* XXX Still no luck?  The label list in GSettings must be screwed up.
     *     We must not return NULL because the tag is used as a key in
     *     the index hash table, so generate a tag from the name. */
    if (result == NULL)
        result = mail_label_list_store_tag_from_name (strv[0]);

    g_strfreev (strv);
    g_free (encoded);

    return result;
}

void
e_mail_label_list_store_set (EMailLabelListStore *store,
                             GtkTreeIter *iter,
                             const gchar *name,
                             const GdkColor *color)
{
    gchar *encoded;
    gchar *label_color;
    gchar *label_tag = NULL;

    g_return_if_fail (E_IS_MAIL_LABEL_LIST_STORE (store));
    g_return_if_fail (name != NULL);
    g_return_if_fail (color != NULL);

    label_color = gdk_color_to_string (color);

    if (iter != NULL)
        label_tag = e_mail_label_list_store_get_tag (store, iter);
    if (label_tag == NULL)
        label_tag = mail_label_list_store_tag_from_name (name);

    encoded = mail_label_list_store_encode_label (
        name, label_color, label_tag);

    /* We use gtk_list_store_insert_with_values() so the data is
     * in place when the 'row-inserted' signal is emitted and our
     * row_inserted() method executes. */
    if (iter != NULL)
        gtk_list_store_set (
            GTK_LIST_STORE (store), iter, 0, encoded, -1);
    else
        gtk_list_store_insert_with_values (
            GTK_LIST_STORE (store), NULL, -1, 0, encoded, -1);

    g_free (label_color);
    g_free (label_tag);
    g_free (encoded);
}

gboolean
e_mail_label_list_store_lookup (EMailLabelListStore *store,
                                const gchar *tag,
                                GtkTreeIter *iter)
{
    GtkTreeRowReference *reference;
    GHashTable *tag_index;
    GtkTreeModel *model;
    GtkTreePath *path;

    g_return_val_if_fail (E_IS_MAIL_LABEL_LIST_STORE (store), FALSE);
    g_return_val_if_fail (tag != NULL, FALSE);
    g_return_val_if_fail (iter != NULL, FALSE);

    tag_index = store->priv->tag_index;
    reference = g_hash_table_lookup (tag_index, tag);

    if (reference == NULL)
        return FALSE;

    if (!gtk_tree_row_reference_valid (reference)) {
        /* Garbage collect the dead reference. */
        g_hash_table_remove (tag_index, tag);
        return FALSE;
    }

    model = gtk_tree_row_reference_get_model (reference);
    path = gtk_tree_row_reference_get_path (reference);
    gtk_tree_model_get_iter (model, iter, path);
    gtk_tree_path_free (path);

    return TRUE;
}

gboolean
e_mail_label_tag_is_default (const gchar *tag)
{
    g_return_val_if_fail (tag != NULL, FALSE);

    return g_str_has_prefix (tag, "$Label");
}