* src/maemo/modest-msg-edit-window.c:
[modest] / src / maemo / modest-msg-view-window.c
index 4503d96..bc8dcf2 100644 (file)
@@ -38,6 +38,7 @@
 #include <modest-msg-view-window.h>
 #include <modest-attachments-view.h>
 #include <modest-main-window-ui.h>
+#include "modest-msg-view-window-ui-dimming.h"
 #include <modest-widget-memory.h>
 #include <modest-runtime.h>
 #include <modest-window-priv.h>
@@ -48,6 +49,7 @@
 #include "modest-defs.h"
 #include "modest-hildon-includes.h"
 #include <gtkhtml/gtkhtml-search.h>
+#include "modest-ui-dimming-manager.h"
 #include <gdk/gdkkeysyms.h>
 
 #define DEFAULT_FOLDER "MyDocs/.documents"
@@ -96,7 +98,7 @@ static void         on_queue_changed                     (ModestMailOperationQue
                                                          ModestMailOperationQueueNotification type,
                                                          ModestMsgViewWindow *self);
 
-static void view_msg_cb (const GObject *obj, const TnyMsg *msg, gpointer user_data);
+static void view_msg_cb (ModestMailOperation *mail_op, TnyHeader *header, TnyMsg *msg, gpointer user_data);
 
 static void set_toolbar_mode (ModestMsgViewWindow *self, 
                              ModestToolBarModes mode);
@@ -416,20 +418,20 @@ modest_msg_view_window_finalize (GObject *obj)
        ModestMsgViewWindowPrivate *priv;
 
        priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (obj);
-       if (priv->header_model != NULL) {
-               g_object_unref (priv->header_model);
-               priv->header_model = NULL;
-       }
        if (priv->clipboard_change_handler > 0) {
                g_signal_handler_disconnect (gtk_clipboard_get (GDK_SELECTION_PRIMARY), priv->clipboard_change_handler);
                priv->clipboard_change_handler = 0;
        }
-
-       /* disconnet operations queue observer */
        if (priv->queue_change_handler > 0) {
                g_signal_handler_disconnect (G_OBJECT (modest_runtime_get_mail_operation_queue ()), priv->queue_change_handler);
                priv->queue_change_handler = 0;
        }
+       if (priv->header_model != NULL) {
+               g_object_unref (priv->header_model);
+               priv->header_model = NULL;
+       }
+
+       /* disconnet operations queue observer */
        
        if (priv->progress_bar_timeout > 0) {
                g_source_remove (priv->progress_bar_timeout);
@@ -480,24 +482,31 @@ modest_msg_view_window_new_with_header_model (TnyMsg *msg, const gchar *account_
 ModestWindow *
 modest_msg_view_window_new (TnyMsg *msg, const gchar *account_name)
 {
-       GObject *obj;
-       ModestMsgViewWindowPrivate *priv;
-       ModestWindowPrivate *parent_priv;
-       GtkActionGroup *action_group;
+       ModestMsgViewWindow *self = NULL;
+       GObject *obj = NULL;
+       ModestMsgViewWindowPrivate *priv = NULL;
+       ModestWindowPrivate *parent_priv = NULL;
+       ModestDimmingRulesGroup *rules_group = NULL;
+       GtkActionGroup *action_group = NULL;
        GError *error = NULL;
        GdkPixbuf *window_icon = NULL;
-       GtkAction *action;
+       GtkAction *action = NULL;
 
        g_return_val_if_fail (msg, NULL);
        
        obj = g_object_new(MODEST_TYPE_MSG_VIEW_WINDOW, NULL);
        priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(obj);
        parent_priv = MODEST_WINDOW_GET_PRIVATE(obj);
-       
+       self = MODEST_MSG_VIEW_WINDOW (obj);
+
        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);
 
+       rules_group = modest_dimming_rules_group_new ("ModestCommonDimmingRules");
+
        /* Add common actions */
        gtk_action_group_add_actions (action_group,
                                      modest_action_entries,
@@ -531,6 +540,16 @@ modest_msg_view_window_new (TnyMsg *msg, const gchar *account_name)
        }
        /* ****** */
 
+       /* Add common dimming rules */
+       modest_dimming_rules_group_add_rules (rules_group, 
+                                             modest_msg_view_dimming_entries,
+                                             G_N_ELEMENTS (modest_msg_view_dimming_entries),
+                                             self);
+
+       /* Insert dimming rules group for this window */
+       modest_ui_dimming_manager_insert_rules_group (parent_priv->ui_dimming_manager, rules_group);
+       g_object_unref (rules_group);
+
        /* Add accelerators */
        gtk_window_add_accel_group (GTK_WINDOW (obj), 
                                    gtk_ui_manager_get_accel_group (parent_priv->ui_manager));
@@ -645,6 +664,8 @@ modest_msg_view_window_get_message_uid (ModestMsgViewWindow *self)
                retval = tny_header_get_uid (header);
                g_object_unref (header);
        }
+       g_object_unref (msg);
+
        return retval;
 }
 
