aboutsummaryrefslogblamecommitdiffstats
path: root/composer/e-composer-header-table.c
blob: c3af87a76d735e0d10fe269a46c88c2fbf74a863 (plain) (tree)
1
2
3
4
5
6
7
8
9
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
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
  



                                                                



                                                                    
                                                  

                                                                   


                                                                               




                                    
                           


























































                                                                           
                   











                                                         
                                 





























































































































































































































































                                                                               





                                                                       


























































































                                                                              






                                                                               
































































                                                                            




                                             
























































































                                                                               










                                                  



























































































































































































































































































































































































                                                                                  






















                                                                           


































































































































                                                                             
/*
 * 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)
 */

#include "e-composer-header-table.h"

#include <string.h>
#include <glib/gi18n-lib.h>
#include <libedataserverui/e-name-selector.h>

#include "e-signature-combo-box.h"

#include "e-composer-from-header.h"
#include "e-composer-name-header.h"
#include "e-composer-post-header.h"
#include "e-composer-text-header.h"

#define E_COMPOSER_HEADER_TABLE_GET_PRIVATE(obj) \
    (G_TYPE_INSTANCE_GET_PRIVATE \
    ((obj), E_TYPE_COMPOSER_HEADER_TABLE, EComposerHeaderTablePrivate))

#define E_COMPOSER_HEADER_TABLE_GET_FROM_HEADER(table) \
    (E_COMPOSER_FROM_HEADER (e_composer_header_table_get_header \
    (E_COMPOSER_HEADER_TABLE (table), E_COMPOSER_HEADER_FROM)))

#define E_COMPOSER_HEADER_TABLE_GET_REPLY_TO_HEADER(table) \
    (E_COMPOSER_TEXT_HEADER (e_composer_header_table_get_header \
    (E_COMPOSER_HEADER_TABLE (table), E_COMPOSER_HEADER_REPLY_TO)))

#define E_COMPOSER_HEADER_TABLE_GET_TO_HEADER(table) \
    (E_COMPOSER_NAME_HEADER (e_composer_header_table_get_header \
    (E_COMPOSER_HEADER_TABLE (table), E_COMPOSER_HEADER_TO)))

#define E_COMPOSER_HEADER_TABLE_GET_CC_HEADER(table) \
    (E_COMPOSER_NAME_HEADER (e_composer_header_table_get_header \
    (E_COMPOSER_HEADER_TABLE (table), E_COMPOSER_HEADER_CC)))

#define E_COMPOSER_HEADER_TABLE_GET_BCC_HEADER(table) \
    (E_COMPOSER_NAME_HEADER (e_composer_header_table_get_header \
    (E_COMPOSER_HEADER_TABLE (table), E_COMPOSER_HEADER_BCC)))

#define E_COMPOSER_HEADER_TABLE_GET_POST_TO_HEADER(table) \
    (E_COMPOSER_POST_HEADER (e_composer_header_table_get_header \
    (E_COMPOSER_HEADER_TABLE (table), E_COMPOSER_HEADER_POST_TO)))

#define E_COMPOSER_HEADER_TABLE_GET_SUBJECT_HEADER(table) \
    (E_COMPOSER_TEXT_HEADER (e_composer_header_table_get_header \
    (E_COMPOSER_HEADER_TABLE (table), E_COMPOSER_HEADER_SUBJECT)))

#define HEADER_TOOLTIP_TO \
    _("Enter the recipients of the message")
#define HEADER_TOOLTIP_CC \
    _("Enter the addresses that will receive a " \
      "carbon copy of the message")
#define HEADER_TOOLTIP_BCC \
    _("Enter the addresses that will receive a " \
      "carbon copy of the message without appearing " \
      "in the recipient list of the message")

enum {
    PROP_0,
    PROP_ACCOUNT,
    PROP_ACCOUNT_LIST,
    PROP_ACCOUNT_NAME,
    PROP_DESTINATIONS_BCC,
    PROP_DESTINATIONS_CC,
    PROP_DESTINATIONS_TO,
    PROP_MODEL,
    PROP_POST_TO,
    PROP_REPLY_TO,
    PROP_SIGNATURE,
    PROP_SIGNATURE_LIST,
    PROP_SUBJECT
};

struct _EComposerHeaderTablePrivate {
    EComposerHeader *headers[E_COMPOSER_NUM_HEADERS];
    GtkWidget *signature_label;
    GtkWidget *signature_combo_box;
    ENameSelector *name_selector;
    EMFolderTreeModel *model;
};

static gpointer parent_class;

