#include "modest-mail-operation.h"
#include "modest-tny-platform-factory.h"
#include "modest-tny-msg.h"
+#include "modest-tny-folder.h"
#include "modest-address-book.h"
#include "modest-text-utils.h"
#include <tny-simple-list.h>
static void remove_attachment_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor);
static void zoom_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor);
static void paste_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor);
+static void copy_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor);
static void setup_insensitive_handlers (ModestMsgEditWindow *editor);
static void reset_modified (ModestMsgEditWindow *editor);
static void text_buffer_refresh_attributes (WPTextBuffer *buffer, ModestMsgEditWindow *window);
static void text_buffer_delete_range (GtkTextBuffer *buffer, GtkTextIter *start, GtkTextIter *end, gpointer userdata);
static void text_buffer_can_undo (GtkTextBuffer *buffer, gboolean can_undo, ModestMsgEditWindow *window);
+static void text_buffer_can_redo (GtkTextBuffer *buffer, gboolean can_redo, ModestMsgEditWindow *window);
static void text_buffer_delete_images_by_id (GtkTextBuffer *buffer, const gchar * image_id);
static void subject_field_changed (GtkEditable *editable, ModestMsgEditWindow *window);
static void modest_msg_edit_window_color_button_change (ModestMsgEditWindow *window,
+/* static gboolean */
+/* on_key_pressed (GtkWidget *self, */
+/* GdkEventKey *event, */
+/* gpointer user_data); */
+
static void edit_menu_activated (GtkAction *action,
gpointer userdata);
static void view_menu_activated (GtkAction *action,
modest_window_class->zoom_plus_func = modest_msg_edit_window_zoom_plus;
modest_window_class->zoom_minus_func = modest_msg_edit_window_zoom_minus;
modest_window_class->show_toolbar_func = modest_msg_edit_window_show_toolbar;
+ modest_window_class->save_state_func = save_state;
g_type_class_add_private (gobject_class, sizeof(ModestMsgEditWindowPrivate));
- modest_window_class->save_state_func = save_state;
+
}
static void
priv->text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->msg_body));
g_object_set (priv->text_buffer, "font_scale", 1.0, NULL);
wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), TRUE);
-/* gtk_text_buffer_set_can_paste_rich_text (priv->text_buffer, TRUE); */
+ gtk_text_buffer_register_serialize_tagset(GTK_TEXT_BUFFER(priv->text_buffer), "wp-text-buffer");
+ gtk_text_buffer_register_deserialize_tagset(GTK_TEXT_BUFFER(priv->text_buffer), "wp-text-buffer");
+
wp_text_buffer_reset_buffer (WP_TEXT_BUFFER (priv->text_buffer), TRUE);
priv->find_toolbar = hildon_find_toolbar_new (NULL);
gtk_widget_set_no_show_all (priv->find_toolbar, TRUE);
+/* g_signal_connect (G_OBJECT (obj), "key_pressed", G_CALLBACK (on_key_pressed), NULL) */
+
g_signal_connect (G_OBJECT (priv->text_buffer), "refresh_attributes",
G_CALLBACK (text_buffer_refresh_attributes), obj);
g_signal_connect (G_OBJECT (priv->text_buffer), "delete-range",
G_CALLBACK (text_buffer_delete_range), obj);
g_signal_connect (G_OBJECT (priv->text_buffer), "can-undo",
G_CALLBACK (text_buffer_can_undo), obj);
+ g_signal_connect (G_OBJECT (priv->text_buffer), "can-redo",
+ G_CALLBACK (text_buffer_can_redo), obj);
g_signal_connect (G_OBJECT (obj), "window-state-event",
G_CALLBACK (modest_msg_edit_window_window_state_event),
NULL);
priv->system_clipboard_change_handler_id = 0;
}
+ if (priv->draft_msg != NULL) {
+ g_object_unref (priv->draft_msg);
+ priv->draft_msg = NULL;
+ }
+
/* This had to stay alive for as long as the combobox that used it: */
modest_pair_list_free (priv->from_field_protos);
ModestMsgEditWindowPrivate *priv;
GtkTextIter iter;
TnyHeaderFlags priority_flags;
+ TnyFolder *msg_folder;
g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self));
g_return_if_fail (TNY_IS_MSG (msg));
update_window_title (self);
-/* gtk_text_buffer_set_can_paste_rich_text (priv->text_buffer, TRUE); */
wp_text_buffer_reset_buffer (WP_TEXT_BUFFER (priv->text_buffer), TRUE);
body = modest_tny_msg_get_body (msg, TRUE);
update_dimmed (self);
text_buffer_can_undo (priv->text_buffer, FALSE, self);
+ text_buffer_can_redo (priv->text_buffer, FALSE, self);
- priv->draft_msg = msg;
+ /* we should set a reference to the incoming message if it is a draft */
+ msg_folder = tny_msg_get_folder (msg);
+ if (msg_folder) {
+ if (modest_tny_folder_is_local_folder (msg_folder) &&
+ modest_tny_folder_get_local_folder_type (msg_folder) == TNY_FOLDER_TYPE_DRAFTS)
+ priv->draft_msg = g_object_ref(msg);
+ g_object_unref (msg_folder);
+ }
}
static void
restore_settings (MODEST_MSG_EDIT_WINDOW(obj));
- gtk_window_set_icon_from_file (GTK_WINDOW(obj), MODEST_APP_ICON, NULL);
-
modest_window_set_active_account (MODEST_WINDOW(obj), account_name);
modest_msg_edit_window_setup_toolbar (MODEST_MSG_EDIT_WINDOW (obj));
else
data->html_body = NULL;
- data->attachments = priv->attachments; /* TODO: copy and free ? */
+ /* deep-copy the data */
+ GList *cursor = priv->attachments;
+ data->attachments = NULL;
+ while (cursor) {
+ if (!(TNY_IS_MIME_PART(cursor->data))) {
+ g_warning ("strange data in attachment list");
+ continue;
+ }
+ data->attachments = g_list_append (data->attachments,
+ g_object_ref (cursor->data));
+ cursor = g_list_next (cursor);
+ }
+
data->priority_flags = priv->priority_flags;
return data;
}
-/* TODO: We must duplicate this implementation for GNOME and Maemo, but that is unwise. */
+
+static void
+unref_gobject (GObject *obj, gpointer data)
+{
+ if (!G_IS_OBJECT(obj))
+ return;
+ g_object_unref (obj);
+}
+
void
modest_msg_edit_window_free_msg_data (ModestMsgEditWindow *edit_window,
MsgData *data)
g_free (data->subject);
g_free (data->plain_body);
g_free (data->html_body);
+ g_free (data->account_name);
+
if (data->draft_msg != NULL) {
g_object_unref (data->draft_msg);
data->draft_msg = NULL;
}
- g_free (data->account_name);
-
- /* TODO: Free data->attachments? */
-
+
+ g_list_foreach (data->attachments, (GFunc)unref_gobject, NULL);
+ g_list_free (data->attachments);
+
g_slice_free (MsgData, data);
}
wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FORECOLOR, (gpointer) (&(buffer_format->color)));
}
if (buffer_format->cs.font_size) {
- wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_BOLD, (gpointer) (buffer_format->font_size));
+ wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FONT_SIZE, (gpointer) (buffer_format->font_size));
}
if (buffer_format->cs.justification) {
switch (buffer_format->justification) {
}
if (buffer_format->cs.font) {
- wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_BOLD, (gpointer) (buffer_format->font));
+ wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FONT, (gpointer) (buffer_format->font));
}
if (buffer_format->cs.bullet) {
wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_BULLET, (gpointer) ((int)buffer_format->bullet));
priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
- if (file_uri) {
+ if (file_uri && strlen(file_uri)) {
gint file_id = 0;
/* TODO: We should probably try to use only the URI,
*/
gchar* filename = g_filename_from_uri (file_uri, NULL, NULL);
if (!filename) {
- g_warning("%s: g_filename_from_uri(%s) failed.\n", __FUNCTION__, file_uri);
+ g_warning("%s: g_filename_from_uri('%s') failed.\n", __FUNCTION__, file_uri);
}
file_id = g_open (filename, O_RDONLY, 0);
WPTextBufferFormat format;
memset (&format, 0, sizeof (format));
- wp_text_buffer_get_current_state (WP_TEXT_BUFFER (priv->text_buffer), &format);
+ wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), &format, FALSE);
label = gtk_bin_get_child (GTK_BIN (menu_item));
format.cs.text_position = TRUE;
format.cs.font = TRUE;
format.font_size = wp_get_font_size_index (new_size_index, DEFAULT_FONT_SIZE);
- wp_text_buffer_set_format (WP_TEXT_BUFFER (priv->text_buffer), &format);
+/* wp_text_buffer_set_format (WP_TEXT_BUFFER (priv->text_buffer), &format); */
-/* if (!wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FONT_SIZE, */
-/* (gpointer) wp_get_font_size_index (new_size_index, 12))) */
-/* wp_text_view_reset_and_show_im (WP_TEXT_VIEW (priv->msg_body)); */
+ if (!wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FONT_SIZE,
+ (gpointer) wp_get_font_size_index (new_size_index, 12)))
+ wp_text_view_reset_and_show_im (WP_TEXT_VIEW (priv->msg_body));
text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), MODEST_MSG_EDIT_WINDOW (window));
- markup = g_strconcat ("<span font_family='Serif'>", gtk_label_get_text (GTK_LABEL (label)), "</span>", NULL);
+ markup = g_strconcat ("<span font_family='", DEFAULT_SIZE_BUTTON_FONT_FAMILY, "'>", gtk_label_get_text (GTK_LABEL (label)), "</span>", NULL);
gtk_label_set_markup (GTK_LABEL (priv->size_tool_button_label), markup);
g_free (markup);
}
gint file_format)
{
ModestMsgEditWindowPrivate *priv;
+ ModestWindowPrivate *parent_priv;
gint current_format;
g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
+ parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
current_format = wp_text_buffer_is_rich_text (WP_TEXT_BUFFER (priv->text_buffer))
dialog = hildon_note_new_confirmation (NULL, _("emev_nc_formatting_lost"));
response = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
- if (response == GTK_RESPONSE_OK)
+ if (response == GTK_RESPONSE_OK) {
wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), FALSE);
+ } else {
+ GtkToggleAction *action = GTK_TOGGLE_ACTION (gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/FileFormatMenu/FileFormatFormattedTextMenu"));
+ toggle_action_set_active_block_notify (action, TRUE);
+ }
}
break;
}
}
+void
+modest_msg_edit_window_redo (ModestMsgEditWindow *window)
+{
+ ModestMsgEditWindowPrivate *priv;
+
+ g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+
+ wp_text_buffer_redo (WP_TEXT_BUFFER (priv->text_buffer));
+
+ update_dimmed (window);
+
+}
+
static void
update_dimmed (ModestMsgEditWindow *window)
{
widget = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/MenuBar/EditMenu/PasteMenu");
g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (paste_insensitive_press), window);
+ widget = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/MenuBar/EditMenu/CopyMenu");
+ g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (copy_insensitive_press), window);
}
static void
gtk_action_set_sensitive (action, can_undo);
}
+static void
+text_buffer_can_redo (GtkTextBuffer *buffer, gboolean can_redo, ModestMsgEditWindow *window)
+{
+ ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
+ GtkAction *action;
+
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/RedoMenu");
+ gtk_action_set_sensitive (action, can_redo);
+}
+
static void
text_buffer_delete_images_by_id (GtkTextBuffer *buffer, const gchar * image_id)
{
hildon_banner_show_information (NULL, NULL, _("mcen_ib_unable_to_display_more"));
else if (n_att_selected == 0)
hildon_banner_show_information (NULL, NULL, _("TODO: select one attachment"));
-
+ else
+ hildon_banner_show_information (NULL, NULL, _("mail_ib_unable_to_purge_attachments"));
}
static void
ModestWindowPrivate *parent_priv;
ModestMsgEditWindowPrivate *priv;
GtkAction *action;
- gchar *selection;
+ gboolean has_selection;
GtkWidget *focused;
GList *selected_attachments = NULL;
gint n_att_selected = 0;
priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
- selection = gtk_clipboard_wait_for_text (clipboard);
+ has_selection = gtk_clipboard_wait_for_targets (clipboard, NULL, NULL);
focused = gtk_window_get_focus (GTK_WINDOW (window));
action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/CutMenu");
- gtk_action_set_sensitive (action, (selection != NULL) && (!MODEST_IS_ATTACHMENTS_VIEW (focused)));
+ gtk_action_set_sensitive (action, (has_selection) && (!MODEST_IS_ATTACHMENTS_VIEW (focused)));
action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/CopyMenu");
- gtk_action_set_sensitive (action, (selection != NULL) && (!MODEST_IS_ATTACHMENTS_VIEW (focused)));
+ gtk_action_set_sensitive (action, (has_selection) && (!MODEST_IS_ATTACHMENTS_VIEW (focused)));
selected_attachments = modest_attachments_view_get_selection (MODEST_ATTACHMENTS_VIEW (priv->attachments_view));
n_att_selected = g_list_length (selected_attachments);
action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/AttachmentsMenu/RemoveAttachmentsMenu");
gtk_action_set_sensitive (action, n_att_selected == 1);
-
update_paste_dimming (window);
}
}
+static void
+copy_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor)
+{
+ hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_unable_to_copy"));
+
+}
+
static void
modest_msg_edit_window_system_clipboard_owner_change (GtkClipboard *clipboard,
priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(window);
priv->sent = sent;
}
+
+