* Added a new account key called type for server accounts
[modest] / src / maemo / modest-main-window.c
index 712245b..8576e2b 100644 (file)
@@ -86,6 +86,17 @@ struct _ModestMainWindowPrivate {
 #define MODEST_MAIN_WINDOW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                                 MODEST_TYPE_MAIN_WINDOW, \
                                                 ModestMainWindowPrivate))
+
+
+typedef struct _GetMsgAsyncHelper {
+        ModestMainWindowPrivate *main_window_private;
+        guint action;
+        ModestMailOperationReplyType reply_type;
+        ModestMailOperationForwardType forward_type;
+        gchar *from;
+} GetMsgAsyncHelper;
+
+
 /* globals */
 static GtkWindowClass *parent_class = NULL;
 
@@ -177,7 +188,7 @@ on_menu_about (GtkWidget *widget, gpointer data)
        gtk_about_dialog_set_comments ( GTK_ABOUT_DIALOG(about),
                _("a modest e-mail client\n\n"
                  "design and implementation: Dirk-Jan C. Binnema\n"
-                 "contributions from the fine people at KernelConcepts\n\n"
+                 "contributions from the fine people at KernelConcepts and Igalia\n\n"
                  "uses the tinymail email framework written by Philip van Hoof"));
        gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
        gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
@@ -221,19 +232,71 @@ on_menu_new_message (ModestMainWindow *self, guint action, GtkWidget *widget)
 }
 
 static void
