* Removed ModestGnomeInfoBar and ModestProgressBarWidget
[modest] / src / gnome / modest-main-window.c
index 97beef2..8217bad 100644 (file)
 #include <glib/gi18n.h>
 #include <gtk/gtktreeviewcolumn.h>
 #include <tny-account-store-view.h>
+#include <tny-simple-list.h>
+#include <tny-error.h>
 
 #include <widgets/modest-main-window.h>
 #include <widgets/modest-window-priv.h>
 #include <widgets/modest-msg-edit-window.h>
 #include <widgets/modest-account-view-window.h>
+#include "widgets/modest-progress-bar.h"
 
 #include <modest-runtime.h>
 #include "modest-widget-memory.h"
 #include <modest-tny-msg.h>
 #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);
 static void modest_main_window_init          (ModestMainWindow *obj);
 static void modest_main_window_finalize      (GObject *obj);
 
-static void restore_sizes (ModestMainWindow *self);
-static void save_sizes (ModestMainWindow *self);
+static void         restore_settings                    (ModestMainWindow *self);
 
 static gboolean     on_header_view_button_press_event   (ModestHeaderView *header_view,
                                                         GdkEventButton   *event,
@@ -75,12 +76,12 @@ static void         on_queue_changed                     (ModestMailOperationQue
                                                          ModestMailOperationQueueNotification type,
                                                          ModestMainWindow *self);
 
-static void         on_header_status_update              (ModestHeaderView *header_view, 
-                                                         const gchar *msg, 
-                                                         gint num, 
-                                                         gint total,  
+static void         on_header_selected                   (ModestHeaderView *header_view, 
+                                                         TnyHeader *header,
                                                          ModestMainWindow *main_window);
 
+static void         save_state                           (ModestWindow *window);
+
 /* list my signals */
 enum {
        /* MY_SIGNAL_1, */
@@ -114,15 +115,6 @@ struct _ModestMainWindowPrivate {
                                                 MODEST_TYPE_MAIN_WINDOW, \
                                                 ModestMainWindowPrivate))
 
-typedef struct _GetMsgAsyncHelper {
-       ModestMainWindowPrivate *main_window_private;
-       guint action;
-       ModestTnyMsgReplyType reply_type;
-       ModestTnyMsgForwardType forward_type;
-       gchar *from;
-       TnyIterator *iter;
-} GetMsgAsyncHelper;
-
 /* globals */
 static GtkWindowClass *parent_class = NULL;
 
@@ -162,9 +154,34 @@ modest_main_window_class_init (ModestMainWindowClass *klass)
        parent_class            = g_type_class_peek_parent (klass);
        gobject_class->finalize = modest_main_window_finalize;
 
+       ((ModestWindowClass *)(klass))->save_state_func = save_state;
+
        g_type_class_add_private (gobject_class, sizeof(ModestMainWindowPrivate));
 }
 
+static GtkWidget *
+create_main_bar (GtkWidget *progress_bar)
+{
+       GtkWidget *status_bar, *main_bar;
+
+       main_bar = gtk_hbox_new (FALSE, 6);
+
+        /* Status bar */
+        status_bar = gtk_statusbar_new ();
+        gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (status_bar), FALSE);
+
+        /* Progress bar */
+        gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), 1.0);
+        gtk_progress_bar_set_ellipsize (GTK_PROGRESS_BAR (progress_bar),
+                                        PANGO_ELLIPSIZE_END);
+
+        /* Pack */
+        gtk_box_pack_start (GTK_BOX (main_bar), status_bar, TRUE, TRUE, 0);
+        gtk_box_pack_start (GTK_BOX (main_bar), progress_bar, FALSE, FALSE, 0);
+
+       return main_bar;
+}
+
 static void
 modest_main_window_init (ModestMainWindow *obj)
 {
@@ -173,6 +190,7 @@ modest_main_window_init (ModestMainWindow *obj)
        TnyFolderStoreQuery     *query;
        GtkWidget               *icon;
        gboolean                online;
+       GtkWidget *progress_bar;
        
        priv = MODEST_MAIN_WINDOW_GET_PRIVATE(obj);
        
@@ -198,12 +216,14 @@ modest_main_window_init (ModestMainWindow *obj)
 
        /* Main bar */
        priv->folder_info_label = gtk_label_new (NULL);
-       priv->main_bar = modest_gnome_info_bar_new ();
+       progress_bar = modest_progress_bar_new ();
+       priv->main_bar = create_main_bar (progress_bar);
        priv->progress_widgets = g_slist_prepend (priv->progress_widgets, 
-                                                         priv->main_bar);
+                                                 progress_bar);
 
        /* msg preview */
-       priv->msg_preview = MODEST_MSG_VIEW(modest_msg_view_new (NULL));
+       priv->msg_preview = MODEST_MSG_VIEW(tny_platform_factory_new_msg_view 
+                                           (modest_tny_platform_factory_get_instance ()));
        if (!priv->msg_preview)
                g_printerr ("modest: cannot instantiate msgpreiew\n");
 
@@ -233,23 +253,23 @@ modest_main_window_finalize (GObject *obj)
 
 GtkWidget*
 modest_main_window_get_child_widget (ModestMainWindow *self,
-                                    ModestWidgetType widget_type)
+                                    ModestMainWindowWidgetType widget_type)
 {
        ModestMainWindowPrivate *priv;
        GtkWidget *widget;
        
        g_return_val_if_fail (self, NULL);
-       g_return_val_if_fail (widget_type >= 0 && widget_type < MODEST_WIDGET_TYPE_NUM,
+       g_return_val_if_fail (widget_type >= 0 && widget_type < MODEST_MAIN_WINDOW_WIDGET_TYPE_NUM,
                              NULL);
                                
        priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
 
        switch (widget_type) {
-       case MODEST_WIDGET_TYPE_HEADER_VIEW:
+       case MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW:
                widget = (GtkWidget*)priv->header_view; break;
-       case MODEST_WIDGET_TYPE_FOLDER_VIEW:
+       case MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW:
                widget = (GtkWidget*)priv->folder_view; break;
-       case MODEST_WIDGET_TYPE_MSG_PREVIEW:
+       case MODEST_MAIN_WINDOW_WIDGET_TYPE_MSG_PREVIEW:
                widget = (GtkWidget*)priv->msg_preview; break;
        default:
                g_return_val_if_reached (NULL);
@@ -261,7 +281,7 @@ modest_main_window_get_child_widget (ModestMainWindow *self,
 
 
 static void
-restore_sizes (ModestMainWindow *self)
+restore_settings (ModestMainWindow *self)
 {
        ModestConf *conf;
        ModestMainWindowPrivate *priv;
@@ -273,73 +293,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");
-}
-
-
-static void
-save_sizes (ModestMainWindow *self)
-{
-       ModestWindowPrivate *parent_priv;
-       ModestMainWindowPrivate *priv;
-       ModestConf *conf;
-       
-       priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
-       parent_priv = MODEST_WINDOW_GET_PRIVATE(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_widget_memory_save (conf, G_OBJECT(priv->msg_paned),
-                                  "modest-msg-paned");
-       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");
-}
-
-
-static void
-on_connection_changed (TnyDevice *device, gboolean online, ModestMainWindow *self)
-{
-       GtkWidget *icon;
-       const gchar *icon_name;
-       ModestMainWindowPrivate *priv;
-       
-       g_return_if_fail (device);
-       g_return_if_fail (self);
-
-       priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
-
-       icon_name = online ? GTK_STOCK_CONNECT : GTK_STOCK_DISCONNECT;
-       icon      = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
-
-       /* Block handlers in order to avoid unnecessary calls */
-       //g_signal_handler_block (G_OBJECT (priv->online_toggle), priv->toggle_button_signal);
-       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(priv->online_toggle), online);
-       //g_signal_handler_unblock (G_OBJECT (online_toggle), priv->toggle_button_signal);
-
-       gtk_button_set_image (GTK_BUTTON(priv->online_toggle), icon);
-       //statusbar_push (widget_factory, 0, online ? _("Modest went online") : _("Modest went offline"));
-       
-       /* 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
-          ask the user for a password */
-
-/*     if (online) { */
-/*             GtkTreeSelection *selected; */
-
-/*             selected = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view)); */
-/*             _modest_header_view_change_selection (selected, header_view); */
-/*     } */
+                                     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);
 }
 
 void
@@ -354,17 +316,24 @@ 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);
 }
 
-static gboolean
-on_delete_event (GtkWidget *widget, GdkEvent  *event, ModestMainWindow *self)
+static void
+modest_main_window_on_show (GtkWidget *widget, gpointer user_data)
 {
-       save_sizes (self);
-       return FALSE;
+       ModestMainWindow *self = MODEST_MAIN_WINDOW (widget);
+
+       /* Connect signals */
+       connect_signals (self);
+
+       /* Restore window & widget settings */  
+       restore_settings (self);
 }
 
 static void
@@ -388,10 +357,10 @@ connect_signals (ModestMainWindow *self)
                          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(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",
@@ -412,12 +381,12 @@ 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(priv->online_toggle), "toggled",
                          G_CALLBACK(on_online_toggle_toggled), self);
 
@@ -426,9 +395,6 @@ connect_signals (ModestMainWindow *self)
                          "queue-changed",
                          G_CALLBACK (on_queue_changed),
                          self);
