summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a8baf3b)
raw | patch | inline | side by side (parent: a8baf3b)
author | Kalle Wallin <kaw@linux.se> | |
Tue, 15 Jun 2004 13:17:22 +0000 (13:17 +0000) | ||
committer | Kalle Wallin <kaw@linux.se> | |
Tue, 15 Jun 2004 13:17:22 +0000 (13:17 +0000) |
src/libmpdclient.h | patch | blob | history | |
src/main.c | patch | blob | history | |
src/mpdclient.h | patch | blob | history | |
src/screen.c | patch | blob | history | |
src/screen_file.c | patch | blob | history | |
src/screen_play.c | patch | blob | history |
diff --git a/src/libmpdclient.h b/src/libmpdclient.h
index 1b5f02dfe4c2533b4cf1e54cf0a1ab1db91f42f5..0cce020283332d9907bd148126dcda3bd7d52dbb 100644 (file)
--- a/src/libmpdclient.h
+++ b/src/libmpdclient.h
#define MPD_ACK_ERROR_PASSWORD 3
#define MPD_ACK_ERROR_PERMISSION 4
#define MPD_ACK_ERROR_UNKNOWN_CMD 5
-#define MPD_ACK_ERROR_NO_EXIST 6
-#define MPD_ACK_ERROR_PLAYLIST_MAX 7
-#define MPD_ACK_ERROR_SYSTEM 8
-#define MPD_ACK_ERROR_PLAYLIST_LOAD 9
-#define MPD_ACK_ERROR_UPDATE_ALREADY 10
-#define MPD_ACK_ERROR_PLAYER_SYNC 11
+
+#define MPD_ACK_ERROR_NO_EXIST 50
+#define MPD_ACK_ERROR_PLAYLIST_MAX 51
+#define MPD_ACK_ERROR_SYSTEM 52
+#define MPD_ACK_ERROR_PLAYLIST_LOAD 53
+#define MPD_ACK_ERROR_UPDATE_ALREADY 54
+#define MPD_ACK_ERROR_PLAYER_SYNC 55
+#define MPD_ACK_ERROR_EXIST 56
#ifdef __cplusplus
extern "C" {
int state;
/* crossfade setting in seconds */
int crossfade;
- /* if in PLAY or PAUSE state, this is the position of the currently
+ /* if a song is currently selected (always the case when state is
+ * PLAY or PAUSE), this is the position of the currently
* playing song in the playlist, beginning with 0
*/
int song;
+ /* Song ID of the currently selected song */
int songid;
/* time in seconds that have elapsed in the currently playing/paused
* song
/* mpd_getStatus
* returns status info, be sure to free it with mpd_freeStatus()
+ * call this after mpd_sendStatusCommand()
*/
mpd_Status * mpd_getStatus(mpd_Connection * connection);
char * name;
/* length of song in seconds, check that it is not MPD_SONG_NO_TIME */
int time;
- /* if plchanges or playlistinfo used, is the position of the song in
- * the playlist */
+ /* if plchanges/playlistinfo/playlistid used, is the position of the
+ * song in the playlist */
int pos;
+ /* song id for a song in the playlist */
int id;
} mpd_Song;
/* use this function to loop over after calling Info/Listall functions */
mpd_InfoEntity * mpd_getNextInfoEntity(mpd_Connection * connection);
+/* fetches the currently seeletect song (the song referenced by status->song
+ * and status->songid*/
void mpd_sendCurrentSongCommand(mpd_Connection * connection);
/* songNum of -1, means to display the whole list */
/* use this to get the changes in the playlist since version _playlist_ */
void mpd_sendPlChangesCommand(mpd_Connection * connection, long long playlist);
+/* recursivel fetches all songs/dir/playlists in "dir* (no metadata is
+ * returned) */
void mpd_sendListallCommand(mpd_Connection * connection, const char * dir);
+/* same as sendListallCommand, but also metadata is returned */
void mpd_sendListallInfoCommand(mpd_Connection * connection, const char * dir);
+/* non-recursive version of ListallInfo */
void mpd_sendLsInfoCommand(mpd_Connection * connection, const char * dir);
#define MPD_TABLE_ARTIST 0
void mpd_sendCommandListEnd(mpd_Connection * connection);
+/* advance to the next listOk
+ * returns 0 if advanced to the next list_OK,
+ * returns -1 if it advanced to an OK or ACK */
int mpd_nextListOkCommand(mpd_Connection * connection);
#ifdef __cplusplus
diff --git a/src/main.c b/src/main.c
index e996233a0f2e35d5366337ab11b5342948e3e6a4..81522f9d79a2eb577adae43915b43dad3567fb11 100644 (file)
--- a/src/main.c
+++ b/src/main.c
gint code = GET_ACK_ERROR_CODE(error);
error = error & 0xFF;
- D("Error [%d:%d]> \"%s\"\n", error, c->connection->errorCode, msg);
+ D("Error [%d:%d]> \"%s\"\n", error, code, msg);
switch(error)
{
case MPD_ERROR_CONNPORT:
break;
default:
screen_status_printf("%s", msg);
- doupdate();
beep();
+ doupdate();
connected = FALSE;
}
}
}
g_free(options.host);
g_free(options.password);
+ g_free(options.list_format);
+ g_free(options.status_format);
if( timer )
g_timer_destroy(timer);
}
mpd->connection->version[1],
mpd->connection->version[2]);
+ if( !MPD_VERSION(mpd, 0,11,0) )
+ {
+ fprintf(stderr, "MPD version %d.%d.%d is to old (0.11.0 needed).\n",
+ mpd->connection->version[0],
+ mpd->connection->version[1],
+ mpd->connection->version[2]);
+ exit(EXIT_FAILURE);
+ }
+
/* initialize curses */
screen_init(mpd);
diff --git a/src/mpdclient.h b/src/mpdclient.h
index 391a5d224576aa7b9f71975ba18f7fd7a2d99883..50b8e9a92fe014d997a196042b1f66110715dd54 100644 (file)
--- a/src/mpdclient.h
+++ b/src/mpdclient.h
#define MPDCLIENT_H
#include "libmpdclient.h"
+#define MPD_VERSION(c,x,y,z) (c->connection->version[0]*10000+c->connection->version[1]*100+c->connection->version[2] >= \
+ x*10000+y*100+z)
+
/****************************************************************************/
/* Playlist */
/****************************************************************************/
diff --git a/src/screen.c b/src/screen.c
index 76d04fa2241cbc48fdff03a543475fddf555ae74..8beab97f2117c199f63b33d3662e2a0000f6c42a 100644 (file)
--- a/src/screen.c
+++ b/src/screen.c
{
if( status->totalTime > 0 )
{
- if( seek_id == c->song->id )
+ if( c->song && seek_id == c->song->id )
elapsedTime = seek_target_time;
snprintf(screen->buf, screen->buf_size,
" [%i:%02i/%i:%02i]",
seek_target_time++;
if( seek_target_time < c->status->totalTime )
break;
- seek_target_time=0;
+ seek_target_time = c->status->totalTime;
+ /* seek_target_time=0; */
}
+ break;
/* fall through... */
case CMD_TRACK_NEXT:
if( !IS_STOPPED(c->status->state) )
diff --git a/src/screen_file.c b/src/screen_file.c
index f4a8c3dc0212043e3b80cd443c076dc618bb035b..f26333a2125ca979f7a8cc9ec8e8ff1be36edf7d 100644 (file)
--- a/src/screen_file.c
+++ b/src/screen_file.c
#include "config.h"
#include "ncmpc.h"
+#include "options.h"
#include "support.h"
#include "mpdclient.h"
#include "strfsong.h"
plf = entity->info.playlistFile;
str = utf8_to_locale(basename(plf->path));
- snprintf(buf, BUFSIZE, _("Delete playlist %s [y/n] ? "), str);
+ snprintf(buf, BUFSIZE, _("Delete playlist %s [%s/%s] ? "), str, YES, NO);
g_free(str);
key = tolower(screen_getch(screen->status_window.w, buf));
if( key==KEY_RESIZE )
screen_resize();
- if( key!='y' )
+ if( key != YES[0] )
{
screen_status_printf(_("Aborted!"));
return 0;
if( mpdclient_cmd_delete_playlist(c, plf->path) )
{
- beep();
return -1;
}
screen_status_printf(_("Playlist deleted!"));
diff --git a/src/screen_play.c b/src/screen_play.c
index 73c0bc679e46537f3db5bd6cb86c0594378c597b..9d3cef8bef41cf778a0e192bb69aa15e5241b727 100644 (file)
--- a/src/screen_play.c
+++ b/src/screen_play.c
*
*/
+#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
}
static int
-handle_save_playlist(screen_t *screen, mpdclient_t *c)
+handle_save_playlist(screen_t *screen, mpdclient_t *c, char *name)
{
- char *filename;
+ gchar *filename;
+ gint error;
- filename=screen_getstr(screen->status_window.w, _("Save playlist as: "));
- filename=trim(filename);
+ if( name==NULL )
+ {
+ /* query the user for a filename */
+ filename=screen_getstr(screen->status_window.w, _("Save playlist as: "));
+ filename=trim(filename);
+ }
+ else
+ {
+ filename=g_strdup(name);
+ }
if( filename==NULL || filename[0]=='\0' )
return -1;
/* send save command to mpd */
- if( mpdclient_cmd_save_playlist(c, filename) )
+ D("Saving playlist as \'%s \'...\n", filename);
+ if( (error=mpdclient_cmd_save_playlist(c, filename)) )
{
- beep();
+ gint code = GET_ACK_ERROR_CODE(error);
+
+ if( code == MPD_ACK_ERROR_EXIST )
+ {
+ char buf[256];
+ int key;
+
+ snprintf(buf, 256, _("Replace %s [%s/%s] ? "), filename, YES, NO);
+ key = tolower(screen_getch(screen->status_window.w, buf));
+ if( key == YES[0] )
+ {
+ char *filename_utf8 = locale_to_utf8(filename);
+
+ if( mpdclient_cmd_delete_playlist(c, filename_utf8) )
+ {
+ g_free(filename);
+ g_free(filename_utf8);
+ return -1;
+ }
+ g_free(filename_utf8);
+ error = handle_save_playlist(screen, c, filename);
+ g_free(filename);
+ return error;
+ }
+ }
+ g_free(filename);
return -1;
}
/* success */
{
case CMD_PLAY:
mpdclient_cmd_play(c, lw->selected);
- break;
+ return 1;
case CMD_DELETE:
mpdclient_cmd_delete(c, lw->selected);
return 1;
case CMD_SAVE_PLAYLIST:
- handle_save_playlist(screen, c);
+ handle_save_playlist(screen, c, NULL);
return 1;
case CMD_SCREEN_UPDATE:
center_playing_item(screen, c);
return 1;
case CMD_LIST_MOVE_UP:
mpdclient_cmd_move(c, lw->selected, lw->selected-1);
- break;
+ return 1;
case CMD_LIST_MOVE_DOWN:
mpdclient_cmd_move(c, lw->selected, lw->selected+1);
- break;
+ return 1;
case CMD_LIST_FIND:
case CMD_LIST_RFIND:
case CMD_LIST_FIND_NEXT: