* src/modest-tny-account.[ch]:
[modest] / src / maemo / modest-main-window.c
index c600a9c..1fa7410 100644 (file)
@@ -178,6 +178,9 @@ static gboolean restore_paned_timeout_handler (gpointer *data);
 
 static gboolean show_retrieving_banner (gpointer user_data);
 
+static void on_window_destroy (GtkObject *widget,
+                              gpointer userdata);
+
 typedef struct _ModestMainWindowPrivate ModestMainWindowPrivate;
 struct _ModestMainWindowPrivate {
        GtkWidget *msg_paned;
@@ -651,6 +654,8 @@ update_menus (ModestMainWindow* self)
                        display_name = g_strdup_printf (_("mcen_me_toolbar_sendreceive_mailbox_n"), 
                                                        modest_account_settings_get_display_name (settings));
                }
+
+               
                
                /* Create action and add it to the action group. The
                   action name must be the account name, this way we
@@ -659,9 +664,13 @@ update_menus (ModestMainWindow* self)
                        gchar* item_name, *refresh_action_name;
                        guint8 merge_id = 0;
                        GtkAction *view_account_action, *refresh_account_action;
+                       gchar *escaped_display_name;
+
+                       escaped_display_name = modest_text_utils_escape_mnemonics (display_name);
 
                        view_account_action = GTK_ACTION (gtk_radio_action_new (account_name,
-                                                                               display_name, NULL, NULL, 0));
+                                                                               escaped_display_name, NULL, NULL, 0));
+                       g_free (escaped_display_name);
                        gtk_action_group_add_action (priv->view_additions_group, view_account_action);
                        gtk_radio_action_set_group (GTK_RADIO_ACTION (view_account_action), radio_group);
                        radio_group = gtk_radio_action_get_group (GTK_RADIO_ACTION (view_account_action));
@@ -985,6 +994,9 @@ connect_signals (ModestMainWindow *self)
                modest_signal_mgr_connect (priv->sighandlers,G_OBJECT (self), "window-state-event",
                                           G_CALLBACK (modest_main_window_window_state_event),
                                           NULL);
+       /* we don't register this in sighandlers, as it should be run after disconnecting all signals,
+        * in destroy stage */
+       g_signal_connect (G_OBJECT (self), "destroy", G_CALLBACK (on_window_destroy), NULL);
 
        /* Mail Operation Queue */
        priv->sighandlers = 
@@ -1569,6 +1581,27 @@ modest_main_window_show_toolbar (ModestWindow *self,
                                                            show_toolbar);
 }
 
+/* 
+ * Counts the number of remote accounts in a list
+ */
+static guint
+num_remote_accounts (TnyList *accounts)
+{
+       TnyIterator *iter;
+       guint num = 0;
+
+       iter = tny_list_create_iterator (accounts);
+       while (!tny_iterator_is_done (iter)) {
+               TnyAccount *account = (TnyAccount *) tny_iterator_get_current (iter);
+               if (modest_tny_folder_store_is_remote (TNY_FOLDER_STORE (account)))
+                       num++;
+               tny_iterator_next (iter);
+       }
+       g_object_unref (iter);
+       return num;
+}
+
+
 static void
 on_account_inserted (TnyAccountStore *accoust_store,
                      TnyAccount *account,
@@ -1577,8 +1610,26 @@ on_account_inserted (TnyAccountStore *accoust_store,
        /* Transport accounts and local ones (MMC and the Local
           folders account do now cause menu changes */
        if (TNY_IS_STORE_ACCOUNT (account) && 
-           modest_tny_folder_store_is_remote (TNY_FOLDER_STORE (account)))
+           modest_tny_folder_store_is_remote (TNY_FOLDER_STORE (account))) {
+               TnyList *list = tny_simple_list_new ();
+
+               /* Update menus */
                update_menus (MODEST_MAIN_WINDOW (user_data));
+
+               /* Perform a send&receive if there are more than 1
+                  remote account , if this is the first remote
+                  account the folder view will automatically select
+                  and update it */
+               tny_account_store_get_accounts (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()), 
+                                               list, TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
+               if (num_remote_accounts (list) > 1) {
+                       const gchar *account_name = 
+                               modest_tny_account_get_parent_modest_account_name_for_server_account (account);
+                       modest_ui_actions_do_send_receive (account_name, FALSE, MODEST_WINDOW (user_data));
+               }
+
+               g_object_unref (list);
+       }
 }
 
 static void
@@ -2297,9 +2348,10 @@ on_mail_operation_started (ModestMailOperation *mail_op,
 
                is_remote = !(modest_tny_account_is_virtual_local_folders (account) ||
                              modest_tny_account_is_memory_card_account (account));
-               g_object_unref (account);
-               if (!is_remote)
+               if (!is_remote) {
+                       g_object_unref (account);
                        return;
+               }
 
                /* Show information banner. Remove old timeout */
                if (priv->retrieving_banner_timeout > 0) {
@@ -2310,6 +2362,7 @@ on_mail_operation_started (ModestMailOperation *mail_op,
                priv->retrieving_banner_timeout = 
                        g_timeout_add (2000, show_retrieving_banner, self);
        }
+       g_object_unref (account);
               
        /* Get toolbar mode from operation id*/
        mode = get_toolbar_mode_from_mail_operation (self, mail_op, &mode_changed);
@@ -2361,9 +2414,10 @@ on_mail_operation_finished (ModestMailOperation *mail_op,
 
                is_remote = !(modest_tny_account_is_virtual_local_folders (account) ||
                              modest_tny_account_is_memory_card_account (account));
-               g_object_unref (account);
-               if (!is_remote)
+               if (!is_remote) {
+                       g_object_unref (account);
                        return;
+               }
 
                /* Remove old timeout */
                if (priv->retrieving_banner_timeout > 0) {
@@ -2377,6 +2431,7 @@ on_mail_operation_finished (ModestMailOperation *mail_op,
                        priv->retrieving_banner = NULL;
                }
        }
+       g_object_unref (account);
 
        /* Get toolbar mode from operation id*/
        mode = get_toolbar_mode_from_mail_operation (self, mail_op, &mode_changed);
@@ -2754,6 +2809,35 @@ modest_main_window_screen_is_on (ModestMainWindow *self)
        return (priv->display_state == OSSO_DISPLAY_ON) ? TRUE : FALSE;
 }
 
+static void
+on_window_destroy (GtkObject *widget, gpointer userdata)
+{
+       ModestMainWindowPrivate *priv;
+
+       priv = MODEST_MAIN_WINDOW_GET_PRIVATE (widget);
+
+       if (priv->retrieving_banner_timeout > 0) {
+               g_source_remove (priv->retrieving_banner_timeout);
+               priv->retrieving_banner_timeout = 0;
+       }
+
+       if (priv->retrieving_banner != NULL) {
+               gtk_widget_destroy (priv->retrieving_banner);
+               priv->retrieving_banner = NULL;
+       }
+       
+       if (priv->updating_banner_timeout > 0) {
+               g_source_remove (priv->updating_banner_timeout);
+               priv->updating_banner_timeout = 0;
+       }
+
+       if (priv->updating_banner != NULL) {
+               gtk_widget_destroy (priv->updating_banner);
+               priv->updating_banner = NULL;
+       }
+       
+}
+
 static gboolean
 show_retrieving_banner (gpointer user_data)
 {