]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-window.c
Remove gs stuff from ps backend.
[evince.git] / shell / ev-window.c
index 3431fad5cd0b3528f0a172d87bc243f29bcccff3..fe05cec093a29fbe0fc1b669fd90c026a92adc3b 100644 (file)
@@ -231,11 +231,13 @@ static void     ev_window_zoom_changed_cb                 (EvView           *view,
 static void     ev_window_add_recent                    (EvWindow         *window,
                                                         const char       *filename);
 static void     ev_window_run_fullscreen                (EvWindow         *window);
 static void     ev_window_add_recent                    (EvWindow         *window,
                                                         const char       *filename);
 static void     ev_window_run_fullscreen                (EvWindow         *window);
-static void     ev_window_stop_fullscreen               (EvWindow         *window);
+static void     ev_window_stop_fullscreen               (EvWindow         *window,
+                                                        gboolean          unfullscreen_window);
 static void     ev_window_cmd_view_fullscreen           (GtkAction        *action,
                                                         EvWindow         *window);
 static void     ev_window_run_presentation              (EvWindow         *window);
 static void     ev_window_cmd_view_fullscreen           (GtkAction        *action,
                                                         EvWindow         *window);
 static void     ev_window_run_presentation              (EvWindow         *window);
-static void     ev_window_stop_presentation             (EvWindow         *window);
+static void     ev_window_stop_presentation             (EvWindow         *window,
+                                                        gboolean          unfullscreen_window);
 static void     ev_window_cmd_view_presentation         (GtkAction        *action,
                                                         EvWindow         *window);
 static void     ev_window_run_preview                   (EvWindow         *window);
 static void     ev_window_cmd_view_presentation         (GtkAction        *action,
                                                         EvWindow         *window);
 static void     ev_window_run_preview                   (EvWindow         *window);
@@ -1429,11 +1431,64 @@ window_open_file_copy_ready_cb (GFile        *source,
                                GAsyncResult *async_result,
                                EvWindow     *ev_window)
 {
                                GAsyncResult *async_result,
                                EvWindow     *ev_window)
 {
-       g_file_copy_finish (source, async_result, NULL);
-       ev_job_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH);
+       GError *error = NULL;
+       
+       g_file_copy_finish (source, async_result, &error);
+       if (!error) {
+               ev_job_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH);
+               g_object_unref (source);
+               
+               return;
+       }
+
+       if (error->domain == G_IO_ERROR &&
+           error->code == G_IO_ERROR_NOT_MOUNTED) {
+               /* TODO: try to mount */
+       }
+
+       ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
+       ev_window->priv->in_reload = FALSE;
+       ev_window_error_message (GTK_WINDOW (ev_window),
+                                _("Unable to open document"),
+                                error);
+       g_free (ev_window->priv->local_uri);
+       ev_window->priv->local_uri = NULL;
+       
+       g_error_free (error);
        g_object_unref (source);
 }
 
        g_object_unref (source);
 }
 
