* In the message viewer, update window title after
[modest] / src / maemo / modest-msg-view-window.c
index e6064c4..d49fda2 100644 (file)
@@ -140,7 +140,9 @@ static void on_move_focus (ModestMsgViewWindow *window,
 
 static void view_msg_cb         (ModestMailOperation *mail_op, 
                                 TnyHeader *header, 
+                                gboolean canceled,
                                 TnyMsg *msg, 
+                                GError *error,
                                 gpointer user_data);
 
 static void set_toolbar_mode    (ModestMsgViewWindow *self, 
@@ -149,6 +151,7 @@ static void set_toolbar_mode    (ModestMsgViewWindow *self,
 static void update_window_title (ModestMsgViewWindow *window);
 
 static gboolean set_toolbar_transfer_mode     (ModestMsgViewWindow *self); 
+static void init_window (ModestMsgViewWindow *obj);
 
 
 /* list my signals */
@@ -324,8 +327,55 @@ static void
 modest_msg_view_window_init (ModestMsgViewWindow *obj)
 {
        ModestMsgViewWindowPrivate *priv;
+       ModestWindowPrivate *parent_priv = NULL;
+       GtkActionGroup *action_group = NULL;
+       GError *error = NULL;
+       GdkPixbuf *window_icon;
+
        priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(obj);
+       parent_priv = MODEST_WINDOW_GET_PRIVATE(obj);
+       parent_priv->ui_manager = gtk_ui_manager_new();
+
+       action_group = gtk_action_group_new ("ModestMsgViewWindowActions");
+       gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
+
+       /* Add common actions */
+       gtk_action_group_add_actions (action_group,
+                                     modest_action_entries,
+                                     G_N_ELEMENTS (modest_action_entries),
+                                     obj);
+       gtk_action_group_add_toggle_actions (action_group,
+                                            modest_toggle_action_entries,
+                                            G_N_ELEMENTS (modest_toggle_action_entries),
+                                            obj);
+       gtk_action_group_add_toggle_actions (action_group,
+                                            msg_view_toggle_action_entries,
+                                            G_N_ELEMENTS (msg_view_toggle_action_entries),
+                                            obj);
+       gtk_action_group_add_radio_actions (action_group,
+                                           msg_view_zoom_action_entries,
+                                           G_N_ELEMENTS (msg_view_zoom_action_entries),
+                                           100,
+                                           G_CALLBACK (modest_ui_actions_on_change_zoom),
+                                           obj);
+
+       gtk_ui_manager_insert_action_group (parent_priv->ui_manager, action_group, 0);
+       g_object_unref (action_group);
+
+       /* Load the UI definition */
+       gtk_ui_manager_add_ui_from_file (parent_priv->ui_manager, MODEST_UIDIR "modest-msg-view-window-ui.xml",
+                                        &error);
+       if (error) {
+               g_printerr ("modest: could not merge modest-msg-view-window-ui.xml: %s\n", error->message);
+               g_error_free (error);
+               error = NULL;
+       }
+       /* ****** */
 
+       /* Add accelerators */
+       gtk_window_add_accel_group (GTK_WINDOW (obj), 
+                                   gtk_ui_manager_get_accel_group (parent_priv->ui_manager));
+       
        priv->is_search_result = FALSE;
 
        priv->msg_view      = NULL;
@@ -346,6 +396,16 @@ modest_msg_view_window_init (ModestMsgViewWindow *obj)
        priv->remove_attachment_banner = NULL;
        priv->msg_uid = NULL;
        
+       /* Init window */
+       init_window (MODEST_MSG_VIEW_WINDOW(obj));
+       /* Set window icon */
+       window_icon = modest_platform_get_icon (MODEST_APP_MSG_VIEW_ICON); 
+       if (window_icon) {
+               gtk_window_set_icon (GTK_WINDOW (obj), window_icon);
+               g_object_unref (window_icon);
+       }
+
+
        modest_window_mgr_register_help_id (modest_runtime_get_window_mgr(),
                                            GTK_WINDOW(obj),"applications_email_viewer");
 }
@@ -536,7 +596,6 @@ init_window (ModestMsgViewWindow *obj)
        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->clipboard_change_handler = g_signal_connect (G_OBJECT (gtk_clipboard_get (GDK_SELECTION_PRIMARY)), "owner-change", G_CALLBACK (modest_msg_view_window_clipboard_owner_change), obj);
        gtk_widget_show_all (GTK_WIDGET(main_vbox));
 }
 
@@ -701,9 +760,6 @@ modest_msg_view_window_construct (ModestMsgViewWindow *self,
        ModestDimmingRulesGroup *menu_rules_group = NULL;
        ModestDimmingRulesGroup *toolbar_rules_group = NULL;
        ModestDimmingRulesGroup *clipboard_rules_group = NULL;
-       GtkActionGroup *action_group = NULL;
-       GError *error = NULL;
-       GdkPixbuf *window_icon;
 
        obj = G_OBJECT (self);
        priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(obj);
@@ -711,49 +767,12 @@ modest_msg_view_window_construct (ModestMsgViewWindow *self,
 
        priv->msg_uid = g_strdup (msg_uid);
 
-       parent_priv->ui_manager = gtk_ui_manager_new();
        parent_priv->ui_dimming_manager = modest_ui_dimming_manager_new();
 
-       action_group = gtk_action_group_new ("ModestMsgViewWindowActions");
-       gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
-
        menu_rules_group = modest_dimming_rules_group_new ("ModestMenuDimmingRules", FALSE);
        toolbar_rules_group = modest_dimming_rules_group_new ("ModestToolbarDimmingRules", TRUE);
        clipboard_rules_group = modest_dimming_rules_group_new ("ModestClipboardDimmingRules", FALSE);
 
-       /* Add common actions */
-       gtk_action_group_add_actions (action_group,
-                                     modest_action_entries,
-                                     G_N_ELEMENTS (modest_action_entries),
-                                     obj);
-       gtk_action_group_add_toggle_actions (action_group,
-                                            modest_toggle_action_entries,
-                                            G_N_ELEMENTS (modest_toggle_action_entries),
-                                            obj);
-       gtk_action_group_add_toggle_actions (action_group,
-                                            msg_view_toggle_action_entries,
-                                            G_N_ELEMENTS (msg_view_toggle_action_entries),
-                                            obj);
-       gtk_action_group_add_radio_actions (action_group,
-                                           msg_view_zoom_action_entries,
-                                           G_N_ELEMENTS (msg_view_zoom_action_entries),
-                                           100,
-                                           G_CALLBACK (modest_ui_actions_on_change_zoom),
-                                           obj);
-
-       gtk_ui_manager_insert_action_group (parent_priv->ui_manager, action_group, 0);
-       g_object_unref (action_group);
-
-       /* Load the UI definition */
-       gtk_ui_manager_add_ui_from_file (parent_priv->ui_manager, MODEST_UIDIR "modest-msg-view-window-ui.xml",
-                                        &error);
-       if (error) {
-               g_printerr ("modest: could not merge modest-msg-view-window-ui.xml: %s\n", error->message);
-               g_error_free (error);
-               error = NULL;
-       }
-       /* ****** */
-
        /* Add common dimming rules */
        modest_dimming_rules_group_add_rules (menu_rules_group, 
                                              modest_msg_view_menu_dimming_entries,
@@ -776,23 +795,11 @@ modest_msg_view_window_construct (ModestMsgViewWindow *self,
        g_object_unref (toolbar_rules_group);
        g_object_unref (clipboard_rules_group);
 
-       /* Add accelerators */
-       gtk_window_add_accel_group (GTK_WINDOW (obj), 
-                                   gtk_ui_manager_get_accel_group (parent_priv->ui_manager));
-       
-       /* Init window */
-       init_window (MODEST_MSG_VIEW_WINDOW(obj));
        restore_settings (MODEST_MSG_VIEW_WINDOW(obj));
        
-       /* Set window icon */
-       window_icon = modest_platform_get_icon (MODEST_APP_MSG_VIEW_ICON); 
-       if (window_icon) {
-               gtk_window_set_icon (GTK_WINDOW (obj), window_icon);
-               g_object_unref (window_icon);
-       }
-
        /* g_signal_connect (G_OBJECT(obj), "delete-event", G_CALLBACK(on_delete_event), obj); */
 
+       priv->clipboard_change_handler = g_signal_connect (G_OBJECT (gtk_clipboard_get (GDK_SELECTION_PRIMARY)), "owner-change", G_CALLBACK (modest_msg_view_window_clipboard_owner_change), obj);
        g_signal_connect (G_OBJECT(priv->msg_view), "activate_link",
                          G_CALLBACK (modest_ui_actions_on_msg_link_clicked), obj);
        g_signal_connect (G_OBJECT(priv->msg_view), "link_hover",
@@ -855,8 +862,10 @@ modest_msg_view_window_new_with_header_model (TnyMsg *msg,
        TnyFolder *header_folder = NULL;
        ModestHeaderView *header_view = NULL;
        ModestWindow *main_window = NULL;
-       
-       window = g_object_new(MODEST_TYPE_MSG_VIEW_WINDOW, NULL);
+       ModestWindowMgr *mgr = NULL;
+
+       mgr = modest_runtime_get_window_mgr ();
+       window = MODEST_MSG_VIEW_WINDOW (modest_window_mgr_get_msg_view_window (mgr));
        g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (window), NULL);
 
        modest_msg_view_window_construct (window, modest_account_name, msg_uid);
@@ -866,8 +875,7 @@ modest_msg_view_window_new_with_header_model (TnyMsg *msg,
        /* Remember the message list's TreeModel so we can detect changes 
         * and change the list selection when necessary: */
 
-       main_window = modest_window_mgr_get_main_window(
-               modest_runtime_get_window_mgr(), FALSE); /* don't create */
+       main_window = modest_window_mgr_get_main_window(mgr, FALSE); /* don't create */
        if (!main_window) {
                g_warning ("%s: BUG: no main window", __FUNCTION__);
                return NULL;
@@ -911,10 +919,9 @@ modest_msg_view_window_new_with_header_model (TnyMsg *msg,
                                MODEST_HEADER_VIEW_OBSERVER(window));
        }
 
-       gtk_widget_show_all (GTK_WIDGET (window));
-
        tny_msg_view_set_msg (TNY_MSG_VIEW (priv->msg_view), msg);
        update_window_title (MODEST_MSG_VIEW_WINDOW (window));
+       gtk_widget_show_all (GTK_WIDGET (window));
 
        modest_msg_view_window_update_priority (window);
 
@@ -931,8 +938,10 @@ modest_msg_view_window_new_for_search_result (TnyMsg *msg,
 {
        ModestMsgViewWindow *window = NULL;
        ModestMsgViewWindowPrivate *priv = NULL;
+       ModestWindowMgr *mgr = NULL;
 
-       window = g_object_new(MODEST_TYPE_MSG_VIEW_WINDOW, NULL);
+       mgr = modest_runtime_get_window_mgr ();
+       window = MODEST_MSG_VIEW_WINDOW (modest_window_mgr_get_msg_view_window (mgr));
        g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (window), NULL);
        modest_msg_view_window_construct (window, modest_account_name, msg_uid);
 
@@ -943,6 +952,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_window_title (window);
 
        return MODEST_WINDOW(window);
 }
@@ -953,15 +963,18 @@ modest_msg_view_window_new_for_attachment (TnyMsg *msg,
                            const gchar *msg_uid)
 {
        GObject *obj = NULL;
-       ModestMsgViewWindowPrivate *priv;
+       ModestMsgViewWindowPrivate *priv;       
+       ModestWindowMgr *mgr = NULL;
+
        g_return_val_if_fail (msg, NULL);
-       
-       obj = g_object_new(MODEST_TYPE_MSG_VIEW_WINDOW, NULL);
+       mgr = modest_runtime_get_window_mgr ();
+       obj = G_OBJECT (modest_window_mgr_get_msg_view_window (mgr));
        priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (obj);
        modest_msg_view_window_construct (MODEST_MSG_VIEW_WINDOW (obj), 
                modest_account_name, msg_uid);
 
        tny_msg_view_set_msg (TNY_MSG_VIEW (priv->msg_view), msg);
+       update_window_title (MODEST_MSG_VIEW_WINDOW (obj));
 
        return MODEST_WINDOW(obj);
 }
@@ -1096,10 +1109,9 @@ void modest_msg_view_window_update_model_replaced(
         * not care about it's model (msg list). Else if the
         * header-view shows the folder the msg shown by us is in, we
         * shall replace our model reference and make some check. */
-       if(tny_folder_id == NULL ||
-                       !g_str_equal(tny_folder_id, priv->header_folder_id))
+       if(tny_folder_id == NULL || !g_str_equal(tny_folder_id, priv->header_folder_id))
                return;
-
+       
        /* Model is changed(replaced), so we should forget the old
         * one. Because there might be other references and there
         * might be some change on the model even if we unreferenced
@@ -1133,9 +1145,6 @@ void modest_msg_view_window_update_model_replaced(
 
        modest_ui_actions_check_toolbar_dimming_rules(MODEST_WINDOW(window));
 
-       if(tny_folder_id == NULL)
-               return;
-
        g_assert(model != NULL);
 
        /* Also we must connect to the new model for row insertions.
@@ -1207,15 +1216,12 @@ modest_msg_view_window_get_header (ModestMsgViewWindow *self)
 TnyMsg*
 modest_msg_view_window_get_message (ModestMsgViewWindow *self)
 {
-       ModestMsgView *msg_view;
        ModestMsgViewWindowPrivate *priv;
-
+       
        g_return_val_if_fail (self, NULL);
-
+       
        priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(self);
-
-       msg_view = MODEST_MSG_VIEW (priv->msg_view);
-
+       
        return tny_msg_view_get_msg (TNY_MSG_VIEW (priv->msg_view));
 }
 
@@ -1777,7 +1783,9 @@ modest_msg_view_window_select_previous_message (ModestMsgViewWindow *window)
 static void
 view_msg_cb (ModestMailOperation *mail_op, 
             TnyHeader *header, 
+            gboolean canceled,
             TnyMsg *msg, 
+            GError *error,
             gpointer user_data)
 {
        ModestMsgViewWindow *self = NULL;