static void
g_value_set_destinations (GValue *value,
                          EDestination **destinations)
{
    GValueArray *value_array;
    GValue element;
    gint ii;

    memset (&element, 0, sizeof (GValue));
    g_value_init (&element, E_TYPE_DESTINATION);

    /* Preallocate some reasonable number. */
    value_array = g_value_array_new (64);

    for (ii = 0; destinations[ii] != NULL; ii++) {
        g_value_set_object (&element, destinations[ii]);
        g_value_array_append (value_array, &element);
    }

    g_value_take_boxed (value, value_array);
}

static EDestination **
g_value_dup_destinations (const GValue *value)
{
    EDestination **destinations;
    GValueArray *value_array;
    GValue *element;
    gint ii;

    value_array = g_value_get_boxed (value);
    destinations = g_new0 (EDestination *, value_array->n_values + 1);

    for (ii = 0; ii < value_array->n_values; ii++) {
        element = g_value_array_get_nth (value_array, ii);
        destinations[ii] = g_value_dup_object (element);
    }

    return destinations;
}

static void
g_value_set_string_list (GValue *value,
                         GList *list)
{
    GValueArray *value_array;
    GValue element;

    memset (&element, 0, sizeof (GValue));
    g_value_init (&element, G_TYPE_STRING);

    value_array = g_value_array_new (g_list_length (list));

    while (list != NULL) {
        g_value_set_string (&element, list->data);
        g_value_array_append (value_array, &element);
    }

    g_value_take_boxed (value, value_array);
}

static GList *
g_value_dup_string_list (const GValue *value)
{
    GValueArray *value_array;
    GList *list = NULL;
    GValue *element;
    gint ii;

    value_array = g_value_get_boxed (value);

    for (ii = 0; ii < value_array->n_values; ii++) {
        element = g_value_array_get_nth (value_array, ii);
        list = g_list_prepend (list, g_value_dup_string (element));
    }

    return g_list_reverse (list);
}

static void
composer_header_table_notify_header (EComposerHeader *header,
                                     const gchar *property_name)
{
    GtkWidget *parent;

    parent = gtk_widget_get_parent (header->input_widget);
    g_return_if_fail (E_IS_COMPOSER_HEADER_TABLE (parent));
    g_object_notify (G_OBJECT (parent), property_name);
}

static void
composer_header_table_notify_widget (GtkWidget *widget,
                                     const gchar *property_name)
{
    GtkWidget *parent;

    parent = gtk_widget_get_parent (widget);
    g_return_if_fail (E_IS_COMPOSER_HEADER_TABLE (parent));
    g_object_notify (G_OBJECT (parent), property_name);
}

static void
composer_header_table_bind_header (const gchar *property_name,
                                   const gchar *signal_name,
                                   EComposerHeader *header)
{
    /* Propagate the signal as "notify::property_name". */

    g_signal_connect (
        header, signal_name,
        G_CALLBACK (composer_header_table_notify_header),
        (gpointer) property_name);
}

static void
composer_header_table_bind_widget (const gchar *property_name,
                                   const gchar *signal_name,
                                   GtkWidget *widget)
{
    /* Propagate the signal as "notify::property_name". */

    g_signal_connect (
        widget, signal_name,
        G_CALLBACK (composer_header_table_notify_widget),
        (gpointer) property_name);
}

static void
composer_header_table_from_changed_cb (EComposerHeaderTable *table)
{
    EAccount *account;
    EComposerPostHeader *post_header;
    EComposerTextHeader *text_header;
    const gchar *reply_to;

    /* Keep "Post-To" and "Reply-To" synchronized with "From" */

    account = e_composer_header_table_get_account (table);

    post_header = E_COMPOSER_HEADER_TABLE_GET_POST_TO_HEADER (table);
    e_composer_post_header_set_account (post_header, account);

    reply_to = (account != NULL) ? account->id->reply_to : NULL;
    text_header = E_COMPOSER_HEADER_TABLE_GET_REPLY_TO_HEADER (table);
    e_composer_text_header_set_text (text_header, reply_to);
}

