Work to complete implementation of purge attachments operation
[modest] / src / maemo / modest-main-window.c
index 8fd643c..a1f8f46 100644 (file)
 #include "modest-ui-dimming-manager.h"
 #include "maemo/modest-osso-state-saving.h"
 
-#ifdef MODEST_HILDON_VERSION_0
+#ifdef MODEST_HAVE_HILDON0_WIDGETS
 #include <hildon-widgets/hildon-program.h>
 #else
 #include <hildon/hildon-program.h>
-#endif /*MODEST_HILDON_VERSION_0*/
+#endif /*MODEST_HAVE_HILDON0_WIDGETS*/
 
 #define MODEST_MAIN_WINDOW_ACTION_GROUP_ADDITIONS "ModestMainWindowActionAdditions"
 
 #define XALIGN 0.5
-#define YALIGN 0.5
+#define YALIGN 0.0
 #define XSPACE 1
 #define YSPACE 0
 
@@ -96,6 +96,8 @@ static void         on_queue_changed                     (ModestMailOperationQue
                                                          ModestMailOperationQueueNotification type,
                                                          ModestMainWindow *self);
 
+static gboolean on_zoom_minus_plus_not_implemented (ModestWindow *window);
+
 static void on_account_update                 (TnyAccountStore *account_store, 
                                               const gchar *account_name,
                                               gpointer user_data);
@@ -277,6 +279,8 @@ modest_main_window_class_init (ModestMainWindowClass *klass)
        
        modest_window_class->show_toolbar_func = modest_main_window_show_toolbar;
        modest_window_class->save_state_func = save_state;
+       modest_window_class->zoom_minus_func = on_zoom_minus_plus_not_implemented;
+       modest_window_class->zoom_plus_func = on_zoom_minus_plus_not_implemented;
 }
 
 static void
@@ -510,7 +514,7 @@ on_account_store_connecting_finished (TnyAccountStore *store, ModestMainWindow *
 
        TnyDevice *device = tny_account_store_get_device (store);
 
-       modest_folder_view_update_model (MODEST_FOLDER_VIEW (priv->folder_view), store);
+       /* modest_folder_view_update_model (MODEST_FOLDER_VIEW (priv->folder_view), store); */
        
        /* Check that we are really online.
         * This signal should not be emitted when we are not connected, 
@@ -745,7 +749,18 @@ modest_main_window_on_show (GtkWidget *self, gpointer user_data)
                It's an ugly hack... jschmid */
                gtk_widget_show_all(GTK_WIDGET(self));
                modest_ui_actions_on_accounts (NULL, MODEST_WINDOW(self));
+       } else {
+               GSList *accounts;
+               GtkAction *send_receive_all;
+               ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (self);
+               accounts = modest_account_mgr_account_names (modest_runtime_get_account_mgr (), TRUE);
+               send_receive_all = gtk_ui_manager_get_action (parent_priv->ui_manager, 
+                                                             "/MenuBar/ToolsMenu/ToolsSendReceiveMainMenu/ToolsSendReceiveAllMenu");
+               gtk_action_set_visible (send_receive_all, g_slist_length (accounts));
+               modest_account_mgr_free_account_names (accounts);
        }
+
+
 }
 
 ModestWindow *
@@ -1137,6 +1152,7 @@ on_account_update (TnyAccountStore *account_store,
        GList *groups;
        gchar *default_account;
        GtkWidget *send_receive_button, *item;
+       GtkAction *send_receive_all = NULL;
                
        self = MODEST_MAIN_WINDOW (user_data);
        priv = MODEST_MAIN_WINDOW_GET_PRIVATE (self);
@@ -1162,6 +1178,10 @@ on_account_update (TnyAccountStore *account_store,
        accounts = g_slist_sort (accounts, (GCompareFunc) compare_display_names);
        num_accounts = g_slist_length (accounts);
 
+       send_receive_all = gtk_ui_manager_get_action (parent_priv->ui_manager, 
+                                                     "/MenuBar/ToolsMenu/ToolsSendReceiveMainMenu/ToolsSendReceiveAllMenu");
+       gtk_action_set_visible (send_receive_all, num_accounts > 1);
+
        /* Delete old send&receive popup items. We can not just do a
           menu_detach because it does not work well with
           tap_and_hold */
@@ -1208,7 +1228,7 @@ on_account_update (TnyAccountStore *account_store,
                                  G_CALLBACK (on_send_receive_csm_activated),
                                  NULL);
                item = gtk_separator_menu_item_new ();
-               gtk_menu_shell_append (GTK_MENU_SHELL (priv->accounts_popup), GTK_WIDGET (item));
+               gtk_menu_shell_prepend (GTK_MENU_SHELL (priv->accounts_popup), GTK_WIDGET (item));
        }
 
        /* Create a new action group */
@@ -1292,7 +1312,7 @@ on_account_update (TnyAccountStore *account_store,
                           it'll be no menu */
                        if (priv->accounts_popup) {
                                item = gtk_menu_item_new_with_label (display_name);
-                               gtk_menu_shell_append (GTK_MENU_SHELL (priv->accounts_popup), GTK_WIDGET (item));
+                               gtk_menu_shell_prepend (GTK_MENU_SHELL (priv->accounts_popup), GTK_WIDGET (item));
                                g_signal_connect_data (G_OBJECT (item), 
                                                       "activate", 
                                                       G_CALLBACK (on_send_receive_csm_activated),
@@ -1379,25 +1399,49 @@ create_empty_view (void)
 }
 
 static GtkWidget *
-create_details_widget (TnyAccount *account)
+create_details_widget (GtkWidget *styled_widget, TnyAccount *account)
 {
+       /* TODO: Clean up this function. It's a mess, with lots of copy/paste. murrayc. */
+       
        GtkWidget *vbox;
+       GtkWidget *label_w;
        gchar *label;
+       gchar *gray_color_markup;
 
        vbox = gtk_vbox_new (FALSE, 0);
 
+       /* Obtain the secondary text color. We need a realized widget, that's why 
+          we get styled_widget from outside */
+#ifndef MODEST_HAVE_HILDON0_WIDGETS
+       GdkColor color;
+       gtk_style_lookup_color (styled_widget->style, "SecondaryTextColor", &color);
+       gray_color_markup = modest_text_utils_get_color_string (&color);
+#else
+       // gray_color_markup is freed below
+       gray_color_markup = g_strdup ("#BBBBBB");
+#endif 
        /* Account description: */
        
-       if (modest_tny_account_is_virtual_local_folders (account)) {
+       if (modest_tny_account_is_virtual_local_folders (account)
+               || (modest_tny_account_is_memory_card_account (account))) {
+               gchar *tmp;
                /* Local folders: */
        
                /* Get device name */
-               gchar *device_name = modest_conf_get_string (modest_runtime_get_conf(),
+               gchar *device_name = NULL;
+               if (modest_tny_account_is_virtual_local_folders (account))
+                       device_name = modest_conf_get_string (modest_runtime_get_conf(),
                                                      MODEST_CONF_DEVICE_NAME, NULL);
-   
-               label = g_strdup_printf (_("mcen_fi_localroot_description"),
-                                        device_name);
-               gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (label), FALSE, FALSE, 0);
+               else
+                       device_name = g_strdup (tny_account_get_name (account));
+                                                     
+               tmp = g_strdup_printf (_("mcen_fi_localroot_description"), ""); //TODO: Why the ""?
+               label = g_markup_printf_escaped ("<span color='%s'>%s</span>%s",
+                                                gray_color_markup, tmp, device_name);
+               g_free (tmp);
+               label_w = gtk_label_new (NULL);
+               gtk_label_set_markup (GTK_LABEL (label_w), label);
+               gtk_box_pack_start (GTK_BOX (vbox), label_w, FALSE, FALSE, 0);
                g_free (device_name);
                g_free (label);
        } else {
@@ -1418,10 +1462,13 @@ create_details_widget (TnyAccount *account)
                        /* note: mcen_fi_localroot_description is something like "%s account"
                         * however, we should display "%s account: %s"... therefore, ugly tmp */
                        tmp   = g_strdup_printf (_("mcen_fi_remoteroot_account"),proto->str);
-                       label = g_strdup_printf ("%s: %s", tmp,tny_account_get_name (account));
+                       label = g_markup_printf_escaped ("<span color='%s'>%s:</span> %s", 
+                                                        gray_color_markup, tmp, tny_account_get_name (account));
                        g_free (tmp);
 
-                       gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (label), FALSE, FALSE, 0);
+                       label_w = gtk_label_new (NULL);
+                       gtk_label_set_markup (GTK_LABEL (label_w), label);
+                       gtk_box_pack_start (GTK_BOX (vbox), label_w, FALSE, FALSE, 0);
                        g_string_free (proto, TRUE);
                        g_free (label);
                }
@@ -1429,23 +1476,34 @@ create_details_widget (TnyAccount *account)
 
        /* Message count */
        TnyFolderStore *folder_store = TNY_FOLDER_STORE (account);
-       label = g_strdup_printf ("%s: %d", _("mcen_fi_rootfolder_messages"), 
-                                modest_tny_folder_store_get_message_count (folder_store));
-       gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (label), FALSE, FALSE, 0);
+       label = g_markup_printf_escaped ("<span color='%s'>%s:</span> %d", 
+                                        gray_color_markup, _("mcen_fi_rootfolder_messages"), 
+                                        modest_tny_folder_store_get_message_count (folder_store));
+       label_w = gtk_label_new (NULL);
+       gtk_label_set_markup (GTK_LABEL (label_w), label);
+       gtk_box_pack_start (GTK_BOX (vbox), label_w, FALSE, FALSE, 0);
        g_free (label);
 
        /* Folder count */
-       label = g_strdup_printf ("%s: %d", _("mcen_fi_rootfolder_folders"), 
-                                modest_tny_folder_store_get_folder_count (folder_store));
-       gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (label), FALSE, FALSE, 0);
+       label = g_markup_printf_escaped ("<span color='%s'>%s</span>: %d", 
+                                        gray_color_markup, 
+                                        _("mcen_fi_rootfolder_folders"), 
+                                        modest_tny_folder_store_get_folder_count (folder_store));
+       label_w = gtk_label_new (NULL);
+       gtk_label_set_markup (GTK_LABEL (label_w), label);
+       gtk_box_pack_start (GTK_BOX (vbox), label_w, FALSE, FALSE, 0);
        g_free (label);
 
        /* Size / Date */
-       if (modest_tny_account_is_virtual_local_folders (account)) {
+       if (modest_tny_account_is_virtual_local_folders (account)
+               || modest_tny_account_is_memory_card_account (account)) {
                /* FIXME: format size */
-               label = g_strdup_printf ("%s: %d", _("mcen_fi_rootfolder_size"), 
-                                        modest_tny_folder_store_get_local_size (folder_store));
-               gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (label), FALSE, FALSE, 0);
+               label = g_markup_printf_escaped ("<span color='%s'>%s:</span> %d", 
+                                                gray_color_markup, _("mcen_fi_rootfolder_size"), 
+                                                modest_tny_folder_store_get_local_size (folder_store));
+               label_w = gtk_label_new (NULL);
+               gtk_label_set_markup (GTK_LABEL (label_w), label);
+               gtk_box_pack_start (GTK_BOX (vbox), label_w, FALSE, FALSE, 0);
                g_free (label);
        } else if (TNY_IS_ACCOUNT(folder_store)) {
                TnyAccount *account = TNY_ACCOUNT(folder_store);
@@ -1462,12 +1520,17 @@ create_details_widget (TnyAccount *account)
                else
                        last_updated_string = g_strdup (_("mcen_va_never"));
 
-               label = g_strdup_printf ("%s: %s", _("mcen_ti_lastupdated"), last_updated_string);
-               gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (label), FALSE, FALSE, 0);
+               label = g_markup_printf_escaped ("<span color='%s'>%s:</span> %s", 
+                                                gray_color_markup, _("mcen_ti_lastupdated"), last_updated_string);
+               label_w = gtk_label_new (NULL);
+               gtk_label_set_markup (GTK_LABEL (label_w), label);
+               gtk_box_pack_start (GTK_BOX (vbox), label_w, FALSE, FALSE, 0);
                g_free (last_updated_string);
                g_free (label);
        }
 
+       g_free (gray_color_markup);
+
        /* Set alignment */
        gtk_container_foreach (GTK_CONTAINER (vbox), (GtkCallback) set_alignment, NULL);
 
@@ -1539,8 +1602,7 @@ _on_msg_count_changed (ModestHeaderView *header_view,
        else {
                modest_main_window_set_contents_style (main_window,
                                                       MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
-       }
-       
+       }       
 }
 
 void 
@@ -1585,8 +1647,8 @@ modest_main_window_set_contents_style (ModestMainWindow *self,
                TnyFolderStore *selected_folderstore = 
                        modest_folder_view_get_selected (priv->folder_view);
                if (TNY_IS_ACCOUNT (selected_folderstore)) {    
-                       priv->details_widget = create_details_widget (
-                               TNY_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);
@@ -1710,37 +1772,64 @@ set_toolbar_mode (ModestMainWindow *self,
        /* Show and hide toolbar items */
        switch (mode) {
        case TOOLBAR_MODE_NORMAL:
-               if (sort_action) 
-                       gtk_action_set_visible (sort_action, TRUE);
-               if (refresh_action) 
-                       gtk_action_set_visible (refresh_action, TRUE);
-               if (priv->progress_toolitem) {
+/*             if (sort_action)  */
+/*                     gtk_action_set_visible (sort_action, TRUE); */
+/*             if (refresh_action)  */
+/*                     gtk_action_set_visible (refresh_action, TRUE); */
+/*             if (priv->progress_toolitem) { */
+/*                     gtk_tool_item_set_expand (GTK_TOOL_ITEM (priv->progress_toolitem), FALSE); */
+/*                     gtk_widget_hide (priv->progress_toolitem); */
+/*             } */
+/*             if (priv->progress_bar) */
+/*                     gtk_widget_hide (priv->progress_bar); */
+               
+/*             if (cancel_action) */
+/*                     gtk_action_set_visible (cancel_action, FALSE); */
+               if (priv->sort_toolitem)
+                       gtk_widget_show (priv->sort_toolitem);
+               
+               if (priv->refresh_toolitem)
+                       gtk_widget_show (priv->refresh_toolitem);
+                       
+               if (priv->progress_toolitem)
                        gtk_tool_item_set_expand (GTK_TOOL_ITEM (priv->progress_toolitem), FALSE);
-                       gtk_widget_hide (priv->progress_toolitem);
-               }
                if (priv->progress_bar)
-                       gtk_widget_hide (priv->progress_bar);                   
-               
-               if (cancel_action)
-                       gtk_action_set_visible (cancel_action, FALSE);
+                       gtk_widget_hide (priv->progress_bar);
+                       
+               if (priv->cancel_toolitem)
+                       gtk_widget_hide (priv->cancel_toolitem);
 
                /* Hide toolbar if optimized view is enabled */
                if (priv->optimized_view)
                        gtk_widget_hide (GTK_WIDGET(parent_priv->toolbar));
                break;
        case TOOLBAR_MODE_TRANSFER:
-               if (sort_action)
-                       gtk_action_set_visible (sort_action, FALSE);
-               if (refresh_action)
-                       gtk_action_set_visible (refresh_action, FALSE);
-               if (cancel_action)
-                       gtk_action_set_visible (cancel_action, TRUE);
-               if (priv->progress_toolitem) {
+/*             if (sort_action) */
+/*                     gtk_action_set_visible (sort_action, FALSE); */
+/*             if (refresh_action) */
+/*                     gtk_action_set_visible (refresh_action, FALSE); */
+/*             if (cancel_action) */
+/*                     gtk_action_set_visible (cancel_action, TRUE); */
+/*             if (priv->progress_toolitem) { */
+/*                     gtk_tool_item_set_expand (GTK_TOOL_ITEM (priv->progress_toolitem), TRUE); */
+/*                     gtk_widget_show (priv->progress_toolitem); */
+/*             } */
+/*             if (priv->progress_bar) */
+/*                     gtk_widget_show (priv->progress_bar); */
+
+               if (priv->sort_toolitem)
+                       gtk_widget_hide (priv->sort_toolitem);
+               
+               if (priv->refresh_toolitem)
+                       gtk_widget_hide (priv->refresh_toolitem);
+               
+               if (priv->progress_toolitem)
                        gtk_tool_item_set_expand (GTK_TOOL_ITEM (priv->progress_toolitem), TRUE);
-                       gtk_widget_show (priv->progress_toolitem);
-               }
                if (priv->progress_bar)
-                       gtk_widget_show (priv->progress_bar);                   
+                       gtk_widget_show (priv->progress_bar);
+                       
+               if (priv->cancel_toolitem)
+                       gtk_widget_show (priv->cancel_toolitem);
 
                /* Show toolbar if it's hiden (optimized view ) */
                if (priv->optimized_view)
@@ -1811,6 +1900,7 @@ on_queue_changed (ModestMailOperationQueue *queue,
        switch (op_type) {
        case MODEST_MAIL_OPERATION_TYPE_SEND:
        case MODEST_MAIL_OPERATION_TYPE_RECEIVE:
+       case MODEST_MAIL_OPERATION_TYPE_OPEN:
                mode = TOOLBAR_MODE_TRANSFER;
                if (priv->current_toolbar_mode == TOOLBAR_MODE_NORMAL)
                        mode_changed = TRUE;
@@ -1914,3 +2004,12 @@ on_send_receive_csm_activated (GtkMenuItem *item,
        refresh_account ((const gchar*) user_data);
 }
 
+static gboolean
+on_zoom_minus_plus_not_implemented (ModestWindow *window)
+{
+       g_return_val_if_fail (MODEST_IS_MAIN_WINDOW (window), FALSE);
+
+       hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_cannot_zoom_here"));
+       return FALSE;
+
+}