+static void
+ev_window_load_file_remote (EvWindow  *ev_window,
+                           GFile     *source_file)
+{
+       GFile *target_file;
+       
+       if (!ev_window->priv->local_uri) {
+               gchar *tmp_name;
+               gchar *base_name;
+
+               /* We'd like to keep extension of source uri since
+                * it helps to resolve some mime types, say cbz */
+               tmp_name = ev_tmp_filename (NULL);
+               base_name = g_file_get_basename (source_file);
+               ev_window->priv->local_uri = g_strconcat ("file:", tmp_name, "-",
+                                                         base_name, NULL);
+               ev_job_load_set_uri (EV_JOB_LOAD (ev_window->priv->load_job),
+                                    ev_window->priv->local_uri);
+               g_free (base_name);
+               g_free (tmp_name);
+       }
+       
+       target_file = g_file_new_for_uri (ev_window->priv->local_uri);
+       g_file_copy_async (source_file, target_file,
+                          0, G_PRIORITY_DEFAULT, NULL,
+                          NULL, NULL, /* no progress callback */
+                          (GAsyncReadyCallback) window_open_file_copy_ready_cb,
+                          ev_window);
+       g_object_unref (target_file);
+}
+
 void
 ev_window_open_uri (EvWindow       *ev_window,
                    const char     *uri,
 void
 ev_window_open_uri (EvWindow       *ev_window,
                    const char     *uri,
@@ -1444,7 +1499,6 @@ ev_window_open_uri (EvWindow       *ev_window,
                    const gchar    *print_settings)
 {
        GFile *source_file;
                    const gchar    *print_settings)
 {
        GFile *source_file;
-       GFile *target_file;
 
        if (ev_window->priv->uri &&
            g_ascii_strcasecmp (ev_window->priv->uri, uri) == 0) {
 
        if (ev_window->priv->uri &&
            g_ascii_strcasecmp (ev_window->priv->uri, uri) == 0) {
@@ -1478,33 +1532,11 @@ ev_window_open_uri (EvWindow       *ev_window,
 
        source_file = g_file_new_for_uri (uri);
        if (!g_file_is_native (source_file) && !ev_window->priv->local_uri) {
 
        source_file = g_file_new_for_uri (uri);
        if (!g_file_is_native (source_file) && !ev_window->priv->local_uri) {
-               char *tmp_name;
-               char *base_name;
-
-               /* We'd like to keep extension of source uri since
-                * it helps to resolve some mime types, say cbz */
-
-               tmp_name = ev_tmp_filename (NULL);
-               base_name = g_file_get_basename (source_file);
-               ev_window->priv->local_uri = g_strconcat ("file:", tmp_name, "-", base_name, NULL);
-               ev_job_load_set_uri (EV_JOB_LOAD (ev_window->priv->load_job),
-                                    ev_window->priv->local_uri);
-               g_free (base_name);
-               g_free (tmp_name);
-               
-               target_file = g_file_new_for_uri (ev_window->priv->local_uri);
-
-               g_file_copy_async (source_file, target_file,
-                                  0, G_PRIORITY_DEFAULT, NULL,
-                                  NULL, NULL, /* no progress callback */
-                                  (GAsyncReadyCallback) window_open_file_copy_ready_cb,
-                                  ev_window);
-               g_object_unref (target_file);
-               return;
+               ev_window_load_file_remote (ev_window, source_file);
+       } else {
+               g_object_unref (source_file);
+               ev_job_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH);
        }
        }
-
-       g_object_unref (source_file);
-       ev_job_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH);
 }
 
 static void
 }
 
 static void
@@ -2480,7 +2512,7 @@ ev_window_cmd_continuous (GtkAction *action, EvWindow *ev_window)
 {
        gboolean continuous;
 
 {
        gboolean continuous;
 
-       ev_window_stop_presentation (ev_window);
+       ev_window_stop_presentation (ev_window, TRUE);
        continuous = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
        g_object_set (G_OBJECT (ev_window->priv->view),
                      "continuous", continuous,
        continuous = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
        g_object_set (G_OBJECT (ev_window->priv->view),
                      "continuous", continuous,
@@ -2493,7 +2525,7 @@ ev_window_cmd_dual (GtkAction *action, EvWindow *ev_window)
 {
        gboolean dual_page;
 
 {
        gboolean dual_page;
 
-       ev_window_stop_presentation (ev_window);
+       ev_window_stop_presentation (ev_window, TRUE);
        dual_page = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
        g_object_set (G_OBJECT (ev_window->priv->view),
                      "dual-page", dual_page,
        dual_page = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
        g_object_set (G_OBJECT (ev_window->priv->view),
                      "dual-page", dual_page,
@@ -2504,7 +2536,7 @@ ev_window_cmd_dual (GtkAction *action, EvWindow *ev_window)
 static void
 ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
 {
 static void
 ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
 {
-       ev_window_stop_presentation (ev_window);
+       ev_window_stop_presentation (ev_window, TRUE);
 
        if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
                ev_view_set_sizing_mode (EV_VIEW (ev_window->priv->view), EV_SIZING_BEST_FIT);
 
        if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
                ev_view_set_sizing_mode (EV_VIEW (ev_window->priv->view), EV_SIZING_BEST_FIT);
@@ -2517,7 +2549,7 @@ ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
 static void
 ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
 {
 static void
 ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
 {
-       ev_window_stop_presentation (ev_window);
+       ev_window_stop_presentation (ev_window, TRUE);
 
        if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
                ev_view_set_sizing_mode (EV_VIEW (ev_window->priv->view), EV_SIZING_FIT_WIDTH);
 
        if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
                ev_view_set_sizing_mode (EV_VIEW (ev_window->priv->view), EV_SIZING_FIT_WIDTH);
@@ -2646,6 +2678,12 @@ fullscreen_toolbar_remove_shadow (GtkWidget *toolbar)
 static void
 ev_window_run_fullscreen (EvWindow *window)
 {
 static void
 ev_window_run_fullscreen (EvWindow *window)
 {
+       EvView  *view = EV_VIEW (window->priv->view);
+       gboolean fullscreen_window = TRUE;
+
+       if (ev_view_get_fullscreen (view))
+               return;
+       
        if (!window->priv->fullscreen_toolbar) {
                window->priv->fullscreen_toolbar =
                        gtk_ui_manager_get_widget (window->priv->ui_manager,
        if (!window->priv->fullscreen_toolbar) {
                window->priv->fullscreen_toolbar =
                        gtk_ui_manager_get_widget (window->priv->ui_manager,
@@ -2663,11 +2701,16 @@ ev_window_run_fullscreen (EvWindow *window)
                                       window->priv->fullscreen_toolbar, 1);
        }
 
                                       window->priv->fullscreen_toolbar, 1);
        }
 
+       if (ev_view_get_presentation (view)) {
+               ev_window_stop_presentation (window, FALSE);
+               fullscreen_window = FALSE;
+       }
+
        g_object_set (G_OBJECT (window->priv->scrolled_window),
                      "shadow-type", GTK_SHADOW_NONE,
                      NULL);
 
        g_object_set (G_OBJECT (window->priv->scrolled_window),
                      "shadow-type", GTK_SHADOW_NONE,
                      NULL);
 
-       ev_view_set_fullscreen (EV_VIEW (window->priv->view), TRUE);
+       ev_view_set_fullscreen (view, TRUE);
        ev_window_update_fullscreen_action (window);
 
        /* If the user doesn't have the main toolbar he/she won't probably want
        ev_window_update_fullscreen_action (window);
 
        /* If the user doesn't have the main toolbar he/she won't probably want
@@ -2676,8 +2719,9 @@ ev_window_run_fullscreen (EvWindow *window)
        update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR,
                            (window->priv->chrome & EV_CHROME_TOOLBAR) != 0);
        update_chrome_visibility (window);
        update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR,
                            (window->priv->chrome & EV_CHROME_TOOLBAR) != 0);
        update_chrome_visibility (window);
-       
-       gtk_window_fullscreen (GTK_WINDOW (window));
+
+       if (fullscreen_window)
+               gtk_window_fullscreen (GTK_WINDOW (window));
        gtk_widget_grab_focus (window->priv->view);
 
        if (!ev_window_is_empty (window))
        gtk_widget_grab_focus (window->priv->view);
 
        if (!ev_window_is_empty (window))
@@ -2685,11 +2729,12 @@ ev_window_run_fullscreen (EvWindow *window)
 }
 
 static void
 }
 
 static void
-ev_window_stop_fullscreen (EvWindow *window)
+ev_window_stop_fullscreen (EvWindow *window,
+                          gboolean  unfullscreen_window)
 {
        EvView *view = EV_VIEW (window->priv->view);
 
 {
        EvView *view = EV_VIEW (window->priv->view);
 
-       if (!ev_view_get_fullscreen (EV_VIEW (view)))
+       if (!ev_view_get_fullscreen (view))
                return;
 
        g_object_set (G_OBJECT (window->priv->scrolled_window),
                return;
 
        g_object_set (G_OBJECT (window->priv->scrolled_window),
@@ -2700,7 +2745,8 @@ ev_window_stop_fullscreen (EvWindow *window)
        ev_window_update_fullscreen_action (window);
        update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR, FALSE);
        update_chrome_visibility (window);
        ev_window_update_fullscreen_action (window);
        update_chrome_flag (window, EV_CHROME_FULLSCREEN_TOOLBAR, FALSE);
        update_chrome_visibility (window);
-       gtk_window_unfullscreen (GTK_WINDOW (window));
+       if (unfullscreen_window)
+               gtk_window_unfullscreen (GTK_WINDOW (window));
 
        if (!ev_window_is_empty (window))
                ev_metadata_manager_set_boolean (window->priv->uri, "fullscreen", FALSE);
 
        if (!ev_window_is_empty (window))
                ev_metadata_manager_set_boolean (window->priv->uri, "fullscreen", FALSE);
@@ -2711,14 +2757,11 @@ ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *window)
 {
        gboolean fullscreen;
 
 {
        gboolean fullscreen;
 
-        g_return_if_fail (EV_IS_WINDOW (window));
-       ev_window_stop_presentation (window);
-
        fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
        if (fullscreen) {
                ev_window_run_fullscreen (window);
        } else {
        fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
        if (fullscreen) {
                ev_window_run_fullscreen (window);
        } else {
-               ev_window_stop_fullscreen (window);
+               ev_window_stop_fullscreen (window, TRUE);
        }
 }
 
        }
 }
 
@@ -2803,17 +2846,29 @@ ev_window_update_presentation_action (EvWindow *window)
 static void
 ev_window_run_presentation (EvWindow *window)
 {
 static void
 ev_window_run_presentation (EvWindow *window)
 {
+       EvView  *view = EV_VIEW (window->priv->view);
+       gboolean fullscreen_window = TRUE;
+
+       if (ev_view_get_presentation (view))
+               return;
+
+       if (ev_view_get_fullscreen (view)) {
+               ev_window_stop_fullscreen (window, FALSE);
+               fullscreen_window = FALSE;
+       }
+       
        g_object_set (G_OBJECT (window->priv->scrolled_window),
                      "shadow-type", GTK_SHADOW_NONE,
                      NULL);
 
        g_object_set (G_OBJECT (window->priv->scrolled_window),
                      "shadow-type", GTK_SHADOW_NONE,
                      NULL);
 
-       ev_view_set_presentation (EV_VIEW (window->priv->view), TRUE);
+       ev_view_set_presentation (view, TRUE);
        ev_window_update_presentation_action (window);
 
        update_chrome_visibility (window);
        
        gtk_widget_grab_focus (window->priv->view);
        ev_window_update_presentation_action (window);
 
        update_chrome_visibility (window);
        
        gtk_widget_grab_focus (window->priv->view);
-       gtk_window_fullscreen (GTK_WINDOW (window));
+       if (fullscreen_window)
+               gtk_window_fullscreen (GTK_WINDOW (window));
 
        g_signal_connect (window->priv->view,
                          "motion-notify-event",
 
        g_signal_connect (window->priv->view,
                          "motion-notify-event",
@@ -2832,9 +2887,12 @@ ev_window_run_presentation (EvWindow *window)
 }
 
 static void
 }
 
 static void
-ev_window_stop_presentation (EvWindow *window)
+ev_window_stop_presentation (EvWindow *window,
+                            gboolean  unfullscreen_window)
 {
 {
-       if (!ev_view_get_presentation (EV_VIEW (window->priv->view)))
+       EvView *view = EV_VIEW (window->priv->view);
+       
+       if (!ev_view_get_presentation (view))
                return;
 
        g_object_set (G_OBJECT (window->priv->scrolled_window),
                return;
 
        g_object_set (G_OBJECT (window->priv->scrolled_window),
@@ -2844,7 +2902,8 @@ ev_window_stop_presentation (EvWindow *window)
        ev_view_set_presentation (EV_VIEW (window->priv->view), FALSE);
        ev_window_update_presentation_action (window);
        update_chrome_visibility (window);
        ev_view_set_presentation (EV_VIEW (window->priv->view), FALSE);
        ev_window_update_presentation_action (window);
        update_chrome_visibility (window);
-       gtk_window_unfullscreen (GTK_WINDOW (window));
+       if (unfullscreen_window)
+               gtk_window_unfullscreen (GTK_WINDOW (window));
 
        g_signal_handlers_disconnect_by_func (window->priv->view,
                                              (gpointer) presentation_motion_notify_cb,
 
        g_signal_handlers_disconnect_by_func (window->priv->view,
                                              (gpointer) presentation_motion_notify_cb,
@@ -2865,14 +2924,11 @@ ev_window_cmd_view_presentation (GtkAction *action, EvWindow *window)
 {
        gboolean presentation;
 
 {
        gboolean presentation;
 
-       g_return_if_fail (EV_IS_WINDOW (window));
-       ev_window_stop_fullscreen (window);
-
        presentation = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
        if (presentation) {
                ev_window_run_presentation (window);
        } else {
        presentation = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
        if (presentation) {
                ev_window_run_presentation (window);
        } else {
-               ev_window_stop_presentation (window);
+               ev_window_stop_presentation (window, TRUE);
        }
 }
 
        }
 }
 
@@ -3170,13 +3226,12 @@ ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
 static void
 ev_window_cmd_leave_fullscreen (GtkAction *action, EvWindow *window)
 {
 static void
 ev_window_cmd_leave_fullscreen (GtkAction *action, EvWindow *window)
 {
-       ev_window_stop_fullscreen (window);
+       ev_window_stop_fullscreen (window, TRUE);
 }
 
 static void
 ev_window_cmd_start_presentation (GtkAction *action, EvWindow *window)
 {
 }
 
 static void
 ev_window_cmd_start_presentation (GtkAction *action, EvWindow *window)
 {
-       ev_window_stop_fullscreen (window);
        ev_window_run_presentation (window);
 }
 
        ev_window_run_presentation (window);
 }
 
@@ -3328,9 +3383,9 @@ ev_window_cmd_escape (GtkAction *action, EvWindow *window)
                              NULL);
 
                if (fullscreen) {
                              NULL);
 
                if (fullscreen) {
-                       ev_window_stop_fullscreen (window);
+                       ev_window_stop_fullscreen (window, TRUE);
                } else if (presentation) {
                } else if (presentation) {
-                       ev_window_stop_presentation (window);
+                       ev_window_stop_presentation (window, TRUE);
                        gtk_widget_grab_focus (window->priv->view);
                } else {
                        gtk_widget_grab_focus (window->priv->view);
                        gtk_widget_grab_focus (window->priv->view);
                } else {
                        gtk_widget_grab_focus (window->priv->view);
@@ -4577,29 +4632,11 @@ static void
 launch_external_uri (EvWindow *window, EvLinkAction *action)
 {
        const gchar *uri = ev_link_action_get_uri (action);
 launch_external_uri (EvWindow *window, EvLinkAction *action)
 {
        const gchar *uri = ev_link_action_get_uri (action);
-       const char *content_type;
-       GFile *file;
-       GFileInfo *file_info;
-       GAppInfo *app;
-       GList *file_list = NULL;
        GError *error = NULL;
        GError *error = NULL;
+       gboolean ret;
        
        
-       file = g_file_new_for_uri (uri);
-       file_info = g_file_query_info (file,
-                                      G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
-                                      0, NULL, NULL);
-       if (file_info == NULL) {
-               g_object_unref (file);
-               return;
-       }
-       
-       content_type = g_file_info_get_content_type (file_info);
-       app = g_app_info_get_default_for_type (content_type, TRUE);
-       g_object_unref (file_info);
-       
-       file_list = g_list_append (file_list, file);
-       
-       if (!g_app_info_launch (app, file_list, NULL, &error)) {
+       ret = g_app_info_launch_default_for_uri (uri, NULL, &error);
+       if (ret == FALSE) {
                GtkWidget *dialog;
        
                dialog = gtk_message_dialog_new (GTK_WINDOW (window),
                GtkWidget *dialog;
        
                dialog = gtk_message_dialog_new (GTK_WINDOW (window),
@@ -4613,11 +4650,8 @@ launch_external_uri (EvWindow *window, EvLinkAction *action)
                                  G_CALLBACK (gtk_widget_destroy),
                                  NULL);
                gtk_widget_show (dialog);
                                  G_CALLBACK (gtk_widget_destroy),
                                  NULL);
                gtk_widget_show (dialog);
+               g_error_free(error);
        }
        }
-
-       g_object_unref (app);
-       g_object_unref (file);
-       g_list_free (file_list);
 }
 
 static void
 }
 
 static void
@@ -4754,7 +4788,6 @@ image_save_dialog_response_cb (GtkWidget *fc,
        GError          *error = NULL;
        GdkPixbuf       *pixbuf;
        gchar           *uri;
        GError          *error = NULL;
        GdkPixbuf       *pixbuf;
        gchar           *uri;
-       gchar           *uri_extension;
        gchar          **extensions;
        gchar           *filename;
        gchar           *file_format;
        gchar          **extensions;
        gchar           *filename;
        gchar           *file_format;
@@ -4785,27 +4818,31 @@ image_save_dialog_response_cb (GtkWidget *fc,
        }
 
        extensions = gdk_pixbuf_format_get_extensions (format);
        }
 
        extensions = gdk_pixbuf_format_get_extensions (format);
-       uri_extension = g_strconcat (uri, ".", extensions[0], NULL);
+       if (g_str_has_suffix(uri, extensions[0])) {
+               gchar *uri_extension;
+               
+               uri_extension = g_strconcat (uri, ".", extensions[0], NULL);
+               target_file = g_file_new_for_uri (uri_extension);
+               g_free (uri_extension);
+       } else {
+               target_file = g_file_new_for_uri (uri);
+       }
        g_strfreev(extensions);
        g_strfreev(extensions);
-       file_format = gdk_pixbuf_format_get_name (format);
+       g_free (uri);
        
        
-       target_file = g_file_new_for_uri (uri_extension);
        is_native = g_file_is_native (target_file);
        is_native = g_file_is_native (target_file);
-       
        if (is_native) {
                filename = g_file_get_path (target_file);
        } else {
                filename = ev_tmp_filename ("saveimage");
        }
        if (is_native) {
                filename = g_file_get_path (target_file);
        } else {
                filename = ev_tmp_filename ("saveimage");
        }
-       
-       g_free (uri);
-       g_free (uri_extension);
 
        ev_document_doc_mutex_lock ();
        pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (ev_window->priv->document),
                                               ev_window->priv->image);
        ev_document_doc_mutex_unlock ();
 
        ev_document_doc_mutex_lock ();
        pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (ev_window->priv->document),
                                               ev_window->priv->image);
        ev_document_doc_mutex_unlock ();
-       
+
+       file_format = gdk_pixbuf_format_get_name (format);
        gdk_pixbuf_save (pixbuf, filename, file_format, &error, NULL);
        g_free (file_format);
        g_object_unref (pixbuf);
        gdk_pixbuf_save (pixbuf, filename, file_format, &error, NULL);
        g_free (file_format);
        g_object_unref (pixbuf);