Build fix
[modest] / src / hildon2 / modest-msg-view-window.c
index 01d7157..70effef 100644 (file)
@@ -66,6 +66,7 @@
 #include <glib/gstdio.h>
 #include <modest-debug.h>
 #include <modest-header-window.h>
+#include <modest-account-protocol.h>
 
 #define MYDOCS_ENV "MYDOCSDIR"
 #define DOCS_FOLDER ".documents"
@@ -227,6 +228,7 @@ static void setup_menu (ModestMsgViewWindow *self);
 static gboolean _modest_msg_view_window_map_event (GtkWidget *widget,
                                                   GdkEvent *event,
                                                   gpointer userdata);
+static void update_branding (ModestMsgViewWindow *self);
 
 
 /* list my signals */
@@ -237,10 +239,9 @@ enum {
 };
 
 static const GtkToggleActionEntry msg_view_toggle_action_entries [] = {
-       { "FindInMessage",    MODEST_TOOLBAR_ICON_FIND,    N_("qgn_toolb_gene_find"), NULL, NULL, G_CALLBACK (modest_msg_view_window_toggle_find_toolbar), FALSE },
+       { "FindInMessage",    MODEST_TOOLBAR_ICON_FIND,    N_("qgn_toolb_gene_find"), "<CTRL>F", NULL, G_CALLBACK (modest_msg_view_window_toggle_find_toolbar), FALSE },
 };
 
-
 #define MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                                     MODEST_TYPE_MSG_VIEW_WINDOW, \
                                                     ModestMsgViewWindowPrivate))
@@ -531,10 +532,6 @@ init_window (ModestMsgViewWindow *obj)
        gtk_box_pack_start (GTK_BOX(main_vbox), priv->main_scroll, TRUE, TRUE, 0);
        gtk_container_add   (GTK_CONTAINER(obj), main_vbox);
 
-       priv->find_toolbar = hildon_find_toolbar_new (NULL);
-       hildon_window_add_toolbar (HILDON_WINDOW (obj), GTK_TOOLBAR (priv->find_toolbar));
-       gtk_widget_set_no_show_all (priv->find_toolbar, TRUE);
-
        /* NULL-ize fields if the window is destroyed */
        g_signal_connect (priv->msg_view, "destroy", G_CALLBACK (gtk_widget_destroyed), &(priv->msg_view));
 
