summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cee4c04)
raw | patch | inline | side by side (parent: cee4c04)
author | Max Kellermann <max@duempel.org> | |
Thu, 25 Sep 2008 19:20:06 +0000 (21:20 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Thu, 25 Sep 2008 19:20:06 +0000 (21:20 +0200) |
Move the hard-coded screen list and everything which works with this
array to screen_list.c.
array to screen_list.c.
src/Makefile.am | patch | blob | history | |
src/screen.c | patch | blob | history | |
src/screen.h | patch | blob | history | |
src/screen_list.c | [new file with mode: 0644] | patch | blob |
src/screen_list.h | [new file with mode: 0644] | patch | blob |
diff --git a/src/Makefile.am b/src/Makefile.am
index f91c2cff5ef04d493b89d0e9de4697021c978c20..106cd3e2eaa0d3ff3d23ca756eeae6bf4db30951 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
command.h\
ncu.h \
screen.h\
+ screen_list.h \
screen_utils.h\
list_window.h\
colors.h\
command.c\
ncu.c \
screen.c\
+ screen_list.c \
screen_utils.c\
screen_play.c\
screen_browser.c\
diff --git a/src/screen.c b/src/screen.c
index 71631db6e48d61fa1aa64d85ec836996b1e812a5..cea637a8de9ea497c9d5642eeef85ab2f557fded 100644 (file)
--- a/src/screen.c
+++ b/src/screen.c
*/
#include "screen.h"
+#include "screen_list.h"
#include "screen_utils.h"
#include "config.h"
#include "ncmpc.h"
#include <time.h>
#include <locale.h>
-#define SCREEN_PLAYLIST_ID 0
-#define SCREEN_BROWSE_ID 1
-#define SCREEN_ARTIST_ID 2
-#define SCREEN_HELP_ID 100
-#define SCREEN_KEYDEF_ID 101
-#define SCREEN_SEARCH_ID 103
-#define SCREEN_LYRICS_ID 104
-
-
-
/* screens */
-extern const struct screen_functions screen_playlist;
-extern const struct screen_functions screen_browse;
-#ifdef ENABLE_ARTIST_SCREEN
-extern const struct screen_functions screen_artist;
-#endif
-extern const struct screen_functions screen_help;
-#ifdef ENABLE_SEARCH_SCREEN
-extern const struct screen_functions screen_search;
-#endif
-#ifdef ENABLE_KEYDEF_SCREEN
-extern const struct screen_functions screen_keydef;
-#endif
-#ifdef ENABLE_LYRICS_SCREEN
-extern const struct screen_functions screen_lyrics;
-#endif
-
-typedef struct screen_functions * (*screen_get_mode_functions_fn_t) (void);
-
-static const struct
-{
- gint id;
- const gchar *name;
- const struct screen_functions *functions;
-} screens[] = {
- { SCREEN_PLAYLIST_ID, "playlist", &screen_playlist },
- { SCREEN_BROWSE_ID, "browse", &screen_browse },
-#ifdef ENABLE_ARTIST_SCREEN
- { SCREEN_ARTIST_ID, "artist", &screen_artist },
-#endif
- { SCREEN_HELP_ID, "help", &screen_help },
-#ifdef ENABLE_SEARCH_SCREEN
- { SCREEN_SEARCH_ID, "search", &screen_search },
-#endif
-#ifdef ENABLE_KEYDEF_SCREEN
- { SCREEN_KEYDEF_ID, "keydef", &screen_keydef },
-#endif
-#ifdef ENABLE_LYRICS_SCREEN
- { SCREEN_LYRICS_ID, "lyrics", &screen_lyrics },
-#endif
-};
-
-#define NUM_SCREENS (sizeof(screens) / sizeof(screens[0]))
static gboolean welcome = TRUE;
static struct screen screen;
static int seek_id = -1;
static int seek_target_time = 0;
-gint
-screen_get_id(const char *name)
-{
- guint i;
-
- for (i = 0; i < NUM_SCREENS; ++i)
- if (strcmp(name, screens[i].name) == 0)
- return screens[i].id;
-
- return -1;
-}
-
-static gint
-lookup_mode(gint id)
-{
- guint i;
-
- for (i = 0; i < NUM_SCREENS; ++i)
- if (screens[i].id == id)
- return i;
-
- return -1;
-}
-
gint get_cur_mode_id(void)
{
- return screens[screen.mode].id;
+ return screen_get_id_by_index(screen.mode);
}
static void
{
gint new_mode;
- if( id == screens[screen.mode].id )
+ if (id == screen_get_id_by_index(screen.mode))
return;
new_mode = lookup_mode(id);
mode_fn->close();
/* get functions for the new mode */
- D("switch_screen(%s)\n", screens[new_mode].name );
- mode_fn = screens[new_mode].functions;
+ mode_fn = screen_get_functions(new_mode);
screen.mode = new_mode;
screen.painted = 0;
int current, next;
/* find current screen */
- current = find_configured_screen(screens[screen.mode].name);
+ current = find_configured_screen(screen_get_name(screen.mode));
next = current + offset;
if (next<0)
next = max-1;
void
screen_exit(void)
{
- guint i;
-
if (mode_fn->close != NULL)
mode_fn->close();
- /* close and exit all screens (playlist,browse,help...) */
- for (i = 0; i < NUM_SCREENS; ++i) {
- const struct screen_functions *sf = screens[i].functions;
-
- if (sf->exit)
- sf->exit();
- }
+ screen_list_exit();
string_list_free(screen.find_history);
g_free(screen.buf);
void
screen_resize(void)
{
- guint i;
-
D("Resize rows %d->%d, cols %d->%d\n",screen.rows,LINES,screen.cols,COLS);
if (COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS) {
screen_exit();
g_free(screen.buf);
screen.buf = g_malloc(screen.cols);
- /* close and exit all screens (playlist,browse,help...) */
- for (i = 0; i < NUM_SCREENS; ++i) {
- const struct screen_functions *sf = screens[i].functions;
-
- if (sf->resize)
- sf->resize(screen.main_window.cols, screen.main_window.rows);
- }
-
+ /* resize all screens */
+ screen_list_resize(screen.main_window.cols, screen.main_window.rows);
/* ? - without this the cursor becomes visible with aterm & Eterm */
curs_set(1);
void
screen_init(mpdclient_t *c)
{
- guint i;
-
if (COLS < SCREEN_MIN_COLS || LINES < SCREEN_MIN_ROWS) {
fprintf(stderr, _("Error: Screen to small!\n"));
exit(EXIT_FAILURE);
refresh();
/* initialize screens */
- for (i = 0; i < NUM_SCREENS; ++i) {
- const struct screen_functions *fn = screens[i].functions;
-
- if (fn->init)
- fn->init(screen.main_window.w,
- screen.main_window.cols,
- screen.main_window.rows);
- }
+ screen_list_init(screen.main_window.w,
+ screen.main_window.cols, screen.main_window.rows);
if (mode_fn->open != NULL)
mode_fn->open(&screen, c);
diff --git a/src/screen.h b/src/screen.h
index 3ba5541fb8896707d0d19190921241aa5a1b5637..7a8b0edb3dba2dba06e13e128dc1b689a7156062 100644 (file)
--- a/src/screen.h
+++ b/src/screen.h
typedef int (*screen_cmd_fn_t)(struct screen *scr, mpdclient_t *c, command_t cmd);
typedef const char *(*screen_title_fn_t)(char *s, size_t size);
+extern const struct screen_functions screen_playlist;
+extern const struct screen_functions screen_browse;
+#ifdef ENABLE_ARTIST_SCREEN
+extern const struct screen_functions screen_artist;
+#endif
+extern const struct screen_functions screen_help;
+#ifdef ENABLE_SEARCH_SCREEN
+extern const struct screen_functions screen_search;
+#endif
+#ifdef ENABLE_KEYDEF_SCREEN
+extern const struct screen_functions screen_keydef;
+#endif
+#ifdef ENABLE_LYRICS_SCREEN
+extern const struct screen_functions screen_lyrics;
+#endif
+
typedef struct screen_functions {
screen_init_fn_t init;
screen_exit_fn_t exit;
diff --git a/src/screen_list.c b/src/screen_list.c
--- /dev/null
+++ b/src/screen_list.c
@@ -0,0 +1,135 @@
+/*
+ * (c) 2004 by Kalle Wallin <kaw@linux.se>
+ * Copyright (C) 2008 Max Kellermann <max@duempel.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "screen_list.h"
+#include "screen.h"
+
+#include <string.h>
+
+static const struct
+{
+ int id;
+ const char *name;
+ const struct screen_functions *functions;
+} screens[] = {
+ { SCREEN_PLAYLIST_ID, "playlist", &screen_playlist },
+ { SCREEN_BROWSE_ID, "browse", &screen_browse },
+#ifdef ENABLE_ARTIST_SCREEN
+ { SCREEN_ARTIST_ID, "artist", &screen_artist },
+#endif
+ { SCREEN_HELP_ID, "help", &screen_help },
+#ifdef ENABLE_SEARCH_SCREEN
+ { SCREEN_SEARCH_ID, "search", &screen_search },
+#endif
+#ifdef ENABLE_KEYDEF_SCREEN
+ { SCREEN_KEYDEF_ID, "keydef", &screen_keydef },
+#endif
+#ifdef ENABLE_LYRICS_SCREEN
+ { SCREEN_LYRICS_ID, "lyrics", &screen_lyrics },
+#endif
+};
+
+static const unsigned NUM_SCREENS = sizeof(screens) / sizeof(screens[0]);
+
+void
+screen_list_init(WINDOW *w, unsigned cols, unsigned rows)
+{
+ unsigned i;
+
+ for (i = 0; i < NUM_SCREENS; ++i) {
+ const struct screen_functions *sf = screens[i].functions;
+
+ if (sf->init)
+ sf->init(w, cols, rows);
+ }
+}
+
+void
+screen_list_exit(void)
+{
+ unsigned i;
+
+ for (i = 0; i < NUM_SCREENS; ++i) {
+ const struct screen_functions *sf = screens[i].functions;
+
+ if (sf->exit)
+ sf->exit();
+ }
+}
+
+void
+screen_list_resize(unsigned cols, unsigned rows)
+{
+ unsigned i;
+
+ for (i = 0; i < NUM_SCREENS; ++i) {
+ const struct screen_functions *sf = screens[i].functions;
+
+ if (sf->resize)
+ sf->resize(cols, rows);
+ }
+}
+
+int
+screen_get_id_by_index(unsigned i)
+{
+ assert(i < NUM_SCREENS);
+
+ return screens[i].id;
+}
+
+const char *
+screen_get_name(unsigned i)
+{
+ assert(i < NUM_SCREENS);
+
+ return screens[i].name;
+}
+
+int
+screen_get_id(const char *name)
+{
+ unsigned i;
+
+ for (i = 0; i < NUM_SCREENS; ++i)
+ if (strcmp(name, screens[i].name) == 0)
+ return screens[i].id;
+
+ return -1;
+}
+
+const struct screen_functions *
+screen_get_functions(unsigned i)
+{
+ assert(i < NUM_SCREENS);
+
+ return screens[i].functions;
+}
+
+int
+lookup_mode(int id)
+{
+ unsigned i;
+
+ for (i = 0; i < NUM_SCREENS; ++i)
+ if (screens[i].id == id)
+ return i;
+
+ return -1;
+}
diff --git a/src/screen_list.h b/src/screen_list.h
--- /dev/null
+++ b/src/screen_list.h
@@ -0,0 +1,75 @@
+/*
+ * (c) 2004 by Kalle Wallin <kaw@linux.se>
+ * Copyright (C) 2008 Max Kellermann <max@duempel.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifndef SCREEN_LIST_H
+#define SCREEN_LIST_H
+
+#include "ncmpc.h"
+
+#include <ncurses.h>
+
+#define SCREEN_PLAYLIST_ID 0
+#define SCREEN_BROWSE_ID 1
+#define SCREEN_ARTIST_ID 2
+#define SCREEN_HELP_ID 100
+#define SCREEN_KEYDEF_ID 101
+#define SCREEN_SEARCH_ID 103
+#define SCREEN_LYRICS_ID 104
+
+extern const struct screen_functions screen_playlist;
+extern const struct screen_functions screen_browse;
+#ifdef ENABLE_ARTIST_SCREEN
+extern const struct screen_functions screen_artist;
+#endif
+extern const struct screen_functions screen_help;
+#ifdef ENABLE_SEARCH_SCREEN
+extern const struct screen_functions screen_search;
+#endif
+#ifdef ENABLE_KEYDEF_SCREEN
+extern const struct screen_functions screen_keydef;
+#endif
+#ifdef ENABLE_LYRICS_SCREEN
+extern const struct screen_functions screen_lyrics;
+#endif
+
+void
+screen_list_init(WINDOW *w, unsigned cols, unsigned rows);
+
+void
+screen_list_exit(void);
+
+void
+screen_list_resize(unsigned cols, unsigned rows);
+
+int
+screen_get_id_by_index(unsigned i);
+
+const char *
+screen_get_name(unsigned i);
+
+int
+screen_get_id(const char *name);
+
+const struct screen_functions *
+screen_get_functions(unsigned i);
+
+int
+lookup_mode(int id);
+
+#endif