static GObject *
composer_header_table_constructor (GType type,
                                   guint n_construct_properties,
                                   GObjectConstructParam *construct_properties)
{
    GObject *object;
    EComposerHeaderTablePrivate *priv;
    guint rows, ii;

    /* Chain up to parent's constructor() method. */
    object = G_OBJECT_CLASS (parent_class)->constructor (
        type, n_construct_properties, construct_properties);

    priv = E_COMPOSER_HEADER_TABLE_GET_PRIVATE (object);

    rows = G_N_ELEMENTS (priv->headers);
    gtk_table_resize (GTK_TABLE (object), rows, 4);
    gtk_table_set_row_spacings (GTK_TABLE (object), 0);
    gtk_table_set_col_spacings (GTK_TABLE (object), 6);

    /* Use "ypadding" instead of "row-spacing" because some rows may
     * be invisible and we don't want spacing around them. */

    for (ii = 0; ii < rows; ii++) {
        gtk_table_attach (
            GTK_TABLE (object), priv->headers[ii]->title_widget,
            0, 1, ii, ii + 1, GTK_FILL, GTK_FILL, 0, 3);
        gtk_table_attach (
            GTK_TABLE (object), priv->headers[ii]->input_widget,
            1, 4, ii, ii + 1, GTK_FILL | GTK_EXPAND, 0, 0, 3);
    }

    ii = E_COMPOSER_HEADER_FROM;

    /* Leave room in the "From" row for signature stuff. */
    gtk_container_child_set (
        GTK_CONTAINER (object),
        priv->headers[ii]->input_widget,
        "right-attach", 2, NULL);

    /* Now add the signature stuff. */
    gtk_table_attach (
        GTK_TABLE (object), priv->signature_label,
        2, 3, ii, ii + 1, 0, 0, 0, 3);
    gtk_table_attach (
        GTK_TABLE (object), priv->signature_combo_box,
        3, 4, ii, ii + 1, 0, 0, 0, 3);

    return object;
}

static void
composer_header_table_set_property (GObject *object,
                                    guint property_id,
                                    const GValue *value,
                                    GParamSpec *pspec)
{
    EDestination **destinations;
    GList *list;

    switch (property_id) {
        case PROP_ACCOUNT:
            e_composer_header_table_set_account (
                E_COMPOSER_HEADER_TABLE (object),
                g_value_get_object (value));
            return;

        case PROP_ACCOUNT_LIST:
            e_composer_header_table_set_account_list (
                E_COMPOSER_HEADER_TABLE (object),
                g_value_get_object (value));
            return;

        case PROP_ACCOUNT_NAME:
            e_composer_header_table_set_account_name (
                E_COMPOSER_HEADER_TABLE (object),
                g_value_get_string (value));
            return;

        case PROP_DESTINATIONS_BCC:
            destinations = g_value_dup_destinations (value);
            e_composer_header_table_set_destinations_bcc (
                E_COMPOSER_HEADER_TABLE (object),
                destinations);
            e_destination_freev (destinations);
            return;

        case PROP_DESTINATIONS_CC:
            destinations = g_value_dup_destinations (value);
            e_composer_header_table_set_destinations_cc (
                E_COMPOSER_HEADER_TABLE (object),
                destinations);
            e_destination_freev (destinations);
            return;

        case PROP_DESTINATIONS_TO:
            destinations = g_value_dup_destinations (value);
            e_composer_header_table_set_destinations_to (
                E_COMPOSER_HEADER_TABLE (object),
                destinations);
            e_destination_freev (destinations);
            return;

        case PROP_MODEL:
            e_composer_header_table_set_folder_tree_model (
                E_COMPOSER_HEADER_TABLE (object),
                g_value_get_object (value));
            return;

        case PROP_POST_TO:
            list = g_value_dup_string_list (value);
            e_composer_header_table_set_post_to_list (
                E_COMPOSER_HEADER_TABLE (object), list);
            g_list_foreach (list, (GFunc) g_free, NULL);
            g_list_free (list);
            return;

        case PROP_REPLY_TO:
            e_composer_header_table_set_reply_to (
                E_COMPOSER_HEADER_TABLE (object),
                g_value_get_string (value));
            return;

        case PROP_SIGNATURE:
            e_composer_header_table_set_signature (
                E_COMPOSER_HEADER_TABLE (object),
                g_value_get_object (value));
            return;

        case PROP_SIGNATURE_LIST:
            e_composer_header_table_set_signature_list (
                E_COMPOSER_HEADER_TABLE (object),
                g_value_get_object (value));
            return;

        case PROP_SUBJECT:
            e_composer_header_table_set_subject (
                E_COMPOSER_HEADER_TABLE (object),
                g_value_get_string (value));
            return;
    }

    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}

