diff options
Diffstat (limited to 'src/settings.c')
-rw-r--r-- | src/settings.c | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/src/settings.c b/src/settings.c index a7a26a6..dddc05c 100644 --- a/src/settings.c +++ b/src/settings.c @@ -30,9 +30,11 @@ THE SOFTWARE. #include <stdlib.h> #include <stdio.h> #include <limits.h> +#include <assert.h> #include "settings.h" #include "config.h" +#include "ui_dispatch.h" #define streq(a, b) (strcmp (a, b) == 0) @@ -93,20 +95,9 @@ void BarSettingsDestroy (BarSettings_t *settings) { void BarSettingsRead (BarSettings_t *settings) { char configfile[PATH_MAX], key[256], val[256]; FILE *configfd; - /* _must_ have same order as in BarKeyShortcutId_t */ - static const char defaultKeys[] = {'?', '+', '-', 'a', 'c', 'd', 'e', 'g', - 'h', 'i', 'j', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'x', '$', - 'b', '(', ')', - }; - static const char *shortcutFileKeys[] = { - "act_help", "act_songlove", "act_songban", "act_stationaddmusic", - "act_stationcreate", "act_stationdelete", "act_songexplain", - "act_stationaddbygenre", "act_history", "act_songinfo", - "act_addshared", "act_songmove", "act_songnext", "act_songpause", - "act_quit", "act_stationrename", "act_stationchange", - "act_songtired", "act_upcoming", "act_stationselectquickmix", - "act_debug", "act_bookmark", "act_voldown", "act_volup", - }; + + assert (sizeof (settings->keys) / sizeof (*settings->keys) == + sizeof (dispatchActions) / sizeof (*dispatchActions)); /* apply defaults */ #ifdef ENABLE_FAAD @@ -119,9 +110,11 @@ void BarSettingsRead (BarSettings_t *settings) { settings->history = 5; settings->volume = 0; settings->sortOrder = BAR_SORT_NAME_AZ; - memcpy (settings->keys, defaultKeys, sizeof (defaultKeys)); settings->loveIcon = strdup ("<3"); settings->banIcon = strdup ("</3"); + for (size_t i = 0; i < BAR_KS_COUNT; i++) { + settings->keys[i] = dispatchActions[i].defaultKey; + } BarGetXdgConfigDir (PACKAGE "/config", configfile, sizeof (configfile)); if ((configfd = fopen (configfile, "r")) == NULL) { @@ -149,7 +142,7 @@ void BarSettingsRead (BarSettings_t *settings) { size_t i; /* keyboard shortcuts */ for (i = 0; i < BAR_KS_COUNT; i++) { - if (streq (shortcutFileKeys[i], key)) { + if (streq (dispatchActions[i].configKey, key)) { if (streq (val, "disabled")) { settings->keys[i] = BAR_KS_DISABLED; } else { |