* Implement remain dimming rules (toolbar and context sensitive menus)
authorJavier Fernandez Garcia-Boente <jfernandez@igalia.com>
Sat, 2 Jun 2007 11:00:31 +0000 (11:00 +0000)
committerJavier Fernandez Garcia-Boente <jfernandez@igalia.com>
Sat, 2 Jun 2007 11:00:31 +0000 (11:00 +0000)
* Fixes: #NB57265, #NB57627, #NB57628, #NB57629, #NB57514, #NB58549, #NB58608, #NB59186, #NB59236

pmo-trunk-r2043

15 files changed:
src/maemo/modest-main-window-ui-dimming.h
src/maemo/modest-main-window.c
src/maemo/modest-msg-view-window-ui-dimming.h
src/maemo/modest-msg-view-window.c
src/maemo/ui/modest-main-window-ui.xml
src/modest-dimming-rule.c
src/modest-dimming-rule.h
src/modest-dimming-rules-group.c
src/modest-ui-actions.c
src/modest-ui-actions.h
src/modest-ui-dimming-manager.c
src/modest-ui-dimming-rules.c
src/modest-ui-dimming-rules.h
src/widgets/modest-window.c
src/widgets/modest-window.h

index 874c61d..8eb4fa8 100644 (file)
@@ -7,8 +7,8 @@
 G_BEGIN_DECLS
 
 
