Commit f78795f4 authored by Matthew Barnes's avatar Matthew Barnes

Adapt composer to the new ESource API.

parent 68c35c4b
......@@ -24,16 +24,7 @@
#include "e-composer-from-header.h"
/* Convenience macro */
#define E_COMPOSER_FROM_HEADER_GET_COMBO_BOX(header) \
(E_ACCOUNT_COMBO_BOX (E_COMPOSER_HEADER (header)->input_widget))
enum {
REFRESHED,
LAST_SIGNAL
};
static guint signal_ids[LAST_SIGNAL];
#include <misc/e-mail-identity-combo-box.h>
G_DEFINE_TYPE (
EComposerFromHeader,
......@@ -41,119 +32,82 @@ G_DEFINE_TYPE (
E_TYPE_COMPOSER_HEADER)
static void
composer_from_header_changed_cb (EAccountComboBox *combo_box,
composer_from_header_changed_cb (EMailIdentityComboBox *combo_box,
EComposerFromHeader *header)
{
g_signal_emit_by_name (header, "changed");
}
static void
composer_from_header_refreshed_cb (EAccountComboBox *combo_box,
EComposerFromHeader *header)
composer_from_header_constructed (GObject *object)
{
g_signal_emit (header, signal_ids[REFRESHED], 0);
}
ESourceRegistry *registry;
EComposerHeader *header;
GtkWidget *widget;
static void
e_composer_from_header_class_init (EComposerFromHeaderClass *class)
{
signal_ids[REFRESHED] = g_signal_new (
"refreshed",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
}
header = E_COMPOSER_HEADER (object);
registry = e_composer_header_get_registry (header);
static void
e_composer_from_header_init (EComposerFromHeader *header)
{
GtkWidget *widget;
/* Input widget must be set before chaining up. */
widget = g_object_ref_sink (e_account_combo_box_new ());
widget = e_mail_identity_combo_box_new (registry);
g_signal_connect (
widget, "changed",
G_CALLBACK (composer_from_header_changed_cb), header);
g_signal_connect (
widget, "refreshed",
G_CALLBACK (composer_from_header_refreshed_cb), header);
E_COMPOSER_HEADER (header)->input_widget = widget;
}
EComposerHeader *
e_composer_from_header_new (const gchar *label)
{
return g_object_new (
E_TYPE_COMPOSER_FROM_HEADER, "label", label,
"button", FALSE, NULL);
}
EAccountList *
e_composer_from_header_get_account_list (EComposerFromHeader *header)
{
EAccountComboBox *combo_box;
g_return_val_if_fail (E_IS_COMPOSER_FROM_HEADER (header), NULL);
header->input_widget = g_object_ref_sink (widget);
combo_box = E_COMPOSER_FROM_HEADER_GET_COMBO_BOX (header);
return e_account_combo_box_get_account_list (combo_box);
/* Chain up to parent's constructed() method. */
G_OBJECT_CLASS (e_composer_from_header_parent_class)->
constructed (object);
}
void
e_composer_from_header_set_account_list (EComposerFromHeader *header,
EAccountList *account_list)
static void
e_composer_from_header_class_init (EComposerFromHeaderClass *class)
{
EAccountComboBox *combo_box;
g_return_if_fail (E_IS_COMPOSER_FROM_HEADER (header));
GObjectClass *object_class;
combo_box = E_COMPOSER_FROM_HEADER_GET_COMBO_BOX (header);
e_account_combo_box_set_account_list (combo_box, account_list);
object_class = G_OBJECT_CLASS (class);
object_class->constructed = composer_from_header_constructed;
}
EAccount *
e_composer_from_header_get_active (EComposerFromHeader *header)
static void
e_composer_from_header_init (EComposerFromHeader *from_header)
{
EAccountComboBox *combo_box;
g_return_val_if_fail (E_IS_COMPOSER_FROM_HEADER (header), NULL);
combo_box = E_COMPOSER_FROM_HEADER_GET_COMBO_BOX (header);
return e_account_combo_box_get_active (combo_box);
}
gboolean
e_composer_from_header_set_active (EComposerFromHeader *header,
EAccount *account)
EComposerHeader *
e_composer_from_header_new (ESourceRegistry *registry,
const gchar *label)
{
EAccountComboBox *combo_box;
g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
g_return_val_if_fail (E_IS_COMPOSER_FROM_HEADER (header), FALSE);
combo_box = E_COMPOSER_FROM_HEADER_GET_COMBO_BOX (header);
return e_account_combo_box_set_active (combo_box, account);
return g_object_new (
E_TYPE_COMPOSER_FROM_HEADER,
"label", label, "button", FALSE,
"registry", registry, NULL);
}
const gchar *
e_composer_from_header_get_active_name (EComposerFromHeader *header)
e_composer_from_header_get_active_id (EComposerFromHeader *header)
{
EAccountComboBox *combo_box;
GtkComboBox *combo_box;
g_return_val_if_fail (E_IS_COMPOSER_FROM_HEADER (header), NULL);
combo_box = E_COMPOSER_FROM_HEADER_GET_COMBO_BOX (header);
return e_account_combo_box_get_active_name (combo_box);
combo_box = GTK_COMBO_BOX (E_COMPOSER_HEADER (header)->input_widget);
return gtk_combo_box_get_active_id (combo_box);
}
gboolean
e_composer_from_header_set_active_name (EComposerFromHeader *header,
const gchar *account_name)
void
e_composer_from_header_set_active_id (EComposerFromHeader *header,
const gchar *active_id)
{
EAccountComboBox *combo_box;
GtkComboBox *combo_box;
g_return_if_fail (E_IS_COMPOSER_FROM_HEADER (header));
g_return_val_if_fail (E_IS_COMPOSER_FROM_HEADER (header), FALSE);
combo_box = GTK_COMBO_BOX (E_COMPOSER_HEADER (header)->input_widget);
combo_box = E_COMPOSER_FROM_HEADER_GET_COMBO_BOX (header);
return e_account_combo_box_set_active_name (combo_box, account_name);
gtk_combo_box_set_active_id (combo_box, active_id);
}
......@@ -21,10 +21,6 @@
#ifndef E_COMPOSER_FROM_HEADER_H
#define E_COMPOSER_FROM_HEADER_H
#include <libedataserver/e-account.h>
#include <libedataserver/e-account-list.h>
#include <misc/e-account-combo-box.h>
#include <composer/e-composer-header.h>
/* Standard GObject macros */
......@@ -60,22 +56,14 @@ struct _EComposerFromHeaderClass {
};
GType e_composer_from_header_get_type (void);
EComposerHeader * e_composer_from_header_new (const gchar *label);
EAccountList * e_composer_from_header_get_account_list
(EComposerFromHeader *header);
void e_composer_from_header_set_account_list
(EComposerFromHeader *header,
EAccountList *account_list);
EAccount * e_composer_from_header_get_active
(EComposerFromHeader *header);
gboolean e_composer_from_header_set_active
(EComposerFromHeader *header,
EAccount *account);
const gchar * e_composer_from_header_get_active_name
EComposerHeader *
e_composer_from_header_new (ESourceRegistry *registry,
const gchar *label);
const gchar * e_composer_from_header_get_active_id
(EComposerFromHeader *header);
gboolean e_composer_from_header_set_active_name
void e_composer_from_header_set_active_id
(EComposerFromHeader *header,
const gchar *account_name);
const gchar *active_id);
G_END_DECLS
......
This diff is collapsed.
......@@ -18,14 +18,11 @@
#ifndef E_COMPOSER_HEADER_TABLE_H
#define E_COMPOSER_HEADER_TABLE_H
#include <libedataserver/e-account.h>
#include <libedataserver/e-account-list.h>
#include <libebook/e-destination.h>
#include <shell/e-shell.h>
#include <composer/e-composer-header.h>
#include <libemail-utils/e-signature.h>
#include <libemail-utils/e-signature-list.h>
#include <misc/e-mail-signature-combo-box.h>
/* Standard GObject macros */
#define E_TYPE_COMPOSER_HEADER_TABLE \
......@@ -74,28 +71,20 @@ struct _EComposerHeaderTableClass {
};
GType e_composer_header_table_get_type (void);
GtkWidget * e_composer_header_table_new (EShell *shell);
GtkWidget * e_composer_header_table_new (EShell *shell,
ESourceRegistry *registry);
EShell * e_composer_header_table_get_shell
(EComposerHeaderTable *table);
ESourceRegistry *
e_composer_header_table_get_registry
(EComposerHeaderTable *table);
EComposerHeader *
e_composer_header_table_get_header
(EComposerHeaderTable *table,
EComposerHeaderType type);
EAccount * e_composer_header_table_get_account
(EComposerHeaderTable *table);
gboolean e_composer_header_table_set_account
(EComposerHeaderTable *table,
EAccount *account);
EAccountList * e_composer_header_table_get_account_list
(EComposerHeaderTable *table);
void e_composer_header_table_set_account_list
(EComposerHeaderTable *table,
EAccountList *account_list);
const gchar * e_composer_header_table_get_account_name
EMailSignatureComboBox *
e_composer_header_table_get_signature_combo_box
(EComposerHeaderTable *table);
gboolean e_composer_header_table_set_account_name
(EComposerHeaderTable *table,
const gchar *account_name);
EDestination ** e_composer_header_table_get_destinations
(EComposerHeaderTable *table);
EDestination ** e_composer_header_table_get_destinations_bcc
......@@ -122,6 +111,11 @@ void e_composer_header_table_add_destinations_to
void e_composer_header_table_set_destinations_to
(EComposerHeaderTable *table,
EDestination **destinations);
const gchar * e_composer_header_table_get_identity_uid
(EComposerHeaderTable *table);
void e_composer_header_table_set_identity_uid
(EComposerHeaderTable *table,
const gchar *identity_uid);
GList * e_composer_header_table_get_post_to
(EComposerHeaderTable *table);
void e_composer_header_table_set_post_to_base
......@@ -136,16 +130,11 @@ const gchar * e_composer_header_table_get_reply_to
void e_composer_header_table_set_reply_to
(EComposerHeaderTable *table,
const gchar *reply_to);
ESignature * e_composer_header_table_get_signature
(EComposerHeaderTable *table);
gboolean e_composer_header_table_set_signature
(EComposerHeaderTable *table,
ESignature *signature);
ESignatureList *e_composer_header_table_get_signature_list
const gchar * e_composer_header_table_get_signature_uid
(EComposerHeaderTable *table);
void e_composer_header_table_set_signature_list
void e_composer_header_table_set_signature_uid
(EComposerHeaderTable *table,
ESignatureList *signature_list);
const gchar *signature_uid);
const gchar * e_composer_header_table_get_subject
(EComposerHeaderTable *table);
void e_composer_header_table_set_subject
......
......@@ -36,12 +36,8 @@
struct _EComposerHeaderPrivate {
gchar *label;
gboolean button;
GtkWidget *action_label;
GtkWidget *add_icon;
GtkWidget *remove_icon;
GtkWidget *show_label;
GtkWidget *hide_label;
ESourceRegistry *registry;
guint sensitive : 1;
guint visible : 1;
......@@ -55,6 +51,7 @@ enum {
PROP_0,
PROP_BUTTON,
PROP_LABEL,
PROP_REGISTRY,
PROP_SENSITIVE,
PROP_VISIBLE
};
......@@ -80,48 +77,14 @@ composer_header_button_clicked_cb (GtkButton *button,
g_signal_emit (header, signal_ids[CLICKED], 0);
}
static GObject *
composer_header_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_properties)
static void
composer_header_set_registry (EComposerHeader *header,
ESourceRegistry *registry)
{
GObject *object;
GtkWidget *widget;
EComposerHeader *header;
GtkWidget *label;
/* Chain up to parent's constructor() method. */
object = G_OBJECT_CLASS (
e_composer_header_parent_class)->constructor (
type, n_construct_properties, construct_properties);
header = E_COMPOSER_HEADER (object);
if (header->priv->button) {
widget = gtk_button_new_with_mnemonic (header->priv->label);
gtk_widget_set_can_focus (widget, FALSE);
g_signal_connect (
widget, "clicked",
G_CALLBACK (composer_header_button_clicked_cb),
header);
label = gtk_bin_get_child (GTK_BIN (widget));
} else {
widget = gtk_label_new_with_mnemonic (header->priv->label);
gtk_label_set_mnemonic_widget (
GTK_LABEL (widget), header->input_widget);
label = widget;
}
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
header->priv->action_label = NULL;
header->title_widget = g_object_ref_sink (widget);
g_free (header->priv->label);
header->priv->label = NULL;
g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
g_return_if_fail (header->priv->registry == NULL);
return object;
header->priv->registry = g_object_ref (registry);
}
static void
......@@ -143,6 +106,12 @@ composer_header_set_property (GObject *object,
priv->label = g_value_dup_string (value);
return;
case PROP_REGISTRY:
composer_header_set_registry (
E_COMPOSER_HEADER (object),
g_value_get_object (value));
return;
case PROP_SENSITIVE:
e_composer_header_set_sensitive (
E_COMPOSER_HEADER (object),
......@@ -175,8 +144,12 @@ composer_header_get_property (GObject *object,
return;
case PROP_LABEL: /* construct only */
g_value_take_string (
value, e_composer_header_get_label (
g_value_set_string (value, priv->label);
return;
case PROP_REGISTRY:
g_value_set_object (
value, e_composer_header_get_registry (
E_COMPOSER_HEADER (object)));
return;
......@@ -211,10 +184,74 @@ composer_header_dispose (GObject *object)
header->input_widget = NULL;
}
if (header->priv->registry != NULL) {
g_object_unref (header->priv->registry);
header->priv->registry = NULL;
}
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (e_composer_header_parent_class)->dispose (object);
}
static void
composer_header_finalize (GObject *object)
{
EComposerHeaderPrivate *priv;
priv = E_COMPOSER_HEADER_GET_PRIVATE (object);
g_free (priv->label);
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (e_composer_header_parent_class)->finalize (object);
}
static void
composer_header_constructed (GObject *object)
{
EComposerHeader *header;
GtkWidget *widget;
GtkWidget *label;
header = E_COMPOSER_HEADER (object);
if (header->input_widget == NULL) {
g_critical (
"EComposerHeader's input_widget "
"must be set before chaining up");
return;
}
if (header->priv->button) {
widget = gtk_button_new_with_mnemonic (header->priv->label);
gtk_widget_set_can_focus (widget, FALSE);
g_signal_connect (
widget, "clicked",
G_CALLBACK (composer_header_button_clicked_cb),
header);
label = gtk_bin_get_child (GTK_BIN (widget));
} else {
widget = gtk_label_new_with_mnemonic (header->priv->label);
gtk_label_set_mnemonic_widget (
GTK_LABEL (widget), header->input_widget);
label = widget;
}
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
header->title_widget = g_object_ref_sink (widget);
g_object_bind_property (
header, "visible",
header->title_widget, "visible",
G_BINDING_SYNC_CREATE);
g_object_bind_property (
header, "visible",
header->input_widget, "visible",
G_BINDING_SYNC_CREATE);
}
static void
e_composer_header_class_init (EComposerHeaderClass *class)
{
......@@ -223,10 +260,11 @@ e_composer_header_class_init (EComposerHeaderClass *class)
g_type_class_add_private (class, sizeof (EComposerHeaderPrivate));
object_class = G_OBJECT_CLASS (class);
object_class->constructor = composer_header_constructor;
object_class->set_property = composer_header_set_property;
object_class->get_property = composer_header_get_property;
object_class->dispose = composer_header_dispose;
object_class->finalize = composer_header_finalize;
object_class->constructed = composer_header_constructed;
g_object_class_install_property (
object_class,
......@@ -252,6 +290,18 @@ e_composer_header_class_init (EComposerHeaderClass *class)
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (
object_class,
PROP_REGISTRY,
g_param_spec_object (
"registry",
NULL,
NULL,
E_TYPE_SOURCE_REGISTRY,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (
object_class,
PROP_SENSITIVE,
......@@ -299,17 +349,20 @@ e_composer_header_init (EComposerHeader *header)
header->priv = E_COMPOSER_HEADER_GET_PRIVATE (header);
}
gchar *
const gchar *
e_composer_header_get_label (EComposerHeader *header)
{
gchar *label;
g_return_val_if_fail (E_IS_COMPOSER_HEADER (header), NULL);
/* GtkButton and GtkLabel both have a "label" property. */
g_object_get (header->title_widget, "label", &label, NULL);
return header->priv->label;
}
return label;
ESourceRegistry *
e_composer_header_get_registry (EComposerHeader *header)
{
g_return_val_if_fail (E_IS_COMPOSER_HEADER (header), NULL);
return header->priv->registry;
}
gboolean
......@@ -347,20 +400,6 @@ e_composer_header_set_visible (EComposerHeader *header,
header->priv->visible = visible;
if (header->priv->action_label) {
if (!visible) {
gtk_widget_show (header->priv->add_icon);
gtk_widget_show (header->priv->show_label);
gtk_widget_hide (header->priv->remove_icon);
gtk_widget_hide (header->priv->hide_label);
} else {
gtk_widget_hide (header->priv->add_icon);
gtk_widget_hide (header->priv->show_label);
gtk_widget_show (header->priv->remove_icon);
gtk_widget_show (header->priv->hide_label);
}
}
g_object_notify (G_OBJECT (header), "visible");
}
......
......@@ -19,6 +19,7 @@
#define E_COMPOSER_HEADER_H
#include <composer/e-composer-common.h>
#include <libedataserver/e-source-registry.h>
/* Standard GObject macros */
#define E_TYPE_COMPOSER_HEADER \
......@@ -61,7 +62,9 @@ struct _EComposerHeaderClass {
};
GType e_composer_header_get_type (void);
gchar * e_composer_header_get_label (EComposerHeader *header);
const gchar * e_composer_header_get_label (EComposerHeader *header);
ESourceRegistry *
e_composer_header_get_registry (EComposerHeader *header);
gboolean e_composer_header_get_sensitive (EComposerHeader *header);
void e_composer_header_set_sensitive (EComposerHeader *header,
gboolean sensitive);
......
......@@ -110,63 +110,6 @@ composer_name_header_entry_query_tooltip_cb (GtkEntry *entry,
return TRUE;
}
static GObject *
composer_name_header_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_properties)
{
EComposerNameHeaderPrivate *priv;
ENameSelectorModel *model;
ENameSelectorEntry *entry;
GObject *object;
GList *sections;
gchar *label;
/* Chain up to parent's constructor() method. */
object = G_OBJECT_CLASS (
e_composer_name_header_parent_class)->constructor (
type, n_construct_properties, construct_properties);
priv = E_COMPOSER_NAME_HEADER_GET_PRIVATE (object);
g_assert (E_IS_NAME_SELECTOR (priv->name_selector));
model = e_name_selector_peek_model (priv->name_selector);
label = e_composer_header_get_label (E_COMPOSER_HEADER (object));
g_assert (label != NULL);
sections = e_name_selector_model_list_sections (model);
priv->destination_index = g_list_length (sections);
e_name_selector_model_add_section (model, label, label, NULL);
g_list_foreach (sections, (GFunc) g_free, NULL);
g_list_free (sections);
e_composer_header_set_title_tooltip (
E_COMPOSER_HEADER (object),
_("Click here for the address book"));
entry = E_NAME_SELECTOR_ENTRY (
e_name_selector_peek_section_list (
priv->name_selector, label));
e_name_selector_entry_set_contact_editor_func (
entry, contact_editor_fudge_new);
e_name_selector_entry_set_contact_list_editor_func (
entry, contact_list_editor_fudge_new);
g_signal_connect (
entry, "changed",
G_CALLBACK (composer_name_header_entry_changed_cb), object);
g_signal_connect (
entry, "query-tooltip",
G_CALLBACK (composer_name_header_entry_query_tooltip_cb),
NULL);
E_COMPOSER_HEADER (object)->input_widget = g_object_ref_sink (entry);
g_free (label);
return object;
}
static void
composer_name_header_set_property (GObject *object,
guint property_id,
......@@ -221,6 +164,57 @@ composer_name_header_dispose (GObject *object)
G_OBJECT_CLASS (e_composer_name_header_parent_class)->dispose (object);
}