* Fixed some strange behaviour on send-queues and
[modest] / src / maemo / modest-main-window.c
index 285a937..5b2fa18 100644 (file)
@@ -180,6 +180,11 @@ modest_main_window_on_folder_selection_changed (ModestFolderView *folder_view,
 static void
 set_at_least_one_account_visible(ModestMainWindow *self);
 
+static void
+modest_main_window_on_send_queue_status_canged (ModestTnySendQueue *send_queue,
+                                               gchar *msg_id, 
+                                               guint status,
+                                               gpointer user_data);
 
 /* list my signals */
 enum {
@@ -1221,11 +1226,11 @@ modest_main_window_new (void)
        action = gtk_ui_manager_get_action (parent_priv->ui_manager, 
                                            "/MenuBar/ViewMenu/ViewShowToolbarMainMenu/ViewShowToolbarNormalScreenMenu");
        gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
-                                     modest_conf_get_bool (conf, MODEST_CONF_SHOW_TOOLBAR, NULL));
+                                     modest_conf_get_bool (conf, MODEST_CONF_MAIN_WINDOW_SHOW_TOOLBAR, NULL));
        action = gtk_ui_manager_get_action (parent_priv->ui_manager, 
                                            "/MenuBar/ViewMenu/ViewShowToolbarMainMenu/ViewShowToolbarFullScreenMenu");
        gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
-                                     modest_conf_get_bool (conf, MODEST_CONF_SHOW_TOOLBAR_FULLSCREEN, NULL));
+                                     modest_conf_get_bool (conf, MODEST_CONF_MAIN_WINDOW_SHOW_TOOLBAR_FULLSCREEN, NULL));
        hildon_window_set_menu (HILDON_WINDOW (self), GTK_MENU (parent_priv->menubar));
        gtk_widget_show (parent_priv->menubar);
 
