summaryrefslogtreecommitdiff
path: root/shell/ev-window.c
diff options
context:
space:
mode:
Diffstat (limited to 'shell/ev-window.c')
-rw-r--r--shell/ev-window.c213
1 files changed, 143 insertions, 70 deletions
diff --git a/shell/ev-window.c b/shell/ev-window.c
index 8a4553e4..4092d77f 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -253,6 +253,10 @@ struct _EvWindowPrivate {
#define GS_SCHEMA_NAME "org.mate.Atril"
#define GS_OVERRIDE_RESTRICTIONS "override-restrictions"
+#define GS_PAGE_CACHE_SIZE "page-cache-size"
+#define GS_AUTO_RELOAD "auto-reload"
+#define GS_LAST_DOCUMENT_DIRECTORY "document-directory"
+#define GS_LAST_PICTURES_DIRECTORY "pictures-directory"
#define SIDEBAR_DEFAULT_SIZE 132
#define LINKS_SIDEBAR_ID "links"
@@ -269,7 +273,6 @@ struct _EvWindowPrivate {
#define EV_TOOLBARS_FILENAME "atril-toolbar.xml"
#define MIN_SCALE 0.05409
-#define PAGE_CACHE_SIZE 52428800 /* 50MB */
#define MAX_RECENT_ITEM_LEN (40)
@@ -1376,6 +1379,18 @@ setup_view_from_metadata (EvWindow *window)
}
static void
+page_cache_size_changed (GSettings *settings,
+ gchar *key,
+ EvWindow *ev_window)
+{
+ guint page_cache_mb;
+
+ page_cache_mb = g_settings_get_uint (settings, GS_PAGE_CACHE_SIZE);
+ ev_view_set_page_cache_size (EV_VIEW (ev_window->priv->view),
+ page_cache_mb * 1024 * 1024);
+}
+
+static void
ev_window_setup_default (EvWindow *ev_window)
{
EvDocumentModel *model = ev_window->priv->model;
@@ -1478,6 +1493,27 @@ lockdown_changed (GSettings *settings,
ev_window_setup_action_sensitivity (ev_window);
}
+static GSettings *
+ev_window_ensure_settings (EvWindow *ev_window)
+{
+ EvWindowPrivate *priv = ev_window->priv;
+
+ if (priv->settings != NULL)
+ return priv->settings;
+
+ priv->settings = g_settings_new (GS_SCHEMA_NAME);
+ g_signal_connect (priv->settings,
+ "changed::"GS_OVERRIDE_RESTRICTIONS,
+ G_CALLBACK (override_restrictions_changed),
+ ev_window);
+ g_signal_connect (priv->settings,
+ "changed::"GS_PAGE_CACHE_SIZE,
+ G_CALLBACK (page_cache_size_changed),
+ ev_window);
+
+ return priv->settings;
+}
+
static gboolean
ev_window_setup_document (EvWindow *ev_window)
{
@@ -1493,13 +1529,7 @@ 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);
- if (!ev_window->priv->settings) {
- 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);
- }
+ ev_window_ensure_settings (ev_window);
#ifdef WITH_MATEDESKTOP
if (mate_gsettings_schema_exists (MATE_LOCKDOWN_SCHEMA)) {
@@ -1629,7 +1659,9 @@ static void
ev_window_document_changed (EvWindow *ev_window,
gpointer user_data)
{
- ev_window_reload_document (ev_window, NULL);
+ if (ev_window->priv->settings &&
+ g_settings_get_boolean (ev_window->priv->settings, GS_AUTO_RELOAD))
+ ev_window_reload_document (ev_window, NULL);
}
static void
@@ -2189,7 +2221,7 @@ ev_window_open_uri (EvWindow *ev_window,
g_object_unref (ev_window->priv->bookmarks);
source_file = g_file_new_for_uri (uri);
- if (!ev_file_is_temp (source_file) && ev_is_metadata_supported_for_file (source_file)) {
+ if (ev_is_metadata_supported_for_file (source_file)) {
ev_window->priv->metadata = ev_metadata_new (source_file);
ev_window_init_metadata_with_default_values (ev_window);
} else {
@@ -2471,6 +2503,75 @@ ev_window_reload_document (EvWindow *ev_window,
}
}
+static const gchar *
+get_settings_key_for_directory (GUserDirectory directory)
+{
+ switch (directory) {
+ case G_USER_DIRECTORY_PICTURES:
+ return GS_LAST_PICTURES_DIRECTORY;
+ case G_USER_DIRECTORY_DOCUMENTS:
+ default:
+ return GS_LAST_DOCUMENT_DIRECTORY;
+ }
+}
+
+static void
+ev_window_file_chooser_restore_folder (EvWindow *window,
+ GtkFileChooser *file_chooser,
+ const gchar *uri,
+ GUserDirectory directory)
+{
+ const gchar *dir;
+ gchar *folder_uri;
+
+ g_settings_get (ev_window_ensure_settings (window),
+ get_settings_key_for_directory (directory),
+ "ms", &folder_uri);
+ if (folder_uri == NULL && uri != NULL) {
+ GFile *file, *parent;
+
+ file = g_file_new_for_uri (uri);
+ parent = g_file_get_parent (file);
+ g_object_unref (file);
+ if (parent) {
+ folder_uri = g_file_get_uri (parent);
+ g_object_unref (parent);
+ }
+ }
+
+ if (folder_uri) {
+ gtk_file_chooser_set_current_folder_uri (file_chooser, folder_uri);
+ } else {
+ dir = g_get_user_special_dir (directory);
+ gtk_file_chooser_set_current_folder (file_chooser,
+ dir ? dir : g_get_home_dir ());
+ }
+
+ g_free (folder_uri);
+}
+
+static void
+ev_window_file_chooser_save_folder (EvWindow *window,
+ GtkFileChooser *file_chooser,
+ GUserDirectory directory)
+{
+ gchar *uri, *folder;
+
+ folder = gtk_file_chooser_get_current_folder (file_chooser);
+ if (g_strcmp0 (folder, g_get_user_special_dir (directory)) == 0) {
+ /* Store 'nothing' if the folder is the default one */
+ uri = NULL;
+ } else {
+ uri = gtk_file_chooser_get_current_folder_uri (file_chooser);
+ }
+ g_free (folder);
+
+ g_settings_set (ev_window_ensure_settings (window),
+ get_settings_key_for_directory (directory),
+ "ms", uri);
+ g_free (uri);
+}
+
static void
file_open_dialog_response_cb (GtkWidget *chooser,
gint response_id,
@@ -2478,7 +2579,9 @@ file_open_dialog_response_cb (GtkWidget *chooser,
{
if (response_id == GTK_RESPONSE_OK) {
GSList *uris;
- gchar *uri;
+
+ ev_window_file_chooser_save_folder (ev_window, GTK_FILE_CHOOSER (chooser),
+ G_USER_DIRECTORY_DOCUMENTS);
uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (chooser));
@@ -2489,11 +2592,6 @@ file_open_dialog_response_cb (GtkWidget *chooser,
g_slist_foreach (uris, (GFunc)g_free, NULL);
g_slist_free (uris);
- uri = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (chooser));
- ev_application_set_filechooser_uri (EV_APP,
- GTK_FILE_CHOOSER_ACTION_OPEN,
- uri);
- g_free (uri);
}
gtk_widget_destroy (chooser);
@@ -2503,8 +2601,6 @@ static void
ev_window_cmd_file_open (GtkAction *action, EvWindow *window)
{
GtkWidget *chooser;
- const gchar *default_uri;
- gchar *parent_uri = NULL;
chooser = gtk_file_chooser_dialog_new (_("Open Document"),
GTK_WINDOW (window),
@@ -2518,30 +2614,8 @@ ev_window_cmd_file_open (GtkAction *action, EvWindow *window)
gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (chooser), TRUE);
gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), FALSE);
- default_uri = ev_application_get_filechooser_uri (EV_APP, GTK_FILE_CHOOSER_ACTION_OPEN);
- if (!default_uri && window->priv->uri) {
- GFile *file, *parent;
-
- file = g_file_new_for_uri (window->priv->uri);
- parent = g_file_get_parent (file);
- if (parent) {
- parent_uri = g_file_get_uri (parent);
- default_uri = parent_uri;
- g_object_unref (parent);
- }
- g_object_unref (file);
- }
-
- if (default_uri) {
- gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (chooser), default_uri);
- } else {
- const gchar *folder;
-
- folder = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
- folder ? folder : g_get_home_dir ());
- }
- g_free (parent_uri);
+ ev_window_file_chooser_restore_folder (window, GTK_FILE_CHOOSER (chooser),
+ NULL, G_USER_DIRECTORY_DOCUMENTS);
g_signal_connect (chooser, "response",
G_CALLBACK (file_open_dialog_response_cb),
@@ -2969,27 +3043,16 @@ file_save_dialog_response_cb (GtkWidget *fc,
EvWindow *ev_window)
{
gchar *uri;
- GFile *file, *parent;
if (response_id != GTK_RESPONSE_OK) {
gtk_widget_destroy (fc);
return;
}
- uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
- file = g_file_new_for_uri (uri);
- parent = g_file_get_parent (file);
- g_object_unref (file);
- if (parent) {
- gchar *folder_uri;
+ ev_window_file_chooser_save_folder (ev_window, GTK_FILE_CHOOSER (fc),
+ G_USER_DIRECTORY_DOCUMENTS);
- folder_uri = g_file_get_uri (parent);
- ev_application_set_filechooser_uri (EV_APP,
- GTK_FILE_CHOOSER_ACTION_SAVE,
- folder_uri);
- g_free (folder_uri);
- g_object_unref (parent);
- }
+ uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
/* FIXME: remote copy should be done here rather than in the save job,
* so that we can track progress and cancel the operation
@@ -3014,7 +3077,6 @@ ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
GtkWidget *fc;
gchar *base_name;
GFile *file;
- const gchar *default_uri;
fc = gtk_file_chooser_dialog_new (
_("Save a Copy"),
@@ -3036,20 +3098,13 @@ ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
base_name = g_file_get_basename (file);
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), base_name);
- default_uri = ev_application_get_filechooser_uri (EV_APP, GTK_FILE_CHOOSER_ACTION_SAVE);
- if (default_uri) {
- gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (fc), default_uri);
- } else {
- const gchar *folder;
-
- folder = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fc),
- folder ? folder : g_get_home_dir ());
- }
-
g_object_unref (file);
g_free (base_name);
+ ev_window_file_chooser_restore_folder (ev_window, GTK_FILE_CHOOSER (fc),
+ ev_window->priv->uri,
+ G_USER_DIRECTORY_DOCUMENTS);
+
g_signal_connect (fc, "response",
G_CALLBACK (file_save_dialog_response_cb),
ev_window);
@@ -4297,17 +4352,19 @@ ev_window_update_max_min_scale (EvWindow *window)
gdouble min_width, min_height;
gdouble width, height;
gdouble max_scale;
+ guint page_cache_mb;
gint rotation = ev_document_model_get_rotation (window->priv->model);
if (!window->priv->document)
return;
+ page_cache_mb = g_settings_get_uint (window->priv->settings, GS_PAGE_CACHE_SIZE);
dpi = get_screen_dpi (window) / 72.0;
ev_document_get_min_page_size (window->priv->document, &min_width, &min_height);
width = (rotation == 0 || rotation == 180) ? min_width : min_height;
height = (rotation == 0 || rotation == 180) ? min_height : min_width;
- max_scale = sqrt (PAGE_CACHE_SIZE / (width * dpi * 4 * height * dpi));
+ max_scale = sqrt ((page_cache_mb * 1024 * 1024) / (width * dpi * 4 * height * dpi));
action = gtk_action_group_get_action (window->priv->action_group,
ZOOM_CONTROL_ACTION);
@@ -6783,6 +6840,9 @@ image_save_dialog_response_cb (GtkWidget *fc,
return;
}
+ ev_window_file_chooser_save_folder (ev_window, GTK_FILE_CHOOSER (fc),
+ G_USER_DIRECTORY_PICTURES);
+
uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (fc));
format = g_object_get_data (G_OBJECT (filter), "pixbuf-format");
@@ -6885,6 +6945,9 @@ ev_view_popup_cmd_save_image_as (GtkAction *action, EvWindow *window)
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
file_chooser_dialog_add_writable_pixbuf_formats (GTK_FILE_CHOOSER (fc));
+
+ ev_window_file_chooser_restore_folder (window, GTK_FILE_CHOOSER (fc), NULL,
+ G_USER_DIRECTORY_PICTURES);
g_signal_connect (fc, "response",
G_CALLBACK (image_save_dialog_response_cb),
@@ -7020,6 +7083,9 @@ attachment_save_dialog_response_cb (GtkWidget *fc,
return;
}
+ ev_window_file_chooser_save_folder (ev_window, GTK_FILE_CHOOSER (fc),
+ G_USER_DIRECTORY_DOCUMENTS);
+
uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
target_file = g_file_new_for_uri (uri);
g_object_get (G_OBJECT (fc), "action", &fc_action, NULL);
@@ -7116,6 +7182,9 @@ ev_attachment_popup_cmd_save_attachment_as (GtkAction *action, EvWindow *window)
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc),
ev_attachment_get_name (attachment));
+ ev_window_file_chooser_restore_folder (window, GTK_FILE_CHOOSER (fc), NULL,
+ G_USER_DIRECTORY_DOCUMENTS);
+
g_signal_connect (fc, "response",
G_CALLBACK (attachment_save_dialog_response_cb),
window);
@@ -7395,6 +7464,7 @@ ev_window_init (EvWindow *ev_window)
GtkWidget *menuitem;
EggToolbarsModel *toolbars_model;
GObject *mpkeys;
+ guint page_cache_mb;
gchar *ui_path;
#ifdef ENABLE_DBUS
GDBusConnection *connection;
@@ -7669,7 +7739,10 @@ ev_window_init (EvWindow *ev_window)
ev_window, 0);
#endif
#endif
- ev_view_set_page_cache_size (EV_VIEW (ev_window->priv->view), PAGE_CACHE_SIZE);
+ page_cache_mb = g_settings_get_uint (ev_window_ensure_settings (ev_window),
+ GS_PAGE_CACHE_SIZE);
+ ev_view_set_page_cache_size (EV_VIEW (ev_window->priv->view),
+ page_cache_mb * 1024 * 1024);
ev_view_set_model (EV_VIEW (ev_window->priv->view), ev_window->priv->model);
ev_window->priv->password_view = ev_password_view_new (GTK_WINDOW (ev_window));