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,
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;
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)
-{
- ModestPair *account_pair = NULL;
- gchar *from;
- TnyHeader *header;
-
- g_return_val_if_fail (transports, NULL);
- g_return_val_if_fail (msg, NULL);
-
- header = tny_msg_get_header (msg);
-
- if (header != NULL && (from = tny_header_dup_from (header))) {
- GSList *iter;
- char *from_addr;
-
- from_addr = modest_text_utils_get_email_address (from);
- g_free (from);
- 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 (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_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->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);
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);
}
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);
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;
* 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) {
+ 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);
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:
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);
mime_type = gnome_vfs_file_info_get_mime_type (info);
mime_part = tny_platform_factory_new_mime_part
(modest_runtime_get_platform_factory ());
+
+ /* 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) {
g_object_unref (mime_part);
gnome_vfs_file_info_unref (info);
- return;
+ return 0;
}
tny_mime_part_construct (mime_part, stream, mime_type, "base64");
g_object_unref (mime_part);
gnome_vfs_file_info_unref (info);
}
+
+ return size;
}
void
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) {
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,
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)