* Fixes NB#90204 fixes a memory leak
[modest] / src / hildon2 / modest-msg-edit-window.c
index 511eb0c..2df0d39 100644 (file)
@@ -43,7 +43,7 @@
 #include <modest-account-mgr-helpers.h>
 
 #include <widgets/modest-msg-edit-window.h>
-#include <widgets/modest-combo-box.h>
+#include <modest-selector-picker.h>
 #include <widgets/modest-recpt-editor.h>
 #include <widgets/modest-attachments-view.h>
 
 #endif
 #include <modest-utils.h>
 #include "modest-maemo-utils.h"
+#include <modest-ui-constants.h>
 
 
 #define DEFAULT_FONT_SIZE 3
 #define DEFAULT_FONT 2
 #define DEFAULT_SIZE_BUTTON_FONT_FAMILY "Sans"
-#define DEFAULT_SIZE_COMBOBOX_WIDTH 80
 #define DEFAULT_MAIN_VBOX_SPACING 6
 #define SUBJECT_MAX_LENGTH 1000
 #define IMAGE_MAX_WIDTH 560
@@ -723,7 +723,7 @@ connect_signals (ModestMsgEditWindow *obj)
 static void
 init_window (ModestMsgEditWindow *obj)
 {
-       GtkWidget *from_caption, *to_caption, *subject_caption;
+       GtkWidget *to_caption, *subject_caption;
        GtkWidget *main_vbox;
        ModestMsgEditWindowPrivate *priv;
        GtkActionGroup *action_group;
@@ -738,6 +738,7 @@ init_window (ModestMsgEditWindow *obj)
 #if (GTK_MINOR_VERSION >= 10)
        GdkAtom deserialize_type;
 #endif
+
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(obj);
        parent_priv = MODEST_WINDOW_GET_PRIVATE (obj);
 
@@ -791,10 +792,15 @@ init_window (ModestMsgEditWindow *obj)
 
        size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
 
-       /* Note: This ModestPairList* must exist for as long as the combo
-        * that uses it, because the ModestComboBox uses the ID opaquely, 
+       /* Note: This ModestPairList* must exist for as long as the picker
+        * that uses it, because the ModestSelectorPicker uses the ID opaquely, 
         * so it can't know how to manage its memory. */ 
-       priv->from_field    = modest_combo_box_new (NULL, g_str_equal);
+       priv->from_field    = modest_selector_picker_new (MODEST_EDITABLE_SIZE,
+                                                         MODEST_EDITABLE_ARRANGEMENT,
+                                                         NULL, g_str_equal);
+       hildon_button_set_alignment (HILDON_BUTTON (priv->from_field), 0.0, 0.5, 1.0, 0.0);
+       hildon_button_set_title_alignment (HILDON_BUTTON (priv->from_field), 0.0, 0.5);
+       hildon_button_set_value_alignment (HILDON_BUTTON (priv->from_field), 0.0, 0.5);
 
        priv->to_field      = modest_recpt_editor_new ();
        priv->cc_field      = modest_recpt_editor_new ();
@@ -802,7 +808,8 @@ init_window (ModestMsgEditWindow *obj)
        subject_box = gtk_hbox_new (FALSE, 0);
        priv->priority_icon = gtk_image_new ();
        gtk_box_pack_start (GTK_BOX (subject_box), priv->priority_icon, FALSE, FALSE, 0);
-       priv->subject_field = gtk_entry_new_with_max_length (SUBJECT_MAX_LENGTH);
+       priv->subject_field = hildon_entry_new (MODEST_EDITABLE_SIZE);
+       gtk_entry_set_max_length (GTK_ENTRY (priv->subject_field) ,SUBJECT_MAX_LENGTH);
        g_object_set (G_OBJECT (priv->subject_field), "truncate-multiline", TRUE, NULL);
        hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->subject_field), 
                                         HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
@@ -811,7 +818,7 @@ init_window (ModestMsgEditWindow *obj)
        GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (priv->add_attachment_button), GTK_CAN_FOCUS);
        gtk_button_set_relief (GTK_BUTTON (priv->add_attachment_button), GTK_RELIEF_NONE);
        gtk_button_set_focus_on_click (GTK_BUTTON (priv->add_attachment_button), FALSE);
-       gtk_button_set_alignment (GTK_BUTTON (priv->add_attachment_button), 1.0, 1.0);
+       gtk_button_set_alignment (GTK_BUTTON (priv->add_attachment_button), 1.0, 0.5);
        attachment_icon = gtk_image_new_from_icon_name (MODEST_HEADER_ICON_ATTACH, GTK_ICON_SIZE_BUTTON);
        gtk_container_add (GTK_CONTAINER (priv->add_attachment_button), attachment_icon);
        gtk_box_pack_start (GTK_BOX (subject_box), priv->add_attachment_button, FALSE, FALSE, 0);
