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 struct database album_db;
|
||||||
static bool album_db_upgraded = false;
|
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);
|
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);
|
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(acf->ac_subdir);
|
||||||
g_free(f->cf_name);
|
g_free(acf->ac_name);
|
||||||
|
g_free(acf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool __album_fetch_cover(struct album *album, gchar *releaseid)
|
static bool __album_fetch_cover(struct album *album, gchar *releaseid)
|
||||||
{
|
{
|
||||||
struct cache_file file;
|
struct album_cache_file *file;
|
||||||
CaaImageData image;
|
CaaImageData image;
|
||||||
CaaCoverArt *caa;
|
CaaCoverArt *caa;
|
||||||
gchar error[256];
|
gchar error[256];
|
||||||
|
@ -52,13 +63,13 @@ static bool __album_fetch_cover(struct album *album, gchar *releaseid)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
__album_init_file(album, &file);
|
file = __album_alloc_file(album);
|
||||||
if (cache_file_open(&file, OPEN_WRITE)) {
|
if (cache_file_open(&file->ac_file, OPEN_WRITE)) {
|
||||||
cache_file_write(&file, caa_imagedata_data(image),
|
cache_file_write(&file->ac_file, caa_imagedata_data(image),
|
||||||
caa_imagedata_size(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);
|
caa_imagedata_delete(image);
|
||||||
out:
|
out:
|
||||||
|
@ -351,40 +362,40 @@ bool album_match_token(struct album *album, const gchar *string)
|
||||||
|
|
||||||
bool album_artwork_exists(struct album *album)
|
bool album_artwork_exists(struct album *album)
|
||||||
{
|
{
|
||||||
struct cache_file file;
|
struct album_cache_file *file;
|
||||||
bool ret;
|
bool ret;
|
||||||
|
|
||||||
__album_init_file(album, &file);
|
file = __album_alloc_file(album);
|
||||||
ret = cache_file_exists(&file);
|
ret = cache_file_exists(&file->ac_file);
|
||||||
__album_deinit_file(&file);
|
__album_free_file(file);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar *album_artwork_path(struct album *album)
|
gchar *album_artwork_path(struct album *album)
|
||||||
{
|
{
|
||||||
struct cache_file file;
|
struct album_cache_file *file;
|
||||||
gchar *ret = NULL;
|
gchar *ret = NULL;
|
||||||
|
|
||||||
__album_init_file(album, &file);
|
file = __album_alloc_file(album);
|
||||||
if (cache_file_exists(&file))
|
if (cache_file_exists(&file->ac_file))
|
||||||
ret = cache_file_path(&file);
|
ret = cache_file_path(&file->ac_file);
|
||||||
__album_deinit_file(&file);
|
__album_free_file(file);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool album_artwork_import(struct album *album, gchar *path)
|
bool album_artwork_import(struct album *album, gchar *path)
|
||||||
{
|
{
|
||||||
struct cache_file file;
|
struct album_cache_file *file;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
__album_init_file(album, &file);
|
file = __album_alloc_file(album);
|
||||||
if (path && cache_file_open(&file, OPEN_WRITE)) {
|
if (path && cache_file_open(&file->ac_file, OPEN_WRITE)) {
|
||||||
ret = cache_file_import(&file, path);
|
ret = cache_file_import(&file->ac_file, path);
|
||||||
cache_file_close(&file);
|
cache_file_close(&file->ac_file);
|
||||||
}
|
}
|
||||||
__album_deinit_file(&file);
|
__album_free_file(file);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue