#include <tny-account-store.h>
#include <tny-fs-stream.h>
#include <tny-vfs-stream.h>
+#include <tny-camel-mem-stream.h>
#include <config.h>
static void text_buffer_apply_tag (GtkTextBuffer *buffer, GtkTextTag *tag,
GtkTextIter *start, GtkTextIter *end,
gpointer userdata);
-static void text_buffer_insert_text (GtkTextBuffer *buffer,
- GtkTextIter *location,
- gchar *text,
- gint len,
- 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 subject_field_insert_text (GtkEditable *editable,
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,
void vadj_changed (GtkAdjustment *adj,
ModestMsgEditWindow *window);
-static ModestPair *find_transport_from_message_sender (ModestPairList *transports,
- TnyMsg *msg);
-
-
-
-
static void DEBUG_BUFFER (WPTextBuffer *buffer)
{
#ifdef DEBUG
ModestPairList *from_field_protos;
GtkWidget *from_field;
- const gchar *original_account_name;
+ gchar *original_account_name;
GtkWidget *to_field;
GtkWidget *cc_field;
GtkWidget *find_toolbar;
gchar *last_search;
+ GtkWidget *font_dialog;
+
GtkWidget *scroll;
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;
priv->scroll_drag_timeout_id = 0;
priv->last_upper = 0.0;
+ priv->font_dialog = NULL;
+
modest_window_mgr_register_help_id (modest_runtime_get_window_mgr(),
GTK_WINDOW(obj),"applications_email_editor");
return transports;
}
-/**
- * Search an (account, address) ModestPairList for a pair whose
- * address matches the one in the From: header of a TnyMsg
- *
- * @result: A ModestPair * with a matching address, or NULL if none found
- */
-static ModestPair *
-find_transport_from_message_sender (ModestPairList *transports, TnyMsg *msg)
-{
- g_return_val_if_fail (transports, NULL);
- g_return_val_if_fail (msg, NULL);
-
- ModestPair *account_pair = NULL;
- TnyHeader *header = tny_msg_get_header (msg);
-
- if (header != NULL && tny_header_get_from (header)) {
- char *from_addr = modest_text_utils_get_email_address (tny_header_get_from (header));
- GSList *iter;
- for (iter = transports; iter && !account_pair; iter = iter->next) {
- ModestPair *pair = (ModestPair *) iter->data;
- char *account_addr = modest_text_utils_get_email_address ((char *) pair->second);
- if (account_addr && !strcasecmp(from_addr, account_addr)) {
- account_pair = pair;
- }
- g_free (account_addr);
- }
- g_free (from_addr);
- }
-
- if (header)
- g_object_unref (header);
-
- return account_pair;
-}
-
static void window_focus (GtkWindow *window,
GtkWidget *widget,
gpointer userdata)
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), "insert-text",
- G_CALLBACK (text_buffer_insert_text), obj);
+ g_signal_connect (G_OBJECT (priv->text_buffer), "modified-changed",
+ G_CALLBACK (body_changed), obj);
g_signal_connect (G_OBJECT (obj), "window-state-event",
G_CALLBACK (modest_msg_edit_window_window_state_event),
NULL);
call this function before */
modest_msg_edit_window_disconnect_signals (MODEST_WINDOW (obj));
+ if (priv->font_dialog != NULL) {
+ gtk_dialog_response (GTK_DIALOG (priv->font_dialog), GTK_RESPONSE_NONE);
+ }
+
if (priv->clipboard_text != NULL) {
g_free (priv->clipboard_text);
priv->clipboard_text = NULL;
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;
+ }
+ if (priv->original_account_name)
+ g_free (priv->original_account_name);
g_free (priv->msg_uid);
g_free (priv->last_search);
g_slist_free (priv->font_items_group);
}
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);
set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich)
{
TnyHeader *header;
- const gchar *to, *cc, *bcc, *subject;
+ gchar *to, *cc, *bcc, *subject;
gchar *body;
ModestMsgEditWindowPrivate *priv;
GtkTextIter iter;
priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
header = tny_msg_get_header (msg);
- to = tny_header_get_to (header);
- cc = tny_header_get_cc (header);
- bcc = tny_header_get_bcc (header);
- subject = tny_header_get_subject (header);
+ to = tny_header_dup_to (header);
+ cc = tny_header_dup_cc (header);
+ bcc = tny_header_dup_bcc (header);
+ subject = tny_header_dup_subject (header);
priority_flags = tny_header_get_priority (header);
if (to)
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) {
wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), FALSE);
/* Get the default format required from configuration */
- } else if (!modest_conf_get_bool (modest_runtime_get_conf (), MODEST_CONF_PREFER_FORMATTED_TEXT, NULL)) {
+ } else if (!preserve_is_rich && !modest_conf_get_bool (modest_runtime_get_conf (), MODEST_CONF_PREFER_FORMATTED_TEXT, NULL)) {
wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), FALSE);
}
}
g_object_unref (msg_folder);
}
+
+ g_free (to);
+ g_free (subject);
+ g_free (cc);
+ g_free (bcc);
}
static void
GObject *obj;
ModestWindowPrivate *parent_priv;
ModestMsgEditWindowPrivate *priv;
- ModestPair *account_pair = NULL;
ModestDimmingRulesGroup *menu_rules_group = NULL;
ModestDimmingRulesGroup *toolbar_rules_group = NULL;
ModestDimmingRulesGroup *clipboard_rules_group = NULL;
hildon_window_set_menu (HILDON_WINDOW (obj), GTK_MENU (parent_priv->menubar));
priv->from_field_protos = get_transports ();
modest_combo_box_set_pair_list (MODEST_COMBO_BOX (priv->from_field), priv->from_field_protos);
+ modest_combo_box_set_active_id (MODEST_COMBO_BOX (priv->from_field), (gpointer) account_name);
modest_msg_edit_window_setup_toolbar (MODEST_MSG_EDIT_WINDOW (obj));
hildon_window_add_toolbar (HILDON_WINDOW (obj), GTK_TOOLBAR (priv->find_toolbar));
modest_window_set_active_account (MODEST_WINDOW(obj), account_name);
- account_pair = find_transport_from_message_sender (priv->from_field_protos, msg);
- if (account_pair == NULL) {
- 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);
-
- priv->original_account_name = account_pair ? (const gchar *) account_pair->first : NULL;
+ priv->original_account_name = (account_name) ? g_strdup (account_name) : NULL;
parent_priv->ui_dimming_manager = modest_ui_dimming_manager_new ();
menu_rules_group = modest_dimming_rules_group_new (MODEST_DIMMING_RULES_MENU, FALSE);
g_object_unref (menu_rules_group);
g_object_unref (toolbar_rules_group);
g_object_unref (clipboard_rules_group);
- 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));
"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;
}
wp_text_buffer_save_document (WP_TEXT_BUFFER(priv->text_buffer), get_formatted_data_cb, &string_buffer);
+ modest_text_utils_hyperlinkify (string_buffer);
+
gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
return g_string_free (string_buffer, FALSE);
-static TnyStream* create_stream_for_uri (const gchar* uri)
+static TnyStream*
+create_stream_for_uri (const gchar* uri)
{
if (!uri)
return NULL;
GnomeVFSHandle *handle = NULL;
GnomeVFSResult test = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ);
if (test == GNOME_VFS_OK) {
- /* Create the tinymail stream: */
- /* Presumably tinymai will call gnome_vfs_close (handle) later. */
- result = TNY_STREAM (tny_vfs_stream_new (handle));
+ TnyStream *vfssstream = TNY_STREAM (tny_vfs_stream_new (handle));
+ /* Streams over OBEX (Bluetooth) are not seekable but
+ * we expect them to be (we might need to read them
+ * several times). So if this is a Bluetooth URI just
+ * read the whole file into memory (this is not a fast
+ * protocol so we can assume that these files are not
+ * going to be very big) */
+ if ((g_ascii_strncasecmp (uri, "obex://", 7) == 0)||
+ (g_ascii_strncasecmp (uri, "upnpav://", 9) == 0)) {
+ TnyStream *memstream = tny_camel_mem_stream_new ();
+ tny_stream_write_to_stream (vfssstream, memstream);
+ g_object_unref (vfssstream);
+ result = memstream;
+ } else {
+ result = vfssstream;
+ }
}
return result;
modest_maemo_utils_setup_images_filechooser (GTK_FILE_CHOOSER (dialog));
+ modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
+ GTK_WINDOW (dialog));
+
response = gtk_dialog_run (GTK_DIALOG (dialog));
switch (response) {
case GTK_RESPONSE_OK:
GnomeVFSURI *vfs_uri;
guint64 stream_size;
+ gnome_vfs_close (handle);
vfs_uri = gnome_vfs_uri_new (uri);
escaped_filename = g_path_get_basename (gnome_vfs_uri_get_path (vfs_uri));
(modest_runtime_get_platform_factory ());
TnyStream *stream = create_stream_for_uri (uri);
+
+ if (stream == NULL) {
+
+ modest_platform_information_banner (NULL, NULL, dgettext("hildon-fm", "sfil_ib_opening_not_allowed"));
+
+ g_object_unref (mime_part);
+ gnome_vfs_file_info_unref (info);
+ continue;
+ }
+
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);
gint response = 0;
GSList *uris = NULL;
GSList *uri_node;
+ GnomeVFSFileSize total_size, allowed_size;
+ ModestMsgEditWindowPrivate *priv;
+ gint att_num;
+ guint64 att_size;
+
+ g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(window));
+
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+
+ if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
+ return;
dialog = hildon_file_chooser_dialog_new (GTK_WINDOW (window), GTK_FILE_CHOOSER_ACTION_OPEN);
gtk_window_set_title (GTK_WINDOW (dialog), _("mcen_ti_select_attachment_title"));
gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), TRUE);
+ modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog));
response = gtk_dialog_run (GTK_DIALOG (dialog));
switch (response) {
}
gtk_widget_destroy (dialog);
+ /* allowed size is the maximum size - what's already there */
+ modest_attachments_view_get_sizes (
+ MODEST_ATTACHMENTS_VIEW (priv->attachments_view),
+ &att_num, &att_size);
+ allowed_size = MODEST_MAX_ATTACHMENT_SIZE - att_size;
+
+ total_size = 0;
for (uri_node = uris; uri_node != NULL; uri_node = g_slist_next (uri_node)) {
+
const gchar *uri = (const gchar *) uri_node->data;
- modest_msg_edit_window_attach_file_one (window, uri);
+
+ total_size += modest_msg_edit_window_attach_file_one
+ (window, uri, allowed_size);
+
+ if (total_size > allowed_size) {
+ g_warning ("%s: total size: %u",
+ __FUNCTION__, (unsigned int)total_size);
+ break;
+ }
+
+ allowed_size -= total_size;
+
+
}
g_slist_foreach (uris, (GFunc) g_free, NULL);
g_slist_free (uris);
}
-void
-modest_msg_edit_window_attach_file_one (
- ModestMsgEditWindow *window,
- const gchar *uri)
+
+GnomeVFSFileSize
+modest_msg_edit_window_attach_file_one (ModestMsgEditWindow *window,
+ const gchar *uri,
+ GnomeVFSFileSize allowed_size)
+
{
GnomeVFSHandle *handle = NULL;
ModestMsgEditWindowPrivate *priv;
GnomeVFSResult result;
+ GnomeVFSFileSize size = 0;
- g_return_if_fail (window);
- g_return_if_fail (uri);
+ g_return_val_if_fail (window, 0);
+ g_return_val_if_fail (uri, 0);
priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
GnomeVFSFileInfo *info;
GnomeVFSURI *vfs_uri;
+ gnome_vfs_close (handle);
vfs_uri = gnome_vfs_uri_new (uri);
mime_type = gnome_vfs_file_info_get_mime_type (info);
mime_part = tny_platform_factory_new_mime_part
(modest_runtime_get_platform_factory ());
- stream = TNY_STREAM (tny_vfs_stream_new (handle));
- tny_mime_part_construct (mime_part, stream, mime_type, "base64");
+ /* try to get the attachment's size; this may fail for weird
+ * file systems, like obex, upnp... */
+ if (allowed_size != 0 &&
+ info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE) {
+ size = info->size;
+ if (size > allowed_size) {
+ g_warning ("%s: attachment too big", __FUNCTION__);
+ modest_platform_information_banner (NULL, NULL, dgettext("hildon-fm", "sfil_ib_opening_not_allowed"));
+ return 0;
+ }
+ } else
+ g_warning ("%s: could not get attachment size", __FUNCTION__);
+
+ stream = create_stream_for_uri (uri);
+
+ if (stream == NULL) {
+
+ modest_platform_information_banner (NULL, NULL, dgettext("hildon-fm", "sfil_ib_opening_not_allowed"));
+
+ g_object_unref (mime_part);
+ gnome_vfs_file_info_unref (info);
+ return 0;
+ }
+ tny_mime_part_construct (mime_part, stream, mime_type, "base64");
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);
g_object_unref (mime_part);
gnome_vfs_file_info_unref (info);
}
+
+ return size;
}
void
if (TNY_IS_MSG (part)) {
TnyHeader *header = tny_msg_get_header (TNY_MSG (part));
if (header) {
- filename = g_strdup (tny_header_get_subject (header));
+ filename = tny_header_dup_subject (header);
g_object_unref (header);
}
if (filename == NULL) {
filename = g_strdup ("");
}
message = g_strdup_printf (ngettext("emev_nc_delete_attachment", "emev_nc_delete_attachments",
- (tny_list_get_length (att_list) == 1)), filename);
+ tny_list_get_length (att_list)), filename);
g_free (filename);
confirmation_dialog = hildon_note_new_confirmation (GTK_WINDOW (window), message);
g_free (message);
g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
g_return_if_fail ((editor == NULL) || (MODEST_IS_RECPT_EDITOR (editor)));
+
+ /* we check for low-mem; in that case, show a warning, and don't allow
+ * for the addressbook
+ */
+ if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
+ return;
+
priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
if (editor == NULL) {
break;
}
modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
+ text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), window);
}
}
priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
dialog = hildon_font_selection_dialog_new (GTK_WINDOW (window), NULL);
+ modest_window_mgr_set_modal (modest_runtime_get_window_mgr(),
+ GTK_WINDOW(dialog));
/* First we get the currently selected font information */
wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), &oldfmt, TRUE);
NULL);
gtk_widget_show_all (dialog);
+ priv->font_dialog = dialog;
response = gtk_dialog_run (GTK_DIALOG (dialog));
+ priv->font_dialog = NULL;
if (response == GTK_RESPONSE_OK) {
g_object_get( dialog,
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,
g_string_free (result, TRUE);
}
-static void
-text_buffer_insert_text (GtkTextBuffer *buffer,
- GtkTextIter *iter,
- gchar *new_text,
- gint new_text_length,
- ModestMsgEditWindow *window)
-{
- GString *result = g_string_new ("");
- gchar *current;
- gint result_len = 0;
- gboolean changed = FALSE;
-
- for (current = new_text; current != NULL && *current != '\0'; current = g_utf8_next_char (current)) {
- gunichar c = g_utf8_get_char_validated (current, 8);
- /* Invalid unichar, stop */
- if (c == -1)
- break;
- /* a bullet */
- switch (c) {
- case 0x2022:
- result = g_string_append_c (result, ' ');
- changed = TRUE;
- break;
- default:
- result = g_string_append_unichar (result, c);
- }
- result_len++;
- }
-
- if (changed) {
- g_signal_stop_emission_by_name (G_OBJECT (buffer), "insert-text");
- g_signal_handlers_block_by_func(G_OBJECT(buffer), G_CALLBACK(text_buffer_insert_text), window);
- g_signal_emit_by_name (buffer, "insert-text",
- (gpointer) iter,
- (gpointer) result->str, (gpointer) result->len,
- (gpointer) window);
- g_signal_handlers_unblock_by_func(G_OBJECT(buffer), G_CALLBACK(text_buffer_insert_text), window);
- }
-
- g_string_free (result, TRUE);
-}
-
void
modest_msg_edit_window_toggle_find_toolbar (ModestMsgEditWindow *window,
gboolean show)