static void
composer_header_table_get_property (GObject *object,
                                    guint property_id,
                                    GValue *value,
                                    GParamSpec *pspec)
{
    EDestination **destinations;
    GList *list;

    switch (property_id) {
        case PROP_ACCOUNT:
            g_value_set_object (
                value,
                e_composer_header_table_get_account (
                E_COMPOSER_HEADER_TABLE (object)));
            return;

        case PROP_ACCOUNT_LIST:
            g_value_set_object (
                value,
                e_composer_header_table_get_account_list (
                E_COMPOSER_HEADER_TABLE (object)));
            return;

        case PROP_ACCOUNT_NAME:
            g_value_set_string (
                value,
                e_composer_header_table_get_account_name (
                E_COMPOSER_HEADER_TABLE (object)));
            return;

        case PROP_DESTINATIONS_BCC:
            destinations =
                e_composer_header_table_get_destinations_bcc (
                E_COMPOSER_HEADER_TABLE (object));
            g_value_set_destinations (value, destinations);
            e_destination_freev (destinations);
            return;

        case PROP_DESTINATIONS_CC:
            destinations =
                e_composer_header_table_get_destinations_cc (
                E_COMPOSER_HEADER_TABLE (object));
            g_value_set_destinations (value, destinations);
            e_destination_freev (destinations);
            return;

        case PROP_DESTINATIONS_TO:
            destinations =
                e_composer_header_table_get_destinations_to (
                E_COMPOSER_HEADER_TABLE (object));
            g_value_set_destinations (value, destinations);
            e_destination_freev (destinations);
            return;

        case PROP_MODEL:
            g_value_set_object (
                value,
                e_composer_header_table_get_folder_tree_model (
                E_COMPOSER_HEADER_TABLE (object)));
            return;

        case PROP_POST_TO:
            list = e_composer_header_table_get_post_to (
                E_COMPOSER_HEADER_TABLE (object));
            g_value_set_string_list (value, list);
            g_list_foreach (list, (GFunc) g_free, NULL);
            g_list_free (list);
            return;

        case PROP_REPLY_TO:
            g_value_set_string (
                value,
                e_composer_header_table_get_reply_to (
                E_COMPOSER_HEADER_TABLE (object)));
            return;

        case PROP_SIGNATURE:
            g_value_set_object (
                value,
                e_composer_header_table_get_signature (
                E_COMPOSER_HEADER_TABLE (object)));
            return;

        case PROP_SIGNATURE_LIST:
            g_value_set_object (
                value,
                e_composer_header_table_get_signature_list (
                E_COMPOSER_HEADER_TABLE (object)));
            return;

        case PROP_SUBJECT:
            g_value_set_string (
                value,
                e_composer_header_table_get_subject (
                E_COMPOSER_HEADER_TABLE (object)));
            return;
    }

    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}