-/* Dimming rules entries */
-static const ModestDimmingEntry modest_dimming_entries [] = {
+/* Menu Dimming rules entries */
+static const ModestDimmingEntry modest_main_window_menu_dimming_entries [] = {
 
        /* Email Menu */
        { "/MenuBar/EmailMenu/EmailNewMainMenu", NULL },
@@ -60,24 +60,23 @@ static const ModestDimmingEntry modest_dimming_entries [] = {
        { "/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 },
+       { "/HeaderViewCSM/HeaderViewCSMOpen", G_CALLBACK(modest_ui_dimming_rules_on_open_msg) },
+       { "/HeaderViewCSM/HeaderViewCSMReply", G_CALLBACK(modest_ui_dimming_rules_on_reply_msg) },
+       { "/HeaderViewCSM/HeaderViewCSMReplyAll", G_CALLBACK(modest_ui_dimming_rules_on_reply_msg) },
+       { "/HeaderViewCSM/HeaderViewCSMForward", G_CALLBACK(modest_ui_dimming_rules_on_reply_msg) },
+       { "/HeaderViewCSM/HeaderViewCSMCut", NULL },
+       { "/HeaderViewCSM/HeaderViewCSMCopy", NULL },
+       { "/HeaderViewCSM/HeaderViewCSMPaste", G_CALLBACK(modest_ui_dimming_rules_on_paste_msgs) },
+       { "/HeaderViewCSM/HeaderViewCSMDelete", G_CALLBACK(modest_ui_dimming_rules_on_delete_msg) },
+       { "/HeaderViewCSM/HeaderViewCSMCancelSending", NULL },
+       { "/HeaderViewCSM/HeaderViewCSMHelp", NULL },
 
        /* Contextual Menus (Folder View) */
        { "/FolderViewCSM/FolderViewCSMNewFolder", G_CALLBACK(modest_ui_dimming_rules_on_new_folder) },
        { "/FolderViewCSM/FolderViewCSMRenameFolder", G_CALLBACK(modest_ui_dimming_rules_on_rename_folder) },
        { "/FolderViewCSM/FolderViewCSMPasteMsgs", G_CALLBACK(modest_ui_dimming_rules_on_paste_msgs) },
-       { "/FolderViewCSM/FolderViewCSMDeleteFolder", G_CALLBACK(modest_ui_dimming_rules_on_paste_msgs) },
+       { "/FolderViewCSM/FolderViewCSMDeleteFolder", G_CALLBACK(modest_ui_dimming_rules_on_delete_folder) },
        { "/FolderViewCSM/FolderViewCSMSearchMessages", NULL },
        { "/FolderViewCSM/FolderViewCSMHelp", NULL },
 
@@ -88,5 +87,18 @@ static const ModestDimmingEntry modest_dimming_entries [] = {
        
 };
 
+/* Toolbar Dimming rules entries */
+static const ModestDimmingEntry modest_main_window_toolbar_dimming_entries [] = {
+
+       /* Toolbar */
+       { "/ToolBar/ToolbarMessageNew", NULL },
+       { "/ToolBar/ToolbarMessageReply", G_CALLBACK(modest_ui_dimming_rules_on_reply_msg) },
+       { "/ToolBar/ToolbarDeleteMessage", G_CALLBACK(modest_ui_dimming_rules_on_delete_msg) },
+       { "/ToolBar/ToolbarToggleView", NULL },
+       { "/ToolBar/ToolbarSort", NULL },
+       { "/ToolBar/ToolbarSendReceive", NULL },
+       { "/ToolBar/ToolbarCancel", NULL },
+};
+
 G_END_DECLS
 #endif /* __MODEST_MAIN_WINDOW_UI_PRIV_H__ */
index 58c2495..fb77733 100644 (file)
@@ -193,6 +193,20 @@ static const GtkActionEntry modest_folder_view_action_entries [] = {
        { "FolderViewCSMHelp", NULL, N_("mcen_me_inbox_help"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_help) },
 };
 
+static const GtkActionEntry modest_header_view_action_entries [] = {
+
+       /* Header View CSM actions */
+       { "HeaderViewCSMOpen",          NULL,  N_("mcen_me_inbox_open"),        NULL,       NULL, G_CALLBACK (modest_ui_actions_on_new_folder) },
+       { "HeaderViewCSMReply",         NULL,  N_("mcen_me_inbox_reply"),       NULL,      NULL, G_CALLBACK (modest_ui_actions_on_reply) },
+       { "HeaderViewCSMReplyAll",      NULL,  N_("mcen_me_inbox_replytoall"),  NULL,      NULL, G_CALLBACK (modest_ui_actions_on_reply_all) },
+       { "HeaderViewCSMForward",       NULL,  N_("mcen_me_inbox_forward"),     NULL,      NULL, G_CALLBACK (modest_ui_actions_on_forward) },
+       { "HeaderViewCSMCut",           NULL,  N_("mcen_me_inbox_cut"),         "<CTRL>X", NULL, G_CALLBACK (modest_ui_actions_on_cut) },
+       { "HeaderViewCSMCopy",          NULL,  N_("mcen_me_inbox_copy"),        "<CTRL>C", NULL, G_CALLBACK (modest_ui_actions_on_copy) },
+       { "HeaderViewCSMPaste",         NULL,  N_("mcen_me_inbox_paste"),       "<CTRL>V", NULL, G_CALLBACK (modest_ui_actions_on_paste) },
+       { "HeaderViewCSMDelete",        NULL,  N_("mcen_me_inbox_delete"),      NULL,      NULL, G_CALLBACK (modest_ui_actions_on_delete) },
+       { "HeaderViewCSMCancelSending", NULL,  N_("mcen_me_outbox_cancelsend"), NULL,      NULL, NULL },
+       { "HeaderViewCSMHelp",          NULL,  N_("mcen_me_inbox_help"),        NULL,      NULL, G_CALLBACK (modest_ui_actions_on_help) },
+};
 
 static const GtkToggleActionEntry modest_main_window_toggle_action_entries [] = {
        { "ToolbarToggleView", MODEST_STOCK_SPLIT_VIEW, N_("gqn_toolb_rss_fldonoff"), "<CTRL>t", NULL, G_CALLBACK (modest_ui_actions_toggle_folders_view), FALSE },
@@ -440,9 +454,19 @@ _folder_view_csm_menu_activated (GtkWidget *widget, gpointer user_data)
        g_return_if_fail (MODEST_IS_MAIN_WINDOW (user_data));
 
        /* Update dimmed */     
-       modest_window_check_dimming_rules (MODEST_WINDOW (user_data));  
+       modest_window_check_dimming_rules_group (MODEST_WINDOW (user_data), "ModestMenuDimmingRules");  
 }
 
+static void
+_header_view_csm_menu_activated (GtkWidget *widget, gpointer user_data)
+{
+       g_return_if_fail (MODEST_IS_MAIN_WINDOW (user_data));
+
+       /* Update visibility */
+
+       /* Update dimmed */     
+       modest_window_check_dimming_rules_group (MODEST_WINDOW (user_data), "ModestMenuDimmingRules");  
+}
 
 static void
 connect_signals (ModestMainWindow *self)
@@ -462,6 +486,7 @@ connect_signals (ModestMainWindow *self)
        g_signal_connect (G_OBJECT(priv->folder_view), "folder-display-name-changed",
                          G_CALLBACK(modest_ui_actions_on_folder_display_name_changed), self);
 
+       /* Folder view CSM */
        menu = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/FolderViewCSM");
        gtk_widget_tap_and_hold_setup (GTK_WIDGET (priv->folder_view), menu, NULL, 0);
        g_signal_connect (G_OBJECT(priv->folder_view), "tap-and-hold",
@@ -479,6 +504,13 @@ connect_signals (ModestMainWindow *self)
        g_signal_connect (G_OBJECT(priv->header_view), "key-press-event",
                          G_CALLBACK(on_inner_widgets_key_pressed), self);
 
+       /* Header view CSM */
+       menu = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/HeaderViewCSM");
+       gtk_widget_tap_and_hold_setup (GTK_WIDGET (priv->header_view), menu, NULL, 0);
+       g_signal_connect (G_OBJECT(priv->header_view), "tap-and-hold",
+                         G_CALLBACK(_header_view_csm_menu_activated),
+                         self);
+       
        /* window */
        g_signal_connect (G_OBJECT(self), "delete-event", G_CALLBACK(on_delete_event), self);
        g_signal_connect (G_OBJECT (self), "window-state-event",
@@ -570,7 +602,8 @@ modest_main_window_new (void)
        ModestMainWindowPrivate *priv = NULL;
        ModestWindowPrivate *parent_priv = NULL;
        GtkWidget *folder_win = NULL;
-       ModestDimmingRulesGroup *rules_group = NULL;
+       ModestDimmingRulesGroup *menu_rules_group = NULL;
+       ModestDimmingRulesGroup *toolbar_rules_group = NULL;
        GtkActionGroup *action_group = NULL;
        GError *error = NULL;
        TnyFolderStoreQuery *query = NULL;
@@ -588,7 +621,8 @@ modest_main_window_new (void)
        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");
+       menu_rules_group = modest_dimming_rules_group_new ("ModestMenuDimmingRules");
+       toolbar_rules_group = modest_dimming_rules_group_new ("ModestToolbarDimmingRules");
 
        /* Add common actions */
        gtk_action_group_add_actions (action_group,
@@ -601,6 +635,11 @@ modest_main_window_new (void)
                                      G_N_ELEMENTS (modest_folder_view_action_entries),
                                      self);
 
+       gtk_action_group_add_actions (action_group,
+                                     modest_header_view_action_entries,
+                                     G_N_ELEMENTS (modest_header_view_action_entries),
+                                     self);
+
        gtk_action_group_add_toggle_actions (action_group,
                                             modest_toggle_action_entries,
                                             G_N_ELEMENTS (modest_toggle_action_entries),
@@ -624,14 +663,20 @@ modest_main_window_new (void)
        }
 
        /* Add common dimming rules */
-       modest_dimming_rules_group_add_rules (rules_group, 
-                                             modest_dimming_entries,
-                                             G_N_ELEMENTS (modest_dimming_entries),
+       modest_dimming_rules_group_add_rules (menu_rules_group, 
+                                             modest_main_window_menu_dimming_entries,
+                                             G_N_ELEMENTS (modest_main_window_menu_dimming_entries),
+                                             self);
+       modest_dimming_rules_group_add_rules (toolbar_rules_group, 
+                                             modest_main_window_toolbar_dimming_entries,
+                                             G_N_ELEMENTS (modest_main_window_toolbar_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);
+       modest_ui_dimming_manager_insert_rules_group (parent_priv->ui_dimming_manager, menu_rules_group);
+       modest_ui_dimming_manager_insert_rules_group (parent_priv->ui_dimming_manager, toolbar_rules_group);
+       g_object_unref (menu_rules_group);
+       g_object_unref (toolbar_rules_group);
        
        /* Add accelerators */
        gtk_window_add_accel_group (GTK_WINDOW (self), 
index 2f3dc57..7ed4e13 100644 (file)
@@ -7,8 +7,8 @@
 G_BEGIN_DECLS
 
 
-/* Dimming rules entries */
-static const ModestDimmingEntry modest_msg_view_dimming_entries [] = {
+/* Menu Dimming rules entries */
+static const ModestDimmingEntry modest_msg_view_menu_dimming_entries [] = {
 
        /* Message Menu */
        { "/MenuBar/MessageMenu/MessageNewMenu", G_CALLBACK(modest_ui_dimming_rules_on_new_msg) },
@@ -48,21 +48,25 @@ static const ModestDimmingEntry modest_msg_view_dimming_entries [] = {
        { "/MenuBar/ToolsMenu/CloseWindowMenu", NULL },
        { "/MenuBar/ToolsMenu/CloseAllWindowsMenu", NULL },
 
+       /* Contextual Menus (Toolbar) */
+       { "/ToolbarReplyCSM/MessageForwardMenu", NULL },
+       { "/ToolbarReplyCSM/MessageReplyAllMenu", NULL },
+       { "/ToolbarReplyCSM/MessageReplyMenu", NULL },
+       
+};
+
+/* Menu Dimming rules entries */
+static const ModestDimmingEntry modest_msg_view_toolbar_dimming_entries [] = {
+
        /* Toolbar */
        { "/Toolbar/ToolbarMessageNew", NULL },
-       { "/Toolbar/ToolbarMessageReply", NULL },
-       { "/Toolbar/ToolbarDeleteMessage", NULL },
-       { "/Toolbar/ToolbarMoveTo", NULL },
+       { "/Toolbar/ToolbarMessageReply", G_CALLBACK(modest_ui_dimming_rules_on_reply_msg) },
+       { "/Toolbar/ToolbarDeleteMessage",  G_CALLBACK(modest_ui_dimming_rules_on_delete_msg) },
+       { "/Toolbar/ToolbarMoveTo", G_CALLBACK(modest_ui_dimming_rules_on_move_to) },
        { "/Toolbar/ToolbarFindInMessage", NULL },
        { "/Toolbar/ToolbarMessageBack", NULL },
        { "/Toolbar/ToolbarMessageNext", NULL },
        { "/Toolbar/ToolbarCancel", NULL },
-
-       /* Contextual Menus (Toolbar) */
-       { "/ToolbarReplyCSM/MessageForwardMenu", NULL },
-       { "/ToolbarReplyCSM/MessageReplyAllMenu", NULL },
-       { "/ToolbarReplyCSM/MessageReplyMenu", NULL },
-       
 };
 
 G_END_DECLS
index 3e9ecdd..949cba0 100644 (file)
@@ -499,7 +499,8 @@ modest_msg_view_window_new (TnyMsg *msg,
        GObject *obj = NULL;
        ModestMsgViewWindowPrivate *priv = NULL;
        ModestWindowPrivate *parent_priv = NULL;
-       ModestDimmingRulesGroup *rules_group = NULL;
+       ModestDimmingRulesGroup *menu_rules_group = NULL;
+       ModestDimmingRulesGroup *toolbar_rules_group = NULL;
        GtkActionGroup *action_group = NULL;
        GError *error = NULL;
        GdkPixbuf *window_icon = NULL;
@@ -520,7 +521,8 @@ modest_msg_view_window_new (TnyMsg *msg,
        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");
+       menu_rules_group = modest_dimming_rules_group_new ("ModestMenuDimmingRules");
+       toolbar_rules_group = modest_dimming_rules_group_new ("ModestToolbarDimmingRules");
 
        /* Add common actions */
        gtk_action_group_add_actions (action_group,
@@ -556,14 +558,20 @@ modest_msg_view_window_new (TnyMsg *msg,
        /* ****** */
 
        /* 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),
+       modest_dimming_rules_group_add_rules (menu_rules_group, 
+                                             modest_msg_view_menu_dimming_entries,
+                                             G_N_ELEMENTS (modest_msg_view_menu_dimming_entries),
+                                             self);
+       modest_dimming_rules_group_add_rules (toolbar_rules_group, 
+                                             modest_msg_view_toolbar_dimming_entries,
+                                             G_N_ELEMENTS (modest_msg_view_toolbar_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);
+       modest_ui_dimming_manager_insert_rules_group (parent_priv->ui_dimming_manager, menu_rules_group);
+       modest_ui_dimming_manager_insert_rules_group (parent_priv->ui_dimming_manager, toolbar_rules_group);
+       g_object_unref (menu_rules_group);
+       g_object_unref (toolbar_rules_group);
 
        /* Add accelerators */
        gtk_window_add_accel_group (GTK_WINDOW (obj), 
index 471c6dc..b261c36 100644 (file)
     <toolitem action="ToolbarCancel"/>
   </toolbar>
 
-  <popup name="HeaderViewCSM" action="HeaderViewCSM">
-    <menuitem action="EmailReply"/>
-    <menuitem action="EmailForward"/>
+  <popup name="HeaderViewCSM">
+    <menuitem action="HeaderViewCSMOpen"/>
+    <menuitem action="HeaderViewCSMReply"/>
+    <menuitem action="HeaderViewCSMReplyAll"/>
+    <menuitem action="HeaderViewCSMForward"/>
+    <separator/>
+    <menuitem action="HeaderViewCSMCut"/>
+    <menuitem action="HeaderViewCSMCopy"/>
+    <menuitem action="HeaderViewCSMPaste"/>
+    <separator/>
+    <menuitem action="HeaderViewCSMDelete"/>
+    <menuitem action="HeaderViewCSMCancelSending"/>
+    <menuitem action="HeaderViewCSMHelp"/>
   </popup>
   
-  <popup name="FolderViewCSM" action="FolderViewCSM">
+  <popup name="FolderViewCSM">
     <menuitem action="FolderViewCSMNewFolder"/>
     <menuitem action="FolderViewCSMRenameFolder"/>
     <separator/>
index 884ccc7..4b7f13b 100644 (file)
@@ -38,6 +38,7 @@ struct _ModestDimmingRulePrivate {
        ModestWindow *win;
        ModestDimmingCallback dimming_rule;
        gchar *action_path;
+       gchar *notification;
 };
 
 #define MODEST_DIMMING_RULE_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
@@ -92,6 +93,7 @@ modest_dimming_rule_init (ModestDimmingRule *obj)
        priv->win = NULL;
        priv->dimming_rule = NULL;
        priv->action_path = NULL;
+       priv->notification = NULL;
 }
 
 static void
@@ -103,6 +105,8 @@ modest_dimming_rule_finalize (GObject *obj)
 
        if (priv->action_path != NULL)
                g_free(priv->action_path);
+       if (priv->notification != NULL)
+               g_free(priv->notification);
 
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
@@ -145,10 +149,38 @@ modest_dimming_rule_process (ModestDimmingRule *self)
        g_return_if_fail (priv->action_path != NULL);
 
        /* process dimming rule */
-       dimmed = priv->dimming_rule (priv->win, NULL);
+       dimmed = priv->dimming_rule (priv->win, self);
 
        /* 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);
 }
+
+void
+modest_dimming_rule_set_notification (ModestDimmingRule *rule,
+                                     const gchar *notification)
+{
+       ModestDimmingRulePrivate *priv = NULL;
+
+       g_return_if_fail (MODEST_IS_DIMMING_RULE (rule));
+       priv = MODEST_DIMMING_RULE_GET_PRIVATE(rule);
+       
+       /* Free previous notification */
+       if (priv->notification != NULL)
+               g_free(priv->notification);
+
+       /* Set new notification message */
+       priv->notification = g_strdup(notification);
+}
+
+gchar *
+modest_dimming_rule_get_notification (ModestDimmingRule *rule)
+{
+       ModestDimmingRulePrivate *priv = NULL;
+
+       g_return_val_if_fail (MODEST_IS_DIMMING_RULE (rule), NULL);
+       priv = MODEST_DIMMING_RULE_GET_PRIVATE(rule);
+       
+       return g_strdup(priv->notification);
+}
index 0e7e8ad..300d098 100644 (file)
@@ -81,8 +81,23 @@ ModestDimmingRule*    modest_dimming_rule_new     (ModestWindow *win,
                                                   ModestDimmingCallback dimming_rule,
                                                   const gchar *action_path);
 
-void
-modest_dimming_rule_process (ModestDimmingRule *self);
+/**
+ * modest_dimming_rule_process:
+ * @rule: a #ModestDimmingRule object to process.
+ * 
+ * Process dimming rule, executing private callback defined at 
+ * instantiation time. This callback may updates notification provate field
+ * of @rule in order to show information banners when 'insensitive-press'
+ * events occurs. 
+ *
+ **/
+void modest_dimming_rule_process (ModestDimmingRule *self);
+
+void modest_dimming_rule_set_notification (ModestDimmingRule *rule,
+                                          const gchar *notification);
+
+gchar *modest_dimming_rule_get_notification (ModestDimmingRule *rule);
+                                          
 
 G_END_DECLS
 
index fe9ff6f..c3e2d64 100644 (file)
 #include "modest-dimming-rules-group.h"
 #include "modest-dimming-rules-group-priv.h"
 #include "modest-dimming-rule.h"
+#include "modest-hildon-includes.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);
 
+static void _insensitive_press_callback (GtkWidget *widget, gpointer user_data);
+
+
 typedef struct _ModestDimmingRulesGroupPrivate ModestDimmingRulesGroupPrivate;
 struct _ModestDimmingRulesGroupPrivate {       
        gchar *name;
@@ -49,6 +53,7 @@ struct _ModestDimmingRulesGroupPrivate {
 static GObjectClass *parent_class = NULL;
 
 static void _execute_dimming_rule (gpointer key, gpointer value, gpointer user_data);
+static void _insensitive_press_callback (GtkWidget *widget, gpointer user_data);
 
 
 
@@ -157,6 +162,7 @@ modest_dimming_rules_group_add_rules (ModestDimmingRulesGroup *self,
        ModestDimmingRulesGroupPrivate *priv;
        ModestDimmingRule *dim_rule = NULL;
        ModestDimmingEntry entry;
+       GtkWidget *widget = NULL;
        gboolean unique = FALSE;
        guint i;
 
@@ -178,11 +184,18 @@ modest_dimming_rules_group_add_rules (ModestDimmingRulesGroup *self,
                unique = g_hash_table_lookup (priv->rules_map, entry.action_path) == NULL;
                if (!unique) continue;
 
+               /* Check action path is valid */
+               widget = modest_window_get_action_widget (MODEST_WINDOW (user_data), entry.action_path);
+               if (widget == NULL) continue;
+
                /* Create a new dimming rule */
                dim_rule = modest_dimming_rule_new (MODEST_WINDOW(user_data),
                                                    (ModestDimmingCallback) entry.callback,
                                                    entry.action_path);
                
+               /* Connect insensitive-presss handler to show notifications */
+               g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (_insensitive_press_callback), dim_rule);
+
                /* Register new dimming rule */         
                g_hash_table_insert (priv->rules_map, g_strdup(entry.action_path), dim_rule);
        }
@@ -207,3 +220,23 @@ _execute_dimming_rule (gpointer key, gpointer value, gpointer user_data)
        /* Process diomming rule */
        modest_dimming_rule_process (MODEST_DIMMING_RULE(value));
 }
+
+static void
+_insensitive_press_callback (GtkWidget *widget, gpointer user_data)
+{
+       ModestDimmingRule *rule;
+       gchar *notification = NULL;
+
+       g_return_if_fail (MODEST_IS_DIMMING_RULE (user_data));
+       rule = MODEST_DIMMING_RULE (user_data);
+
+       /* Get specific notification */
+       notification = modest_dimming_rule_get_notification (rule);
+       if (notification == NULL) return;
+
+       /* Show notification banner */
+       hildon_banner_show_information (NULL, NULL, notification);      
+
+       /* Free */
+       g_free(notification);
+}
index ce758b1..c551d04 100644 (file)
@@ -1174,6 +1174,9 @@ modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
                else
                        gtk_window_set_title (GTK_WINDOW (main_window), _("mail_va_no_subject"));
        }
+
+       /* Update toolbar dimming state */
+       modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
 }
 
 void
@@ -1266,6 +1269,9 @@ modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
                        modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view), NULL);
                }
        }
+
+       /* Update toolbar dimming state */
+       modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
 }
 
 void 
@@ -2139,6 +2145,21 @@ modest_ui_actions_on_select_all (GtkAction *action,
                gtk_text_buffer_get_end_iter (buffer, &end);
                gtk_text_buffer_select_range (buffer, &start, &end);
        }
+       else if ((MODEST_IS_FOLDER_VIEW (focused_widget)) ||
+                (MODEST_IS_HEADER_VIEW (focused_widget))) {
+               
+               GtkTreeSelection *selection = NULL;
+
+               /* Get header view */           
+               GtkWidget *header_view = focused_widget;
+               if (MODEST_IS_FOLDER_VIEW (focused_widget))
+                       header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
+                                                                          MODEST_WIDGET_TYPE_HEADER_VIEW);
+
+               /* Select all messages */
+               selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
+               gtk_tree_selection_select_all (selection);
+       }
 }
 
 void
@@ -2931,7 +2952,7 @@ modest_ui_actions_on_email_menu_activated (GtkAction *action,
        g_return_if_fail (MODEST_IS_WINDOW (window));
 
        /* Update dimmed */     
-       modest_window_check_dimming_rules (window);     
+       modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");     
 }
 
 void
@@ -2941,7 +2962,7 @@ modest_ui_actions_on_edit_menu_activated (GtkAction *action,
        g_return_if_fail (MODEST_IS_WINDOW (window));
 
        /* Update dimmed */     
-       modest_window_check_dimming_rules (window);     
+       modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");     
 }
 
 void
@@ -2951,7 +2972,7 @@ modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
        g_return_if_fail (MODEST_IS_WINDOW (window));
 
        /* Update dimmed */     
-       modest_window_check_dimming_rules (window);     
+       modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");     
 }
 
 void
@@ -2961,7 +2982,7 @@ modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
        g_return_if_fail (MODEST_IS_WINDOW (window));
 
        /* Update dimmed */     
-       modest_window_check_dimming_rules (window);     
+       modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");     
 }
 
 void
@@ -2971,5 +2992,14 @@ modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
        g_return_if_fail (MODEST_IS_WINDOW (window));
 
        /* Update dimmed */     
-       modest_window_check_dimming_rules (window);     
+       modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");     
+}
+
+void
+modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */     
+       modest_window_check_dimming_rules_group (window, "ModestToolbarDimmingRules");  
 }
index 46eb9dd..e82d84a 100644 (file)
@@ -352,6 +352,9 @@ void
 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
                                                     ModestWindow *window);
 
+void
+modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window);
+
 /**
  * modest_ui_actions_move_folder_error_handler:
  * @mail_op: a #ModestMailOperation
index 2dd082c..c2a5427 100644 (file)
@@ -171,10 +171,11 @@ modest_ui_dimming_manager_process_dimming_rules_group (ModestUIDimmingManager *s
        priv = MODEST_UI_DIMMING_MANAGER_GET_PRIVATE(self);
 
        /* Serach group by name */
