* src/maemo/modest-msg-edit-window.c:
[modest] / src / maemo / modest-msg-edit-window.c
index e09c165..026a676 100644 (file)
@@ -56,6 +56,7 @@
 #include "modest-tny-platform-factory.h"
 #include "modest-tny-msg.h"
 #include "modest-tny-folder.h"
+#include "modest-tny-account.h"
 #include "modest-address-book.h"
 #include "modest-text-utils.h"
 #include <tny-simple-list.h>
@@ -152,6 +153,11 @@ static gboolean gtk_text_iter_forward_search_insensitive (const GtkTextIter *ite
 
 static void remove_tags (WPTextBuffer *buffer);
 
+static void on_account_removed (TnyAccountStore *account_store, 
+                               TnyAccount *account,
+                               gpointer user_data);
+
+
 static void DEBUG_BUFFER (WPTextBuffer *buffer)
 {
 #ifdef DEBUG
@@ -253,6 +259,7 @@ struct _ModestMsgEditWindowPrivate {
        gboolean    can_undo, can_redo;
        gulong      clipboard_change_handler_id;
        gulong      default_clipboard_change_handler_id;
+       gulong      account_removed_handler_id;
        gchar       *clipboard_text;
 
        TnyMsg      *draft_msg;
@@ -369,6 +376,7 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj)
        priv->can_redo = FALSE;
        priv->clipboard_change_handler_id = 0;
        priv->default_clipboard_change_handler_id = 0;
+       priv->account_removed_handler_id = 0;
        priv->clipboard_text = NULL;
        priv->sent = FALSE;
 
@@ -628,6 +636,12 @@ modest_msg_edit_window_disconnect_signals (ModestWindow *window)
                                           priv->default_clipboard_change_handler_id))
                g_signal_handler_disconnect (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD), 
                                             priv->default_clipboard_change_handler_id);
+
+       if (priv->account_removed_handler_id && 
+           g_signal_handler_is_connected (modest_runtime_get_account_store (), 
+                                          priv->account_removed_handler_id))
+               g_signal_handler_disconnect(modest_runtime_get_account_store (), 
+                                          priv->account_removed_handler_id);
 }
 
 static void
@@ -1327,6 +1341,15 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, gboolean pre
        priv->update_caption_visibility = TRUE;
 
        modest_msg_edit_window_reset_modified (MODEST_MSG_EDIT_WINDOW (obj));
+
+       /* Track account-removed signal, this window should be closed
+          in the case we're creating a mail associated to the account
+          that is deleted */
+       priv->account_removed_handler_id = 
+               g_signal_connect (G_OBJECT (modest_runtime_get_account_store ()),
+                                 "account_removed",
+                                 G_CALLBACK(on_account_removed),
+                                 obj);
        
        return (ModestWindow*) obj;
 }
@@ -1706,7 +1729,7 @@ text_buffer_refresh_attributes (WPTextBuffer *buffer, ModestMsgEditWindow *windo
 
 }
 
-
+#ifdef MODEST_HILDON_VERSION_0
 void
 modest_msg_edit_window_select_color (ModestMsgEditWindow *window)
 {
@@ -1715,43 +1738,69 @@ modest_msg_edit_window_select_color (ModestMsgEditWindow *window)
        ModestMsgEditWindowPrivate *priv;
        GtkWidget *dialog = NULL;
        gint response;
-       const GdkColor *new_color = NULL;
-       
+       GdkColor *new_color = NULL;
+
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
        wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), buffer_format, FALSE);
        
-#ifdef MODEST_HILDON_VERSION_0 
        dialog = hildon_color_selector_new (GTK_WINDOW (window));
        hildon_color_selector_set_color (HILDON_COLOR_SELECTOR (dialog), &(buffer_format->color));
