X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmaemo%2Fmodest-main-window.c;h=a7178653ff8e290b8890ecb6705df8ccc0834e63;hp=6a91ba579847d990985ee1ddeb0f79a82064e248;hb=40e92875620a12ce1d34126c9a9c6bce97b21e6c;hpb=fd958e8a96328612ae617b3f04627781d6dc7b1f diff --git a/src/maemo/modest-main-window.c b/src/maemo/modest-main-window.c index 6a91ba5..a717865 100644 --- a/src/maemo/modest-main-window.c +++ b/src/maemo/modest-main-window.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "modest-hildon-includes.h" #include "modest-defs.h" #include @@ -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 @@ -187,9 +190,23 @@ static const GtkActionEntry modest_folder_view_action_entries [] = { { "FolderViewCSMPasteMsgs", NULL, N_("mcen_me_inbox_paste"), NULL, NULL, NULL }, { "FolderViewCSMDeleteFolder", NULL, N_("mcen_me_inbox_delete"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_delete_folder) }, { "FolderViewCSMSearchMessages", NULL, N_("mcen_me_inbox_search"), NULL, NULL, NULL }, - { "FolderViewCSMHelp", NULL, N_("mcen_me_inbox_help"), NULL, NULL, NULL }, + { "FolderViewCSMHelp", NULL, N_("mcen_me_inbox_help"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_help) }, }; +static const GtkActionEntry modest_header_view_action_entries [] = { + + /* Header View CSM actions */ + { "HeaderViewCSMOpen", NULL, N_("mcen_me_inbox_open"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_new_folder) }, + { "HeaderViewCSMReply", NULL, N_("mcen_me_inbox_reply"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_reply) }, + { "HeaderViewCSMReplyAll", NULL, N_("mcen_me_inbox_replytoall"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_reply_all) }, + { "HeaderViewCSMForward", NULL, N_("mcen_me_inbox_forward"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_forward) }, + { "HeaderViewCSMCut", NULL, N_("mcen_me_inbox_cut"), "X", NULL, G_CALLBACK (modest_ui_actions_on_cut) }, + { "HeaderViewCSMCopy", NULL, N_("mcen_me_inbox_copy"), "C", NULL, G_CALLBACK (modest_ui_actions_on_copy) }, + { "HeaderViewCSMPaste", NULL, N_("mcen_me_inbox_paste"), "V", NULL, G_CALLBACK (modest_ui_actions_on_paste) }, + { "HeaderViewCSMDelete", NULL, N_("mcen_me_inbox_delete"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_delete) }, + { "HeaderViewCSMCancelSending", NULL, N_("mcen_me_outbox_cancelsend"), NULL, NULL, NULL }, + { "HeaderViewCSMHelp", NULL, N_("mcen_me_inbox_help"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_help) }, +}; static const GtkToggleActionEntry modest_main_window_toggle_action_entries [] = { { "ToolbarToggleView", MODEST_STOCK_SPLIT_VIEW, N_("gqn_toolb_rss_fldonoff"), "t", NULL, G_CALLBACK (modest_ui_actions_toggle_folders_view), FALSE }, @@ -321,13 +338,19 @@ restore_settings (ModestMainWindow *self) priv = MODEST_MAIN_WINDOW_GET_PRIVATE(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->folder_view), + MODEST_CONF_FOLDER_VIEW_KEY); + modest_widget_memory_restore (conf, G_OBJECT(priv->main_paned), + MODEST_CONF_MAIN_PANED_KEY); + + /* We need to force a redraw here in order to get the right + position of the horizontal paned separator */ + gtk_widget_show (GTK_WIDGET (self)); } @@ -347,6 +370,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,10 +400,73 @@ 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); + + /* Check that we are really online. + * This signal should not be emitted when we are not connected, + * but it seems to happen sometimes: */ + if (!tny_device_is_online (device)) + return; + + 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)); } +static void +_folder_view_csm_menu_activated (GtkWidget *widget, gpointer user_data) +{ + g_return_if_fail (MODEST_IS_MAIN_WINDOW (user_data)); + + /* Update dimmed */ + modest_window_check_dimming_rules_group (MODEST_WINDOW (user_data), "ModestMenuDimmingRules"); +} + +static void +_header_view_csm_menu_activated (GtkWidget *widget, gpointer user_data) +{ + g_return_if_fail (MODEST_IS_MAIN_WINDOW (user_data)); + + /* Update visibility */ + /* Update dimmed */ + modest_window_check_dimming_rules_group (MODEST_WINDOW (user_data), "ModestMenuDimmingRules"); +} static void connect_signals (ModestMainWindow *self) @@ -398,9 +486,12 @@ connect_signals (ModestMainWindow *self) g_signal_connect (G_OBJECT(priv->folder_view), "folder-display-name-changed", G_CALLBACK(modest_ui_actions_on_folder_display_name_changed), self); + /* Folder view CSM */ menu = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/FolderViewCSM"); gtk_widget_tap_and_hold_setup (GTK_WIDGET (priv->folder_view), menu, NULL, 0); - + g_signal_connect (G_OBJECT(priv->folder_view), "tap-and-hold", + G_CALLBACK(_folder_view_csm_menu_activated), + self); /* header view */ /* g_signal_connect (G_OBJECT(priv->header_view), "status_update", */ /* G_CALLBACK(modest_ui_actions_on_header_status_update), self); */ @@ -413,6 +504,13 @@ connect_signals (ModestMainWindow *self) g_signal_connect (G_OBJECT(priv->header_view), "key-press-event", G_CALLBACK(on_inner_widgets_key_pressed), self); + /* Header view CSM */ + menu = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/HeaderViewCSM"); + gtk_widget_tap_and_hold_setup (GTK_WIDGET (priv->header_view), menu, NULL, 0); + g_signal_connect (G_OBJECT(priv->header_view), "tap-and-hold", + G_CALLBACK(_header_view_csm_menu_activated), + self); + /* window */ g_signal_connect (G_OBJECT(self), "delete-event", G_CALLBACK(on_delete_event), self); g_signal_connect (G_OBJECT (self), "window-state-event", @@ -500,25 +598,32 @@ static void on_hildon_program_is_topmost_notify(GObject *self, ModestWindow* modest_main_window_new (void) { - ModestMainWindow *self; - ModestMainWindowPrivate *priv; - ModestWindowPrivate *parent_priv; - GtkWidget *folder_win; - GtkActionGroup *action_group; + ModestMainWindow *self = NULL; + ModestMainWindowPrivate *priv = NULL; + ModestWindowPrivate *parent_priv = NULL; + GtkWidget *folder_win = NULL; + ModestDimmingRulesGroup *menu_rules_group = NULL; + ModestDimmingRulesGroup *toolbar_rules_group = NULL; + GtkActionGroup *action_group = NULL; GError *error = NULL; - TnyFolderStoreQuery *query; - GdkPixbuf *window_icon; - ModestConf *conf; - GtkAction *action; + TnyFolderStoreQuery *query = NULL; + GdkPixbuf *window_icon = NULL; + ModestConf *conf = NULL; + GtkAction *action = NULL; self = MODEST_MAIN_WINDOW(g_object_new(MODEST_TYPE_MAIN_WINDOW, NULL)); priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self); 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); + menu_rules_group = modest_dimming_rules_group_new ("ModestMenuDimmingRules"); + toolbar_rules_group = modest_dimming_rules_group_new ("ModestToolbarDimmingRules"); + /* Add common actions */ gtk_action_group_add_actions (action_group, modest_action_entries, @@ -530,6 +635,11 @@ modest_main_window_new (void) G_N_ELEMENTS (modest_folder_view_action_entries), self); + gtk_action_group_add_actions (action_group, + modest_header_view_action_entries, + G_N_ELEMENTS (modest_header_view_action_entries), + self); + gtk_action_group_add_toggle_actions (action_group, modest_toggle_action_entries, G_N_ELEMENTS (modest_toggle_action_entries), @@ -552,6 +662,22 @@ modest_main_window_new (void) error = NULL; } + /* Add common dimming rules */ + modest_dimming_rules_group_add_rules (menu_rules_group, + modest_main_window_menu_dimming_entries, + G_N_ELEMENTS (modest_main_window_menu_dimming_entries), + self); + modest_dimming_rules_group_add_rules (toolbar_rules_group, + modest_main_window_toolbar_dimming_entries, + G_N_ELEMENTS (modest_main_window_toolbar_dimming_entries), + self); + + /* Insert dimming rules group for this window */ + modest_ui_dimming_manager_insert_rules_group (parent_priv->ui_dimming_manager, menu_rules_group); + modest_ui_dimming_manager_insert_rules_group (parent_priv->ui_dimming_manager, toolbar_rules_group); + g_object_unref (menu_rules_group); + g_object_unref (toolbar_rules_group); + /* Add accelerators */ gtk_window_add_accel_group (GTK_WINDOW (self), gtk_ui_manager_get_accel_group (parent_priv->ui_manager)); @@ -605,9 +731,8 @@ modest_main_window_new (void) /* paned */ priv->main_paned = gtk_hpaned_new (); - gtk_paned_add1 (GTK_PANED(priv->main_paned), folder_win); - gtk_paned_add2 (GTK_PANED(priv->main_paned), priv->contents_widget); - gtk_widget_show (GTK_WIDGET(priv->header_view)); + gtk_paned_pack1 (GTK_PANED(priv->main_paned), folder_win, TRUE, TRUE); + gtk_paned_pack2 (GTK_PANED(priv->main_paned), priv->contents_widget, TRUE, TRUE); gtk_tree_view_columns_autosize (GTK_TREE_VIEW(priv->header_view)); /* putting it all together... */ @@ -615,7 +740,6 @@ modest_main_window_new (void) gtk_box_pack_start (GTK_BOX(priv->main_vbox), priv->main_paned, TRUE, TRUE,0); gtk_container_add (GTK_CONTAINER(self), priv->main_vbox); - restore_settings (MODEST_MAIN_WINDOW(self)); /* Set window icon */ window_icon = modest_platform_get_icon (MODEST_APP_ICON); @@ -657,6 +781,9 @@ modest_main_window_new (void) * hibernation: */ modest_osso_load_state(); + /* Restore window & widget settings */ + restore_settings (MODEST_MAIN_WINDOW(self)); + return MODEST_WINDOW(self); } @@ -704,7 +831,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 */ @@ -1122,7 +1248,7 @@ set_alignment (GtkWidget *widget, } static GtkWidget * -create_details_widget (TnyFolderStore *folder_store) +create_details_widget (TnyAccount *account) { GtkWidget *vbox; gchar *label; @@ -1131,7 +1257,7 @@ create_details_widget (TnyFolderStore *folder_store) /* Account description: */ - if (modest_tny_folder_store_is_virtual_local_folders (folder_store)) { + if (modest_tny_account_is_virtual_local_folders (account)) { /* Local folders: */ /* Get device name */ @@ -1144,12 +1270,11 @@ create_details_widget (TnyFolderStore *folder_store) gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (label), FALSE, FALSE, 0); g_free (device_name); g_free (label); - } else if (TNY_IS_ACCOUNT (folder_store)) { - TnyAccount *account = TNY_ACCOUNT(folder_store); - + } else { if(!strcmp (tny_account_get_id (account), MODEST_MMC_ACCOUNT_ID)) { - /* TODO: MMC ? */ - gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("FIXME: MMC ?"), FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (vbox), + gtk_label_new (tny_account_get_name (account)), + FALSE, FALSE, 0); } else { /* Other accounts, such as IMAP and POP: */ @@ -1170,7 +1295,7 @@ create_details_widget (TnyFolderStore *folder_store) } /* 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); @@ -1183,7 +1308,7 @@ create_details_widget (TnyFolderStore *folder_store) g_free (label); /* Size / Date */ - if (modest_tny_folder_store_is_virtual_local_folders (folder_store)) { + if (modest_tny_account_is_virtual_local_folders (account)) { /* FIXME: format size */ label = g_strdup_printf ("%s: %d", _("mcen_fi_rootfolder_size"), modest_tny_folder_store_get_local_size (folder_store)); @@ -1193,7 +1318,9 @@ create_details_widget (TnyFolderStore *folder_store) TnyAccount *account = TNY_ACCOUNT(folder_store); if (!strcmp (tny_account_get_id (account), MODEST_MMC_ACCOUNT_ID)) { - gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("FIXME: MMC ?"), FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (vbox), + gtk_label_new (tny_account_get_name (account)), + FALSE, FALSE, 0); } else { time_t last_updated; gchar *last_updated_string; @@ -1257,11 +1384,13 @@ modest_main_window_set_contents_style (ModestMainWindow *self, /* TODO: show here account details */ TnyFolderStore *selected_folderstore = modest_folder_view_get_selected (priv->folder_view); - - priv->details_widget = create_details_widget (selected_folderstore); + if (TNY_IS_ACCOUNT (selected_folderstore)) { + priv->details_widget = create_details_widget ( + TNY_ACCOUNT (selected_folderstore)); - wrap_in_scrolled_window (priv->contents_widget, - priv->details_widget); + wrap_in_scrolled_window (priv->contents_widget, + priv->details_widget); + } break; } default: @@ -1451,7 +1580,7 @@ on_queue_changed (ModestMailOperationQueue *queue, 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); @@ -1486,11 +1615,6 @@ 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); - /* Change toolbar mode */ if (mode == TOOLBAR_MODE_TRANSFER) { while (tmp) {