static void
composer_header_table_dispose (GObject *object)
{
    EComposerHeaderTablePrivate *priv;
    gint ii;

    priv = E_COMPOSER_HEADER_TABLE_GET_PRIVATE (object);

    for (ii = 0; ii < G_N_ELEMENTS (priv->headers); ii++) {
        if (priv->headers[ii] != NULL) {
            g_object_unref (priv->headers[ii]);
            priv->headers[ii] = NULL;
        }
    }

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

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

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

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

static void
composer_header_table_class_init (EComposerHeaderTableClass *class)
{
    GObjectClass *object_class;
    GParamSpec *element_spec;

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

    object_class = G_OBJECT_CLASS (class);
    object_class->constructor = composer_header_table_constructor;
    object_class->set_property = composer_header_table_set_property;
    object_class->get_property = composer_header_table_get_property;
    object_class->dispose = composer_header_table_dispose;

    g_object_class_install_property (
        object_class,
        PROP_ACCOUNT,
        g_param_spec_object (
            "account",
            NULL,
            NULL,
            E_TYPE_ACCOUNT,
            G_PARAM_READWRITE));

    g_object_class_install_property (
        object_class,
        PROP_ACCOUNT_LIST,
        g_param_spec_object (
            "account-list",
            NULL,
            NULL,
            E_TYPE_ACCOUNT_LIST,
            G_PARAM_READWRITE));

    g_object_class_install_property (
        object_class,
        PROP_ACCOUNT_NAME,
        g_param_spec_string (
            "account-name",
            NULL,
            NULL,
            NULL,
            G_PARAM_READWRITE));

    /* floating reference */
    element_spec = g_param_spec_object (
        "value-array-element",
        NULL,
        NULL,
        E_TYPE_DESTINATION,
        G_PARAM_READWRITE);

    g_object_class_install_property (
        object_class,
        PROP_DESTINATIONS_BCC,
        g_param_spec_value_array (
            "destinations-bcc",
            NULL,
            NULL,
            element_spec,
            G_PARAM_READWRITE));

    g_object_class_install_property (
        object_class,
        PROP_DESTINATIONS_CC,
        g_param_spec_value_array (
            "destinations-cc",
            NULL,
            NULL,
            element_spec,
            G_PARAM_READWRITE));

    g_object_class_install_property (
        object_class,
        PROP_DESTINATIONS_TO,
        g_param_spec_value_array (
            "destinations-to",
            NULL,
            NULL,
            element_spec,
            G_PARAM_READWRITE));

    g_object_class_install_property (
        object_class,
        PROP_MODEL,
        g_param_spec_object (
            "model",
            NULL,
            NULL,
            EM_TYPE_FOLDER_TREE_MODEL,
            G_PARAM_READWRITE |
            G_PARAM_CONSTRUCT_ONLY));

    g_object_class_install_property (
        object_class,
        PROP_REPLY_TO,
        g_param_spec_string (
            "reply-to",
            NULL,
            NULL,
            NULL,
            G_PARAM_READWRITE));

    g_object_class_install_property (
        object_class,
        PROP_SIGNATURE,
        g_param_spec_object (
            "signature",
            NULL,
            NULL,
            E_TYPE_SIGNATURE,
            G_PARAM_READWRITE));

    g_object_class_install_property (
        object_class,
        PROP_SIGNATURE_LIST,
        g_param_spec_object (
            "signature-list",
            NULL,
            NULL,
            E_TYPE_SIGNATURE_LIST,
            G_PARAM_READWRITE));

    g_object_class_install_property (
        object_class,
        PROP_SUBJECT,
        g_param_spec_string (
            "subject",
            NULL,
            NULL,
            NULL,
            G_PARAM_READWRITE));
}

static void
composer_header_table_init (EComposerHeaderTable *table)
{
    EComposerHeader *header;
    ENameSelector *name_selector;
    GtkWidget *widget;

    table->priv = E_COMPOSER_HEADER_TABLE_GET_PRIVATE (table);

    name_selector = e_name_selector_new ();
    table->priv->name_selector = name_selector;

    header = e_composer_from_header_new (_("Fr_om:"));
    composer_header_table_bind_header ("account", "changed", header);
    composer_header_table_bind_header ("account-list", "refreshed", header);
    composer_header_table_bind_header ("account-name", "changed", header);
    g_signal_connect_swapped (
        header, "changed", G_CALLBACK (
        composer_header_table_from_changed_cb), table);
    table->priv->headers[E_COMPOSER_HEADER_FROM] = header;

    header = e_composer_text_header_new_label (_("_Reply-To:"));
    composer_header_table_bind_header ("reply-to", "changed", header);
    table->priv->headers[E_COMPOSER_HEADER_REPLY_TO] = header;

    header = e_composer_name_header_new (_("_To:"), name_selector);
    e_composer_header_set_input_tooltip (header, HEADER_TOOLTIP_TO);
    composer_header_table_bind_header ("destinations-to", "changed", header);
    table->priv->headers[E_COMPOSER_HEADER_TO] = header;

    header = e_composer_name_header_new (_("_Cc:"), name_selector);
    e_composer_header_set_input_tooltip (header, HEADER_TOOLTIP_CC);
    composer_header_table_bind_header ("destinations-cc", "changed", header);
    table->priv->headers[E_COMPOSER_HEADER_CC] = header;

    header = e_composer_name_header_new (_("_Bcc:"), name_selector);
    e_composer_header_set_input_tooltip (header, HEADER_TOOLTIP_BCC);
    composer_header_table_bind_header ("destinations-bcc", "changed", header);
    table->priv->headers[E_COMPOSER_HEADER_BCC] = header;

    header = e_composer_post_header_new (_("_Post To:"));
    composer_header_table_bind_header ("post-to", "changed", header);
    table->priv->headers[E_COMPOSER_HEADER_POST_TO] = header;

    header = e_composer_text_header_new_label (_("S_ubject:"));
    composer_header_table_bind_header ("subject", "changed", header);
    table->priv->headers[E_COMPOSER_HEADER_SUBJECT] = header;

    widget = e_signature_combo_box_new ();
    composer_header_table_bind_widget ("signature", "changed", widget);
    composer_header_table_bind_widget ("signature-list", "refreshed", widget);
    table->priv->signature_combo_box = g_object_ref_sink (widget);

    widget = gtk_label_new_with_mnemonic (_("Si_gnature:"));
    gtk_label_set_mnemonic_widget (
        GTK_LABEL (widget), table->priv->signature_combo_box);
    table->priv->signature_label = g_object_ref_sink (widget);
}

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

    if (G_UNLIKELY (type == 0)) {
        static const GTypeInfo type_info = {
            sizeof (EComposerHeaderTableClass),
            (GBaseInitFunc) NULL,
            (GBaseFinalizeFunc) NULL,
            (GClassInitFunc) composer_header_table_class_init,
            (GClassFinalizeFunc) NULL,
            NULL,  /* class_data */
            sizeof (EComposerHeaderTable),
            0,     /* n_preallocs */
            (GInstanceInitFunc) composer_header_table_init,
            NULL   /* value_table */
        };

        type = g_type_register_static (
            GTK_TYPE_TABLE, "EComposerHeaderTable", &type_info, 0);
    }

    return type;
}

