X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fgnome%2Fmodest-main-window.c;h=5d07395017a7bf78af2b3a1f68311d303defe175;hb=c9001bc9a4aa41e6c9a6ff9923e3ed194b02d5ad;hp=1b43e424301124a33d4fbf93a8835fc92840ef40;hpb=c8b9bfc0b28ec5aad0ad72e49a7f049b0fb5f41e;p=modest diff --git a/src/gnome/modest-main-window.c b/src/gnome/modest-main-window.c index 1b43e42..5d07395 100644 --- a/src/gnome/modest-main-window.c +++ b/src/gnome/modest-main-window.c @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include @@ -45,6 +47,7 @@ #include #include "modest-mail-operation.h" #include "modest-icon-names.h" +#include "modest-gnome-info-bar.h" /* 'private'/'protected' functions */ static void modest_main_window_class_init (ModestMainWindowClass *klass); @@ -69,6 +72,20 @@ static gboolean show_context_popup_menu (ModestMainWindow *windo static void connect_signals (ModestMainWindow *self); +static void on_queue_changed (ModestMailOperationQueue *queue, + ModestMailOperation *mail_op, + ModestMailOperationQueueNotification type, + ModestMainWindow *self); + +static void on_header_status_update (ModestHeaderView *header_view, + const gchar *msg, + gint num, + gint total, + ModestMainWindow *main_window); + +static void on_header_selected (ModestHeaderView *header_view, + TnyHeader *header, + ModestMainWindow *main_window); /* list my signals */ enum { @@ -80,12 +97,12 @@ enum { typedef struct _ModestMainWindowPrivate ModestMainWindowPrivate; struct _ModestMainWindowPrivate { - GtkWidget *folder_paned; - GtkWidget *msg_paned; - GtkWidget *main_paned; + GtkWidget *folder_paned; + GtkWidget *msg_paned; + GtkWidget *main_paned; - GtkWidget *online_toggle; - GtkWidget *folder_info_label; + GtkWidget *online_toggle; + GtkWidget *folder_info_label; ModestHeaderView *header_view; ModestFolderView *folder_view; @@ -94,6 +111,8 @@ struct _ModestMainWindowPrivate { GtkWidget *status_bar; GtkWidget *progress_bar; + GSList *progress_widgets; + GtkWidget *main_bar; }; @@ -101,15 +120,6 @@ struct _ModestMainWindowPrivate { MODEST_TYPE_MAIN_WINDOW, \ ModestMainWindowPrivate)) -typedef struct _GetMsgAsyncHelper { - ModestMainWindowPrivate *main_window_private; - guint action; - ModestMailOperationReplyType reply_type; - ModestMailOperationForwardType forward_type; - gchar *from; - TnyIterator *iter; -} GetMsgAsyncHelper; - /* globals */ static GtkWindowClass *parent_class = NULL; @@ -166,10 +176,11 @@ modest_main_window_init (ModestMainWindow *obj) priv->folder_paned = NULL; priv->msg_paned = NULL; priv->main_paned = NULL; + priv->progress_widgets = NULL; account_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()); - /* online/offline combo */ + /* online/offline toggle */ priv->online_toggle = gtk_toggle_button_new (); online = tny_device_is_online (modest_runtime_get_device()); icon = gtk_image_new_from_icon_name (online ? GTK_STOCK_CONNECT : GTK_STOCK_DISCONNECT, @@ -177,20 +188,16 @@ modest_main_window_init (ModestMainWindow *obj) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(priv->online_toggle), online); gtk_button_set_image (GTK_BUTTON(priv->online_toggle),icon); - /* label with number of items, unread items for - the current folder */ - priv->folder_info_label = gtk_label_new (NULL); - - /* status bar */ - priv->status_bar = gtk_statusbar_new (); - gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR(priv->status_bar), - FALSE); + /* Paned */ + priv->folder_paned = gtk_vpaned_new (); + priv->main_paned = gtk_hpaned_new (); + priv->msg_paned = gtk_vpaned_new (); - /* progress bar */ - priv->progress_bar = gtk_progress_bar_new (); - gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(priv->progress_bar), 1.0); - gtk_progress_bar_set_ellipsize (GTK_PROGRESS_BAR(priv->progress_bar), - PANGO_ELLIPSIZE_END); + /* Main bar */ + priv->folder_info_label = gtk_label_new (NULL); + priv->main_bar = modest_gnome_info_bar_new (); + priv->progress_widgets = g_slist_prepend (priv->progress_widgets, + priv->main_bar); /* msg preview */ priv->msg_preview = MODEST_MSG_VIEW(modest_msg_view_new (NULL)); @@ -241,10 +248,6 @@ modest_main_window_get_child_widget (ModestMainWindow *self, widget = (GtkWidget*)priv->folder_view; break; case MODEST_WIDGET_TYPE_MSG_PREVIEW: widget = (GtkWidget*)priv->msg_preview; break; - case MODEST_WIDGET_TYPE_STATUS_BAR: - widget = (GtkWidget*)priv->status_bar; break; - case MODEST_WIDGET_TYPE_PROGRESS_BAR: - widget = (GtkWidget*)priv->progress_bar; break; default: g_return_val_if_reached (NULL); return NULL; @@ -267,13 +270,15 @@ restore_sizes (ModestMainWindow *self) conf = modest_runtime_get_conf (); modest_widget_memory_restore (conf, G_OBJECT(priv->folder_paned), - "modest-folder-paned"); + MODEST_CONF_FOLDER_PANED_KEY); modest_widget_memory_restore (conf, G_OBJECT(priv->msg_paned), - "modest-msg-paned"); + MODEST_CONF_MSG_PANED_KEY); modest_widget_memory_restore (conf, G_OBJECT(priv->main_paned), - "modest-main-paned"); - modest_widget_memory_restore (conf, G_OBJECT(priv->header_view),"header-view"); - modest_widget_memory_restore (conf,G_OBJECT(self), "modest-main-window"); + 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(self), + MODEST_CONF_MAIN_WINDOW_KEY); } @@ -289,20 +294,24 @@ save_sizes (ModestMainWindow *self) conf = modest_runtime_get_conf (); - modest_widget_memory_save (conf,G_OBJECT(self), "modest-main-window"); modest_widget_memory_save (conf, G_OBJECT(priv->folder_paned), - "modest-folder-paned"); + MODEST_CONF_FOLDER_PANED_KEY); modest_widget_memory_save (conf, G_OBJECT(priv->msg_paned), - "modest-msg-paned"); + MODEST_CONF_MSG_PANED_KEY); modest_widget_memory_save (conf, G_OBJECT(priv->main_paned), - "modest-main-paned"); - modest_widget_memory_save (conf, G_OBJECT(priv->header_view), "header-view"); + 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(self), + MODEST_CONF_MAIN_WINDOW_KEY); } static void -on_connection_changed (TnyDevice *device, gboolean online, ModestMainWindow *self) +on_account_store_connecting_finished (TnyAccountStore *store, ModestMainWindow *self) { + const gboolean online = TRUE; + GtkWidget *icon; const gchar *icon_name; ModestMainWindowPrivate *priv; @@ -325,7 +334,7 @@ on_connection_changed (TnyDevice *device, gboolean online, ModestMainWindow *sel /* If Modest has became online and the header view has a header selected then show it */ - /* FIXME: there is a race condition if some account needs to + /* TODO: FIXME: there is a race condition if some account needs to ask the user for a password */ /* if (online) { */ @@ -348,8 +357,10 @@ on_online_toggle_toggled (GtkToggleButton *toggle, ModestMainWindow *self) device = modest_runtime_get_device (); online = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->online_toggle)); - if (online) + if (online) { + /* TODO: Just attempt to go online, instead of forcing the online status: */ tny_device_force_online (device); + } else tny_device_force_offline (device); } @@ -362,14 +373,6 @@ on_delete_event (GtkWidget *widget, GdkEvent *event, ModestMainWindow *self) } static void -on_destroy (GtkWidget *widget, GdkEvent *event, ModestMainWindow *self) -{ - gtk_main_quit(); -} - - - -static void connect_signals (ModestMainWindow *self) { ModestWindowPrivate *parent_priv; @@ -382,18 +385,20 @@ connect_signals (ModestMainWindow *self) account_store = modest_runtime_get_account_store (); /* folder view */ - g_signal_connect (G_OBJECT(priv->folder_view), "folder_selection_changed", - G_CALLBACK(modest_ui_actions_on_folder_selection_changed), self); g_signal_connect (G_OBJECT(priv->folder_view), "button-press-event", G_CALLBACK (on_folder_view_button_press_event),self); -/* g_signal_connect (priv->folder_view, "popup-menu", */ -/* G_CALLBACK (on_folder_view_button_press_event),self); */ + g_signal_connect (G_OBJECT(priv->folder_view), "folder_selection_changed", + G_CALLBACK(modest_ui_actions_on_folder_selection_changed), self); + g_signal_connect (G_OBJECT(priv->folder_view), "folder-display-name-changed", + G_CALLBACK(modest_ui_actions_on_folder_display_name_changed), self); /* header view */ g_signal_connect (G_OBJECT(priv->header_view), "status_update", - G_CALLBACK(modest_ui_actions_on_header_status_update), self); + G_CALLBACK(on_header_status_update), self); g_signal_connect (G_OBJECT(priv->header_view), "header_selected", G_CALLBACK(modest_ui_actions_on_header_selected), self); + g_signal_connect (G_OBJECT(priv->header_view), "header_selected", + G_CALLBACK(on_header_selected), self); g_signal_connect (G_OBJECT(priv->header_view), "header_activated", G_CALLBACK(modest_ui_actions_on_header_activated), self); g_signal_connect (G_OBJECT(priv->header_view), "item_not_found", @@ -414,17 +419,24 @@ connect_signals (ModestMainWindow *self) G_CALLBACK(modest_ui_actions_on_msg_recpt_activated), self); /* Account store */ + /* Emmitted by our TnyAccountStore::get_password_func() implementation, + * This is not a normal part of tinymail: */ g_signal_connect (G_OBJECT (modest_runtime_get_account_store()), "password_requested", G_CALLBACK (modest_ui_actions_on_password_requested), self); /* Device */ - g_signal_connect (G_OBJECT(modest_runtime_get_device()), "connection_changed", - G_CALLBACK(on_connection_changed), self); + g_signal_connect (G_OBJECT(modest_runtime_get_account_store()), "connecting-finished", + G_CALLBACK(on_account_store_connecting_finished), self); g_signal_connect (G_OBJECT(priv->online_toggle), "toggled", G_CALLBACK(on_online_toggle_toggled), self); + + /* Mail Operation Queue */ + g_signal_connect (G_OBJECT (modest_runtime_get_mail_operation_queue ()), + "queue-changed", + G_CALLBACK (on_queue_changed), + self); /* window */ - g_signal_connect (G_OBJECT(self), "destroy", G_CALLBACK(on_destroy), NULL); g_signal_connect (G_OBJECT(self), "delete-event", G_CALLBACK(on_delete_event), self); } @@ -474,7 +486,6 @@ modest_main_window_new (void) priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self); parent_priv = MODEST_WINDOW_GET_PRIVATE(self); - /* ***************** */ parent_priv->ui_manager = gtk_ui_manager_new(); action_group = gtk_action_group_new ("ModestMainWindowActions"); @@ -495,7 +506,6 @@ modest_main_window_new (void) g_error_free (error); error = NULL; } - /* *************** */ /* Add accelerators */ gtk_window_add_accel_group (GTK_WINDOW (obj), @@ -505,29 +515,25 @@ modest_main_window_new (void) parent_priv->toolbar = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar"); parent_priv->menubar = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/MenuBar"); - gtk_toolbar_set_tooltips (GTK_TOOLBAR (parent_priv->toolbar), TRUE); + gtk_toolbar_set_tooltips (GTK_TOOLBAR (parent_priv->toolbar), TRUE); folder_win = wrapped_in_scrolled_window (GTK_WIDGET(priv->folder_view), FALSE); - header_win = wrapped_in_scrolled_window (GTK_WIDGET(priv->header_view), FALSE); + header_win = wrapped_in_scrolled_window (GTK_WIDGET(priv->header_view), FALSE); - /* paned */ - priv->folder_paned = gtk_vpaned_new (); - priv->msg_paned = gtk_vpaned_new (); - priv->main_paned = gtk_hpaned_new (); + /* Paned */ preview_scroll = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (preview_scroll), + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (preview_scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_paned_add1 (GTK_PANED(priv->main_paned), folder_win); gtk_paned_add2 (GTK_PANED(priv->main_paned), priv->msg_paned); gtk_paned_add1 (GTK_PANED(priv->msg_paned), header_win); - gtk_container_add (GTK_CONTAINER (preview_scroll), + gtk_container_add (GTK_CONTAINER (preview_scroll), GTK_WIDGET(priv->msg_preview)); gtk_paned_add2 (GTK_PANED(priv->msg_paned), preview_scroll); - /* status bar / progress */ + /* Main Bar */ status_hbox = gtk_hbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX(status_hbox), priv->folder_info_label, FALSE,FALSE, 6); - gtk_box_pack_start (GTK_BOX(status_hbox), priv->status_bar, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX(status_hbox), priv->progress_bar,FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(status_hbox), priv->main_bar, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX(status_hbox), priv->online_toggle,FALSE, FALSE, 0); /* putting it all together... */ @@ -564,7 +570,7 @@ on_header_view_button_press_event (ModestHeaderView *header_view, ModestWindowPrivate *parent_priv; parent_priv = MODEST_WINDOW_GET_PRIVATE (self); - menu = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/HeaderViewContextMenu"); + menu = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/HeaderViewCSM"); return show_context_popup_menu (self, GTK_TREE_VIEW (header_view), @@ -585,7 +591,7 @@ on_folder_view_button_press_event (ModestFolderView *folder_view, ModestWindowPrivate *parent_priv; parent_priv = MODEST_WINDOW_GET_PRIVATE (self); - menu = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/FolderViewContextMenu"); + menu = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/FolderViewCSM"); return show_context_popup_menu (self, GTK_TREE_VIEW (folder_view), @@ -633,3 +639,135 @@ show_context_popup_menu (ModestMainWindow *window, } return TRUE; } + +static void +on_queue_changed (ModestMailOperationQueue *queue, + ModestMailOperation *mail_op, + ModestMailOperationQueueNotification type, + ModestMainWindow *self) +{ + GSList *tmp; + ModestMainWindowPrivate *priv; + + priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self); + + tmp = priv->progress_widgets; + + switch (type) { + case MODEST_MAIL_OPERATION_QUEUE_OPERATION_ADDED: + while (tmp) { + modest_progress_object_add_operation (MODEST_PROGRESS_OBJECT (tmp->data), + mail_op); + tmp = g_slist_next (tmp); + } + break; + case MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED: + while (tmp) { + modest_progress_object_remove_operation (MODEST_PROGRESS_OBJECT (tmp->data), + mail_op); + tmp = g_slist_next (tmp); + } + break; + } +} + +static void +on_header_status_update (ModestHeaderView *header_view, + const gchar *msg, gint num, + gint total, ModestMainWindow *self) +{ + ModestMainWindowPrivate *priv; + gchar *txt; + + priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self); + + /* Set progress */ + txt = g_strdup_printf (_("Downloading %d of %d"), num, total); + modest_gnome_info_bar_set_progress (MODEST_GNOME_INFO_BAR (priv->main_bar), + (const gchar*) txt, + num, total); + g_free (txt); + + /* Set status message */ + modest_gnome_info_bar_set_message (MODEST_GNOME_INFO_BAR (priv->main_bar), msg); +} + +gboolean +modest_main_window_close_all (ModestMainWindow *self) +{ + /* TODO: show a dialog to ask the user for permission to close + all */ + return TRUE; +} + +void +modest_main_window_set_style (ModestMainWindow *self, + ModestMainWindowStyle style) +{ + /* TODO */ +} + + +ModestMainWindowStyle +modest_main_window_get_style (ModestMainWindow *self) +{ + /* TODO */ + return MODEST_MAIN_WINDOW_STYLE_SPLIT; +} + +void +modest_main_window_set_contents_style (ModestMainWindow *self, + ModestMainWindowContentsStyle style) +{ + /* TODO */ +} + +ModestMainWindowContentsStyle +modest_main_window_get_contents_style (ModestMainWindow *self) +{ + /* TODO */ + return MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS; +} + + +static void +get_msg_callback (TnyFolder *folder, + gboolean cancelled, + TnyMsg *msg, + GError **err, + gpointer user_data) +{ + if (!(*err)) { + ModestMsgView *msg_preview; + + msg_preview = MODEST_MSG_VIEW (user_data); + modest_msg_view_set_message (msg_preview, msg); + } + + /* Frees */ + g_object_unref (folder); +} + +static void +on_header_selected (ModestHeaderView *header_view, + TnyHeader *header, + ModestMainWindow *main_window) +{ + TnyFolder *folder; + ModestMainWindowPrivate *priv; + + priv = MODEST_MAIN_WINDOW_GET_PRIVATE (main_window); + + if (!header) + return; + + folder = tny_header_get_folder (header); + + /* FIXME: do not use this directly. Use a mail operation + instead in order to get progress info */ + tny_folder_get_msg_async (folder, + header, + get_msg_callback, + NULL, + priv->msg_preview); +}