-       group = g_hash_table_lookup (priv->groups_map, group_name);
+       group = MODEST_DIMMING_RULES_GROUP(g_hash_table_lookup (priv->groups_map, group_name));
        g_return_if_fail (group != NULL);
        
-       /*  */
+       /* Performs group dimming rules checking */
+       modest_dimming_rules_group_execute (group);
 }
 
 
index 82ad2de..b4db632 100644 (file)
 
 #include <string.h>
 #include "modest-ui-dimming-rules.h"
+#include "modest-dimming-rule.h"
 #include "modest-tny-folder.h"
 #include <modest-runtime.h>
 
 
 static gboolean _folder_is_any_of_type (TnyFolder *folder, TnyFolderType types[], guint ntypes);
-static gboolean _invalid_msg_selected (ModestMainWindow *win, gboolean unique);
+static gboolean _invalid_msg_selected (ModestMainWindow *win, gboolean unique, ModestDimmingRule *rule);
 static gboolean _already_opened_msg (ModestWindow *win);
 static gboolean _selected_msg_marked_as (ModestWindow *win, TnyHeaderFlags mask, gboolean opposite);
 static gboolean _selected_folder_not_writeable (ModestMainWindow *win);
 static gboolean _selected_folder_is_any_of_type (ModestMainWindow *win, TnyFolderType types[], guint ntypes);
 static gboolean _selected_folder_is_root (ModestMainWindow *win);
