#include <modest-wp-text-view.h>
#include <wptextbuffer.h>
#include <modest-scrollable.h>
+#include <modest-isearch-toolbar.h>
#include <hildon/hildon-touch-selector.h>
#include <hildon/hildon-picker-dialog.h>
#include "modest-msg-edit-window-ui-dimming.h"
static void update_window_title (ModestMsgEditWindow *window);
/* Find toolbar */
-static void modest_msg_edit_window_find_toolbar_search (GtkWidget *widget,
- ModestMsgEditWindow *window);
-static void modest_msg_edit_window_find_toolbar_close (GtkWidget *widget,
- ModestMsgEditWindow *window);
+static void modest_msg_edit_window_isearch_toolbar_search (GtkWidget *widget,
+ ModestMsgEditWindow *window);
+static void modest_msg_edit_window_isearch_toolbar_close (GtkWidget *widget,
+ ModestMsgEditWindow *window);
static gboolean gtk_text_iter_forward_search_insensitive (const GtkTextIter *iter,
const gchar *str,
GtkTextIter *match_start,
gint current_size_index;
GtkWidget *size_tool_button_label;
- GtkWidget *find_toolbar;
+ GtkWidget *isearch_toolbar;
gchar *last_search;
GtkWidget *font_dialog;
priv->priority_flags = 0;
- priv->find_toolbar = NULL;
+ priv->isearch_toolbar = NULL;
priv->last_search = NULL;
priv->draft_msg = NULL;
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), "search", G_CALLBACK (modest_msg_edit_window_find_toolbar_search), obj);
- g_signal_connect (G_OBJECT (priv->find_toolbar), "close", G_CALLBACK (modest_msg_edit_window_find_toolbar_close), obj);
+ g_signal_connect (G_OBJECT (priv->isearch_toolbar), "isearch-search",
+ G_CALLBACK (modest_msg_edit_window_isearch_toolbar_search), obj);
+ g_signal_connect (G_OBJECT (priv->isearch_toolbar), "isearch-close",
+ G_CALLBACK (modest_msg_edit_window_isearch_toolbar_close), obj);
priv->clipboard_change_handler_id =
g_signal_connect (G_OBJECT (gtk_clipboard_get (GDK_SELECTION_PRIMARY)), "owner-change",
priv->subject_box = gtk_hbox_new (FALSE, MODEST_MARGIN_NONE);
priv->priority_icon = gtk_image_new ();
gtk_box_pack_start (GTK_BOX (priv->subject_box), priv->priority_icon, FALSE, FALSE, 0);
- priv->subject_field = hildon_entry_new (MODEST_EDITABLE_SIZE);
+ priv->subject_field = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
gtk_entry_set_max_length (GTK_ENTRY (priv->subject_field) ,SUBJECT_MAX_LENGTH);
g_object_set (G_OBJECT (priv->subject_field), "truncate-multiline", TRUE, NULL);
- hildon_entry_set_placeholder ((HildonEntry *) priv->subject_field, _("mail_va_no_subject"));
+ modest_entry_set_hint (priv->subject_field, _("mail_va_no_subject"));
hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->subject_field),
HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
gtk_box_pack_start (GTK_BOX (priv->subject_box), priv->subject_field, TRUE, TRUE, 0);
#endif
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);
+ priv->isearch_toolbar = modest_toolkit_factory_create_isearch_toolbar (modest_runtime_get_toolkit_factory (),
+ NULL);
+ gtk_widget_set_no_show_all (priv->isearch_toolbar, TRUE);
/* g_signal_connect (G_OBJECT (obj), "key_pressed", G_CALLBACK (on_key_pressed), NULL) */
gtk_widget_hide (priv->cc_caption);
field_view_set = FALSE;
}
- hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->cc_button), field_view_set);
+ modest_togglable_set_active (priv->cc_button, field_view_set);
field_view_set = TRUE;
if (bcc) {
gtk_widget_hide (priv->bcc_caption);
field_view_set = FALSE;
}
- hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->bcc_button), field_view_set);
+ modest_togglable_set_active (priv->bcc_button, field_view_set);
if (subject)
hildon_touch_selector_get_current_text
(HILDON_TOUCH_SELECTOR (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (priv->from_field)))));
modest_msg_edit_window_setup_toolbar (MODEST_MSG_EDIT_WINDOW (obj));
- modest_window_add_toolbar (MODEST_WINDOW (obj), GTK_TOOLBAR (priv->find_toolbar));
+ modest_window_add_toolbar (MODEST_WINDOW (obj), GTK_TOOLBAR (priv->isearch_toolbar));
/* Init window */
connect_signals (MODEST_MSG_EDIT_WINDOW(obj));
gpointer userdata)
{
ModestMsgEditWindowPrivate *priv;
- GdkColor *new_color;
+ GdkColor new_color;
+
priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
- hildon_color_button_get_color (HILDON_COLOR_BUTTON(priv->font_color_button), new_color);
+ hildon_color_button_get_color (HILDON_COLOR_BUTTON(priv->font_color_button), &new_color);
- 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);
gtk_window_set_focus (GTK_WINDOW (window), priv->msg_body);
}
/* Check names */
g_object_ref (window);
- if (!modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->to_field), &address_list)) {
+ if (!modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->to_field),
+ (add_to_addressbook) ? &address_list : NULL)) {
modest_recpt_editor_grab_focus (MODEST_RECPT_EDITOR (priv->to_field));
g_object_unref (window);
return FALSE;
}
- if (!modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->cc_field), &address_list)) {
+ if (!modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->cc_field),
+ (add_to_addressbook) ? &address_list : NULL)) {
modest_recpt_editor_grab_focus (MODEST_RECPT_EDITOR (priv->cc_field));
g_object_unref (window);
return FALSE;
}
- if (!modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->bcc_field), &address_list)) {
+ if (!modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->bcc_field),
+ (add_to_addressbook) ? &address_list : NULL)) {
modest_recpt_editor_grab_focus (MODEST_RECPT_EDITOR (priv->bcc_field));
g_object_unref (window);
return FALSE;
}
/* Add contacts to address book */
- if (address_list)
+ if (add_to_addressbook && address_list)
modest_address_book_add_address_list (address_list);
if (!modest_recpt_editor_has_focus (MODEST_RECPT_EDITOR (priv->cc_field)) &&
}
+void
+modest_msg_edit_window_add_to_contacts (ModestMsgEditWindow *self)
+{
+ GSList *recipients = NULL;
+ ModestMsgEditWindowPrivate *priv;
+ gchar *joined, *after_remove, *to, *cc, *bcc;
+
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
+
+ /* First of all check names */
+ if (!modest_msg_edit_window_check_names (self, FALSE))
+ return;
+
+ if (!modest_msg_edit_window_has_pending_addresses (self))
+ return;
+
+ /* Don't add the from obviously */
+ to = g_strdup (modest_recpt_editor_get_recipients ((ModestRecptEditor *) priv->to_field));
+ cc = g_strdup (modest_recpt_editor_get_recipients ((ModestRecptEditor *) priv->cc_field));
+ bcc = g_strdup (modest_recpt_editor_get_recipients ((ModestRecptEditor *) priv->bcc_field));
+
+ joined = modest_text_utils_join_addresses (NULL, to, cc, bcc);
+ g_free (to);
+ g_free (cc);
+ g_free (bcc);
+
+ after_remove = modest_text_utils_remove_duplicate_addresses (joined);
+ g_free (joined);
+
+ recipients = modest_text_utils_split_addresses_list (after_remove);
+ g_free (after_remove);
+
+ if (recipients) {
+ /* Offer the user to add recipients to the address book */
+ modest_address_book_add_address_list_with_selector (recipients, (GtkWindow *) self);
+ g_slist_foreach (recipients, (GFunc) g_free, NULL); g_slist_free (recipients);
+ }
+}
+
static void
modest_msg_edit_window_add_attachment_clicked (GtkButton *button,
ModestMsgEditWindow *window)
}
void
-modest_msg_edit_window_toggle_find_toolbar (ModestMsgEditWindow *window,
- gboolean show)
+modest_msg_edit_window_toggle_isearch_toolbar (ModestMsgEditWindow *window,
+ gboolean show)
{
ModestMsgEditWindowPrivate *priv = NULL;
g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
- gtk_widget_set_no_show_all (priv->find_toolbar, FALSE);
+ gtk_widget_set_no_show_all (priv->isearch_toolbar, FALSE);
if (show) {
- gtk_widget_show_all (priv->find_toolbar);
- hildon_find_toolbar_highlight_entry (HILDON_FIND_TOOLBAR (priv->find_toolbar), TRUE);
+ gtk_widget_show_all (priv->isearch_toolbar);
+ modest_isearch_toolbar_highlight_entry (MODEST_ISEARCH_TOOLBAR (priv->isearch_toolbar), TRUE);
} else {
- gtk_widget_hide_all (priv->find_toolbar);
+ gtk_widget_hide_all (priv->isearch_toolbar);
gtk_widget_grab_focus (priv->msg_body);
}
}
static void
-modest_msg_edit_window_find_toolbar_search (GtkWidget *widget,
- ModestMsgEditWindow *window)
+modest_msg_edit_window_isearch_toolbar_search (GtkWidget *widget,
+ ModestMsgEditWindow *window)
{
- gchar *current_search = NULL;
+ const gchar *current_search = NULL;
ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
gboolean result;
GtkTextIter selection_start, selection_end;
return;
}
- g_object_get (G_OBJECT (widget), "prefix", ¤t_search, NULL);
+ current_search = modest_isearch_toolbar_get_search (MODEST_ISEARCH_TOOLBAR (widget));
if ((current_search == NULL) || (strcmp (current_search, "") == 0)) {
- g_free (current_search);
g_free (priv->last_search);
priv->last_search = NULL;
/* Information banner about empty search */
g_free (priv->last_search);
priv->last_search = NULL;
}
- g_free (current_search);
}
gboolean
}
static void
-modest_msg_edit_window_find_toolbar_close (GtkWidget *widget,
- ModestMsgEditWindow *window)
+modest_msg_edit_window_isearch_toolbar_close (GtkWidget *widget,
+ ModestMsgEditWindow *window)
{
- modest_msg_edit_window_toggle_find_toolbar (window, FALSE);
+ modest_msg_edit_window_toggle_isearch_toolbar (window, FALSE);
}
void
}
static void
-on_cc_button_toggled (HildonCheckButton *button,
+on_cc_button_toggled (GtkWidget *button,
ModestMsgEditWindow *window)
{
g_return_if_fail (MODEST_MSG_EDIT_WINDOW (window));
modest_msg_edit_window_show_cc (MODEST_MSG_EDIT_WINDOW (window),
- hildon_check_button_get_active (button));
+ modest_togglable_get_active (button));
}
static void
-on_bcc_button_toggled (HildonCheckButton *button,
+on_bcc_button_toggled (GtkWidget *button,
ModestMsgEditWindow *window)
{
g_return_if_fail (MODEST_MSG_EDIT_WINDOW (window));
modest_msg_edit_window_show_bcc (MODEST_MSG_EDIT_WINDOW (window),
- hildon_check_button_get_active (button));
+ modest_togglable_get_active (button));
}
static void
priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
/* Settings menu buttons */
- modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_editor_checknames"), NULL,
- APP_MENU_CALLBACK (modest_ui_actions_on_check_names),
- NULL);
- modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_undo"), "<Ctrl>z",
- APP_MENU_CALLBACK (modest_ui_actions_on_undo),
- MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_undo));
+ modest_window_add_to_menu (MODEST_WINDOW (self), _("mcen_me_editor_checknames"), NULL,
+ MODEST_WINDOW_MENU_CALLBACK (modest_ui_actions_on_check_names),
+ NULL);
+ modest_window_add_to_menu (MODEST_WINDOW (self), _("mcen_me_viewer_addtocontacts"), NULL,
+ MODEST_WINDOW_MENU_CALLBACK (modest_ui_actions_add_to_contacts),
+ MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_add_to_contacts));
+ modest_window_add_to_menu (MODEST_WINDOW (self), _("mcen_me_inbox_undo"), "<Ctrl>z",
+ MODEST_WINDOW_MENU_CALLBACK (modest_ui_actions_on_undo),
+ MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_undo));
priv->cc_button = hildon_check_button_new (0);
gtk_button_set_label (GTK_BUTTON (priv->cc_button), _("mcen_me_editor_showcc"));
hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->cc_button),
FALSE);
- modest_hildon2_window_add_button_to_menu (MODEST_HILDON2_WINDOW (self), GTK_BUTTON (priv->cc_button),
- NULL);
+ modest_window_add_item_to_menu (MODEST_WINDOW (self), priv->cc_button, NULL);
g_signal_connect (G_OBJECT (priv->cc_button), "toggled",
G_CALLBACK (on_cc_button_toggled), (gpointer) self);
- gtk_button_set_alignment (GTK_BUTTON (priv->cc_button), 0.5, 0.5);
- gtk_button_set_alignment (GTK_BUTTON (priv->cc_button), 0.5, 0.5);
- priv->bcc_button = hildon_check_button_new (0);
- gtk_button_set_label (GTK_BUTTON (priv->bcc_button), _("mcen_me_editor_showbcc"));
- hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->bcc_button),
- FALSE);
- modest_hildon2_window_add_button_to_menu (MODEST_HILDON2_WINDOW (self), GTK_BUTTON (priv->bcc_button),
- NULL);
+ priv->bcc_button = modest_toolkit_factory_create_check_menu (modest_runtime_get_toolkit_factory (),
+ _("mcen_me_editor_showbcc"));
+ modest_togglable_set_active (priv->bcc_button,
+ FALSE);
+ modest_window_add_item_to_menu (MODEST_WINDOW (self), priv->bcc_button,
+ NULL);
g_signal_connect (G_OBJECT (priv->bcc_button), "toggled",
G_CALLBACK (on_bcc_button_toggled), (gpointer) self);
- gtk_button_set_alignment (GTK_BUTTON (priv->bcc_button), 0.5, 0.5);
- gtk_button_set_alignment (GTK_BUTTON (priv->bcc_button), 0.5, 0.5);
-
- modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_editor_attach_inlineimage"), NULL,
- APP_MENU_CALLBACK (modest_ui_actions_on_insert_image),
- MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_set_style));
- modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_editor_add_attachment"), NULL,
- APP_MENU_CALLBACK (modest_msg_edit_window_add_attachment_clicked),
- NULL);
- modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_remove_attachments"), NULL,
- APP_MENU_CALLBACK (modest_ui_actions_on_remove_attachments),
- MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_editor_remove_attachment));
- modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_message_settings"), NULL,
- APP_MENU_CALLBACK (on_message_settings),
- NULL);
- modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_viewer_find"), "<Ctrl>f",
- APP_MENU_CALLBACK (modest_ui_actions_on_toggle_find_in_page),
- NULL);
+
+ modest_window_add_to_menu (MODEST_WINDOW (self), _("mcen_me_editor_attach_inlineimage"), NULL,
+ MODEST_WINDOW_MENU_CALLBACK (modest_ui_actions_on_insert_image),
+ MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_set_style));
+ modest_window_add_to_menu (MODEST_WINDOW (self), _("mcen_me_editor_add_attachment"), NULL,
+ MODEST_WINDOW_MENU_CALLBACK (modest_msg_edit_window_add_attachment_clicked),
+ NULL);
+ modest_window_add_to_menu (MODEST_WINDOW (self), _("mcen_me_inbox_remove_attachments"), NULL,
+ MODEST_WINDOW_MENU_CALLBACK (modest_ui_actions_on_remove_attachments),
+ MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_editor_remove_attachment));
+ modest_window_add_to_menu (MODEST_WINDOW (self), _("mcen_me_message_settings"), NULL,
+ MODEST_WINDOW_MENU_CALLBACK (on_message_settings),
+ NULL);
+ modest_window_add_to_menu (MODEST_WINDOW (self), _("mcen_me_viewer_find"), "<Ctrl>f",
+ MODEST_WINDOW_MENU_CALLBACK (modest_ui_actions_on_toggle_find_in_page),
+ NULL);
}
static void
priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
priv->max_chars_banner = NULL;
}
+
+static gboolean
+has_pending_addresses (ModestRecptEditor *recpt_editor)
+{
+ const gchar *recipients = NULL;
+ GSList *start_indexes = NULL, *end_indexes = NULL;
+ GSList *current_start, *current_end;
+ GtkTextBuffer *buffer;
+ gint offset_delta = 0;
+ gint last_length;
+ gboolean has_recipients_to_add = FALSE;
+
+ recipients = modest_recpt_editor_get_recipients (recpt_editor);
+ last_length = g_utf8_strlen (recipients, -1);
+ modest_text_utils_get_addresses_indexes (recipients, &start_indexes, &end_indexes);
+
+ if (!start_indexes)
+ return FALSE;
+
+ current_start = start_indexes;
+ current_end = end_indexes;
+ buffer = modest_recpt_editor_get_buffer (recpt_editor);
+
+ while (current_start && !has_recipients_to_add) {
+ gchar *address;
+ gchar *start_ptr, *end_ptr;
+ gint start_pos, end_pos;
+
+ start_pos = (*((gint*) current_start->data)) + offset_delta;
+ end_pos = (*((gint*) current_end->data)) + offset_delta;
+
+ start_ptr = g_utf8_offset_to_pointer (recipients, start_pos);
+ end_ptr = g_utf8_offset_to_pointer (recipients, end_pos);
+
+ address = g_strstrip (g_strndup (start_ptr, end_ptr - start_ptr));
+
+ if (modest_text_utils_validate_recipient (address, NULL)) {
+ if (!modest_address_book_has_address (address)) {
+ has_recipients_to_add = TRUE;
+ }
+ }
+ current_start = g_slist_next (current_start);
+ current_end = g_slist_next (current_end);
+ }
+ return has_recipients_to_add;
+}
+
+gboolean
+modest_msg_edit_window_has_pending_addresses (ModestMsgEditWindow *self)
+{
+ ModestMsgEditWindowPrivate *priv = NULL;
+
+ g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(self), FALSE);
+
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
+
+ if (!has_pending_addresses ((ModestRecptEditor *) priv->to_field) &&
+ !has_pending_addresses ((ModestRecptEditor *) priv->cc_field) &&
+ !has_pending_addresses ((ModestRecptEditor *) priv->bcc_field))
+ return FALSE;
+ else
+ return TRUE;
+}