]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-window.c
Take default settings from last document opened
[evince.git] / shell / ev-window.c
index a9a8736c6f4dcfb06b7924e37164f0b986c49021..87ec655ba796580d8b4b3231175d9f32271fa1eb 100644 (file)
@@ -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);
@@ -433,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);
 }
 
@@ -568,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);
@@ -900,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;
 }
 
@@ -950,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
@@ -1061,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;
@@ -1193,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,
@@ -1219,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 ();
@@ -1226,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);
@@ -2329,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)
 {
@@ -2350,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);
@@ -2361,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;
 
@@ -2371,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),
@@ -2399,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;
@@ -3572,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;
@@ -3583,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);
@@ -3938,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) {
@@ -4201,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;
@@ -4252,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
@@ -4310,6 +4372,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 +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) {
@@ -5418,10 +5492,10 @@ window_configure_event_cb (EvWindow *window, GdkEventConfigure *event, gpointer
                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);
@@ -6380,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);