* add support for GtkWidget settings
[modest] / src / gtk / modest-ui-message-editor.c
index 9a7feab..96d3690 100644 (file)
@@ -1,3 +1,32 @@
+/* Copyright (c) 2006, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
 #include <gtk/gtk.h>
 #include <glade/glade.h>
 #include <glib/gi18n.h>
@@ -10,6 +39,8 @@
 /* TODO: put in auto* */
 #include <tny-text-buffer-stream.h>
 #include <tny-msg-folder.h>
+#include <tny-list.h>
+
 
 #include "../modest-ui.h"
 #include "../modest-window-mgr.h"
@@ -18,9 +49,9 @@
 #include "../modest-identity-mgr.h"
 
 #include "../modest-tny-account-store.h"
-#include "../modest-tny-folder-tree-view.h"
-#include "../modest-tny-header-tree-view.h"
-#include "../modest-tny-msg-view.h"
+#include "../widgets/modest-folder-view.h"
+#include "../widgets/modest-header-view.h"
+#include "../widgets/modest-msg-view.h"
 #include "../modest-tny-transport-actions.h"
 #include "../modest-tny-store-actions.h"
 
@@ -270,7 +301,7 @@ new_editor_with_presets (ModestUI *modest_ui, const gchar *to_header,
 
        g_return_if_fail (modest_ui);
 
-       edit_win = modest_editor_window_new(modest_ui);
+       edit_win = GTK_WIDGET(modest_editor_window_new(modest_ui));
        windata = (EditWinData *)modest_editor_window_get_data(MODEST_EDITOR_WINDOW(edit_win));
        g_return_if_fail(windata);
 
@@ -297,9 +328,9 @@ new_editor_with_presets (ModestUI *modest_ui, const gchar *to_header,
 
        priv = MODEST_UI_GET_PRIVATE(modest_ui);
        height = modest_conf_get_int (priv->modest_conf,
-                                         MODEST_CONF_EDIT_WINDOW_HEIGHT, NULL);
+                                         MODEST_EDIT_WINDOW_HEIGHT, NULL);
        width  = modest_conf_get_int (priv->modest_conf,
-                                         MODEST_CONF_EDIT_WINDOW_WIDTH, NULL);
+                                         MODEST_EDIT_WINDOW_WIDTH, NULL);
 
        // g_message("new editor win@%dx%d", width, height);
 
@@ -350,8 +381,8 @@ quoted_send_msg (ModestUI *modest_ui, quoted_send_type qstype)
 
        TnyMsgHeaderIface *header;
 
-       ModestTnyHeaderTreeView *header_view;
-       ModestTnyMsgView *msg_view;
+       ModestHeaderView *header_view;
+       ModestMsgView *msg_view;
        ModestUIPrivate *priv;
 
        const TnyMsgIface *msg;
@@ -368,10 +399,10 @@ quoted_send_msg (ModestUI *modest_ui, quoted_send_type qstype)
 
        priv = MODEST_UI_GET_PRIVATE(modest_ui);
 
-       msg_view = MODEST_TNY_MSG_VIEW(priv->message_view);
+       msg_view = MODEST_MSG_VIEW(priv->message_view);
        g_return_if_fail (msg_view);
 
-       header_view = MODEST_TNY_HEADER_TREE_VIEW(priv->header_view);
+       header_view = MODEST_HEADER_VIEW(priv->header_view);
        g_return_if_fail (header_view);
 
        sel = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
@@ -409,23 +440,26 @@ quoted_send_msg (ModestUI *modest_ui, quoted_send_type qstype)
        from = tny_msg_header_iface_get_from(header);
        sent_date = tny_msg_header_iface_get_date_sent(header);
 
