From 414817031d3825bc4f4f5127c6a37d535b40d2d1 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Sat, 30 Nov 2013 12:57:38 +0100 Subject: [PATCH] Configurable library names Names of Library, Music, Movies, TV Shows and Podcasts made configurable --- forked-daapd.conf | 8 ++++++++ src/conffile.c | 5 +++++ src/db.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/forked-daapd.conf b/forked-daapd.conf index a6035bcb..7be42a22 100644 --- a/forked-daapd.conf +++ b/forked-daapd.conf @@ -44,6 +44,14 @@ library { # a single name which will be used for all music in the compilation dir compilation_artist = "Various artists" + # There are 5 default playlists: "Library", "Music", "Movies", "TV Shows" + # and "Podcasts". Here you can change the names of these playlists. +# name_library = "Library" +# name_music = "Music" +# name_movies = "Movies" +# name_tvshows = "TV Shows" +# name_podcasts = "Podcasts" + # Artwork file names (without file type extension) # forked-daapd will look for jpg and png files with these base names # artwork_basenames = { "artwork", "cover", "Folder" } diff --git a/src/conffile.c b/src/conffile.c index dedb7d28..ebff3f6e 100644 --- a/src/conffile.c +++ b/src/conffile.c @@ -63,6 +63,11 @@ static cfg_opt_t sec_library[] = CFG_STR_LIST("podcasts", NULL, CFGF_NONE), CFG_STR_LIST("compilations", NULL, CFGF_NONE), CFG_STR("compilation_artist", NULL, CFGF_NONE), + CFG_STR("name_library", "Library", CFGF_NONE), + CFG_STR("name_music", "Music", CFGF_NONE), + CFG_STR("name_movies", "Movies", CFGF_NONE), + CFG_STR("name_tvshows", "TV Shows", CFGF_NONE), + CFG_STR("name_podcasts", "Podcasts", CFGF_NONE), CFG_STR_LIST("artwork_basenames", "{artwork,cover,Folder}", CFGF_NONE), CFG_STR_LIST("filetypes_ignore", "{.db,.ini}", CFGF_NONE), CFG_BOOL("itunes_overrides", cfg_false, CFGF_NONE), diff --git a/src/db.c b/src/db.c index e80aaac7..93f83762 100644 --- a/src/db.c +++ b/src/db.c @@ -588,6 +588,55 @@ db_analyze(void) } } +/* Set names of default playlists according to config */ +static void +db_set_cfg_names(void) +{ +#define Q_TMPL "UPDATE playlists SET title = '%q' WHERE type = 1 AND special_id = %d;" + char *cfg_item[5] = { "name_library", "name_music", "name_movies", "name_tvshows", "name_podcasts" }; + char special_id[5] = { 0, 6, 4, 5, 1 }; + cfg_t *lib; + char *query; + char *title; + char *errmsg; + int ret; + int i; + + lib = cfg_getsec(cfg, "library"); + + for (i = 0; i < (sizeof(cfg_item) / sizeof(cfg_item[0])); i++) + { + title = cfg_getstr(lib, cfg_item[i]); + if (!title) + { + DPRINTF(E_LOG, L_DB, "Internal error, unknown config item '%s'\n", cfg_item[i]); + + continue; + } + + query = sqlite3_mprintf(Q_TMPL, title, special_id[i]); + if (!query) + { + DPRINTF(E_LOG, L_DB, "Out of memory for query string\n"); + + return; + } + + ret = db_exec(query, &errmsg); + if (ret != SQLITE_OK) + { + DPRINTF(E_LOG, L_DB, "Error setting playlist title, query %s, error: %s\n", query, errmsg); + + sqlite3_free(errmsg); + } + else + DPRINTF(E_DBG, L_DB, "Playlist title for config item '%s' set with query '%s'\n", cfg_item[i], query); + + sqlite3_free(query); + } +#undef Q_TMPL +} + void db_hook_post_scan(void) { @@ -4989,6 +5038,8 @@ db_init(void) db_analyze(); + db_set_cfg_names(); + files = db_files_get_count(); pls = db_pl_get_count();