#include <string.h>
+char *xdg_user_dir_lookup (char *type);
+
typedef enum {
PAGE_MODE_DOCUMENT,
PAGE_MODE_PASSWORD
}
}
+/**
+ * ev_window_is_empty:
+ * @ev_window: The instance of the #EvWindow.
+ *
+ * It does look if there is any document loaded or if there is any job to load
+ * a document.
+ *
+ * Returns: %TRUE if there isn't any document loaded or any any documente to be
+ * loaded, %FALSE in other case.
+ */
gboolean
ev_window_is_empty (const EvWindow *ev_window)
{
if (window->priv->page_cache &&
ev_metadata_manager_get (uri, "window_width_ratio", &width_ratio, FALSE) &&
ev_metadata_manager_get (uri, "window_height_ratio", &height_ratio, FALSE)) {
+
gint document_width;
gint document_height;
+
+ GdkScreen *screen;
+
+ gint request_width;
+ gint request_height;
ev_page_cache_get_max_width (window->priv->page_cache,
0, 1.0,
0, 1.0,
&document_height);
+ request_width = g_value_get_double (&width_ratio) * document_width;
+ request_height = g_value_get_double (&height_ratio) * document_height;
+
+ 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));
+ }
+
gtk_window_resize (GTK_WINDOW (window),
- g_value_get_double (&width_ratio) * document_width,
- g_value_get_double (&height_ratio) * document_height);
+ request_width,
+ request_height);
g_value_unset (&width_ratio);
g_value_unset (&height_ratio);
}
g_object_unref (ev_window->priv->document);
ev_window->priv->document = g_object_ref (document);
- if (!ev_window->priv->unlink_temp_file) {
+ if (job->mode != EV_WINDOW_MODE_PREVIEW) {
setup_view_from_metadata (ev_window);
+ }
+
+ if (!ev_window->priv->unlink_temp_file) {
ev_window_add_recent (ev_window, ev_window->priv->uri);
}
return;
}
+/**
+ * ev_window_get_uri:
+ * @ev_window: The instance of the #EvWindow.
+ *
+ * It returns the uri of the document showed in the #EvWindow.
+ *
+ * Returns: the uri of the document showed in the #EvWindow.
+ */
const char *
ev_window_get_uri (EvWindow *ev_window)
{
return ev_window->priv->uri;
}
+/**
+ * ev_window_close_dialogs:
+ * @ev_window: The window where dialogs will be closed.
+ *
+ * It looks for password, print and properties dialogs and closes them and
+ * frees them from memory. If there is any print job it does free it too.
+ */
static void
ev_window_close_dialogs (EvWindow *ev_window)
{
gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (chooser),
window->priv->uri);
}
+ else {
+ char *folder;
+ folder = xdg_user_dir_lookup ("DOCUMENTS");
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
+ folder);
+ free (folder);
+ }
g_signal_connect (chooser, "response",
G_CALLBACK (file_open_dialog_response_cb),
static void
ev_window_cmd_file_open_copy_at_dest (EvWindow *window, EvLinkDest *dest)
{
- GError *error = NULL;
- gchar *symlink_uri;
- gchar *old_filename;
- gchar *new_filename;
- gchar *uri_unc;
+ GError *error = NULL;
+ gchar *symlink_uri;
+ gchar *old_filename;
+ gchar *new_filename;
+ const gchar *uri_unc;
uri_unc = g_object_get_data (G_OBJECT (window->priv->document),
"uri-uncompressed");
p = filename;
end = filename + length;
- while (p != end)
- {
+ while (p != end) {
const gchar *next;
next = g_utf8_next_char (p);
- switch (*p)
- {
+ switch (*p) {
case '_':
g_string_append (str, "__");
break;
gint response_id,
EvWindow *ev_window)
{
- gboolean success;
+ const gchar *uri_unc;
+ gint fd;
+ gchar *filename;
+ gchar *tmp_filename;
+ GError *error = NULL;
- if (response_id == GTK_RESPONSE_OK) {
- gint fd;
- gchar *filename;
- gchar *tmp_filename;
- GError *error = NULL;
+ if (response_id != GTK_RESPONSE_OK) {
+ gtk_widget_destroy (fc);
+ return;
+ }
+
- filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fc));
- tmp_filename = g_strdup_printf ("%s.XXXXXX", filename);
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fc));
+ tmp_filename = g_strdup_printf ("%s.XXXXXX", filename);
+
+ fd = g_mkstemp (tmp_filename);
+ if (fd == -1) {
+ gchar *display_name;
+ gint save_errno = errno;
- fd = g_mkstemp (tmp_filename);
- if (fd == -1) {
- gchar *display_name;
- gint save_errno = errno;
-
- display_name = g_filename_display_name (tmp_filename);
- g_set_error (&error,
- G_FILE_ERROR,
- g_file_error_from_errno (save_errno),
- _("Failed to create file “%s”: %s"),
- display_name, g_strerror (save_errno));
- g_free (display_name);
- } else {
- gchar *uri;
+ display_name = g_filename_display_name (tmp_filename);
+ g_set_error (&error,
+ G_FILE_ERROR,
+ g_file_error_from_errno (save_errno),
+ _("Failed to create file “%s”: %s"),
+ display_name, g_strerror (save_errno));
+ g_free (display_name);
+ } else {
+ gchar *uri;
+
+ uri = g_filename_to_uri (tmp_filename, NULL, NULL);
+
+ ev_document_doc_mutex_lock ();
+ ev_document_save (ev_window->priv->document, uri, &error);
+ ev_document_doc_mutex_unlock ();
+
+ g_free (uri);
+ close (fd);
+ }
- uri = g_filename_to_uri (tmp_filename, NULL, NULL);
-
- ev_document_doc_mutex_lock ();
- success = ev_document_save (ev_window->priv->document,
- uri,
- &error);
- ev_document_doc_mutex_unlock ();
+ if (!error) {
+ uri_unc = g_object_get_data (G_OBJECT (ev_window->priv->document),
+ "uri-uncompressed");
+ if (uri_unc) {
+ EvCompressionType ctype;
+ gchar *uri_comp;
+ gchar *uri;
+ const gchar *ext;
+ ctype = EV_COMPRESSION_NONE;
+
+ ext = g_strrstr (ev_window->priv->uri, ".gz");
+ if (ext && g_ascii_strcasecmp (ext, ".gz") == 0)
+ ctype = EV_COMPRESSION_GZIP;
+
+ ext = g_strrstr (ev_window->priv->uri, ".bz2");
+ if (ext && g_ascii_strcasecmp (ext, ".bz2") == 0)
+ ctype = EV_COMPRESSION_BZIP2;
+
+ uri = g_filename_to_uri (tmp_filename, NULL, NULL);
+ uri_comp = ev_file_compress (uri, ctype, &error);
g_free (uri);
- close (fd);
- }
+ g_unlink (tmp_filename);
+ g_free (tmp_filename);
- if (!error) {
- if (g_rename (tmp_filename, filename) == -1) {
- g_unlink (tmp_filename);
+ if (!uri_comp || error) {
+ tmp_filename = NULL;
+ } else {
+ tmp_filename = g_filename_from_uri (uri_comp,
+ NULL, NULL);
}
- } else {
- gchar *msg;
- gchar *uri;
-
- uri = g_filename_to_uri (filename, NULL, NULL);
- msg = g_strdup_printf (_("The file could not be saved as “%s”."), uri);
- ev_window_error_dialog (GTK_WINDOW (ev_window), msg, error);
- g_free (msg);
- g_free (uri);
- g_error_free (error);
+
+ g_free (uri_comp);
}
+ }
+
+ if (tmp_filename && g_rename (tmp_filename, filename) == -1) {
+ g_unlink (tmp_filename);
+ }
+
+ if (error) {
+ gchar *msg;
+ gchar *uri;
- g_free (tmp_filename);
- g_free (filename);
+ uri = g_filename_to_uri (filename, NULL, NULL);
+ msg = g_strdup_printf (_("The file could not be saved as “%s”."), uri);
+ ev_window_error_dialog (GTK_WINDOW (ev_window), msg, error);
+ g_free (msg);
+ g_free (uri);
+ g_error_free (error);
}
+
+ g_free (tmp_filename);
+ g_free (filename);
gtk_widget_destroy (fc);
}
GtkWidget *fc;
gchar *base_name;
gchar *file_name;
+ gchar *folder;
fc = gtk_file_chooser_dialog_new (
_("Save a Copy"),
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER (fc), TRUE);
file_name = gnome_vfs_format_uri_for_display (ev_window->priv->uri);
base_name = g_path_get_basename (file_name);
+ folder = xdg_user_dir_lookup ("DOCUMENTS");
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), base_name);
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fc), folder);
g_free (file_name);
g_free (base_name);
-
+ free (folder);
+
g_signal_connect (fc, "response",
G_CALLBACK (file_save_dialog_response_cb),
ev_window);
{ "FileOpen", GTK_STOCK_OPEN, N_("_Open..."), "<control>O",
N_("Open an existing document"),
G_CALLBACK (ev_window_cmd_file_open) },
- { "FileOpenCopy", NULL, N_("Open a _Copy"), NULL,
+ { "FileOpenCopy", NULL, N_("Op_en a Copy"), NULL,
N_("Open a copy of the current document in a new window"),
G_CALLBACK (ev_window_cmd_file_open_copy) },
{ "FileSaveAs", GTK_STOCK_SAVE_AS, N_("_Save a Copy..."), "<control>S",
allowing to launch executables is a good idea though. -- marco */
}
+static gboolean
+uri_is_valid (const gchar *uri)
+{
+ gchar *p = (gchar *) uri;
+
+ if (!p || !g_ascii_isalpha (*p))
+ return FALSE;
+
+ p++;
+ while (g_ascii_isalnum (*p))
+ p++;
+
+ return (g_ascii_strncasecmp (p, "://", strlen ("://")) == 0);
+}
+
static void
launch_external_uri (EvWindow *window, EvLinkAction *action)
{
- gnome_vfs_url_show (ev_link_action_get_uri (action));
+ const gchar *uri = ev_link_action_get_uri (action);
+
+ if (!uri_is_valid (uri)) {
+ GtkWidget *dialog;
+
+ dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ _("Unable to open external link"));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ _("Invalid URI: “%s”"), uri);
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (gtk_widget_destroy),
+ NULL);
+ gtk_widget_show (dialog);
+
+ return;
+ }
+
+ gnome_vfs_url_show (uri);
}
static void
ev_window_setup_action_sensitivity (ev_window);
}
+/**
+ * ev_window_new:
+ *
+ * Creates a #GtkWidget that represents the window.
+ *
+ * Returns: the #GtkWidget that represents the window.
+ */
GtkWidget *
ev_window_new (void)
{