X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmaemo%2Fmodest-msg-edit-window.c;h=7e11cde1e32ea704687a0002c0bd1b84858fc713;hp=3c0b0bcf38d123d9b1c696691626bdc31d5ead30;hb=7929406e046ed92142ff337bd9161e6a16e1d04e;hpb=8f7aad0dd79ba73052e58292a8b76582b8fdfa23 diff --git a/src/maemo/modest-msg-edit-window.c b/src/maemo/modest-msg-edit-window.c index 3c0b0bc..7e11cde 100644 --- a/src/maemo/modest-msg-edit-window.c +++ b/src/maemo/modest-msg-edit-window.c @@ -75,6 +75,7 @@ #else #include #endif +#include #include "modest-maemo-utils.h" @@ -87,6 +88,8 @@ #define IMAGE_MAX_WIDTH 560 #define DEFAULT_FONT_SCALE 1.5 +static gboolean is_wp_text_buffer_started = FALSE; + static void modest_msg_edit_window_class_init (ModestMsgEditWindowClass *klass); static void modest_msg_edit_window_init (ModestMsgEditWindow *obj); static void modest_msg_edit_window_finalize (GObject *obj); @@ -125,10 +128,6 @@ static void modest_msg_edit_window_add_attachment_clicked (GtkButton *button, /* ModestWindow methods implementation */ static void modest_msg_edit_window_disconnect_signals (ModestWindow *window); -static void modest_msg_edit_window_set_zoom (ModestWindow *window, gdouble zoom); -static gdouble modest_msg_edit_window_get_zoom (ModestWindow *window); -static gboolean modest_msg_edit_window_zoom_minus (ModestWindow *window); -static gboolean modest_msg_edit_window_zoom_plus (ModestWindow *window); static void modest_msg_edit_window_show_toolbar (ModestWindow *window, gboolean show_toolbar); static void modest_msg_edit_window_clipboard_owner_change (GtkClipboard *clipboard, @@ -157,6 +156,8 @@ static void on_account_removed (TnyAccountStore *account_store, TnyAccount *account, gpointer user_data); +static gboolean on_zoom_minus_plus_not_implemented (ModestWindow *window); + static void init_window (ModestMsgEditWindow *obj); static void DEBUG_BUFFER (WPTextBuffer *buffer) @@ -254,8 +255,6 @@ struct _ModestMsgEditWindowPrivate { GList *images; TnyHeaderFlags priority_flags; - - gdouble zoom_level; gboolean can_undo, can_redo; gulong clipboard_change_handler_id; @@ -300,7 +299,6 @@ modest_msg_edit_window_get_type (void) "ModestMsgEditWindow", &my_info, 0); - wp_text_buffer_library_init (); } return my_type; } @@ -323,19 +321,19 @@ restore_settings (ModestMsgEditWindow *self) 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_utils_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_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), modest_conf_get_bool (conf, MODEST_CONF_EDIT_WINDOW_SHOW_TOOLBAR_FULLSCREEN, NULL)); /* 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_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), modest_conf_get_bool(modest_runtime_get_conf(), MODEST_CONF_SHOW_CC, NULL)); action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ViewBccFieldMenu"); - modest_maemo_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), + modest_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), modest_conf_get_bool(modest_runtime_get_conf(), MODEST_CONF_SHOW_BCC, NULL)); /* Dim at start clipboard actions */ @@ -362,10 +360,8 @@ modest_msg_edit_window_class_init (ModestMsgEditWindowClass *klass) parent_class = g_type_class_peek_parent (klass); gobject_class->finalize = modest_msg_edit_window_finalize; - modest_window_class->set_zoom_func = modest_msg_edit_window_set_zoom; - modest_window_class->get_zoom_func = modest_msg_edit_window_get_zoom; - modest_window_class->zoom_plus_func = modest_msg_edit_window_zoom_plus; - modest_window_class->zoom_minus_func = modest_msg_edit_window_zoom_minus; + modest_window_class->zoom_plus_func = on_zoom_minus_plus_not_implemented; + modest_window_class->zoom_minus_func = on_zoom_minus_plus_not_implemented; modest_window_class->show_toolbar_func = modest_msg_edit_window_show_toolbar; modest_window_class->save_state_func = save_state; modest_window_class->disconnect_signals_func = modest_msg_edit_window_disconnect_signals; @@ -388,7 +384,6 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj) priv->attachments = NULL; priv->images = NULL; priv->last_cid = 0; - priv->zoom_level = 1.0; priv->cc_caption = NULL; priv->bcc_caption = NULL; @@ -415,6 +410,12 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj) modest_window_mgr_register_help_id (modest_runtime_get_window_mgr(), GTK_WINDOW(obj),"applications_email_editor"); + + if (!is_wp_text_buffer_started) { + is_wp_text_buffer_started = TRUE; + wp_text_buffer_library_init (); + } + init_window (obj); } @@ -605,12 +606,6 @@ init_window (ModestMsgEditWindow *obj) G_CALLBACK (modest_ui_actions_on_change_justify), obj); gtk_action_group_add_radio_actions (action_group, - modest_msg_edit_zoom_action_entries, - G_N_ELEMENTS (modest_msg_edit_zoom_action_entries), - 100, - G_CALLBACK (modest_ui_actions_on_change_zoom), - obj); - gtk_action_group_add_radio_actions (action_group, modest_msg_edit_priority_action_entries, G_N_ELEMENTS (modest_msg_edit_priority_action_entries), 0, @@ -637,9 +632,7 @@ init_window (ModestMsgEditWindow *obj) gtk_window_add_accel_group (GTK_WINDOW (obj), gtk_ui_manager_get_accel_group (parent_priv->ui_manager)); - /* Menubar. Update the state of some toggles */ - parent_priv->menubar = menubar_to_menu (parent_priv->ui_manager); - hildon_window_set_menu (HILDON_WINDOW (obj), GTK_MENU (parent_priv->menubar)); + parent_priv->menubar = NULL; size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); @@ -1300,6 +1293,9 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, gboolean pre priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (obj); parent_priv = MODEST_WINDOW_GET_PRIVATE (obj); + /* Menubar. Update the state of some toggles */ + parent_priv->menubar = menubar_to_menu (parent_priv->ui_manager); + 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_msg_edit_window_setup_toolbar (MODEST_MSG_EDIT_WINDOW (obj)); @@ -1625,27 +1621,34 @@ modest_msg_edit_window_set_format_state (ModestMsgEditWindow *self, wp_text_buffer_freeze (WP_TEXT_BUFFER (priv->text_buffer)); if (buffer_format->cs.bold) { - wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_BOLD, (gpointer) (buffer_format->bold&0x1)); + wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_BOLD, + GINT_TO_POINTER (buffer_format->bold&0x1)); } if (buffer_format->cs.italic) { - wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_ITALIC, (gpointer) (buffer_format->italic&0x1)); + wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_ITALIC, + GINT_TO_POINTER (buffer_format->italic&0x1)); } if (buffer_format->cs.color) { - wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FORECOLOR, (gpointer) (&(buffer_format->color))); + wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FORECOLOR, + GINT_TO_POINTER (&(buffer_format->color))); } if (buffer_format->cs.font_size) { - wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FONT_SIZE, (gpointer) (buffer_format->font_size)); + wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FONT_SIZE, + GINT_TO_POINTER (buffer_format->font_size)); } if (buffer_format->cs.justification) { switch (buffer_format->justification) { case GTK_JUSTIFY_LEFT: - wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_LEFT, (gpointer) TRUE); + wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_LEFT, + GINT_TO_POINTER(TRUE)); break; case GTK_JUSTIFY_CENTER: - wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_CENTER, (gpointer) TRUE); + wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_CENTER, + GINT_TO_POINTER(TRUE)); break; case GTK_JUSTIFY_RIGHT: - wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_RIGHT, (gpointer) TRUE); + wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_RIGHT, + GINT_TO_POINTER(TRUE)); break; default: break; @@ -1653,14 +1656,16 @@ modest_msg_edit_window_set_format_state (ModestMsgEditWindow *self, } if (buffer_format->cs.font) { - wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FONT, (gpointer) (buffer_format->font)); + wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FONT, + GINT_TO_POINTER (buffer_format->font)); } wp_text_buffer_thaw (WP_TEXT_BUFFER (priv->text_buffer)); if (buffer_format->cs.bullet) { - wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_BULLET, (gpointer) ((buffer_format->bullet)?1:0)); + wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_BULLET, + GINT_TO_POINTER ((buffer_format->bullet)?1:0)); } /* wp_text_buffer_set_format (WP_TEXT_BUFFER (priv->text_buffer), buffer_format); */ - + g_free (current_format); } @@ -1681,23 +1686,23 @@ text_buffer_refresh_attributes (WPTextBuffer *buffer, ModestMsgEditWindow *windo if (wp_text_buffer_is_rich_text (WP_TEXT_BUFFER (priv->text_buffer))) { action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/FileFormatMenu/FileFormatFormattedTextMenu"); if (!gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) - modest_maemo_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), TRUE); + modest_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), TRUE); } else { action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/FileFormatMenu/FileFormatPlainTextMenu"); if (!gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) - modest_maemo_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), TRUE); + modest_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), TRUE); } 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); + modest_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), buffer_format->bold); action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ActionsItalics"); - modest_maemo_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), buffer_format->italic); + modest_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), buffer_format->italic); /* action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/BulletedListMenu"); */ -/* modest_maemo_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), buffer_format->bullet); */ +/* modest_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), buffer_format->bullet); */ g_signal_handlers_block_by_func (G_OBJECT (priv->font_color_button), G_CALLBACK (modest_msg_edit_window_color_button_change), @@ -2047,7 +2052,7 @@ modest_msg_edit_window_attach_file_one ( tny_mime_part_set_filename (mime_part, basename); g_free (basename); - priv->attachments = g_list_prepend (priv->attachments, mime_part); + priv->attachments = g_list_prepend (priv->attachments, g_object_ref(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); @@ -2185,7 +2190,7 @@ modest_msg_edit_window_size_change (GtkCheckMenuItem *menu_item, /* wp_text_buffer_set_format (WP_TEXT_BUFFER (priv->text_buffer), &format); */ if (!wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FONT_SIZE, - (gpointer) wp_get_font_size_index (new_size_index, 12))) + GINT_TO_POINTER (wp_get_font_size_index (new_size_index, 12)))) wp_text_view_reset_and_show_im (WP_TEXT_VIEW (priv->msg_body)); text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), MODEST_MSG_EDIT_WINDOW (window)); @@ -2216,7 +2221,7 @@ modest_msg_edit_window_font_change (GtkCheckMenuItem *menu_item, new_font_index = wp_get_font_index (gtk_label_get_text (GTK_LABEL (label)), DEFAULT_FONT); if (!wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FONT, - (gpointer) new_font_index)) + GINT_TO_POINTER(new_font_index))) wp_text_view_reset_and_show_im (WP_TEXT_VIEW (priv->msg_body)); text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), MODEST_MSG_EDIT_WINDOW (window)); @@ -2226,117 +2231,6 @@ modest_msg_edit_window_font_change (GtkCheckMenuItem *menu_item, } } -static void -modest_msg_edit_window_set_zoom (ModestWindow *window, - gdouble zoom) -{ - ModestMsgEditWindowPrivate *priv; - ModestWindowPrivate *parent_priv; - GtkRadioAction *zoom_radio_action; - - g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window)); - - priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); - parent_priv = MODEST_WINDOW_GET_PRIVATE (window); - priv->zoom_level = zoom; - wp_text_buffer_set_font_scaling_factor (WP_TEXT_BUFFER (priv->text_buffer), zoom*DEFAULT_FONT_SCALE); - - /* Zoom level menu options should be updated with the current zoom level */ - parent_priv = MODEST_WINDOW_GET_PRIVATE (window); - zoom_radio_action = GTK_RADIO_ACTION (gtk_ui_manager_get_action (parent_priv->ui_manager, - "/MenuBar/ViewMenu/ZoomMenu/Zoom50Menu")); -#ifdef MODEST_HAVE_HILDON0_WIDGETS - /* FIXME: Not availible before Gtk 2.10 */ -#else - gtk_radio_action_set_current_value (zoom_radio_action, (gint) (zoom*100.0+0.1)); -#endif -} - -static gdouble -modest_msg_edit_window_get_zoom (ModestWindow *window) -{ - ModestMsgEditWindowPrivate *priv; - - g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window), 1.0); - - priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); - return priv->zoom_level; -} - -static gboolean -zoom_allowed (ModestMsgEditWindow *window) -{ - GtkWidget *focus; - - focus = gtk_window_get_focus (GTK_WINDOW (window)); - return (focus != NULL && WP_IS_TEXT_VIEW (focus)); -} - -static gboolean -modest_msg_edit_window_zoom_plus (ModestWindow *window) -{ - ModestWindowPrivate *parent_priv; - GtkRadioAction *zoom_radio_action; - GSList *group, *node; - - /* First we check if the text view is focused. If not, zooming is not allowed */ - if (!zoom_allowed (MODEST_MSG_EDIT_WINDOW (window))) { - hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_cannot_zoom_here")); - return FALSE; - } - - parent_priv = MODEST_WINDOW_GET_PRIVATE (window); - zoom_radio_action = GTK_RADIO_ACTION (gtk_ui_manager_get_action (parent_priv->ui_manager, - "/MenuBar/ViewMenu/ZoomMenu/Zoom50Menu")); - - group = gtk_radio_action_get_group (zoom_radio_action); - - if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (group->data))) { - hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_max_zoom_level_reached")); - return FALSE; - } - - for (node = group; node != NULL; node = g_slist_next (node)) { - if ((node->next != NULL) && gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (node->next->data))) { - gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (node->data), TRUE); - return TRUE; - } - } - return FALSE; -} - -static gboolean -modest_msg_edit_window_zoom_minus (ModestWindow *window) -{ - ModestWindowPrivate *parent_priv; - GtkRadioAction *zoom_radio_action; - GSList *group, *node; - - /* First we check if the text view is focused. If not, zooming is not allowed */ - if (!zoom_allowed (MODEST_MSG_EDIT_WINDOW (window))) { - hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_cannot_zoom_here")); - return FALSE; - } - - parent_priv = MODEST_WINDOW_GET_PRIVATE (window); - zoom_radio_action = GTK_RADIO_ACTION (gtk_ui_manager_get_action (parent_priv->ui_manager, - "/MenuBar/ViewMenu/ZoomMenu/Zoom50Menu")); - - group = gtk_radio_action_get_group (zoom_radio_action); - - for (node = group; node != NULL; node = g_slist_next (node)) { - if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (node->data))) { - if (node->next != NULL) { - gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (node->next->data), TRUE); - return TRUE; - } else - hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_min_zoom_level_reached")); - break; - } - } - return FALSE; -} - static gboolean modest_msg_edit_window_window_state_event (GtkWidget *widget, GdkEventWindowState *event, gpointer userdata) { @@ -2480,7 +2374,7 @@ modest_msg_edit_window_show_toolbar (ModestWindow *self, 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), + modest_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), show_toolbar); } @@ -2559,7 +2453,7 @@ modest_msg_edit_window_set_file_format (ModestMsgEditWindow *window, wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), FALSE); } else { GtkToggleAction *action = GTK_TOGGLE_ACTION (gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/FileFormatMenu/FileFormatFormattedTextMenu")); - modest_maemo_toggle_action_set_active_block_notify (action, TRUE); + modest_utils_toggle_action_set_active_block_notify (action, TRUE); } } break; @@ -2593,7 +2487,6 @@ modest_msg_edit_window_select_font (ModestMsgEditWindow *window) /* First we get the currently selected font information */ wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), &oldfmt, TRUE); - g_object_set (G_OBJECT (dialog), "font-scaling", priv->zoom_level, NULL); switch (oldfmt.text_position) { case TEXT_POSITION_NORMAL: @@ -3345,3 +3238,13 @@ on_account_removed (TnyAccountStore *account_store, modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (user_data)); } } + +static gboolean +on_zoom_minus_plus_not_implemented (ModestWindow *window) +{ + g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window), FALSE); + + hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_cannot_zoom_here")); + return FALSE; + +}