* widgets/modest-window.c: Add a method to get action from its private
[modest] / src / maemo / modest-main-window.c
index f1e93f4..ef562e5 100644 (file)
@@ -31,6 +31,7 @@
 #include <gtk/gtktreeviewcolumn.h>
 #include <tny-account-store-view.h>
 #include <tny-simple-list.h>
+#include <tny-maemo-conic-device.h>
 #include "modest-hildon-includes.h"
 #include "modest-defs.h"
 #include <string.h>
@@ -44,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"
@@ -54,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
@@ -322,12 +325,14 @@ restore_settings (ModestMainWindow *self)
 
        conf = modest_runtime_get_conf ();
        
-       modest_widget_memory_restore (conf, G_OBJECT(self), 
+       modest_widget_memory_restore (conf, G_OBJECT(self),
                                      MODEST_CONF_MAIN_WINDOW_KEY);
-       modest_widget_memory_restore (conf, G_OBJECT(priv->main_paned),
-                                     MODEST_CONF_MAIN_PANED_KEY);
        modest_widget_memory_restore (conf, G_OBJECT(priv->header_view),
                                      MODEST_CONF_HEADER_VIEW_KEY);
+       modest_widget_memory_restore (conf, G_OBJECT(priv->main_paned),
+                                     MODEST_CONF_MAIN_PANED_KEY);
+       modest_widget_memory_restore (conf, G_OBJECT(priv->folder_view),
+                                     MODEST_CONF_FOLDER_VIEW_KEY);
 }
 
 
@@ -347,6 +352,8 @@ save_state (ModestWindow *window)
                                   MODEST_CONF_MAIN_PANED_KEY);
        modest_widget_memory_save (conf, G_OBJECT(priv->header_view), 
                                   MODEST_CONF_HEADER_VIEW_KEY);
+       modest_widget_memory_save (conf, G_OBJECT(priv->folder_view), 
+                                  MODEST_CONF_FOLDER_VIEW_KEY);
 }
 
 static void
@@ -375,6 +382,44 @@ on_account_store_connecting_finished (TnyAccountStore *store, ModestMainWindow *
        /* When going online, do the equivalent of pressing the send/receive button, 
         * as per the specification:
         * (without the check for >0 accounts, though that is not specified): */
+
+       TnyDevice *device = tny_account_store_get_device (store);
+       const gchar *iap_id = tny_maemo_conic_device_get_current_iap_id (TNY_MAEMO_CONIC_DEVICE (device));
+       printf ("DEBUG: %s: connection id=%s\n", __FUNCTION__, iap_id);
+       
+       /* Stop the existing send queues: */
+       modest_runtime_remove_all_send_queues ();
+       
+       /* Create the send queues again, using the appropriate transport accounts 
+        * for this new connection.
+        * This could be the first time that they are created if this is the first 
+        * connection. */
+       /* TODO: Does this really destroy the TnySendQueues and their threads
+        * We do not want 2 TnySendQueues to exist with the same underlying 
+        * outbox directory. */
+       GSList *account_names = modest_account_mgr_account_names (
+               modest_runtime_get_account_mgr(), 
+               TRUE /* enabled accounts only */);
+       GSList *iter = account_names;
+       while (iter) {
+               const gchar *account_name = (const gchar*)(iter->data);
+                       if (account_name) {
+                       TnyTransportAccount *account = TNY_TRANSPORT_ACCOUNT (
+                               modest_tny_account_store_get_transport_account_for_open_connection
+                                                (modest_runtime_get_account_store(), account_name));
+                       if (account) {
+                               printf ("debug: %s:\n  Transport account for %s: %s\n", __FUNCTION__, account_name, 
+                                       tny_account_get_id(TNY_ACCOUNT(account)));
+                               modest_runtime_get_send_queue (account);
+                       }
+               }
+               
+               iter = g_slist_next (iter);
+       }
+       
+       g_slist_free (account_names);
+       
+       
        modest_ui_actions_do_send_receive (NULL, MODEST_WINDOW (self));
 }
 
@@ -504,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;
@@ -516,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,
@@ -552,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));
@@ -704,7 +764,6 @@ modest_main_window_set_style (ModestMainWindow *self,
        action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ToolbarToggleView");
 
        priv->style = style;
-
        switch (style) {
        case MODEST_MAIN_WINDOW_STYLE_SIMPLE:
                /* Remove main paned */
@@ -1447,20 +1506,20 @@ on_queue_changed (ModestMailOperationQueue *queue,
                  ModestMainWindow *self)
 {
        ModestMainWindowPrivate *priv;
-       ModestMailOperationId op_id;
+       ModestMailOperationTypeOperation op_type;
        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);
               
        /* Get toolbar mode from operation id*/
-       op_id = modest_mail_operation_get_id (mail_op);
-       switch (op_id) {
-       case MODEST_MAIL_OPERATION_ID_SEND:
-       case MODEST_MAIL_OPERATION_ID_RECEIVE:
+       op_type = modest_mail_operation_get_type_operation (mail_op);
+       switch (op_type) {
+       case MODEST_MAIL_OPERATION_TYPE_SEND:
+       case MODEST_MAIL_OPERATION_TYPE_RECEIVE:
                mode = TOOLBAR_MODE_TRANSFER;
                if (priv->current_toolbar_mode == TOOLBAR_MODE_NORMAL)
                        mode_changed = TRUE;
@@ -1487,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) {