-on_menu_reply_forward (ModestMainWindow *self, guint action, GtkWidget *widget)
+get_msg_cb (TnyFolder *folder, TnyMsg *msg, GError **err, gpointer user_data)
 {
        GtkWidget *msg_win;
+       TnyHeader *new_header;
+       TnyMsg *new_msg;
+       ModestMainWindowPrivate *priv;
+       ModestEditType edit_type = -2;
+       GetMsgAsyncHelper *helper;
+
+       helper = (GetMsgAsyncHelper *) (user_data);
+       priv  = helper->main_window_private;
+
+       /* FIXME: select proper action */
+       new_msg = NULL;
+       switch (helper->action) {
+       case 1:
+               new_msg = 
+                       modest_mail_operation_create_reply_mail (msg, helper->from, helper->reply_type,
+                                                                MODEST_MAIL_OPERATION_REPLY_MODE_SENDER);
+               edit_type = MODEST_EDIT_TYPE_REPLY;
+               break;
+       case 2:
+               new_msg = 
+                       modest_mail_operation_create_reply_mail (msg, helper->from, helper->reply_type,
+                                                                MODEST_MAIL_OPERATION_REPLY_MODE_ALL);
+               edit_type = MODEST_EDIT_TYPE_REPLY;
+               break;
+       case 3:
+               new_msg = 
+                       modest_mail_operation_create_forward_mail (msg, helper->from, helper->forward_type);
+               edit_type = MODEST_EDIT_TYPE_FORWARD;
+               break;
+       default:
+               g_warning ("unexpected action type: %d", helper->action);
+       }
+       
+       if (new_msg) {
+               /* Set from */
+               new_header = tny_msg_get_header (new_msg);
+               tny_header_set_from (new_header, helper->from);
+               
+               /* Show edit window */
+               msg_win = modest_edit_msg_window_new (priv->widget_factory,
+                                                     edit_type,
+                                                     new_msg);
+               gtk_widget_show (msg_win);
+               
+               /* Clean and go on */
+               g_object_unref (new_msg);
+       }
+}
+
+static void
+on_menu_reply_forward (ModestMainWindow *self, guint action, GtkWidget *widget)
+{
        ModestMainWindowPrivate *priv;
        ModestHeaderView *header_view;
        TnyList *header_list;
        TnyIterator *iter;
-       const gchar *from;
        gchar *reply_key, *forward_key;
        ModestMailOperationReplyType reply_type;
        ModestMailOperationForwardType forward_type;
        ModestConf *conf;
        GError *error;
+       GetMsgAsyncHelper *helper;
 
        priv  = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
        conf = modest_tny_platform_factory_get_modest_conf_instance (priv->factory);
@@ -245,77 +308,71 @@ on_menu_reply_forward (ModestMainWindow *self, guint action, GtkWidget *widget)
        error = NULL;
        reply_key = g_strdup_printf ("%s/%s", MODEST_CONF_NAMESPACE, MODEST_CONF_REPLY_TYPE);
        reply_type = modest_conf_get_int (conf, reply_key, &error);
-       if (error) {
+       if (error || reply_type == 0) {
                g_warning ("key %s not defined", reply_key);
                reply_type = MODEST_MAIL_OPERATION_REPLY_TYPE_CITE;
-               g_error_free (error);
-               error = NULL;
+               if (error) {
+                       g_error_free (error);
+                       error = NULL;
+               }
        }
        g_free (reply_key);
        
        forward_key = g_strdup_printf ("%s/%s", MODEST_CONF_NAMESPACE, MODEST_CONF_FORWARD_TYPE);
-       forward_type = modest_conf_get_int (conf, forward_key, NULL);
-       if (error) {
+       forward_type = modest_conf_get_int (conf, forward_key, &error);
+       if (error || forward_type == 0) {
                g_warning ("key %s not defined", forward_key);
-               reply_type = MODEST_MAIL_OPERATION_FORWARD_TYPE_INLINE;
-               g_error_free (error);
+               forward_type = MODEST_MAIL_OPERATION_FORWARD_TYPE_INLINE;
+               if (error) {
+                       g_error_free (error);
+                       error = NULL;
+               }
        }
        g_free (forward_key);
        
        if (header_list) {
+               TnyHeader *header;
+               TnyFolder *folder;
+               gchar *from, *email_key;
+               const gchar *account_name;
+
+               /* We assume that we can only select messages of the
+                  same folder and that we reply all of them from the
+                  same account. In fact the interface currently only
+                  allows single selection */
+               account_name = modest_folder_view_get_selected_account (priv->folder_view);
+               email_key = g_strdup_printf ("%s/%s/%s", MODEST_ACCOUNT_NAMESPACE, 
+                                            account_name, MODEST_ACCOUNT_EMAIL);
+               from = modest_conf_get_string (conf, email_key, NULL);
+               g_free (email_key);
+
                iter = tny_list_create_iterator (header_list);
+               header = TNY_HEADER (tny_iterator_get_current (iter));
+               folder = tny_header_get_folder (header);
+
                do {
-                       TnyHeader *header, *new_header;
-                       TnyFolder *folder;
-                       TnyMsg    *msg, *new_msg;
-                       ModestEditType edit_type;
+                       /* Since it's not an object, we need to create
+                          it each time due to it's not a GObject and
+                          we can not do a g_object_ref. No need to
+                          free it, tinymail will do it for us. */
+                       helper = g_slice_new0 (GetMsgAsyncHelper);
+                       helper->main_window_private = priv;
+                       helper->reply_type = reply_type;
+                       helper->forward_type = forward_type;
+                       helper->action = action;
+                       helper->from = from;
 
                        /* Get msg from header */
                        header = TNY_HEADER (tny_iterator_get_current (iter));
-                       folder = tny_header_get_folder (header);
-                       msg = tny_folder_get_msg (folder, header, NULL); /* FIXME */
-
-                       from = modest_folder_view_get_selected_account (priv->folder_view);
-
-                       /* FIXME: select proper action */
-                       switch (action) {
-                       case 1:
-                               new_msg = 
-                                       modest_mail_operation_create_reply_mail (msg, from, reply_type,
-                                                                                MODEST_MAIL_OPERATION_REPLY_MODE_SENDER);
-                               edit_type = MODEST_EDIT_TYPE_REPLY;
-                               break;
-                       case 2:
-                               new_msg = 
-                                       modest_mail_operation_create_reply_mail (msg, from, reply_type,
-                                                                                MODEST_MAIL_OPERATION_REPLY_MODE_ALL);
-                               edit_type = MODEST_EDIT_TYPE_REPLY;
-                               break;
-                       case 3:
-                               new_msg = 
-                                       modest_mail_operation_create_forward_mail (msg, from, forward_type);
-                               edit_type = MODEST_EDIT_TYPE_FORWARD;
-                               break;
-                       default:
-                               g_warning ("unexpected action type: %d", action);
-                       }
-
-                       /* Set from */
-                       new_header = tny_msg_get_header (new_msg);
-                       tny_header_set_from (new_header, 
-                                            modest_folder_view_get_selected_account (priv->folder_view));
-
-                       /* Show edit window */
-                       msg_win = modest_edit_msg_window_new (priv->widget_factory,
-                                                             edit_type,
-                                                             new_msg);
-                       gtk_widget_show (msg_win);
-
-                       /* Clean and go on */
-                       g_object_unref (new_msg);
+                       tny_folder_get_msg_async (folder, header, get_msg_cb, helper);
                        tny_iterator_next (iter);
 
                } while (!tny_iterator_is_done (iter));
+
+               /* Clean */
+               g_free (from);
+               g_object_unref (G_OBJECT (iter));
+               g_object_unref (G_OBJECT (folder));
        }
 }
 
@@ -371,18 +428,18 @@ on_menu_delete (ModestMainWindow *self, guint action, GtkWidget *widget)
 
 /* Our menu, an array of GtkItemFactoryEntry structures that defines each menu item */
 static const gchar* UI_DEF=
-       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+//     "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
        "<ui>"
        "  <popup>"
-       "    <menu name=\"Message\" \"MenuMessage\">"
+       "    <menu name=\"Message\" action=\"MenuMessage\">"
        "      <menuitem name=\"New\" action=\"on_menu_new_message\" />"
        "    </menu>"
-//     "    <menu name=\"JustifyMenu\" action=\"JustifyMenuAction\">"
-//     "      <menuitem name=\"Left\" action=\"justify-left\"/>"
-//     "      <menuitem name=\"Centre\" action=\"justify-center\"/>"
-//     "      <menuitem name=\"Right\" action=\"justify-right\"/>"
-//     "      <menuitem name=\"Fill\" action=\"justify-fill\"/>"
-//     "    </menu>"
+       "    <menu name=\"JustifyMenu\" action=\"JustifyMenuAction\">"
+       "      <menuitem name=\"Left\" action=\"justify-left\"/>"
+       "      <menuitem name=\"Centre\" action=\"justify-center\"/>"
+       "      <menuitem name=\"Right\" action=\"justify-right\"/>"
+       "      <menuitem name=\"Fill\" action=\"justify-fill\"/>"
+       "    </menu>"
        "  </popup>"
        "</ui>";
 
@@ -390,6 +447,7 @@ static GtkMenu *
 get_menu (ModestMainWindow *self)
 {
        GtkWidget *w;
+       GError *err = NULL;
        int i = 0;
        
        ModestMainWindowPrivate *priv;
@@ -397,13 +455,14 @@ get_menu (ModestMainWindow *self)
 
        priv->ui_manager = gtk_ui_manager_new ();
 
-       gtk_ui_manager_add_ui_from_string (priv->ui_manager,
-                                          UI_DEF, strlen(UI_DEF),
-                                          NULL);
-
-       w = gtk_ui_manager_get_widget (priv->ui_manager, "/popup");
-       g_warning ("==> GtkMenu? ==> %s", GTK_IS_MENU(w) ? "yes" : "no"); 
-
+       if (!gtk_ui_manager_add_ui_from_string (priv->ui_manager,
+                                               UI_DEF, strlen(UI_DEF),
+                                               &err)) {
+               g_warning (err->message);
+               g_error_free (err);
+       }
+       
+       w = gtk_ui_manager_get_widget (priv->ui_manager, "/ui/popup");
        return GTK_MENU(w);
 }
 
@@ -413,29 +472,30 @@ static ModestHeaderView*
 header_view_new (ModestMainWindow *self)
 {
        int i;
-       GSList *columns = NULL;
+       GList *columns = NULL;
        ModestHeaderView *header_view;
        ModestMainWindowPrivate *priv;
        ModestHeaderViewColumn cols[] = {
                MODEST_HEADER_VIEW_COLUMN_MSGTYPE,
                MODEST_HEADER_VIEW_COLUMN_ATTACH,
-/*             MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER, */
-               MODEST_HEADER_VIEW_COLUMN_FROM,
-               MODEST_HEADER_VIEW_COLUMN_SUBJECT,
-               MODEST_HEADER_VIEW_COLUMN_RECEIVED_DATE
+               MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER
+//             MODEST_HEADER_VIEW_COLUMN_FROM,
+//             MODEST_HEADER_VIEW_COLUMN_SUBJECT,
+//             MODEST_HEADER_VIEW_COLUMN_RECEIVED_DATE
        };
        priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
        
        for (i = 0 ; i != sizeof(cols) / sizeof(ModestHeaderViewColumn); ++i)
-               columns = g_slist_append (columns, GINT_TO_POINTER(cols[i]));
+               columns = g_list_append (columns, GINT_TO_POINTER(cols[i]));
 
        header_view = modest_widget_factory_get_header_view (priv->widget_factory);
        modest_header_view_set_columns (header_view, columns);
-       g_slist_free (columns);
+       g_list_free (columns);
 
        return header_view;
 }
 
+
 static void
 on_toolbar_button_clicked (ModestToolbar *toolbar, ModestToolbarButton button_id,
                           ModestMainWindow *self)
@@ -535,11 +595,11 @@ restore_sizes (ModestMainWindow *self)
        priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
        conf = modest_tny_platform_factory_get_modest_conf_instance (priv->factory);
 
-       modest_widget_memory_restore_settings (conf,GTK_WIDGET(self),
+       modest_widget_memory_restore (conf,G_OBJECT(self),
                                               "modest-main-window");
-       modest_widget_memory_restore_settings (conf, GTK_WIDGET(priv->msg_paned),
+       modest_widget_memory_restore (conf, G_OBJECT(priv->msg_paned),
                                               "modest-msg-paned");
-       modest_widget_memory_restore_settings (conf, GTK_WIDGET(priv->main_paned),
+       modest_widget_memory_restore (conf, G_OBJECT(priv->main_paned),
                                               "modest-main-paned");
 }
 
@@ -553,11 +613,11 @@ save_sizes (ModestMainWindow *self)
        priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
        conf = modest_tny_platform_factory_get_modest_conf_instance (priv->factory);
        
-       modest_widget_memory_save_settings (conf,GTK_WIDGET(self),
+       modest_widget_memory_save (conf,G_OBJECT(self),
                                            "modest-main-window");
-       modest_widget_memory_save_settings (conf, GTK_WIDGET(priv->msg_paned),
+       modest_widget_memory_save (conf, G_OBJECT(priv->msg_paned),
                                            "modest-msg-paned");
-       modest_widget_memory_save_settings (conf, GTK_WIDGET(priv->main_paned),
+       modest_widget_memory_save (conf, G_OBJECT(priv->main_paned),
                                            "modest-main-paned");
 }