* widgets/modest-window.c: Add a method to get action from its private
authorJavier Fernandez Garcia-Boente <jfernandez@igalia.com>
Tue, 29 May 2007 15:39:23 +0000 (15:39 +0000)
committerJavier Fernandez Garcia-Boente <jfernandez@igalia.com>
Tue, 29 May 2007 15:39:23 +0000 (15:39 +0000)
ui_manager instance. A new UI Dimming Manager was added too, and methods
for calling this dimming manager to check dimming rules.

* modest-mail-operation.c: Add a new private field into mail operation
to set an user defined callback to perform actions when some error
is detected during mail operation execution.
Add support to cancel tinymail operations, aborting camel operaiton
in progress. To identify operaiton to cancel, a new private field was
added to private section of mail_operation: account.

* modest-ui-dimming-manager.c: A new dimming rules design apporach.
very similar to UI Manager pattern.

pmo-trunk-r1988

20 files changed:
src/Makefile.am
src/maemo/modest-main-window-ui-dimming.h [new file with mode: 0644]
src/maemo/modest-main-window-ui.h
src/maemo/modest-main-window.c
src/modest-dimming-rule.c [new file with mode: 0644]
src/modest-dimming-rule.h [new file with mode: 0644]
src/modest-dimming-rules-group-priv.h [new file with mode: 0644]
src/modest-dimming-rules-group.c [new file with mode: 0644]
src/modest-dimming-rules-group.h [new file with mode: 0644]
src/modest-mail-operation.c
src/modest-ui-actions.c
src/modest-ui-actions.h
src/modest-ui-dimming-manager.c [new file with mode: 0644]
src/modest-ui-dimming-manager.h [new file with mode: 0644]
src/modest-ui-dimming-rules.c [new file with mode: 0644]
src/modest-ui-dimming-rules.h [new file with mode: 0644]
src/widgets/modest-folder-view.c
src/widgets/modest-window-priv.h
src/widgets/modest-window.c
src/widgets/modest-window.h

index 7cd6ea6..ce14819 100644 (file)
@@ -53,6 +53,12 @@ modest_SOURCES=\
        modest-mail-operation-queue.h \
        modest-mail-operation.c \
        modest-mail-operation.h \
+       modest-ui-dimming-manager.c \
+       modest-ui-dimming-manager.h \
+       modest-dimming-rules-group.c \
+       modest-dimming-rules-group.h \
+       modest-dimming-rule.c \
+       modest-dimming-rule.h \
        modest-main.c\
        modest-marshal.c \
        modest-marshal.h \
@@ -89,6 +95,8 @@ modest_SOURCES=\
        modest-tny-send-queue.h\
        modest-ui-actions.c\
        modest-ui-actions.h\
+       modest-ui-dimming-rules.c\
+       modest-ui-dimming-rules.h\
        modest-widget-memory-priv.h \
        modest-widget-memory.c\
        modest-widget-memory.h\
diff --git a/src/maemo/modest-main-window-ui-dimming.h b/src/maemo/modest-main-window-ui-dimming.h
new file mode 100644 (file)
index 0000000..0f0394a
--- /dev/null
@@ -0,0 +1,92 @@
+#ifndef __MODEST_MAIN_WINDOW_UI_DIMMING_PRIV_H__
+#define __MODEST_MAIN_WINDOW_UI_DIMMING_PRIV_H__
+
+#include "modest-dimming-rules-group.h"
+#include "modest-ui-dimming-rules.h"
+
+G_BEGIN_DECLS
+
+
+/* Dimming rules entries */
+static const ModestDimmingEntry modest_dimming_entries [] = {
+
+       /* Email Menu */
+       { "/MenuBar/EmailMenu/EmailNewMainMenu", NULL },
+       { "/MenuBar/EmailMenu/EmailNewMainMenu/EmailNewMessageMenu", NULL },
+       { "/MenuBar/EmailMenu/EmailNewMainMenu/EmailNewFolderMenu", G_CALLBACK(modest_ui_dimming_rules_on_new_folder) },
+       { "/MenuBar/EmailMenu/EmailOpenMenu", G_CALLBACK(modest_ui_dimming_rules_on_open_msg) },
+       { "/MenuBar/EmailMenu/EmailReplyMenu", G_CALLBACK(modest_ui_dimming_rules_on_reply_msg) },
+       { "/MenuBar/EmailMenu/EmailReplyAllMenu", G_CALLBACK(modest_ui_dimming_rules_on_reply_msg) },
+       { "/MenuBar/EmailMenu/EmailForwardMenu",  G_CALLBACK(modest_ui_dimming_rules_on_reply_msg)},
+       { "/MenuBar/EmailMenu/EmailContentsMenu", G_CALLBACK(modest_ui_dimming_rules_on_contents_msg) },
+       { "/MenuBar/EmailMenu/EmailPurgeAttachmentsMenu", NULL },
+       { "/MenuBar/EmailMenu/EmailDeleteMenu", NULL },
+       { "/MenuBar/EmailMenu/EmailDetailsMenu", NULL },
+
+       /* Edit Menu */
+       { "/MenuBar/EditMenu", NULL },
+       { "/MenuBar/EditMenu/EditUndoMenu", NULL },
+       { "/MenuBar/EditMenu/EditCutMenu", NULL },
+       { "/MenuBar/EditMenu/EditCopyMenu", NULL },
+       { "/MenuBar/EditMenu/EditPasteMenu", NULL },
+       { "/MenuBar/EditMenu/EditSelectAllMenu", NULL },
+       { "/MenuBar/EditMenu/EditMarkAsReadMenu", NULL },
+       { "/MenuBar/EditMenu/EditMarkAsUnreadMenu", NULL },
+       { "/MenuBar/EditMenu/EditMoveToMenu", NULL },
+
+       /* View Menu */
+       { "/MenuBar/ViewMenu", NULL },
+       { "/MenuBar/ViewMenu/ViewSortMenu", NULL },
+       { "/MenuBar/ViewMenu/ViewToggleFoldersMenu", NULL },
+       { "/MenuBar/ViewMenu/ViewToggleFullscreenMenu", NULL },
+       { "/MenuBar/ViewMenu/ViewShowToolbarMainMenu", NULL },
+       { "/MenuBar/ViewMenu/ViewShowToolbarMainMenu/ViewShowToolbarNormalScreenMenu", NULL },
+       { "/MenuBar/ViewMenu/ViewShowToolbarMainMenu/ViewShowToolbarFullScreenMenu", NULL },
+       
+       /* Tools Menu */
+       { "/MenuBar/ToolsMenu", NULL },
+       { "/MenuBar/ToolsMenu/ToolsSettingsMenu", NULL },
+       { "/MenuBar/ToolsMenu/ToolsAccountsMenu", NULL },
+       { "/MenuBar/ToolsMenu/ToolsSMTPServersMenu", NULL },
+       { "/MenuBar/ToolsMenu/ToolsSendReceiveMainMenu", NULL },
+       { "/MenuBar/ToolsMenu/ToolsSendReceiveMainMenu/ToolsSendReceiveAllMenu", NULL },
+       { "/MenuBar/ToolsMenu/ToolsSendReceiveCancelSendingMenu", NULL },
+       { "/MenuBar/ToolsMenu/ToolsContactsMenu", NULL },
+       { "/MenuBar/ToolsMenu/ToolsSearchMessagesMenu", NULL },
+       { "/MenuBar/ToolsMenu/ToolsHelpMenu", NULL },
+
+       /* Close Menu */
+       { "/MenuBar/CloseMenu", NULL },
+       { "/MenuBar/ToolsMenu/CloseWindowMenu", NULL },
+       { "/MenuBar/ToolsMenu/CloseAllWindowsMenu", NULL },
+
+       /* Toolbar */
+       { "/Toolbar/ToolbarMessageNew", NULL },
+       { "/Toolbar/ToolbarMessageReply", NULL },
+       { "/Toolbar/ToolbarDeleteMessage", NULL },
+       { "/Toolbar/ToolbarToggleView", NULL },
+       { "/Toolbar/ToolbarSort", NULL },
+       { "/Toolbar/ToolbarSendReceive", NULL },
+       { "/Toolbar/ToolbarCancel", NULL },
+
+       /* Contextual Menus (Header View) */
+       { "/HeaderViewCSM/EmailReply", NULL },
+       { "/HeaderViewCSM/EmailForward", NULL },
+
+       /* Contextual Menus (Folder View) */
+       { "/FolderViewCSM/FolderViewCSMNewFolder", G_CALLBACK(modest_ui_dimming_rules_on_new_folder) },
+       { "/FolderViewCSM/FolderViewCSMRenameFolder", NULL },
+       { "/FolderViewCSM/FolderViewCSMPasteMsgs", NULL },
+       { "/FolderViewCSM/FolderViewCSMDeleteFolder", NULL },
+       { "/FolderViewCSM/FolderViewCSMSearchMessages", NULL },
+       { "/FolderViewCSM/FolderViewCSMHelp", NULL },
+
+       /* Contextual Menus (Toolbar) */
+       { "/ToolbarReplyCSM/ToolbarMessageForward", NULL },
+       { "/ToolbarReplyCSM/ToolbarMessageReplyAll", NULL },
+       { "/ToolbarReplyCSM/ToolbarMessageReply", NULL },
+       
+};
+
+G_END_DECLS
+#endif /* __MODEST_MAIN_WINDOW_UI_PRIV_H__ */
index f3db69f..825fdfa 100644 (file)
@@ -40,7 +40,7 @@ G_BEGIN_DECLS
 static const GtkActionEntry modest_action_entries [] = {
 
        /* Toplevel menus */
-       { "Email", NULL, N_("mcen_me_inbox_email") },
+       { "Email", NULL, N_("mcen_me_inbox_email"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_edit_menu_activated) },
        { "Edit",    NULL, N_("mcen_me_inbox_edit") },
        { "View",    NULL, N_("mcen_me_inbox_view") },
        { "Tools",   NULL, N_("mcen_me_inbox_tools") },
index 63ed5e0..ef562e5 100644 (file)
@@ -45,6 +45,7 @@
 #include "modest-widget-memory.h"
 #include "modest-window-priv.h"
 #include "modest-main-window-ui.h"
+#include "modest-main-window-ui-dimming.h"
 #include "modest-account-mgr.h"
 #include "modest-tny-account.h"
 #include "modest-conf.h"
@@ -55,6 +56,7 @@
 #include "modest-icon-names.h"
 #include "modest-progress-bar-widget.h"
 #include "modest-text-utils.h"
+#include "modest-ui-dimming-manager.h"
 #include "maemo/modest-osso-state-saving.h"
 
 #ifdef MODEST_HILDON_VERSION_0
@@ -547,6 +549,7 @@ modest_main_window_new (void)
        ModestMainWindowPrivate *priv;
        ModestWindowPrivate *parent_priv;
        GtkWidget *folder_win;
+       ModestDimmingRulesGroup *rules_group;
        GtkActionGroup *action_group;
        GError *error = NULL;
        TnyFolderStoreQuery *query;
@@ -559,9 +562,13 @@ modest_main_window_new (void)
        parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
 
        parent_priv->ui_manager = gtk_ui_manager_new();
+       parent_priv->ui_dimming_manager = modest_ui_dimming_manager_new();
+
        action_group = gtk_action_group_new ("ModestMainWindowActions");
        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,
@@ -595,6 +602,16 @@ modest_main_window_new (void)
                error = NULL;
        }
 
