X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=sidebyside;f=shell%2Fev-window.c;h=87ec655ba796580d8b4b3231175d9f32271fa1eb;hb=2b7b6bf6c958d95290100d2c48915c0dc9788e73;hp=0ceb24f1be459cfcc91c9550f4da53c1749b2602;hpb=0c3040ad65632ef58234bbbb68af8513e94307bc;p=evince.git diff --git a/shell/ev-window.c b/shell/ev-window.c index 0ceb24f1..87ec655b 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -23,7 +23,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H @@ -140,6 +140,10 @@ struct _EvWindowPrivate { GtkWidget *sidebar_attachments; GtkWidget *sidebar_layers; + /* Settings */ + GSettings *settings; + GSettings *last_settings; + /* Menubar accels */ guint menubar_accel_keyval; GdkModifierType menubar_accel_modifier; @@ -224,6 +228,9 @@ struct _EvWindowPrivate { #define GCONF_LOCKDOWN_PRINT "/desktop/gnome/lockdown/disable_printing" #define GCONF_LOCKDOWN_PRINT_SETUP "/desktop/gnome/lockdown/disable_print_setup" +#define GS_SCHEMA_NAME "org.gnome.Evince" +#define GS_OVERRIDE_RESTRICTIONS "override_restrictions" + #define SIDEBAR_DEFAULT_SIZE 132 #define LINKS_SIDEBAR_ID "links" #define THUMBNAILS_SIDEBAR_ID "thumbnails" @@ -239,6 +246,8 @@ struct _EvWindowPrivate { #define MIN_SCALE 0.05409 #define MAX_SCALE 4.0 +#define MAX_RECENT_ITEM_LEN (40) + static const gchar *document_print_settings[] = { GTK_PRINT_SETTINGS_N_COPIES, GTK_PRINT_SETTINGS_COLLATE, @@ -375,12 +384,12 @@ ev_window_setup_action_sensitivity (EvWindow *ev_window) can_find = TRUE; } -#ifdef WITH_GCONF - if (has_document) - override_restrictions = gconf_client_get_bool (ev_window->priv->gconf_client, - GCONF_OVERRIDE_RESTRICTIONS, - NULL); -#endif + if (has_document && ev_window->priv->settings) { + override_restrictions = + g_settings_get_boolean (ev_window->priv->settings, + GS_OVERRIDE_RESTRICTIONS); + } + if (!override_restrictions && info && info->fields_mask & EV_DOCUMENT_INFO_PERMISSIONS) { ok_to_print = (info->permissions & EV_DOCUMENT_PERMISSIONS_OK_TO_PRINT); ok_to_copy = (info->permissions & EV_DOCUMENT_PERMISSIONS_OK_TO_COPY); @@ -409,9 +418,6 @@ ev_window_setup_action_sensitivity (EvWindow *ev_window) /* File menu */ ev_window_set_action_sensitive (ev_window, "FileOpenCopy", has_document); ev_window_set_action_sensitive (ev_window, "FileSaveAs", has_document && ok_to_copy); -#if !GTK_CHECK_VERSION (2, 17, 4) - ev_window_set_action_sensitive (ev_window, "FilePageSetup", has_pages && ok_to_print && ok_to_print_setup); -#endif ev_window_set_action_sensitive (ev_window, "FilePrint", has_pages && ok_to_print); ev_window_set_action_sensitive (ev_window, "FileProperties", has_document && has_properties); @@ -436,11 +442,6 @@ ev_window_setup_action_sensitivity (EvWindow *ev_window) ev_window_set_action_sensitive (ev_window, ZOOM_CONTROL_ACTION, has_pages); ev_window_set_action_sensitive (ev_window, NAVIGATION_ACTION, FALSE); - /* Help menu */ -#ifdef G_OS_WIN32 - ev_window_set_action_sensitive (ev_window, "HelpContents", FALSE); -#endif - ev_window_update_actions (ev_window); } @@ -571,7 +572,7 @@ update_chrome_visibility (EvWindow *window) fullscreen_toolbar = ((priv->chrome & EV_CHROME_FULLSCREEN_TOOLBAR) != 0 || (priv->chrome & EV_CHROME_RAISE_TOOLBAR) != 0) && fullscreen; findbar = (priv->chrome & EV_CHROME_FINDBAR) != 0; - sidebar = (priv->chrome & EV_CHROME_SIDEBAR) != 0 && !presentation; + sidebar = (priv->chrome & EV_CHROME_SIDEBAR) != 0 && priv->document && !presentation; set_widget_visibility (priv->menubar, menubar); set_widget_visibility (priv->toolbar, toolbar); @@ -903,11 +904,16 @@ setup_chrome_from_metadata (EvWindow *window) EvChrome chrome = EV_CHROME_NORMAL; gboolean show_toolbar; - if (window->priv->metadata && - ev_metadata_get_boolean (window->priv->metadata, "show_toolbar", &show_toolbar)) { + if (window->priv->document) { + if (!window->priv->metadata || + !ev_metadata_get_boolean (window->priv->metadata, "show_toolbar", &show_toolbar)) { + show_toolbar = g_settings_get_boolean (window->priv->last_settings, "show-toolbar"); + } + if (!show_toolbar) chrome &= ~EV_CHROME_TOOLBAR; } + window->priv->chrome = chrome; } @@ -953,10 +959,11 @@ setup_sidebar_from_metadata (EvWindow *window) } } - if (ev_metadata_get_boolean (window->priv->metadata, "sidebar_visibility", &sidebar_visibility)) { - update_chrome_flag (window, EV_CHROME_SIDEBAR, sidebar_visibility); - update_chrome_visibility (window); - } + if (!ev_metadata_get_boolean (window->priv->metadata, "sidebar_visibility", &sidebar_visibility)) + sidebar_visibility = g_settings_get_boolean (window->priv->last_settings, "show-sidebar"); + + update_chrome_flag (window, EV_CHROME_SIDEBAR, sidebar_visibility); + update_chrome_visibility (window); } static void @@ -1064,8 +1071,8 @@ setup_document_from_metadata (EvWindow *window) ev_metadata_get_int (window->priv->metadata, "window_height", &height)) return; /* size was already set in setup_size_from_metadata */ - if (ev_metadata_get_double (window->priv->metadata, "window_width_ratio", &width_ratio) && - ev_metadata_get_double (window->priv->metadata, "window_height_ratio", &height_ratio)) { + g_settings_get (window->priv->last_settings, "window-ratio", "(dd)", &width_ratio, &height_ratio); + if (width_ratio > 0. && height_ratio > 0.) { gdouble document_width; gdouble document_height; GdkScreen *screen; @@ -1196,6 +1203,14 @@ ev_window_refresh_window_thumbnail (EvWindow *ev_window) ev_job_scheduler_push_job (ev_window->priv->thumbnail_job, EV_JOB_PRIORITY_NONE); } +static void +override_restrictions_changed (GSettings *settings, + gchar *key, + EvWindow *ev_window) +{ + ev_window_setup_action_sensitivity (ev_window); +} + #ifdef WITH_GCONF static void lockdown_changed (GConfClient *client, @@ -1222,6 +1237,12 @@ ev_window_setup_document (EvWindow *ev_window) ev_window_title_set_document (ev_window->priv->title, document); ev_window_title_set_uri (ev_window->priv->title, ev_window->priv->uri); + ev_window->priv->settings = g_settings_new (GS_SCHEMA_NAME); + g_signal_connect (ev_window->priv->settings, + "changed::"GS_OVERRIDE_RESTRICTIONS, + G_CALLBACK (override_restrictions_changed), + ev_window); + #ifdef WITH_GCONF if (!ev_window->priv->gconf_client) ev_window->priv->gconf_client = gconf_client_get_default (); @@ -1229,18 +1250,10 @@ ev_window_setup_document (EvWindow *ev_window) GCONF_LOCKDOWN_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); - gconf_client_add_dir (ev_window->priv->gconf_client, - GCONF_OVERRIDE_RESTRICTIONS, - GCONF_CLIENT_PRELOAD_NONE, - NULL); gconf_client_notify_add (ev_window->priv->gconf_client, GCONF_LOCKDOWN_DIR, (GConfClientNotifyFunc)lockdown_changed, ev_window, NULL, NULL); - gconf_client_notify_add (ev_window->priv->gconf_client, - GCONF_OVERRIDE_RESTRICTIONS, - (GConfClientNotifyFunc)lockdown_changed, - ev_window, NULL, NULL); #endif /* WITH_GCONF */ ev_window_setup_action_sensitivity (ev_window); @@ -2332,6 +2345,23 @@ ev_window_get_recent_file_label (gint index, const gchar *filename) return g_string_free (str, FALSE); } +static void +ev_window_recent_action_connect_proxy_cb (GtkActionGroup *action_group, + GtkAction *action, + GtkWidget *proxy, + gpointer data) +{ + GtkLabel *label; + + if (!GTK_IS_MENU_ITEM (proxy)) + return; + + label = GTK_LABEL (gtk_bin_get_child (GTK_BIN (proxy))); + + gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_MIDDLE); + gtk_label_set_max_width_chars (label, MAX_RECENT_ITEM_LEN); +} + static void ev_window_setup_recent (EvWindow *ev_window) { @@ -2353,8 +2383,11 @@ ev_window_setup_recent (EvWindow *ev_window) g_object_unref (ev_window->priv->recent_action_group); } ev_window->priv->recent_action_group = gtk_action_group_new ("RecentFilesActions"); + g_signal_connect (ev_window->priv->recent_action_group, "connect-proxy", + G_CALLBACK (ev_window_recent_action_connect_proxy_cb), NULL); + gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager, - ev_window->priv->recent_action_group, 0); + ev_window->priv->recent_action_group, -1); items = gtk_recent_manager_get_items (ev_window->priv->recent_manager); items = g_list_sort (items, (GCompareFunc) compare_recent_items); @@ -2364,6 +2397,9 @@ ev_window_setup_recent (EvWindow *ev_window) GtkAction *action; gchar *action_name; gchar *label; + const gchar *mime_type; + gchar *content_type; + GIcon *icon = NULL; info = (GtkRecentInfo *) l->data; @@ -2374,10 +2410,19 @@ ev_window_setup_recent (EvWindow *ev_window) action_name = g_strdup_printf ("RecentFile%u", i++); label = ev_window_get_recent_file_label ( n_items + 1, gtk_recent_info_get_display_name (info)); - + + mime_type = gtk_recent_info_get_mime_type (info); + content_type = g_content_type_from_mime_type (mime_type); + if (content_type != NULL) { + icon = g_content_type_get_icon (content_type); + g_free (content_type); + } + action = g_object_new (GTK_TYPE_ACTION, "name", action_name, "label", label, + "gicon", icon, + "always-show-image", TRUE, NULL); g_object_set_data_full (G_OBJECT (action), @@ -2402,6 +2447,8 @@ ev_window_setup_recent (EvWindow *ev_window) FALSE); g_free (action_name); g_free (label); + if (icon != NULL) + g_object_unref (icon); if (++n_items == 5) break; @@ -2880,43 +2927,6 @@ get_print_page_setup (GKeyFile *key_file) return page_setup ? page_setup : gtk_page_setup_new (); } -static void -ev_window_print_page_setup_done_cb (GtkPageSetup *page_setup, - EvWindow *window) -{ - /* Dialog was canceled */ - if (!page_setup) - return; - - ev_window_save_print_page_setup (window, page_setup); -} - -static void -ev_window_cmd_file_print_setup (GtkAction *action, - EvWindow *ev_window) -{ - GKeyFile *print_settings_file; - GtkPrintSettings *print_settings; - GtkPageSetup *print_page_setup; - - print_settings_file = get_print_settings_file (); - - print_settings = get_print_settings (print_settings_file); - ev_window_load_print_settings_from_metadata (ev_window, print_settings); - - print_page_setup = get_print_page_setup (print_settings_file); - ev_window_load_print_page_setup_from_metadata (ev_window, print_page_setup); - - gtk_print_run_page_setup_dialog_async (GTK_WINDOW (ev_window), - print_page_setup, - print_settings, - (GtkPageSetupDoneFunc)ev_window_print_page_setup_done_cb, - ev_window); - g_object_unref (print_settings); - g_object_unref (print_page_setup); - g_key_file_free (print_settings_file); -} - static void ev_window_print_cancel (EvWindow *ev_window) { @@ -3242,6 +3252,15 @@ ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window) gchar *text, *markup; gint n_print_jobs; + if (EV_WINDOW_IS_PRESENTATION (ev_window)) { + gint current_page; + + /* Save current page */ + current_page = ev_view_presentation_get_current_page ( + EV_VIEW_PRESENTATION (ev_window->priv->presentation_view)); + ev_document_model_set_page (ev_window->priv->model, current_page); + } + n_print_jobs = ev_window->priv->print_queue ? g_queue_get_length (ev_window->priv->print_queue) : 0; @@ -3603,6 +3622,7 @@ ev_window_run_presentation (EvWindow *window) gboolean fullscreen_window = TRUE; guint current_page; guint rotation; + gboolean inverted_colors; if (EV_WINDOW_IS_PRESENTATION (window)) return; @@ -3614,8 +3634,11 @@ ev_window_run_presentation (EvWindow *window) current_page = ev_document_model_get_page (window->priv->model); rotation = ev_document_model_get_rotation (window->priv->model); - window->priv->presentation_view = - ev_view_presentation_new (window->priv->document, current_page, rotation); + inverted_colors = ev_document_model_get_inverted_colors (window->priv->model); + window->priv->presentation_view = ev_view_presentation_new (window->priv->document, + current_page, + rotation, + inverted_colors); g_signal_connect_swapped (window->priv->presentation_view, "finished", G_CALLBACK (ev_window_view_presentation_finished), window); @@ -3844,6 +3867,7 @@ ev_window_cmd_edit_toolbar (GtkAction *action, EvWindow *ev_window) { GtkWidget *dialog; GtkWidget *editor; + GtkWidget *content_area; EggEditableToolbar *toolbar; dialog = gtk_dialog_new_with_buttons (_("Toolbar Editor"), @@ -3852,9 +3876,10 @@ ev_window_cmd_edit_toolbar (GtkAction *action, EvWindow *ev_window) GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL); + content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE); gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)), 5); - gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2); + gtk_box_set_spacing (GTK_BOX (content_area), 2); gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); gtk_window_set_default_size (GTK_WINDOW (dialog), 500, 400); @@ -3865,7 +3890,7 @@ ev_window_cmd_edit_toolbar (GtkAction *action, EvWindow *ev_window) gtk_container_set_border_width (GTK_CONTAINER (editor), 5); gtk_box_set_spacing (GTK_BOX (EGG_TOOLBAR_EDITOR (editor)), 5); - gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), editor); + gtk_container_add (GTK_CONTAINER (content_area), editor); egg_editable_toolbar_set_edit_mode (toolbar, TRUE); @@ -3967,13 +3992,19 @@ ev_window_cmd_view_autoscroll (GtkAction *action, EvWindow *ev_window) ev_view_autoscroll_start (EV_VIEW (ev_window->priv->view)); } +#if OFFLINE_HELP_ENABLED +#define EV_HELP "ghelp:evince" +#else +#define EV_HELP "http://library.gnome.org/users/evince/stable/" +#endif + static void ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window) { GError *error = NULL; gtk_show_uri (gtk_window_get_screen (GTK_WINDOW (ev_window)), - "ghelp:evince", + EV_HELP, gtk_get_current_event_time (), &error); if (error) { @@ -4230,7 +4261,7 @@ ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window) "GNU General Public License for more details.\n"), N_("You should have received a copy of the GNU General Public License " "along with Evince; if not, write to the Free Software Foundation, Inc., " - "59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n") + "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n") }; char *license_trans; @@ -4281,6 +4312,8 @@ ev_window_view_toolbar_cb (GtkAction *action, EvWindow *ev_window) update_chrome_visibility (ev_window); if (ev_window->priv->metadata) ev_metadata_set_boolean (ev_window->priv->metadata, "show_toolbar", active); + if (ev_window->priv->document) + g_settings_set_boolean (ev_window->priv->last_settings, "show-toolbar", active); } static void @@ -4332,12 +4365,15 @@ ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar, action = gtk_action_group_get_action (ev_window->priv->action_group, "ViewSidebar"); if (!EV_WINDOW_IS_PRESENTATION (ev_window)) { - gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), - GTK_WIDGET_VISIBLE (ev_sidebar)); + gboolean visible = gtk_widget_get_visible (GTK_WIDGET (ev_sidebar)); + + gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible); if (ev_window->priv->metadata) ev_metadata_set_boolean (ev_window->priv->metadata, "sidebar_visibility", - GTK_WIDGET_VISIBLE (ev_sidebar)); + visible); + if (ev_window->priv->document) + g_settings_set_boolean (ev_window->priv->last_settings, "show-sidebar", visible); } } @@ -4656,7 +4692,7 @@ find_bar_visibility_changed_cb (EggFindBar *find_bar, { gboolean visible; - visible = GTK_WIDGET_VISIBLE (find_bar); + visible = gtk_widget_get_visible (GTK_WIDGET (find_bar)); if (ev_window->priv->document && EV_IS_DOCUMENT_FIND (ev_window->priv->document)) { @@ -4827,6 +4863,16 @@ ev_window_dispose (GObject *object) priv->recent_manager = NULL; } + if (priv->settings) { + g_object_unref (priv->settings); + priv->settings = NULL; + } + + if (priv->last_settings) { + g_object_unref (priv->last_settings); + priv->last_settings = NULL; + } + priv->recent_ui_id = 0; if (priv->model) { @@ -4966,7 +5012,7 @@ ev_window_key_press_event (GtkWidget *widget, */ if (priv->view) { g_object_ref (priv->view); - if (GTK_WIDGET_IS_SENSITIVE (priv->view)) + if (gtk_widget_is_sensitive (priv->view)) handled = gtk_widget_event (priv->view, (GdkEvent*) event); g_object_unref (priv->view); } @@ -4977,7 +5023,7 @@ ev_window_key_press_event (GtkWidget *widget, if (priv->menubar_accel_keyval != 0 && event->keyval == priv->menubar_accel_keyval && modifier == priv->menubar_accel_modifier) { - if (!GTK_WIDGET_VISIBLE (priv->menubar)) { + if (!gtk_widget_get_visible (priv->menubar)) { g_signal_connect (priv->menubar, "deactivate", G_CALLBACK (menubar_deactivate_cb), ev_window); @@ -5032,9 +5078,6 @@ static const GtkActionEntry entries[] = { { "FileSaveAs", GTK_STOCK_SAVE_AS, N_("_Save a Copy…"), "S", N_("Save a copy of the current document"), G_CALLBACK (ev_window_cmd_save_as) }, - { "FilePageSetup", GTK_STOCK_PAGE_SETUP, N_("Page Set_up…"), NULL, - N_("Set up the page settings for printing"), - G_CALLBACK (ev_window_cmd_file_print_setup) }, { "FilePrint", GTK_STOCK_PRINT, N_("_Print…"), "P", N_("Print this document"), G_CALLBACK (ev_window_cmd_file_print) }, @@ -5443,16 +5486,16 @@ window_configure_event_cb (EvWindow *window, GdkEventConfigure *event, gpointer if (!window->priv->metadata) return FALSE; - state = gdk_window_get_state (GTK_WIDGET (window)->window); + state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (window))); if (!(state & GDK_WINDOW_STATE_FULLSCREEN)) { if (!ev_window_is_empty (window) && window->priv->document) { ev_document_get_max_page_size (window->priv->document, &document_width, &document_height); - ev_metadata_set_double (window->priv->metadata, "window_width_ratio", - (double)event->width / document_width); - ev_metadata_set_double (window->priv->metadata, "window_height_ratio", - (double)event->height / document_height); + g_settings_set (window->priv->last_settings, "window-ratio", "(dd)", + (double)event->width / document_width, + (double)event->height / document_height); + ev_metadata_set_int (window->priv->metadata, "window_x", event->x); ev_metadata_set_int (window->priv->metadata, "window_y", event->y); ev_metadata_set_int (window->priv->metadata, "window_width", event->width); @@ -6155,16 +6198,6 @@ ev_window_init (EvWindow *ev_window) } g_free (ui_path); -#if GTK_CHECK_VERSION (2, 17, 4) - { - GtkAction *action; - - action = gtk_action_group_get_action (ev_window->priv->action_group, - "FilePageSetup"); - g_object_set (action, "visible", FALSE, "sensitive", FALSE, NULL); - } -#endif - ev_window->priv->recent_manager = gtk_recent_manager_get_default (); ev_window->priv->recent_action_group = NULL; ev_window->priv->recent_ui_id = 0; @@ -6421,6 +6454,8 @@ ev_window_init (EvWindow *ev_window) /* Give focus to the document view */ gtk_widget_grab_focus (ev_window->priv->view); + ev_window->priv->last_settings = g_settings_new (GS_SCHEMA_NAME".Default"); + /* Set it user interface params */ ev_window_setup_recent (ev_window);