-       unquoted = modest_tny_msg_view_get_selected_text(msg_view);
+       unquoted = modest_msg_view_get_selected_text(msg_view);
        quoted = modest_tny_msg_actions_quote(msg, from, sent_date, line_limit, unquoted);
 
        switch (qstype) {
                case QUOTED_SEND_REPLY:
                        g_string_prepend(re_sub, _("Re: "));
-                       new_editor_with_presets(modest_ui, from, /* cc */ "", /* bcc */ "", re_sub->str, quoted, attachments);
+                       new_editor_with_presets(modest_ui, from, /* cc */ "", /* bcc */ "",
+                                               re_sub->str, quoted, attachments);
                        break;
                case QUOTED_SEND_FORWARD:
                        attachments = modest_tny_attachment_new_list_from_msg(msg, FALSE);
                        g_string_prepend(re_sub, _("Fwd: "));
-                       new_editor_with_presets(modest_ui, /* from */ "", /* cc */ "", /* bcc */ "", re_sub->str, quoted, attachments);
+                       new_editor_with_presets(modest_ui, /* from */ "", /* cc */ "",
+                                               /* bcc */ "", re_sub->str, quoted, attachments);
                        break;
                case QUOTED_SEND_FORWARD_ATTACHED:
                        attachments = modest_tny_attachment_new_list_from_msg(msg, TRUE);
                        g_string_prepend(re_sub, _("Fwd: "));
-                       new_editor_with_presets(modest_ui, /* from */ "", /* cc */ "", /* bcc */ "", re_sub->str, "", attachments);
+                       new_editor_with_presets(modest_ui, /* from */ "", /* cc */ "",
+                                               /* bcc */ "", re_sub->str, "", attachments);
                        break;
                default:
                        break;
@@ -484,14 +518,14 @@ on_send_button_clicked (GtkWidget *widget, ModestEditorWindow *modest_editwin)
        gchar *body;
        GtkTextIter start, end;
        GtkTextBuffer *buf;
-       TnyAccountStoreIface *account_store;
-       const GList *transport_accounts;
        TnyTransportAccountIface *transport_account;
        ModestIdentityMgr *id_mgr;
        EditWinData *win_data;
        GList * attachments;
 
-
+       TnyListIface *transport_accounts;
+       TnyIteratorIface *iter;
+       
        win_data = modest_editor_window_get_data(modest_editwin);
        modest_ui = win_data->modest_ui;
 
@@ -502,15 +536,6 @@ on_send_button_clicked (GtkWidget *widget, ModestEditorWindow *modest_editwin)
 
        priv = MODEST_UI_GET_PRIVATE(modest_ui);
 
-       account_store = priv->account_store;
-       transport_accounts =
-               tny_account_store_iface_get_transport_accounts (account_store);
-       if (!transport_accounts) {
-               g_message ("cannot send message: no transport account defined");
-               return;
-       } else /* take the first one! */
-               transport_account =
-                       TNY_TRANSPORT_ACCOUNT_IFACE(transport_accounts->data);
 
        to_entry      = glade_xml_get_widget (win_data->glade_xml, "to_entry");
        subject_entry = glade_xml_get_widget (win_data->glade_xml, "subject_entry");
@@ -533,13 +558,31 @@ on_send_button_clicked (GtkWidget *widget, ModestEditorWindow *modest_editwin)
        
        g_message("sending \"%s\" %s ==> %s", subject, email_from, to);
 
+       transport_accounts = TNY_LIST_IFACE(tny_list_new ());
+       tny_account_store_iface_get_accounts (priv->account_store,
+                                             transport_accounts,
+                                             TNY_ACCOUNT_STORE_IFACE_TRANSPORT_ACCOUNTS);
+       
+       iter = tny_list_iface_create_iterator (transport_accounts);
+               
+       if (!transport_accounts || !tny_iterator_iface_has_first(iter)) {
+               g_printerr ("modest: cannot send message: no transport account defined");
+               return;
+       } else { /* take the first one! */
+               tny_iterator_iface_first (iter);
+               transport_account = 
+                       TNY_TRANSPORT_ACCOUNT_IFACE(tny_iterator_iface_current(iter));
+       }
+       
        modest_tny_transport_actions_send_message (actions,
                                                   transport_account,
                                                   email_from,
                                                   to, "", "", subject,
                                                   body,
                                                   attachments);
-
+       g_object_unref (G_OBJECT(iter));
+       g_object_unref (G_OBJECT(transport_accounts));
+       
        modest_editor_window_set_attachments(modest_editwin, NULL); /* This unrefs them, too. */
        g_free (body);
        g_object_unref (G_OBJECT(actions));