+static gboolean _selected_folder_is_empty (ModestMainWindow *win);
 static gboolean _msg_download_in_progress (ModestMsgViewWindow *win);
 
 
@@ -102,6 +104,22 @@ modest_ui_dimming_rules_on_new_folder (ModestWindow *win, gpointer user_data)
 }
 
 gboolean 
+modest_ui_dimming_rules_on_delete_folder (ModestWindow *win, gpointer user_data)
+{
+       gboolean dimmed = FALSE;
+
+       g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
+               
+       /* Check dimmed rule */ 
+       if (!dimmed)
+               dimmed = _selected_folder_not_writeable (MODEST_MAIN_WINDOW(win));
+       if (!dimmed)
+               dimmed = _selected_folder_is_root (MODEST_MAIN_WINDOW(win));
+
+       return dimmed;
+}
+
+gboolean 
 modest_ui_dimming_rules_on_rename_folder (ModestWindow *win, gpointer user_data)
 {
        gboolean dimmed = FALSE;
@@ -120,13 +138,16 @@ modest_ui_dimming_rules_on_rename_folder (ModestWindow *win, gpointer user_data)
 gboolean 
 modest_ui_dimming_rules_on_open_msg (ModestWindow *win, gpointer user_data)
 {
+       ModestDimmingRule *rule = NULL;
        gboolean dimmed = FALSE;
 
        g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
+       g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
+       rule = MODEST_DIMMING_RULE (user_data);
                
        /* Check dimmed rule */ 
        if (!dimmed)
-               dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), TRUE);
+               dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), TRUE, user_data);
 
        return dimmed;
 }