@@ -950,7 +971,7 @@ modest_msg_view_window_select_next_message (ModestMsgViewWindow *window)
                                tny_header_set_flags (header, flags | TNY_HEADER_FLAG_SEEN);
 
                        /* New mail operation */
-                       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(window));
+                       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(window));
                        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
                        modest_mail_operation_get_msg (mail_op, header, view_msg_cb, NULL);
                        g_object_unref (mail_op);
@@ -997,7 +1018,7 @@ modest_msg_view_window_select_first_message (ModestMsgViewWindow *self)
                tny_header_set_flags (header, flags | TNY_HEADER_FLAG_SEEN);
        
        /* New mail operation */
-       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(self));
+       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(self));
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
        modest_mail_operation_get_msg (mail_op, header, view_msg_cb, NULL);
        g_object_unref (mail_op);
@@ -1044,7 +1065,7 @@ modest_msg_view_window_select_previous_message (ModestMsgViewWindow *window)
                                tny_header_set_flags (header, flags | TNY_HEADER_FLAG_SEEN);
 
                        /* New mail operation */
-                       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(window));
+                       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(window));
                        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
                        modest_mail_operation_get_msg (mail_op, header, view_msg_cb, NULL);             
 
@@ -1056,20 +1077,24 @@ modest_msg_view_window_select_previous_message (ModestMsgViewWindow *window)
 }
 
 static void
-view_msg_cb(const GObject *obj, const TnyMsg *msg, gpointer user_data)
+view_msg_cb (ModestMailOperation *mail_op, 
+            TnyHeader *header, 
+            TnyMsg *msg, 
+            gpointer user_data)
 {
        ModestMsgViewWindow *self = NULL;
        ModestMsgViewWindowPrivate *priv = NULL;
-       TnyMsg *new_msg = NULL;
-       g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (obj));
+
        g_return_if_fail (TNY_IS_MSG (msg));
-       self = MODEST_MSG_VIEW_WINDOW (obj);
+
+       /* Get the window */ 
+       self = (ModestMsgViewWindow *) modest_mail_operation_get_source (mail_op);
+       g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (self));
+
        priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (self);
 
        /* Set new message */
-       new_msg = g_object_ref (G_OBJECT(msg));
-       modest_msg_view_set_message (MODEST_MSG_VIEW (priv->msg_view), new_msg);
+       modest_msg_view_set_message (MODEST_MSG_VIEW (priv->msg_view), msg);
        modest_msg_view_window_update_dimmed (self);
        modest_msg_view_window_update_priority (self);
        gtk_widget_grab_focus (priv->msg_view);
@@ -1102,6 +1127,7 @@ modest_msg_view_window_get_folder_type (ModestMsgViewWindow *window)
 
                        g_object_unref (folder);
                }
+               g_object_unref (msg);
        }
 
        return folder_type;
@@ -1406,7 +1432,7 @@ on_queue_changed (ModestMailOperationQueue *queue,
 {
        GSList *tmp;
        ModestMsgViewWindowPrivate *priv;
-       ModestMailOperationId op_id;
+       ModestMailOperationTypeOperation op_type;
        ModestToolBarModes mode;
        
        g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (self));
@@ -1417,10 +1443,10 @@ on_queue_changed (ModestMailOperationQueue *queue,
            return;
 
        /* Get toolbar mode from operation id*/
-       op_id = modest_mail_operation_get_id (mail_op);
-       switch (op_id) {
-       case MODEST_MAIL_OPERATION_ID_SEND:
-       case MODEST_MAIL_OPERATION_ID_RECEIVE:
+       op_type = modest_mail_operation_get_type_operation (mail_op);
+       switch (op_type) {
+       case MODEST_MAIL_OPERATION_TYPE_SEND:
+       case MODEST_MAIL_OPERATION_TYPE_RECEIVE:
                mode = TOOLBAR_MODE_TRANSFER;
                break;
        default: