summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 299c6bd)
raw | patch | inline | side by side (parent: 299c6bd)
author | Andreas Obergrusberger <tradiaz@yahoo.de> | |
Thu, 7 Sep 2006 20:25:08 +0000 (20:25 +0000) | ||
committer | Andreas Obergrusberger <tradiaz@yahoo.de> | |
Thu, 7 Sep 2006 20:25:08 +0000 (20:25 +0000) |
git-svn-id: https://svn.musicpd.org/ncmpc/branches/tradiaz@4741 09075e82-0dd4-0310-85a5-a0d7c8717e4f
ChangeLog | patch | blob | history | |
src/Makefile.am | patch | blob | history | |
src/conf.c | patch | blob | history | |
src/main.c | patch | blob | history | |
src/mpdclient.c | patch | blob | history | |
src/options.c | patch | blob | history | |
src/options.h | patch | blob | history | |
src/screen.c | patch | blob | history | |
src/screen_utils.c | patch | blob | history | |
src/screen_utils.h | patch | blob | history | |
src/wreadln.c | patch | blob | history |
diff --git a/ChangeLog b/ChangeLog
index b526d9c2ef603933621b1464ac9aac1235201f88..aa4335090e78fbc7fa02daad2471fcec42b4b7aa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
+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
diff --git a/src/Makefile.am b/src/Makefile.am
index 3d3fd6ed6bdd9a6191bb1dbce713547d0ea176eb..427c1f52936401b957f12dd128a27d6bd9f562d5 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
strfsong.h\
utils.h\
ncmpc.h\
- screen_browse.h
+ screen_browse.h\
+ splash.h
# $Id$
wreadln.c\
strfsong.c\
utils.c\
+ splash.c\
$(ncmpc_headers)
ncmpc_LDADD = \
diff --git a/src/conf.c b/src/conf.c
index ac9b83c2e43b745b9b1550db552b578b87a33074..3efdbbc6977c0e4b2c3c3b98c86c9d70a296524e 100644 (file)
--- a/src/conf.c
+++ b/src/conf.c
#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,
{
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 c00b7ad68b6d358bd4fba2e5cd1f5442e8446c99..35e343be73f230b7c509cc6864d497a9698c8d45 100644 (file)
--- a/src/main.c
+++ b/src/main.c
#include "screen.h"
#include "screen_utils.h"
#include "strfsong.h"
+#include "splash.h"
#define BUFSIZE 1024
/* 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,
/* 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",
/* 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 ffa74a8a7a18b37054520a08d7b7611a8abc3fe8..88330b2a9fc2e3a87d8904698e29420af8487fda 100644 (file)
--- a/src/mpdclient.c
+++ b/src/mpdclient.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 89a62366b0a5e16c38fbf4e8c67c468410381034..a9a1f1f36843a95126ead26223897036d1c91a32 100644 (file)
--- a/src/options.c
+++ b/src/options.c
{ '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" },
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);
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 1bfb350a3ae2446214412daa15b21fdbbdfe3b09..d858b709e0a4239a1ecccb8ccbd92f6576392108 100644 (file)
--- a/src/options.h
+++ b/src/options.h
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 d30573917f1951dbf19be4104759de7e3e1208c3..7f21ec934a39fc667f666e44269e28d82dbf0d05 100644 (file)
--- a/src/screen.c
+++ b/src/screen.c
g_free(msg);
}
-int
-screen_init(mpdclient_t *c)
+void
+ncurses_init()
{
- gint i;
/* initialize the curses library */
initscr();
nonl();
/* use raw mode (ignore interrupt,quit,suspend, and flow control ) */
#ifdef ENABLE_RAW_MODE
- raw();
+ // raw();
#endif
/* don't echo input */
noecho();
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 86b77924567087d27ad04440f85ffc9b6213396f..417a74d67a7e3cac8d021388a7d0d806e85e9c1b 100644 (file)
--- a/src/screen_utils.c
+++ b/src/screen_utils.c
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);
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
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 d68867a46987538963cfd47c8dbe2ab540c3dbdd..27ff0eb8ccbbf70d81aa639fcef3e2668584fff3 100644 (file)
--- a/src/screen_utils.h
+++ b/src/screen_utils.h
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,
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 c3c5bfd06a71fe758f7360b293ac5e1e6f1f4337..380e87280f6aecd49007bd9475cf15490a8ab8b8 100644 (file)
--- a/src/wreadln.c
+++ b/src/wreadln.c
/* 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;
/* 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 */
/* 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;
/* 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 */
}
#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);
+ }