core/settings: Check for a NULL key

This fixes a problem with restoring treeview columns.  Sometimes
"Played" gets allocated way too much space, so I solve this by changing
it's setting key to NULL so the column always gets whatever space is
leftover.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2016-09-26 10:52:44 -04:00
parent 2e38b3551e
commit 93d1550763
5 changed files with 16 additions and 8 deletions

View File

@ -1,3 +1,7 @@
6.5.0:
- Add a switch to disable GUI tests
- Don't save and restore the "Last Played" tracks column width
6.5.0-rc:
- Convert to CMake/CTest
- Save current track in settings database

View File

@ -54,7 +54,7 @@ void settings_deinit()
void settings_set(const gchar *key, unsigned int value)
{
if (gui_settings) {
if (gui_settings && key) {
g_hash_table_replace(gui_settings, g_strdup(key),
GUINT_TO_POINTER(value));
__settings_save();
@ -63,14 +63,14 @@ void settings_set(const gchar *key, unsigned int value)
unsigned int settings_get(const gchar *key)
{
if (gui_settings)
if (gui_settings && key)
return GPOINTER_TO_UINT(g_hash_table_lookup(gui_settings, key));
return 0;
}
bool settings_has(const gchar *key)
{
if (gui_settings)
if (gui_settings && key)
return g_hash_table_contains(gui_settings, key);
return false;
}

View File

@ -20,9 +20,9 @@ static const gchar *QUEUE_SETTINGS[Q_MODEL_N_COLUMNS] = {
[Q_MODEL_YEAR] = "gui.queue.year",
[Q_MODEL_GENRE] = "gui.queue.genre",
[Q_MODEL_COUNT] = "gui.queue.count",
[Q_MODEL_LAST_PLAY] = "gui.queue.played",
[Q_MODEL_FILE_PATH] = "gui.queue.filepath",
[Q_MODEL_FONT] = "gui.queue.font",
[Q_MODEL_LAST_PLAY] = NULL,
[Q_MODEL_FILE_PATH] = NULL,
[Q_MODEL_FONT] = NULL,
};
static const enum compare_t QUEUE_SORT[Q_MODEL_N_COLUMNS] = {

View File

@ -9,6 +9,10 @@ static void test_settings()
{
struct file f = FILE_INIT("settings", 0);
settings_set(NULL, 0);
g_assert_cmpuint(settings_get(NULL), ==, 0);
g_assert_false(settings_has(NULL));
g_assert_null(test_get_settings());
settings_set("test.value1", 42);
settings_set("test.value2", 84);

View File

@ -86,10 +86,10 @@ static void test_treeview()
g_main_loop_run(main_loop);
for (i = 0; i < Q_MODEL_N_COLUMNS; i++) {
bool has = (i != Q_MODEL_FILE_PATH) && (i != Q_MODEL_FONT);
bool has = (i < Q_MODEL_LAST_PLAY);
g_assert(settings_has(QUEUE_SETTINGS[i]) == has);
/* The "Played" column gets any remaining space. */
if (has && i != Q_MODEL_LAST_PLAY)
if (has)
g_assert_cmpuint(settings_get(QUEUE_SETTINGS[i]),
==, (i + 2) * 10);
}