X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=shell%2Fev-window.c;h=007ca8893ac86d434178bde2ad9beb9d35b3695e;hb=560d83a31c3acab2e640a8dfa8c6d6097baeea7a;hp=0d8124f6e89ce7ede07201ce48d3b0b162cb858d;hpb=63cb6b1b8f61547c3ab6c4e305bad2a4828f9bfa;p=evince.git diff --git a/shell/ev-window.c b/shell/ev-window.c index 0d8124f6..007ca889 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -29,6 +29,8 @@ #endif #include "ev-window.h" +#include "ev-navigation-action.h" +#include "ev-page-action.h" #include "ev-sidebar.h" #include "ev-sidebar-bookmarks.h" #include "ev-sidebar-thumbnails.h" @@ -39,7 +41,7 @@ #include "pdf-document.h" #include "pixbuf-document.h" -#include "gtkgs.h" +#include "ps-document.h" #include #include @@ -72,6 +74,8 @@ struct _EvWindowPrivate { GtkWidget *statusbar; guint help_message_cid; GtkWidget *exit_fullscreen_popup; + char *uri; + GtkAction *page_action; EvDocument *document; @@ -181,8 +185,8 @@ update_action_sensitivity (EvWindow *ev_window) page = ev_view_get_page (EV_VIEW (ev_window->priv->view)); set_action_sensitive (ev_window, "GoFirstPage", page > 1); - set_action_sensitive (ev_window, "GoPreviousPage", page > 1); - set_action_sensitive (ev_window, "GoNextPage", page < n_pages); + set_action_sensitive (ev_window, "GoPageDown", page > 1); + set_action_sensitive (ev_window, "GoPageUp", page < n_pages); set_action_sensitive (ev_window, "GoLastPage", page < n_pages); } @@ -249,24 +253,65 @@ mime_type_supported_by_gdk_pixbuf (const gchar *mime_type) return retval; } +static void +update_window_title (EvDocument *document, GParamSpec *pspec, EvWindow *ev_window) +{ + char *title = NULL; + + if (document == NULL) { + title = g_strdup (_("Document Viewer")); + } else { + title = ev_document_get_title (document); + + if (title == NULL) { + title = g_path_get_basename (ev_window->priv->uri); + } + } + + gtk_window_set_title (GTK_WINDOW (ev_window), title); + + g_free (title); +} + +static void +update_total_pages (EvWindow *ev_window) +{ + EvPageAction *page_action; + int pages; + + pages = ev_document_get_n_pages (ev_window->priv->document); + page_action = EV_PAGE_ACTION (ev_window->priv->page_action); + ev_page_action_set_total_pages (page_action, pages); +} + void ev_window_open (EvWindow *ev_window, const char *uri) { EvDocument *document = NULL; char *mime_type; + + g_free (ev_window->priv->uri); + ev_window->priv->uri = g_strdup (uri); mime_type = gnome_vfs_get_mime_type (uri); - if (!strcmp (mime_type, "application/pdf")) + if (mime_type == NULL) + document = NULL; + else if (!strcmp (mime_type, "application/pdf")) document = g_object_new (PDF_TYPE_DOCUMENT, NULL); else if (!strcmp (mime_type, "application/postscript")) - document = g_object_new (GTK_GS_TYPE, NULL); + document = g_object_new (PS_TYPE_DOCUMENT, NULL); else if (mime_type_supported_by_gdk_pixbuf (mime_type)) document = g_object_new (PIXBUF_TYPE_DOCUMENT, NULL); if (document) { GError *error = NULL; + g_signal_connect_object (G_OBJECT (document), + "notify::title", + G_CALLBACK (update_window_title), + ev_window, 0); + if (ev_document_load (document, uri, &error)) { if (ev_window->priv->document) g_object_unref (ev_window->priv->document); @@ -277,8 +322,8 @@ ev_window_open (EvWindow *ev_window, const char *uri) ev_sidebar_set_document (EV_SIDEBAR (ev_window->priv->sidebar), document); + update_total_pages (ev_window); update_action_sensitivity (ev_window); - } else { g_assert (error != NULL); g_object_unref (document); @@ -289,7 +334,7 @@ ev_window_open (EvWindow *ev_window, const char *uri) char *error_message; error_message = g_strdup_printf (_("Unhandled MIME type: '%s'"), - mime_type); + mime_type?mime_type:""); unable_to_load (ev_window, error_message); g_free (error_message); } @@ -710,7 +755,7 @@ ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window) } static void -ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window) +ev_window_cmd_go_page_up (GtkAction *action, EvWindow *ev_window) { g_return_if_fail (EV_IS_WINDOW (ev_window)); @@ -719,7 +764,7 @@ ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window) } static void -ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window) +ev_window_cmd_go_page_down (GtkAction *action, EvWindow *ev_window) { g_return_if_fail (EV_IS_WINDOW (ev_window)); @@ -891,10 +936,22 @@ disconnect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action, } } +static void +update_current_page (EvWindow *ev_window) +{ + EvPageAction *page_action; + int page; + + page = ev_view_get_page (EV_VIEW (ev_window->priv->view)); + page_action = EV_PAGE_ACTION (ev_window->priv->page_action); + ev_page_action_set_current_page (page_action, page); +} + static void view_page_changed_cb (EvView *view, EvWindow *ev_window) { + update_current_page (ev_window); update_action_sensitivity (ev_window); } @@ -1095,12 +1152,12 @@ static GtkActionEntry entries[] = { { "GoForward", GTK_STOCK_GO_FORWARD, N_("Fo_rward"), "Right", N_("Go to the page viewed before this one"), G_CALLBACK (ev_window_cmd_go_forward) }, - { "GoPreviousPage", GTK_STOCK_GO_BACK, N_("_Previous Page"), "Page_Up", + { "GoPageDown", GTK_STOCK_GO_UP, N_("_Page Up"), "Page_Up", N_("Go to the previous page"), - G_CALLBACK (ev_window_cmd_go_previous_page) }, - { "GoNextPage", GTK_STOCK_GO_FORWARD, N_("_Next Page"), "Page_Down", + G_CALLBACK (ev_window_cmd_go_page_up) }, + { "GoPageUp", GTK_STOCK_GO_DOWN, N_("_Page Down"), "Page_Down", N_("Go to the next page"), - G_CALLBACK (ev_window_cmd_go_next_page) }, + G_CALLBACK (ev_window_cmd_go_page_down) }, { "GoFirstPage", GTK_STOCK_GOTO_FIRST, N_("_First Page"), "Home", N_("Go to the first page"), G_CALLBACK (ev_window_cmd_go_first_page) }, @@ -1129,12 +1186,59 @@ static GtkToggleActionEntry toggle_entries[] = { G_CALLBACK (ev_window_view_statusbar_cb), TRUE }, { "ViewSidebar", NULL, N_("Side_bar"), "F9", N_("Show or hide sidebar"), - G_CALLBACK (ev_window_view_sidebar_cb), FALSE }, + G_CALLBACK (ev_window_view_sidebar_cb), TRUE }, { "ViewFullscreen", NULL, N_("_Fullscreen"), "F11", N_("Expand the window to fill the screen"), G_CALLBACK (ev_window_cmd_view_fullscreen) }, }; +static void +goto_page_cb (GtkAction *action, int page_number, EvWindow *ev_window) +{ + + ev_view_set_page (EV_VIEW (ev_window->priv->view), page_number); +} + +static void +register_custom_actions (EvWindow *window, GtkActionGroup *group) +{ + GtkAction *action; + + action = g_object_new (EV_TYPE_NAVIGATION_ACTION, + "name", "NavigationBack", + "label", _("Back"), + "stock_id", GTK_STOCK_GO_BACK, + "tooltip", _("Go back"), + "arrow-tooltip", _("Back history"), + "direction", EV_NAVIGATION_DIRECTION_BACK, + "is_important", TRUE, + NULL); + gtk_action_group_add_action (group, action); + g_object_unref (action); + + action = g_object_new (EV_TYPE_NAVIGATION_ACTION, + "name", "NavigationForward", + "label", _("Forward"), + "stock_id", GTK_STOCK_GO_FORWARD, + "tooltip", _("Go forward"), + "arrow-tooltip", _("Forward history"), + "direction", EV_NAVIGATION_DIRECTION_FORWARD, + NULL); + gtk_action_group_add_action (group, action); + g_object_unref (action); + + action = g_object_new (EV_TYPE_PAGE_ACTION, + "name", "PageSelector", + "label", _("Page"), + "tooltip", _("Select Page"), + NULL); + g_signal_connect (action, "goto_page", + G_CALLBACK (goto_page_cb), window); + window->priv->page_action = action; + gtk_action_group_add_action (group, action); + g_object_unref (action); +} + static void ev_window_init (EvWindow *ev_window) { @@ -1148,7 +1252,7 @@ ev_window_init (EvWindow *ev_window) ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window); - gtk_window_set_title (GTK_WINDOW (ev_window), _("Document Viewer")); + update_window_title (NULL, NULL, ev_window); ev_window->priv->main_box = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box); @@ -1163,6 +1267,8 @@ ev_window_init (EvWindow *ev_window) G_N_ELEMENTS (toggle_entries), ev_window); + register_custom_actions (ev_window, action_group); + ev_window->priv->ui_manager = gtk_ui_manager_new (); gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager, action_group, 0);