diff options
author | Jeffrey Stedfast <fejj@helixcode.com> | 2001-01-13 05:13:26 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2001-01-13 05:13:26 +0800 |
commit | 8ad2b343a02b954f2393e08deece19861352329e (patch) | |
tree | 4eb49b0956aeda5cbec9ef6ee51967202f5f52b3 /composer | |
parent | d9a01d4e270df5a5332808b4c2e34f688f65d10b (diff) | |
download | gsoc2013-evolution-8ad2b343a02b954f2393e08deece19861352329e.tar gsoc2013-evolution-8ad2b343a02b954f2393e08deece19861352329e.tar.gz gsoc2013-evolution-8ad2b343a02b954f2393e08deece19861352329e.tar.bz2 gsoc2013-evolution-8ad2b343a02b954f2393e08deece19861352329e.tar.lz gsoc2013-evolution-8ad2b343a02b954f2393e08deece19861352329e.tar.xz gsoc2013-evolution-8ad2b343a02b954f2393e08deece19861352329e.tar.zst gsoc2013-evolution-8ad2b343a02b954f2393e08deece19861352329e.zip |
Call set_from_account which means we no longer have to do all the crap
2001-01-12 Jeffrey Stedfast <fejj@helixcode.com>
* e-msg-composer.c (build_message): Call set_from_account which
means we no longer have to do all the crap involved in formatting
strings into an internet-address.
(e_msg_composer_get_preferred_account): New access function.
* e-msg-composer-hdrs.c (add_header): case COMBOBOX has changed to
OPTIOMENU.
(create_optionmenu): Update to use an optionmenu of accounts.
(from_changed): New callback for the From optionmenu.
(setup_headers): s/COMBOBOX/OPTIONMENU
(init): Set the account and from_options to NULL.
(e_msg_composer_hdrs_get_from): Updated.
(destroy): free the from_options.
(e_msg_composer_hdrs_set_from_address): Renamed from set_from
because it no longer takes a string arg but rather an account arg.
svn path=/trunk/; revision=7458
Diffstat (limited to 'composer')
-rw-r--r-- | composer/ChangeLog | 18 | ||||
-rw-r--r-- | composer/e-msg-composer-hdrs.c | 171 | ||||
-rw-r--r-- | composer/e-msg-composer-hdrs.h | 7 | ||||
-rw-r--r-- | composer/e-msg-composer.c | 36 | ||||
-rw-r--r-- | composer/e-msg-composer.h | 5 |
5 files changed, 168 insertions, 69 deletions
diff --git a/composer/ChangeLog b/composer/ChangeLog index 68208b057f..581003eba3 100644 --- a/composer/ChangeLog +++ b/composer/ChangeLog @@ -1,3 +1,21 @@ +2001-01-12 Jeffrey Stedfast <fejj@helixcode.com> + + * e-msg-composer.c (build_message): Call set_from_account which + means we no longer have to do all the crap involved in formatting + strings into an internet-address. + (e_msg_composer_get_preferred_account): New access function. + + * e-msg-composer-hdrs.c (add_header): case COMBOBOX has changed to + OPTIOMENU. + (create_optionmenu): Update to use an optionmenu of accounts. + (from_changed): New callback for the From optionmenu. + (setup_headers): s/COMBOBOX/OPTIONMENU + (init): Set the account and from_options to NULL. + (e_msg_composer_hdrs_get_from): Updated. + (destroy): free the from_options. + (e_msg_composer_hdrs_set_from_address): Renamed from set_from + because it no longer takes a string arg but rather an account arg. + 2001-01-12 Miguel de Icaza <miguel@ximian.com> * e-msg-composer-hdrs.c (add_header): Only attach to "changed" if diff --git a/composer/e-msg-composer-hdrs.c b/composer/e-msg-composer-hdrs.c index bb1bbe1fec..b59b5b8d2b 100644 --- a/composer/e-msg-composer-hdrs.c +++ b/composer/e-msg-composer-hdrs.c @@ -51,7 +51,9 @@ struct _EMsgComposerHdrsPrivate { /* The tooltips. */ GtkTooltips *tooltips; - + + GSList *from_options; + /* Standard headers. */ GtkWidget *from_entry; GtkWidget *to_entry; @@ -70,7 +72,7 @@ enum { enum { HEADER_ADDRBOOK, - HEADER_COMBOBOX, + HEADER_OPTIONMENU, HEADER_ENTRYBOX }; @@ -124,63 +126,67 @@ address_button_clicked_cb (GtkButton *button, CORBA_exception_free (&ev); } +static void +from_changed (GtkWidget *item, gpointer data) +{ + EMsgComposerHdrs *hdrs = E_MSG_COMPOSER_HDRS (data); + + hdrs->account = gtk_object_get_data (GTK_OBJECT (item), "account"); +} + static GtkWidget * -create_dropdown_entry (EMsgComposerHdrs *hdrs, - const char *name) +create_optionmenu (EMsgComposerHdrs *hdrs, + const char *name) { - GtkWidget *combo; - GList *values = NULL; + GtkWidget *omenu, *menu, *first = NULL; + int i = 0, history = 0; + + omenu = gtk_option_menu_new (); + menu = gtk_menu_new (); - combo = gtk_combo_new (); - gtk_combo_set_use_arrows (GTK_COMBO (combo), TRUE); - gtk_combo_set_case_sensitive (GTK_COMBO (combo), FALSE); if (!strcmp (name, _("From:"))) { - const MailConfigIdentity *id; - const GSList *accounts, *stmp; - GList *tmp; - char *val; + const GSList *accounts; + GtkWidget *item; accounts = mail_config_get_accounts (); - stmp = accounts; - while (stmp) { + while (accounts) { const MailConfigAccount *account; - char *address, *addr_local; - account = stmp->data; - g_assert (account); - g_assert (account->id); - g_assert (account->id->name); - g_assert (account->id->address); + account = accounts->data; - address = camel_internet_address_format_address (account->id->name, account->id->address); - addr_local = e_utf8_to_gtk_string (combo, address); - g_free (address); - values = g_list_append (values, addr_local); - stmp = stmp->next; - } - - if (values) - gtk_combo_set_popdown_strings (GTK_COMBO (combo), values); - - tmp = values; - while (tmp) { - g_free (tmp->data); - tmp = tmp->next; + /* this should never ever fail */ + if (!account || !account->name || !account->id) { + g_assert_not_reached (); + continue; + } + + item = gtk_menu_item_new_with_label (account->name); + gtk_object_set_data (GTK_OBJECT (item), "account", account_copy (account)); + gtk_signal_connect (GTK_OBJECT (item), "activate", + GTK_SIGNAL_FUNC (from_changed), hdrs); + + if (account->default_account) { + first = item; + history = i; + } + + /* this is so we can later set which one we want */ + hdrs->priv->from_options = g_slist_append (hdrs->priv->from_options, item); + + gtk_widget_show (item); + + accounts = accounts->next; + i++; } - g_list_free (values); - - id = mail_config_get_default_identity (); - g_assert (id); - g_assert (id->name); - g_assert (id->address); - - val = camel_internet_address_format_address (id->name, id->address); - - e_utf8_gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (combo)->entry), val); - g_free (val); } - return combo; + gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu); + if (first) { + gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), history); + gtk_signal_emit_by_name (GTK_OBJECT (first), "activate", hdrs); + } + + return omenu; } static GtkWidget * @@ -264,8 +270,8 @@ add_header (EMsgComposerHdrs *hdrs, case HEADER_ADDRBOOK: entry = create_addressbook_entry (hdrs, name); break; - case HEADER_COMBOBOX: - entry = create_dropdown_entry (hdrs, name); + case HEADER_OPTIONMENU: + entry = create_optionmenu (hdrs, name); break; default: entry = e_entry_new (); @@ -305,7 +311,7 @@ setup_headers (EMsgComposerHdrs *hdrs) (hdrs, _("From:"), _("Enter the identity you wish to send this message from"), NULL, - HEADER_COMBOBOX); + HEADER_OPTIONMENU); priv->to_entry = add_header (hdrs, _("To:"), _("Enter the recipients of the message"), @@ -339,6 +345,7 @@ destroy (GtkObject *object) { EMsgComposerHdrs *hdrs; EMsgComposerHdrsPrivate *priv; + GSList *l; hdrs = E_MSG_COMPOSER_HDRS (object); priv = hdrs->priv; @@ -352,7 +359,19 @@ destroy (GtkObject *object) } gtk_object_destroy (GTK_OBJECT (priv->tooltips)); - + + l = priv->from_options; + while (l) { + MailConfigAccount *account; + GtkWidget *item = l->data; + + account = gtk_object_get_data (GTK_OBJECT (item), "account"); + account_destroy (account); + + l = l->next; + } + g_slist_free (priv->from_options); + if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); } @@ -388,19 +407,23 @@ init (EMsgComposerHdrs *hdrs) priv = g_new (EMsgComposerHdrsPrivate, 1); priv->corba_select_names = CORBA_OBJECT_NIL; - + + priv->from_options = NULL; + priv->from_entry = NULL; priv->to_entry = NULL; priv->cc_entry = NULL; priv->bcc_entry = NULL; priv->subject_entry = NULL; - + priv->tooltips = gtk_tooltips_new (); priv->num_hdrs = 0; hdrs->priv = priv; + hdrs->account = NULL; + hdrs->has_changed = FALSE; } @@ -522,17 +545,38 @@ set_entry (BonoboWidget *bonobo_widget, g_string_free (string, TRUE); } + +/* FIXME: yea, this could be better... but it's doubtful it'll be used much */ void -e_msg_composer_hdrs_set_from (EMsgComposerHdrs *hdrs, - const char *from) +e_msg_composer_hdrs_set_from_account (EMsgComposerHdrs *hdrs, + const char *account_name) { - GtkEntry *entry; + GtkOptionMenu *omenu; + GtkWidget *item; + GSList *l; + int i = 0; g_return_if_fail (hdrs != NULL); g_return_if_fail (E_IS_MSG_COMPOSER_HDRS (hdrs)); - entry = GTK_ENTRY (GTK_COMBO (hdrs->priv->from_entry)->entry); - e_utf8_gtk_entry_set_text (entry, from); + omenu = GTK_OPTION_MENU (hdrs->priv->from_entry); + + /* find the item that represents the account and activate it */ + l = hdrs->priv->from_options; + while (l) { + MailConfigAccount *account; + item = l->data; + + account = gtk_object_get_data (GTK_OBJECT (item), "account"); + if (!strcmp (account_name, account->name)) { + gtk_option_menu_set_history (omenu, i); + gtk_signal_emit_by_name (GTK_OBJECT (item), "activate", hdrs); + return; + } + + l = l->next; + i++; + } } void @@ -578,14 +622,23 @@ e_msg_composer_hdrs_set_subject (EMsgComposerHdrs *hdrs, NULL); } + /* FIXME: This should probably return a CamelInternetAddress */ char * e_msg_composer_hdrs_get_from (EMsgComposerHdrs *hdrs) { + const MailConfigAccount *account; + g_return_val_if_fail (hdrs != NULL, NULL); g_return_val_if_fail (E_IS_MSG_COMPOSER_HDRS (hdrs), NULL); - return e_utf8_gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (hdrs->priv->from_entry)->entry)); + account = hdrs->account; + if (!account || !account->id) { + /* FIXME: perhaps we should try the default account? */ + return NULL; + } + + return camel_internet_address_format_address (account->id->name, account->id->address); } /* FIXME this is currently unused and broken. */ diff --git a/composer/e-msg-composer-hdrs.h b/composer/e-msg-composer-hdrs.h index a343fb0b7d..1521cc94a3 100644 --- a/composer/e-msg-composer-hdrs.h +++ b/composer/e-msg-composer-hdrs.h @@ -26,6 +26,7 @@ #include <gnome.h> #include <camel/camel-mime-message.h> +#include <mail/mail-config.h> #ifdef __cplusplus extern "C" { @@ -48,6 +49,8 @@ struct _EMsgComposerHdrs { EMsgComposerHdrsPrivate *priv; + const MailConfigAccount *account; + gboolean has_changed; }; @@ -64,8 +67,8 @@ GtkWidget *e_msg_composer_hdrs_new (void); void e_msg_composer_hdrs_to_message (EMsgComposerHdrs *hdrs, CamelMimeMessage *msg); -void e_msg_composer_hdrs_set_from (EMsgComposerHdrs *hdrs, - const char *from); +void e_msg_composer_hdrs_set_from_account (EMsgComposerHdrs *hdrs, + const char *account_name); void e_msg_composer_hdrs_set_to (EMsgComposerHdrs *hdrs, const GList *to_list); void e_msg_composer_hdrs_set_cc (EMsgComposerHdrs *hdrs, diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c index 369b207dc2..9c63c962dc 100644 --- a/composer/e-msg-composer.c +++ b/composer/e-msg-composer.c @@ -261,15 +261,15 @@ build_message (EMsgComposer *composer) /* get and/or set the From field */ from = e_msg_composer_hdrs_get_from (E_MSG_COMPOSER_HDRS (composer->hdrs)); if (!from) { - const MailConfigIdentity *id = NULL; - CamelInternetAddress *ciaddr; + const MailConfigAccount *account = NULL; - id = mail_config_get_default_identity (); - ciaddr = camel_internet_address_new (); - camel_internet_address_add (ciaddr, id->name, id->address); - from = camel_address_encode (CAMEL_ADDRESS (ciaddr)); - e_msg_composer_hdrs_set_from (E_MSG_COMPOSER_HDRS (composer->hdrs), from); - camel_object_unref (CAMEL_OBJECT (ciaddr)); + account = mail_config_get_default_account (); + + /* if !account then we have mucho problemos, amigo */ + if (!account) + return NULL; + + e_msg_composer_hdrs_set_from_account (E_MSG_COMPOSER_HDRS (composer->hdrs), account->name); } g_free (from); @@ -2061,6 +2061,26 @@ e_msg_composer_get_send_html (EMsgComposer *composer) /** + * e_msg_composer_get_preferred_account: + * @composer: composer + * + * Returns the user-specified account (from field). + */ +const MailConfigAccount * +e_msg_composer_get_preferred_account (EMsgComposer *composer) +{ + EMsgComposerHdrs *hdrs; + + g_return_val_if_fail (composer != NULL, NULL); + g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), NULL); + + hdrs = E_MSG_COMPOSER_HDRS (composer->hdrs); + + return hdrs->account; +} + + +/** * e_msg_composer_set_pgp_sign: * @composer: A message composer widget * @send_html: Whether the composer should have the "PGP Sign" flag set diff --git a/composer/e-msg-composer.h b/composer/e-msg-composer.h index f50832fd4c..529321aa89 100644 --- a/composer/e-msg-composer.h +++ b/composer/e-msg-composer.h @@ -34,6 +34,8 @@ typedef struct _EMsgComposerClass EMsgComposerClass; #include "e-msg-composer-hdrs.h" #include "Editor.h" +#include <mail/mail-config.h> + #ifdef __cplusplus extern "C" { #pragma } @@ -115,6 +117,9 @@ void e_msg_composer_set_send_html (EMsgComposer *compose gboolean e_msg_composer_get_send_html (EMsgComposer *composer); void e_msg_composer_set_pgp_sign (EMsgComposer *composer, gboolean pgp_sign); + +const MailConfigAccount *e_msg_composer_get_preferred_account (EMsgComposer *composer); + gboolean e_msg_composer_get_pgp_sign (EMsgComposer *composer); void e_msg_composer_set_pgp_encrypt (EMsgComposer *composer, gboolean pgp_encrypt); |