@@ -134,9 +155,13 @@ 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)
 {
+       ModestDimmingRule *rule = NULL;
        gboolean dimmed = FALSE;
        TnyFolderType types[3];
 
+       g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
+       rule = MODEST_DIMMING_RULE (user_data);
+
        /* main window dimming rules */
        if (MODEST_IS_MAIN_WINDOW(win)) {
                
@@ -145,11 +170,16 @@ modest_ui_dimming_rules_on_reply_msg (ModestWindow *win, gpointer user_data)
                types[2] = TNY_FOLDER_TYPE_ROOT;
                
                /* Check dimmed rule */ 
+               if (!dimmed) {
+                       dimmed = _selected_folder_is_any_of_type (MODEST_MAIN_WINDOW(win), types, 3);                   
+                       modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_reply"));
+               }
+               if (!dimmed) {
+                       dimmed = _selected_folder_is_empty (MODEST_MAIN_WINDOW(win));                   
+                       modest_dimming_rule_set_notification (rule, _("mcen_ib_nothing_to_reply"));
+               }
                if (!dimmed)
-                       dimmed = _selected_folder_is_any_of_type (MODEST_MAIN_WINDOW(win), types, 3);
-               
-               if (!dimmed)
-                       dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE);
+                       dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), TRUE, rule);
 
        /* msg view window dimming rules */
        } else if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