@@ -1445,7 +1450,14 @@ modest_main_window_show_toolbar (ModestWindow *self,
        ModestWindowPrivate *parent_priv = NULL;        
        GtkWidget *reply_button = NULL, *menu = NULL;
        GtkWidget *placeholder = NULL;
+       ModestAccountMgr *mgr = NULL;
+       TnyTransportAccount *transport_account = NULL;
+       ModestTnySendQueue *send_queue = NULL;
        gint insert_index;
+       GSList *iter = NULL;
+       GSList *account_names = NULL;
+       const gchar *action_name;
+       GtkAction *action;
 
        g_return_if_fail (MODEST_IS_MAIN_WINDOW (self));
        priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
@@ -1457,6 +1469,7 @@ modest_main_window_show_toolbar (ModestWindow *self,
        if (!parent_priv->toolbar) {
                parent_priv->toolbar = gtk_ui_manager_get_widget (parent_priv->ui_manager, 
                                                                  "/ToolBar");
+               gtk_widget_set_no_show_all (parent_priv->toolbar, TRUE);
 
                /* Set homogeneous toolbar */
                gtk_container_foreach (GTK_CONTAINER (parent_priv->toolbar), 
@@ -1500,8 +1513,40 @@ modest_main_window_show_toolbar (ModestWindow *self,
 
                /* Set send & receive button tap and hold menu */
                update_menus (MODEST_MAIN_WINDOW (self));
-       }
 
+               /* Create send queue for all defined accounts  */
+               mgr = modest_runtime_get_account_mgr ();
+               account_names = modest_account_mgr_account_names (mgr, TRUE);
+               iter = account_names;
+               while (iter) {
+                       transport_account =
+                               TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
+                                                     (modest_runtime_get_account_store(),
+                                                      iter->data,
+                                                      TNY_ACCOUNT_TYPE_TRANSPORT));
+                       
+                       /* Create new send queue for this new account */
+                       send_queue =  modest_runtime_get_send_queue (transport_account);
+                       if (MODEST_IS_TNY_SEND_QUEUE(send_queue)) {
+                               
+                               /* Connect 'status_changed' signal of this new send-queue */
+                               priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers, G_OBJECT (send_queue), "status_changed", 
+                                                                              G_CALLBACK (modest_main_window_on_send_queue_status_canged), 
+                                                                              self);
+                       }
+                       
+                       iter = iter->next;
+
+                       /* free */
+                       if (send_queue != NULL)
+                               g_object_unref (send_queue);
+                       if (transport_account != NULL)
+                               g_object_unref (transport_account);
+                       
+               }
+               modest_account_mgr_free_account_names (account_names);
+       }
+       
        if (show_toolbar) {
                /* Quick hack: this prevents toolbar icons "dance" when progress bar show status is changed */ 
                /* TODO: resize mode migth be GTK_RESIZE_QUEUE, in order to avoid unneccesary shows */
@@ -1509,9 +1554,56 @@ modest_main_window_show_toolbar (ModestWindow *self,
 
                gtk_widget_show (GTK_WIDGET (parent_priv->toolbar));
                set_toolbar_mode (MODEST_MAIN_WINDOW(self), TOOLBAR_MODE_NORMAL);
-       } else
+       } else {
                gtk_widget_hide (GTK_WIDGET (parent_priv->toolbar));
 
+       }
+
+       /* Update also the actions (to update the toggles in the
+          menus), we have to do it manually because some other window
+          of the same time could have changed it (remember that the
+          toolbar fullscreen mode is shared by all the windows of the
+          same type */
+       if (modest_window_mgr_get_fullscreen_mode (modest_runtime_get_window_mgr ()))
+               action_name = "/MenuBar/ViewMenu/ViewShowToolbarMenu/ViewShowToolbarFullScreenMenu";
+       else
+               action_name = "/MenuBar/ViewMenu/ViewShowToolbarMenu/ViewShowToolbarNormalScreenMenu";
+
+       action = gtk_ui_manager_get_action (parent_priv->ui_manager, action_name);
+       modest_maemo_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action),
+                                                           show_toolbar);
+}
+
+static void
+modest_main_window_on_send_queue_status_canged (ModestTnySendQueue *send_queue,
+                                               gchar *msg_id, 
+                                               guint status,
+                                               gpointer user_data)
+{
+       ModestMainWindowPrivate *priv = NULL;
+       TnyFolderStore *selected_folder = NULL;
+       TnyFolderType folder_type;
+
+       g_return_if_fail (MODEST_IS_TNY_SEND_QUEUE (send_queue));
+       g_return_if_fail (MODEST_IS_MAIN_WINDOW (user_data));
+       priv = MODEST_MAIN_WINDOW_GET_PRIVATE(user_data);
+
+       /* Check if selected folder is OUTBOX */
+       selected_folder = modest_folder_view_get_selected (priv->folder_view);
+       if (!TNY_IS_FOLDER (selected_folder)) goto frees;
+       folder_type = modest_tny_folder_guess_folder_type (TNY_FOLDER (selected_folder)); 
+#if GTK_CHECK_VERSION(2, 8, 0) /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */
+       if (folder_type ==  TNY_FOLDER_TYPE_OUTBOX) {           
+               GtkTreeViewColumn * tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (priv->header_view), 
+                                                                           TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN);
+               gtk_tree_view_column_queue_resize (tree_column);
+#endif         
+       }
+       
+       /* Free */
+ frees:
+       if (selected_folder != NULL)
+               g_object_unref (selected_folder);
 }
 
 static void
@@ -1519,7 +1611,39 @@ on_account_inserted (TnyAccountStore *accoust_store,
                      TnyAccount *account,
                      gpointer user_data)
 {
+       TnyTransportAccount *transport_account = NULL;
+       ModestTnySendQueue *send_queue = NULL;
+       ModestMainWindowPrivate *priv;
+       const gchar *account_name = NULL;
+
+       g_return_if_fail (MODEST_IS_MAIN_WINDOW (user_data));
+       priv = MODEST_MAIN_WINDOW_GET_PRIVATE (user_data);
+
        update_menus (MODEST_MAIN_WINDOW (user_data));
+
+       /* Get transport account */
+       account_name = tny_account_get_name (TNY_ACCOUNT (account));
+       transport_account =
+               TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
+                                     (modest_runtime_get_account_store(),
+                                      account_name,
+                                      TNY_ACCOUNT_TYPE_TRANSPORT));
+
+       /* Create new send queue for this new account */
+       send_queue =  modest_runtime_get_send_queue (transport_account);
+       if (!MODEST_IS_TNY_SEND_QUEUE(send_queue)) goto frees;
+       /* Connect 'status_changed' signal of this new send-queue */
+       priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,G_OBJECT (send_queue), "status_changed", 
+                                                      G_CALLBACK (modest_main_window_on_send_queue_status_canged), 
+                                                      user_data);
+       
+       /* Free */
+ frees:
+       if (transport_account != NULL) 
+               g_object_unref (G_OBJECT (transport_account));
+       if (send_queue != NULL)
+               g_object_unref (send_queue);
 }
 
 static void
