X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=inline;f=shell%2Fev-window.c;h=b4e87394b2768c25b0b16980af3562adcdbeee0d;hb=d52ff81f97f4bd3794e1517443096846baee068b;hp=a9a8736c6f4dcfb06b7924e37164f0b986c49021;hpb=80aa207c49dda77a013f0df2a2e2a393062a96b6;p=evince.git diff --git a/shell/ev-window.c b/shell/ev-window.c index a9a8736c..b4e87394 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; @@ -219,11 +223,13 @@ struct _EvWindowPrivate { #define NAVIGATION_ACTION "Navigation" #define GCONF_LOCKDOWN_DIR "/desktop/gnome/lockdown" -#define GCONF_OVERRIDE_RESTRICTIONS "/apps/evince/override_restrictions" #define GCONF_LOCKDOWN_SAVE "/desktop/gnome/lockdown/disable_save_to_disk" #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 +245,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 +383,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); @@ -433,11 +441,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); } @@ -568,7 +571,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); @@ -900,11 +903,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; } @@ -921,6 +929,15 @@ setup_sidebar_from_metadata (EvWindow *window) gint sidebar_size; gboolean sidebar_visibility; + if (document) { + if (!window->priv->metadata || + !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); + } + if (!window->priv->metadata) return; @@ -949,11 +966,6 @@ setup_sidebar_from_metadata (EvWindow *window) ev_sidebar_set_page (EV_SIDEBAR (sidebar), layers); } } - - 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); - } } static void @@ -1043,26 +1055,25 @@ setup_document_from_metadata (EvWindow *window) gdouble width_ratio; gdouble height_ratio; - if (!window->priv->metadata) - return; - - /* Make sure to not open a document on the last page, - * since closing it on the last page most likely means the - * user was finished reading the document. In that case, reopening should - * show the first page. */ - page = ev_document_model_get_page (window->priv->model); - n_pages = ev_document_get_n_pages (window->priv->document); - if (page == n_pages - 1) - ev_document_model_set_page (window->priv->model, 0); + if (window->priv->metadata) { + /* Make sure to not open a document on the last page, + * since closing it on the last page most likely means the + * user was finished reading the document. In that case, reopening should + * show the first page. */ + page = ev_document_model_get_page (window->priv->model); + n_pages = ev_document_get_n_pages (window->priv->document); + if (page == n_pages - 1) + ev_document_model_set_page (window->priv->model, 0); - setup_sidebar_from_metadata (window); + setup_sidebar_from_metadata (window); - if (ev_metadata_get_int (window->priv->metadata, "window_width", &width) && - ev_metadata_get_int (window->priv->metadata, "window_height", &height)) - return; /* size was already set in setup_size_from_metadata */ + if (ev_metadata_get_int (window->priv->metadata, "window_width", &width) && + 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; @@ -1078,7 +1089,7 @@ setup_document_from_metadata (EvWindow *window) screen = gtk_window_get_screen (GTK_WINDOW (window)); if (screen) { request_width = MIN (request_width, gdk_screen_get_width (screen)); - request_height = MIN (request_width, gdk_screen_get_height (screen)); + request_height = MIN (request_height, gdk_screen_get_height (screen)); } if (request_width > 0 && request_height > 0) { @@ -1193,6 +1204,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, @@ -1219,6 +1238,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 (); @@ -1226,18 +1251,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); @@ -1854,7 +1871,8 @@ ev_window_open_uri (EvWindow *ev_window, g_object_unref (ev_window->priv->metadata); source_file = g_file_new_for_uri (uri); - if (ev_is_metadata_supported_for_file (source_file)) + if (!ev_file_is_temp (source_file) && + ev_is_metadata_supported_for_file (source_file)) ev_window->priv->metadata = ev_metadata_new (source_file); else ev_window->priv->metadata = NULL; @@ -2329,6 +2347,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) { @@ -2350,8 +2385,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); @@ -2361,6 +2399,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; @@ -2371,10 +2412,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), @@ -2399,6 +2449,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; @@ -2579,6 +2631,8 @@ ev_window_save_job_cb (EvJob *job, ev_window_error_message (window, job->error, _("The file could not be saved as “%s”."), EV_JOB_SAVE (job)->uri); + } else { + ev_window_add_recent (window, EV_JOB_SAVE (job)->uri); } ev_window_clear_save_job (window); @@ -3572,6 +3626,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; @@ -3583,8 +3638,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); @@ -3938,13 +3996,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) { @@ -4201,7 +4265,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; @@ -4252,6 +4316,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 @@ -4310,6 +4376,8 @@ ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar, if (ev_window->priv->metadata) ev_metadata_set_boolean (ev_window->priv->metadata, "sidebar_visibility", visible); + if (ev_window->priv->document) + g_settings_set_boolean (ev_window->priv->last_settings, "show-sidebar", visible); } } @@ -4799,6 +4867,17 @@ 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_settings_apply (priv->last_settings); + g_object_unref (priv->last_settings); + priv->last_settings = NULL; + } + priv->recent_ui_id = 0; if (priv->model) { @@ -5415,13 +5494,13 @@ window_configure_event_cb (EvWindow *window, GdkEventConfigure *event, gpointer 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) { + if (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); @@ -6380,6 +6459,9 @@ 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"); + g_settings_delay (ev_window->priv->last_settings); + /* Set it user interface params */ ev_window_setup_recent (ev_window);