static void modest_msg_edit_window_clipboard_owner_change (GtkClipboard *clipboard,
GdkEvent *event,
ModestMsgEditWindow *window);
+static void modest_msg_edit_window_clipboard_owner_handle_change_in_idle (ModestMsgEditWindow *window);
static void subject_field_move_cursor (GtkEntry *entry,
GtkMovementStep step,
gint a1,
guint scroll_drag_timeout_id;
gdouble last_upper;
- gint last_cid;
+ gint next_cid;
TnyList *attachments;
TnyList *images;
guint64 images_size;
gulong clipboard_change_handler_id;
gulong default_clipboard_change_handler_id;
gulong account_removed_handler_id;
+ guint clipboard_owner_idle;
gchar *clipboard_text;
TnyMsg *draft_msg;
priv->images = TNY_LIST (tny_simple_list_new ());
priv->images_size = 0;
priv->images_count = 0;
- priv->last_cid = 0;
+ priv->next_cid = 0;
priv->cc_caption = NULL;
priv->bcc_caption = NULL;
priv->clipboard_change_handler_id = 0;
priv->default_clipboard_change_handler_id = 0;
priv->account_removed_handler_id = 0;
+ priv->clipboard_owner_idle = 0;
priv->clipboard_text = NULL;
priv->sent = FALSE;
gtk_text_buffer_end_user_action (buffer);
}
+static void
+cut_clipboard_check (GtkTextView *text_view,
+ gpointer userdata)
+{
+ GtkTextBuffer *buffer;
+
+ buffer = gtk_text_view_get_buffer (text_view);
+ if (!modest_text_utils_buffer_selection_is_valid (buffer)) {
+ g_signal_stop_emission_by_name ((gpointer )text_view, "cut-clipboard");
+ }
+}
+
+static void
+copy_clipboard_check (GtkTextView *text_view,
+ gpointer userdata)
+{
+ GtkTextBuffer *buffer;
+
+ buffer = gtk_text_view_get_buffer (text_view);
+ if (!modest_text_utils_buffer_selection_is_valid (buffer)) {
+ g_signal_stop_emission_by_name ((gpointer )text_view, "copy-clipboard");
+ }
+}
+
void vadj_changed (GtkAdjustment *adj,
ModestMsgEditWindow *window)
{
G_CALLBACK (text_buffer_can_redo), obj);
g_signal_connect (G_OBJECT (priv->text_buffer), "changed",
G_CALLBACK (body_changed), obj);
+ g_signal_connect (G_OBJECT (priv->text_buffer), "modified-changed",
+ G_CALLBACK (body_changed), obj);
g_signal_connect (G_OBJECT (priv->text_buffer), "insert-text",
G_CALLBACK (text_buffer_insert_text), obj);
g_signal_connect (G_OBJECT (obj), "window-state-event",
g_signal_connect (G_OBJECT (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD)), "owner-change",
G_CALLBACK (modest_msg_edit_window_clipboard_owner_change), obj);
+ g_signal_connect (G_OBJECT (priv->msg_body), "cut-clipboard", G_CALLBACK (cut_clipboard_check), NULL);
+ g_signal_connect (G_OBJECT (priv->msg_body), "copy-clipboard", G_CALLBACK (copy_clipboard_check), NULL);
+
}
static void
g_source_remove (priv->scroll_drag_timeout_id);
priv->scroll_drag_timeout_id = 0;
}
+ if (priv->clipboard_owner_idle > 0) {
+ g_source_remove (priv->clipboard_owner_idle);
+ priv->clipboard_owner_idle = 0;
+ }
g_free (priv->msg_uid);
g_free (priv->last_search);
g_slist_free (priv->font_items_group);
tny_stream_reset (TNY_STREAM (stream));
while (!tny_stream_is_eos (TNY_STREAM (stream))) {
+ GError *error = NULL;
unsigned char read_buffer[128];
gint readed;
readed = tny_stream_read (TNY_STREAM (stream), (char *) read_buffer, 128);
size += readed;
- if (!gdk_pixbuf_loader_write (loader, read_buffer, readed, NULL))
+ if (!gdk_pixbuf_loader_write (loader, read_buffer, readed, &error)) {
break;
+ }
}
pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
- g_object_ref (pixbuf);
+ if (pixbuf)
+ g_object_ref (pixbuf);
gdk_pixbuf_loader_close (loader, NULL);
g_object_unref (loader);
+ if (!pixbuf)
+ return NULL;
+
if (gdk_pixbuf_get_width (pixbuf) > IMAGE_MAX_WIDTH) {
GdkPixbuf *new_pixbuf;
gint new_height;
const gchar *mime_type = tny_mime_part_get_content_type (part);
if ((cid != NULL)&&(mime_type != NULL)) {
guint64 stream_size;
- TnyStream *stream = tny_mime_part_get_stream (part);
+ TnyStream *stream = tny_mime_part_get_decoded_stream (part);
GdkPixbuf *pixbuf = pixbuf_from_stream (stream, mime_type, &stream_size);
}
static void
-update_last_cid (ModestMsgEditWindow *self, TnyList *attachments)
+update_next_cid (ModestMsgEditWindow *self, TnyList *attachments)
{
TnyIterator *iter;
ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
if (cid != NULL) {
char *invalid = NULL;
gint int_cid = strtol (cid, &invalid, 10);
- if ((invalid != NULL) && (*invalid == '\0') && (int_cid > priv->last_cid)) {
- priv->last_cid = int_cid;
+ if ((invalid != NULL) && (*invalid == '\0') && (int_cid >= priv->next_cid)) {
+ priv->next_cid = int_cid + 1;
}
}
g_object_unref (part);
gtk_widget_show_all (priv->attachments_caption);
}
get_related_images (self, msg);
- update_last_cid (self, priv->attachments);
- update_last_cid (self, priv->images);
+ update_next_cid (self, priv->attachments);
+ update_next_cid (self, priv->images);
replace_with_images (self, priv->images);
if (preserve_is_rich && !is_html) {
gtk_text_buffer_get_start_iter (priv->text_buffer, &iter);
gtk_text_buffer_place_cursor (priv->text_buffer, &iter);
- modest_msg_edit_window_reset_modified (self);
+ modest_msg_edit_window_set_modified (self, FALSE);
modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (self));
modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (self));
g_object_unref (menu_rules_group);
g_object_unref (toolbar_rules_group);
g_object_unref (clipboard_rules_group);
- gtk_widget_show_all (GTK_WIDGET (obj));
- modest_msg_edit_window_clipboard_owner_change (NULL, NULL, MODEST_MSG_EDIT_WINDOW (obj));
-
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));
modest_window_check_dimming_rules_group (MODEST_WINDOW (obj), MODEST_DIMMING_RULES_CLIPBOARD);
priv->update_caption_visibility = TRUE;
- modest_msg_edit_window_reset_modified (MODEST_MSG_EDIT_WINDOW (obj));
+ modest_msg_edit_window_set_modified (MODEST_MSG_EDIT_WINDOW (obj), FALSE);
/* Track account-removed signal, this window should be closed
in the case we're creating a mail associated to the account
"account_removed",
G_CALLBACK(on_account_removed),
obj);
-
+
+ modest_msg_edit_window_clipboard_owner_handle_change_in_idle (MODEST_MSG_EDIT_WINDOW (obj));
+
return (ModestWindow*) obj;
}
switch (buffer_format->justification)
{
case GTK_JUSTIFY_LEFT:
- action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentLeftMenu");
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentMenu/AlignmentLeftMenu");
break;
case GTK_JUSTIFY_CENTER:
- action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentCenterMenu");
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentMenu/AlignmentCenterMenu");
break;
case GTK_JUSTIFY_RIGHT:
- action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentRightMenu");
+ action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentMenu/AlignmentRightMenu");
break;
default:
break;
TnyStream *stream = create_stream_for_uri (uri);
tny_mime_part_construct (mime_part, stream, mime_type, "base64");
- content_id = g_strdup_printf ("%d", priv->last_cid);
+ content_id = g_strdup_printf ("%d", priv->next_cid);
tny_mime_part_set_content_id (mime_part, content_id);
g_free (content_id);
- priv->last_cid++;
+ priv->next_cid++;
basename = g_path_get_basename (filename);
tny_mime_part_set_filename (mime_part, basename);
g_object_unref (stream);
- content_id = g_strdup_printf ("%d", priv->last_cid);
+ content_id = g_strdup_printf ("%d", priv->next_cid);
tny_mime_part_set_content_id (mime_part, content_id);
g_free (content_id);
- priv->last_cid++;
+ priv->next_cid++;
basename = g_path_get_basename (filename);
tny_mime_part_set_filename (mime_part, basename);
break;
}
modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
+ text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), window);
}
}
}
void
-modest_msg_edit_window_reset_modified (ModestMsgEditWindow *editor)
+modest_msg_edit_window_set_modified (ModestMsgEditWindow *editor,
+ gboolean modified)
{
ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (editor);
GtkTextBuffer *buffer;
buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR(priv->to_field));
- gtk_text_buffer_set_modified (buffer, FALSE);
+ gtk_text_buffer_set_modified (buffer, modified);
buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR(priv->cc_field));
- gtk_text_buffer_set_modified (buffer, FALSE);
+ gtk_text_buffer_set_modified (buffer, modified);
buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR(priv->bcc_field));
- gtk_text_buffer_set_modified (buffer, FALSE);
- gtk_text_buffer_set_modified (priv->text_buffer, FALSE);
+ gtk_text_buffer_set_modified (buffer, modified);
+ gtk_text_buffer_set_modified (priv->text_buffer, modified);
}
gboolean
if (!GTK_WIDGET_VISIBLE (window))
return;
+ g_object_ref (window);
text = gtk_clipboard_wait_for_text (selection_clipboard);
if (priv->clipboard_text != NULL) {
}
priv->clipboard_text = text;
- modest_window_check_dimming_rules_group (MODEST_WINDOW (window), MODEST_DIMMING_RULES_CLIPBOARD);
+ if (GTK_WIDGET_VISIBLE (window)) {
+ modest_window_check_dimming_rules_group (MODEST_WINDOW (window), MODEST_DIMMING_RULES_CLIPBOARD);
+ }
+ g_object_unref (window);
+}
+
+static gboolean clipboard_owner_change_idle (gpointer userdata)
+{
+ ModestMsgEditWindow *window = (ModestMsgEditWindow *) userdata;
+ ModestMsgEditWindowPrivate *priv;
+
+ gdk_threads_enter ();
+ g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window), FALSE);
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+
+ priv->clipboard_owner_idle = 0;
+ modest_msg_edit_window_clipboard_owner_change (NULL, NULL, window);
+ gdk_threads_leave ();
+
+ return FALSE;
}
+
+static void
+modest_msg_edit_window_clipboard_owner_handle_change_in_idle (ModestMsgEditWindow *window)
+{
+ ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+ if (priv->clipboard_owner_idle == 0) {
+ priv->clipboard_owner_idle = g_idle_add (clipboard_owner_change_idle, window);
+ }
+}
+
static void
subject_field_move_cursor (GtkEntry *entry,
GtkMovementStep step,