-#else
+       g_free (buffer_format);
+
+       response = gtk_dialog_run (GTK_DIALOG (dialog));
+       switch (response) {
+       case GTK_RESPONSE_OK: {
+               new_color = hildon_color_selector_get_color (HILDON_COLOR_SELECTOR (dialog));
+       }
+               break;
+       default:
+               break;
+       }
+       gtk_widget_destroy (dialog);
+       
+       if (new_color != NULL) {
+               wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FORECOLOR, (gpointer) new_color);
+               /* FIXME: free new_color here? */
+       }
+}
+#else 
+void
+modest_msg_edit_window_select_color (ModestMsgEditWindow *window)
+{
+       
+       WPTextBufferFormat *buffer_format = g_new0 (WPTextBufferFormat, 1);
+       ModestMsgEditWindowPrivate *priv;
+       GtkWidget *dialog = NULL;
+       gint response;
+       const GdkColor *new_color = NULL;
+       GdkColor col;
+
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+       wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), buffer_format, FALSE);
+               
        dialog = hildon_color_chooser_new ();
        hildon_color_chooser_set_color (HILDON_COLOR_CHOOSER (dialog), &(buffer_format->color));
-#endif /*MODEST_HILDON_VERSION_0*/             
        g_free (buffer_format);
 
        response = gtk_dialog_run (GTK_DIALOG (dialog));
        switch (response) {
        case GTK_RESPONSE_OK: {
-#ifdef MODEST_HILDON_VERSION_0
-               new_color = hildon_color_selector_get_color (HILDON_COLOR_SELECTOR (dialog));
-#else
-               GdkColor col;
                hildon_color_chooser_get_color (HILDON_COLOR_CHOOSER(dialog), &col);
                new_color = &col;
-#endif /*MODEST_HILDON_VERSION_0*/
        }
-
-       break;
+               
+               break;
        default:
                break;
        }
        gtk_widget_destroy (dialog);
-
        if (new_color != NULL)
-               wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FORECOLOR, (gpointer) new_color);
-
+               wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FORECOLOR,
+                                             (gpointer) new_color);
 }
 
+#endif /*!MODEST_HILDON_VERSION_0*/
+
 void
 modest_msg_edit_window_select_background_color (ModestMsgEditWindow *window)
 {
@@ -2023,15 +2072,27 @@ modest_msg_edit_window_remove_attachments (ModestMsgEditWindow *window,
                gboolean dialog_response;
                GList *node;
                gchar *message = NULL;
-               const gchar *filename = NULL;
+               gchar *filename = NULL;
 
                if (att_list->next == NULL) {
-                       filename = tny_mime_part_get_filename (TNY_MIME_PART (att_list->data));
+                       if (TNY_IS_MSG (att_list->data)) {
+                               TnyHeader *header = tny_msg_get_header (TNY_MSG (att_list->data));
+                               if (header) {
+                                       filename = g_strdup (tny_header_get_subject (header));
+                                       g_object_unref (header);
+                               }
+                               if (filename == NULL) {
+                                       filename = g_strdup (_("mail_va_no_subject"));
+                               }
+                       } else {
+                               filename = g_strdup (tny_mime_part_get_filename (TNY_MIME_PART (att_list->data)));
+                       }
                } else {
-                       filename = "";
+                       filename = g_strdup ("");
                }
                message = g_strdup_printf (ngettext("emev_nc_delete_attachment", "emev_nc_delete_attachments",
                                                    att_list->next == NULL), filename);
+               g_free (filename);
                confirmation_dialog = hildon_note_new_confirmation (GTK_WINDOW (window), message);
                g_free (message);
                dialog_response = (gtk_dialog_run (GTK_DIALOG (confirmation_dialog))==GTK_RESPONSE_OK);
@@ -3263,3 +3324,22 @@ remove_tags (WPTextBuffer *buffer)
 
        gtk_text_buffer_remove_all_tags (GTK_TEXT_BUFFER (buffer), &start, &end);
 }
+
+static void
+on_account_removed (TnyAccountStore *account_store, 
+                   TnyAccount *account,
+                   gpointer user_data)
+{
+       /* Do nothing if it's a store account, because we use the
+          transport to send the messages */
+       if (tny_account_get_account_type(account) == TNY_ACCOUNT_TYPE_TRANSPORT) {
+               const gchar *parent_acc = NULL;
+               const gchar *our_acc = NULL;
+
+               our_acc = modest_window_get_active_account (MODEST_WINDOW (user_data));
+               parent_acc = modest_tny_account_get_parent_modest_account_name_for_server_account (account);
+               /* Close this window if I'm showing a message of the removed account */
+               if (strcmp (parent_acc, our_acc) == 0)
+                       modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (user_data));
+       }
+}