-       
-       /* window */
-       g_signal_connect (G_OBJECT(self), "delete-event", G_CALLBACK(on_delete_event), self);
 }
 
 
@@ -476,8 +442,10 @@ 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();
+       parent_priv->ui_dimming_manager = modest_ui_dimming_manager_new ();
        action_group = gtk_action_group_new ("ModestMainWindowActions");
        
        /* Add common actions */
@@ -533,21 +501,21 @@ modest_main_window_new (void)
        gtk_box_pack_start (GTK_BOX(main_vbox), parent_priv->toolbar, FALSE, FALSE, 0);
        gtk_box_pack_start (GTK_BOX(main_vbox), priv->main_paned, TRUE, TRUE,0);
        gtk_box_pack_start (GTK_BOX(main_vbox), status_hbox, FALSE, FALSE, 0);
-       
        gtk_container_add (GTK_CONTAINER(obj), main_vbox);
-       restore_sizes (MODEST_MAIN_WINDOW(obj));        
 
        gtk_window_set_title (GTK_WINDOW(obj), _("Modest"));
        gtk_window_set_icon_from_file  (GTK_WINDOW(obj), MODEST_APP_ICON, NULL);        
        gtk_widget_show_all (main_vbox);
        
-       /* Connect signals */
-       connect_signals (MODEST_MAIN_WINDOW(obj));
+       /* Do some tasks on show */
+       g_signal_connect (G_OBJECT(self), "show", G_CALLBACK (modest_main_window_on_show), NULL);
 
        /* Set account store */
        tny_account_store_view_set_account_store (TNY_ACCOUNT_STORE_VIEW (priv->folder_view),
                                                  TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
 
+       gtk_window_set_default_size (GTK_WINDOW (obj), 800, 600);
+
        return (ModestWindow *) obj;
 }
 
@@ -662,35 +630,6 @@ on_queue_changed (ModestMailOperationQueue *queue,
        }
 }
 
-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)
@@ -698,6 +637,7 @@ modest_main_window_set_style (ModestMainWindow *self,
        /* TODO */
 }
 
+
 ModestMainWindowStyle
 modest_main_window_get_style (ModestMainWindow *self)
 {
@@ -711,3 +651,106 @@ modest_main_window_set_contents_style (ModestMainWindow *self,
 {
        /* 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 ||!(*err)) {
+               ModestMsgView *msg_preview;
+
+               msg_preview = MODEST_MSG_VIEW (user_data);
+               tny_msg_view_set_msg (TNY_MSG_VIEW (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, 
+                                 (TnyGetMsgCallback) get_msg_callback, 
+                                 NULL, 
+                                 priv->msg_preview);
+}
+
+void      
+modest_main_window_notify_send_receive_initied    (ModestMainWindow *self)
+{
+       g_message("NOT IMPLEMENTED %s", __FUNCTION__);
+}
+void      
+modest_main_window_notify_send_receive_completed    (ModestMainWindow *self)
+{
+       g_message("NOT IMPLEMENTED %s", __FUNCTION__);
+}
+
+gboolean
+modest_main_window_transfer_mode_enabled (ModestMainWindow *self)
+{
+       g_message("NOT IMPLEMENTED %s", __FUNCTION__);
+       return FALSE;
+}
+
+gboolean  
+modest_main_window_on_msg_view_window_msg_changed (ModestMsgViewWindow *view_window,
+                                                  GtkTreeModel *model,
+                                                  GtkTreeRowReference *row_reference,
+                                                  ModestMainWindow *self)
+{
+       g_message("NOT IMPLEMENTED %s", __FUNCTION__);
+       return FALSE;
+}
+
+gboolean  
+modest_main_window_screen_is_on (ModestMainWindow *self)
+{
+       g_message("NOT IMPLEMENTED %s", __FUNCTION__);
+       return TRUE;
+}
+
+static void
+save_state (ModestWindow *window)
+{
+       ModestConf *conf;
+       ModestMainWindow* self = MODEST_MAIN_WINDOW(window);
+       ModestMainWindowPrivate *priv;
+               
+       priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
+       conf = modest_runtime_get_conf ();
+       
+       modest_widget_memory_save (conf, G_OBJECT(self), 
+                                  MODEST_CONF_MAIN_WINDOW_KEY);
+       modest_widget_memory_save (conf, G_OBJECT(priv->main_paned), 
+                                  MODEST_CONF_MAIN_PANED_KEY);
+       modest_widget_memory_save (conf, G_OBJECT(priv->folder_view), 
+                                  MODEST_CONF_FOLDER_VIEW_KEY);
+}