core/tags/album: Create a new structure to store name and subdir strings
I eventually want to make these fields const in the file code, so we need a different way to manage and eventually free these strings. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
a2854ef31e
commit
d7d553b80f
|
@ -19,24 +19,35 @@
|
|||
static struct database album_db;
|
||||
static bool album_db_upgraded = false;
|
||||
|
||||
struct album_cache_file {
|
||||
struct cache_file ac_file;
|
||||
gchar *ac_subdir;
|
||||
gchar *ac_name;
|
||||
};
|
||||
|
||||
static inline void __album_init_file(struct album *al, struct cache_file *f)
|
||||
struct album_cache_file *__album_alloc_file(struct album *al)
|
||||
{
|
||||
struct album_cache_file *ret = g_malloc(sizeof(struct album_cache_file));
|
||||
gchar *name = g_uri_escape_string(al->al_name, " ", true);
|
||||
cache_file_init(f, g_strdup_printf("%d", al->al_year),
|
||||
g_strdup_printf("%s.jpg", name));
|
||||
|
||||
ret->ac_subdir = g_strdup_printf("%d", al->al_year);
|
||||
ret->ac_name = g_strdup_printf("%s.jpg", name);
|
||||
cache_file_init(&ret->ac_file, ret->ac_subdir, ret->ac_name);
|
||||
|
||||
g_free(name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline void __album_deinit_file(struct cache_file *f)
|
||||
static inline void __album_free_file(struct album_cache_file *acf)
|
||||
{
|
||||
g_free(f->cf_subdir);
|
||||
g_free(f->cf_name);
|
||||
g_free(acf->ac_subdir);
|
||||
g_free(acf->ac_name);
|
||||
g_free(acf);
|
||||
}
|
||||
|
||||
static bool __album_fetch_cover(struct album *album, gchar *releaseid)
|
||||
{
|
||||
struct cache_file file;
|
||||
struct album_cache_file *file;
|
||||
CaaImageData image;
|
||||
CaaCoverArt *caa;
|
||||
gchar error[256];
|
||||
|
@ -52,13 +63,13 @@ static bool __album_fetch_cover(struct album *album, gchar *releaseid)
|
|||
goto out;
|
||||
}
|
||||
|
||||
__album_init_file(album, &file);
|
||||
if (cache_file_open(&file, OPEN_WRITE)) {
|
||||
cache_file_write(&file, caa_imagedata_data(image),
|
||||
file = __album_alloc_file(album);
|
||||
if (cache_file_open(&file->ac_file, OPEN_WRITE)) {
|
||||
cache_file_write(&file->ac_file, caa_imagedata_data(image),
|
||||
caa_imagedata_size(image));
|
||||
cache_file_close(&file);
|
||||
cache_file_close(&file->ac_file);
|
||||
}
|
||||
__album_deinit_file(&file);
|
||||
__album_free_file(file);
|
||||
|
||||
caa_imagedata_delete(image);
|
||||
out:
|
||||
|
@ -351,40 +362,40 @@ bool album_match_token(struct album *album, const gchar *string)
|
|||
|
||||
bool album_artwork_exists(struct album *album)
|
||||
{
|
||||
struct cache_file file;
|
||||
struct album_cache_file *file;
|
||||
bool ret;
|
||||
|
||||
__album_init_file(album, &file);
|
||||
ret = cache_file_exists(&file);
|
||||
__album_deinit_file(&file);
|
||||
file = __album_alloc_file(album);
|
||||
ret = cache_file_exists(&file->ac_file);
|
||||
__album_free_file(file);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
gchar *album_artwork_path(struct album *album)
|
||||
{
|
||||
struct cache_file file;
|
||||
struct album_cache_file *file;
|
||||
gchar *ret = NULL;
|
||||
|
||||
__album_init_file(album, &file);
|
||||
if (cache_file_exists(&file))
|
||||
ret = cache_file_path(&file);
|
||||
__album_deinit_file(&file);
|
||||
file = __album_alloc_file(album);
|
||||
if (cache_file_exists(&file->ac_file))
|
||||
ret = cache_file_path(&file->ac_file);
|
||||
__album_free_file(file);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool album_artwork_import(struct album *album, gchar *path)
|
||||
{
|
||||
struct cache_file file;
|
||||
struct album_cache_file *file;
|
||||
bool ret = false;
|
||||
|
||||
__album_init_file(album, &file);
|
||||
if (path && cache_file_open(&file, OPEN_WRITE)) {
|
||||
ret = cache_file_import(&file, path);
|
||||
cache_file_close(&file);
|
||||
file = __album_alloc_file(album);
|
||||
if (path && cache_file_open(&file->ac_file, OPEN_WRITE)) {
|
||||
ret = cache_file_import(&file->ac_file, path);
|
||||
cache_file_close(&file->ac_file);
|
||||
}
|
||||
__album_deinit_file(&file);
|
||||
__album_free_file(file);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue