fixes NB#64231
authorPeter Csaszar <pcsaszar@blumsoft.eu>
Wed, 29 Aug 2007 09:18:07 +0000 (09:18 +0000)
committerPeter Csaszar <pcsaszar@blumsoft.eu>
Wed, 29 Aug 2007 09:18:07 +0000 (09:18 +0000)
pmo-trunk-r3118

src/modest-ui-actions.c

index 90df4ab..4666309 100644 (file)
@@ -3486,8 +3486,10 @@ create_move_to_dialog_on_new_folder(GtkWidget *button, gpointer user_data)
 /*
  * This function is used to track changes in the selection of the
  * folder view that is inside the "move to" dialog to enable/disable
- * the OK button because we do not want the user to select a
- * disallowed destination for a folder
+ * the OK button because we do not want the user to select a disallowed
+ * destination for a folder.
+ * The user also not desired to be able to use NEW button on items where
+ * folder creation is not possibel.
  */
 static void
 on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
@@ -3495,9 +3497,12 @@ on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
                                            gboolean selected,
                                            gpointer user_data)
 {
-       GtkWidget *dialog = NULL, *ok_button = NULL;
+       GtkWidget *dialog = NULL;
+       GtkWidget *ok_button = NULL, *new_button = NULL;
        GList *children = NULL;
-       gboolean sensitive = TRUE, moving_folder = FALSE;
+       gboolean ok_sensitive = TRUE, new_sensitive = TRUE;
+       gboolean moving_folder = FALSE;
+       gboolean is_remote_account = FALSE;
        GtkWidget *folder_view = NULL;
 
        if (!selected)
@@ -3510,8 +3515,33 @@ on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
 
        children = gtk_container_get_children (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area));
        ok_button = GTK_WIDGET (children->next->next->data);
+       new_button = GTK_WIDGET (children->next->data);
        g_list_free (children);
 
+       /* check if folder_store is an remote account */
+       if (TNY_IS_ACCOUNT (folder_store)) {
+               TnyAccount *local_account = NULL;
+               ModestTnyAccountStore *account_store = NULL;
+
+               account_store = modest_runtime_get_account_store ();
+               local_account = modest_tny_account_store_get_local_folders_account (account_store);
+
+               if ((gpointer) local_account != (gpointer) folder_store)
+                       is_remote_account = TRUE;
+               g_object_unref (local_account);
+       }
+
+       /* New button should be dimmed on remote account root folder
+        * and on inbox folder. */
+       if (is_remote_account)
+               new_sensitive = FALSE;
+
+       /* check if folder_store is an rmeote inbox folder */
+       if (TNY_IS_FOLDER (folder_store))
+               if (tny_folder_get_folder_type(TNY_FOLDER(folder_store))
+                               == TNY_FOLDER_TYPE_INBOX)
+                       new_sensitive = FALSE;
+
        /* If it */
        if (MODEST_IS_MAIN_WINDOW (user_data)) {
                /* Get the widgets */
@@ -3531,27 +3561,20 @@ on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
                if (TNY_IS_FOLDER (moved_folder)) {
                        parent = tny_folder_get_folder_store (TNY_FOLDER (moved_folder));
                        if (parent == folder_store)
-                               sensitive = FALSE;
+                               ok_sensitive = FALSE;
                        g_object_unref (parent);
                } 
 
-               if (sensitive && TNY_IS_ACCOUNT (folder_store)) {
-                       TnyAccount *local_account = NULL;
-                       ModestTnyAccountStore *account_store;
-
-                       account_store = modest_runtime_get_account_store ();
-                       local_account = modest_tny_account_store_get_local_folders_account (account_store);
-
+               if (ok_sensitive && TNY_IS_ACCOUNT (folder_store)) {
                        /* Do not allow to move to an account unless it's the
                           local folders account */
-                       if ((gpointer) local_account != (gpointer) folder_store)
-                               sensitive = FALSE;
-                       g_object_unref (local_account);
+                       if (is_remote_account)
+                               ok_sensitive = FALSE;
                } 
 
-               if (sensitive && (moved_folder == folder_store)) {
+               if (ok_sensitive && (moved_folder == folder_store)) {
                        /* Do not allow to move to itself */
-                       sensitive = FALSE;
+                       ok_sensitive = FALSE;
                }
                g_object_unref (moved_folder);
        } else {
@@ -3572,12 +3595,14 @@ on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
                /* Do not allow to move the msg to an account */
                if ((gpointer) src_folder == (gpointer) folder_store ||
                    TNY_IS_ACCOUNT (folder_store))
-                       sensitive = FALSE;
+                       ok_sensitive = FALSE;
                g_object_unref (src_folder);
        }
 
        /* Set sensitivity of the OK button */
-       gtk_widget_set_sensitive (ok_button, sensitive);
+       gtk_widget_set_sensitive (ok_button, ok_sensitive);
+       /* Set sensitivity of the NEW button */
+       gtk_widget_set_sensitive (new_button, new_sensitive);
 }
 
 static GtkWidget*
@@ -3609,8 +3634,9 @@ create_move_to_dialog (GtkWindow *win,
        /* Create folder view */
        *tree_view = modest_platform_create_folder_view (NULL);
 
-       /* Track changes in the selection to disable the OK button
-          whenever "Move to" is not possible */
+       /* Track changes in the selection to
+        * disable the OK button whenever "Move to" is not possible
+        * disbale NEW button whenever New is not possible */
        g_signal_connect (*tree_view,
                          "folder_selection_changed",
                          G_CALLBACK (on_move_to_dialog_folder_selection_changed),