diff options
author | Meilof Veeningen <meilof@wanadoo.nl> | 2004-01-13 06:21:26 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2004-01-13 06:21:26 +0800 |
commit | 6390a47a1f115a87c6e769e804ead077e276e7ef (patch) | |
tree | d7ef2dffbb697572a962f2f4b0ed76965be22e40 /composer/e-msg-composer-hdrs.c | |
parent | 70f49bc0d7ce40521c4c99b7c9dbe6255db2c788 (diff) | |
download | gsoc2013-evolution-6390a47a1f115a87c6e769e804ead077e276e7ef.tar.gz gsoc2013-evolution-6390a47a1f115a87c6e769e804ead077e276e7ef.tar.zst gsoc2013-evolution-6390a47a1f115a87c6e769e804ead077e276e7ef.zip |
added "View To", "View Post To" menu items, made it possible to see both
2004-01-12 Meilof Veeningen <meilof@wanadoo.nl>
* e-msg-composer.[ch]: added "View To", "View Post To" menu items,
made it possible to see both at the same time, new
e_msg_composer_new_with_type, only visibility info of headers if
in the visible mask.
* e-msg-composer.[ch]: replaced folder selection button by entry
with selection button next to it, enabled multiple folder selection,
made it possible to see both To and PostTo fields, disabled
setting the "X-Evolution-PostTo" header.
svn path=/trunk/; revision=24179
Diffstat (limited to 'composer/e-msg-composer-hdrs.c')
-rw-r--r-- | composer/e-msg-composer-hdrs.c | 266 |
1 files changed, 245 insertions, 21 deletions
diff --git a/composer/e-msg-composer-hdrs.c b/composer/e-msg-composer-hdrs.c index 4e222b0bfd..fe64e96c5f 100644 --- a/composer/e-msg-composer-hdrs.c +++ b/composer/e-msg-composer-hdrs.c @@ -50,7 +50,10 @@ #include <camel/camel.h> #include "e-msg-composer-hdrs.h" #include "mail/mail-config.h" -#include "mail/em-folder-selection-button.h" +/*#include "mail/em-folder-selection-button.h"*/ +#include "mail/em-folder-selector.h" +#include "mail/mail-component.h" +#include "mail/em-folder-tree.h" @@ -82,6 +85,8 @@ struct _EMsgComposerHdrsPrivate { EAccountList *accounts; GSList *from_options; + gboolean post_custom; + /* Standard headers. */ EMsgComposerHdrPair from, reply_to, to, cc, bcc, post_to, subject; }; @@ -179,6 +184,11 @@ from_changed (GtkWidget *item, gpointer data) { EMsgComposerHdrs *hdrs = E_MSG_COMPOSER_HDRS (data); const char *reply_to; + GList *post_items = NULL; + + /* this will retrieve items relative to the previous account */ + if (!hdrs->priv->post_custom) + post_items = e_msg_composer_hdrs_get_post_to(hdrs); hdrs->account = g_object_get_data ((GObject *) item, "account"); @@ -187,6 +197,13 @@ from_changed (GtkWidget *item, gpointer data) reply_to = hdrs->account->id->reply_to; gtk_entry_set_text (GTK_ENTRY (hdrs->priv->reply_to.entry), reply_to ? reply_to : ""); + /* folders should be made relative to the new from */ + if (!hdrs->priv->post_custom) { + e_msg_composer_hdrs_set_post_to_list (hdrs, post_items); + g_list_foreach (post_items, (GFunc)g_free, NULL); + g_list_free(post_items); + } + g_signal_emit (hdrs, signals [FROM_CHANGED], 0); } @@ -460,6 +477,51 @@ create_addressbook_entry (EMsgComposerHdrs *hdrs, const char *name) return control_widget; } +static void +post_browser_response (EMFolderSelector *emfs, int response, EMsgComposerHdrs *hdrs) +{ + if (response == GTK_RESPONSE_OK) { + GList *uris = em_folder_selector_get_selected_uris (emfs); + e_msg_composer_hdrs_set_post_to_list (hdrs, uris); + hdrs->priv->post_custom = FALSE; + g_list_foreach (uris, (GFunc) g_free, NULL); + g_list_free (uris); + } + + gtk_widget_destroy ((GtkWidget *) emfs); +} + +static void +post_browser_clicked_cb (GtkButton *button, EMsgComposerHdrs *hdrs) +{ + EMFolderTreeModel *model; + EMFolderTree *emft; + GtkWidget *dialog; + GList *post_items; + + model = mail_component_peek_tree_model (mail_component_peek ()); + emft = (EMFolderTree *) em_folder_tree_new_with_model (model); + em_folder_tree_set_multiselect (emft, TRUE); + + dialog = em_folder_selector_new (emft, EM_FOLDER_SELECTOR_CAN_CREATE, + _("Posting destination"), + _("Choose folders to post the message to.")); + + post_items = e_msg_composer_hdrs_get_post_to (hdrs); + em_folder_selector_set_selected_list ((EMFolderSelector *) dialog, post_items); + g_list_foreach (post_items, (GFunc) g_free, NULL); + g_list_free (post_items); + + g_signal_connect (dialog, "response", G_CALLBACK (post_browser_response), hdrs); + gtk_widget_show (dialog); +} + +static void +post_entry_changed_cb (GtkButton *button, EMsgComposerHdrs *hdrs) +{ + hdrs->priv->post_custom = TRUE; +} + static EMsgComposerHdrPair header_new_recipient (EMsgComposerHdrs *hdrs, const char *name, const char *tip) { @@ -544,8 +606,17 @@ create_headers (EMsgComposerHdrs *hdrs) /* * Post-To */ - priv->post_to.label = gtk_label_new (_("Post To:")); - priv->post_to.entry = em_folder_selection_button_new (_("Posting destination"), _("Choose a folder to post the message to.")); + priv->post_to.label = gtk_button_new_with_label (_("Post To:")); + GTK_OBJECT_UNSET_FLAGS (priv->post_to.label, GTK_CAN_FOCUS); + g_signal_connect (priv->post_to.label, "clicked", + G_CALLBACK (post_browser_clicked_cb), hdrs); + gtk_tooltips_set_tip (hdrs->priv->tooltips, priv->post_to.label, + _("Click here to select folders to post to"), + NULL); + + priv->post_to.entry = gtk_entry_new (); + g_signal_connect(priv->post_to.entry, "changed", + G_CALLBACK (post_entry_changed_cb), hdrs); } static void @@ -579,7 +650,7 @@ attach_headers (EMsgComposerHdrs *hdrs) static void set_pair_visibility (EMsgComposerHdrs *h, EMsgComposerHdrPair *pair, int visible) { - if (visible & h->visible_mask) { + if (visible /*& h->visible_mask*/) { gtk_widget_show (pair->label); gtk_widget_show (pair->entry); } else { @@ -611,21 +682,14 @@ headers_set_visibility (EMsgComposerHdrs *h, int visible_flags) static void headers_set_sensitivity (EMsgComposerHdrs *h) { + /* these ones are always on */ bonobo_ui_component_set_prop ( - h->priv->uic, "/commands/ViewFrom", "sensitive", - h->visible_mask & E_MSG_COMPOSER_VISIBLE_FROM ? "1" : "0", NULL); + h->priv->uic, "/commands/ViewTo", "sensitive", + h->visible_mask & E_MSG_COMPOSER_VISIBLE_TO ? "0" : "1", NULL); bonobo_ui_component_set_prop ( - h->priv->uic, "/commands/ViewReplyTo", "sensitive", - h->visible_mask & E_MSG_COMPOSER_VISIBLE_REPLYTO ? "1" : "0", NULL); - - bonobo_ui_component_set_prop ( - h->priv->uic, "/commands/ViewCC", "sensitive", - h->visible_mask & E_MSG_COMPOSER_VISIBLE_CC ? "1" : "0", NULL); - - bonobo_ui_component_set_prop ( - h->priv->uic, "/commands/ViewBCC", "sensitive", - h->visible_mask & E_MSG_COMPOSER_VISIBLE_BCC ? "1" : "0", NULL); + h->priv->uic, "/commands/ViewPostTo", "sensitive", + h->visible_mask & E_MSG_COMPOSER_VISIBLE_POSTTO ? "0" : "1", NULL); } void @@ -775,6 +839,8 @@ init (EMsgComposerHdrs *hdrs) priv->accounts = mail_config_get_accounts (); g_object_ref (priv->accounts); + + priv->post_custom = FALSE; hdrs->priv = priv; } @@ -958,11 +1024,13 @@ e_msg_composer_hdrs_to_message_internal (EMsgComposerHdrs *hdrs, eab_destination_freev (bcc_destv); } +#if 0 if (hdrs->visible_mask & E_MSG_COMPOSER_VISIBLE_POSTTO) { header = e_msg_composer_hdrs_get_post_to (hdrs); camel_medium_set_header (CAMEL_MEDIUM (msg), "X-Evolution-PostTo", header); g_free (header); } +#endif } @@ -1096,12 +1164,144 @@ void e_msg_composer_hdrs_set_post_to (EMsgComposerHdrs *hdrs, const char *post_to) { + GList *list; + g_return_if_fail (E_IS_MSG_COMPOSER_HDRS (hdrs)); g_return_if_fail (post_to != NULL); - em_folder_selection_button_set_selection ((EMFolderSelectionButton *) hdrs->priv->post_to.entry, post_to); + list = g_list_append (NULL, g_strdup (post_to)); + + e_msg_composer_hdrs_set_post_to_list (hdrs, list); + + g_free (list->data) + g_list_free (list); } +static GList * +newsgroups_list_split (const char *list) +{ + GList *lst = NULL; + char *tmp; + char **items, **cur_ptr; + + cur_ptr = items = g_strsplit (list, ",", 0); + + while ((tmp = *cur_ptr) != NULL) { + g_strstrip (tmp); + + if (tmp[0]) + lst = g_list_append (lst, g_strdup (tmp)); + + cur_ptr++; + } + + g_strfreev (items); + + return lst; +} + +static char * +get_account_store_url (EMsgComposerHdrs *hdrs) +{ + CamelURL *url; + char *ret = NULL; + + if (hdrs->account->source && hdrs->account->source->url) { + url = camel_url_new (hdrs->account->source->url, NULL); + ret = camel_url_to_string (url, CAMEL_URL_HIDE_ALL); + camel_url_free (url); + } + + return ret; +} + +static char * +folder_name_to_string (EMsgComposerHdrs *hdrs, const char *uri) +{ + char *storeurl = get_account_store_url (hdrs); + int len; + + if (storeurl) { + len = strlen (storeurl); + + if (g_ascii_strncasecmp (uri, storeurl, len) == 0) { + g_free (storeurl); + return g_strdup (uri + len); + } + + g_free (storeurl); + } + + return g_strdup (uri); +} + +void +e_msg_composer_hdrs_set_post_to_list (EMsgComposerHdrs *hdrs, GList *urls) +{ + /* compile the name */ + char *caption, *tmp, *tmp2; + gboolean post_custom; + + if (hdrs->priv->post_to.entry == NULL) + return; + + caption = g_strdup (""); + + while (urls) { + tmp = folder_name_to_string (hdrs, (char *)urls->data); + if (tmp) { + tmp2 = g_strconcat (caption, ", ", tmp, NULL); + g_free (caption); + caption = tmp2; + g_free (tmp); + } + + urls = g_list_next (urls); + } + + post_custom = hdrs->priv->post_custom; + gtk_entry_set_text (GTK_ENTRY (hdrs->priv->post_to.entry), caption[0] ? caption + 2 : ""); + hdrs->priv->post_custom = post_custom; + g_free (caption); +} + +void +e_msg_composer_hdrs_set_post_to_base (EMsgComposerHdrs *hdrs, + const char *base, const char *post_to) +{ + GList *lst, *curlist; + char *hdr_copy = g_strdup (post_to), *caption, *tmp, *tmp2; + gboolean post_custom; + + /* split to newsgroup names */ + lst = newsgroups_list_split (hdr_copy); + curlist = lst; + + /* compile the name */ + caption = g_strdup (""); + + while (curlist) { + tmp2 = g_strdup_printf ("%s/%s", base, (char *)curlist->data); + tmp = folder_name_to_string (hdrs, tmp2); + g_free (tmp2); + if (tmp) { + tmp2 = g_strconcat (caption, ", ", tmp, NULL); + g_free (caption); + caption = tmp2; + g_free (tmp); + } + curlist = g_list_next (curlist); + } + + post_custom = hdrs->priv->post_custom; + gtk_entry_set_text (GTK_ENTRY (hdrs->priv->post_to.entry), caption[0] ? caption + 2 : ""); + hdrs->priv->post_custom = post_custom; + g_free (caption); + + g_list_foreach (lst, (GFunc) g_free, NULL); + g_list_free (lst); + g_free (hdr_copy); +} void e_msg_composer_hdrs_set_subject (EMsgComposerHdrs *hdrs, @@ -1255,16 +1455,40 @@ e_msg_composer_hdrs_get_recipients (EMsgComposerHdrs *hdrs) } -char * +GList * e_msg_composer_hdrs_get_post_to (EMsgComposerHdrs *hdrs) { - const char *uri; + GList *uris, *cur; + char *storeurl = NULL, *tmp; g_return_val_if_fail (E_IS_MSG_COMPOSER_HDRS (hdrs), NULL); - uri = em_folder_selection_button_get_selection ((EMFolderSelectionButton *) hdrs->priv->post_to.entry); + if (hdrs->priv->post_to.entry == NULL) + return NULL; - return g_strdup (uri); + tmp = g_strdup (gtk_entry_get_text (GTK_ENTRY (hdrs->priv->post_to.entry))); + uris = newsgroups_list_split (tmp); + g_free (tmp); + + cur = uris; + while (cur) { + if (strstr ((char *) cur->data, "://") == NULL) { + /* relative folder name: convert to absolute */ + if (!storeurl) + storeurl = get_account_store_url (hdrs); + if (!storeurl) + break; + tmp = g_strconcat (storeurl, cur->data, NULL); + g_free (cur->data); + cur->data = tmp; + } + + cur = cur->next; + } + + g_free (storeurl); + + return uris; } |