Add a way to limit the number of chars in value part of from field selector picker.
[modest] / src / hildon2 / modest-msg-edit-window.c
index bb5f4b3..8571461 100644 (file)
@@ -92,6 +92,7 @@
 #define IMAGE_MAX_WIDTH 560
 #define DEFAULT_FONT_SCALE 1.5
 #define ATTACHMENT_BUTTON_WIDTH 118
+#define MAX_FROM_VALUE 48
 
 static gboolean is_wp_text_buffer_started = FALSE;
 
@@ -448,46 +449,6 @@ 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)
 {
@@ -549,7 +510,7 @@ get_transports (void)
                        gboolean multi_mailbox = FALSE;
                        ModestProtocol *protocol = NULL;
 
-                       if (account_is_multimailbox (account_name, &protocol)) {
+                       if (modest_account_mgr_account_is_multimailbox (account_mgr, account_name, &protocol)) {
 
                                transport_account = modest_account_mgr_get_server_account_name 
                                        (modest_runtime_get_account_mgr (),
@@ -898,6 +859,7 @@ init_window (ModestMsgEditWindow *obj)
        priv->from_field    = modest_selector_picker_new (MODEST_EDITABLE_SIZE,
                                                          HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
                                                          NULL, g_str_equal);
+       modest_selector_picker_set_value_max_chars (MODEST_SELECTOR_PICKER (priv->from_field), MAX_FROM_VALUE);
        modest_maemo_utils_set_hbutton_layout (title_size_group, value_size_group, 
                                               _("mail_va_from"), priv->from_field);
 
@@ -987,6 +949,8 @@ init_window (ModestMsgEditWindow *obj)
 /*     g_signal_connect (G_OBJECT (obj), "key_pressed", G_CALLBACK (on_key_pressed), NULL) */
 
        priv->pannable = hildon_pannable_area_new ();
+
+       g_object_set (G_OBJECT (priv->pannable), "hscrollbar-policy", GTK_POLICY_NEVER, NULL);
        
        main_vbox = gtk_vbox_new  (FALSE, DEFAULT_MAIN_VBOX_SPACING);
        window_align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
@@ -1625,11 +1589,15 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, const gchar
        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)) {
+       } else if (modest_account_mgr_account_is_multimailbox (modest_runtime_get_account_mgr (), 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);
+               if (priv->original_mailbox != NULL)
+                       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);
        } else {
                modest_selector_picker_set_active_id (MODEST_SELECTOR_PICKER (priv->from_field), (gpointer) account_name);
        }
@@ -1682,10 +1650,6 @@ 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);
 
-       if (mailbox)
-               update_signature (MODEST_MSG_EDIT_WINDOW (obj), mailbox, NULL);
-       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));
@@ -2815,6 +2779,7 @@ font_face_clicked (GtkToolButton *button,
 
        selector = hildon_touch_selector_new ();
        renderer = gtk_cell_renderer_text_new ();
+       g_object_set (G_OBJECT (renderer), "alignment", PANGO_ALIGN_CENTER, "xalign", 0.5, NULL);
        hildon_touch_selector_append_column (HILDON_TOUCH_SELECTOR (selector), priv->faces_model, 
                                             renderer, "family", 0, "text", 0, NULL);
        hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, priv->current_face_index);
@@ -3888,33 +3853,6 @@ on_account_removed (TnyAccountStore *account_store,
        }
 }
 
-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)
@@ -3936,7 +3874,7 @@ static void update_signature (ModestMsgEditWindow *self,
 
 
        if (old_account) {
-               signature = get_signature (old_account, &has_old_signature);
+               signature = modest_account_mgr_get_signature_from_recipient (mgr, 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)) {
@@ -3952,7 +3890,7 @@ static void update_signature (ModestMsgEditWindow *self,
        }
 
        priv->last_from_account = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field));
-       signature = get_signature (new_account, &has_new_signature);
+       signature = modest_account_mgr_get_signature_from_recipient (mgr, 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);