summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ecaa213)
raw | patch | inline | side by side (parent: ecaa213)
author | Kalle Wallin <kaw@linux.se> | |
Wed, 24 Mar 2004 15:17:52 +0000 (15:17 +0000) | ||
committer | Kalle Wallin <kaw@linux.se> | |
Wed, 24 Mar 2004 15:17:52 +0000 (15:17 +0000) |
Added function list_window_cmd() for basic commands (movment).
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@454 09075e82-0dd4-0310-85a5-a0d7c8717e4f
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@454 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Makefile.am | patch | blob | history | |
list_window.c | [new file with mode: 0644] | patch | blob |
list_window.h | [new file with mode: 0644] | patch | blob |
main.c | patch | blob | history | |
screen.h | patch | blob | history | |
screen_file.c | patch | blob | history | |
screen_help.c | patch | blob | history | |
screen_play.c | patch | blob | history | |
screen_utils.c | patch | blob | history | |
screen_utils.h | patch | blob | history |
diff --git a/Makefile.am b/Makefile.am
index 9731afbec33046f948f601ac2f1dd0d40d9c8f29..96e6b1dd05dc72bd28cb9daf94884b1658f644d2 100644 (file)
--- a/Makefile.am
+++ b/Makefile.am
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
--- /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
--- /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
index 4e420b75d4cc4c1be2ada8f86193092be908461e..c2c29b3aca577e651b5f04b53a97805b6555f4bd 100644 (file)
--- a/main.c
+++ b/main.c
{
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 42b8d9133281c884da5c0c26ea195c21b7d58cef..7b667d8238497f99097320cb41936ceba814bb6f 100644 (file)
--- a/screen.h
+++ b/screen.h
#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 ba0dbd3e1c948b280d70cbe2bd9b000085b05a1d..809ae3faf81f16f67319d0a6f243c66052180d26 100644 (file)
--- a/screen_file.c
+++ b/screen_file.c
-/*
- * $Id: screen_file.c,v 1.9 2004/03/18 09:33:07 kalle Exp $
- *
- */
-
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "mpc.h"
#include "command.h"
#include "screen.h"
+#include "screen_utils.h"
#include "screen_file.h"
#define BUFSIZE 1024
{
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 )
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 3d01363b91a1d552cf54e919c6e4eb67c1a03a2e..5320647be47712913f75dedb72aba36ceab974cd 100644 (file)
--- a/screen_help.c
+++ b/screen_help.c
-/*
- * $Id: screen_help.c,v 1.8 2004/03/17 13:40:25 kalle Exp $
- *
- */
-
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "mpc.h"
#include "command.h"
#include "screen.h"
+#include "screen_utils.h"
#include "screen_help.h"
typedef struct
{
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 )
{
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 9d1e9e80a42a4f2e9942cf41a3f5a303fb0360a3..48dc86961130fd940a3f0dab24869a6bb28d501f 100644 (file)
--- a/screen_play.c
+++ b/screen_play.c
-/*
- * $Id: screen_play.c,v 1.6 2004/03/17 14:49:31 kalle Exp $
- *
- */
-
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "mpc.h"
#include "command.h"
#include "screen.h"
+#include "screen_utils.h"
#include "screen_file.h"
#include "screen_play.h"
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, "/");
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 8de23e16c6492d148d6d32b8b6dd7a9e51ec69a7..49bd6692a2682c3e14bd53940203af0c99cc3f93 100644 (file)
--- a/screen_utils.c
+++ b/screen_utils.c
#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 cddbe7e74f38d1595e23846ef2bbc5cc9fe4e601..70091f5c86a675b6ade53b7b071752cd86b28849 100644 (file)
--- a/screen_utils.h
+++ b/screen_utils.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;
-
-
-
-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);