@@ -819,15 +826,16 @@ init_window (ModestMsgEditWindow *obj)
        
        priv->header_box = gtk_vbox_new (FALSE, 0);
        
-       from_caption = hildon_caption_new (size_group, _("mail_va_from"), priv->from_field, NULL, 0);
-       to_caption = hildon_caption_new (size_group, _("mail_va_to"), priv->to_field, NULL, 0);
-       priv->cc_caption = hildon_caption_new (size_group, _("mail_va_cc"), priv->cc_field, NULL, 0);
-       priv->bcc_caption = hildon_caption_new (size_group, _("mail_va_hotfix1"), priv->bcc_field, NULL, 0);
-       subject_caption = hildon_caption_new (size_group, _("mail_va_subject"), subject_box, NULL, 0);
-       priv->attachments_caption = hildon_caption_new (size_group, _("mail_va_attachment"), priv->attachments_view, NULL, 0);
+       hildon_button_add_title_size_group (HILDON_BUTTON (priv->from_field), size_group);
+       to_caption = modest_maemo_utils_create_captioned (size_group, _("mail_va_to"), priv->to_field);
+       priv->cc_caption = modest_maemo_utils_create_captioned (size_group, _("mail_va_cc"), priv->cc_field);
+       priv->bcc_caption = modest_maemo_utils_create_captioned (size_group, _("mail_va_hotfix1"), priv->bcc_field);
+       subject_caption = modest_maemo_utils_create_captioned (size_group, _("mail_va_subject"), subject_box);
+       priv->attachments_caption = modest_maemo_utils_create_captioned (size_group, _("mail_va_attachment"), priv->attachments_view);
        g_object_unref (size_group);
 
        size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+       hildon_button_add_value_size_group (HILDON_BUTTON (priv->from_field), size_group);
        modest_recpt_editor_set_field_size_group (MODEST_RECPT_EDITOR (priv->to_field), size_group);
        modest_recpt_editor_set_field_size_group (MODEST_RECPT_EDITOR (priv->cc_field), size_group);
        modest_recpt_editor_set_field_size_group (MODEST_RECPT_EDITOR (priv->bcc_field), size_group);
@@ -835,7 +843,7 @@ init_window (ModestMsgEditWindow *obj)
        gtk_size_group_add_widget (size_group, priv->attachments_view);
        g_object_unref (size_group);
 
-       gtk_box_pack_start (GTK_BOX (priv->header_box), from_caption, FALSE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (priv->header_box), priv->from_field, FALSE, FALSE, 0);
        gtk_box_pack_start (GTK_BOX (priv->header_box), to_caption, FALSE, FALSE, 0);
        gtk_box_pack_start (GTK_BOX (priv->header_box), priv->cc_caption, FALSE, FALSE, 0);
        gtk_box_pack_start (GTK_BOX (priv->header_box), priv->bcc_caption, FALSE, FALSE, 0);
@@ -969,7 +977,7 @@ modest_msg_edit_window_finalize (GObject *obj)
        g_object_unref (priv->attachments);
        g_object_unref (priv->images);
 
-       /* This had to stay alive for as long as the combobox that used it: */
+       /* This had to stay alive for as long as the picker that used it: */
        modest_pair_list_free (priv->from_field_protos);
        
        G_OBJECT_CLASS(parent_class)->finalize (obj);
@@ -1000,6 +1008,8 @@ pixbuf_from_stream (TnyStream *stream, const gchar *mime_type, guint64 *stream_s
                readed = tny_stream_read (TNY_STREAM (stream), (char *) read_buffer, 128);
                size += readed;
                if (!gdk_pixbuf_loader_write (loader, read_buffer, readed, &error)) {
+                       if (error)
+                               g_error_free (error);
                        break;
                }
        }
@@ -1233,10 +1243,6 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich)
                gtk_widget_grab_focus (priv->msg_body);
        }
 
-       /* TODO: lower priority, select in the From: combo to the
-          value that comes from msg <- not sure, should it be
-          allowed? */
-       
        DEBUG_BUFFER (WP_TEXT_BUFFER (priv->text_buffer));
 
        gtk_text_buffer_get_start_iter (priv->text_buffer, &iter);
