summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b4983de)
raw | patch | inline | side by side (parent: b4983de)
author | Kalle Wallin <kaw@linux.se> | |
Fri, 7 May 2004 07:49:06 +0000 (07:49 +0000) | ||
committer | Kalle Wallin <kaw@linux.se> | |
Fri, 7 May 2004 07:49:06 +0000 (07:49 +0000) |
command.c | patch | blob | history | |
command.h | patch | blob | history | |
screen_help.c | patch | blob | history | |
screen_play.c | patch | blob | history | |
screen_play.h | patch | blob | history |
diff --git a/command.c b/command.c
index f900f3733b5b0c8386c1c460e07dade6d1c26f02..1e9edcd0d5096e65088968c10beed11b105a6081 100644 (file)
--- a/command.c
+++ b/command.c
#define F5 KEY_F(5)
#define F6 KEY_F(6)
+
static command_definition_t cmds[] =
{
{ { 13, 0, 0 }, CMD_PLAY, "play",
{ { 'S', 0, 0 }, CMD_SAVE_PLAYLIST, "save",
"Save playlist" },
+ { { 0, 0, 0 }, CMD_LIST_MOVE_UP, "move-up",
+ "Move item up" },
+ { { 0, 0, 0 }, CMD_LIST_MOVE_DOWN, "move-down",
+ "Move item down" },
+
{ { UP, ',', 0 }, CMD_LIST_PREVIOUS, "up",
"Move cursor up" },
{ { DWN, '.', 0 }, CMD_LIST_NEXT, "down",
char *
key2str(int key)
{
- static char buf[4];
+ static char buf[32];
int i;
buf[0] = 0;
for(i=0; i<=63; i++)
if( key==KEY_F(i) )
{
- snprintf(buf, 4, "F%d", i );
+ snprintf(buf, 32, "F%d", i );
return buf;
}
- snprintf(buf, 4, "%c", key);
+ if( !(key & ~037) )
+ snprintf(buf, 32, "Ctrl-%c", 'A'+(key & 037)-1 );
+ else if( (key & ~037) == 224 )
+ snprintf(buf, 32, "Alt-%c", 'A'+(key & 037)-1 );
+ else if( key>32 && key<256 )
+ snprintf(buf, 32, "%c", key);
+ else
+ snprintf(buf, 32, "0x%03X", key);
}
return buf;
}
diff --git a/command.h b/command.h
index 7b6bf3098eb666cc28ecebf8176adf7c86358d84..1ce67e894c0c615b19e8c8adedb39c6b1027f013 100644 (file)
--- a/command.h
+++ b/command.h
CMD_LIST_FIND_NEXT,
CMD_LIST_RFIND,
CMD_LIST_RFIND_NEXT,
+ CMD_LIST_MOVE_UP,
+ CMD_LIST_MOVE_DOWN,
CMD_SCREEN_UPDATE,
CMD_SCREEN_PREVIOUS,
CMD_SCREEN_NEXT,
diff --git a/screen_help.c b/screen_help.c
index 37bf9a385965dc077e20c7b201584807ad013e40..c55c963802c4a31cfb33f12857473cb3801bb843 100644 (file)
--- a/screen_help.c
+++ b/screen_help.c
{ 0, CMD_PLAY, "Play" },
{ 0, CMD_DELETE, NULL },
{ 0, CMD_CLEAR, NULL },
+ { 0, CMD_LIST_MOVE_UP, "Move song up" },
+ { 0, CMD_LIST_MOVE_DOWN, "Move song down" },
{ 0, CMD_SAVE_PLAYLIST, NULL },
{ 0, CMD_SCREEN_UPDATE, "Center" },
{ 0, CMD_TOGGLE_AUTOCENTER, NULL },
diff --git a/screen_play.c b/screen_play.c
index db42f58d816ecbcdc4e764d8d512bc9a0f737403..cdec4f77e4de2e98b91db8ce82519841a243cd53 100644 (file)
--- a/screen_play.c
+++ b/screen_play.c
#include "screen_file.h"
#include "screen_play.h"
+#ifdef DEBUG
+#define D(x) x
+#else
+#define D(x)
+#endif
+
#define BUFSIZE 256
static list_window_t *lw = NULL;
case CMD_SCREEN_UPDATE:
center_playing_item(screen, c);
return 1;
+ case CMD_LIST_MOVE_UP:
+ playlist_move_song(c, lw->selected, lw->selected-1);
+ break;
+ case CMD_LIST_MOVE_DOWN:
+ playlist_move_song(c, lw->selected, lw->selected+1);
+ break;
case CMD_LIST_FIND:
case CMD_LIST_RFIND:
case CMD_LIST_FIND_NEXT:
return lw->selected;
}
+int
+playlist_move_song(mpd_client_t *c, int old_index, int new_index)
+{
+ int index1, index2;
+ GList *item1, *item2;
+ gpointer data1, data2;
+
+ if( old_index==new_index || new_index<0 || new_index>=c->playlist_length )
+ return -1;
+
+ /* send the move command to mpd */
+ mpd_sendMoveCommand(c->connection, old_index, new_index);
+ mpd_finishCommand(c->connection);
+ if( mpc_error(c) )
+ return -1;
+
+ index1 = MIN(old_index, new_index);
+ index2 = MAX(old_index, new_index);
+ item1 = g_list_nth(c->playlist, index1);
+ item2 = g_list_nth(c->playlist, index2);
+ data1 = item1->data;
+ data2 = item2->data;
+
+ /* move the second item */
+ D(fprintf(stderr, "move second item [%d->%d]...\n", index2, index1));
+ c->playlist = g_list_remove(c->playlist, data2);
+ c->playlist = g_list_insert_before(c->playlist, item1, data2);
+
+ /* move the first item */
+ if( index2-index1 >1 )
+ {
+ D(fprintf(stderr, "move first item [%d->%d]...\n", index1, index2));
+ item2 = g_list_nth(c->playlist, index2);
+ c->playlist = g_list_remove(c->playlist, data1);
+ c->playlist = g_list_insert_before(c->playlist, item2, data1);
+ }
+
+ /* increment the playlist id, so we dont retrives a new playlist */
+ c->playlist_id++;
+
+ /* make shure the playlist is repainted */
+ lw->clear = 1;
+ lw->repaint = 1;
+
+ /* keep song selected */
+ lw->selected = new_index;
+
+ return 0;
+}
+
int
playlist_add_song(mpd_client_t *c, mpd_Song *song)
{
if( mpc_error(c) )
return -1;
-#ifndef DISABLE_FANCY_PLAYLIST_MANAGMENT
/* add the song to playlist */
c->playlist = g_list_append(c->playlist, (gpointer) mpd_songDup(song));
c->playlist_length++;
/* make shure the playlist is repainted */
lw->clear = 1;
lw->repaint = 1;
-#endif
/* set selected highlight in the browse screen */
file_set_highlight(c, song, 1);
/* clear selected highlight in the browse screen */
file_set_highlight(c, song, 0);
-#ifndef DISABLE_FANCY_PLAYLIST_MANAGMENT
/* increment the playlist id, so we dont retrives a new playlist */
c->playlist_id++;
lw->clear = 1;
lw->repaint = 1;
list_window_check_selected(lw, c->playlist_length);
-#endif
return 0;
}
diff --git a/screen_play.h b/screen_play.h
index 535fc1887bca84c51237356cdfca746a69fdefb8..2155ae593e5c6a0f5110ccbfb983c9d4b636f6bd 100644 (file)
--- a/screen_play.h
+++ b/screen_play.h
int play_get_selected(void);
+int playlist_move_song(mpd_client_t *c, int old_index, int new_index);
int playlist_add_song(mpd_client_t *c, mpd_Song *song);
int playlist_delete_song(mpd_client_t *c, int index);