summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2adb895)
raw | patch | inline | side by side (parent: 2adb895)
author | Kalle Wallin <kaw@linux.se> | |
Tue, 23 Mar 2004 19:17:20 +0000 (19:17 +0000) | ||
committer | Kalle Wallin <kaw@linux.se> | |
Tue, 23 Mar 2004 19:17:20 +0000 (19:17 +0000) |
TODO | patch | blob | history | |
main.c | patch | blob | history | |
options.c | patch | blob | history | |
options.h | patch | blob | history | |
screen.c | patch | blob | history | |
screen.h | patch | blob | history | |
screen_file.c | patch | blob | history | |
screen_play.c | patch | blob | history | |
screen_utils.c | patch | blob | history |
index c76a4e54507964200078de43275437765a6c860d..d2a38c62da5ce276763e35bfbfc663fac945ee65 100644 (file)
--- a/TODO
+++ b/TODO
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
index 0a44051121436f42fab977011103f538cdb19730..7bd80c5dd24d699aa027180cb67a06ee4babdaad 100644 (file)
--- a/main.c
+++ b/main.c
-/*
- * $Id: main.c,v 1.5 2004/03/16 14:34:49 kalle Exp $
- *
- */
-
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "command.h"
#include "screen.h"
-#define BUFSIZE 256
-
static mpd_client_t *mpc = NULL;
+
void
exit_and_cleanup(void)
{
}
int
-main(int argc, char *argv[])
+main(int argc, const char *argv[])
{
options_t *options;
struct sigaction act;
if( mpc_error(mpc) )
exit(EXIT_FAILURE);
+ /* initialize curses */
screen_init();
counter=0;
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;
}
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;
}
diff --git a/options.c b/options.c
index 03fe3eea90eec3db7b33a7927dc1450724da0367..9685ce3b22cc5b4323daef204043ec1d352025b5 100644 (file)
--- a/options.c
+++ b/options.c
}
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 */
diff --git a/options.h b/options.h
index 143be3b2df484b29bb4c33dcffa442ce6117cbe3..49af19984540c5169d62d4ead9d73fdb346563e5 100644 (file)
--- a/options.h
+++ b/options.h
} 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);
diff --git a/screen.c b/screen.c
index 696c35f7f6811bebd0fe866244bc217b5a4f0326..3012fa31ae668494f3126b78bffd67c271f9a119 100644 (file)
--- a/screen.c
+++ b/screen.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,
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);
}
void
-screen_status_message(mpd_client_t *c, char *msg)
+screen_status_message(char *msg)
{
WINDOW *w = screen->status_window.w;
}
void
-screen_status_printf(mpd_client_t *c, char *format, ...)
+screen_status_printf(char *format, ...)
{
char buffer[STATUS_LINE_MAX_SIZE];
va_list ap;
va_start(ap,format);
vsnprintf(buffer,sizeof(buffer),format,ap);
va_end(ap);
- screen_status_message(c, buffer);
+ screen_status_message(buffer);
}
int
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)
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:
diff --git a/screen.h b/screen.h
index 4681319c391d646c39e14aff07b4a832fd0337d5..70d3e121836b500eb8362e4ea40c91798acbb58e 100644 (file)
--- a/screen.h
+++ b/screen.h
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 c09682cc629e90122dd8cac18aff35d6183c3159..d503628cbe62dc0fae02413eaef17270e1fc29b3 100644 (file)
--- a/screen_file.c
+++ b/screen_file.c
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);
{
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
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);
{
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));
+
}
}
}
}
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 5ba3839c8c3862e5178816dd0ca58270a229e1c4..9d1e9e80a42a4f2e9942cf41a3f5a303fb0360a3 100644 (file)
--- a/screen_play.c
+++ b/screen_play.c
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:
}
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 d467c1a2c5a47d4ca62b8f2264454e8faf9e3f3e..8de23e16c6492d148d6d32b8b6dd7a9e51ec69a7 100644 (file)
--- a/screen_utils.c
+++ b/screen_utils.c
-/*
- * $Id: screen_utils.c,v 1.4 2004/03/16 13:57:24 kalle Exp $
- *
- */
-
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#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)
{