@@ -171,7 +201,7 @@ modest_ui_dimming_rules_on_contents_msg (ModestWindow *win, gpointer user_data)
        g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
                
        /* Check dimmed rule */ 
-       dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE);
+       dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
 
        return dimmed;
 }
@@ -193,16 +223,27 @@ modest_ui_dimming_rules_always_dimmed (ModestWindow *win, gpointer user_data)
 gboolean 
 modest_ui_dimming_rules_on_delete_msg (ModestWindow *win, gpointer user_data)
 {
+       ModestDimmingRule *rule = NULL;
        gboolean dimmed = FALSE;
        
        g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
+       g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
+       rule = MODEST_DIMMING_RULE (user_data);
        
        /* Check dimmed rule */ 
-       if (!dimmed)
-               dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE);
-       if (!dimmed)
+       if (!dimmed) {
+               dimmed = _selected_folder_is_empty (MODEST_MAIN_WINDOW(win));                   
+               modest_dimming_rule_set_notification (rule, _("mcen_ib_nothing_to_del"));
+       }
+       if (!dimmed) {
+               dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
+               modest_dimming_rule_set_notification (rule, _("mcen_ib_no_message_selected"));
+       }
+       if (!dimmed) {
                dimmed = _already_opened_msg (win);
-       
+               modest_dimming_rule_set_notification (rule, _("mcen_nc_unable_to_delete_n_messages"));
+       }
+
        return dimmed;
 }
 