@@ -1492,8 +1498,13 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, gboolean pre
        parent_priv->menubar = modest_maemo_utils_get_manager_menubar_as_menu (parent_priv->ui_manager, "/MenuBar");
        hildon_window_set_menu (HILDON_WINDOW (obj), GTK_MENU (parent_priv->menubar));
        priv->from_field_protos = get_transports ();
-       modest_combo_box_set_pair_list (MODEST_COMBO_BOX (priv->from_field), priv->from_field_protos);
-       modest_combo_box_set_active_id (MODEST_COMBO_BOX (priv->from_field), (gpointer) account_name);
+       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);
+       hildon_button_set_title (HILDON_BUTTON (priv->from_field),
+                                _("mail_va_from"));
+       hildon_button_set_value (HILDON_BUTTON (priv->from_field), 
+                                hildon_touch_selector_get_current_text 
+                                (HILDON_TOUCH_SELECTOR (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (priv->from_field)))));
        modest_msg_edit_window_setup_toolbar (MODEST_MSG_EDIT_WINDOW (obj));
        hildon_window_add_toolbar (HILDON_WINDOW (obj), GTK_TOOLBAR (priv->find_toolbar));
 
@@ -1608,7 +1619,7 @@ modest_msg_edit_window_get_msg_data (ModestMsgEditWindow *edit_window)
 
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (edit_window);
                                                                        
-       account_name = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->from_field));
+       account_name = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field));
        g_return_val_if_fail (account_name, NULL);
        
        
@@ -1893,6 +1904,7 @@ modest_msg_edit_window_set_format_state (ModestMsgEditWindow *self,
        
        text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), self);
        
+       g_free (buffer_format);
        g_free (current_format);
 
        /* Check dimming rules */
@@ -2160,7 +2172,7 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window)
        modest_maemo_utils_setup_images_filechooser (GTK_FILE_CHOOSER (dialog));
 
        modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), 
-                                    GTK_WINDOW (dialog));
+                                    GTK_WINDOW (dialog), GTK_WINDOW (window));
 
        response = gtk_dialog_run (GTK_DIALOG (dialog));
        switch (response) {
@@ -2274,7 +2286,7 @@ modest_msg_edit_window_offer_attach_file (ModestMsgEditWindow *window)
        dialog = hildon_file_chooser_dialog_new (GTK_WINDOW (window), GTK_FILE_CHOOSER_ACTION_OPEN);
        gtk_window_set_title (GTK_WINDOW (dialog), _("mcen_ti_select_attachment_title"));
        gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), TRUE);
-       modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog));
+       modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), GTK_WINDOW (window));
 
        response = gtk_dialog_run (GTK_DIALOG (dialog));
        switch (response) {
@@ -2853,7 +2865,7 @@ modest_msg_edit_window_select_font (ModestMsgEditWindow *window)
        
        dialog = hildon_font_selection_dialog_new (GTK_WINDOW (window), NULL);
        modest_window_mgr_set_modal (modest_runtime_get_window_mgr(),
-                                    GTK_WINDOW(dialog));
+                                    GTK_WINDOW(dialog), GTK_WINDOW (window));
 
        /* First we get the currently selected font information */
        wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), &oldfmt, TRUE);
@@ -2890,7 +2902,7 @@ modest_msg_edit_window_select_font (ModestMsgEditWindow *window)
                      NULL);
 
        modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), 
-                                    GTK_WINDOW (dialog));
+                                    GTK_WINDOW (dialog), GTK_WINDOW (window));
        gtk_widget_show_all (dialog);
        priv->font_dialog = dialog;
        response = gtk_dialog_run (GTK_DIALOG (dialog));
@@ -3144,7 +3156,7 @@ modest_msg_edit_window_is_modified (ModestMsgEditWindow *editor)
                return TRUE;
        if (gtk_text_buffer_get_modified (priv->text_buffer))
                return TRUE;
-       account_name = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->from_field));
+       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)) {
                return TRUE;
        }
@@ -3544,8 +3556,12 @@ modest_msg_edit_window_set_draft (ModestMsgEditWindow *window,
                        priv->msg_uid = NULL;
                }
                priv->msg_uid = modest_tny_folder_get_header_unique_id (header);
-               if (GTK_WIDGET_REALIZED (window))
-                       modest_window_mgr_register_window (mgr, MODEST_WINDOW (window));
+               if (GTK_WIDGET_REALIZED (window)) {
+                       if (!modest_window_mgr_register_window (mgr, MODEST_WINDOW (window), NULL)) {
+                               gtk_widget_destroy (GTK_WIDGET (window));
+                               return;
+                       }
+               }
        }
 
        priv->draft_msg = draft;