From 938636d838432d71cd8ed1c2aa1604faa6f8d083 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 6 Jul 2005 10:36:28 +0000 Subject: [PATCH] Add support for some more types 2005-07-06 Marco Pesenti Gritti * shell/ev-metadata-manager.c: (parse_value), (save_values), (ev_metadata_manager_set_int), (ev_metadata_manager_set_double), (ev_metadata_manager_set_string), (ev_metadata_manager_set_boolean): * shell/ev-metadata-manager.h: Add support for some more types * shell/ev-view.c: (scroll_to_current_page), (ev_view_get_continuous), (ev_view_set_continuous), (ev_view_get_dual_page): * shell/ev-view.h: * shell/ev-window.c: (page_changed_cb), (setup_document_from_metadata), (ev_window_setup_document), (setup_view_from_metadata), (ev_window_open_uri), (ev_window_run_fullscreen), (ev_window_stop_fullscreen), (ev_window_run_presentation), (ev_window_stop_presentation), (save_sizing_mode), (ev_window_sizing_mode_changed_cb), (ev_window_zoom_changed_cb), (ev_window_update_continuous_action), (ev_window_update_dual_page_action), (ev_window_continuous_changed_cb), (ev_window_dual_mode_changed_cb), (ev_window_init): Remember a bunch of view/document properties. Prolly some are still missing but it's getting interesting. --- ChangeLog | 28 ++++++ shell/ev-metadata-manager.c | 45 ++++++++++ shell/ev-metadata-manager.h | 9 ++ shell/ev-view.c | 22 ++++- shell/ev-view.h | 6 +- shell/ev-window.c | 167 ++++++++++++++++++++++++++++++++++-- 6 files changed, 266 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2fd227d3..7678511a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2005-07-06 Marco Pesenti Gritti + + * shell/ev-metadata-manager.c: (parse_value), (save_values), + (ev_metadata_manager_set_int), (ev_metadata_manager_set_double), + (ev_metadata_manager_set_string), + (ev_metadata_manager_set_boolean): + * shell/ev-metadata-manager.h: + + Add support for some more types + + * shell/ev-view.c: (scroll_to_current_page), + (ev_view_get_continuous), (ev_view_set_continuous), + (ev_view_get_dual_page): + * shell/ev-view.h: + * shell/ev-window.c: (page_changed_cb), + (setup_document_from_metadata), (ev_window_setup_document), + (setup_view_from_metadata), (ev_window_open_uri), + (ev_window_run_fullscreen), (ev_window_stop_fullscreen), + (ev_window_run_presentation), (ev_window_stop_presentation), + (save_sizing_mode), (ev_window_sizing_mode_changed_cb), + (ev_window_zoom_changed_cb), (ev_window_update_continuous_action), + (ev_window_update_dual_page_action), + (ev_window_continuous_changed_cb), + (ev_window_dual_mode_changed_cb), (ev_window_init): + + Remember a bunch of view/document properties. Prolly some + are still missing but it's getting interesting. + 2005-07-05 Martin Kretzschmar * configure.ac: check if dbus-binding-tool is installed. Not the diff --git a/shell/ev-metadata-manager.c b/shell/ev-metadata-manager.c index bbf5f762..6e709e32 100644 --- a/shell/ev-metadata-manager.c +++ b/shell/ev-metadata-manager.c @@ -149,6 +149,12 @@ parse_value (xmlChar *value, xmlChar *type) case G_TYPE_INT: g_value_set_int (ret, atoi ((char *)value)); break; + case G_TYPE_DOUBLE: + g_value_set_double (ret, atof ((char *)value)); + break; + case G_TYPE_BOOLEAN: + g_value_set_boolean (ret, atoi ((char *)value)); + break; } return ret; @@ -426,6 +432,12 @@ save_values (const gchar *key, GValue *value, xmlNodePtr parent) case G_TYPE_INT: string_value = g_strdup_printf ("%d", g_value_get_int (value)); break; + case G_TYPE_DOUBLE: + string_value = g_strdup_printf ("%f", g_value_get_double (value)); + break; + case G_TYPE_BOOLEAN: + string_value = g_strdup_printf ("%d", g_value_get_boolean (value)); + break; default: string_value = NULL; g_assert_not_reached (); @@ -549,3 +561,36 @@ ev_metadata_manager_set_int (const gchar *uri, const gchar *key, int value) ev_metadata_manager_set (uri, key, &val); } + +void +ev_metadata_manager_set_double (const gchar *uri, const gchar *key, double value) +{ + GValue val = { 0, }; + + g_value_init (&val, G_TYPE_DOUBLE); + g_value_set_double (&val, value); + + ev_metadata_manager_set (uri, key, &val); +} + +void +ev_metadata_manager_set_string (const gchar *uri, const gchar *key, const gchar *value) +{ + GValue val = { 0, }; + + g_value_init (&val, G_TYPE_STRING); + g_value_set_string (&val, value); + + ev_metadata_manager_set (uri, key, &val); +} + +void +ev_metadata_manager_set_boolean (const gchar *uri, const gchar *key, gboolean value) +{ + GValue val = { 0, }; + + g_value_init (&val, G_TYPE_BOOLEAN); + g_value_set_boolean (&val, value); + + ev_metadata_manager_set (uri, key, &val); +} diff --git a/shell/ev-metadata-manager.h b/shell/ev-metadata-manager.h index 5c4d61d6..9934c251 100644 --- a/shell/ev-metadata-manager.h +++ b/shell/ev-metadata-manager.h @@ -37,6 +37,15 @@ void ev_metadata_manager_set (const gchar *uri, void ev_metadata_manager_set_int (const gchar *uri, const gchar *key, int value); +void ev_metadata_manager_set_double (const gchar *uri, + const gchar *key, + double value); +void ev_metadata_manager_set_string (const gchar *uri, + const gchar *key, + const gchar *value); +void ev_metadata_manager_set_boolean (const gchar *uri, + const gchar *key, + gboolean value); void ev_metadata_manager_shutdown (void); G_END_DECLS diff --git a/shell/ev-view.c b/shell/ev-view.c index 131966b9..8e494ade 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -371,7 +371,11 @@ scroll_to_current_page (EvView *view, GtkOrientation orientation) { GdkRectangle page_area; GtkBorder border; - + + if (view->document == NULL) { + return; + } + get_page_extents (view, view->current_page, &page_area, &border); if (orientation == GTK_ORIENTATION_VERTICAL) { @@ -2095,6 +2099,14 @@ ev_view_get_zoom (EvView *view) return view->scale; } +gboolean +ev_view_get_continuous (EvView *view) +{ + g_return_val_if_fail (EV_IS_VIEW (view), FALSE); + + return view->continuous; +} + void ev_view_set_continuous (EvView *view, gboolean continuous) @@ -2112,6 +2124,14 @@ ev_view_set_continuous (EvView *view, g_object_notify (G_OBJECT (view), "continuous"); } +gboolean +ev_view_get_dual_page (EvView *view) +{ + g_return_val_if_fail (EV_IS_VIEW (view), FALSE); + + return view->dual_page; +} + void ev_view_set_dual_page (EvView *view, gboolean dual_page) diff --git a/shell/ev-view.h b/shell/ev-view.h index 0c0ebaf6..2790a1c4 100644 --- a/shell/ev-view.h +++ b/shell/ev-view.h @@ -28,10 +28,12 @@ G_BEGIN_DECLS #define EV_TYPE_VIEW (ev_view_get_type ()) -#define EV_TYPE_SIZING_MODE (ev_sizing_mode_get_type()) #define EV_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EV_TYPE_VIEW, EvView)) #define EV_IS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EV_TYPE_VIEW)) +#define EV_TYPE_SIZING_MODE (ev_sizing_mode_get_type()) +#define EV_SIZING_MODE_CLASS (g_type_class_peek (EV_TYPE_SIZING_MODE)) + typedef struct _EvView EvView; typedef struct _EvViewClass EvViewClass; @@ -66,8 +68,10 @@ void ev_view_select_all (EvView *view); /* These are all orthoganal to each other, except 'presentation' trumps all * other behaviors */ +gboolean ev_view_get_continuous (EvView *view); void ev_view_set_continuous (EvView *view, gboolean continuous); +gboolean ev_view_get_dual_page (EvView *view); void ev_view_set_dual_page (EvView *view, gboolean dual_page); void ev_view_set_fullscreen (EvView *view, diff --git a/shell/ev-window.c b/shell/ev-window.c index 8f55f13d..88392d96 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -618,6 +618,8 @@ page_changed_cb (EvPageCache *page_cache, EvWindow *ev_window) { update_action_sensitivity (ev_window); + + ev_metadata_manager_set_int (ev_window->priv->uri, "page", page); } static void @@ -631,6 +633,22 @@ update_document_mode (EvWindow *window, EvDocumentMode mode) } } +#ifdef ENABLE_METADATA +static void +setup_document_from_metadata (EvWindow *window) +{ + char *uri = window->priv->uri; + GValue page = { 0, }; + + /* Page */ + if (ev_metadata_manager_get (uri, "page", &page)) { + ev_page_cache_set_current_page (window->priv->page_cache, + g_value_get_int (&page)); + } + +} +#endif + static void ev_window_setup_document (EvWindow *ev_window) { @@ -675,6 +693,10 @@ ev_window_setup_document (EvWindow *ev_window) ev_properties_dialog_set_document (EV_PROPERTIES_DIALOG (ev_window->priv->properties), ev_window->priv->document); } + +#ifdef ENABLE_METADATA + setup_document_from_metadata (ev_window); +#endif } static void @@ -913,18 +935,65 @@ ev_window_xfer_job_cb (EvJobXfer *job, #ifdef ENABLE_METADATA static void -ev_window_setup_from_metadata (EvWindow *window) +setup_view_from_metadata (EvWindow *window) { + EvView *view = EV_VIEW (window->priv->view); char *uri = window->priv->uri; + GEnumValue *enum_value; GValue width = { 0, }; GValue height = { 0, }; + GValue sizing_mode = { 0, }; + GValue zoom = { 0, }; + GValue continuous = { 0, }; + GValue dual_page = { 0, }; + GValue presentation = { 0, }; + GValue fullscreen = { 0, }; - ev_metadata_manager_get (uri, "window_width", &width); - ev_metadata_manager_get (uri, "window_height", &height); + /* Window size */ + if (ev_metadata_manager_get (uri, "window_width", &width) && + ev_metadata_manager_get (uri, "window_height", &height)) { + gtk_window_set_default_size (GTK_WINDOW (window), + g_value_get_int (&width), + g_value_get_int (&height)); + } + + /* Sizing mode */ + if (ev_metadata_manager_get (uri, "sizing_mode", &sizing_mode)) { + enum_value = g_enum_get_value_by_nick + (EV_SIZING_MODE_CLASS, g_value_get_string (&sizing_mode)); + g_value_unset (&sizing_mode); + ev_view_set_sizing_mode (view, enum_value->value); + } - gtk_window_set_default_size (GTK_WINDOW (window), - g_value_get_int (&width), - g_value_get_int (&height)); + /* Zoom */ + if (ev_metadata_manager_get (uri, "zoom", &zoom) && + ev_view_get_sizing_mode (view) == EV_SIZING_FREE) { + ev_view_set_zoom (view, g_value_get_double (&zoom), FALSE); + } + + /* Continuous */ + if (ev_metadata_manager_get (uri, "continuous", &continuous)) { + ev_view_set_continuous (view, g_value_get_boolean (&continuous)); + } + + /* Dual page */ + if (ev_metadata_manager_get (uri, "dual-page", &dual_page)) { + ev_view_set_dual_page (view, g_value_get_boolean (&dual_page)); + } + + /* Presentation */ + if (ev_metadata_manager_get (uri, "presentation", &presentation)) { + if (g_value_get_boolean (&presentation)) { + ev_window_run_presentation (window); + } + } + + /* Fullscreen */ + if (ev_metadata_manager_get (uri, "fullscreen", &fullscreen)) { + if (g_value_get_boolean (&fullscreen)) { + ev_window_run_fullscreen (window); + } + } } #endif @@ -938,7 +1007,7 @@ ev_window_open_uri (EvWindow *ev_window, const char *uri) ev_window->priv->uri = g_strdup (uri); #ifdef ENABLE_METADATA - ev_window_setup_from_metadata (ev_window); + setup_view_from_metadata (ev_window); #endif ev_window_clear_jobs (ev_window); @@ -1666,6 +1735,8 @@ ev_window_run_fullscreen (EvWindow *window) ev_window_update_fullscreen_action (window); gtk_window_fullscreen (GTK_WINDOW (window)); ev_window_update_fullscreen_popup (window); + + ev_metadata_manager_set_boolean (window->priv->uri, "fullscreen", TRUE); } static void @@ -1692,6 +1763,8 @@ ev_window_stop_fullscreen (EvWindow *window) ev_window_update_fullscreen_action (window); gtk_window_unfullscreen (GTK_WINDOW (window)); update_chrome_visibility (window); + + ev_metadata_manager_set_boolean (window->priv->uri, "fullscreen", FALSE); } static void @@ -1736,6 +1809,8 @@ ev_window_run_presentation (EvWindow *window) gtk_window_fullscreen (GTK_WINDOW (window)); ev_window_update_presentation_action (window); update_chrome_visibility (window); + + ev_metadata_manager_set_boolean (window->priv->uri, "presentation", TRUE); } static void @@ -1751,6 +1826,8 @@ ev_window_stop_presentation (EvWindow *window) gtk_window_unfullscreen (GTK_WINDOW (window)); ev_window_update_presentation_action (window); update_chrome_visibility (window); + + ev_metadata_manager_set_boolean (window->priv->uri, "presentation", FALSE); } static void @@ -2093,6 +2170,23 @@ update_view_size (EvView *view, EvWindow *window) hsb_requisition.height + scrollbar_spacing); } +static void +save_sizing_mode (EvWindow *window) +{ +#ifdef ENABLE_METADATA + EvSizingMode mode; + GEnumValue *enum_value; + + if (window->priv->uri) { + mode = ev_view_get_sizing_mode (EV_VIEW (window->priv->view)); + enum_value = g_enum_get_value (EV_SIZING_MODE_CLASS, mode); + + ev_metadata_manager_set_string (window->priv->uri, "sizing_mode", + enum_value->value_nick); + } +#endif +} + static void ev_window_sizing_mode_changed_cb (EvView *view, GParamSpec *pspec, EvWindow *ev_window) @@ -2139,13 +2233,60 @@ ev_window_sizing_mode_changed_cb (EvView *view, GParamSpec *pspec, } update_sizing_buttons (ev_window); + save_sizing_mode (ev_window); } static void -ev_window_zoom_changed_cb (EvView *view, GParamSpec *pspec, - EvWindow *ev_window) +ev_window_zoom_changed_cb (EvView *view, GParamSpec *pspec, EvWindow *ev_window) { update_action_sensitivity (ev_window); + + ev_metadata_manager_set_double (ev_window->priv->uri, "zoom", + ev_view_get_zoom (EV_VIEW (ev_window->priv->view))); +} + +static void +ev_window_update_continuous_action (EvWindow *window) +{ + GtkAction *action; + + action = gtk_action_group_get_action (window->priv->action_group, "ViewContinuous"); + g_signal_handlers_block_by_func + (action, G_CALLBACK (ev_window_cmd_continuous), window); + gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), + ev_view_get_continuous (EV_VIEW (window->priv->view))); + g_signal_handlers_unblock_by_func + (action, G_CALLBACK (ev_window_cmd_continuous), window); +} + +static void +ev_window_update_dual_page_action (EvWindow *window) +{ + GtkAction *action; + + action = gtk_action_group_get_action (window->priv->action_group, "ViewDual"); + g_signal_handlers_block_by_func + (action, G_CALLBACK (ev_window_cmd_dual), window); + gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), + ev_view_get_dual_page (EV_VIEW (window->priv->view))); + g_signal_handlers_unblock_by_func + (action, G_CALLBACK (ev_window_cmd_dual), window); +} + +static void +ev_window_continuous_changed_cb (EvView *view, GParamSpec *pspec, EvWindow *ev_window) +{ + ev_window_update_continuous_action (ev_window); + ev_metadata_manager_set_boolean (ev_window->priv->uri, "continuous", + ev_view_get_continuous (EV_VIEW (ev_window->priv->view))); +} + +static void +ev_window_dual_mode_changed_cb (EvView *view, GParamSpec *pspec, EvWindow *ev_window) +{ + ev_window_update_dual_page_action (ev_window); + ev_metadata_manager_set_boolean (ev_window->priv->uri, "dual-page", + ev_view_get_dual_page (EV_VIEW (ev_window->priv->view))); } static char * @@ -3226,6 +3367,14 @@ ev_window_init (EvWindow *ev_window) "notify::zoom", G_CALLBACK (ev_window_zoom_changed_cb), ev_window); + g_signal_connect (ev_window->priv->view, + "notify::dual-page", + G_CALLBACK (ev_window_dual_mode_changed_cb), + ev_window); + g_signal_connect (ev_window->priv->view, + "notify::continuous", + G_CALLBACK (ev_window_continuous_changed_cb), + ev_window); ev_window->priv->statusbar = ev_statusbar_new (); gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box), -- 2.43.5