@@ -817,12 +814,20 @@ modest_msg_view_window_construct (ModestMsgViewWindow *self,
        modest_window_set_active_account (MODEST_WINDOW(obj), modest_account_name);
        modest_window_set_active_mailbox (MODEST_WINDOW(obj), mailbox);
 
-       g_signal_connect (G_OBJECT (priv->find_toolbar), "close", G_CALLBACK (modest_msg_view_window_find_toolbar_close), obj);
-       g_signal_connect (G_OBJECT (priv->find_toolbar), "search", G_CALLBACK (modest_msg_view_window_find_toolbar_search), obj);
-       priv->last_search = NULL;
-
+       /* First add out toolbar ... */
        modest_msg_view_window_show_toolbar (MODEST_WINDOW (obj), TRUE);
 
+       /* ... and later the find toolbar. This way find toolbar will
+          be shown over the other */
+       priv->find_toolbar = hildon_find_toolbar_new (NULL);
+       hildon_window_add_toolbar (HILDON_WINDOW (obj), GTK_TOOLBAR (priv->find_toolbar));
+       gtk_widget_set_no_show_all (priv->find_toolbar, TRUE);
+       g_signal_connect (G_OBJECT (priv->find_toolbar), "close", 
+                         G_CALLBACK (modest_msg_view_window_find_toolbar_close), obj);
+       g_signal_connect (G_OBJECT (priv->find_toolbar), "search", 
+                         G_CALLBACK (modest_msg_view_window_find_toolbar_search), obj);
+       priv->last_search = NULL;
+
        /* Init the clipboard actions dim status */
        modest_msg_view_grab_focus(MODEST_MSG_VIEW (priv->msg_view));
 
@@ -905,6 +910,7 @@ modest_msg_view_window_new_with_header_model (TnyMsg *msg,
 
        tny_msg_view_set_msg (TNY_MSG_VIEW (priv->msg_view), msg);
        update_window_title (MODEST_MSG_VIEW_WINDOW (window));
+       update_branding (MODEST_MSG_VIEW_WINDOW (window));
 
        /* gtk_widget_show_all (GTK_WIDGET (window)); */
        modest_msg_view_window_update_priority (window);
@@ -992,6 +998,7 @@ modest_msg_view_window_new_from_header_view (ModestHeaderView *header_view,
        }
 
        tny_msg_view_set_msg (TNY_MSG_VIEW (priv->msg_view), NULL);
+       update_branding (MODEST_MSG_VIEW_WINDOW (window));
 
        path = gtk_tree_row_reference_get_path (row_reference);
        if (gtk_tree_model_get_iter (priv->header_model, &iter, path)) {
@@ -1034,6 +1041,7 @@ modest_msg_view_window_new_for_search_result (TnyMsg *msg,
        priv->is_search_result = TRUE;
 
        tny_msg_view_set_msg (TNY_MSG_VIEW (priv->msg_view), msg);
+       update_branding (MODEST_MSG_VIEW_WINDOW (window));
        
        update_window_title (window);
        /* gtk_widget_show_all (GTK_WIDGET (window));*/
@@ -1083,6 +1091,7 @@ modest_msg_view_window_new_with_other_body (TnyMsg *msg,
                tny_msg_view_set_msg (TNY_MSG_VIEW (priv->msg_view), msg);
        }
        update_window_title (MODEST_MSG_VIEW_WINDOW (obj));
+       update_branding (MODEST_MSG_VIEW_WINDOW (obj));
 
        /* gtk_widget_show_all (GTK_WIDGET (obj)); */
 
@@ -1182,7 +1191,7 @@ modest_msg_view_window_on_row_inserted (GtkTreeModel *model,
        /* Setup row_reference for the actual msg. */
        priv->row_reference = gtk_tree_row_reference_new (priv->header_model, tree_path);
        if (priv->row_reference == NULL) {
-               g_warning("No reference for msg header item.");
+               g_warning("%s: No reference for msg header item.", __FUNCTION__);
                return;
        }
 
@@ -2088,6 +2097,7 @@ view_msg_cb (ModestMailOperation *mail_op,
                tny_msg_view_set_msg (TNY_MSG_VIEW (priv->msg_view), msg);
                modest_msg_view_window_update_priority (self);
                update_window_title (MODEST_MSG_VIEW_WINDOW (self));
+               update_branding (MODEST_MSG_VIEW_WINDOW (self));
                modest_msg_view_grab_focus (MODEST_MSG_VIEW (priv->msg_view));
        }
 
@@ -2585,7 +2595,7 @@ modest_msg_view_window_view_attachment (ModestMsgViewWindow *window,
                                                                       &msg_win);
                
                if (found) {
-                       g_warning ("window for this body is already being created");
+                       g_debug ("window for this body is already being created");
                } else {
 
                        /* it's not found, so create a new window for it */
@@ -2620,7 +2630,7 @@ modest_msg_view_window_view_attachment (ModestMsgViewWindow *window,
                if (found) {
                        /* if it's found, but there is no msg_win, it's probably in the process of being created;
                         * thus, we don't do anything */
-                       g_warning ("window for is already being created");
+                       g_debug ("window for is already being created");
                } else {
                        /* it's not found, so create a new window for it */
                        modest_window_mgr_register_header (mgr, header, attachment_uid); /* register the uid before building the window */
@@ -2661,7 +2671,7 @@ typedef struct
 static void save_mime_part_info_free (SaveMimePartInfo *info, gboolean with_struct);
 static gboolean idle_save_mime_part_show_result (SaveMimePartInfo *info);
 static gpointer save_mime_part_to_file (SaveMimePartInfo *info);
-static void save_mime_parts_to_file_with_checks (SaveMimePartInfo *info);
+static void save_mime_parts_to_file_with_checks (GtkWindow *parent, SaveMimePartInfo *info);
 
 static void
 save_mime_part_info_free (SaveMimePartInfo *info, gboolean with_struct)
@@ -2734,7 +2744,7 @@ save_mime_part_to_file (SaveMimePartInfo *info)
                g_slice_free (SaveMimePartPair, pair);
                info->pairs = g_list_delete_link (info->pairs, info->pairs);
        } else {
-               g_warning ("modest: could not create save attachment %s: %s\n", pair->filename, gnome_vfs_result_to_string (info->result));
+               g_warning ("Could not create save attachment %s: %s\n", pair->filename, gnome_vfs_result_to_string (info->result));
                save_mime_part_info_free (info, FALSE);
        }
 
@@ -2743,39 +2753,43 @@ save_mime_part_to_file (SaveMimePartInfo *info)
 }
 
 static void
-save_mime_parts_to_file_with_checks (SaveMimePartInfo *info)
+save_mime_parts_to_file_with_checks (GtkWindow *parent,
+                                    SaveMimePartInfo *info)
 {
        gboolean is_ok = TRUE;
         gint replaced_files = 0;
         const GList *files = info->pairs;
-        const GList *iter;
+        const GList *iter, *to_replace = NULL;
 
         for (iter = files; (iter != NULL) && (replaced_files < 2); iter = g_list_next(iter)) {
                 SaveMimePartPair *pair = iter->data;
                 if (modest_utils_file_exists (pair->filename)) {
                        replaced_files++;
+                       if (replaced_files == 1)
+                               to_replace = iter;
                 }
         }
        if (replaced_files) {
-               GtkWidget *confirm_overwrite_dialog;
+               gint response;
 
                if (replaced_files == 1) {
-                       SaveMimePartPair *pair = files->data;
+                       SaveMimePartPair *pair = to_replace->data;
                        const gchar *basename = strrchr (pair->filename, G_DIR_SEPARATOR) + 1;
+                       gchar *escaped_basename, *message;
 
-                       gchar *message = g_strdup_printf ("%s\n%s",
-                                                         _FM("docm_nc_replace_file"),
-                                                         (basename) ? basename : "");
-                       confirm_overwrite_dialog = hildon_note_new_confirmation (NULL, message);
+                       escaped_basename = g_uri_unescape_string (basename, NULL);
+                       message = g_strdup_printf ("%s\n%s",
+                                                  _FM("docm_nc_replace_file"),
+                                                  (escaped_basename) ? escaped_basename : "");
+                       response = modest_platform_run_confirmation_dialog (parent, message);
                        g_free (message);
+                       g_free (escaped_basename);
                } else {
-                       confirm_overwrite_dialog = hildon_note_new_confirmation (NULL,
-                                                                                _FM("docm_nc_replace_multiple"));
+                       response = modest_platform_run_confirmation_dialog (parent,
+                                                                           _FM("docm_nc_replace_multiple"));
                }
-               if (gtk_dialog_run (GTK_DIALOG (confirm_overwrite_dialog)) != GTK_RESPONSE_OK)
+               if (response != GTK_RESPONSE_OK)
                        is_ok = FALSE;
-
-               gtk_widget_destroy (confirm_overwrite_dialog);
        }
 
        if (!is_ok) {
@@ -2852,7 +2866,7 @@ save_attachments_response (GtkDialog *dialog,
                SaveMimePartInfo *info = g_slice_new0 (SaveMimePartInfo);
                info->pairs = files_to_save;
                info->result = TRUE;
-               save_mime_parts_to_file_with_checks (info);
+               save_mime_parts_to_file_with_checks ((GtkWindow *) dialog, info);
        }
 
  end:
@@ -2906,14 +2920,17 @@ modest_msg_view_window_save_attachments (ModestMsgViewWindow *window,
                        filename = g_strdup (tny_mime_part_get_filename (mime_part));
                } else {
                        /* TODO: show any error? */
-                       g_warning ("Tried to save a non-file attachment");
+                       g_warning ("%s: Tried to save a non-file attachment", __FUNCTION__);
                        g_object_unref (mime_parts);
                        return;
                }
                g_object_unref (mime_part);
        } else {
-               save_multiple_str = g_strdup_printf (_FM("sfil_va_number_of_objects_attachments"), 
-                                                    tny_list_get_length (mime_parts));
+               gint num = tny_list_get_length (mime_parts);
+               save_multiple_str = g_strdup_printf (dngettext("hildon-fm",
+                                                              "sfil_va_number_of_objects_attachment",
+                                                             "sfil_va_number_of_objects_attachments",
+                                                             num), num);
        }
 
        save_dialog = hildon_file_chooser_dialog_new (GTK_WINDOW (window), 
@@ -3069,6 +3086,7 @@ modest_msg_view_window_remove_attachments (ModestMsgViewWindow *window, gboolean
        tny_msg_rewrite_cache (msg);
        tny_msg_view_set_msg (TNY_MSG_VIEW (priv->msg_view), msg);
        g_object_unref (msg);
+       update_branding (MODEST_MSG_VIEW_WINDOW (window));
 
        g_object_unref (mime_parts);
 
@@ -3445,3 +3463,34 @@ modest_msg_view_window_reload (ModestMsgViewWindow *self)
 
        g_object_unref (header);
 }
+
+static void
+update_branding (ModestMsgViewWindow *self)
+{
+       const gchar *account; 
+       const gchar *mailbox;
+       ModestAccountMgr *mgr;
+       ModestProtocol *protocol = NULL;
+       gchar *service_name = NULL;
+       const GdkPixbuf *service_icon = NULL;
+       ModestMsgViewWindowPrivate *priv;
+
+       priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (self);
+
+       account = modest_window_get_active_account (MODEST_WINDOW (self));
+       mailbox = modest_window_get_active_mailbox (MODEST_WINDOW (self));
+
+       mgr = modest_runtime_get_account_mgr ();
+       
+       if (modest_account_mgr_account_is_multimailbox (mgr, account, &protocol)) {
+               if (MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
+                       service_name = modest_account_protocol_get_service_name (MODEST_ACCOUNT_PROTOCOL (protocol),
+                                                                                account, mailbox);
+                       service_icon = modest_account_protocol_get_service_icon (MODEST_ACCOUNT_PROTOCOL (protocol),
+                                                                                account, mailbox, MODEST_ICON_SIZE_SMALL);
+               }
+       }
+
+       modest_msg_view_set_branding (MODEST_MSG_VIEW (priv->msg_view), service_name, service_icon);
+       g_free (service_name);
+}