Exemple #1
0
static void cache_maint_copied(FileData *fd)
{
	gchar *dest_base;
	gchar *src_cache;
	mode_t mode = 0755;

	src_cache = cache_find_location(CACHE_TYPE_METADATA, fd->change->source);
	if (!src_cache) return;

	dest_base = cache_get_location(CACHE_TYPE_METADATA, fd->change->dest, FALSE, &mode);
	if (recursive_mkdir_if_not_exists(dest_base, mode))
		{
		gchar *path;

		path = cache_get_location(CACHE_TYPE_METADATA, fd->change->dest, TRUE, NULL);
		if (!copy_file(src_cache, path))
			{
			DEBUG_1("failed to copy metadata %s to %s", src_cache, path);
			}
		g_free(path);
		}

	g_free(dest_base);
	g_free(src_cache);
}
Exemple #2
0
static void cache_maint_moved(FileData *fd)
{
	gchar *base;
	mode_t mode = 0755;
	const gchar *src = fd->change->source;
	const gchar *dest = fd->change->dest;

	if (!src || !dest) return;

	base = cache_get_location(CACHE_TYPE_THUMB, dest, FALSE, &mode);
	if (recursive_mkdir_if_not_exists(base, mode))
		{
		gchar *buf;
		gchar *d;

		buf = cache_find_location(CACHE_TYPE_THUMB, src);
		d = cache_get_location(CACHE_TYPE_THUMB, dest, TRUE, NULL);
		cache_file_move(buf, d);
		g_free(d);
		g_free(buf);

		buf = cache_find_location(CACHE_TYPE_SIM, src);
		d = cache_get_location(CACHE_TYPE_SIM, dest, TRUE, NULL);
		cache_file_move(buf, d);
		g_free(d);
		g_free(buf);
		}
	else
		{
		log_printf("Failed to create cache dir for move %s\n", base);
		}
	g_free(base);

	base = cache_get_location(CACHE_TYPE_METADATA, dest, FALSE, &mode);
	if (recursive_mkdir_if_not_exists(base, mode))
		{
		gchar *buf;
		gchar *d;

		buf = cache_find_location(CACHE_TYPE_METADATA, src);
		d = cache_get_location(CACHE_TYPE_METADATA, dest, TRUE, NULL);
		cache_file_move(buf, d);
		g_free(d);
		g_free(buf);
		}
	g_free(base);

	if (options->thumbnails.enable_caching && options->thumbnails.spec_standard)
		thumb_std_maint_moved(src, dest);
}
Exemple #3
0
void
cache_maint_moved (CacheType type, const gchar * src, const gchar * dest)
{
    gchar  *base;
    mode_t  mode = 0755;

    if (!src || !dest)
	return;

    base = cache_get_location (type, dest, FALSE, NULL, &mode);

    if (cache_ensure_dir_exists (base, mode))
    {
	gchar  *buf;
	gchar  *d;

	if (type == CACHE_THUMBS)
	{
	    buf = cache_find_location (type, src, PORNVIEW_CACHE_THUMB_EXT);
	    d = cache_get_location (type, dest, TRUE,
				    PORNVIEW_CACHE_THUMB_EXT, NULL);
	}
	else
	{
	    buf = cache_find_location (type, src, PORNVIEW_CACHE_COMMENT_EXT);
	    d = cache_get_location (type, dest, TRUE,
				    PORNVIEW_CACHE_COMMENT_EXT, NULL);
	}

	cache_file_move (buf, d);
	g_free (d);
	g_free (buf);
    }
    else
	g_free (base);
}
Exemple #4
0
static  gint
thumb_loader_mark_failure (ThumbLoader * tl)
{
    gchar  *cache_dir;
    gint    success = FALSE;
    mode_t  mode = 0755;

    if (!tl)
	return FALSE;

    cache_dir =
	cache_get_location (CACHE_THUMBS, tl->path, FALSE, NULL, &mode);

    if (cache_ensure_dir_exists (cache_dir, mode))
    {
	gchar  *cache_path;
	FILE   *f;

	cache_path =
	    g_strconcat (cache_dir, "/", filename_from_path (tl->path),
			 PORNVIEW_CACHE_THUMB_EXT, NULL);

	f = fopen (cache_path, "w");
	if (f)
	{
	    struct utimbuf ut;

	    fclose (f);

	    ut.actime = ut.modtime = filetime (tl->path);
	    if (ut.modtime > 0)
	    {
		utime (cache_path, &ut);
	    }

	    success = TRUE;
	}

	g_free (cache_path);
    }

    g_free (cache_dir);
    return success;
}
Exemple #5
0
static  gint
thumb_loader_save_to_cache (ThumbLoader * tl)
{
    gchar  *cache_dir;
    gint    success = FALSE;
    mode_t  mode = 0755;

    if (!tl || !tl->pixbuf)
	return FALSE;

    cache_dir =
	cache_get_location (CACHE_THUMBS, tl->path, FALSE, NULL, &mode);

    if (cache_ensure_dir_exists (cache_dir, mode))
    {
	gchar  *cache_path;

	cache_path =
	    g_strconcat (cache_dir, "/", filename_from_path (tl->path),
			 PORNVIEW_CACHE_THUMB_EXT, NULL);

	success = pixbuf_to_file_as_png (tl->pixbuf, cache_path);
	if (success)
	{
	    struct utimbuf ut;
	    /*
	     * set thumb time to that of source file 
	     */

	    ut.actime = ut.modtime = filetime (tl->path);
	    if (ut.modtime > 0)
	    {
		utime (cache_path, &ut);
	    }
	}

	g_free (cache_path);
    }

    g_free (cache_dir);

    return success;
}
Exemple #6
0
static  gint
thumbview_thumbs_next (void)
{
    ZAlbumCell *cell;

    thumbview->thumbs_count++;

    if (thumbview->thumbs_stop)
    {
	thumbview_thumbs_cleanup ();
	return FALSE;
    }

    if (thumbview->thumbs_count < ZALBUM (thumbview->album)->len)
    {
	gchar  *path;
	cell =
	    ZLIST_CELL_FROM_INDEX (ZLIST (thumbview->album),
				   thumbview->thumbs_count);
	path = g_strdup (cell->name);

	if (file_type_is_movie (cell->name))
	{
	    GdkPixbuf *pixbuf = NULL;
	    GdkPixmap *pixmap;
	    GdkBitmap *mask;
	    gchar  *cache_dir;
	    mode_t  mode = 0755;
	    gfloat  status;
	    cache_dir =
		cache_get_location (CACHE_THUMBS, path, FALSE, NULL, &mode);


	    if (cache_ensure_dir_exists (cache_dir, mode))
	    {
		gchar  *cache_path;
		cache_path =
		    g_strconcat (cache_dir, "/", g_basename (cell->name),
				 PORNVIEW_CACHE_THUMB_EXT, NULL);

#ifdef USE_GTK2
		pixbuf = gdk_pixbuf_new_from_file (cache_path, NULL);
#else
		pixbuf = gdk_pixbuf_new_from_file (cache_path);
#endif
		if (pixbuf)
		{
		    gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap,
						       &mask, 128);
		    zalbum_set_pixmap (ZALBUM (thumbview->album),
				       thumbview->thumbs_count, pixmap, mask);
		    if (pixmap)
			gdk_pixmap_unref (pixmap);
		    if (mask)
			gdk_bitmap_unref (mask);
		    gdk_pixbuf_unref (pixbuf);
		}
		else
		{
		    pixbuf = image_get_video_pixbuf ();

		    gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap,
						       &mask, 128);
		    zalbum_set_pixmap (ZALBUM (thumbview->album),
				       thumbview->thumbs_count, pixmap, mask);
		    if (pixmap)
			gdk_pixmap_unref (pixmap);
		    if (mask)
			gdk_bitmap_unref (mask);
		    gdk_pixbuf_unref (pixbuf);
		}

		g_free (cache_path);
	    }

	    g_free (cache_dir);
	    g_free (path);

	    status =
		(gfloat) thumbview->thumbs_count /
		ZALBUM (thumbview->album)->len;
	    thumbview_thumbs_progressbar (status);

	    while (gtk_events_pending ())
		gtk_main_iteration ();

	    thumbview_thumbs_do (NULL);
	    return TRUE;
	}
	else
	{
	    thumb_loader_free (thumbview->thumbs_loader);
	    thumbview->thumbs_loader = thumb_loader_new (path, 100, 100);
	    g_free (path);
	    thumb_loader_set_error_func (thumbview->thumbs_loader,
					 cb_thumbview_thumbs_error, NULL);
	    if (!thumb_loader_start
		(thumbview->thumbs_loader, cb_thumbview_thumbs_done, NULL))
	    {
		thumbview_thumbs_do (NULL);
		return TRUE;
	    }

	}
	return FALSE;
    }
    else
    {
	thumbview_thumbs_cleanup ();
	return FALSE;
    }

    return TRUE;
}
Exemple #7
0
static gboolean cache_loader_process(CacheLoader *cl)
{
	if (cl->todo_mask & CACHE_LOADER_SIMILARITY &&
	    !cl->cd->similarity)
		{
		GdkPixbuf *pixbuf;

		if (!cl->il && !cl->error)
			{
			cl->il = image_loader_new(cl->fd);
			g_signal_connect(G_OBJECT(cl->il), "error", (GCallback)cache_loader_error_cb, cl);
			g_signal_connect(G_OBJECT(cl->il), "done", (GCallback)cache_loader_done_cb, cl);
			if (image_loader_start(cl->il))
				{
				return FALSE;
				}

			cl->error = TRUE;
			}

		pixbuf = image_loader_get_pixbuf(cl->il);
		if (pixbuf)
			{
			if (!cl->error)
				{
				ImageSimilarityData *sim;

				sim = image_sim_new_from_pixbuf(pixbuf);
				cache_sim_data_set_similarity(cl->cd, sim);
				image_sim_free(sim);

				cl->done_mask |= CACHE_LOADER_SIMILARITY;
				}

			/* we have the dimensions via pixbuf */
			if (!cl->cd->dimensions)
				{
				cache_sim_data_set_dimensions(cl->cd, gdk_pixbuf_get_width(pixbuf),
								      gdk_pixbuf_get_height(pixbuf));
				if (cl->todo_mask & CACHE_LOADER_DIMENSIONS)
					{
					cl->todo_mask &= ~CACHE_LOADER_DIMENSIONS;
					cl->done_mask |= CACHE_LOADER_DIMENSIONS;
					}
				}
			}

		image_loader_free(cl->il);
		cl->il = NULL;

		cl->todo_mask &= ~CACHE_LOADER_SIMILARITY;
		}
	else if (cl->todo_mask & CACHE_LOADER_DIMENSIONS &&
		 !cl->cd->dimensions)
		{
		if (!cl->error &&
		    image_load_dimensions(cl->fd, &cl->cd->width, &cl->cd->height))
			{
			cl->cd->dimensions = TRUE;
			cl->done_mask |= CACHE_LOADER_DIMENSIONS;
			}
		else
			{
			cl->error = TRUE;
			}

		cl->todo_mask &= ~CACHE_LOADER_DIMENSIONS;
		}
	else if (cl->todo_mask & CACHE_LOADER_MD5SUM &&
		 !cl->cd->have_md5sum)
		{
		if (md5_get_digest_from_file_utf8(cl->fd->path, cl->cd->md5sum))
			{
			cl->cd->have_md5sum = TRUE;
			cl->done_mask |= CACHE_LOADER_MD5SUM;
			}
		else
			{
			cl->error = TRUE;
			}

		cl->todo_mask &= ~CACHE_LOADER_MD5SUM;
		}
	else if (cl->todo_mask & CACHE_LOADER_DATE &&
		 !cl->cd->have_date)
		{
		time_t date = -1;
		gchar *text;

		text =  metadata_read_string(cl->fd, "formatted.DateTime", METADATA_FORMATTED);
		if (text)
			{
			struct tm t;

			memset(&t, 0, sizeof(t));

			if (sscanf(text, "%d:%d:%d %d:%d:%d", &t.tm_year, &t.tm_mon, &t.tm_mday,
				   &t.tm_hour, &t.tm_min, &t.tm_sec) == 6)
				{
				t.tm_year -= 1900;
				t.tm_mon -= 1;
				t.tm_isdst = -1;
				date = mktime(&t);
				}
			g_free(text);
			}

		cl->cd->date = date;
		cl->cd->have_date = TRUE;

		cl->done_mask |= CACHE_LOADER_DATE;
		cl->todo_mask &= ~CACHE_LOADER_DATE;
		}
	else
		{
		/* done, save then call done function */
		if (options->thumbnails.enable_caching &&
		    cl->done_mask != CACHE_LOADER_NONE)
			{
			gchar *base;
			mode_t mode = 0755;

			base = cache_get_location(CACHE_TYPE_SIM, cl->fd->path, FALSE, &mode);
			if (recursive_mkdir_if_not_exists(base, mode))
				{
				g_free(cl->cd->path);
				cl->cd->path = cache_get_location(CACHE_TYPE_SIM, cl->fd->path, TRUE, NULL);
				if (cache_sim_data_save(cl->cd))
					{
					filetime_set(cl->cd->path, filetime(cl->fd->path));
					}
				}
			g_free(base);
			}

		cl->idle_id = 0;

		if (cl->done_func)
			{
			cl->done_func(cl, cl->error, cl->done_data);
			}

		return FALSE;
		}

	return TRUE;
}