(GInstanceInitFunc)image_loader_init, /* instance_init */
NULL /* value_table */
};
- type = g_type_register_static(G_TYPE_OBJECT, "ImageLoaderType", &info, G_TYPE_FLAG_NONE);
+ type = g_type_register_static(G_TYPE_OBJECT, "ImageLoaderType", &info, GTypeFlags(0));
}
return type;
}
/**************************************************************************************/
/* execution via idle calls */
-//static gboolean image_loader_idle_cb(gpointer data)
-//{
- //gboolean ret = FALSE;
- //ImageLoader *il = static_cast<ImageLoader *>(data);
-
- //if (il->idle_id)
- //{
- //ret = image_loader_continue(il);
- //}
+static gboolean image_loader_idle_cb(gpointer data)
+{
+ gboolean ret = FALSE;
+ ImageLoader *il = static_cast<ImageLoader *>(data);
- //if (!ret)
- //{
- //image_loader_stop_source(il);
- //}
+ if (il->idle_id)
+ {
+ ret = image_loader_continue(il);
+ }
- //return ret;
-//}
+ if (!ret)
+ {
+ image_loader_stop_source(il);
+ }
+ return ret;
+}
-//static gboolean image_loader_start_idle(ImageLoader *il)
-//{
- //gboolean ret;
+static gboolean image_loader_start_idle(ImageLoader *il)
+{
+ gboolean ret;
- //if (!il) return FALSE;
+ if (!il) return FALSE;
- //if (!il->fd) return FALSE;
+ if (!il->fd) return FALSE;
- //if (!image_loader_setup_source(il)) return FALSE;
+ if (!image_loader_setup_source(il)) return FALSE;
- //ret = image_loader_begin(il);
+ ret = image_loader_begin(il);
- //if (ret && !il->done) il->idle_id = g_idle_add_full(il->idle_priority, image_loader_idle_cb, il, NULL);
- //return ret;
-//}
+ if (ret && !il->done) il->idle_id = g_idle_add_full(il->idle_priority, image_loader_idle_cb, il, NULL);
+ return ret;
+}
/**************************************************************************************/
/* execution via thread */
return ret;
}
+
+/**
+ * @FIXME this can be rather slow and blocks until the size is known
+ */
gboolean image_load_dimensions(FileData *fd, gint *width, gint *height)
{
+ ImageLoader *il;
gboolean success;
- gint width_file = 0;
- gint height_file = 0;
- gdk_pixbuf_get_file_info(fd->path, &width_file, &height_file);
+ il = image_loader_new(fd);
- if (width_file && height_file)
+ success = image_loader_start_idle(il);
+
+ if (success && il->pixbuf)
{
- *width = width_file;
- *height = height_file;
- success = TRUE;
+ if (width) *width = gdk_pixbuf_get_width(il->pixbuf);
+ if (height) *height = gdk_pixbuf_get_height(il->pixbuf);;
}
else
{
- *width = -1;
- *height = -1;
- success = FALSE;
+ if (width) *width = -1;
+ if (height) *height = -1;
}
+ image_loader_free(il);
+
return success;
}
/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */