aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Makefile.am4
-rw-r--r--list_window.c206
-rw-r--r--list_window.h54
-rw-r--r--main.c2
-rw-r--r--screen.h2
-rw-r--r--screen_file.c38
-rw-r--r--screen_help.c36
-rw-r--r--screen_play.c39
-rw-r--r--screen_utils.c159
-rw-r--r--screen_utils.h46
10 files changed, 280 insertions, 306 deletions
diff --git a/Makefile.am b/Makefile.am
index 9731afbec..96e6b1dd0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -11,12 +11,12 @@ EXTRA_DIST = COPYING $(pkgdata_DATA) $(man_MANS) $(doc_DATA)
ncmpc_headers = libmpdclient.h mpc.h options.h command.h screen.h \
screen_utils.h screen_play.h screen_file.h screen_search.h \
- screen_help.h support.h
+ screen_help.h list_window.h support.h
ncmpc_SOURCES = libmpdclient.c main.c mpc.c options.c command.c \
screen.c screen_utils.c screen_play.c screen_file.c \
screen_search.c screen_help.c \
- support.c $(ncmpc_headers)
+ list_window.c support.c $(ncmpc_headers)
diff --git a/list_window.c b/list_window.c
new file mode 100644
index 000000000..21ee9119f
--- /dev/null
+++ b/list_window.c
@@ -0,0 +1,206 @@
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <glib.h>
+#include <ncurses.h>
+
+#include "support.h"
+#include "command.h"
+#include "list_window.h"
+
+list_window_t *
+list_window_init(WINDOW *w, int width, int height)
+{
+ list_window_t *lw;
+
+ lw = malloc(sizeof(list_window_t));
+ memset(lw, 0, sizeof(list_window_t));
+ lw->w = w;
+ lw->cols = width;
+ lw->rows = height;
+ lw->clear = 1;
+ return lw;
+}
+
+list_window_t *
+list_window_free(list_window_t *lw)
+{
+ if( lw )
+ {
+ memset(lw, 0, sizeof(list_window_t));
+ free(lw);
+ }
+ return NULL;
+}
+
+void
+list_window_reset(list_window_t *lw)
+{
+ lw->selected = 0;
+ lw->start = 0;
+ lw->clear = 1;
+}
+
+void
+list_window_set_selected(list_window_t *lw, int n)
+{
+ lw->selected=n;
+}
+
+void
+list_window_next(list_window_t *lw, int length)
+{
+ if( lw->selected < length-1 )
+ lw->selected++;
+}
+
+void
+list_window_previous(list_window_t *lw)
+{
+ if( lw->selected > 0 )
+ lw->selected--;
+}
+
+void
+list_window_first(list_window_t *lw)
+{
+ lw->selected = 0;
+}
+
+void
+list_window_last(list_window_t *lw, int length)
+{
+ lw->selected = length-1;
+}
+
+void
+list_window_next_page(list_window_t *lw, int length)
+{
+ int step = lw->rows-1;
+ if( step<= 0 )
+ return;
+ if( lw->selected+step < length-1 )
+ lw->selected+=step;
+ else
+ return list_window_last(lw,length);
+}
+
+void
+list_window_previous_page(list_window_t *lw)
+{
+ int step = lw->rows-1;
+ if( step<= 0 )
+ return;
+ if( lw->selected-step > 0 )
+ lw->selected-=step;
+ else
+ list_window_first(lw);
+}
+
+
+void
+list_window_paint(list_window_t *lw,
+ list_window_callback_fn_t callback,
+ void *callback_data)
+{
+ int i;
+
+ while( lw->selected < lw->start )
+ {
+ lw->start--;
+ lw->clear=1;
+ }
+ while( lw->selected >= lw->start+lw->rows )
+ {
+ lw->start++;
+ lw->clear=1;
+ }
+ if( lw->clear )
+ {
+ wclear(lw->w);
+ lw->clear=0;
+ }
+
+ for(i=0; i<lw->rows; i++)
+ {
+ int highlight;
+ char *label;
+
+ label = (callback) (lw->start+i, &highlight, callback_data);
+ if( label )
+ {
+ wmove(lw->w, i, 0);
+ if( highlight )
+ wattron(lw->w, A_BOLD);
+ if( lw->start+i == lw->selected )
+ wattron(lw->w, A_REVERSE);
+
+ waddnstr(lw->w, label, lw->cols);
+
+ if( highlight )
+ wattroff(lw->w, A_BOLD);
+ if( lw->start+i == lw->selected )
+ wattroff(lw->w, A_REVERSE);
+ }
+ }
+}
+
+
+int
+list_window_find(list_window_t *lw,
+ list_window_callback_fn_t callback,
+ void *callback_data,
+ char *str)
+{
+ int h;
+ int i = lw->selected+1;
+ char *label;
+
+ while( (label=(callback) (i,&h,callback_data)) )
+ {
+ if( str && label && strcasestr(label, str) )
+ {
+ lw->selected = i;
+ return 0;
+ }
+ i++;
+ }
+ return 1;
+}
+
+
+/* perform basic list window commands (movement) */
+int
+list_window_cmd(list_window_t *lw, int rows, command_t cmd)
+{
+ switch(cmd)
+ {
+ case CMD_LIST_PREVIOUS:
+ list_window_previous(lw);
+ lw->repaint=1;
+ break;
+ case CMD_LIST_NEXT:
+ list_window_next(lw, rows);
+ lw->repaint=1;
+ break;
+ case CMD_LIST_FIRST:
+ list_window_first(lw);
+ lw->repaint = 1;
+ break;
+ case CMD_LIST_LAST:
+ list_window_last(lw, rows);
+ lw->repaint = 1;
+ break;
+ case CMD_LIST_NEXT_PAGE:
+ list_window_next_page(lw, rows);
+ lw->repaint = 1;
+ break;
+ case CMD_LIST_PREVIOUS_PAGE:
+ list_window_previous_page(lw);
+ lw->repaint = 1;
+ break;
+ default:
+ return 0;
+ }
+ return 1;
+}
diff --git a/list_window.h b/list_window.h
new file mode 100644
index 000000000..87bbf826d
--- /dev/null
+++ b/list_window.h
@@ -0,0 +1,54 @@
+#ifndef LIST_WINDOW_H
+#define LIST_WINDOW_H
+
+typedef char * (*list_window_callback_fn_t) (int index,
+ int *highlight,
+ void *data);
+
+typedef struct
+{
+ WINDOW *w;
+ int rows, cols;
+
+ int start;
+ int selected;
+ int clear;
+ int repaint;
+
+} list_window_t;
+
+
+/* create a new list window */
+list_window_t *list_window_init(WINDOW *w, int width, int height);
+
+/* destroy a list window (returns NULL) */
+list_window_t *list_window_free(list_window_t *lw);
+
+/* reset a list window (selected=0, start=0, clear=1) */
+void list_window_reset(list_window_t *lw);
+
+/* paint a list window */
+void list_window_paint(list_window_t *lw,
+ list_window_callback_fn_t callback,
+ void *callback_data);
+
+/* perform basic list window commands (movement) */
+int list_window_cmd(list_window_t *lw, int rows, command_t cmd);
+
+
+/* select functions */
+void list_window_set_selected(list_window_t *lw, int n);
+void list_window_previous(list_window_t *lw);
+void list_window_next(list_window_t *lw, int length);
+void list_window_first(list_window_t *lw);
+void list_window_last(list_window_t *lw, int length);
+void list_window_previous_page(list_window_t *lw);
+void list_window_next_page(list_window_t *lw, int length);
+
+/* find a string in a list window */
+int list_window_find(list_window_t *lw,
+ list_window_callback_fn_t callback,
+ void *callback_data,
+ char *str);
+
+#endif
diff --git a/main.c b/main.c
index 4e420b75d..c2c29b3ac 100644
--- a/main.c
+++ b/main.c
@@ -121,7 +121,7 @@ main(int argc, const char *argv[])
{
screen_cmd(mpc, cmd);
if( cmd==CMD_VOLUME_UP || cmd==CMD_VOLUME_DOWN)
- counter=10;
+ counter=10; /* make shure we dont update the volume yet */
else
counter=0;
}
diff --git a/screen.h b/screen.h
index 42b8d9133..7b667d823 100644
--- a/screen.h
+++ b/screen.h
@@ -1,7 +1,7 @@
#ifndef SCREEN_H
#define SCREEN_H
#include <ncurses.h>
-#include "screen_utils.h"
+#include "list_window.h"
#define TOP_HEADER_PREFIX "Music Player Client - "
#define TOP_HEADER_PLAY TOP_HEADER_PREFIX "Playlist"
diff --git a/screen_file.c b/screen_file.c
index ba0dbd3e1..809ae3faf 100644
--- a/screen_file.c
+++ b/screen_file.c
@@ -1,8 +1,3 @@
-/*
- * $Id: screen_file.c,v 1.9 2004/03/18 09:33:07 kalle Exp $
- *
- */
-
#include <stdlib.h>
#include <string.h>
#include <glib.h>
@@ -14,6 +9,7 @@
#include "mpc.h"
#include "command.h"
#include "screen.h"
+#include "screen_utils.h"
#include "screen_file.h"
#define BUFSIZE 1024
@@ -302,33 +298,11 @@ file_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
{
case CMD_PLAY:
change_directory(screen, c);
- break;
- case CMD_LIST_PREVIOUS:
- list_window_previous(screen->filelist);
- screen->filelist->repaint=1;
- break;
+ return 1;
case CMD_SELECT:
select_entry(screen, c);
/* continue and select next item... */
- case CMD_LIST_NEXT:
- list_window_next(screen->filelist, c->filelist_length);
- screen->filelist->repaint=1;
- break;
- case CMD_LIST_FIRST:
- list_window_first(screen->filelist);
- screen->filelist->repaint = 1;
- break;
- case CMD_LIST_LAST:
- list_window_last(screen->filelist, c->filelist_length);
- screen->filelist->repaint = 1;
- break;
- case CMD_LIST_NEXT_PAGE:
- list_window_next_page(screen->filelist, c->filelist_length);
- screen->filelist->repaint = 1;
- break;
- case CMD_LIST_PREVIOUS_PAGE:
- list_window_previous_page(screen->filelist);
- screen->filelist->repaint = 1;
+ cmd = CMD_LIST_NEXT;
break;
case CMD_LIST_FIND:
if( screen->findbuf )
@@ -352,9 +326,9 @@ file_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
screen_status_printf("Unable to find \'%s\'", screen->findbuf);
beep();
}
- break;
+ return 1;
default:
- return 0;
+ break;
}
- return 1;
+ return list_window_cmd(screen->filelist, c->filelist_length, cmd);
}
diff --git a/screen_help.c b/screen_help.c
index 3d01363b9..5320647be 100644
--- a/screen_help.c
+++ b/screen_help.c
@@ -1,8 +1,3 @@
-/*
- * $Id: screen_help.c,v 1.8 2004/03/17 13:40:25 kalle Exp $
- *
- */
-
#include <stdlib.h>
#include <string.h>
#include <glib.h>
@@ -13,6 +8,7 @@
#include "mpc.h"
#include "command.h"
#include "screen.h"
+#include "screen_utils.h"
#include "screen_help.h"
typedef struct
@@ -137,30 +133,6 @@ help_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
{
switch(cmd)
{
- case CMD_LIST_PREVIOUS:
- list_window_previous(screen->helplist);
- screen->helplist->repaint=1;
- break;
- case CMD_LIST_NEXT:
- list_window_next(screen->helplist, help_text_rows);
- screen->helplist->repaint=1;
- break;
- case CMD_LIST_FIRST:
- list_window_first(screen->helplist);
- screen->helplist->repaint = 1;
- break;
- case CMD_LIST_LAST:
- list_window_last(screen->helplist, help_text_rows);
- screen->helplist->repaint = 1;
- break;
- case CMD_LIST_PREVIOUS_PAGE:
- list_window_previous_page(screen->helplist);
- screen->helplist->repaint = 1;
- break;
- case CMD_LIST_NEXT_PAGE:
- list_window_next_page(screen->helplist, help_text_rows);
- screen->helplist->repaint = 1;
- break;
case CMD_LIST_FIND:
if( screen->findbuf )
{
@@ -183,9 +155,9 @@ help_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
screen_status_printf("Unable to find \'%s\'", screen->findbuf);
beep();
}
- break;
+ return 1;
default:
- return 0;
+ break;
}
- return 1;
+ return list_window_cmd(screen->helplist, help_text_rows, cmd);
}
diff --git a/screen_play.c b/screen_play.c
index 9d1e9e80a..48dc86961 100644
--- a/screen_play.c
+++ b/screen_play.c
@@ -1,8 +1,3 @@
-/*
- * $Id: screen_play.c,v 1.6 2004/03/17 14:49:31 kalle Exp $
- *
- */
-
#include <stdlib.h>
#include <string.h>
#include <glib.h>
@@ -12,6 +7,7 @@
#include "mpc.h"
#include "command.h"
#include "screen.h"
+#include "screen_utils.h"
#include "screen_file.h"
#include "screen_play.h"
@@ -95,37 +91,14 @@ play_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
mpd_finishCommand(c->connection);
screen_status_printf("Removed \'%s\' from playlist!",
mpc_get_song_name(song));
- break;
- case CMD_LIST_PREVIOUS:
- list_window_previous(screen->playlist);
- screen->playlist->repaint=1;
- break;
- case CMD_LIST_NEXT:
- list_window_next(screen->playlist, c->playlist_length);
- screen->playlist->repaint=1;
- break;
- case CMD_LIST_FIRST:
- list_window_first(screen->playlist);
- screen->playlist->repaint = 1;
- break;
- case CMD_LIST_LAST:
- list_window_last(screen->playlist, c->playlist_length);
- screen->playlist->repaint = 1;
- case CMD_LIST_NEXT_PAGE:
- list_window_next_page(screen->playlist, c->playlist_length);
- screen->playlist->repaint = 1;
- break;
- case CMD_LIST_PREVIOUS_PAGE:
- list_window_previous_page(screen->playlist);
- screen->playlist->repaint = 1;
- break;
+ return 1;
case CMD_LIST_FIND:
if( screen->findbuf )
{
free(screen->findbuf);
screen->findbuf=NULL;
}
- /* fall throw... */
+ /* continue... */
case CMD_LIST_FIND_NEXT:
if( !screen->findbuf )
screen->findbuf=screen_readln(screen->status_window.w, "/");
@@ -141,9 +114,9 @@ play_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
screen_status_printf("Unable to find \'%s\'", screen->findbuf);
beep();
}
- break;
+ return 1;
default:
- return 0;
+ break;
}
- return 1;
+ return list_window_cmd(screen->playlist, c->playlist_length, cmd) ;
}
diff --git a/screen_utils.c b/screen_utils.c
index 8de23e16c..49bd6692a 100644
--- a/screen_utils.c
+++ b/screen_utils.c
@@ -10,165 +10,6 @@
#include "command.h"
#include "screen.h"
-list_window_t *
-list_window_init(WINDOW *w, int width, int height)
-{
- list_window_t *lw;
-
- lw = malloc(sizeof(list_window_t));
- memset(lw, 0, sizeof(list_window_t));
- lw->w = w;
- lw->cols = width;
- lw->rows = height;
- lw->clear = 1;
- return lw;
-}
-
-list_window_t *
-list_window_free(list_window_t *lw)
-{
- if( lw )
- {
- memset(lw, 0, sizeof(list_window_t));
- free(lw);
- }
- return NULL;
-}
-
-void
-list_window_reset(list_window_t *lw)
-{
- lw->selected = 0;
- lw->start = 0;
- lw->clear = 1;
-}
-
-void
-list_window_set_selected(list_window_t *lw, int n)
-{
- lw->selected=n;
-}
-
-void
-list_window_paint(list_window_t *lw,
- list_window_callback_fn_t callback,
- void *callback_data)
-{
- int i;
-
- while( lw->selected < lw->start )
- {
- lw->start--;
- lw->clear=1;
- }
- while( lw->selected >= lw->start+lw->rows )
- {
- lw->start++;
- lw->clear=1;
- }
- if( lw->clear )
- {
- wclear(lw->w);
- lw->clear=0;
- }
-
- for(i=0; i<lw->rows; i++)
- {
- int highlight;
- char *label;
-
- label = (callback) (lw->start+i, &highlight, callback_data);
- if( label )
- {
- wmove(lw->w, i, 0);
- if( highlight )
- wattron(lw->w, A_BOLD);
- if( lw->start+i == lw->selected )
- wattron(lw->w, A_REVERSE);
-
- waddnstr(lw->w, label, lw->cols);
-
- if( highlight )
- wattroff(lw->w, A_BOLD);
- if( lw->start+i == lw->selected )
- wattroff(lw->w, A_REVERSE);
- }
- }
-}
-
-void
-list_window_next(list_window_t *lw, int length)
-{
- if( lw->selected < length-1 )
- lw->selected++;
-}
-
-void
-list_window_previous(list_window_t *lw)
-{
- if( lw->selected > 0 )
- lw->selected--;
-}
-
-void
-list_window_first(list_window_t *lw)
-{
- lw->selected = 0;
-}
-
-void
-list_window_last(list_window_t *lw, int length)
-{
- lw->selected = length-1;
-}
-
-void
-list_window_next_page(list_window_t *lw, int length)
-{
- int step = lw->rows-1;
- if( step<= 0 )
- return;
- if( lw->selected+step < length-1 )
- lw->selected+=step;
- else
- return list_window_last(lw,length);
-}
-
-void
-list_window_previous_page(list_window_t *lw)
-{
- int step = lw->rows-1;
- if( step<= 0 )
- return;
- if( lw->selected-step > 0 )
- lw->selected-=step;
- else
- list_window_first(lw);
-}
-
-int
-list_window_find(list_window_t *lw,
- list_window_callback_fn_t callback,
- void *callback_data,
- char *str)
-{
- int h;
- int i = lw->selected+1;
- char *label;
-
- while( (label=(callback) (i,&h,callback_data)) )
- {
- if( str && label && strcasestr(label, str) )
- {
- lw->selected = i;
- return 0;
- }
- i++;
- }
- return 1;
-}
-
-
char *
screen_readln(WINDOW *w, char *prompt)
{
diff --git a/screen_utils.h b/screen_utils.h
index cddbe7e74..70091f5c8 100644
--- a/screen_utils.h
+++ b/screen_utils.h
@@ -1,48 +1,2 @@
-typedef char * (*list_window_callback_fn_t) (int index,
- int *highlight,
- void *data);
-
-
-
-typedef struct
-{
- WINDOW *w;
- int rows, cols;
-
- int start;
- int selected;
- int clear;
- int repaint;
-
-} list_window_t;
-
-
-
-list_window_t *list_window_init(WINDOW *w, int width, int height);
-list_window_t *list_window_free(list_window_t *lw);
-
-
-void list_window_reset(list_window_t *lw);
-void list_window_set_selected(list_window_t *lw, int n);
-
-void list_window_paint(list_window_t *lw,
- list_window_callback_fn_t callback,
- void *callback_data);
-
-
-
-
-void list_window_previous(list_window_t *lw);
-void list_window_next(list_window_t *lw, int length);
-void list_window_first(list_window_t *lw);
-void list_window_last(list_window_t *lw, int length);
-void list_window_previous_page(list_window_t *lw);
-void list_window_next_page(list_window_t *lw, int length);
-int list_window_find(list_window_t *lw,
- list_window_callback_fn_t callback,
- void *callback_data,
- char *str);
-
-
char *screen_readln(WINDOW *w, char *prompt);