GtkWidget *
e_composer_header_table_new (void)
{
    return g_object_new (E_TYPE_COMPOSER_HEADER_TABLE, NULL);
}

EComposerHeader *
e_composer_header_table_get_header (EComposerHeaderTable *table,
                                    EComposerHeaderType type)
{
    g_return_val_if_fail (E_IS_COMPOSER_HEADER_TABLE (table), NULL);
    g_return_val_if_fail (type < E_COMPOSER_NUM_HEADERS, NULL);
    g_return_val_if_fail (type >= 0, NULL);

    return table->priv->headers[type];
}

gboolean
e_composer_header_table_get_header_visible (EComposerHeaderTable *table,
                                            EComposerHeaderType type)
{
    EComposerHeader *header;

    header = e_composer_header_table_get_header (table, type);
    return e_composer_header_get_visible (header);
}

void
e_composer_header_table_set_header_visible (EComposerHeaderTable *table,
                                            EComposerHeaderType type,
                                            gboolean visible)
{
    EComposerHeader *header;

    header = e_composer_header_table_get_header (table, type);
    e_composer_header_set_visible (header, visible);

    /* Signature widgets track the "From" header. */
    if (type == E_COMPOSER_HEADER_FROM) {
        if (visible) {
            gtk_widget_show (table->priv->signature_label);
            gtk_widget_show (table->priv->signature_combo_box);
        } else {
            gtk_widget_hide (table->priv->signature_label);
            gtk_widget_hide (table->priv->signature_combo_box);
        }
    }
}

gboolean
e_composer_header_table_get_header_sensitive (EComposerHeaderTable *table,
                                              EComposerHeaderType type)
{
    EComposerHeader *header;

    header = e_composer_header_table_get_header (table, type);
    return e_composer_header_get_sensitive (header);
}

void
e_composer_header_table_set_header_sensitive (EComposerHeaderTable *table,
                                              EComposerHeaderType type,
                                              gboolean sensitive)
{
    EComposerHeader *header;

    header = e_composer_header_table_get_header (table, type);
    e_composer_header_set_sensitive (header, sensitive);
}

EAccount *
e_composer_header_table_get_account (EComposerHeaderTable *table)
{
    EComposerFromHeader *header;

    g_return_val_if_fail (E_IS_COMPOSER_HEADER_TABLE (table), NULL);

    header = E_COMPOSER_HEADER_TABLE_GET_FROM_HEADER (table);
    return e_composer_from_header_get_active (header);
}

gboolean
e_composer_header_table_set_account (EComposerHeaderTable *table,
                                     EAccount *account)
{
    EComposerFromHeader *header;

    g_return_val_if_fail (E_IS_COMPOSER_HEADER_TABLE (table), FALSE);

    header = E_COMPOSER_HEADER_TABLE_GET_FROM_HEADER (table);
    return e_composer_from_header_set_active (header, account);
}

EAccountList *
e_composer_header_table_get_account_list (EComposerHeaderTable *table)
{
    EComposerFromHeader *header;

    g_return_val_if_fail (E_IS_COMPOSER_HEADER_TABLE (table), NULL);

    header = E_COMPOSER_HEADER_TABLE_GET_FROM_HEADER (table);
    return e_composer_from_header_get_account_list (header);
}

void
e_composer_header_table_set_account_list (EComposerHeaderTable *table,
                                          EAccountList *account_list)
{
    EComposerFromHeader *header;

    g_return_if_fail (E_IS_COMPOSER_HEADER_TABLE (table));

    header = E_COMPOSER_HEADER_TABLE_GET_FROM_HEADER (table);
    e_composer_from_header_set_account_list (header, account_list);
}

const gchar *
e_composer_header_table_get_account_name (EComposerHeaderTable *table)
{
    EComposerFromHeader *header;

    g_return_val_if_fail (E_IS_COMPOSER_HEADER_TABLE (table), NULL);

    header = E_COMPOSER_HEADER_TABLE_GET_FROM_HEADER (table);
    return e_composer_from_header_get_active_name (header);
}

gboolean
e_composer_header_table_set_account_name (EComposerHeaderTable *table,
                                          const gchar *account_name)
{
    EComposerFromHeader *header;

    g_return_val_if_fail (E_IS_COMPOSER_HEADER_TABLE (table), FALSE);

    header = E_COMPOSER_HEADER_TABLE_GET_FROM_HEADER (table);
    return e_composer_from_header_set_active_name (header, account_name);
}