@@ -210,22 +251,23 @@ gboolean
 modest_ui_dimming_rules_on_details (ModestWindow *win, gpointer user_data)
 {
        gboolean dimmed = FALSE;
+       GtkWidget *header_view = NULL;
        
        /* main window dimming rules */
        if (MODEST_IS_MAIN_WINDOW(win)) {
-               GtkWidget *header_view;
-
+                               
                /* Check dimmed rule */
                header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
                                                                   MODEST_WIDGET_TYPE_HEADER_VIEW);
-
+               
                /* If the header view does not have the focus then do
                   not apply msg dimming rules because the action will
                   show the folder details that have no dimming
                   rule */
                if (gtk_widget_is_focus (header_view)) {
+                       /* Check dimmed rule */ 
                        if (!dimmed)
-                               dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), TRUE);
+                               dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), TRUE, user_data);
                }
 
        /* msg view window dimming rules */
@@ -251,7 +293,7 @@ modest_ui_dimming_rules_on_mark_as_read_msg (ModestWindow *win, gpointer user_da
 
        /* Check dimmed rule */ 
        if (!dimmed)
-               dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE);
+               dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
        if (!dimmed) 
                dimmed = _selected_msg_marked_as (win, flags, FALSE);
        
@@ -270,7 +312,7 @@ modest_ui_dimming_rules_on_mark_as_unread_msg (ModestWindow *win, gpointer user_
 
        /* Check dimmed rule */ 
        if (!dimmed)
-               dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE);
+               dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
        if (!dimmed) 
                dimmed = _selected_msg_marked_as (win, flags, TRUE);
 
@@ -318,7 +360,7 @@ modest_ui_dimming_rules_on_main_window_move_to (ModestWindow *win, gpointer user
        /* Check diming rules for msg transfer  */
        else if (gtk_widget_is_focus (header_view)) {
                if (!dimmed)
-                       dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE);
+                       dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
                
        }
 
@@ -395,7 +437,7 @@ _selected_folder_not_writeable (ModestMainWindow *win)
        
        /* 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 || TNY_IS_FOLDER(parent_folder)))
+       if (!(parent_folder && TNY_IS_FOLDER(parent_folder)))
                return TRUE;
        
        /* Check dimmed rule */ 
@@ -425,6 +467,37 @@ _selected_folder_is_root (ModestMainWindow *win)
        return result;
 }
 
