* Fixes NB#78357, new mail sound is played now with IMAP IDLE events
[modest] / src / gnome / modest-main-window.c
index 59cfd67..0030755 100644 (file)
@@ -30,6 +30,8 @@
 #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>
@@ -81,6 +83,10 @@ static void         on_header_status_update              (ModestHeaderView *head
                                                          gint total,  
                                                          ModestMainWindow *main_window);
 
+static void         on_header_selected                   (ModestHeaderView *header_view, 
+                                                         TnyHeader *header,
+                                                         ModestMainWindow *main_window);
+
 /* list my signals */
 enum {
        /* MY_SIGNAL_1, */
@@ -114,15 +120,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;
 
@@ -203,7 +200,8 @@ modest_main_window_init (ModestMainWindow *obj)
                                                          priv->main_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 +231,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);
@@ -273,13 +271,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);
 }
 
 
@@ -295,25 +295,28 @@ 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;
        
-       g_return_if_fail (device);
        g_return_if_fail (self);
 
        priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
@@ -331,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) { */
@@ -394,6 +397,8 @@ connect_signals (ModestMainWindow *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,12 +419,14 @@ 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);
 
@@ -478,8 +485,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 */
@@ -685,14 +694,6 @@ on_header_status_update (ModestHeaderView *header_view,
        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)
@@ -714,3 +715,88 @@ 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;
+}