EDestination **
e_composer_header_table_get_destinations (EComposerHeaderTable *table)
{
    EDestination **destinations;
    EDestination **to, **cc, **bcc;
    gint total, n_to, n_cc, n_bcc;

    g_return_val_if_fail (E_IS_COMPOSER_HEADER_TABLE (table), NULL);

    to = e_composer_header_table_get_destinations_to (table);
    for (n_to = 0; to != NULL && to[n_to] != NULL; n_to++);

    cc = e_composer_header_table_get_destinations_cc (table);
    for (n_cc = 0; cc != NULL && cc[n_cc] != NULL; n_cc++);

    bcc = e_composer_header_table_get_destinations_bcc (table);
    for (n_bcc = 0; bcc != NULL && bcc[n_bcc] != NULL; n_bcc++);

    total = n_to + n_cc + n_bcc;
    destinations = g_new0 (EDestination *, total + 1);

    while (n_bcc > 0 && total > 0)
        destinations[--total] = g_object_ref (bcc[--n_bcc]);

    while (n_cc > 0 && total > 0)
        destinations[--total] = g_object_ref (cc[--n_cc]);

    while (n_to > 0 && total > 0)
        destinations[--total] = g_object_ref (to[--n_to]);

    /* Counters should all be zero now. */
    g_assert (total == 0 && n_to == 0 && n_cc == 0 && n_bcc == 0);

    e_destination_freev (to);
    e_destination_freev (cc);
    e_destination_freev (bcc);

    return destinations;
}

EDestination **
e_composer_header_table_get_destinations_bcc (EComposerHeaderTable *table)
{
    EComposerNameHeader *header;

    g_return_val_if_fail (E_IS_COMPOSER_HEADER_TABLE (table), NULL);

    header = E_COMPOSER_HEADER_TABLE_GET_BCC_HEADER (table);
    return e_composer_name_header_get_destinations (header);
}

void
e_composer_header_table_set_destinations_bcc (EComposerHeaderTable *table,
                                              EDestination **destinations)
{
    EComposerNameHeader *header;

    g_return_if_fail (E_IS_COMPOSER_HEADER_TABLE (table));

    header = E_COMPOSER_HEADER_TABLE_GET_BCC_HEADER (table);
    e_composer_name_header_set_destinations (header, destinations);

    if (destinations != NULL && *destinations != NULL)
        e_composer_header_table_set_header_visible (
            table, E_COMPOSER_HEADER_BCC, TRUE);
}

EDestination **
e_composer_header_table_get_destinations_cc (EComposerHeaderTable *table)
{
    EComposerNameHeader *header;

    g_return_val_if_fail (E_IS_COMPOSER_HEADER_TABLE (table), NULL);

    header = E_COMPOSER_HEADER_TABLE_GET_CC_HEADER (table);
    return e_composer_name_header_get_destinations (header);
}

void
e_composer_header_table_set_destinations_cc (EComposerHeaderTable *table,
                                             EDestination **destinations)
{
    EComposerNameHeader *header;

    g_return_if_fail (E_IS_COMPOSER_HEADER_TABLE (table));

    header = E_COMPOSER_HEADER_TABLE_GET_CC_HEADER (table);
    e_composer_name_header_set_destinations (header, destinations);

    if (destinations != NULL && *destinations != NULL)
        e_composer_header_table_set_header_visible (
            table, E_COMPOSER_HEADER_CC, TRUE);
}

EDestination **
e_composer_header_table_get_destinations_to (EComposerHeaderTable *table)
{
    EComposerNameHeader *header;

    g_return_val_if_fail (E_IS_COMPOSER_HEADER_TABLE (table), NULL);

    header = E_COMPOSER_HEADER_TABLE_GET_TO_HEADER (table);
    return e_composer_name_header_get_destinations (header);
}

void
e_composer_header_table_set_destinations_to (EComposerHeaderTable *table,
                                             EDestination **destinations)
{
    EComposerNameHeader *header;

    g_return_if_fail (E_IS_COMPOSER_HEADER_TABLE (table));

    header = E_COMPOSER_HEADER_TABLE_GET_TO_HEADER (table);
    e_composer_name_header_set_destinations (header, destinations);
}

EMFolderTreeModel *
e_composer_header_table_get_folder_tree_model (EComposerHeaderTable *table)
{
    EComposerPostHeader *header;

    g_return_val_if_fail (E_IS_COMPOSER_HEADER_TABLE (table), NULL);

    header = E_COMPOSER_HEADER_TABLE_GET_POST_TO_HEADER (table);
    return e_composer_post_header_get_folder_tree_model (header);
}

void
e_composer_header_table_set_folder_tree_model (EComposerHeaderTable *table,
                                               EMFolderTreeModel *model)
{
    EComposerPostHeader *header;

    g_return_if_fail (E_IS_COMPOSER_HEADER_TABLE (table));

    header = E_COMPOSER_HEADER_TABLE_GET_POST_TO_HEADER (table);
    e_composer_post_header_set_folder_tree_model (header, model);
}

