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; }
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; }
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); }
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; }
static void thumb_loader_std_save(ThumbLoaderStd *tl, GdkPixbuf *pixbuf) { gchar *base_path; gchar *tmp_path; gint fail; if (!tl->cache_enable || tl->cache_hit) return; if (tl->thumb_path) return; if (!pixbuf) { /* local failures are not stored */ if (tl->cache_local) return; pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 1, 1); fail = TRUE; } else { g_object_ref(G_OBJECT(pixbuf)); fail = FALSE; } tl->thumb_path = thumb_loader_std_cache_path(tl, tl->cache_local, pixbuf, fail); if (!tl->thumb_path) { g_object_unref(G_OBJECT(pixbuf)); return; } tl->thumb_path_local = tl->cache_local; /* create thumbnail dir if needed */ base_path = remove_level_from_path(tl->thumb_path); if (tl->cache_local) { if (!isdir(base_path)) { struct stat st; gchar *source_base; source_base = remove_level_from_path(tl->source_path); if (stat_utf8(source_base, &st)) { cache_ensure_dir_exists(base_path, st.st_mode); } g_free(source_base); } } else { cache_ensure_dir_exists(base_path, THUMB_PERMS_FOLDER); } g_free(base_path); if (debug) { printf("thumb saving: %s\n", tl->source_path); printf(" saved: %s\n", tl->thumb_path); } /* save thumb, using a temp file then renaming into place */ tmp_path = unique_filename(tl->thumb_path, ".tmp", "_", 2); if (tmp_path) { const gchar *mark_uri; gchar *mark_app; gchar *mark_mtime; gchar *pathl; gint success; mark_uri = (tl->cache_local) ? tl->local_uri :tl->thumb_uri; mark_app = g_strdup_printf("GQview %s", VERSION); mark_mtime = g_strdup_printf("%lu", tl->source_mtime); pathl = path_from_utf8(tmp_path); success = gdk_pixbuf_save(pixbuf, pathl, "png", NULL, THUMB_MARKER_URI, mark_uri, THUMB_MARKER_MTIME, mark_mtime, THUMB_MARKER_APP, mark_app, NULL); if (success) { chmod(pathl, (tl->cache_local) ? tl->source_mode : THUMB_PERMS_THUMB); success = rename_file(tmp_path, tl->thumb_path); } g_free(pathl); g_free(mark_mtime); g_free(mark_app); g_free(tmp_path); if (!success && debug) { printf("thumb save failed: %s\n", tl->source_path); printf(" thumb: %s\n", tl->thumb_path); } } g_object_unref(G_OBJECT(pixbuf)); }