summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3809e2f)
raw | patch | inline | side by side (parent: 3809e2f)
author | Max Kellermann <max@duempel.org> | |
Thu, 25 Sep 2008 19:21:00 +0000 (21:21 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Thu, 25 Sep 2008 19:21:00 +0000 (21:21 +0200) |
Trying to get rid of the screen ids. A pointer to screen_functions is
better for identifying a screen.
better for identifying a screen.
src/conf.c | patch | blob | history | |
src/screen.c | patch | blob | history | |
src/screen_list.c | patch | blob | history | |
src/screen_list.h | patch | blob | history |
diff --git a/src/conf.c b/src/conf.c
index c02df52cf42f79e19273c0b8ca96aef27076f8d9..557024dc52967ce726fda045552ea9dab03bb62a 100644 (file)
--- a/src/conf.c
+++ b/src/conf.c
#include "support.h"
#include "command.h"
#include "colors.h"
+#include "screen_list.h"
#include <ctype.h>
#include <stdio.h>
KEY_PARSER_DONE
} key_parser_state_t;
-
-extern gint screen_get_id(char *name);
-
-
static gboolean
str2bool(char *str)
{
j=0;
while( tmp && tmp[i] ) {
tmp[i] = lowerstr(tmp[i]);
- if( screen_get_id(tmp[i]) == -1 )
+ if (screen_lookup_name(tmp[i]) == NULL)
fprintf(stderr,
_("Error: Unsupported screen \"%s\"\n"),
tmp[i]);
diff --git a/src/screen.c b/src/screen.c
index 02df03b528df4a0a4231527c8210a1ab5019e777..2124a2b7489c81cc0709616a6d5ede22af50b638 100644 (file)
--- a/src/screen.c
+++ b/src/screen.c
}
static void
-switch_screen_mode(gint id, mpdclient_t *c)
+switch_screen_mode(const struct screen_functions *sf, mpdclient_t *c)
{
gint new_mode;
- if (id == screen_get_id_by_index(screen.mode))
+ if (sf == mode_fn)
return;
- new_mode = lookup_mode(id);
+ new_mode = lookup_mode(sf);
if (new_mode < 0)
return;
mode_fn->close();
/* get functions for the new mode */
- mode_fn = screen_get_functions(new_mode);
+ mode_fn = sf;
screen.mode = new_mode;
screen.painted = 0;
next = 0;
D("current mode: %d:%d next:%d\n", current, max, next);
- switch_screen_mode(screen_get_id(options.screen_list[next]), c);
+ switch_screen_mode(screen_lookup_name(options.screen_list[next]), c);
}
static void
screen_next_mode(c, 1);
break;
case CMD_SCREEN_PLAY:
- switch_screen_mode(SCREEN_PLAYLIST_ID, c);
+ switch_screen_mode(&screen_playlist, c);
break;
case CMD_SCREEN_FILE:
- switch_screen_mode(SCREEN_BROWSE_ID, c);
+ switch_screen_mode(&screen_browse, c);
break;
case CMD_SCREEN_HELP:
- switch_screen_mode(SCREEN_HELP_ID, c);
+ switch_screen_mode(&screen_help, c);
break;
+#ifdef ENABLE_SEARCH_SCREEN
case CMD_SCREEN_SEARCH:
- switch_screen_mode(SCREEN_SEARCH_ID, c);
+ switch_screen_mode(&screen_search, c);
break;
+#endif
+#ifdef ENABLE_ARTIST_SCREEN
case CMD_SCREEN_ARTIST:
- switch_screen_mode(SCREEN_ARTIST_ID, c);
+ switch_screen_mode(&screen_artist, c);
break;
+#endif
+#ifdef ENABLE_KEYDEF_SCREEN
case CMD_SCREEN_KEYDEF:
- switch_screen_mode(SCREEN_KEYDEF_ID, c);
+ switch_screen_mode(&screen_keydef, c);
break;
+#endif
+#ifdef ENABLE_LYRICS_SCREEN
case CMD_SCREEN_LYRICS:
- switch_screen_mode(SCREEN_LYRICS_ID, c);
+ switch_screen_mode(&screen_lyrics, c);
break;
+#endif
default:
break;
}
diff --git a/src/screen_list.c b/src/screen_list.c
index 46e6244180756fbc72614626afc4761e2489eb30..76ae8b155c53978580ac3237364fcbfe18771e19 100644 (file)
--- a/src/screen_list.c
+++ b/src/screen_list.c
}
}
-int
-screen_get_id_by_index(unsigned i)
-{
- assert(i < NUM_SCREENS);
-
- return screens[i].id;
-}
-
const char *
screen_get_name(unsigned i)
{
return screens[i].name;
}
-int
-screen_get_id(const char *name)
+const struct screen_functions *
+screen_lookup_name(const char *name)
{
unsigned i;
for (i = 0; i < NUM_SCREENS; ++i)
if (strcmp(name, screens[i].name) == 0)
- return screens[i].id;
+ return screens[i].functions;
- return -1;
+ return NULL;
}
const struct screen_functions *
}
int
-lookup_mode(int id)
+lookup_mode(const struct screen_functions *sf)
{
unsigned i;
for (i = 0; i < NUM_SCREENS; ++i)
- if (screens[i].id == id)
+ if (screens[i].functions == sf)
return i;
return -1;
diff --git a/src/screen_list.h b/src/screen_list.h
index 7efed89b06c4bc12a858f41f1326b9e0abb4b321..763b4ee9be84ce033b26c896b4bedee890709f0f 100644 (file)
--- a/src/screen_list.h
+++ b/src/screen_list.h
void
screen_list_resize(unsigned cols, unsigned rows);
-int
-screen_get_id_by_index(unsigned i);
-
const char *
screen_get_name(unsigned i);
+const struct screen_functions *
+screen_lookup_name(const char *name);
+
int
screen_get_id(const char *name);
screen_get_functions(unsigned i);
int
-lookup_mode(int id);
+lookup_mode(const struct screen_functions *sf);
#endif