#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>
#include <wptextview.h>
#include <wptextbuffer.h>
#include "modest-scroll-area.h"
+#include "modest-msg-edit-window-ui-dimming.h"
#include "modest-hildon-includes.h"
#ifdef MODEST_HAVE_HILDON0_WIDGETS
static gboolean msg_body_focus (GtkWidget *focus, GdkEventFocus *event, gpointer userdata);
static void body_changed (GtkTextBuffer *buffer, ModestMsgEditWindow *editor);
static void recpt_field_changed (GtkTextBuffer *buffer, ModestMsgEditWindow *editor);
-static void send_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor);
-static void style_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_can_undo (GtkTextBuffer *buffer, gboolean can_undo, ModestMsgEditWindow *window);
static void modest_msg_edit_window_clipboard_owner_change (GtkClipboard *clipboard,
GdkEvent *event,
ModestMsgEditWindow *window);
+static void subject_field_move_cursor (GtkEntry *entry,
+ GtkMovementStep step,
+ gint a1,
+ gboolean a2,
+ gpointer userdata);
static void update_window_title (ModestMsgEditWindow *window);
-static void update_dimmed (ModestMsgEditWindow *window);
-static void update_paste_dimming (ModestMsgEditWindow *window);
-static void update_remove_attachment_dimming (ModestMsgEditWindow *window);
-static void update_copy_cut_dimming (ModestMsgEditWindow *window);
-static void update_select_all_dimming (ModestMsgEditWindow *window);
-static void update_zoom_dimming (ModestMsgEditWindow *window);
-static void update_send_dimming (ModestMsgEditWindow *window);
/* Find toolbar */
static void modest_msg_edit_window_find_toolbar_search (GtkWidget *widget,
const gchar *str,
GtkTextIter *match_start,
GtkTextIter *match_end);
-
+
+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
/* GdkEventKey *event, */
/* gpointer user_data); */
-static void edit_menu_activated (GtkAction *action,
- gpointer userdata);
-static void view_menu_activated (GtkAction *action,
- gpointer userdata);
-
/* list my signals */
enum {
/* MY_SIGNAL_1, */
gint last_cid;
GList *attachments;
+ GList *images;
TnyHeaderFlags priority_flags;
gdouble zoom_level;
+ 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;
TnyMsg *outbox_msg;
priv->bcc_field = NULL;
priv->subject_field = NULL;
priv->attachments = NULL;
+ priv->images = NULL;
priv->last_cid = 0;
priv->zoom_level = 1.0;
priv->draft_msg = NULL;
priv->outbox_msg = NULL;
priv->msg_uid = NULL;
+
+ priv->can_undo = FALSE;
+ 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;
priv->last_vadj_upper = 0;
+
+ modest_window_mgr_register_help_id (modest_runtime_get_window_mgr(),
+ GTK_WINDOW(obj),"applications_email_editor");
}
return transports;
}
-static gboolean attachment_view_focus_leaved (
- GtkWidget *widget,
- GdkEventFocus *event,
- ModestMsgEditWindow *window)
-{
- g_assert(MODEST_IS_MSG_EDIT_WINDOW(window));
-
- update_remove_attachment_dimming(window);
-
- return FALSE;
-}
-
void vadj_changed (GtkAdjustment *adj,
ModestMsgEditWindow *window)
{
gtk_container_add (GTK_CONTAINER (priv->add_attachment_button), attachment_icon);
gtk_box_pack_start (GTK_BOX (subject_box), priv->add_attachment_button, FALSE, FALSE, 0);
priv->attachments_view = modest_attachments_view_new (NULL);
- g_signal_connect (G_OBJECT (priv->attachments_view), "focus-out-event",
- G_CALLBACK (attachment_view_focus_leaved), obj);
priv->header_box = gtk_vbox_new (FALSE, 0);
"changed", G_CALLBACK (recpt_field_changed), obj);
g_signal_connect (G_OBJECT (modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->bcc_field))),
"changed", G_CALLBACK (recpt_field_changed), obj);
- recpt_field_changed (modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->to_field)), MODEST_MSG_EDIT_WINDOW (obj));
g_signal_connect (G_OBJECT (priv->subject_field), "changed", G_CALLBACK (subject_field_changed), obj);
+ g_signal_connect_after (G_OBJECT (priv->subject_field), "move-cursor", G_CALLBACK (subject_field_move_cursor), obj);
g_signal_connect (G_OBJECT (priv->subject_field), "insert-text", G_CALLBACK (subject_field_insert_text), obj);
g_signal_connect (G_OBJECT (priv->find_toolbar), "close", G_CALLBACK (modest_msg_edit_window_find_toolbar_close), obj);
priv->clipboard_change_handler_id = g_signal_connect (G_OBJECT (gtk_clipboard_get (GDK_SELECTION_PRIMARY)), "owner-change",
G_CALLBACK (modest_msg_edit_window_clipboard_owner_change), obj);
+ priv->default_clipboard_change_handler_id = g_signal_connect (G_OBJECT (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD)), "owner-change",
+ G_CALLBACK (modest_msg_edit_window_clipboard_owner_change), obj);
}
{
ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
- if (g_signal_handler_is_connected (gtk_clipboard_get (GDK_SELECTION_PRIMARY),
+ if (gtk_clipboard_get (GDK_SELECTION_PRIMARY) &&
+ g_signal_handler_is_connected (gtk_clipboard_get (GDK_SELECTION_PRIMARY),
priv->clipboard_change_handler_id))
g_signal_handler_disconnect (gtk_clipboard_get (GDK_SELECTION_PRIMARY),
priv->clipboard_change_handler_id);
+ if (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD) &&
+ g_signal_handler_is_connected (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD),
+ 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
/* Sanity check: shouldn't be needed, the window mgr should
call this function before */
modest_msg_edit_window_disconnect_signals (MODEST_WINDOW (obj));
+
+ if (priv->clipboard_text != NULL) {
+ g_free (priv->clipboard_text);
+ priv->clipboard_text = NULL;
+ }
if (priv->draft_msg != NULL) {
TnyHeader *header = tny_msg_get_header (priv->draft_msg);
}
static void
-replace_with_attachments (ModestMsgEditWindow *self, GList *attachments)
+replace_with_images (ModestMsgEditWindow *self, GList *attachments)
{
ModestMsgEditWindowPrivate *priv;
GList *node;
g_object_unref (stream);
if (pixbuf != NULL) {
-/* wp_text_buffer_replace_image (WP_TEXT_BUFFER (priv->text_buffer), cid, pixbuf); */
+ wp_text_buffer_replace_image (WP_TEXT_BUFFER (priv->text_buffer), cid, pixbuf);
g_object_unref (pixbuf);
}
}
}
static void
+get_related_images (ModestMsgEditWindow *self, TnyMsg *msg)
+{
+ TnyMimePart *parent = NULL;
+ const gchar *content_type = NULL;
+ ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
+
+ content_type = tny_mime_part_get_content_type (TNY_MIME_PART (msg));
+
+ if (content_type && !g_strcasecmp (content_type, "multipart/related")) {
+ parent = g_object_ref (msg);
+ } else if (content_type && !g_strcasecmp (content_type, "multipart/mixed")) {
+ TnyList *parts = TNY_LIST (tny_simple_list_new ());
+ TnyIterator *iter;
+
+ tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
+ iter = tny_list_create_iterator (parts);
+ while (!tny_iterator_is_done (iter)) {
+ TnyMimePart *part;
+ part = TNY_MIME_PART (tny_iterator_get_current (iter));
+ content_type = tny_mime_part_get_content_type (part);
+ if (content_type && !g_strcasecmp (content_type, "multipart/related")) {
+ parent = part;
+ break;
+ } else {
+ g_object_unref (part);
+ }
+ tny_iterator_next (iter);
+ }
+ g_object_unref (iter);
+ g_object_unref (parts);
+ }
+
+ if (parent != NULL) {
+ TnyList *parts = TNY_LIST (tny_simple_list_new ());
+ TnyIterator *iter;
+
+ tny_mime_part_get_parts (TNY_MIME_PART (parent), parts);
+ iter = tny_list_create_iterator (parts);
+ while (!tny_iterator_is_done (iter)) {
+ TnyMimePart *part;
+ part = TNY_MIME_PART (tny_iterator_get_current (iter));
+ content_type = tny_mime_part_get_content_type (part);
+ if (content_type && g_str_has_prefix (content_type, "image/")) {
+ priv->images = g_list_prepend (priv->images, part);
+ } else {
+ g_object_unref (part);
+ }
+ tny_iterator_next (iter);
+ }
+ g_object_unref (iter);
+ g_object_unref (parts);
+ g_object_unref (parent);
+ }
+}
+
+static void
update_last_cid (ModestMsgEditWindow *self, GList *attachments)
{
GList *node;
cc = tny_header_get_cc (header);
bcc = tny_header_get_bcc (header);
subject = tny_header_get_subject (header);
- priority_flags = tny_header_get_flags (header) & TNY_HEADER_FLAG_PRIORITY;
+ priority_flags = tny_header_get_priority (header);
if (to)
modest_recpt_editor_set_recipients (MODEST_RECPT_EDITOR (priv->to_field), to);
wp_text_buffer_load_document_end (WP_TEXT_BUFFER (priv->text_buffer));
g_free (body);
+ /* Add attachments to the view */
+ modest_attachments_view_set_message (MODEST_ATTACHMENTS_VIEW (priv->attachments_view), msg);
+ priv->attachments = modest_attachments_view_get_attachments (MODEST_ATTACHMENTS_VIEW (priv->attachments_view));
+ if (priv->attachments == NULL) {
+ gtk_widget_hide (priv->attachments_caption);
+ } else {
+ gtk_widget_set_no_show_all (priv->attachments_caption, FALSE);
+ gtk_widget_show_all (priv->attachments_caption);
+ }
+ get_related_images (self, msg);
+ update_last_cid (self, priv->attachments);
+ update_last_cid (self, priv->images);
+ replace_with_images (self, priv->images);
+
if (preserve_is_rich && !is_html) {
wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), FALSE);
/* Get the default format required from configuration */
value that comes from msg <- not sure, should it be
allowed? */
- /* Add attachments to the view */
- modest_attachments_view_set_message (MODEST_ATTACHMENTS_VIEW (priv->attachments_view), msg);
- priv->attachments = modest_attachments_view_get_attachments (MODEST_ATTACHMENTS_VIEW (priv->attachments_view));
- if (priv->attachments == NULL) {
- gtk_widget_hide (priv->attachments_caption);
- } else {
- gtk_widget_set_no_show_all (priv->attachments_caption, FALSE);
- gtk_widget_show_all (priv->attachments_caption);
- replace_with_attachments (self, priv->attachments);
- }
- update_last_cid (self, priv->attachments);
-
DEBUG_BUFFER (WP_TEXT_BUFFER (priv->text_buffer));
gtk_text_buffer_get_start_iter (priv->text_buffer, &iter);
gtk_text_buffer_place_cursor (priv->text_buffer, &iter);
- reset_modified (self);
+ modest_msg_edit_window_reset_modified (self);
- update_dimmed (self);
+ modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (self));
text_buffer_can_undo (priv->text_buffer, FALSE, self);
text_buffer_can_redo (priv->text_buffer, FALSE, self);
if (msg_folder) {
if (modest_tny_folder_is_local_folder (msg_folder)) {
TnyFolderType type = modest_tny_folder_get_local_or_mmc_folder_type (msg_folder);
+ if (type == TNY_FOLDER_TYPE_INVALID)
+ g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
+
if (type == TNY_FOLDER_TYPE_DRAFTS)
priv->draft_msg = g_object_ref(msg);
if (type == TNY_FOLDER_TYPE_OUTBOX)
parent_priv->toolbar = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar");
hildon_window_add_toolbar (HILDON_WINDOW (window), GTK_TOOLBAR (parent_priv->toolbar));
- /* should we hide the toolbar? */
- if (!modest_conf_get_bool (modest_runtime_get_conf (), MODEST_CONF_SHOW_TOOLBAR, NULL))
- gtk_widget_hide (parent_priv->toolbar);
-
/* Font color placeholder */
placeholder = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar/FontColor");
insert_index = gtk_toolbar_get_item_index(GTK_TOOLBAR (parent_priv->toolbar), GTK_TOOL_ITEM(placeholder));
gtk_tool_item_set_expand (GTK_TOOL_ITEM (tool_item), TRUE);
gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (tool_item), TRUE);
gtk_toolbar_insert(GTK_TOOLBAR(parent_priv->toolbar), GTK_TOOL_ITEM (tool_item), insert_index);
- g_signal_connect_swapped (G_OBJECT (priv->font_color_button), "notify::color", G_CALLBACK (modest_msg_edit_window_color_button_change), window);
+ g_signal_connect_swapped (G_OBJECT (priv->font_color_button),
+ "notify::color",
+ G_CALLBACK (modest_msg_edit_window_color_button_change),
+ window);
/* Font size and face placeholder */
placeholder = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar/FontAttributes");
gtk_tool_item_set_expand (GTK_TOOL_ITEM (tool_item), TRUE);
gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (tool_item), TRUE);
+ /* Explicitelly show all the toolbar (a normal gtk_widget_show
+ will not show the tool items added to the placeholders) */
+ gtk_widget_show_all (parent_priv->toolbar);
+ /* Set the no show all *after* showing all items. We do not
+ want the toolbar to be shown with a show all because it
+ could go agains the gconf setting regarding showing or not
+ the toolbar of the editor window */
+ gtk_widget_set_no_show_all (parent_priv->toolbar, TRUE);
}
GdkPixbuf *window_icon = NULL;
GtkAction *action;
ModestConf *conf;
- gboolean prefer_formatted;
- gint file_format;
ModestPair *account_pair = NULL;
+ ModestDimmingRulesGroup *menu_rules_group = NULL;
+ ModestDimmingRulesGroup *toolbar_rules_group = NULL;
+ ModestDimmingRulesGroup *clipboard_rules_group = NULL;
g_return_val_if_fail (msg, NULL);
g_return_val_if_fail (account_name, NULL);
gtk_window_add_accel_group (GTK_WINDOW (obj),
gtk_ui_manager_get_accel_group (parent_priv->ui_manager));
- /* Menubar */
+ /* Menubar. Update the state of some toggles */
parent_priv->menubar = menubar_to_menu (parent_priv->ui_manager);
+ conf = modest_runtime_get_conf ();
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager,
+ "/MenuBar/ViewMenu/ShowToolbarMenu/ViewShowToolbarNormalScreenMenu");
+ modest_maemo_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action),
+ modest_conf_get_bool (conf, MODEST_CONF_EDIT_WINDOW_SHOW_TOOLBAR, NULL));
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager,
+ "/MenuBar/ViewMenu/ShowToolbarMenu/ViewShowToolbarFullScreenMenu");
+ modest_maemo_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action),
+ modest_conf_get_bool (conf, MODEST_CONF_EDIT_WINDOW_SHOW_TOOLBAR_FULLSCREEN, NULL));
+
hildon_window_set_menu (HILDON_WINDOW (obj), GTK_MENU (parent_priv->menubar));
/* Init window */
modest_msg_edit_window_setup_toolbar (MODEST_MSG_EDIT_WINDOW (obj));
hildon_window_add_toolbar (HILDON_WINDOW (obj), GTK_TOOLBAR (priv->find_toolbar));
- setup_insensitive_handlers (MODEST_MSG_EDIT_WINDOW (obj));
-
account_pair = modest_pair_list_find_by_first_as_string (priv->from_field_protos, account_name);
if (account_pair != NULL)
modest_combo_box_set_active_id (MODEST_COMBO_BOX (priv->from_field), account_pair->first);
+ parent_priv->ui_dimming_manager = modest_ui_dimming_manager_new ();
+ menu_rules_group = modest_dimming_rules_group_new ("ModestMenuDimmingRules", FALSE);
+ toolbar_rules_group = modest_dimming_rules_group_new ("ModestToolbarDimmingRules", TRUE);
+ clipboard_rules_group = modest_dimming_rules_group_new ("ModestClipboardDimmingRules", FALSE);
+ /* Add common dimming rules */
+ modest_dimming_rules_group_add_rules (menu_rules_group,
+ modest_msg_edit_window_menu_dimming_entries,
+ G_N_ELEMENTS (modest_msg_edit_window_menu_dimming_entries),
+ MODEST_WINDOW (obj));
+ modest_dimming_rules_group_add_rules (toolbar_rules_group,
+ modest_msg_edit_window_toolbar_dimming_entries,
+ G_N_ELEMENTS (modest_msg_edit_window_toolbar_dimming_entries),
+ MODEST_WINDOW (obj));
+ modest_dimming_rules_group_add_widget_rule (toolbar_rules_group, priv->font_color_button,
+ G_CALLBACK (modest_ui_dimming_rules_on_set_style),
+ MODEST_WINDOW (obj));
+ modest_dimming_rules_group_add_widget_rule (toolbar_rules_group, priv->font_size_toolitem,
+ G_CALLBACK (modest_ui_dimming_rules_on_set_style),
+ MODEST_WINDOW (obj));
+ modest_dimming_rules_group_add_widget_rule (toolbar_rules_group, priv->font_face_toolitem,
+ G_CALLBACK (modest_ui_dimming_rules_on_set_style),
+ MODEST_WINDOW (obj));
+ modest_dimming_rules_group_add_rules (clipboard_rules_group,
+ modest_msg_edit_window_clipboard_dimming_entries,
+ G_N_ELEMENTS (modest_msg_edit_window_clipboard_dimming_entries),
+ MODEST_WINDOW (obj));
+ /* Insert dimming rules group for this window */
+ modest_ui_dimming_manager_insert_rules_group (parent_priv->ui_dimming_manager, menu_rules_group);
+ modest_ui_dimming_manager_insert_rules_group (parent_priv->ui_dimming_manager, toolbar_rules_group);
+ modest_ui_dimming_manager_insert_rules_group (parent_priv->ui_dimming_manager, clipboard_rules_group);
+ /* Checks the dimming rules */
+ g_object_unref (menu_rules_group);
+ g_object_unref (toolbar_rules_group);
+ g_object_unref (clipboard_rules_group);
+
set_msg (MODEST_MSG_EDIT_WINDOW (obj), msg, preserve_is_rich);
text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), MODEST_MSG_EDIT_WINDOW (obj));
g_object_unref (window_icon);
}
+ modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (obj));
+ modest_window_check_dimming_rules_group (MODEST_WINDOW (obj), "ModestClipboardDimmingRules");
+
/* Dim at start clipboard actions */
action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/CutMenu");
gtk_action_set_sensitive (action, FALSE);
action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/AttachmentsMenu/RemoveAttachmentsMenu");
gtk_action_set_sensitive (action, FALSE);
- /* Update select all */
- update_select_all_dimming (MODEST_MSG_EDIT_WINDOW (obj));
- action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu");
- g_signal_connect (G_OBJECT (action), "activate", G_CALLBACK (edit_menu_activated), obj);
- action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu");
- g_signal_connect (G_OBJECT (action), "activate", G_CALLBACK (view_menu_activated), obj);
-
/* set initial state of cc and bcc */
action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ViewCcFieldMenu");
modest_maemo_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action),
modest_maemo_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action),
modest_conf_get_bool(modest_runtime_get_conf(), MODEST_CONF_SHOW_BCC, NULL));
- /* Setup the file format */
- conf = modest_runtime_get_conf ();
- prefer_formatted = modest_conf_get_bool (conf, MODEST_CONF_PREFER_FORMATTED_TEXT, &error);
- if (error) {
- g_clear_error (&error);
- file_format = MODEST_FILE_FORMAT_FORMATTED_TEXT;
- } else
- file_format = (prefer_formatted) ?
- MODEST_FILE_FORMAT_FORMATTED_TEXT :
- MODEST_FILE_FORMAT_PLAIN_TEXT;
- modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (obj), file_format);
-
- update_paste_dimming (MODEST_MSG_EDIT_WINDOW (obj));
+ modest_window_check_dimming_rules_group (MODEST_WINDOW (obj), "ModestClipboardDimmingRules");
priv->update_caption_visibility = TRUE;
- reset_modified (MODEST_MSG_EDIT_WINDOW (obj));
+ 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;
}
g_object_ref (cursor->data));
cursor = g_list_next (cursor);
}
+
+ GtkTextTagTable *tag_table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (priv->text_buffer));
+ cursor = priv->images;
+ data->images = NULL;
+ while (cursor) {
+ const gchar *cid;
+ if (!(TNY_IS_MIME_PART(cursor->data))) {
+ g_warning ("strange data in attachment list");
+ cursor = g_list_next (cursor);
+ continue;
+ }
+ cid = tny_mime_part_get_content_id (cursor->data);
+ if (cid) {
+ gchar *image_tag_id;
+ GtkTextTag *image_tag;
+ GtkTextIter iter;
+ image_tag_id = g_strdup_printf ("image-tag-%s", cid);
+ image_tag = gtk_text_tag_table_lookup (tag_table, image_tag_id);
+ g_free (image_tag_id);
+
+ gtk_text_buffer_get_start_iter (priv->text_buffer, &iter);
+ if (image_tag &&
+ ((gtk_text_iter_has_tag (&iter, image_tag))||
+ (gtk_text_iter_forward_to_tag_toggle (&iter, image_tag))))
+ data->images = g_list_append (data->images,
+ g_object_ref (cursor->data));
+ }
+ cursor = g_list_next (cursor);
+ }
data->priority_flags = priv->priority_flags;
g_list_foreach (data->attachments, (GFunc)unref_gobject, NULL);
g_list_free (data->attachments);
+ g_list_foreach (data->images, (GFunc)unref_gobject, NULL);
+ g_list_free (data->images);
g_slice_free (MsgData, data);
}
}
wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), buffer_format, FALSE);
-
+
action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ActionsBold");
modest_maemo_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), buffer_format->bold);
}
-
+#ifdef MODEST_HILDON_VERSION_0
void
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)
{
wp_text_buffer_insert_image (WP_TEXT_BUFFER (priv->text_buffer), &position, g_strdup (tny_mime_part_get_content_id (mime_part)), pixbuf);
}
- priv->attachments = g_list_prepend (priv->attachments, mime_part);
- modest_attachments_view_add_attachment (MODEST_ATTACHMENTS_VIEW (priv->attachments_view),
- mime_part);
- gtk_widget_set_no_show_all (priv->attachments_caption, FALSE);
- gtk_widget_show_all (priv->attachments_caption);
+ priv->images = g_list_prepend (priv->images, mime_part);
gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
g_free (filename);
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);
}
void
-modest_msg_edit_window_toggle_fullscreen (ModestMsgEditWindow *window)
-{
- ModestWindowPrivate *parent_priv;
- GtkAction *fs_toggle_action;
- gboolean active;
-
- parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
-
- fs_toggle_action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ViewToggleFullscreenMenu");
- active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (fs_toggle_action));
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (fs_toggle_action), !active);
-}
-
-void
modest_msg_edit_window_show_cc (ModestMsgEditWindow *window,
gboolean show)
{
gboolean show_toolbar)
{
ModestWindowPrivate *parent_priv;
+ const gchar *action_name;
+ GtkAction *action;
g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self));
parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
- /* FIXME: we can not just use the code of
+ /* We can not just use the code of
modest_msg_edit_window_setup_toolbar because it has a
mixture of both initialization and creation code. */
-
if (show_toolbar)
gtk_widget_show (GTK_WIDGET (parent_priv->toolbar));
else
gtk_widget_hide (GTK_WIDGET (parent_priv->toolbar));
+
+ /* Update also the actions (to update the toggles in the
+ menus), we have to do it manually because some other window
+ of the same time could have changed it (remember that the
+ toolbar fullscreen mode is shared by all the windows of the
+ same type */
+ if (modest_window_mgr_get_fullscreen_mode (modest_runtime_get_window_mgr ()))
+ action_name = "/MenuBar/ViewMenu/ShowToolbarMenu/ViewShowToolbarFullScreenMenu";
+ else
+ action_name = "/MenuBar/ViewMenu/ShowToolbarMenu/ViewShowToolbarNormalScreenMenu";
+
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, action_name);
+ modest_maemo_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action),
+ show_toolbar);
+
}
void
priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
- priority_flags = priority_flags & (TNY_HEADER_FLAG_PRIORITY);
if (priv->priority_flags != priority_flags) {
GtkAction *priority_action = NULL;
switch (file_format) {
case MODEST_FILE_FORMAT_FORMATTED_TEXT:
wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), TRUE);
+ remove_tags (WP_TEXT_BUFFER (priv->text_buffer));
break;
case MODEST_FILE_FORMAT_PLAIN_TEXT:
{
}
break;
}
- update_dimmed (window);
+ modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
}
}
fmt.cs.font_size = TRUE;
}
wp_text_buffer_set_format(WP_TEXT_BUFFER(priv->text_buffer), &fmt);
+ text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), window);
}
gtk_widget_destroy (dialog);
wp_text_buffer_undo (WP_TEXT_BUFFER (priv->text_buffer));
- update_dimmed (window);
+ modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
}
wp_text_buffer_redo (WP_TEXT_BUFFER (priv->text_buffer));
- update_dimmed (window);
+ modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
}
-static void
-update_dimmed (ModestMsgEditWindow *window)
+static void
+text_buffer_can_undo (GtkTextBuffer *buffer, gboolean can_undo, ModestMsgEditWindow *window)
{
ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
- ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
- GtkAction *action;
- GtkWidget *widget;
- gboolean rich_text;
- gboolean editor_focused;
-
- rich_text = wp_text_buffer_is_rich_text (WP_TEXT_BUFFER (priv->text_buffer));
- editor_focused = gtk_widget_is_focus (priv->msg_body);
- action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/SelectFontMenu");
- gtk_action_set_sensitive (action, rich_text && editor_focused);
-/* action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/BulletedListMenu"); */
-/* gtk_action_set_sensitive (action, rich_text && editor_focused); */
- action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentMenu");
- gtk_action_set_sensitive (action, rich_text && editor_focused);
- action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentMenu/AlignmentLeftMenu");
- gtk_action_set_sensitive (action, rich_text && editor_focused);
- action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentMenu/AlignmentCenterMenu");
- gtk_action_set_sensitive (action, rich_text && editor_focused);
- action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentMenu/AlignmentRightMenu");
- gtk_action_set_sensitive (action, rich_text && editor_focused);
- action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/AttachmentsMenu/InsertImageMenu");
- gtk_action_set_sensitive (action, rich_text && editor_focused);
- action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ActionsBold");
- gtk_action_set_sensitive (action, rich_text && editor_focused);
- action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ActionsItalics");
- gtk_action_set_sensitive (action, rich_text && editor_focused);
- widget = priv->font_color_button;
- gtk_widget_set_sensitive (widget, rich_text && editor_focused);
- widget = priv->font_size_toolitem;
- gtk_widget_set_sensitive (widget, rich_text && editor_focused);
- widget = priv->font_face_toolitem;
- gtk_widget_set_sensitive (widget, rich_text && editor_focused);
+ priv->can_undo = can_undo;
}
-static void
-setup_insensitive_handlers (ModestMsgEditWindow *window)
+static void
+text_buffer_can_redo (GtkTextBuffer *buffer, gboolean can_redo, ModestMsgEditWindow *window)
{
- ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
- GtkWidget *widget;
-
- widget = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar/ToolbarSend");
- g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (send_insensitive_press), window);
- widget = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar/ActionsBold");
- g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (style_insensitive_press), window);
- widget = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar/ActionsItalics");
- g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (style_insensitive_press), window);
- widget = priv->font_color_button;
- g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (style_insensitive_press), window);
- widget = priv->font_size_toolitem;
- g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (style_insensitive_press), window);
- widget = priv->font_face_toolitem;
- g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (style_insensitive_press), window);
+ priv->can_redo = can_redo;
}
-static void
-text_buffer_can_undo (GtkTextBuffer *buffer, gboolean can_undo, ModestMsgEditWindow *window)
+gboolean
+modest_msg_edit_window_can_undo (ModestMsgEditWindow *window)
{
- ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
- GtkAction *action;
+ ModestMsgEditWindowPrivate *priv;
+ g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window), FALSE);
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
- action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/UndoMenu");
- gtk_action_set_sensitive (action, can_undo);
+ return priv->can_undo;
}
-static void
-text_buffer_can_redo (GtkTextBuffer *buffer, gboolean can_redo, ModestMsgEditWindow *window)
+gboolean
+modest_msg_edit_window_can_redo (ModestMsgEditWindow *window)
{
- ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
- GtkAction *action;
+ ModestMsgEditWindowPrivate *priv;
+ g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window), FALSE);
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
- action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/RedoMenu");
- gtk_action_set_sensitive (action, can_redo);
+ return priv->can_redo;
}
+
static void
text_buffer_delete_images_by_id (GtkTextBuffer *buffer, const gchar * image_id)
{
gpointer userdata)
{
- update_dimmed (MODEST_MSG_EDIT_WINDOW (userdata));
+ modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (userdata));
return FALSE;
}
recpt_field_changed (GtkTextBuffer *buffer,
ModestMsgEditWindow *editor)
{
- update_send_dimming (editor);
+ modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (editor));
}
static void
body_changed (GtkTextBuffer *buffer, ModestMsgEditWindow *editor)
{
- update_send_dimming (editor);
-}
-
-static void
-send_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor)
-{
- ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (editor);
- const gchar *subject = gtk_entry_get_text (GTK_ENTRY (priv->subject_field));
- if (message_is_empty(editor) || (subject == NULL || subject[0] == '\0')) {
- hildon_banner_show_information (NULL, NULL, _("mcen_ib_subject_or_body_not_modified"));
- } else {
- hildon_banner_show_information (NULL, NULL, _("mcen_ib_add_recipients_first"));
- }
-}
-
-static void
-style_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor)
-{
- gboolean rich_text, editor_focused;
-
- ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (editor);
- rich_text = wp_text_buffer_is_rich_text (WP_TEXT_BUFFER (priv->text_buffer));
- editor_focused = gtk_widget_is_focus (priv->msg_body);
-
- if (!rich_text)
- hildon_banner_show_information (NULL, NULL, _("mcen_ib_item_unavailable_plaintext"));
- else if (!editor_focused)
- hildon_banner_show_information (NULL, NULL, _("mcen_ib_move_cursor_to_message"));
+ modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (editor));
}
-static void
-reset_modified (ModestMsgEditWindow *editor)
+void
+modest_msg_edit_window_reset_modified (ModestMsgEditWindow *editor)
{
ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (editor);
GtkTextBuffer *buffer;
modest_msg_edit_window_offer_attach_file (window);
}
+const gchar *
+modest_msg_edit_window_get_clipboard_text (ModestMsgEditWindow *win)
+{
+ ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (win);
+
+ return priv->clipboard_text;
+}
+
static void
modest_msg_edit_window_clipboard_owner_change (GtkClipboard *clipboard,
GdkEvent *event,
ModestMsgEditWindow *window)
{
+ ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+ GtkClipboard *selection_clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+ gchar *text = NULL;
+ if (!GTK_WIDGET_VISIBLE (window))
+ return;
+
+ text = gtk_clipboard_wait_for_text (selection_clipboard);
+
+ if (priv->clipboard_text != NULL) {
+ g_free (priv->clipboard_text);
+ }
+ priv->clipboard_text = text;
+
+ modest_window_check_dimming_rules_group (MODEST_WINDOW (window), "ModestClipboardDimmingRules");
+}
+static void
+subject_field_move_cursor (GtkEntry *entry,
+ GtkMovementStep step,
+ gint a1,
+ gboolean a2,
+ gpointer window)
+{
if (!GTK_WIDGET_VISIBLE (window))
return;
- update_remove_attachment_dimming (window);
- update_copy_cut_dimming (window);
- update_paste_dimming (window);
+ modest_window_check_dimming_rules_group (MODEST_WINDOW (window), "ModestClipboardDimmingRules");
}
static void
ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
update_window_title (window);
gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
- update_send_dimming (window);
+ modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
}
static void
GString *result = g_string_new ("");
gchar *current;
gint result_len = 0;
+ const gchar *entry_text = NULL;
+ gint old_length;
+
+ entry_text = gtk_entry_get_text (GTK_ENTRY (editable));
+ old_length = g_utf8_strlen (entry_text, -1);
for (current = new_text; current != NULL && *current != '\0'; current = g_utf8_next_char (current)) {
gunichar c = g_utf8_get_char_validated (current, 8);
if (MIN (result_len, 1000) != g_utf8_strlen (new_text, 1000)) {
g_signal_stop_emission_by_name (G_OBJECT (editable), "insert-text");
if (result_len > 0)
+ {
+ /* Prevent endless recursion */
+ g_signal_handlers_block_by_func(G_OBJECT(editable), G_CALLBACK(subject_field_insert_text), window);
g_signal_emit_by_name (editable, "insert-text",
- (gpointer) result->str, (gpointer) strlen (result->str),
+ (gpointer) result->str, (gpointer) result->len,
(gpointer) position, (gpointer) window);
+ g_signal_handlers_unblock_by_func(G_OBJECT(editable), G_CALLBACK(subject_field_insert_text), window);
+ }
+ }
+
+ if (result_len + old_length > 1000) {
+ hildon_banner_show_information (GTK_WIDGET (window), NULL,
+ dgettext("hildon-common-strings",
+ "ckdg_ib_maximum_characters_reached"));
}
g_string_free (result, TRUE);
gtk_toggle_action_set_active (toggle, FALSE);
}
-static void
-update_remove_attachment_dimming (ModestMsgEditWindow *window)
-{
- ModestWindowPrivate *parent_priv;
- ModestMsgEditWindowPrivate *priv;
- GtkAction *action;
- GList *selected_attachments = NULL;
- gint n_att_selected = 0;
-
- priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
- parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
-
- selected_attachments = modest_attachments_view_get_selection (
- MODEST_ATTACHMENTS_VIEW (priv->attachments_view));
- n_att_selected = g_list_length (selected_attachments);
- g_list_free (selected_attachments);
-
- action = gtk_ui_manager_get_action (
- parent_priv->ui_manager,
- "/MenuBar/AttachmentsMenu/RemoveAttachmentsMenu");
- gtk_action_set_sensitive (action, n_att_selected == 1);
-}
-
-static void
-update_copy_cut_dimming (ModestMsgEditWindow *window)
-{
- ModestWindowPrivate *parent_priv = NULL;
- ModestMsgEditWindowPrivate *priv = NULL;
- GtkClipboard *clipboard = NULL;
- GtkAction *action = NULL;
- gboolean has_selection = FALSE;
- GtkWidget *focused = NULL;
- gchar *selection = NULL;
-
- priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
- parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
- clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
- focused = gtk_window_get_focus (GTK_WINDOW (window));
-
- has_selection = gtk_clipboard_wait_for_targets (clipboard, NULL, NULL);
-
- action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/CutMenu");
- 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, (has_selection) && (!MODEST_IS_ATTACHMENTS_VIEW (focused)));
-
- if (selection != NULL)
- g_free(selection);
-}
-
-static void
-update_paste_dimming (ModestMsgEditWindow *window)
-{
- ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
- GtkAction *action = NULL;
- GtkClipboard *clipboard = NULL;
- ModestEmailClipboard *e_clipboard;
- GtkWidget *focused;
- gboolean active;
-
- focused = gtk_window_get_focus (GTK_WINDOW (window));
-
- e_clipboard = modest_runtime_get_email_clipboard ();
- if (!modest_email_clipboard_cleared (e_clipboard)) {
- active = TRUE;
- } else {
- clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
- active = gtk_clipboard_wait_is_text_available (clipboard);
- }
-
- if (active) {
- if (MODEST_IS_ATTACHMENTS_VIEW (focused))
- active = FALSE;
- }
-
- action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/PasteMenu");
- gtk_action_set_sensitive (action, active);
-
-}
-
-static void
-update_select_all_dimming (ModestMsgEditWindow *window)
-{
- GtkWidget *focused;
- gboolean dimmed = FALSE;
- GtkAction *action;
- ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
-
- focused = gtk_window_get_focus (GTK_WINDOW (window));
- if (GTK_IS_ENTRY (focused)) {
- const gchar *current_text;
- current_text = gtk_entry_get_text (GTK_ENTRY (focused));
- dimmed = ((current_text == NULL) || (current_text[0] == '\0'));
- } else if (GTK_IS_TEXT_VIEW (focused)) {
- GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused));
- dimmed = (gtk_text_buffer_get_char_count (buffer) < 1);
- } else if (MODEST_IS_ATTACHMENTS_VIEW (focused)) {
- dimmed = FALSE;
- }
- action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/SelectAllMenu");
- gtk_action_set_sensitive (action, !dimmed);
-}
-
-static void
-update_zoom_dimming (ModestMsgEditWindow *window)
-{
- GtkWidget *focused;
- gboolean dimmed = FALSE;
- GtkAction *action;
- ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
-
- focused = gtk_window_get_focus (GTK_WINDOW (window));
- dimmed = ! WP_IS_TEXT_VIEW (focused);
- action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ZoomMenu");
- gtk_action_set_sensitive (action, !dimmed);
-}
-
-static void
-update_send_dimming (ModestMsgEditWindow *window)
-{
- ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
- ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
- GtkTextBuffer *to_buffer, *cc_buffer, *bcc_buffer;
- const gchar *subject;
- gboolean dim = FALSE;
- GtkAction *action;
-
- to_buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->to_field));
- cc_buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->cc_field));
- bcc_buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->bcc_field));
- subject = gtk_entry_get_text (GTK_ENTRY (priv->subject_field));
-
- dim = ((gtk_text_buffer_get_char_count (to_buffer) +
- gtk_text_buffer_get_char_count (cc_buffer) +
- gtk_text_buffer_get_char_count (bcc_buffer)) == 0)
- || (subject == NULL || subject[0] == '\0')
- || message_is_empty(window);
-
- action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ToolbarSend");
- gtk_action_set_sensitive (action, !dim);
- action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EmailMenu/SendMenu");
- gtk_action_set_sensitive (action, !dim);
-}
-
-static void
-edit_menu_activated (GtkAction *action,
- gpointer userdata)
-{
- ModestMsgEditWindow *window = MODEST_MSG_EDIT_WINDOW (userdata);
-
- update_select_all_dimming (window);
- update_copy_cut_dimming (window);
- update_paste_dimming (window);
-}
-static void
-view_menu_activated (GtkAction *action,
- gpointer userdata)
-{
- ModestMsgEditWindow *window = MODEST_MSG_EDIT_WINDOW (userdata);
-
- update_zoom_dimming (window);
-}
-
gboolean
modest_msg_edit_window_get_sent (ModestMsgEditWindow *window)
{
ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
if (priv->draft_msg != NULL) {
- header = tny_msg_get_header (priv->draft_msg);
- if (TNY_IS_HEADER (header)) {
- modest_window_mgr_unregister_header (mgr, header);
- }
+ modest_window_mgr_unregister_window (mgr, MODEST_WINDOW (window));
g_object_unref (priv->draft_msg);
}
if (draft != NULL) {
g_object_ref (draft);
header = tny_msg_get_header (draft);
- if (TNY_IS_HEADER (header))
- modest_window_mgr_register_header (mgr, header);
if (priv->msg_uid) {
g_free (priv->msg_uid);
priv->msg_uid = NULL;
}
priv->msg_uid = modest_tny_folder_get_header_unique_id (header);
+ if (GTK_WIDGET_REALIZED (window))
+ modest_window_mgr_register_window (mgr, MODEST_WINDOW (window));
}
priv->draft_msg = draft;
if (tag == NULL+13) return;
g_object_get (G_OBJECT (tag), "name", &tag_name, NULL);
if ((tag_name != NULL) && (g_str_has_prefix (tag_name, "image-tag-replace-"))) {
- replace_with_attachments (window, priv->attachments);
+ replace_with_images (window, priv->images);
}
}
return priv->msg_uid;
}
+
+GtkWidget *
+modest_msg_edit_window_get_child_widget (ModestMsgEditWindow *win,
+ ModestMsgEditWindowWidgetType widget_type)
+{
+ ModestMsgEditWindowPrivate *priv;
+
+ g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (win), NULL);
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (win);
+
+ switch (widget_type) {
+ case MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_BODY:
+ return priv->msg_body;
+ break;
+ case MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_TO:
+ return priv->to_field;
+ break;
+ case MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_CC:
+ return priv->cc_field;
+ break;
+ case MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_BCC:
+ return priv->bcc_field;
+ break;
+ case MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_SUBJECT:
+ return priv->subject_field;
+ break;
+ case MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_ATTACHMENTS:
+ return priv->attachments_view;
+ break;
+ default:
+ return NULL;
+ }
+}
+
+static void
+remove_tags (WPTextBuffer *buffer)
+{
+ GtkTextIter start, end;
+
+ gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &start);
+ gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (buffer), &end);
+
+ 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));
+ }
+}