Do not need to unref tree models, they're automatically destroyed
[modest] / src / hildon2 / modest-msg-edit-window.c
index 04ee6ea..66fb0a4 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006, Nokia Corporation
+/1* Copyright (c) 2006, Nokia Corporation
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -187,13 +187,16 @@ static void font_face_clicked (GtkToolButton *button,
 static void update_signature (ModestMsgEditWindow *self,
                              const gchar *old_account, 
                              const gchar *new_account);
+static void update_branding (ModestMsgEditWindow *self,
+                            const gchar *new_account);
 static GtkWidget *_create_addressbook_box (GtkSizeGroup *title_size_group, GtkSizeGroup *value_size_group,
                                           const gchar *label, GtkWidget *control);
+static void max_chars_banner_unref (ModestMsgEditWindow *self, GObject *old_ref);
 static void DEBUG_BUFFER (WPTextBuffer *buffer)
 {
 #ifdef DEBUG
        GtkTextIter iter;
-       g_message ("BEGIN BUFFER OF SIZE %d", gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (buffer)));
+       g_debug ("BEGIN BUFFER OF SIZE %d", gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (buffer)));
 
        gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &iter);
        while (!gtk_text_iter_is_end (&iter)) {
@@ -220,11 +223,11 @@ static void DEBUG_BUFFER (WPTextBuffer *buffer)
                        g_string_append (output, " ");
                }
                output = g_string_append (output, "]\n");
-               g_message ("%s", output->str);
+               g_debug ("%s", output->str);
                g_string_free (output, TRUE);
                gtk_text_iter_forward_to_tag_toggle (&iter, NULL);
        }
-       g_message ("END BUFFER");
+       g_debug ("END BUFFER");
 #endif
 }
 
@@ -322,6 +325,11 @@ struct _ModestMsgEditWindowPrivate {
        GtkWidget   *app_menu;
        GtkWidget   *cc_button;
        GtkWidget   *bcc_button;
+
+       GtkWidget   *max_chars_banner;
+
+       GtkWidget   *brand_icon;
+       GtkWidget   *brand_label;
 };
 
 #define MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
@@ -445,6 +453,7 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj)
 
        priv->references = NULL;
        priv->in_reply_to = NULL;
+       priv->max_chars_banner = NULL;
 
        if (!is_wp_text_buffer_started) {
                is_wp_text_buffer_started = TRUE;
@@ -806,6 +815,7 @@ init_window (ModestMsgEditWindow *obj)
        GtkWidget *from_send_hbox;
        GtkWidget *send_icon;
        GtkWidget *attachments_label;
+       GtkWidget *branding_box;
 
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(obj);
        parent_priv = MODEST_WINDOW_GET_PRIVATE (obj);
@@ -928,16 +938,29 @@ init_window (ModestMsgEditWindow *obj)
        g_object_unref (title_size_group);
        g_object_unref (value_size_group);
 
+       priv->brand_icon = gtk_image_new ();
+       gtk_misc_set_alignment (GTK_MISC (priv->brand_icon), 0.5, 0.5);
+       priv->brand_label = gtk_label_new (NULL);
+       gtk_misc_set_alignment (GTK_MISC (priv->brand_label), 0.0, 0.5);
+       gtk_widget_set_no_show_all (priv->brand_icon, TRUE);
+       gtk_widget_set_no_show_all (priv->brand_label, TRUE);
+
        from_send_hbox = gtk_hbox_new (FALSE, 0);
        gtk_box_pack_start (GTK_BOX (from_send_hbox), priv->from_field, TRUE, TRUE, 0);
        gtk_box_pack_start (GTK_BOX (from_send_hbox), priv->send_button, FALSE, FALSE, 0);
 
+       branding_box = gtk_hbox_new (FALSE, MODEST_MARGIN_DEFAULT);
+       gtk_box_pack_start (GTK_BOX (branding_box), priv->brand_icon, FALSE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (branding_box), priv->brand_label, TRUE, TRUE, 0);
+
+
        gtk_box_pack_start (GTK_BOX (priv->header_box), from_send_hbox, 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);
        gtk_box_pack_start (GTK_BOX (priv->header_box), subject_caption, FALSE, FALSE, 0);
        gtk_box_pack_start (GTK_BOX (priv->header_box), priv->attachments_caption, FALSE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (priv->header_box), branding_box, FALSE, FALSE, 0);
        gtk_widget_set_no_show_all (priv->attachments_caption, TRUE);
 
        init_wp_text_view_style ();
@@ -1018,7 +1041,12 @@ static void
 modest_msg_edit_window_finalize (GObject *obj)
 {
        ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (obj);
-       
+
+       if (priv->max_chars_banner) {
+               g_object_weak_unref (G_OBJECT (priv->max_chars_banner), (GWeakNotify) max_chars_banner_unref, obj);
+               priv->max_chars_banner = FALSE;
+       }
+
        /* Sanity check: shouldn't be needed, the window mgr should
           call this function before */
        modest_msg_edit_window_disconnect_signals (MODEST_WINDOW (obj));
@@ -1070,8 +1098,6 @@ modest_msg_edit_window_finalize (GObject *obj)
        g_free (priv->last_search);
        g_free (priv->references);
        g_free (priv->in_reply_to);
-       g_object_unref (priv->faces_model);
-       g_object_unref (priv->sizes_model);
        g_object_unref (priv->attachments);
        g_object_unref (priv->images);
 
@@ -1614,6 +1640,7 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, const gchar
                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));