+       /* Add common dimming rules */
+       modest_dimming_rules_group_add_rules (rules_group, 
+                                             modest_dimming_entries,
+                                             G_N_ELEMENTS (modest_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 (self), 
                                    gtk_ui_manager_get_accel_group (parent_priv->ui_manager));
@@ -1493,7 +1510,7 @@ on_queue_changed (ModestMailOperationQueue *queue,
        ModestToolBarModes mode;
        GSList *tmp;
        gboolean mode_changed = FALSE;
-       ModestMailOperationStatus status;
+/*     ModestMailOperationStatus status; */
 
        g_return_if_fail (MODEST_IS_MAIN_WINDOW (self));
        priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
@@ -1529,9 +1546,9 @@ on_queue_changed (ModestMailOperationQueue *queue,
                break;
        case MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED:
                /* If mail_op is mine, check errors */
-               status = modest_mail_operation_get_status (mail_op);
-               if (status != MODEST_MAIL_OPERATION_STATUS_SUCCESS)
-                       modest_mail_operation_execute_error_handler (mail_op);
+/*             status = modest_mail_operation_get_status (mail_op); */
+/*             if (status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) */
+/*                     modest_mail_operation_execute_error_handler (mail_op); */
 
                /* Change toolbar mode */
                if (mode == TOOLBAR_MODE_TRANSFER) {                    
diff --git a/src/modest-dimming-rule.c b/src/modest-dimming-rule.c
new file mode 100644 (file)
index 0000000..884ccc7
--- /dev/null
@@ -0,0 +1,154 @@
+/* Copyright (c) 2006, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "modest-dimming-rule.h"
+
+static void modest_dimming_rule_class_init (ModestDimmingRuleClass *klass);
+static void modest_dimming_rule_init       (ModestDimmingRule *obj);
+static void modest_dimming_rule_finalize   (GObject *obj);
+
+typedef struct _ModestDimmingRulePrivate ModestDimmingRulePrivate;
+struct _ModestDimmingRulePrivate {
+       ModestWindow *win;
+       ModestDimmingCallback dimming_rule;
+       gchar *action_path;
+};
+
+#define MODEST_DIMMING_RULE_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
+                                                   MODEST_TYPE_DIMMING_RULE, \
+                                                   ModestDimmingRulePrivate))
+
+/* globals */
+static GObjectClass *parent_class = NULL;
+
+GType
+modest_dimming_rule_get_type (void)
+{
+       static GType my_type = 0;
+       if (!my_type) {
+               static const GTypeInfo my_info = {
+                       sizeof(ModestDimmingRuleClass),
+                       NULL,           /* base init */
+                       NULL,           /* base finalize */
+                       (GClassInitFunc) modest_dimming_rule_class_init,
+                       NULL,           /* class finalize */
+                       NULL,           /* class data */
+                       sizeof(ModestDimmingRule),
+                       1,              /* n_preallocs */
+                       (GInstanceInitFunc) modest_dimming_rule_init,
+                       NULL
+               };
+               my_type = g_type_register_static (G_TYPE_OBJECT,
+                                                 "ModestDimmingRule",
+                                                 &my_info, 0);
+       }
+       return my_type;
+}
+
+static void
+modest_dimming_rule_class_init (ModestDimmingRuleClass *klass)
+{
+       GObjectClass *gobject_class;
+       gobject_class = (GObjectClass*) klass;
+
+       parent_class            = g_type_class_peek_parent (klass);
+       gobject_class->finalize = modest_dimming_rule_finalize;
+
+       g_type_class_add_private (gobject_class, sizeof(ModestDimmingRulePrivate));
+}
+
+static void
+modest_dimming_rule_init (ModestDimmingRule *obj)
+{
+       ModestDimmingRulePrivate *priv;
+
+       priv = MODEST_DIMMING_RULE_GET_PRIVATE(obj);
+       priv->win = NULL;
+       priv->dimming_rule = NULL;
+       priv->action_path = NULL;
+}
+
+static void
+modest_dimming_rule_finalize (GObject *obj)
+{
+       ModestDimmingRulePrivate *priv;
+
+       priv = MODEST_DIMMING_RULE_GET_PRIVATE(obj);
+
+       if (priv->action_path != NULL)
+               g_free(priv->action_path);
+
+       G_OBJECT_CLASS(parent_class)->finalize (obj);
+}
+
+
+ModestDimmingRule*
+modest_dimming_rule_new(ModestWindow *win,
+                       ModestDimmingCallback dimming_rule,
+                       const gchar *action_path)
+{
+       ModestDimmingRule *obj;
+       ModestDimmingRulePrivate *priv;
+               
+       g_return_val_if_fail (MODEST_IS_WINDOW (win), NULL);
+       g_return_val_if_fail (dimming_rule != NULL, NULL);
+       g_return_val_if_fail (action_path != NULL, NULL);
+                             
+       obj = MODEST_DIMMING_RULE(g_object_new(MODEST_TYPE_DIMMING_RULE, NULL));
+
+       priv = MODEST_DIMMING_RULE_GET_PRIVATE(obj);
+       priv->win = win;
+       priv->dimming_rule = dimming_rule;
+       priv->action_path = g_strdup(action_path);
+
+       return obj;
+}
+
+
+void
+modest_dimming_rule_process (ModestDimmingRule *self)
+{
+       
+       ModestDimmingRulePrivate *priv = NULL;
+       GtkAction *action = NULL;
+       gboolean dimmed = FALSE;
+
+       priv = MODEST_DIMMING_RULE_GET_PRIVATE(self);
+       g_return_if_fail (priv->win != NULL);
+       g_return_if_fail (priv->dimming_rule != NULL);
+       g_return_if_fail (priv->action_path != NULL);
+
+       /* process dimming rule */
+       dimmed = priv->dimming_rule (priv->win, NULL);
+
+       /* Update dimming status */
+        action = modest_window_get_action (priv->win, priv->action_path);      
+       g_return_if_fail (action != NULL);
+       gtk_action_set_sensitive (action, !dimmed);
+}
diff --git a/src/modest-dimming-rule.h b/src/modest-dimming-rule.h
new file mode 100644 (file)
index 0000000..0e7e8ad
--- /dev/null
@@ -0,0 +1,89 @@
+/* Copyright (c) 2006, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __MODEST_DIMMING_RULE_H__
+#define __MODEST_DIMMING_RULE_H__
+
+#include <glib-object.h>
+#include "widgets/modest-window.h"
+
+G_BEGIN_DECLS
+
+/* convenience macros */
+#define MODEST_TYPE_DIMMING_RULE             (modest_dimming_rule_get_type())
+#define MODEST_DIMMING_RULE(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_DIMMING_RULE,ModestDimmingRule))
+#define MODEST_DIMMING_RULE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_DIMMING_RULE,GObject))
+#define MODEST_IS_DIMMING_RULE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_DIMMING_RULE))
+#define MODEST_IS_DIMMING_RULE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_DIMMING_RULE))
+#define MODEST_DIMMING_RULE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_DIMMING_RULE,ModestDimmingRuleClass))
+
+typedef struct _ModestDimmingRule      ModestDimmingRule;
+typedef struct _ModestDimmingRuleClass ModestDimmingRuleClass;
+
+typedef gboolean (*ModestDimmingCallback) (ModestWindow *self, gpointer user_data);
+
+
+struct _ModestDimmingRule {
+        GObject parent;
+       /* insert public members, if any */
+};
+
+struct _ModestDimmingRuleClass {
+       GObjectClass parent_class;
+
+       /* Signals */
+};
+
+/* member functions */
+GType        modest_dimming_rule_get_type    (void) G_GNUC_CONST;
+
+/**
+ * modest_dimming_rule_new:
+ * @win: the #ModestWindow object which executes dimming rule.
+ * @dimming_rule: a #ModestDimmingCallback function to check dimmed status.
+ * @action_path: full path of action registered on #GtkUIManager UIManager.
+ * 
+ * Creates a new instance of class #ModestDimmingRule using parameters to
+ * fill private data, required to process dimming rules. All parameters
+ * are required and NULL will be returned if one of these parameters is
+ * invalid or NULL.
+ * 
+ * Returns: a new instance of #ModestDimmingRule class, or NULL, if parameters
+ * are invalid.
+ **/
+ModestDimmingRule*    modest_dimming_rule_new     (ModestWindow *win,
+                                                  ModestDimmingCallback dimming_rule,
+                                                  const gchar *action_path);
+
+void
+modest_dimming_rule_process (ModestDimmingRule *self);
+
+G_END_DECLS
+
+#endif /* __MODEST_DIMMING_RULE_H__ */
diff --git a/src/modest-dimming-rules-group-priv.h b/src/modest-dimming-rules-group-priv.h
new file mode 100644 (file)
index 0000000..994d046
--- /dev/null
@@ -0,0 +1,42 @@
+/* Copyright (c) 2006, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __MODEST_DIMMING_RULES_GROUP_PRIV_H__
+#define __MODEST_DIMMING_RULES_GROUP_PRIV_H__
+
+G_BEGIN_DECLS
+
+/* PROTECTED method. It's useful to execute all dimming rules of 
+ * a specific rules group. The UI Dimming Manager calls internally
+ * this method to execute all registered dimming rules. */
+void modest_dimming_rules_group_execute (ModestDimmingRulesGroup *self);
+
+G_END_DECLS
+
+#endif
diff --git a/src/modest-dimming-rules-group.c b/src/modest-dimming-rules-group.c
new file mode 100644 (file)
index 0000000..fe9ff6f
--- /dev/null
@@ -0,0 +1,209 @@
+/* Copyright (c) 2006, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "modest-dimming-rules-group.h"
+#include "modest-dimming-rules-group-priv.h"
+#include "modest-dimming-rule.h"
+
+static void modest_dimming_rules_group_class_init (ModestDimmingRulesGroupClass *klass);
+static void modest_dimming_rules_group_init       (ModestDimmingRulesGroup *obj);
+static void modest_dimming_rules_group_finalize   (GObject *obj);
+
+typedef struct _ModestDimmingRulesGroupPrivate ModestDimmingRulesGroupPrivate;
+struct _ModestDimmingRulesGroupPrivate {       
+       gchar *name;
+       GHashTable *rules_map;
+};
+
+#define MODEST_DIMMING_RULES_GROUP_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
+                                                   MODEST_TYPE_DIMMING_RULES_GROUP, \
+                                                   ModestDimmingRulesGroupPrivate))
+
+/* globals */
+static GObjectClass *parent_class = NULL;
+
+static void _execute_dimming_rule (gpointer key, gpointer value, gpointer user_data);
+
+
+
+GType
+modest_dimming_rules_group_get_type (void)
+{
+       static GType my_type = 0;
+       if (!my_type) {
+               static const GTypeInfo my_info = {
+                       sizeof(ModestDimmingRulesGroupClass),
+                       NULL,           /* base init */
+                       NULL,           /* base finalize */
+                       (GClassInitFunc) modest_dimming_rules_group_class_init,
+                       NULL,           /* class finalize */
+                       NULL,           /* class data */
+                       sizeof(ModestDimmingRulesGroup),
+                       1,              /* n_preallocs */
+                       (GInstanceInitFunc) modest_dimming_rules_group_init,
+                       NULL
+               };
+               my_type = g_type_register_static (G_TYPE_OBJECT,
+                                                 "ModestDimmingRulesGroup",
+                                                 &my_info, 0);
+       }
+       return my_type;
+}
+
+static void
+modest_dimming_rules_group_class_init (ModestDimmingRulesGroupClass *klass)
+{
+       GObjectClass *gobject_class;
+       gobject_class = (GObjectClass*) klass;
+
+       parent_class            = g_type_class_peek_parent (klass);
+       gobject_class->finalize = modest_dimming_rules_group_finalize;
+
+       g_type_class_add_private (gobject_class, sizeof(ModestDimmingRulesGroupPrivate));
+}
+
+static void
+modest_dimming_rules_group_init (ModestDimmingRulesGroup *obj)
+{
+       ModestDimmingRulesGroupPrivate *priv;
+
+       priv = MODEST_DIMMING_RULES_GROUP_GET_PRIVATE(obj);
+
+       priv->name = NULL;
+       priv->rules_map = g_hash_table_new_full ((GHashFunc) g_str_hash,
+                                                (GEqualFunc) g_str_equal,
+                                                (GDestroyNotify) g_free,
+                                                (GDestroyNotify) g_object_unref);
+}
+
+static void
+modest_dimming_rules_group_finalize (GObject *obj)
+{
+       ModestDimmingRulesGroupPrivate *priv;
+
+       priv = MODEST_DIMMING_RULES_GROUP_GET_PRIVATE(obj);
+
+       if (priv->name != NULL)
+               g_free(priv->name);
+
+       if (priv->rules_map != NULL)
+               g_hash_table_destroy (priv->rules_map);
+
+       G_OBJECT_CLASS(parent_class)->finalize (obj);
+}
+
+
+ModestDimmingRulesGroup*
+modest_dimming_rules_group_new(const gchar *group_name)
+{
+       ModestDimmingRulesGroup *obj;
+       ModestDimmingRulesGroupPrivate *priv;
+               
+       g_return_val_if_fail (group_name != NULL, NULL);
+
+       obj = MODEST_DIMMING_RULES_GROUP(g_object_new(MODEST_TYPE_DIMMING_RULES_GROUP, NULL));
+
+       priv = MODEST_DIMMING_RULES_GROUP_GET_PRIVATE(obj);
+       priv->name = g_strdup(group_name);
+
+       return obj;
+}
+
+
+gchar *
+modest_dimming_rules_group_get_name (ModestDimmingRulesGroup *self) 
+{
+       ModestDimmingRulesGroupPrivate *priv;
+       
+       g_return_val_if_fail (MODEST_IS_DIMMING_RULES_GROUP(self), NULL);
+
+       priv = MODEST_DIMMING_RULES_GROUP_GET_PRIVATE(self);
+       
+       return g_strdup (priv->name);
+}
+
+void
+modest_dimming_rules_group_add_rules (ModestDimmingRulesGroup *self,
+                                     const ModestDimmingEntry modest_dimming_entries[],
+                                     guint n_elements,
+                                     gpointer user_data)
+{
+       ModestDimmingRulesGroupPrivate *priv;
+       ModestDimmingRule *dim_rule = NULL;
+       ModestDimmingEntry entry;
+       gboolean unique = FALSE;
+       guint i;
+
+       g_return_if_fail (MODEST_IS_DIMMING_RULES_GROUP(self));
+       g_return_if_fail (modest_dimming_entries != NULL);
+       g_return_if_fail (n_elements > 0);
+       g_return_if_fail (MODEST_IS_WINDOW(user_data));
+       
+       priv = MODEST_DIMMING_RULES_GROUP_GET_PRIVATE(self);
+
+       for (i=0; i < n_elements; i++) {
+               entry = modest_dimming_entries[i]; 
+               
+               /* Check dimming_rule and action path are NOT NULL */
+               if (entry.action_path == NULL) continue;
+               if (entry.callback == NULL) continue;
+               
+               /* Check action path is unique */
+               unique = g_hash_table_lookup (priv->rules_map, entry.action_path) == NULL;
+               if (!unique) continue;
+
+               /* Create a new dimming rule */
+               dim_rule = modest_dimming_rule_new (MODEST_WINDOW(user_data),
+                                                   (ModestDimmingCallback) entry.callback,
+                                                   entry.action_path);
+               
+               /* Register new dimming rule */         
+               g_hash_table_insert (priv->rules_map, g_strdup(entry.action_path), dim_rule);
+       }
+}
+
+void 
+modest_dimming_rules_group_execute (ModestDimmingRulesGroup *self) 
+{
+       ModestDimmingRulesGroupPrivate *priv;
+
+       priv = MODEST_DIMMING_RULES_GROUP_GET_PRIVATE(self);
+
+       g_hash_table_foreach (priv->rules_map, _execute_dimming_rule, NULL);
+}
+
+
+static void
+_execute_dimming_rule (gpointer key, gpointer value, gpointer user_data)
+{
+       g_return_if_fail (MODEST_IS_DIMMING_RULE (value));
+
+       /* Process diomming rule */
+       modest_dimming_rule_process (MODEST_DIMMING_RULE(value));
+}
diff --git a/src/modest-dimming-rules-group.h b/src/modest-dimming-rules-group.h
new file mode 100644 (file)
index 0000000..aa3941a
--- /dev/null
@@ -0,0 +1,111 @@
+/* Copyright (c) 2006, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __MODEST_DIMMING_RULES_GROUP_H__
+#define __MODEST_DIMMING_RULES_GROUP_H__
+
+#include <glib-object.h>
+#include <widgets/modest-window.h>
+
+G_BEGIN_DECLS
+
+/* convenience macros */
+#define MODEST_TYPE_DIMMING_RULES_GROUP             (modest_dimming_rules_group_get_type())
+#define MODEST_DIMMING_RULES_GROUP(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_DIMMING_RULES_GROUP,ModestDimmingRulesGroup))
+#define MODEST_DIMMING_RULES_GROUP_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_DIMMING_RULES_GROUP,GObject))
+#define MODEST_IS_DIMMING_RULES_GROUP(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_DIMMING_RULES_GROUP))
+#define MODEST_IS_DIMMING_RULES_GROUP_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_DIMMING_RULES_GROUP))
+#define MODEST_DIMMING_RULES_GROUP_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_DIMMING_RULES_GROUP,ModestDimmingRulesGroupClass))
+
+typedef struct {
+       const gchar     *action_path;
+       GCallback  callback;
+} ModestDimmingEntry;
+
+typedef struct _ModestDimmingRulesGroup      ModestDimmingRulesGroup;
+typedef struct _ModestDimmingRulesGroupClass ModestDimmingRulesGroupClass;
+
+struct _ModestDimmingRulesGroup {
+        GObject parent;
+       /* insert public members, if any */
+};
+
+struct _ModestDimmingRulesGroupClass {
+       GObjectClass parent_class;
+
+       /* Signals */
+};
+
+
+/* member functions */
+GType        modest_dimming_rules_group_get_type    (void) G_GNUC_CONST;
+
+/**
+ * modest_dimming_rules_group_new:
+ * @group_name: the name to identify new created group 
+ * 
+ * Creates a new instance of class #ModestDimmingRulesGroup. The @group_name
+ * parameter identifies uniquely new group created, so it must not be NULL.
+ *
+ * Returns: a new #ModestDimmingRulesGroup instance, or NULL if parameters 
+ * are invalid.
+ **/
+ModestDimmingRulesGroup*    modest_dimming_rules_group_new     (const gchar *group_name);
+
+
+
+/**
+ * modest_dimming_rules_group_add_rules:
+ * @self: the #ModestDimmingRulesGroup object which stores dimming rules.
+ * @modest_dimming_entries: a #ModestDimmingEntry array to define dimmed status handlers.
+ * @n_elements: the number of elements of @modest_dimming_entries array.
+ * @user_data: generic user data.
+ * 
+ * Add rules to @self dimming rules group object. 
+ **/
+void
+modest_dimming_rules_group_add_rules (ModestDimmingRulesGroup *self,
+                                     const ModestDimmingEntry modest_dimming_entries[],
+                                     guint n_elements,
+                                     gpointer user_data);
+
+/**
+ * modest_dimming_rules_group_get_name:
+ * @self: the #ModestDimmingRulesGroup object which stores dimming rules.
+ * 
+ * Gets the name, which uniquely identifies @self dimming rules group.
+ *
+ * Returns: a string with group name. 
+ **/
+gchar *
+modest_dimming_rules_group_get_name (ModestDimmingRulesGroup *self);
+
+G_END_DECLS
+
+#endif /* __MODEST_DIMMING_RULES_GROUP_H__ */
index 12001e1..fe628e7 100644 (file)
@@ -81,7 +81,7 @@ enum _ModestMailOperationSignals
 
 typedef struct _ModestMailOperationPrivate ModestMailOperationPrivate;
 struct _ModestMailOperationPrivate {
-       guint                      id;
+       TnyAccount                 *account;
        guint                      done;
        guint                      total;
        GObject                   *source;
@@ -179,11 +179,11 @@ modest_mail_operation_init (ModestMailOperation *obj)
 
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(obj);
 
+       priv->account  = NULL;
        priv->status         = MODEST_MAIL_OPERATION_STATUS_INVALID;
        priv->op_type        = MODEST_MAIL_OPERATION_TYPE_UNKNOWN;
        priv->error          = NULL;
        priv->error_checking = NULL;
-       priv->id             = 0;
        priv->done           = 0;
        priv->total          = 0;
        priv->source         = NULL;
@@ -204,6 +204,11 @@ modest_mail_operation_finalize (GObject *obj)
                g_object_unref (priv->source);
                priv->source = NULL;
        }
+       if (priv->account) {
+               g_object_unref (priv->account);
+               priv->account = NULL;
+       }
+
 
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
@@ -439,12 +444,18 @@ modest_mail_operation_send_mail (ModestMailOperation *self,
                                 TnyTransportAccount *transport_account,
                                 TnyMsg* msg)
 {
-       TnySendQueue *send_queue;
+       TnySendQueue *send_queue = NULL;
+       ModestMailOperationPrivate *priv;
        
        g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
        g_return_if_fail (TNY_IS_TRANSPORT_ACCOUNT (transport_account));
        g_return_if_fail (TNY_IS_MSG (msg));
        
+       priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
+
+       /* Get account and set it into mail_operation */
+       priv->account = g_object_ref (transport_account);
+
        send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
        if (!TNY_IS_SEND_QUEUE(send_queue))
                g_printerr ("modest: could not find send queue for account\n");
@@ -474,17 +485,21 @@ modest_mail_operation_send_new_mail (ModestMailOperation *self,
                                     const GList *attachments_list,
                                     TnyHeaderFlags priority_flags)
 {
-       TnyMsg *new_msg;
+       TnyMsg *new_msg = NULL;
        ModestMailOperationPrivate *priv = NULL;
-       /* GList *node = NULL; */
 
        g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
        g_return_if_fail (TNY_IS_TRANSPORT_ACCOUNT (transport_account));
 
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
 
+       /* Get account and set it into mail_operation */
+       priv->account = g_object_ref (transport_account);
+
        /* Check parametters */
        if (to == NULL) {
+               /* Set status failed and set an error */
+               priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
                g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
                             MODEST_MAIL_OPERATION_ERROR_BAD_PARAMETER,
                             _("Error trying to send a mail. You need to set at least one recipient"));
@@ -526,13 +541,14 @@ modest_mail_operation_save_to_drafts (ModestMailOperation *self,
        ModestMailOperationPrivate *priv = NULL;
        GError *err = NULL;
 
-       /* GList *node = NULL; */
-
        g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
        g_return_if_fail (TNY_IS_TRANSPORT_ACCOUNT (transport_account));
 
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
 
+       /* Get account and set it into mail_operation */
+       priv->account = g_object_ref (transport_account);
+
        if (html_body == NULL) {
                msg = modest_tny_msg_new (to, from, cc, bcc, subject, plain_body, (GSList *) attachments_list); /* FIXME: attachments */
        } else {
@@ -557,7 +573,7 @@ modest_mail_operation_save_to_drafts (ModestMailOperation *self,
                goto cleanup;
        }
 
-       modest_mail_operation_notify_end (self);
+       modest_mail_operation_notify_end (self);
 
        /* Free */
 cleanup:
@@ -769,6 +785,9 @@ update_account_thread (gpointer thr_user_data)
        info = (UpdateAccountInfo *) thr_user_data;
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(info->mail_op);
 
+       /* Get account and set it into mail_operation */
+       priv->account = g_object_ref (info->account);
+
        /* Get all the folders We can do it synchronously because
           we're already running in a different thread than the UI */
        all_folders = tny_simple_list_new ();
@@ -814,8 +833,8 @@ update_account_thread (gpointer thr_user_data)
                tny_folder_refresh (TNY_FOLDER (folder), &(priv->error));
 
                /* If the retrieve type is headers only do nothing more */
-               if (!strcmp (info->retrieve_type, MODEST_ACCOUNT_RETRIEVE_VALUE_MESSAGES) || 
-                   !strcmp (info->retrieve_type, MODEST_ACCOUNT_RETRIEVE_VALUE_MESSAGES_AND_ATTACHMENTS)) {
+               if (!g_ascii_strcasecmp (info->retrieve_type, MODEST_ACCOUNT_RETRIEVE_VALUE_MESSAGES) || 
+                   !g_ascii_strcasecmp (info->retrieve_type, MODEST_ACCOUNT_RETRIEVE_VALUE_MESSAGES_AND_ATTACHMENTS)) {
                        TnyIterator *iter;
 
                        iter = tny_list_create_iterator (observer->new_headers);
@@ -883,7 +902,10 @@ update_account_thread (gpointer thr_user_data)
        priv->op_type = MODEST_MAIL_OPERATION_TYPE_SEND;
        priv->done = 0;
        priv->total = 0;
-
+       if (priv->account != NULL) 
+               g_object_unref (priv->account);
+       priv->account = g_object_ref (info->transport_account);
+       
        ModestTnySendQueue *send_queue = modest_runtime_get_send_queue
                (info->transport_account);
 
@@ -1023,18 +1045,26 @@ modest_mail_operation_create_folder (ModestMailOperation *self,
        
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
 
+       /* Get account and set it into mail_operation */
+       priv->account = tny_folder_get_account (TNY_FOLDER(parent));
+
        /* Check parent */
        if (!TNY_IS_FOLDER (parent)) {
+               /* Set status failed and set an error */
+               priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
                g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
                             MODEST_MAIL_OPERATION_ERROR_BAD_PARAMETER,
                             _("mail_in_ui_folder_create_error"));
        } else {
                /* Check folder rules */
                rules = modest_tny_folder_get_rules (TNY_FOLDER (parent));
-               if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE)
+               if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
+                       /* Set status failed and set an error */
+                       priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
                        g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
                                     MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES,
                                     _("mail_in_ui_folder_create_error"));
+               } 
                else
                        can_create = TRUE;              
        }
@@ -1068,6 +1098,8 @@ modest_mail_operation_remove_folder (ModestMailOperation *self,
        /* Check folder rules */
        rules = modest_tny_folder_get_rules (TNY_FOLDER (folder));
        if (rules & MODEST_FOLDER_RULES_FOLDER_NON_DELETABLE) {
+               /* Set status failed and set an error */
+               priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
                g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
                             MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES,
                             _("mail_in_ui_folder_delete_error"));
@@ -1076,6 +1108,7 @@ modest_mail_operation_remove_folder (ModestMailOperation *self,
 
        /* Get the account */
        account = tny_folder_get_account (folder);
+       priv->account = g_object_ref(account);
 
        /* Delete folder or move to trash */
        if (remove_to_trash) {
@@ -1101,46 +1134,6 @@ modest_mail_operation_remove_folder (ModestMailOperation *self,
        modest_mail_operation_notify_end (self);
 }
 
-void
-modest_mail_operation_rename_folder (ModestMailOperation *self,
-                                    TnyFolder *folder,
-                                    const gchar *name)
-{
-       ModestMailOperationPrivate *priv;
-       ModestTnyFolderRules rules;
-
-       g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
-       g_return_if_fail (TNY_IS_FOLDER_STORE (folder));
-       g_return_if_fail (name);
-       
-       priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
-
-       /* Check folder rules */
-       rules = modest_tny_folder_get_rules (TNY_FOLDER (folder));
-       if (rules & MODEST_FOLDER_RULES_FOLDER_NON_RENAMEABLE) {
-               g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
-                            MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES,
-                            _("FIXME: unable to rename"));
-       } else {
-               /* Rename. Camel handles folder subscription/unsubscription */
-               TnyFolderStore *into;
-               TnyFolder *nfol;
-
-               into = tny_folder_get_folder_store (folder);
-               nfol = tny_folder_copy (folder, into, name, TRUE, &(priv->error));
-               if (into)
-                       g_object_unref (into);
-               if (nfol)
-                       g_object_unref (nfol);
-
-               CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED);
-               
-       }
-
-       /* Notify about operation end */
-       modest_mail_operation_notify_end (self);
- }
-
 static void
 transfer_folder_status_cb (GObject *obj,
                           TnyStatus *status,
@@ -1217,17 +1210,27 @@ modest_mail_operation_xfer_folder (ModestMailOperation *self,
        ModestTnyFolderRules parent_rules, rules;
 
        g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
-       g_return_if_fail (TNY_IS_FOLDER_STORE (parent));
        g_return_if_fail (TNY_IS_FOLDER (folder));
+       g_return_if_fail (TNY_IS_FOLDER (parent));
 
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
 
+       /* Get account and set it into mail_operation */
+       priv->account = tny_folder_get_account (TNY_FOLDER(folder));
+       priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
+
        /* Get folder rules */
        rules = modest_tny_folder_get_rules (TNY_FOLDER (folder));
        parent_rules = modest_tny_folder_get_rules (TNY_FOLDER (parent));
 
+       if (!TNY_IS_FOLDER_STORE (parent)) {
+               
+       }
+       
        /* The moveable restriction is applied also to copy operation */
-       if (rules & MODEST_FOLDER_RULES_FOLDER_NON_MOVEABLE) {
+       if ((!TNY_IS_FOLDER_STORE (parent)) || (rules & MODEST_FOLDER_RULES_FOLDER_NON_MOVEABLE)) {
+               /* Set status failed and set an error */
+               priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
                g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
                             MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES,
                             _("mail_in_ui_folder_move_target_error"));
@@ -1235,6 +1238,8 @@ modest_mail_operation_xfer_folder (ModestMailOperation *self,
                /* Notify the queue */
                modest_mail_operation_notify_end (self);
        } else if (parent_rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
+               /* Set status failed and set an error */
+               priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
                g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
                             MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES,
                             _("FIXME: parent folder does not accept new folders"));
@@ -1257,6 +1262,48 @@ modest_mail_operation_xfer_folder (ModestMailOperation *self,
        }
 }
 
+void
+modest_mail_operation_rename_folder (ModestMailOperation *self,
+                                    TnyFolder *folder,
+                                    const gchar *name)
+{
+       ModestMailOperationPrivate *priv;
+       ModestTnyFolderRules rules;
+
+       g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
+       g_return_if_fail (TNY_IS_FOLDER_STORE (folder));
+       g_return_if_fail (name);
+       
+       priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
+
+       /* Get account and set it into mail_operation */
+       priv->account = tny_folder_get_account (TNY_FOLDER(folder));
+
+       /* Check folder rules */
+       rules = modest_tny_folder_get_rules (TNY_FOLDER (folder));
+       if (rules & MODEST_FOLDER_RULES_FOLDER_NON_RENAMEABLE) {
+               /* Set status failed and set an error */
+               priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
+               g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
+                            MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES,
+                            _("FIXME: unable to rename"));
+
+               /* Notify about operation end */
+               modest_mail_operation_notify_end (self);
+       } else {
+               /* Rename. Camel handles folder subscription/unsubscription */
+               TnyFolderStore *into;
+
+               into = tny_folder_get_folder_store (folder);
+               tny_folder_copy_async (folder, into, name, TRUE,
+                                transfer_folder_cb,
+                                transfer_folder_status_cb,
+                                self);
+               if (into)
+                       g_object_unref (into);
+               
+       }
+ }
 
 /* ******************************************************************* */
 /* **************************  MSG  ACTIONS  ************************* */
@@ -1281,6 +1328,9 @@ void modest_mail_operation_get_msg (ModestMailOperation *self,
 
        /* Get message from folder */
        if (folder) {
+               /* Get account and set it into mail_operation */
+               priv->account = tny_folder_get_account (TNY_FOLDER(folder));            
+
                helper = g_slice_new0 (GetMsgAsyncHelper);
                helper->mail_op = self;
                helper->user_callback = user_callback;
@@ -1296,6 +1346,9 @@ void modest_mail_operation_get_msg (ModestMailOperation *self,
                g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
                             MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
                             _("Error trying to get a message. No folder found for header"));
+
+               /* Notify the queue */
+               modest_mail_operation_notify_end (self);
        }
 }
 
@@ -1517,12 +1570,15 @@ modest_mail_operation_get_msgs_full (ModestMailOperation *self,
                                     gpointer user_data,
                                     GDestroyNotify notify)
 {
+       TnyHeader *header = NULL;
+       TnyFolder *folder = NULL;
        GThread *thread;
        ModestMailOperationPrivate *priv = NULL;
        GetFullMsgsInfo *info = NULL;
        gboolean size_ok = TRUE;
        gint max_size;
        GError *error = NULL;
+       TnyIterator *iter = NULL;
        
        g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
        
@@ -1532,6 +1588,16 @@ modest_mail_operation_get_msgs_full (ModestMailOperation *self,
        priv->done = 0;
        priv->total = tny_list_get_length(header_list);
 
+       /* Get account and set it into mail_operation */
+       if (tny_list_get_length (header_list) > 1) {
+               iter = tny_list_create_iterator (header_list);          
+               header = TNY_HEADER (tny_iterator_get_current (iter));
+               folder = tny_header_get_folder (header);                
+               priv->account = tny_folder_get_account (TNY_FOLDER(folder));
+               g_object_unref (header);
+               g_object_unref (folder);
+       }
+
        /* Get msg size limit */
        max_size  = modest_conf_get_int (modest_runtime_get_conf (), 
                                         MODEST_CONF_MSG_SIZE_LIMIT, 
@@ -1545,12 +1611,9 @@ modest_mail_operation_get_msgs_full (ModestMailOperation *self,
 
        /* Check message size limits. If there is only one message
           always retrieve it */
-       if (tny_list_get_length (header_list) > 1) {
-               TnyIterator *iter;
-
-               iter = tny_list_create_iterator (header_list);
+       if (iter != NULL) {
                while (!tny_iterator_is_done (iter) && size_ok) {
-                       TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
+                       header = TNY_HEADER (tny_iterator_get_current (iter));
                        if (tny_header_get_message_size (header) >= max_size)
                                size_ok = FALSE;
                        g_object_unref (header);
@@ -1570,6 +1633,8 @@ modest_mail_operation_get_msgs_full (ModestMailOperation *self,
 
                thread = g_thread_create (get_msgs_full_thread, info, FALSE, NULL);
        } else {
+               /* Set status failed and set an error */
+               priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
                /* FIXME: the error msg is different for pop */
                g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
                             MODEST_MAIL_OPERATION_ERROR_BAD_PARAMETER,
@@ -1596,6 +1661,9 @@ modest_mail_operation_remove_msg (ModestMailOperation *self,
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
        folder = tny_header_get_folder (header);
 
+       /* Get account and set it into mail_operation */
+       priv->account = tny_folder_get_account (TNY_FOLDER(folder));
+
        priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
 
        /* Delete or move to trash */
@@ -1752,6 +1820,8 @@ modest_mail_operation_xfer_msgs (ModestMailOperation *self,
        rules = modest_tny_folder_get_rules (TNY_FOLDER (folder));
 
        if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
+               /* Set status failed and set an error */
+               priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
                g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
                             MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES,
                             _("FIXME: folder does not accept msgs"));
@@ -1775,6 +1845,9 @@ modest_mail_operation_xfer_msgs (ModestMailOperation *self,
        g_object_unref (header);
        g_object_unref (iter);
 
+       /* Get account and set it into mail_operation */
+       priv->account = tny_folder_get_account (src_folder);
+
        /* Transfer messages */
        tny_folder_transfer_msgs_async (src_folder, 
                                        headers, 
@@ -1859,6 +1932,9 @@ modest_mail_operation_refresh_folder  (ModestMailOperation *self,
 
        priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
 
+       /* Get account and set it into mail_operation */
+       priv->account = tny_folder_get_account (folder);
+
        /* Refresh the folder. TODO: tinymail could issue a status
           updates before the callback call then this could happen. We
           must review the design */
index c97f21e..45321f1 100644 (file)
@@ -2480,8 +2480,8 @@ move_to_error_checking (const GObject *obj, gpointer user_data)
        win = MODEST_WINDOW (obj);
 
        /* TODO: show error message */
-/*     modest_platform_run_information_dialog (GTK_WINDOW (win), */
-/*                                             _("mail_in_ui_folder_move_target_error")); */
+       modest_platform_run_information_dialog (GTK_WINDOW (win),
+                                               _("mail_in_ui_folder_move_target_error"));
 }
 
 /*
@@ -2497,6 +2497,7 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
        gint result;
        TnyFolderStore *folder_store = NULL;
        ModestMailOperation *mail_op = NULL;
+       ModestMailOperationStatus status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
 
        g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
 
@@ -2531,18 +2532,18 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
                modest_header_view_set_folder (MODEST_HEADER_VIEW (header_view), NULL); 
 
                if (TNY_IS_FOLDER (src_folder)) {
-                       mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE, 
-                                                                                G_OBJECT(win),
-                                                                                move_to_error_checking);
+                       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, 
+                                                            G_OBJECT(win));
                        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
                                                         mail_op);
 
                        modest_mail_operation_xfer_folder (mail_op, 
                                                           TNY_FOLDER (src_folder),
                                                           folder_store,
-                                                          TRUE);
+                                                          TRUE);                       
+                       /* Get status and unref mail operation */
+                       status = modest_mail_operation_get_status (mail_op);                                            
                        g_object_unref (G_OBJECT (mail_op));
-                       
                }
 
                /* Frees */
@@ -2571,6 +2572,9 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
                                                                 TRUE,
                                                                 NULL,
                                                                 NULL);
+
+                               /* Get status and unref mail operation */
+                               status = modest_mail_operation_get_status (mail_op);                                            
                                g_object_unref (G_OBJECT (mail_op));
                        }
                        g_object_unref (headers);
@@ -2578,6 +2582,9 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
        }
        g_object_unref (folder_store);
        
+       /* Check errors */                      
+       if (status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) 
+               move_to_error_checking (G_OBJECT(win), NULL);
  end:
        gtk_widget_destroy (dialog);
 }
@@ -2766,3 +2773,13 @@ modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
        g_object_unref (headers);
        g_object_unref (mail_op);
 }
+
+void
+modest_ui_actions_on_edit_menu_activated (GtkAction *action,
+                                         ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */     
+       modest_window_check_dimming_rules (window);     
+}
index bc2b7ab..01fdbf2 100644 (file)
@@ -322,5 +322,9 @@ void     modest_ui_actions_remove_attachments             (GtkAction *action,
 void     modest_ui_actions_on_retrieve_msg_contents       (GtkAction *action,
                                                           ModestWindow *window);
 
+void
+modest_ui_actions_on_edit_menu_activated (GtkAction *action,
+                                         ModestWindow *window);
+
 G_END_DECLS
 #endif /* __MODEST_UI_ACTIONS_H__ */
diff --git a/src/modest-ui-dimming-manager.c b/src/modest-ui-dimming-manager.c
new file mode 100644 (file)
index 0000000..2dd082c
--- /dev/null
@@ -0,0 +1,188 @@
+/* Copyright (c) 2006, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "modest-ui-dimming-manager.h"
+#include "modest-dimming-rules-group-priv.h"
+
+static void modest_ui_dimming_manager_class_init (ModestUIDimmingManagerClass *klass);
+static void modest_ui_dimming_manager_init       (ModestUIDimmingManager *obj);
+static void modest_ui_dimming_manager_finalize   (GObject *obj);
+
+static void _process_all_rules (gpointer key, gpointer value, gpointer user_data);
+
+
+typedef struct _ModestUIDimmingManagerPrivate ModestUIDimmingManagerPrivate;
+struct _ModestUIDimmingManagerPrivate {
+       GHashTable *groups_map;
+};
+
+#define MODEST_UI_DIMMING_MANAGER_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
+                                                   MODEST_TYPE_UI_DIMMING_MANAGER, \
+                                                   ModestUIDimmingManagerPrivate))
+
+/* globals */
+static GObjectClass *parent_class = NULL;
+
+GType
+modest_ui_dimming_manager_get_type (void)
+{
+       static GType my_type = 0;
+       if (!my_type) {
+               static const GTypeInfo my_info = {
+                       sizeof(ModestUIDimmingManagerClass),
+                       NULL,           /* base init */
+                       NULL,           /* base finalize */
+                       (GClassInitFunc) modest_ui_dimming_manager_class_init,
+                       NULL,           /* class finalize */
+                       NULL,           /* class data */
+                       sizeof(ModestUIDimmingManager),
+                       1,              /* n_preallocs */
+                       (GInstanceInitFunc) modest_ui_dimming_manager_init,
+                       NULL
+               };
+               my_type = g_type_register_static (G_TYPE_OBJECT,
+                                                 "ModestUIDimmingManager",
+                                                 &my_info, 0);
+       }
+       return my_type;
+}
+
+static void
+modest_ui_dimming_manager_class_init (ModestUIDimmingManagerClass *klass)
+{
+       GObjectClass *gobject_class;
+       gobject_class = (GObjectClass*) klass;
+
+       parent_class            = g_type_class_peek_parent (klass);
+       gobject_class->finalize = modest_ui_dimming_manager_finalize;
+
+       g_type_class_add_private (gobject_class, sizeof(ModestUIDimmingManagerPrivate));
+}
+
+static void
+modest_ui_dimming_manager_init (ModestUIDimmingManager *obj)
+{
+       ModestUIDimmingManagerPrivate *priv;
+
+       priv = MODEST_UI_DIMMING_MANAGER_GET_PRIVATE(obj);
+
+       priv->groups_map = g_hash_table_new_full ((GHashFunc) g_str_hash,
+                                                 (GEqualFunc) g_str_equal,
+                                                 (GDestroyNotify) g_free,
+                                                 (GDestroyNotify) g_object_unref);
+}
+
+static void
+modest_ui_dimming_manager_finalize (GObject *obj)
+{
+       ModestUIDimmingManagerPrivate *priv;
+
+       priv = MODEST_UI_DIMMING_MANAGER_GET_PRIVATE(obj);
+
+       if (priv->groups_map != NULL)
+               g_hash_table_destroy (priv->groups_map);
+
+       G_OBJECT_CLASS(parent_class)->finalize (obj);
+}
+
+
+ModestUIDimmingManager*
+modest_ui_dimming_manager_new()
+{
+       ModestUIDimmingManager *obj;
+               
+       obj = MODEST_UI_DIMMING_MANAGER(g_object_new(MODEST_TYPE_UI_DIMMING_MANAGER, NULL));
+
+
+       return obj;
+}
+
+void
+modest_ui_dimming_manager_insert_rules_group (ModestUIDimmingManager *self,
+                                             ModestDimmingRulesGroup *group)
+{
+       ModestUIDimmingManagerPrivate *priv;
+       gchar *group_name = NULL;
+       gboolean unique = FALSE;
+       
+       priv = MODEST_UI_DIMMING_MANAGER_GET_PRIVATE(self);
+       
+       /* Get group name */
+       group_name = modest_dimming_rules_group_get_name (group);
+       
+       /* Check group name is unique */
+       unique = g_hash_table_lookup (priv->groups_map, group_name) == NULL;
+       if (!unique) {
+               g_free(group_name);
+               g_return_if_fail (unique);
+       }
+       
+       
+       /* Insert new dimming rules group */
+       g_hash_table_insert (priv->groups_map, group_name, g_object_ref(group));
+}
+
+void
+modest_ui_dimming_manager_process_dimming_rules (ModestUIDimmingManager *self)
+{
+       ModestUIDimmingManagerPrivate *priv;
+       
+       priv = MODEST_UI_DIMMING_MANAGER_GET_PRIVATE(self);
+
+       /* Peforms a full dimming tules checking */
+       g_hash_table_foreach (priv->groups_map, _process_all_rules, NULL);
+}
+
+void
+modest_ui_dimming_manager_process_dimming_rules_group (ModestUIDimmingManager *self,
+                                                      const gchar *group_name)
+{
+       ModestDimmingRulesGroup *group = NULL;
+       ModestUIDimmingManagerPrivate *priv;
+       
+       g_return_if_fail (group_name != NULL);
+
+       priv = MODEST_UI_DIMMING_MANAGER_GET_PRIVATE(self);
+
+       /* Serach group by name */
+       group = g_hash_table_lookup (priv->groups_map, group_name);
+       g_return_if_fail (group != NULL);
+       
+       /*  */
+}
+
+
+static void
+_process_all_rules (gpointer key, gpointer value, gpointer user_data)
+{
+       g_return_if_fail (MODEST_IS_DIMMING_RULES_GROUP (value));
+       
+       modest_dimming_rules_group_execute (MODEST_DIMMING_RULES_GROUP (value));
+}
+
diff --git a/src/modest-ui-dimming-manager.h b/src/modest-ui-dimming-manager.h
new file mode 100644 (file)
index 0000000..4b6f520
--- /dev/null
@@ -0,0 +1,78 @@
+/* COPYRIGHT (c) 2006, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __MODEST_UI_DIMMING_MANAGER_H__
+#define __MODEST_UI_DIMMING_MANAGER_H__
+
+#include <glib-object.h>
+#include "modest-dimming-rules-group.h"
+
+G_BEGIN_DECLS
+
+/* convenience macros */
+#define MODEST_TYPE_UI_DIMMING_MANAGER             (modest_ui_dimming_manager_get_type())
+#define MODEST_UI_DIMMING_MANAGER(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_UI_DIMMING_MANAGER,ModestUIDimmingManager))
+#define MODEST_UI_DIMMING_MANAGER_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_UI_DIMMING_MANAGER,GObject))
+#define MODEST_IS_UI_DIMMING_MANAGER(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_UI_DIMMING_MANAGER))
+#define MODEST_IS_UI_DIMMING_MANAGER_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_UI_DIMMING_MANAGER))
+#define MODEST_UI_DIMMING_MANAGER_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_UI_DIMMING_MANAGER,ModestUIDimmingManagerClass))
+
+typedef struct _ModestUIDimmingManager      ModestUIDimmingManager;
+typedef struct _ModestUIDimmingManagerClass ModestUIDimmingManagerClass;
+
+struct _ModestUIDimmingManager {
+        GObject parent;
+       /* insert public members, if any */
+};
+
+struct _ModestUIDimmingManagerClass {
+       GObjectClass parent_class;
+       
+       /* Signals */
+};
+
+ModestUIDimmingManager* modest_ui_dimming_manager_new(void);
+
+
+void
+modest_ui_dimming_manager_insert_rules_group (ModestUIDimmingManager *self,
+                                                ModestDimmingRulesGroup *group);
+
+void
+modest_ui_dimming_manager_process_dimming_rules (ModestUIDimmingManager *self);
+
+
+void
+modest_ui_dimming_manager_process_dimming_rules_group (ModestUIDimmingManager *self,
+                                                      const gchar *group_name);
+
+
+G_END_DECLS
+
+#endif 
diff --git a/src/modest-ui-dimming-rules.c b/src/modest-ui-dimming-rules.c
new file mode 100644 (file)
index 0000000..3572d5a
--- /dev/null
@@ -0,0 +1,203 @@
+/* Copyright (c) 2006, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif /*HAVE_CONFIG_H*/
+
+#include "modest-ui-dimming-rules.h"
+#include "modest-tny-folder.h"
+
+static gboolean _folder_is_any_of_type (TnyFolder *folder, TnyFolderType types[], guint ntypes);
+static gboolean _invalid_msg_selected (ModestMainWindow *win, gboolean unique);
+
+gboolean 
+modest_ui_dimming_rules_on_new_folder (ModestWindow *win, gpointer user_data)
+{
+       GtkWidget *folder_view = NULL;
+       TnyFolderStore *parent_folder = NULL;
+       ModestTnyFolderRules rules;
+       gboolean dimmed = FALSE;
+
+       g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
+
+       /* Get folder view */
+       folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
+                                                          MODEST_WIDGET_TYPE_FOLDER_VIEW);
+       /* If no folder view, always dimmed */
+       if (!folder_view)
+               return TRUE;
+       
+       /* Get selected folder as parent of new folder to create */
+       parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
+       if (!parent_folder)
+               return TRUE;
+       
+       /* Check dimmed rule */ 
+       rules = modest_tny_folder_get_rules (TNY_FOLDER (parent_folder));
+       dimmed = rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE;
+
+       /* free */
+       g_object_unref (parent_folder);
+
+       return dimmed;
+}
+
+gboolean 
+modest_ui_dimming_rules_on_open_msg (ModestWindow *win, gpointer user_data)
+{
+       gboolean dimmed = FALSE;
+
+       g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
+               
+       /* Check dimmed rule */ 
+       dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), TRUE);
+
+       return dimmed;
+}
+
+gboolean 
+modest_ui_dimming_rules_on_reply_msg (ModestWindow *win, gpointer user_data)
+{
+       GtkWidget *folder_view = NULL;
+       TnyFolderStore *current_folder = NULL;
+       gboolean local_folder = FALSE;
+       gboolean dimmed = FALSE;
+       TnyFolderType types[2];
+
+       g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
+
+       /* Get folder view */
+       folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
+                                                          MODEST_WIDGET_TYPE_FOLDER_VIEW);
+       /* If no folder view, always dimmed */
+       if (!folder_view)
+               return TRUE;
+
+       /* Get selected folder as parent of new folder to create */
+       current_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
+       if (!current_folder)
+               return TRUE;
+       
+       if (TNY_IS_FOLDER(current_folder))
+               local_folder = modest_tny_folder_is_local_folder (TNY_FOLDER(current_folder));
+       types[0] = TNY_FOLDER_TYPE_DRAFTS; 
+       types[1] = TNY_FOLDER_TYPE_OUTBOX;
+
+       /* Check dimmed rule */ 
+       if (!dimmed)
+               dimmed = ((local_folder) && 
+                         (_folder_is_any_of_type (TNY_FOLDER(current_folder), types, 2)));
+       
+       if (!dimmed)
+               dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE);
+
+       /* free */
+       g_object_unref (current_folder);
+
+       return dimmed;
+}
+
+
+gboolean 
+modest_ui_dimming_rules_on_contents_msg (ModestWindow *win, gpointer user_data)
+{
+       gboolean dimmed = FALSE;
+
+       g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
+               
+       /* Check dimmed rule */ 
+       dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE);
+
+       return dimmed;
+}
+
+/* *********************** static utility functions ******************** */
+
+static gboolean
+_folder_is_any_of_type (TnyFolder *folder,
+                       TnyFolderType types[], 
+                       guint ntypes)
+{
+       TnyFolderType folder_type;
+       gboolean result = FALSE;
+       guint i;
+
+       g_return_val_if_fail (TNY_IS_FOLDER(folder), FALSE);
+
+       /* Get folder type */
+       if (modest_tny_folder_is_local_folder (folder))
+               folder_type = modest_tny_folder_get_local_folder_type (folder);         
+       else 
+               folder_type = modest_tny_folder_guess_folder_type (folder);             
+       
+       /* Check foler type */
+       for (i=0; i < ntypes; i++) {
+               result = result || folder_type == types[i];
+       }
+
+       return result;
+}
+
+
+
+static gboolean
+_invalid_msg_selected (ModestMainWindow *win,
+                      gboolean unique) 
+{
+       GtkWidget *header_view = NULL;          
+       GtkWidget *folder_view = NULL;
+       TnyList *selected_headers = NULL;
+       gboolean result = FALSE;
+
+       g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
+               
+       /* Get header view to check selected messages */
+       header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
+                                                          MODEST_WIDGET_TYPE_HEADER_VIEW);
+       
+       /* Get folder view to check focus */
+       folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
+                                                          MODEST_WIDGET_TYPE_FOLDER_VIEW);
+
+       /* Get selected headers */
+       selected_headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
+
+       /* Check dimmed rule (TODO: check focus on widgets */   
+       result = ((selected_headers == NULL) || 
+                 (GTK_WIDGET_HAS_FOCUS (folder_view)));
+       if (!result)
+               result = tny_list_get_length (selected_headers) > 1;
+       
+       /* free */
+       if (selected_headers != NULL) 
+               g_object_unref (selected_headers);
+
+       return result;
+}
diff --git a/src/modest-ui-dimming-rules.h b/src/modest-ui-dimming-rules.h
new file mode 100644 (file)
index 0000000..97c9c8d
--- /dev/null
@@ -0,0 +1,46 @@
+/* Copyright (c) 2006, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __MODEST_UI_DIMMING_RULES_H__
+#define __MODEST_UI_DIMMING_RULES_H__
+
+#include <widgets/modest-main-window.h>
+#include <widgets/modest-msg-edit-window.h>
+#include <widgets/modest-recpt-view.h>
+
+G_BEGIN_DECLS
+
+/* Menu & toolbar dimming rules */
+gboolean modest_ui_dimming_rules_on_new_folder (ModestWindow *win, gpointer user_data);
+gboolean modest_ui_dimming_rules_on_open_msg (ModestWindow *win, gpointer user_data);
+gboolean modest_ui_dimming_rules_on_reply_msg (ModestWindow *win, gpointer user_data);
+gboolean modest_ui_dimming_rules_on_contents_msg (ModestWindow *win, gpointer user_data);
+
+G_END_DECLS
+#endif 
index ae7a423..f1ddbdf 100644 (file)
@@ -1226,7 +1226,7 @@ drag_and_drop_from_header_view (GtkTreeModel *source_model,
        headers = tny_simple_list_new ();
        tny_list_append (headers, G_OBJECT (header));
        modest_mail_operation_xfer_msgs (mail_op, headers, folder, helper->delete_source, NULL, NULL);
-
+       
        /* Frees */
        g_object_unref (G_OBJECT (mail_op));
        g_object_unref (G_OBJECT (header));
index 5d10b75..ccf9ab0 100644 (file)
 #include <gtk/gtkuimanager.h>
 #include <tny-account-store.h>
 #include "modest-tny-platform-factory.h"
+#include "modest-ui-dimming-manager.h"
 
 G_BEGIN_DECLS
 
 typedef struct _ModestWindowPrivate ModestWindowPrivate;
 struct _ModestWindowPrivate {
        GtkUIManager         *ui_manager;
+       ModestUIDimmingManager  *ui_dimming_manager;
        GtkWidget            *toolbar;
        GtkWidget            *menubar;
 
index 07629b0..3eda53e 100644 (file)
@@ -112,6 +112,7 @@ modest_window_init (ModestWindow *obj)
        priv = MODEST_WINDOW_GET_PRIVATE(obj);
 
        priv->ui_manager     = NULL;
+       priv->ui_dimming_manager     = NULL;
        priv->toolbar        = NULL;
        priv->menubar        = NULL;
 
@@ -129,6 +130,10 @@ modest_window_finalize (GObject *obj)
                g_object_unref (G_OBJECT(priv->ui_manager));
                priv->ui_manager = NULL;
        }
+       if (priv->ui_dimming_manager) {
+               g_object_unref (G_OBJECT(priv->ui_dimming_manager));
+               priv->ui_dimming_manager = NULL;
+       }
 
        g_free (priv->active_account);
        
@@ -163,6 +168,29 @@ modest_window_set_active_account (ModestWindow *self, const gchar *active_accoun
 }
 
 void
+modest_window_check_dimming_rules (ModestWindow *self)
+{
+       ModestWindowPrivate *priv;      
+
+       priv = MODEST_WINDOW_GET_PRIVATE(self);
+       modest_ui_dimming_manager_process_dimming_rules (priv->ui_dimming_manager);
+}
+
+GtkAction *
+modest_window_get_action (ModestWindow *window, 
+                         const gchar *action_path) 
+{
+       GtkAction *action = NULL;
+       ModestWindowPrivate *priv;      
+
+       priv = MODEST_WINDOW_GET_PRIVATE(window);
+
+        action = gtk_ui_manager_get_action (priv->ui_manager, action_path);    
+
+       return action;
+}
+
+void
 modest_window_set_zoom (ModestWindow *window,
                        gdouble zoom)
 {
index edc9b34..808778e 100644 (file)
@@ -187,6 +187,27 @@ void     modest_window_show_toolbar (ModestWindow *window,
  **/
 void     modest_window_save_state (ModestWindow *window);
 
+
+/**
+ * modest_window_get_action:
+ * @window: a #ModestWindow instance object
+ * @action_path: the full path of required action.
+ * 
+ * Get an action from ui manager, using @action_path parameter,
+ * which represent the full path to the required action into UIManager 
+ * xml definition.
+ **/
+GtkAction * modest_window_get_action (ModestWindow *window, const gchar *action_path); 
+
+/**
+ * modest_window_check_dimming_rules:
+ * @self: a #ModestWindow instance object
+ * 
+ * Calls UI Dimming Manager of @self window to check all dimming rules.
+ * 
+ **/
+void modest_window_check_dimming_rules (ModestWindow *self);
+
 G_END_DECLS
 
 #endif /* __MODEST_WINDOW_H__ */