summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4314bb9)
raw | patch | inline | side by side (parent: 4314bb9)
author | Kalle Wallin <kaw@linux.se> | |
Thu, 22 Apr 2004 20:34:52 +0000 (20:34 +0000) | ||
committer | Kalle Wallin <kaw@linux.se> | |
Thu, 22 Apr 2004 20:34:52 +0000 (20:34 +0000) |
mpc.c | patch | blob | history | |
screen_file.c | patch | blob | history | |
screen_file.h | patch | blob | history | |
screen_play.c | patch | blob | history | |
screen_play.h | patch | blob | history |
index 00a044462d3d0b0cd9568759373154c284c35252..0a80af4dd1280f7c9b867153e8784ed93df16c06 100644 (file)
--- a/mpc.c
+++ b/mpc.c
#define MAX_SONG_LENGTH 1024
-void
-mpc_update_song(mpd_client_t *c)
-{
- mpd_InfoEntity *entity;
-
- if( mpc_error(c) )
- return;
-
- if( c->song )
- {
- mpd_freeSong(c->song);
- c->song = NULL;
- }
-
- mpd_sendPlaylistInfoCommand(c->connection, c->status->song);
- if( mpc_error(c) )
- return;
- while( (entity=mpd_getNextInfoEntity(c->connection)) )
- {
- mpd_Song *song = entity->info.song;
-
- if(c->connection->error)
- {
- fprintf(stderr,"error: %s\n",c->connection->errorStr);
- exit(EXIT_FAILURE);
- }
- if(entity->type!=MPD_INFO_ENTITY_TYPE_SONG) {
- mpd_freeInfoEntity(entity);
- fprintf(stderr,
- "error: type != MPD_INFO_ENTITY_TYPE_SONG [%d]\n",
- entity->type);
- exit(EXIT_FAILURE);
- }
- c->song = mpd_songDup(song);
- mpd_freeInfoEntity(entity);
- }
-}
+#ifdef DEBUG
+#define D(x) x
+#else
+#define D(x)
+#endif
int
mpc_close(mpd_client_t *c)
c->playlist=NULL;
c->playlist_length=0;
+ c->song_id = -1;
+ c->song = NULL;
+
return 0;
}
{
mpd_InfoEntity *entity;
- // fprintf(stderr, "mpc_update_playlist(): status->playlist = %d\n", c->status->playlist);
+ D(fprintf(stderr, "mpc_update_playlist() [%d]\n", c->status->playlist));
if( mpc_error(c) )
return -1;
c->playlist_id = c->status->playlist;
c->playlist_updated = 1;
c->song_id = -1;
+ c->song = NULL;
+
+ mpc_filelist_set_selected(c);
return 0;
}
return (mpd_Song *) g_list_nth_data(c->playlist, n);
}
+
char *
mpc_get_song_name(mpd_Song *song)
{
if( c->playlist_id!=c->status->playlist )
mpc_update_playlist(c);
- if( c->status->song != c->song_id )
+ if( !c->song || c->status->song != c->song_id )
{
c->song = mpc_playlist_get_song(c, c->status->song);
c->song_id = c->status->song;
diff --git a/screen_file.c b/screen_file.c
index e57fc317f25d03478f9ff4f643c7d3e13440a1c0..d2b1f78449e10abd70ed3b54f0ca2a1ff261b210 100644 (file)
--- a/screen_file.c
+++ b/screen_file.c
#include "command.h"
#include "screen.h"
#include "screen_utils.h"
+#include "screen_play.h"
#include "screen_file.h"
#define BUFSIZE 1024
{
mpd_Song *song = entry->entity->info.song;
- mpd_sendAddCommand(c->connection, song->file);
- mpd_finishCommand(c->connection);
+ playlist_add_song(c, song);
screen_status_printf("Adding \'%s\' to playlist\n",
mpc_get_song_name(song));
}
else
{
+ /* remove song from playlist */
if( entry->entity->type==MPD_INFO_ENTITY_TYPE_SONG )
{
- int i;
mpd_Song *song = entry->entity->info.song;
-
- i = mpc_playlist_get_song_index(c, song->file);
- if( i>=0 )
- {
- mpd_sendDeleteCommand(c->connection, i);
- mpd_finishCommand(c->connection);
- screen_status_printf("Removed \'%s\' from playlist\n",
- mpc_get_song_name(song));
+ if( song )
+ {
+ int index = mpc_playlist_get_song_index(c, song->file);
+
+ while( (index=mpc_playlist_get_song_index(c, song->file))>=0 )
+ playlist_delete_song(c, index);
}
}
}
}
void
-file_clear_highlight(mpd_client_t *c, mpd_Song *song)
+file_set_highlight(mpd_client_t *c, mpd_Song *song, int highlight)
{
GList *list = g_list_first(c->filelist);
if( strcmp(song->file, song2->file) == 0 )
{
- entry->selected = 0;
+ entry->selected = highlight;
}
}
list = list->next;
diff --git a/screen_file.h b/screen_file.h
index 1a48fc7066f809caacbf80d4bfee481b742cf9ca..a7199a62e0c2fbeb53cc8e937fcba9f9fb44cd20 100644 (file)
--- a/screen_file.h
+++ b/screen_file.h
-void file_clear_highlight(mpd_client_t *c, mpd_Song *song);
+void file_set_highlight(mpd_client_t *c, mpd_Song *song, int hightlight);
void file_clear_highlights(mpd_client_t *c);
list_window_t *get_filelist_window(void);
diff --git a/screen_play.c b/screen_play.c
index eb1048951a5081f744bdae0d1427af99313238b5..cfdfa410af65aa525dfcbaababab74a007434835 100644 (file)
--- a/screen_play.c
+++ b/screen_play.c
#define BUFSIZE 256
+#define ENABLE_FANCY_PLAYLIST_MANAGMENT
+
static list_window_t *lw = NULL;
static char *
return 0;
}
-
static void
play_init(WINDOW *w, int cols, int rows)
{
play_paint(screen_t *screen, mpd_client_t *c)
{
lw->clear = 1;
-
+
list_window_paint(lw, list_callback, (void *) c);
wnoutrefresh(lw->w);
}
static int
play_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
{
- mpd_Song *song;
-
switch(cmd)
{
case CMD_DELETE:
- song = mpc_playlist_get_song(c, lw->selected);
- if( song )
- {
- file_clear_highlight(c, song);
- mpd_sendDeleteCommand(c->connection, lw->selected);
- mpd_finishCommand(c->connection);
- if( !mpc_error(c) )
- {
- screen_status_printf("Removed \'%s\' from playlist!",
- mpc_get_song_name(song));
-
- }
- }
+ playlist_delete_song(c, lw->selected);
return 1;
case CMD_SAVE_PLAYLIST:
handle_save_playlist(screen, c);
return lw->selected;
}
+int
+playlist_add_song(mpd_client_t *c, mpd_Song *song)
+{
+ if( !song || !song->file )
+ return -1;
+
+ /* send the add command to mpd */
+ mpd_sendAddCommand(c->connection, song->file);
+ mpd_finishCommand(c->connection);
+ if( mpc_error(c) )
+ return -1;
+
+#ifdef ENABLE_FANCY_PLAYLIST_MANAGMENT
+ /* add the song to playlist */
+ c->playlist = g_list_append(c->playlist, (gpointer) mpd_songDup(song));
+ c->playlist_length++;
+
+ /* 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;
+#endif
+
+ /* set selected highlight in the browse screen */
+ file_set_highlight(c, song, 1);
+
+ return 0;
+}
+
+int
+playlist_delete_song(mpd_client_t *c, int index)
+{
+ mpd_Song *song = mpc_playlist_get_song(c, index);
+
+ if( !song )
+ return -1;
+
+ /* send the delete command to mpd */
+ mpd_sendDeleteCommand(c->connection, index);
+ mpd_finishCommand(c->connection);
+ if( mpc_error(c) )
+ return -1;
+
+ /* print a status message */
+ screen_status_printf("Removed \'%s\' from playlist!",
+ mpc_get_song_name(song));
+ /* clear selected highlight in the browse screen */
+ file_set_highlight(c, song, 0);
+
+#ifdef ENABLE_FANCY_PLAYLIST_MANAGMENT
+ /* increment the playlist id, so we dont retrives a new playlist */
+ c->playlist_id++;
+
+ /* remove references to the song */
+ if( c->song == song )
+ {
+ c->song = NULL;
+ c->song_id = -1;
+ }
+
+ /* remove the song from the playlist */
+ c->playlist = g_list_remove(c->playlist, (gpointer) song);
+ c->playlist_length = g_list_length(c->playlist);
+ mpd_freeSong(song);
+
+ /* make shure the playlist is repainted */
+ lw->clear = 1;
+ lw->repaint = 1;
+ list_window_check_selected(lw, c->playlist_length);
+#endif
+
+ return 0;
+}
+
+
screen_functions_t *
get_screen_playlist(void)
{
diff --git a/screen_play.h b/screen_play.h
index f7c10185639b087399a9041560a0b994b8648267..535fc1887bca84c51237356cdfca746a69fdefb8 100644 (file)
--- a/screen_play.h
+++ b/screen_play.h
int play_get_selected(void);
+int playlist_add_song(mpd_client_t *c, mpd_Song *song);
+int playlist_delete_song(mpd_client_t *c, int index);
+
screen_functions_t *get_screen_playlist(void);