+       update_branding (MODEST_MSG_EDIT_WINDOW (obj), priv->last_from_account);
        hildon_button_set_title (HILDON_BUTTON (priv->from_field),
                                 _("mail_va_from"));
        hildon_button_set_value (HILDON_BUTTON (priv->from_field), 
@@ -2469,7 +2496,7 @@ on_attach_file_response (GtkDialog *dialog,
                        modest_msg_edit_window_attach_file_one (window, uri, allowed_size);
 
                if (total_size > allowed_size) {
-                       g_warning ("%s: total size: %u", 
+                       g_debug ("%s: total size: %u", 
                                   __FUNCTION__, (unsigned int)total_size);
                        break;
                }
@@ -2573,13 +2600,13 @@ modest_msg_edit_window_attach_file_one (ModestMsgEditWindow *window,
                    info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE) {
                        size = info->size;
                        if (size > allowed_size) {
-                               modest_platform_information_banner (NULL, NULL, 
-                                                                   _FM("sfil_ib_opening_not_allowed"));
+                               modest_platform_information_banner (NULL, NULL,
+                                                                   _("mail_ib_error_attachment_size"));
                                g_free (filename);
                                return 0;
                        }
                } else
-                       g_warning ("%s: could not get attachment size", __FUNCTION__);
+                       g_debug ("%s: could not get attachment size", __FUNCTION__);
                
                stream = create_stream_for_uri (uri);
                
@@ -3536,6 +3563,8 @@ body_insert_text (GtkTextBuffer *buffer,
        gint offset;
        glong utf8_len;
 
+       ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+
        gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (buffer), &end_iter);
 
        offset = gtk_text_iter_get_offset (&end_iter);
@@ -3561,8 +3590,11 @@ body_insert_text (GtkTextBuffer *buffer,
 
        }
        if (offset + utf8_len > MAX_BODY_LENGTH) {
-               hildon_banner_show_information (GTK_WIDGET (window), NULL, 
-                                               _CS("ckdg_ib_maximum_characters_reached"));
+               if (priv->max_chars_banner == NULL) {
+                       priv->max_chars_banner = hildon_banner_show_information (GTK_WIDGET (window), NULL, 
+                                                                                _CS("ckdg_ib_maximum_characters_reached"));
+                       g_object_weak_ref (G_OBJECT (priv->max_chars_banner), (GWeakNotify) max_chars_banner_unref, window);
+               }
        }
 }
 
@@ -3687,7 +3719,7 @@ gtk_text_iter_forward_search_insensitive (const GtkTextIter *iter,
                        result = TRUE;
                        if (!gtk_text_iter_forward_search (iter, found_text, GTK_TEXT_SEARCH_VISIBLE_ONLY|GTK_TEXT_SEARCH_TEXT_ONLY,
                                                           match_start, match_end, NULL)) {
-                               g_warning ("Matched string with collate, but not matched in model");
+                               g_debug ("Matched string with collate, but not matched in model");
                        }
                        g_free (found_text);
                }
@@ -3971,6 +4003,34 @@ static void update_signature (ModestMsgEditWindow *self,
        gtk_text_buffer_end_user_action (priv->text_buffer);
 }
 
+static void update_branding (ModestMsgEditWindow *self,
+                            const gchar *new_account)
+{
+       ModestMsgEditWindowPrivate *priv;
+       ModestAccountMgr *mgr;
+       const GdkPixbuf *new_icon = NULL;
+       gchar *new_label = NULL;
+
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
+
+       mgr = modest_runtime_get_account_mgr ();
+
+       modest_account_mgr_get_branding_from_recipient (mgr, new_account, &new_label, &new_icon, MODEST_ICON_SIZE_SMALL);
+       if (new_icon) {
+               gtk_image_set_from_pixbuf (GTK_IMAGE (priv->brand_icon), (GdkPixbuf *) new_icon);
+               gtk_widget_show (priv->brand_icon);
+       } else {
+               gtk_widget_hide (priv->brand_icon);
+       }
+       if (new_label) {
+               gtk_label_set_text (GTK_LABEL (priv->brand_label), new_label);
+               gtk_widget_show (priv->brand_label);
+               g_free (new_label);
+       } else {
+               gtk_widget_hide (priv->brand_label);
+       }
+}
+
 static void
 from_field_changed (HildonPickerButton *button,
                    ModestMsgEditWindow *self)
@@ -3985,6 +4045,7 @@ from_field_changed (HildonPickerButton *button,
        new_account = priv->last_from_account;
 
        update_signature (self, old_account, new_account);
+       update_branding (self, new_account);
 
 }
 
@@ -4307,7 +4368,7 @@ _create_addressbook_box (GtkSizeGroup *title_size_group, GtkSizeGroup *value_siz
 
        box = gtk_hbox_new (FALSE, 0);
 
-       align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
+       align = gtk_alignment_new (0.0, 0.0, 1.0, 0.0);
        gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, 0, MODEST_MARGIN_DEFAULT);
 
        abook_button = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT);
@@ -4329,3 +4390,14 @@ _create_addressbook_box (GtkSizeGroup *title_size_group, GtkSizeGroup *value_siz
   
        return box;  
 }
+
+static void 
+max_chars_banner_unref (ModestMsgEditWindow *self, GObject *old_ref)
+{
+       ModestMsgEditWindowPrivate *priv = NULL;
+
+       g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(self));
+
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
+       priv->max_chars_banner = NULL;
+}