GList *
e_composer_header_table_get_post_to (EComposerHeaderTable *table)
{
    EComposerPostHeader *header;

    g_return_val_if_fail (E_IS_COMPOSER_HEADER_TABLE (table), NULL);

    header = E_COMPOSER_HEADER_TABLE_GET_POST_TO_HEADER (table);
    return e_composer_post_header_get_folders (header);
}

void
e_composer_header_table_set_post_to_base (EComposerHeaderTable *table,
                                          const gchar *base_url,
                                          const gchar *folders)
{
    EComposerPostHeader *header;

    g_return_if_fail (E_IS_COMPOSER_HEADER_TABLE (table));

    header = E_COMPOSER_HEADER_TABLE_GET_POST_TO_HEADER (table);
    e_composer_post_header_set_folders_base (header, base_url, folders);
}

void
e_composer_header_table_set_post_to_list (EComposerHeaderTable *table,
                                          GList *folders)
{
    EComposerPostHeader *header;

    g_return_if_fail (E_IS_COMPOSER_HEADER_TABLE (table));

    header = E_COMPOSER_HEADER_TABLE_GET_POST_TO_HEADER (table);
    e_composer_post_header_set_folders (header, folders);
}

const gchar *
e_composer_header_table_get_reply_to (EComposerHeaderTable *table)
{
    EComposerTextHeader *header;

    g_return_val_if_fail (E_IS_COMPOSER_HEADER_TABLE (table), NULL);

    header = E_COMPOSER_HEADER_TABLE_GET_REPLY_TO_HEADER (table);
    return e_composer_text_header_get_text (header);
}

void
e_composer_header_table_set_reply_to (EComposerHeaderTable *table,
                                      const gchar *reply_to)
{
    EComposerTextHeader *header;

    g_return_if_fail (E_IS_COMPOSER_HEADER_TABLE (table));

    header = E_COMPOSER_HEADER_TABLE_GET_REPLY_TO_HEADER (table);
    e_composer_text_header_set_text (header, reply_to);

    if (reply_to != NULL && *reply_to != '\0')
        e_composer_header_table_set_header_visible (
            table, E_COMPOSER_HEADER_REPLY_TO, TRUE);
}

ESignature *
e_composer_header_table_get_signature (EComposerHeaderTable *table)
{
    ESignatureComboBox *combo_box;

    g_return_val_if_fail (E_IS_COMPOSER_HEADER_TABLE (table), NULL);

    combo_box = E_SIGNATURE_COMBO_BOX (table->priv->signature_combo_box);
    return e_signature_combo_box_get_active (combo_box);
}

gboolean
e_composer_header_table_set_signature (EComposerHeaderTable *table,
                                       ESignature *signature)
{
    ESignatureComboBox *combo_box;

    g_return_val_if_fail (E_IS_COMPOSER_HEADER_TABLE (table), FALSE);

    combo_box = E_SIGNATURE_COMBO_BOX (table->priv->signature_combo_box);
    return e_signature_combo_box_set_active (combo_box, signature);
}

ESignatureList *
e_composer_header_table_get_signature_list (EComposerHeaderTable *table)
{
    ESignatureComboBox *combo_box;

    g_return_val_if_fail (E_IS_COMPOSER_HEADER_TABLE (table), NULL);

    combo_box = E_SIGNATURE_COMBO_BOX (table->priv->signature_combo_box);
    return e_signature_combo_box_get_signature_list (combo_box);
}

void
e_composer_header_table_set_signature_list (EComposerHeaderTable *table,
                                            ESignatureList *signature_list)
{
    ESignatureComboBox *combo_box;

    g_return_if_fail (E_IS_COMPOSER_HEADER_TABLE (table));

    combo_box = E_SIGNATURE_COMBO_BOX (table->priv->signature_combo_box);
    e_signature_combo_box_set_signature_list (combo_box, signature_list);
}

const gchar *
e_composer_header_table_get_subject (EComposerHeaderTable *table)
{
    EComposerTextHeader *header;

    g_return_val_if_fail (E_IS_COMPOSER_HEADER_TABLE (table), NULL);

    header = E_COMPOSER_HEADER_TABLE_GET_SUBJECT_HEADER (table);
    return e_composer_text_header_get_text (header);
}

void
e_composer_header_table_set_subject (EComposerHeaderTable *table,
                                     const gchar *subject)
{
    EComposerTextHeader *header;

    g_return_if_fail (E_IS_COMPOSER_HEADER_TABLE (table));

    header = E_COMPOSER_HEADER_TABLE_GET_SUBJECT_HEADER (table);
    e_composer_text_header_set_text (header, subject);
}