#include <glib/gi18n.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
-#if GTK_CHECK_VERSION (2, 14, 0)
#include <gtk/gtkunixprint.h>
-#else
-#include <gtk/gtkprintunixdialog.h>
-#endif
+
#ifdef WITH_GCONF
#include <gconf/gconf-client.h>
#endif
#include "ev-jobs.h"
#include "ev-message-area.h"
#include "ev-metadata-manager.h"
-#include "ev-mount-operation.h"
#include "ev-navigation-action.h"
#include "ev-open-recent-action.h"
#include "ev-page-action.h"
}
static void
-ev_window_clear_temp_file (EvWindow *ev_window)
+ev_window_clear_temp_symlink (EvWindow *ev_window)
{
GFile *file, *tempdir;
return;
file = g_file_new_for_uri (ev_window->priv->uri);
- tempdir = g_file_new_for_path (g_get_tmp_dir ());
+ tempdir = g_file_new_for_path (ev_tmp_dir ());
if (g_file_has_prefix (file, tempdir)) {
- g_file_delete (file, NULL, NULL);
+ GFileInfo *file_info;
+ GError *error = NULL;
+
+ file_info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL, &error);
+ if (file_info) {
+ if (g_file_info_get_is_symlink (file_info))
+ g_file_delete (file, NULL, NULL);
+ g_object_unref (file_info);
+ } else {
+ g_warning ("Error deleting temp symlink: %s\n", error->message);
+ g_error_free (error);
+ }
}
g_object_unref (file);
return;
}
- if (error->domain == G_IO_ERROR &&
- error->code == G_IO_ERROR_NOT_MOUNTED) {
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_MOUNTED)) {
GMountOperation *operation;
- operation = ev_mount_operation_new (GTK_WINDOW (ev_window));
+ operation = gtk_mount_operation_new (GTK_WINDOW (ev_window));
g_file_mount_enclosing_volume (source,
G_MOUNT_MOUNT_NONE,
operation, NULL,
(GAsyncReadyCallback)mount_volume_ready_cb,
ev_window);
g_object_unref (operation);
- } else if (error->domain == G_IO_ERROR &&
- error->code == G_IO_ERROR_CANCELLED) {
+ } else if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
ev_window_clear_load_job (ev_window);
ev_window_clear_local_uri (ev_window);
g_free (ev_window->priv->uri);
g_file_copy_finish (remote, async_result, &error);
if (error) {
- if (error->domain != G_IO_ERROR ||
- error->code != G_IO_ERROR_CANCELLED)
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
ev_window_error_message (ev_window, error,
"%s", _("Failed to reload document."));
g_error_free (error);
static gchar *
ev_window_create_tmp_symlink (const gchar *filename, GError **error)
{
- gchar *tmp_filename = NULL;
- gchar *name;
- gint res;
- guint i = 0;
+ gchar *tmp_filename = NULL;
+ gchar *name;
+ guint i = 0;
+ GError *link_error = NULL;
+ GFile *tmp_file = NULL;
name = g_path_get_basename (filename);
if (tmp_filename)
g_free (tmp_filename);
+ if (tmp_file)
+ g_object_unref (tmp_file);
+ g_clear_error (&link_error);
basename = g_strdup_printf ("%s-%d", name, i++);
tmp_filename = g_build_filename (ev_tmp_dir (),
basename, NULL);
g_free (basename);
- } while ((res = symlink (filename, tmp_filename)) != 0 && errno == EEXIST);
-
- g_free (name);
+ tmp_file = g_file_new_for_path (tmp_filename);
+ } while (!g_file_make_symbolic_link (tmp_file, filename, NULL, &link_error) &&
+ g_error_matches (link_error, G_IO_ERROR, G_IO_ERROR_EXISTS));
- if (res != 0 && errno != EEXIST) {
- if (error) {
- *error = g_error_new (G_FILE_ERROR,
- g_file_error_from_errno (errno),
- _("Couldn't create symlink ā%sā: %s"),
- tmp_filename, strerror (errno));
- }
+ g_free (name);
+ g_object_unref (tmp_file);
+ if (link_error) {
+ g_propagate_prefixed_error (error,
+ link_error,
+ _("Couldn't create symlink ā%sā: "),
+ tmp_filename);
g_free (tmp_filename);
-
+
return NULL;
}
-
+
return tmp_filename;
}
return;
}
- if (error->domain != G_IO_ERROR ||
- error->code != G_IO_ERROR_CANCELLED) {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
gchar *name;
name = g_file_get_basename (dst);
ev_view_autoscroll_start (EV_VIEW (ev_window->priv->view));
}
-#if GTK_CHECK_VERSION (2, 14, 0)
static void
ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
{
g_error_free (error);
}
}
-#else /* !GTK_CHECK_VERSION (2, 14, 0) */
-static void
-ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
-{
- GError *error = NULL;
- GdkScreen *screen;
- char *command;
- const char *lang;
- char *uri = NULL;
-
- int i;
-
- const char * const * langs = g_get_language_names ();
-
- for (i = 0; langs[i]; i++) {
- lang = langs[i];
- if (strchr (lang, '.')) {
- continue;
- }
-
- uri = g_build_filename(GNOMEDATADIR,
- "/gnome/help/" PACKAGE,
- lang,
- "/evince.xml",
- NULL);
-
- if (g_file_test (uri, G_FILE_TEST_EXISTS)) {
- break;
- }
- g_free (uri);
- uri = NULL;
- }
-
- if (uri == NULL) {
- g_warning ("Cannot find help");
- return;
- }
-
- command = g_strconcat ("gnome-help ghelp://", uri, NULL);
- g_free (uri);
-
- screen = gtk_widget_get_screen (GTK_WIDGET (ev_window));
- gdk_spawn_command_line_on_screen (screen, command, &error);
- if (error != NULL) {
- g_warning ("%s", error->message);
- g_error_free (error);
- }
- g_free (command);
-}
-#endif /* GTK_CHECK_VERSION (2, 14, 0) */
static void
ev_window_cmd_leave_fullscreen (GtkAction *action, EvWindow *window)
}
if (priv->uri) {
+ /* Delete the uri if it's a temp symlink (open a copy) */
+ ev_window_clear_temp_symlink (window);
g_free (priv->uri);
priv->uri = NULL;
}
GAppInfo *app_info;
GFile *file;
GList file_list = {NULL};
- GAppLaunchContext *context = NULL;
+ GAppLaunchContext *context;
GError *error = NULL;
if (filename == NULL)
return;
}
-#if GTK_CHECK_VERSION (2, 14, 0)
context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context),
gtk_window_get_screen (GTK_WINDOW (window)));
gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context), GDK_CURRENT_TIME);
-#endif
file_list.data = file;
if (!g_app_info_launch (app_info, &file_list, context, &error)) {
const gchar *uri = ev_link_action_get_uri (action);
GError *error = NULL;
gboolean ret;
-#if GTK_CHECK_VERSION (2, 14, 0)
- GAppLaunchContext *context = NULL;
-#endif
+ GAppLaunchContext *context;
-#if GTK_CHECK_VERSION (2, 14, 0)
context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context),
gtk_window_get_screen (GTK_WINDOW (window)));
gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context),
GDK_CURRENT_TIME);
-#endif
if (!g_strstr_len (uri, strlen (uri), "://") &&
!g_str_has_prefix (uri, "mailto:")) {