X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhildon2%2Fmodest-msg-edit-window.c;h=801e52d787923e0fd69cfaa151f6437e921dc492;hb=0101197b8dd4be2d5b1486bdf6c276257803567a;hp=7fad0c15a530ef6524372cd82388a77186621f18;hpb=1f49ac9df5635e0427ef1c2e1b2cc0c30c7c0cd2;p=modest diff --git a/src/hildon2/modest-msg-edit-window.c b/src/hildon2/modest-msg-edit-window.c index 7fad0c1..801e52d 100644 --- a/src/hildon2/modest-msg-edit-window.c +++ b/src/hildon2/modest-msg-edit-window.c @@ -36,6 +36,7 @@ #include #include #include +#include #include @@ -176,6 +177,9 @@ static void font_size_clicked (GtkToolButton *button, ModestMsgEditWindow *window); static void font_face_clicked (GtkToolButton *button, ModestMsgEditWindow *window); +static void update_signature (ModestMsgEditWindow *self, + const gchar *old_account, + const gchar *new_account); static void DEBUG_BUFFER (WPTextBuffer *buffer) { #ifdef DEBUG @@ -444,6 +448,85 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj) HILDON_WINDOW(obj)); } +static gboolean account_is_multimailbox (const gchar *account_name, ModestProtocol **mmb_protocol) +{ + gchar *transport_account; + gboolean result = FALSE; + + if (mmb_protocol) + *mmb_protocol = NULL; + + transport_account = modest_account_mgr_get_server_account_name (modest_runtime_get_account_mgr (), + account_name, + TNY_ACCOUNT_TYPE_TRANSPORT); + if (transport_account) { + gchar *proto; + ModestProtocolRegistry *registry; + + registry = modest_runtime_get_protocol_registry (); + + proto = modest_account_mgr_get_string (modest_runtime_get_account_mgr (), transport_account, + MODEST_ACCOUNT_PROTO, TRUE); + if (proto != NULL) { + ModestProtocol *protocol = + modest_protocol_registry_get_protocol_by_name (registry, + MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS, + proto); + if (protocol && + modest_protocol_registry_protocol_type_has_tag + (registry, + modest_protocol_get_type_id (protocol), + MODEST_PROTOCOL_REGISTRY_MULTI_MAILBOX_PROVIDER_PROTOCOLS)) { + if (mmb_protocol) + *mmb_protocol = protocol; + result = TRUE; + } + + } + } + + return result; +} + +static gchar * +multimailbox_get_default_mailbox (const gchar *account_name) +{ + gchar *transport_account; + gchar *result = NULL; + + transport_account = modest_account_mgr_get_server_account_name (modest_runtime_get_account_mgr (), + account_name, + TNY_ACCOUNT_TYPE_TRANSPORT); + if (transport_account) { + gchar *proto; + ModestProtocolRegistry *registry; + + registry = modest_runtime_get_protocol_registry (); + + proto = modest_account_mgr_get_string (modest_runtime_get_account_mgr (), transport_account, + MODEST_ACCOUNT_PROTO, TRUE); + if (proto != NULL) { + ModestProtocol *protocol = + modest_protocol_registry_get_protocol_by_name (registry, + MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS, + proto); + if (MODEST_ACCOUNT_PROTOCOL (protocol)) { + ModestPairList *pair_list; + + pair_list = modest_account_protocol_get_from_list (MODEST_ACCOUNT_PROTOCOL (protocol), + account_name); + if (pair_list) { + ModestPair *pair = (ModestPair *) pair_list->data; + result = g_strdup ((const gchar *) pair->first); + modest_pair_list_free (pair_list); + } + } + + } + } + + return result; +} /** * @result: A ModestPairList, which must be freed with modest_pair_list_free(). @@ -460,17 +543,41 @@ get_transports (void) GSList *cursor = accounts; while (cursor) { gchar *account_name = cursor->data; - gchar *from_string = NULL; if (account_name) { - from_string = modest_account_mgr_get_from_string (account_mgr, - account_name); - } - - if (from_string && account_name) { - gchar *name = account_name; - ModestPair *pair = modest_pair_new ((gpointer) name, - (gpointer) from_string , TRUE); - transports = g_slist_prepend (transports, pair); + + gchar *transport_account; + gboolean multi_mailbox = FALSE; + ModestProtocol *protocol = NULL; + + if (account_is_multimailbox (account_name, &protocol)) { + + transport_account = modest_account_mgr_get_server_account_name + (modest_runtime_get_account_mgr (), + account_name, + TNY_ACCOUNT_TYPE_TRANSPORT); + if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol)) { + ModestPairList *pair_list; + pair_list = modest_account_protocol_get_from_list (MODEST_ACCOUNT_PROTOCOL (protocol), + account_name); + if (pair_list) { + transports = g_slist_concat (transports, pair_list); + multi_mailbox = TRUE; + } + } + } + + if (!multi_mailbox) { + gchar *from_string = NULL; + + from_string = modest_account_mgr_get_from_string (account_mgr, + account_name, NULL); + if (from_string && account_name) { + gchar *name = account_name; + ModestPair *pair = modest_pair_new ((gpointer) name, + (gpointer) from_string , TRUE); + transports = g_slist_prepend (transports, pair); + } + } } cursor = cursor->next; @@ -1511,9 +1618,22 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, const gchar /* Menubar. Update the state of some toggles */ priv->from_field_protos = get_transports (); + priv->original_mailbox = NULL; modest_selector_picker_set_pair_list (MODEST_SELECTOR_PICKER (priv->from_field), priv->from_field_protos); modest_selector_picker_set_active_id (MODEST_SELECTOR_PICKER (priv->from_field), (gpointer) account_name); priv->last_from_account = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field)); + if (mailbox && modest_pair_list_find_by_first_as_string (priv->from_field_protos, mailbox)) { + modest_selector_picker_set_active_id (MODEST_SELECTOR_PICKER (priv->from_field), (gpointer) mailbox); + priv->original_mailbox = g_strdup (mailbox); + } else if (account_is_multimailbox (account_name, NULL)) { + /* We set the first mailbox as the active mailbox */ + priv->original_mailbox = multimailbox_get_default_mailbox (account_name); + modest_selector_picker_set_active_id (MODEST_SELECTOR_PICKER (priv->from_field), + (gpointer) priv->original_mailbox); + } else { + modest_selector_picker_set_active_id (MODEST_SELECTOR_PICKER (priv->from_field), (gpointer) account_name); + } + priv->last_from_account = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field)); hildon_button_set_title (HILDON_BUTTON (priv->from_field), _("mail_va_from")); hildon_button_set_value (HILDON_BUTTON (priv->from_field), @@ -1528,10 +1648,9 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, const gchar restore_settings (MODEST_MSG_EDIT_WINDOW(obj)); modest_window_set_active_account (MODEST_WINDOW(obj), account_name); - modest_window_set_active_mailbox (MODEST_WINDOW(obj), mailbox); + modest_window_set_active_mailbox (MODEST_WINDOW(obj), priv->original_mailbox); priv->original_account_name = (account_name) ? g_strdup (account_name) : NULL; - priv->original_mailbox = (mailbox) ? g_strdup (mailbox) : NULL; toolbar_rules_group = modest_dimming_rules_group_new (MODEST_DIMMING_RULES_TOOLBAR, TRUE); clipboard_rules_group = modest_dimming_rules_group_new (MODEST_DIMMING_RULES_CLIPBOARD, FALSE); @@ -1563,6 +1682,8 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, const gchar gtk_widget_queue_resize (priv->subject_box); set_msg (MODEST_MSG_EDIT_WINDOW (obj), msg, preserve_is_rich); + update_signature (MODEST_MSG_EDIT_WINDOW (obj), account_name, priv->last_from_account); + text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), MODEST_MSG_EDIT_WINDOW (obj)); modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (obj)); @@ -1624,19 +1745,19 @@ modest_msg_edit_window_get_msg_data (ModestMsgEditWindow *edit_window) const gchar *account_name; ModestMsgEditWindowPrivate *priv; TnyIterator *att_iter; + const gchar *picker_active_id; g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (edit_window), NULL); priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (edit_window); - - account_name = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field)); - g_return_val_if_fail (account_name, NULL); + picker_active_id = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field)); + g_return_val_if_fail (picker_active_id, NULL); + account_name = modest_utils_get_account_name_from_recipient (picker_active_id, NULL); /* don't free these (except from) */ data = g_slice_new0 (MsgData); - data->from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(), - account_name); + data->from = g_strdup ((gchar *) modest_selector_picker_get_active_display_name (MODEST_SELECTOR_PICKER (priv->from_field))); data->account_name = g_strdup (account_name); data->to = g_strdup (modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR (priv->to_field))); data->cc = g_strdup (modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR (priv->cc_field))); @@ -3251,9 +3372,11 @@ modest_msg_edit_window_is_modified (ModestMsgEditWindow *editor) if (gtk_text_buffer_get_modified (priv->text_buffer)) return TRUE; - /* TODO: check the mailbox too here */ account_name = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field)); - if (!priv->original_account_name || strcmp(account_name, priv->original_account_name)) { + if (priv->original_mailbox) { + if (!account_name || strcmp (account_name, priv->original_mailbox)) + return TRUE; + } else if (!priv->original_account_name || strcmp(account_name, priv->original_account_name)) { return TRUE; } @@ -3763,9 +3886,36 @@ on_account_removed (TnyAccountStore *account_store, } } -static void -from_field_changed (HildonPickerButton *button, - ModestMsgEditWindow *self) +static gchar * +get_signature (const gchar *current_recipient, gboolean *has_signature) +{ + gchar *result = NULL; + gchar *mailbox = NULL; + gchar *account_name; + ModestProtocol *protocol = NULL; + + *has_signature = FALSE; + + account_name = modest_utils_get_account_name_from_recipient (current_recipient, &mailbox); + if (account_is_multimailbox (account_name, &protocol) + && mailbox) { + if (MODEST_IS_ACCOUNT_PROTOCOL (protocol)) { + result = modest_account_protocol_get_signature (MODEST_ACCOUNT_PROTOCOL (protocol), + account_name, mailbox, + has_signature); + } + } + + if (result == NULL) { + result = modest_account_mgr_get_signature (modest_runtime_get_account_mgr (), + account_name, has_signature); + } + return result; +} + +static void update_signature (ModestMsgEditWindow *self, + const gchar *old_account, + const gchar *new_account) { ModestMsgEditWindowPrivate *priv; gboolean has_old_signature, has_new_signature; @@ -3777,30 +3927,54 @@ from_field_changed (HildonPickerButton *button, priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self); + gtk_text_buffer_begin_user_action (priv->text_buffer); + gtk_text_buffer_get_start_iter (priv->text_buffer, &iter); mgr = modest_runtime_get_account_mgr (); - signature = modest_account_mgr_get_signature (mgr, priv->last_from_account, &has_old_signature); - if (has_old_signature) { - full_signature = g_strconcat ("\n--\n", signature, NULL); - if (gtk_text_iter_forward_search (&iter, full_signature, 0, &match_start, &match_end, NULL)) { - gtk_text_buffer_delete (priv->text_buffer, &match_start, &match_end); - iter = match_start; - } else if (gtk_text_iter_forward_search (&iter, _("mcen_ia_editor_original_message"), 0, - &match_start, &match_end, NULL)) { - iter = match_start; + + + if (old_account) { + signature = get_signature (old_account, &has_old_signature); + if (has_old_signature) { + full_signature = g_strconcat ("\n--\n", signature, NULL); + if (gtk_text_iter_forward_search (&iter, full_signature, 0, &match_start, &match_end, NULL)) { + gtk_text_buffer_delete (priv->text_buffer, &match_start, &match_end); + iter = match_start; + } else if (gtk_text_iter_forward_search (&iter, _("mcen_ia_editor_original_message"), 0, + &match_start, &match_end, NULL)) { + iter = match_start; + } + g_free (full_signature); } - g_free (full_signature); + g_free (signature); } - g_free (signature); priv->last_from_account = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field)); - signature = modest_account_mgr_get_signature (mgr, priv->last_from_account, &has_new_signature); + signature = get_signature (new_account, &has_new_signature); if (has_new_signature) { full_signature = g_strconcat ("\n--\n", signature, NULL); gtk_text_buffer_insert (priv->text_buffer, &iter, full_signature, -1); g_free (full_signature); } g_free (signature); + gtk_text_buffer_end_user_action (priv->text_buffer); +} + +static void +from_field_changed (HildonPickerButton *button, + ModestMsgEditWindow *self) +{ + ModestMsgEditWindowPrivate *priv; + gchar *old_account, *new_account; + + priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self); + + old_account = priv->last_from_account; + priv->last_from_account = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field)); + new_account = priv->last_from_account; + + update_signature (self, old_account, new_account); + } typedef struct _MessageSettingsHelper {