aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Obergrusberger <tradiaz@yahoo.de>2006-09-07 20:25:08 +0000
committerAndreas Obergrusberger <tradiaz@yahoo.de>2006-09-07 20:25:08 +0000
commit420a65325b977440effcfd820b5a5f3b9f9698b1 (patch)
tree78b59c19d5e0621671c9d64ebef30d8a78c84713
parent299c6bd912709f5e27fd6a8a0e1bad1bfb3e279a (diff)
downloadmpd-420a65325b977440effcfd820b5a5f3b9f9698b1.tar.gz
mpd-420a65325b977440effcfd820b5a5f3b9f9698b1.tar.xz
mpd-420a65325b977440effcfd820b5a5f3b9f9698b1.zip
due to bensonk's demand i added a splash screen.
git-svn-id: https://svn.musicpd.org/ncmpc/branches/tradiaz@4741 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--ChangeLog6
-rw-r--r--src/Makefile.am4
-rw-r--r--src/conf.c7
-rw-r--r--src/main.c13
-rw-r--r--src/mpdclient.c6
-rw-r--r--src/options.c5
-rw-r--r--src/options.h1
-rw-r--r--src/screen.c15
-rw-r--r--src/screen_utils.c52
-rw-r--r--src/screen_utils.h4
-rw-r--r--src/wreadln.c38
11 files changed, 130 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index b526d9c2e..aa4335090 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,10 @@
2006-08.8 Andreas Obergrusberger <tradiaz@yahoo.de>
+ * Here it is! the splash screen. asking you for password
+ everytime and featuring a nice animation :)
+ * ncmpc will now always ask for a password when it's not
+ permitted to execute a command
+
+2006-08.8 Andreas Obergrusberger <tradiaz@yahoo.de>
* Avuton fixed some warning
* fixed a bug that doubled empty lines
when loading lyrics from hd
diff --git a/src/Makefile.am b/src/Makefile.am
index 3d3fd6ed6..427c1f529 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -21,7 +21,8 @@ ncmpc_headers = \
strfsong.h\
utils.h\
ncmpc.h\
- screen_browse.h
+ screen_browse.h\
+ splash.h
# $Id$
@@ -51,6 +52,7 @@ ncmpc_SOURCES = \
wreadln.c\
strfsong.c\
utils.c\
+ splash.c\
$(ncmpc_headers)
ncmpc_LDADD = \
diff --git a/src/conf.c b/src/conf.c
index ac9b83c2e..3efdbbc69 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -68,6 +68,7 @@
#define CONF_HOST "host"
#define CONF_PORT "port"
#define CONF_LYRICS_TIMEOUT "lyrics-timeout"
+#define CONF_SHOW_SPLASH "show-splash"
typedef enum {
KEY_PARSER_UNKNOWN,
@@ -553,7 +554,11 @@ read_rc_file(char *filename, options_t *options)
{
g_strfreev(options->screen_list);
options->screen_list = check_screen_list(value);
-
+ }
+ else if( !strcasecmp(CONF_SHOW_SPLASH, name) )
+ {
+ options->show_splash = str2bool(value);
+
#ifdef DEBUG
D("screen-list:");
j=0;
diff --git a/src/main.c b/src/main.c
index c00b7ad68..35e343be7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -36,6 +36,7 @@
#include "screen.h"
#include "screen_utils.h"
#include "strfsong.h"
+#include "splash.h"
#define BUFSIZE 1024
@@ -259,9 +260,13 @@ main(int argc, const char *argv[])
/* install exit function */
atexit(exit_and_cleanup);
+
+ ncurses_init();
+ if(options->show_splash == TRUE) draw_splash();
/* connect to our music player daemon */
mpd = mpdclient_new();
+
if( mpdclient_connect(mpd,
options->host,
options->port,
@@ -274,8 +279,11 @@ main(int argc, const char *argv[])
/* if no password is used, but the mpd wants one, the connection
might be established but no status information is avaiable */
mpdclient_update(mpd);
- if(!mpd->status)
- exit(EXIT_FAILURE);
+ if(!mpd->status)
+ {
+ screen_auth(mpd);
+ }
+ if(!mpd->status) exit(EXIT_FAILURE);
connected = TRUE;
D("Connected to MPD version %d.%d.%d\n",
@@ -296,7 +304,6 @@ main(int argc, const char *argv[])
/* initialize curses */
screen_init(mpd);
-
/* install error callback function */
mpdclient_install_error_callback(mpd, error_callback);
diff --git a/src/mpdclient.c b/src/mpdclient.c
index ffa74a8a7..88330b2a9 100644
--- a/src/mpdclient.c
+++ b/src/mpdclient.c
@@ -91,10 +91,12 @@ mpdclient_finish_command(mpdclient_t *c)
{
gchar *msg = locale_to_utf8(c->connection->errorStr);
gint error = c->connection->error;
-
if( error == MPD_ERROR_ACK )
error = error | (c->connection->errorCode << 8);
-
+ if( c->connection->errorCode == MPD_ACK_ERROR_PERMISSION )
+ {
+ if(screen_auth(c) == 0) return 0;
+ }
error_cb(c, error, msg);
g_free(msg);
return error;
diff --git a/src/options.c b/src/options.c
index 89a62366b..a9a1f1f36 100644
--- a/src/options.c
+++ b/src/options.c
@@ -69,6 +69,7 @@ static arg_opt_t option_table[] = {
{ 'P', "password","PASSWORD", "Connect with password" },
{ 'f', "config", "FILE", "Read configuration from file" },
{ 'k', "key-file","FILE", "Read configuration from file" },
+ { 'S', "no-splash", NULL, "Don't show the splash screen" },
#ifdef DEBUG
{ 'K', "dump-keys", NULL, "Dump key bindings to stdout" },
{ 'D', "debug", NULL, "Enable debug output on stderr" },
@@ -215,6 +216,9 @@ handle_option(int c, char *arg)
g_free(options.key_file);
options.key_file = g_strdup(arg);
break;
+ case 'S': /* --key-file */
+ options.show_splash = FALSE;
+ break;
#ifdef DEBUG
case 'K': /* --dump-keys */
read_configuration(&options);
@@ -370,6 +374,7 @@ options_init( void )
options.screen_list = g_strsplit_set(DEFAULT_SCREEN_LIST, " ", 0);
options.timedisplay_type = DEFAULT_TIMEDISPLAY_TYPE;
options.lyrics_timeout = DEFAULT_LYRICS_TIMEOUT;
+ options.show_splash = TRUE;
return &options;
}
diff --git a/src/options.h b/src/options.h
index 1bfb350a3..d858b709e 100644
--- a/src/options.h
+++ b/src/options.h
@@ -32,6 +32,7 @@ typedef struct
gboolean visible_bell;
gboolean enable_xterm_title;
gboolean enable_mouse;
+ gboolean show_splash;
} options_t;
diff --git a/src/screen.c b/src/screen.c
index d30573917..7f21ec934 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -546,10 +546,9 @@ screen_status_printf(char *format, ...)
g_free(msg);
}
-int
-screen_init(mpdclient_t *c)
+void
+ncurses_init()
{
- gint i;
/* initialize the curses library */
initscr();
@@ -559,7 +558,7 @@ screen_init(mpdclient_t *c)
nonl();
/* use raw mode (ignore interrupt,quit,suspend, and flow control ) */
#ifdef ENABLE_RAW_MODE
- raw();
+ // raw();
#endif
/* don't echo input */
noecho();
@@ -580,12 +579,18 @@ screen_init(mpdclient_t *c)
fprintf(stderr, _("Error: Screen to small!\n"));
exit(EXIT_FAILURE);
}
-
screen = g_malloc(sizeof(screen_t));
memset(screen, 0, sizeof(screen_t));
screen->mode = 0;
screen->cols = COLS;
screen->rows = LINES;
+}
+
+int
+screen_init(mpdclient_t *c)
+{
+ gint i;
+
screen->buf = g_malloc(screen->cols);
screen->buf_size = screen->cols;
screen->findbuf = NULL;
diff --git a/src/screen_utils.c b/src/screen_utils.c
index 86b779245..417a74d67 100644
--- a/src/screen_utils.c
+++ b/src/screen_utils.c
@@ -53,7 +53,7 @@ screen_getch(WINDOW *w, char *prompt)
int key = -1;
int prompt_len = strlen(prompt);
- colors_use(w, COLOR_STATUS_ALERT);
+ // colors_use(w, COLOR_STATUS_ALERT);
wclear(w);
wmove(w, 0, 0);
waddstr(w, prompt);
@@ -102,6 +102,54 @@ screen_getstr(WINDOW *w, char *prompt)
return screen_readln(w, prompt, NULL, NULL, NULL);
}
+char *
+screen_getstr_masked(WINDOW *w, char *prompt)
+{
+ return screen_readln(w, prompt, NULL, NULL, NULL);
+}
+
+
+char *
+screen_read_password(WINDOW *w, char *prompt)
+{
+ if(w == NULL)
+ {
+ int rows, cols;
+ getmaxyx(stdscr, rows, cols);
+ /* create window for input */
+ w = newwin(1, cols, rows-1, 0);
+ leaveok(w, FALSE);
+ keypad(w, TRUE);
+ }
+ wmove(w, 0,0);
+ curs_set(1);
+ colors_use(w, COLOR_STATUS_ALERT);
+ if(prompt == NULL)
+ return wreadln_masked(w, _("Password: "), NULL, COLS, NULL, NULL);
+ else
+ return wreadln_masked(w, prompt, NULL, COLS, NULL, NULL);
+ curs_set(0);
+}
+
+gint
+_screen_auth(mpdclient_t *c, gint recursion)
+{
+ mpd_clearError(c->connection);
+ if(recursion > 2) return 1;
+ mpd_sendPasswordCommand(c->connection, screen_read_password(NULL, NULL));
+ mpd_finishCommand(c->connection);
+ mpdclient_update(c);
+ if( c->connection->errorCode == MPD_ACK_ERROR_PASSWORD ) return _screen_auth(c, ++recursion);
+ return 0;
+}
+
+gint
+screen_auth(mpdclient_t *c)
+{
+ _screen_auth(c, 0);
+ mpdclient_update(c);
+ curs_set(0);
+}
/* query user for a string and find it in a list window */
int
@@ -196,7 +244,7 @@ screen_display_completion_list(screen_t *screen, GList *list)
offset = 0;
}
- colors_use(w, COLOR_STATUS_ALERT);
+ colors_use(w, COLOR_STATUS_ALERT);
while( y<screen->main_window.rows )
{
GList *item = g_list_nth(list, y+offset);
diff --git a/src/screen_utils.h b/src/screen_utils.h
index d68867a46..27ff0eb8c 100644
--- a/src/screen_utils.h
+++ b/src/screen_utils.h
@@ -11,7 +11,8 @@ int screen_getch(WINDOW *w, char *prompt);
char *screen_getstr(WINDOW *w, char *prompt);
char *screen_readln(WINDOW *w, char *prompt, char *value,
GList **history, GCompletion *gcmp);
-
+char *screen_readln_masked(WINDOW *w, char *prompt);
+char *screen_read_pasword(WINDOW *w, char *prompt);
/* query user for a string and find it in a list window */
int screen_find(screen_t *screen,
mpdclient_t *c,
@@ -21,6 +22,7 @@ int screen_find(screen_t *screen,
list_window_callback_fn_t callback_fn,
void *callback_data);
+gint screen_auth(mpdclient_t *c);
void screen_display_completion_list(screen_t *screen, GList *list);
diff --git a/src/wreadln.c b/src/wreadln.c
index c3c5bfd06..380e87280 100644
--- a/src/wreadln.c
+++ b/src/wreadln.c
@@ -60,12 +60,13 @@ extern size_t my_strlen(char *str);
/* libcurses version */
gchar *
-wreadln(WINDOW *w,
+_wreadln(WINDOW *w,
gchar *prompt,
gchar *initial_value,
gint x1,
GList **history,
- GCompletion *gcmp)
+ GCompletion *gcmp,
+ gboolean masked)
{
GList *hlist = NULL, *hcurrent = NULL;
gchar *line;
@@ -103,7 +104,8 @@ wreadln(WINDOW *w,
/* clear input area */
whline(w, ' ', width);
/* print visible part of the line buffer */
- waddnstr(w, line+start, width);
+ if(masked == TRUE) whline(w, '*', my_strlen(line)-start);
+ else waddnstr(w, line+start, width);
/* move the cursor to the correct position */
wmove(w, y, x0 + cursor-start);
/* tell ncurses to redraw the screen */
@@ -365,12 +367,13 @@ wreadln(WINDOW *w,
/* libcursesw version */
gchar *
-wreadln(WINDOW *w,
+_wreadln(WINDOW *w,
gchar *prompt,
gchar *initial_value,
gint x1,
GList **history,
- GCompletion *gcmp)
+ GCompletion *gcmp,
+ gboolean masked)
{
GList *hlist = NULL, *hcurrent = NULL;
wchar_t *wline;
@@ -437,7 +440,8 @@ wreadln(WINDOW *w,
/* clear input area */
whline(w, ' ', width);
/* print visible part of the line buffer */
- waddnwstr(w, wline+start, width);
+ if(masked == TRUE) whline(w, '*', my_strlen(line)-start);
+ else waddnstr(w, line+start, width);
/* move the cursor to the correct position */
wmove(w, y, x0 + cursor-start);
/* tell ncurses to redraw the screen */
@@ -698,3 +702,25 @@ wreadln(WINDOW *w,
}
#endif
+
+gchar *
+wreadln(WINDOW *w,
+ gchar *prompt,
+ gchar *initial_value,
+ gint x1,
+ GList **history,
+ GCompletion *gcmp)
+ {
+ return _wreadln(w, prompt, initial_value, x1, history, gcmp, FALSE);
+ }
+
+gchar *
+wreadln_masked(WINDOW *w,
+ gchar *prompt,
+ gchar *initial_value,
+ gint x1,
+ GList **history,
+ GCompletion *gcmp)
+ {
+ return _wreadln(w, prompt, initial_value, x1, history, gcmp, TRUE);
+ }