+
+static gboolean
+_selected_folder_is_empty (ModestMainWindow *win)
+{
+       GtkWidget *folder_view = NULL;
+       TnyFolderStore *folder = NULL;
+       gboolean result = 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 */
+       folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
+       if (!(folder && TNY_IS_FOLDER(folder)))
+               return TRUE;
+       
+       /* Check folder type */
+       result = tny_folder_get_all_count (TNY_FOLDER (folder)) == 0;
+
+       /* free */
+       g_object_unref (folder);
+
+       return result;
+}
+
 static gboolean
 _selected_folder_is_any_of_type (ModestMainWindow *win,
                                 TnyFolderType types[], 
@@ -445,7 +518,7 @@ _selected_folder_is_any_of_type (ModestMainWindow *win,
        
        /* Get selected folder as parent of new folder to create */
        folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
-       if (!(folder || TNY_IS_FOLDER(folder)))
+       if (!(folder && TNY_IS_FOLDER(folder)))
                return TRUE;
        
        /* Check folder type */
@@ -486,7 +559,8 @@ _folder_is_any_of_type (TnyFolder *folder,
 
 static gboolean
 _invalid_msg_selected (ModestMainWindow *win,
-                      gboolean unique) 
+                      gboolean unique,
+                      ModestDimmingRule *rule) 
 {
        GtkWidget *header_view = NULL;          
        GtkWidget *folder_view = NULL;
@@ -494,6 +568,7 @@ _invalid_msg_selected (ModestMainWindow *win,
        gboolean result = FALSE;
 
        g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
+       g_return_val_if_fail (MODEST_IS_DIMMING_RULE (rule), FALSE);
                
        /* Get header view to check selected messages */
        header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
@@ -507,11 +582,16 @@ _invalid_msg_selected (ModestMainWindow *win,
        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)
+       if (!result) {
+               result = ((selected_headers == NULL) || 
+                         (GTK_WIDGET_HAS_FOCUS (folder_view)));
+               modest_dimming_rule_set_notification (rule, _("mcen_ib_no_message_selected"));
+       }
+       if (!result) {
                result = tny_list_get_length (selected_headers) > 1;
-       
+               modest_dimming_rule_set_notification (rule, _("mcen_ib_select_one_message"));
+       }
+
        /* free */
        if (selected_headers != NULL) 
                g_object_unref (selected_headers);
index 5f5c7ca..4022e66 100644 (file)
@@ -39,6 +39,7 @@ G_BEGIN_DECLS
 /* Menu & toolbar dimming rules */
 gboolean modest_ui_dimming_rules_on_new_msg (ModestWindow *win, gpointer user_data);
 gboolean modest_ui_dimming_rules_on_new_folder (ModestWindow *win, gpointer user_data);
+gboolean modest_ui_dimming_rules_on_delete_folder (ModestWindow *win, gpointer user_data);
 gboolean modest_ui_dimming_rules_on_rename_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);
index 3eda53e..3407115 100644 (file)
@@ -172,10 +172,24 @@ modest_window_check_dimming_rules (ModestWindow *self)
 {
        ModestWindowPrivate *priv;      
 
+       g_return_if_fail (MODEST_IS_WINDOW (self));
        priv = MODEST_WINDOW_GET_PRIVATE(self);
+
        modest_ui_dimming_manager_process_dimming_rules (priv->ui_dimming_manager);
 }
 
+void
+modest_window_check_dimming_rules_group (ModestWindow *self,
+                                        const gchar *group_name)
+{
+       ModestWindowPrivate *priv;      
+
+       g_return_if_fail (MODEST_IS_WINDOW (self));
+       priv = MODEST_WINDOW_GET_PRIVATE(self);
+
+       modest_ui_dimming_manager_process_dimming_rules_group (priv->ui_dimming_manager, group_name);
+}
+
 GtkAction *
 modest_window_get_action (ModestWindow *window, 
                          const gchar *action_path) 
@@ -183,6 +197,7 @@ modest_window_get_action (ModestWindow *window,
        GtkAction *action = NULL;
        ModestWindowPrivate *priv;      
 
+       g_return_val_if_fail (MODEST_IS_WINDOW (window), NULL);
        priv = MODEST_WINDOW_GET_PRIVATE(window);
 
         action = gtk_ui_manager_get_action (priv->ui_manager, action_path);    
@@ -190,6 +205,21 @@ modest_window_get_action (ModestWindow *window,
        return action;
 }
 
+GtkWidget *
+modest_window_get_action_widget (ModestWindow *window, 
+                                const gchar *action_path) 
+{
+       GtkWidget *widget = NULL;
+       ModestWindowPrivate *priv;      
+
+       g_return_val_if_fail (MODEST_IS_WINDOW (window), NULL);
+       priv = MODEST_WINDOW_GET_PRIVATE(window);
+
+        widget = gtk_ui_manager_get_widget (priv->ui_manager, action_path);    
+
+       return widget;
+}
+
 void
 modest_window_set_zoom (ModestWindow *window,
                        gdouble zoom)
index 808778e..d41f16c 100644 (file)
@@ -200,6 +200,18 @@ void     modest_window_save_state (ModestWindow *window);
 GtkAction * modest_window_get_action (ModestWindow *window, const gchar *action_path); 
 
 /**
+ * modest_window_get_action_widget:
+ * @window: a #ModestWindow instance object
+ * @action_path: the full path of required action.
+ * 
+ * Get action widget from ui manager, using @action_path parameter,
+ * which represent the full path to the required action into UIManager 
+ * xml definition.
+ **/
+GtkWidget *modest_window_get_action_widget (ModestWindow *window, 
+                                           const gchar *action_path);
+
+/**
  * modest_window_check_dimming_rules:
  * @self: a #ModestWindow instance object
  * 
@@ -208,6 +220,19 @@ GtkAction * modest_window_get_action (ModestWindow *window, const gchar *action_
  **/
 void modest_window_check_dimming_rules (ModestWindow *self);
 
+/**
+ * modest_window_check_dimming_rules:
+ * @self: a #ModestWindow instance object
+ * @group: a #ModestWindow instance object
+ * 
+ * Calls UI Dimming Manager of @self window to check @group_name specific
+ * dimming rules.
+ * 
+ **/
+void
+modest_window_check_dimming_rules_group (ModestWindow *self,
+                                        const gchar *group_name);
+
 G_END_DECLS
 
 #endif /* __MODEST_WINDOW_H__ */