aboutsummaryrefslogtreecommitdiffstats
path: root/composer/e-composer-from-header.c
blob: de4f8ac8e0d125a02282a5681a0d9232f6d950b2 (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
#include "e-composer-from-header.h"

#define E_COMPOSER_FROM_HEADER_GET_PRIVATE(obj) \
    (G_TYPE_INSTANCE_GET_PRIVATE \
    ((obj), E_TYPE_COMPOSER_FROM_HEADER, EComposerFromHeaderPrivate))

struct _EComposerFromHeaderPrivate {
    GtkWidget *combo_box;
};

static gpointer parent_class;

static void
composer_from_header_changed_cb (EAccountComboBox *combo_box,
                                 EComposerFromHeader *header)
{
    g_signal_emit_by_name (header, "changed");
}

static void
composer_from_header_dispose (GObject *object)
{
    EComposerFromHeaderPrivate *priv;

    priv = E_COMPOSER_FROM_HEADER_GET_PRIVATE (object);

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

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

static void
composer_from_header_class_init (EComposerFromHeaderClass *class)
{
    GObjectClass *object_class;

    parent_class = g_type_class_peek_parent (class);
    g_type_class_add_private (class, sizeof (EComposerFromHeaderPrivate));

    object_class = G_OBJECT_CLASS (class);
    object_class->dispose = composer_from_header_dispose;
}

static void
composer_from_header_init (EComposerFromHeader *header)
{
    GtkWidget *hbox;
    GtkWidget *widget;

    header->priv = E_COMPOSER_FROM_HEADER_GET_PRIVATE (header);

    hbox = g_object_ref_sink (gtk_hbox_new (FALSE, 6));
    E_COMPOSER_HEADER (header)->input_widget = hbox;

    widget = e_account_combo_box_new ();
    g_signal_connect (
        widget, "changed",
        G_CALLBACK (composer_from_header_changed_cb), header);
    gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
    header->priv->combo_box = g_object_ref_sink (widget);
    gtk_widget_show (widget);
}

GType
e_composer_from_header_get_type (void)
{
    static GType type = 0;

    if (G_UNLIKELY (type == 0)) {
        static const GTypeInfo type_info = {
            sizeof (EComposerFromHeaderClass),
            (GBaseInitFunc) NULL,
            (GBaseFinalizeFunc) NULL,
            (GClassInitFunc) composer_from_header_class_init,
            (GClassFinalizeFunc) NULL,
            NULL,  /* class_data */
            sizeof (EComposerFromHeader),
            0,     /* n_preallocs */
            (GInstanceInitFunc) composer_from_header_init,
            NULL   /* value_table */
        };

        type = g_type_register_static (
            E_TYPE_COMPOSER_HEADER, "EComposerFromHeader",
            &type_info, 0);
    }

    return type;
}

EComposerHeader *
e_composer_from_header_new (const gchar *label)
{
    return g_object_new (
        E_TYPE_COMPOSER_FROM_HEADER, "label", label,
        "button", FALSE, NULL);
}

void
e_composer_from_header_set_account_list (EComposerFromHeader *header,
                                         EAccountList *account_list)
{
    EAccountComboBox *combo_box;

    g_return_if_fail (E_IS_COMPOSER_FROM_HEADER (header));

    combo_box = E_ACCOUNT_COMBO_BOX (header->priv->combo_box);
    e_account_combo_box_set_account_list (combo_box, account_list);
}

EAccount *
e_composer_from_header_get_active (EComposerFromHeader *header)
{
    EAccountComboBox *combo_box;

    g_return_val_if_fail (E_IS_COMPOSER_FROM_HEADER (header), NULL);

    combo_box = E_ACCOUNT_COMBO_BOX (header->priv->combo_box);
    return e_account_combo_box_get_active (combo_box);
}

gboolean
e_composer_from_header_set_active (EComposerFromHeader *header,
                                   EAccount *account)
{
    EAccountComboBox *combo_box;

    g_return_val_if_fail (E_IS_COMPOSER_FROM_HEADER (header), FALSE);

    combo_box = E_ACCOUNT_COMBO_BOX (header->priv->combo_box);
    return e_account_combo_box_set_active (combo_box, account);
}

const gchar *
e_composer_from_header_get_active_name (EComposerFromHeader *header)
{
    EAccountComboBox *combo_box;

    g_return_val_if_fail (E_IS_COMPOSER_FROM_HEADER (header), NULL);

    combo_box = E_ACCOUNT_COMBO_BOX (header->priv->combo_box);
    return e_account_combo_box_get_active_name (combo_box);
}

gboolean
e_composer_from_header_set_active_name (EComposerFromHeader *header,
                                        const gchar *account_name)
{
    EAccountComboBox *combo_box;

    g_return_val_if_fail (E_IS_COMPOSER_FROM_HEADER (header), FALSE);

    combo_box = E_ACCOUNT_COMBO_BOX (header->priv->combo_box);
    return e_account_combo_box_set_active_name (combo_box, account_name);
}

CamelInternetAddress *
e_composer_from_header_get_active_address (EComposerFromHeader *header)
{
    CamelInternetAddress *address;
    EAccount *account;

    g_return_val_if_fail (E_IS_COMPOSER_FROM_HEADER (header), NULL);

    account = e_composer_from_header_get_active (header);
    if (account == NULL)
        return NULL;

    address = camel_internet_address_new ();
    camel_internet_address_add (
        address, account->id->name, account->id->address);

    return address;
}