diff options
author | Kalle Wallin <kaw@linux.se> | 2004-03-23 19:17:20 +0000 |
---|---|---|
committer | Kalle Wallin <kaw@linux.se> | 2004-03-23 19:17:20 +0000 |
commit | c7444417a1ed04aee6144ca4754ed758dcb0c208 (patch) | |
tree | 2fe65f61cc4590bc6f5bc38e2bc3e95c7e609362 | |
parent | 2adb895c7853727adc57eae84229969203bf5731 (diff) | |
download | mpd-c7444417a1ed04aee6144ca4754ed758dcb0c208.tar.gz mpd-c7444417a1ed04aee6144ca4754ed758dcb0c208.tar.xz mpd-c7444417a1ed04aee6144ca4754ed758dcb0c208.zip |
Use screen_status_printf() instead of screen_status_message().
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@418 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r-- | TODO | 4 | ||||
-rw-r--r-- | main.c | 26 | ||||
-rw-r--r-- | options.c | 2 | ||||
-rw-r--r-- | options.h | 2 | ||||
-rw-r--r-- | screen.c | 57 | ||||
-rw-r--r-- | screen.h | 4 | ||||
-rw-r--r-- | screen_file.c | 25 | ||||
-rw-r--r-- | screen_play.c | 5 | ||||
-rw-r--r-- | screen_utils.c | 11 |
9 files changed, 59 insertions, 77 deletions
@@ -13,6 +13,8 @@ ncurses other ---------------------------------------------------------------------------- - * find/search function in playlist (like in less '/') + * find/search function in playlist (like in less '/') - done + * configuration file(s) - keybindings,colors... + * internationalization - gettext @@ -1,8 +1,3 @@ -/* - * $Id: main.c,v 1.5 2004/03/16 14:34:49 kalle Exp $ - * - */ - #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -17,10 +12,9 @@ #include "command.h" #include "screen.h" -#define BUFSIZE 256 - static mpd_client_t *mpc = NULL; + void exit_and_cleanup(void) { @@ -42,7 +36,7 @@ catch_sigint( int sig ) } int -main(int argc, char *argv[]) +main(int argc, const char *argv[]) { options_t *options; struct sigaction act; @@ -96,6 +90,7 @@ main(int argc, char *argv[]) if( mpc_error(mpc) ) exit(EXIT_FAILURE); + /* initialize curses */ screen_init(); counter=0; @@ -103,16 +98,14 @@ main(int argc, char *argv[]) while( connected || options->reconnect ) { command_t cmd; - char buf[BUFSIZE]; - + if( connected && counter==0 ) { mpc_update(mpc); if( mpc_error(mpc) ) { connected=0; - snprintf(buf, BUFSIZE, "Lost connection to %s", options->host); - screen_status_message(mpc, buf); + screen_status_printf("Lost connection to %s", options->host); mpd_closeConnection(mpc->connection); mpc->connection = NULL; } @@ -133,14 +126,11 @@ main(int argc, char *argv[]) else if( options->reconnect ) { sleep(3); - snprintf(buf, BUFSIZE, - "Connecting to %s... [Press Ctrl-C to abort]", - options->host); - screen_status_message(mpc, buf); + screen_status_printf("Connecting to %s... [Press Ctrl-C to abort]", + options->host); if( mpc_reconnect(mpc, options->host, options->port) == 0 ) { - snprintf(buf, BUFSIZE, "Connected to %s!", options->host); - screen_status_message(mpc, buf); + screen_status_printf("Connected to %s!", options->host); connected=1; counter=0; } @@ -40,7 +40,7 @@ usage(poptContext optCon, int exitcode, char *error, char *addl) } options_t * -options_parse( int argc, char **argv ) +options_parse( int argc, const char **argv) { int c; poptContext optCon; /* context for parsing command-line options */ @@ -13,6 +13,6 @@ typedef struct } options_t; void options_init(void); -options_t *options_parse(int argc, char **argv); +options_t *options_parse(int argc, const char **argv); options_t *get_options(void); @@ -176,11 +176,6 @@ paint_status_window(mpd_client_t *c) { x = screen->status_window.cols - strlen(screen->buf); - if( c->status->repeat ) - mvwaddstr(w, 0, x-3, "<R>"); - else - mvwaddstr(w, 0, x-3, " "); - snprintf(screen->buf, screen->buf_size, " [%i:%02i/%i:%02i] ", status->elapsedTime/60, status->elapsedTime%60, @@ -188,6 +183,18 @@ paint_status_window(mpd_client_t *c) mvwaddstr(w, 0, x, screen->buf); } +#if 1 + else if( c->status->state == MPD_STATUS_STATE_STOP ) + { + time_t timep; + x = screen->status_window.cols - strlen(screen->buf); + + time(&timep); + //strftime(screen->buf, screen->buf_size, "%X ", localtime(&timep)); + strftime(screen->buf, screen->buf_size, "%R ", localtime(&timep)); + mvwaddstr(w, 0, x, screen->buf); + } +#endif wrefresh(w); @@ -225,7 +232,7 @@ screen_resized(int sig) } void -screen_status_message(mpd_client_t *c, char *msg) +screen_status_message(char *msg) { WINDOW *w = screen->status_window.w; @@ -239,7 +246,7 @@ screen_status_message(mpd_client_t *c, char *msg) } void -screen_status_printf(mpd_client_t *c, char *format, ...) +screen_status_printf(char *format, ...) { char buffer[STATUS_LINE_MAX_SIZE]; va_list ap; @@ -247,7 +254,7 @@ screen_status_printf(mpd_client_t *c, char *format, ...) va_start(ap,format); vsnprintf(buffer,sizeof(buffer),format,ap); va_end(ap); - screen_status_message(c, buffer); + screen_status_message(buffer); } int @@ -398,7 +405,7 @@ void screen_cmd(mpd_client_t *c, command_t cmd) { int n; - char buf[256]; + // char buf[256]; screen_mode_t new_mode = screen->mode; switch(screen->mode) @@ -452,46 +459,42 @@ screen_cmd(mpd_client_t *c, command_t cmd) case CMD_SHUFFLE: mpd_sendShuffleCommand(c->connection); mpd_finishCommand(c->connection); - screen_status_message(c, "Shuffled playlist!"); + screen_status_message("Shuffled playlist!"); break; case CMD_CLEAR: mpd_sendClearCommand(c->connection); mpd_finishCommand(c->connection); file_clear_highlights(c); - screen_status_message(c, "Cleared playlist!"); + screen_status_message("Cleared playlist!"); break; case CMD_REPEAT: n = !c->status->repeat; mpd_sendRepeatCommand(c->connection, n); mpd_finishCommand(c->connection); - snprintf(buf, 256, "Repeat is %s", n ? "On" : "Off"); - screen_status_message(c, buf); + screen_status_printf("Repeat is %s", n ? "On" : "Off"); break; case CMD_RANDOM: n = !c->status->random; mpd_sendRandomCommand(c->connection, n); mpd_finishCommand(c->connection); - snprintf(buf, 256, "Random is %s", n ? "On" : "Off"); - screen_status_message(c, buf); + screen_status_printf("Random is %s", n ? "On" : "Off"); break; case CMD_VOLUME_UP: - // mpd_sendSetvolCommand(c->connection, X ); - mpd_sendVolumeCommand(c->connection, 1); - mpd_finishCommand(c->connection); - if( c->status->volume!=MPD_STATUS_NO_VOLUME ) + if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 ) { - snprintf(buf, 256, "Volume %d%%", c->status->volume+1); - screen_status_message(c, buf); + c->status->volume=c->status->volume+1; + mpd_sendSetvolCommand(c->connection, c->status->volume ); + mpd_finishCommand(c->connection); + screen_status_printf("Volume %d%%", c->status->volume); } break; case CMD_VOLUME_DOWN: - // mpd_sendSetvolCommand(c->connection, X ); - mpd_sendVolumeCommand(c->connection, -1); - mpd_finishCommand(c->connection); - if( c->status->volume!=MPD_STATUS_NO_VOLUME ) + if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 ) { - snprintf(buf, 256, "Volume %d%%", c->status->volume-1); - screen_status_message(c, buf); + c->status->volume=c->status->volume-1; + mpd_sendSetvolCommand(c->connection, c->status->volume ); + mpd_finishCommand(c->connection); + screen_status_printf("Volume %d%%", c->status->volume); } break; case CMD_SCREEN_PREVIOUS: @@ -64,8 +64,8 @@ typedef struct int screen_init(void); int screen_exit(void); void screen_resized(int sig); -void screen_status_message(mpd_client_t *c, char *msg); -void screen_status_printf(mpd_client_t *c, char *format, ...); +void screen_status_message(char *msg); +void screen_status_printf(char *format, ...); char *screen_error(void); void screen_paint(mpd_client_t *c); void screen_update(mpd_client_t *c); diff --git a/screen_file.c b/screen_file.c index c09682cc6..d503628cb 100644 --- a/screen_file.c +++ b/screen_file.c @@ -101,10 +101,12 @@ add_directory(mpd_client_t *c, char *dir) mpd_InfoEntity *entity; GList *subdir_list = NULL; GList *list = NULL; - char buf[80]; + char *dirname; - snprintf(buf, 80, "Adding directory %s...\n", dir); - screen_status_message(c, buf); + dirname = utf8_to_locale(dir); + screen_status_printf("Adding directory %s...\n", dirname); + free(dirname); + dirname = NULL; mpd_sendLsInfoCommand(c->connection, dir); mpd_sendCommandListBegin(c->connection); @@ -168,16 +170,13 @@ select_entry(screen_t *screen, mpd_client_t *c) { if( entry->entity->type==MPD_INFO_ENTITY_TYPE_SONG ) { - char buf[80]; mpd_Song *song = entry->entity->info.song; mpd_sendAddCommand(c->connection, song->file); mpd_finishCommand(c->connection); - snprintf(buf, 80, - "Adding \'%s\' to playlist\n", - mpc_get_song_name(song)); - screen_status_message(c, buf); + screen_status_printf("Adding \'%s\' to playlist\n", + mpc_get_song_name(song)); } } else @@ -185,7 +184,6 @@ select_entry(screen_t *screen, mpd_client_t *c) if( entry->entity->type==MPD_INFO_ENTITY_TYPE_SONG ) { int i; - char buf[80]; mpd_Song *song = entry->entity->info.song; i = mpc_playlist_get_song_index(c, song->file); @@ -193,10 +191,9 @@ select_entry(screen_t *screen, mpd_client_t *c) { mpd_sendDeleteCommand(c->connection, i); mpd_finishCommand(c->connection); - snprintf(buf, 80, - "Removed \'%s\' from playlist\n", - mpc_get_song_name(song)); - screen_status_message(c, buf); + screen_status_printf("Removed \'%s\' from playlist\n", + mpc_get_song_name(song)); + } } } @@ -352,7 +349,7 @@ file_cmd(screen_t *screen, mpd_client_t *c, command_t cmd) } else { - screen_status_printf(c, "Unable to find \'%s\'", screen->findbuf); + screen_status_printf("Unable to find \'%s\'", screen->findbuf); beep(); } break; diff --git a/screen_play.c b/screen_play.c index 5ba3839c8..9d1e9e80a 100644 --- a/screen_play.c +++ b/screen_play.c @@ -93,8 +93,7 @@ play_cmd(screen_t *screen, mpd_client_t *c, command_t cmd) file_clear_highlight(c, song); mpd_sendDeleteCommand(c->connection, screen->playlist->selected); mpd_finishCommand(c->connection); - screen_status_printf(c, - "Removed \'%s\' from playlist!", + screen_status_printf("Removed \'%s\' from playlist!", mpc_get_song_name(song)); break; case CMD_LIST_PREVIOUS: @@ -139,7 +138,7 @@ play_cmd(screen_t *screen, mpd_client_t *c, command_t cmd) } else { - screen_status_printf(c, "Unable to find \'%s\'", screen->findbuf); + screen_status_printf("Unable to find \'%s\'", screen->findbuf); beep(); } break; diff --git a/screen_utils.c b/screen_utils.c index d467c1a2c..8de23e16c 100644 --- a/screen_utils.c +++ b/screen_utils.c @@ -1,8 +1,3 @@ -/* - * $Id: screen_utils.c,v 1.4 2004/03/16 13:57:24 kalle Exp $ - * - */ - #include <stdlib.h> #include <unistd.h> #include <string.h> @@ -11,14 +6,10 @@ #include "libmpdclient.h" #include "mpc.h" +#include "support.h" #include "command.h" #include "screen.h" -#if 0 -#include <readline/readline.h> -#endif - - list_window_t * list_window_init(WINDOW *w, int width, int height) { |