@@ -1888,20 +2012,22 @@ modest_main_window_set_contents_style (ModestMainWindow *self,
                break;
        case MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS:
        {
-               TnyFolderStore *selected_folderstore = 
-                       modest_folder_view_get_selected (priv->folder_view);
-               if (TNY_IS_ACCOUNT (selected_folderstore)) {    
-                 priv->details_widget = create_details_widget (GTK_WIDGET (self),
+               /* if we're started without main win, there may not be a folder
+                * view. this fixes a GLib-Critical */
+               if (priv->folder_view) {
+                       TnyFolderStore *selected_folderstore = 
+                               modest_folder_view_get_selected (priv->folder_view);
+                       if (TNY_IS_ACCOUNT (selected_folderstore)) {    
+                               priv->details_widget = create_details_widget (GTK_WIDGET (self),
                                                                TNY_ACCOUNT (selected_folderstore));
-
-                       wrap_in_scrolled_window (priv->contents_widget, 
-                                        priv->details_widget);
+                               
+                               wrap_in_scrolled_window (priv->contents_widget, 
+                                                        priv->details_widget);
+                       }
+                       g_object_unref (selected_folderstore);
+                       modest_maemo_set_thumbable_scrollbar (GTK_SCROLLED_WINDOW(priv->contents_widget),
+                                                             FALSE);
                }
-               g_object_unref (selected_folderstore);
-               modest_maemo_set_thumbable_scrollbar (GTK_SCROLLED_WINDOW(priv->contents_widget),
-                                                     FALSE);
-
-               
                break;
        }
        case MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY:
@@ -1937,7 +2063,7 @@ on_configuration_key_changed (ModestConf* conf,
                              ModestMainWindow *self)
 {
        ModestMainWindowPrivate *priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
-       TnyAccount *account;
+       TnyAccount *account = NULL;
 
        if (!key || 
            priv->notification_id != id ||
@@ -1946,10 +2072,10 @@ on_configuration_key_changed (ModestConf* conf,
 
        if (priv->contents_style != MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS)
                return;
-
-       account = (TnyAccount *) modest_folder_view_get_selected (priv->folder_view);
-       if (TNY_IS_ACCOUNT (account) &&
-           !strcmp (tny_account_get_id (account), MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
+       if (priv->folder_view) 
+               account = (TnyAccount *) modest_folder_view_get_selected (priv->folder_view);
+       if (account && TNY_IS_ACCOUNT (account) &&
+           strcmp (tny_account_get_id (account), MODEST_LOCAL_FOLDERS_ACCOUNT_ID) == 0) {
                GList *children;
                GtkLabel *label;
                const gchar *device_name;
@@ -2020,6 +2146,9 @@ set_toolbar_mode (ModestMainWindow *self,
        /* Sets current toolbar mode */
        priv->current_toolbar_mode = mode;
 
+        /* Checks the dimming rules */
+        modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (self));
+
        /* Show and hide toolbar items */
        switch (mode) {
        case TOOLBAR_MODE_NORMAL:
@@ -2064,6 +2193,17 @@ set_toolbar_mode (ModestMainWindow *self,
        }
 }
 
+gboolean
+modest_main_window_transfer_mode_enabled (ModestMainWindow *self)
+{
+       ModestMainWindowPrivate *priv;
+
+       g_return_val_if_fail (MODEST_IS_MAIN_WINDOW (self), FALSE);
+       priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
+
+       return priv->current_toolbar_mode == TOOLBAR_MODE_TRANSFER;
+}
+
 static void
 cancel_progressbar (GtkToolButton *toolbutton,
                    ModestMainWindow *self)