]> www.fi.muni.cz Git - evince.git/blobdiff - libdocument/ev-image.c
[dualscreen] fix crash on ctrl+w and fix control window closing
[evince.git] / libdocument / ev-image.c
index f906b0006c9f9da0cf1b496e789ae78bbd6ea002..fcbbd7d00e7ee85d0abf8a4d13c623a023b06fc0 100644 (file)
  *
  * 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.
  */
 
+#include <config.h>
+
 #include <glib/gstdio.h>
+#include <unistd.h>
+
+#include "ev-document-misc.h"
 #include "ev-file-helpers.h"
 #include "ev-image.h"
 
 struct _EvImagePrivate {
+       gint       page;
+       gint       id;
        GdkPixbuf *pixbuf;
        gchar     *tmp_uri;
 };
@@ -42,7 +49,11 @@ ev_image_finalize (GObject *object)
        }
 
        if (image->priv->tmp_uri) {
-               g_unlink (image->priv->tmp_uri);
+               gchar *filename;
+
+               filename = g_filename_from_uri (image->priv->tmp_uri, NULL, NULL);
+               ev_tmp_filename_unlink (filename);
+               g_free (filename);
                g_free (image->priv->tmp_uri);
                image->priv->tmp_uri = NULL;
        }
@@ -68,6 +79,19 @@ ev_image_init (EvImage *image)
        image->priv = EV_IMAGE_GET_PRIVATE (image);
 }
 
+EvImage *
+ev_image_new (gint page,
+             gint img_id)
+{
+       EvImage *image;
+
+       image = EV_IMAGE (g_object_new (EV_TYPE_IMAGE, NULL));
+       image->priv->page = page;
+       image->priv->id = img_id;
+
+       return image;
+}
+
 EvImage *
 ev_image_new_from_pixbuf (GdkPixbuf *pixbuf)
 {
@@ -81,6 +105,22 @@ ev_image_new_from_pixbuf (GdkPixbuf *pixbuf)
        return image;
 }
 
+gint
+ev_image_get_page (EvImage *image)
+{
+       g_return_val_if_fail (EV_IS_IMAGE (image), -1);
+
+       return image->priv->page;
+}
+
+gint
+ev_image_get_id (EvImage *image)
+{
+       g_return_val_if_fail (EV_IS_IMAGE (image), -1);
+
+       return image->priv->id;
+}
+
 GdkPixbuf *
 ev_image_get_pixbuf (EvImage *image)
 {
@@ -91,28 +131,43 @@ ev_image_get_pixbuf (EvImage *image)
 }
 
 const gchar *
-ev_image_save_tmp (EvImage *image)
+ev_image_save_tmp (EvImage   *image,
+                  GdkPixbuf *pixbuf)
 {
        GError *error = NULL;
+       gchar  *filename = NULL;
+        int fd;
        
        g_return_val_if_fail (EV_IS_IMAGE (image), NULL);
-       g_return_val_if_fail (GDK_IS_PIXBUF (image->priv->pixbuf), NULL);
+       g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
 
        if (image->priv->tmp_uri)
                return image->priv->tmp_uri;
 
-       image->priv->tmp_uri = ev_tmp_filename ("image");
-       gdk_pixbuf_save (image->priv->pixbuf,
-                        image->priv->tmp_uri, "png", &error,
+       if ((fd = ev_mkstemp ("image.XXXXXX.png", &filename, &error)) == -1)
+               goto had_error;
+
+       gdk_pixbuf_save (pixbuf, filename,
+                        "png", &error,
                         "compression", "3", NULL);
-       if (!error)
+        close (fd);
+
+       if (!error) {
+               image->priv->tmp_uri = g_filename_to_uri (filename, NULL, &error);
+                if (image->priv->tmp_uri == NULL)
+                        goto had_error;
+
+               g_free (filename);
+               
                return image->priv->tmp_uri;
+       }
+
+    had_error:
 
        /* Erro saving image */
-       g_warning (error->message);
+       g_warning ("Error saving image: %s", error->message);
        g_error_free (error);
-       g_free (image->priv->tmp_uri);
-       image->priv->tmp_uri = NULL;
+       g_free (filename);
 
        return NULL;
 }
@@ -124,44 +179,3 @@ ev_image_get_tmp_uri (EvImage *image)
 
        return image->priv->tmp_uri;
 }
-
-/* EvImageMapping */
-static void
-ev_image_mapping_free_foreach (EvImageMapping *mapping)
-{
-       g_object_unref (mapping->image);
-       g_free (mapping);
-}
-
-void
-ev_image_mapping_free (GList *image_mapping)
-{
-       if (!image_mapping)
-               return;
-
-       g_list_foreach (image_mapping, (GFunc) ev_image_mapping_free_foreach, NULL);
-       g_list_free (image_mapping);
-}
-
-EvImage *
-ev_image_mapping_find (GList   *image_mapping,
-                      gdouble  x,
-                      gdouble  y)
-{
-       GList *list;
-
-       for (list = image_mapping; list; list = list->next) {
-               EvImageMapping *mapping = list->data;
-
-               if ((x >= mapping->x1) &&
-                   (y >= mapping->y1) &&
-                   (x <= mapping->x2) &&
-                   (y <= mapping->y2)) {
-                       return mapping->image;
-               }
-       }
-
-       return NULL;
-}
-
-