summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1304e41)
raw | patch | inline | side by side (parent: 1304e41)
author | Kalle Wallin <kaw@linux.se> | |
Tue, 14 Jun 2005 22:04:50 +0000 (22:04 +0000) | ||
committer | Kalle Wallin <kaw@linux.se> | |
Tue, 14 Jun 2005 22:04:50 +0000 (22:04 +0000) |
src/mpdclient.c | patch | blob | history | |
src/mpdclient.h | patch | blob | history | |
src/screen_artist.c | patch | blob | history | |
src/screen_search.c | patch | blob | history |
diff --git a/src/mpdclient.c b/src/mpdclient.c
index 03c69f30ec2fc2c3e0c70f760d41e137bb3ed571..1cb06bc75eb5bb86db80b485c180dc4b419c8c65 100644 (file)
--- a/src/mpdclient.c
+++ b/src/mpdclient.c
}
mpdclient_filelist_t *
-mpdclient_filelist_search_utf8(mpdclient_t *c, int table, gchar *filter_utf8)
+mpdclient_filelist_search_utf8(mpdclient_t *c,
+ int exact_match,
+ int table,
+ gchar *filter_utf8)
{
mpdclient_filelist_t *filelist;
mpd_InfoEntity *entity;
D("mpdclient_filelist_search(%s)\n", filter_utf8);
- mpd_sendSearchCommand(c->connection, table, filter_utf8);
+ if( exact_match )
+ mpd_sendFindCommand(c->connection, table, filter_utf8);
+ else
+ mpd_sendSearchCommand(c->connection, table, filter_utf8);
filelist = g_malloc0(sizeof(mpdclient_filelist_t));
while( (entity=mpd_getNextInfoEntity(c->connection)) )
mpdclient_filelist_t *
-mpdclient_filelist_search(mpdclient_t *c, int table, gchar *filter)
+mpdclient_filelist_search(mpdclient_t *c,
+ int exact_match,
+ int table,
+ gchar *filter)
{
mpdclient_filelist_t *filelist;
gchar *filter_utf8 = locale_to_utf8(filter);
D("mpdclient_filelist_search(%s)\n", filter);
- filelist = mpdclient_filelist_search_utf8(c, table, filter_utf8);
+ filelist = mpdclient_filelist_search_utf8(c,exact_match,table,filter_utf8);
g_free(filter_utf8);
return filelist;
return NULL;
}
+int
+mpdclient_filelist_add_all(mpdclient_t *c, mpdclient_filelist_t *fl)
+{
+ GList *list = g_list_first(fl->list);
+
+ if( fl->list==NULL || fl->length<1 )
+ return 0;
+
+ mpd_sendCommandListBegin(c->connection);
+ while( list )
+ {
+ filelist_entry_t *entry = list->data;
+ mpd_InfoEntity *entity = entry->entity;
+
+ if( entity && entity->type==MPD_INFO_ENTITY_TYPE_SONG )
+ {
+ mpd_Song *song = entity->info.song;
+
+ mpd_sendAddCommand(c->connection, song->file);
+ }
+ list = list->next;
+ }
+ mpd_sendCommandListEnd(c->connection);
+ return mpdclient_finish_command(c);
+}
+
+
+
+
+
+
+
GList *
mpdclient_get_artists_utf8(mpdclient_t *c)
diff --git a/src/mpdclient.h b/src/mpdclient.h
index a14811b5a9f13096c888e855276e7cce0b9414b2..3837b1e7b7659e15846f43fcfb4248e28b4c377c 100644 (file)
--- a/src/mpdclient.h
+++ b/src/mpdclient.h
mpdclient_filelist_t *mpdclient_filelist_free(mpdclient_filelist_t *filelist);
mpdclient_filelist_t *mpdclient_filelist_get(mpdclient_t *c, gchar *path);
mpdclient_filelist_t *mpdclient_filelist_search(mpdclient_t *c,
+ int exact_match,
int table,
gchar *path);
mpdclient_filelist_t *mpdclient_filelist_search_utf8(mpdclient_t *c,
+ int exact_match,
int table,
gchar *path);
mpdclient_filelist_t *mpdclient_filelist_update(mpdclient_t *c,
filelist_entry_t *mpdclient_filelist_find_song(mpdclient_filelist_t *flist,
mpd_Song *song);
+/* add all songs in filelist to the playlist */
+int mpdclient_filelist_add_all(mpdclient_t *c, mpdclient_filelist_t *fl);
+
/*** mpdclient browse callbacks ********************************************/
#define BROWSE_DB_UPDATED 0x01
diff --git a/src/screen_artist.c b/src/screen_artist.c
index a363304f52d5a4f5caa9c651b615597b8019219a..8909638b05e866a7fae8896ee2887bbdf57dedbf 100644 (file)
--- a/src/screen_artist.c
+++ b/src/screen_artist.c
#define BUFSIZE 1024
+typedef enum { LIST_ARTISTS, LIST_ALBUMS, LIST_SONGS } artist_mode_t;
+
+static artist_mode_t mode = LIST_ARTISTS;
static char *artist = NULL;
static char *album = NULL;
static list_window_t *lw = NULL;
{
album = g_strdup(_("All tracks"));
filelist = mpdclient_filelist_search_utf8(c,
+ TRUE,
MPD_TABLE_ARTIST,
artist);
}
else
filelist = mpdclient_filelist_search_utf8(c,
+ TRUE,
MPD_TABLE_ALBUM,
album);
/* add a dummy entry for ".." */
/* install playlist callback and fix highlights */
sync_highlights(c, filelist);
mpdclient_install_playlist_callback(c, playlist_changed_callback);
+ mode = LIST_SONGS;
}
else if( m_artist ) /* retreive albums... */
{
metalist = g_list_insert(metalist, g_strdup(".."), 0);
/* add a dummy entry for all songs */
metalist = g_list_insert(metalist, g_strdup(_("All tracks")), -1);
-
+ mode = LIST_ALBUMS;
}
else /* retreive artists... */
{
metalist = mpdclient_get_artists_utf8(c);
+ mode = LIST_ARTISTS;
}
metalist_length = g_list_length(metalist);
lw->clear = TRUE;
char *s1 = artist ? utf8_to_locale(artist) : NULL;
char *s2 = album ? utf8_to_locale(album) : NULL;
- if( album )
- g_snprintf(str, size, _("Artist: %s - %s"), s1, s2);
- else if( artist )
- g_snprintf(str, size, _("Artist: %s"), s1);
- else
- g_snprintf(str, size, _("Artist: [db browser - EXPERIMENTAL]"));
+ switch(mode)
+ {
+ case LIST_ARTISTS:
+ g_snprintf(str, size, _("Artist: [db browser - EXPERIMENTAL]"));
+ break;
+ case LIST_ALBUMS:
+ g_snprintf(str, size, _("Artist: %s"), s1);
+ break;
+ case LIST_SONGS:
+ g_snprintf(str, size, _("Artist: %s - %s"), s1, s2);
+ break;
+ }
g_free(s1);
g_free(s2);
return str;
return lw;
}
+static void
+add_query(mpdclient_t *c, int table, char *filter)
+{
+ char *str;
+ mpdclient_filelist_t *addlist;
+
+ str = utf8_to_locale(filter);
+ if( table== MPD_TABLE_ALBUM )
+ screen_status_printf("Adding album %s...", str);
+ else
+ screen_status_printf("Adding %s...", str);
+ g_free(str);
+ addlist = mpdclient_filelist_search_utf8(c, TRUE, table, filter);
+ if( addlist )
+ {
+ mpdclient_filelist_add_all(c, addlist);
+ addlist = mpdclient_filelist_free(addlist);
+ }
+}
+
static int
artist_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
{
+ char *selected;
+
switch(cmd)
{
case CMD_PLAY:
- if( artist && album )
- {
- if( lw->selected==0 ) /* handle ".." */
- {
- update_metalist(c, g_strdup(artist), NULL);
- list_window_reset(lw);
- /* restore previous list window state */
- list_window_pop_state(lw_state,lw);
- }
- else
- browse_handle_enter(screen, c, lw, filelist);
- }
- else if ( artist )
+ switch(mode)
{
+ case LIST_ARTISTS:
+ selected = (char *) g_list_nth_data(metalist, lw->selected);
+ update_metalist(c, g_strdup(selected), NULL);
+ list_window_push_state(lw_state,lw);
+ break;
+ case LIST_ALBUMS:
if( lw->selected == 0 ) /* handle ".." */
-
{
update_metalist(c, NULL, NULL);
list_window_reset(lw);
}
else /* select album */
{
- char *selected = (char *) g_list_nth_data(metalist, lw->selected);
+ selected = (char *) g_list_nth_data(metalist, lw->selected);
update_metalist(c, g_strdup(artist), g_strdup(selected));
list_window_push_state(lw_state,lw);
}
- }
- else
- {
- char *selected = (char *) g_list_nth_data(metalist, lw->selected);
- update_metalist(c, g_strdup(selected), NULL);
- list_window_push_state(lw_state,lw);
+ break;
+ case LIST_SONGS:
+ if( lw->selected==0 ) /* handle ".." */
+ {
+ update_metalist(c, g_strdup(artist), NULL);
+ list_window_reset(lw);
+ /* restore previous list window state */
+ list_window_pop_state(lw_state,lw);
+ }
+ else
+ browse_handle_enter(screen, c, lw, filelist);
+ break;
}
return 1;
case CMD_SELECT:
- if( browse_handle_select(screen, c, lw, filelist) == 0 )
+ switch(mode)
{
- /* continue and select next item... */
- cmd = CMD_LIST_NEXT;
+ case LIST_ARTISTS:
+ selected = (char *) g_list_nth_data(metalist, lw->selected);
+ add_query(c, MPD_TABLE_ARTIST, selected);
+ cmd = CMD_LIST_NEXT; /* continue and select next item... */
+ break;
+ case LIST_ALBUMS:
+ if( lw->selected && lw->selected == metalist_length-1)
+ {
+ add_query(c, MPD_TABLE_ARTIST, artist);
+ }
+ else if( lw->selected > 0 )
+ {
+ selected = (char *) g_list_nth_data(metalist, lw->selected);
+ add_query(c, MPD_TABLE_ALBUM, selected);
+ cmd = CMD_LIST_NEXT; /* continue and select next item... */
+ }
+ break;
+ case LIST_SONGS:
+ if( browse_handle_select(screen, c, lw, filelist) == 0 )
+ {
+ cmd = CMD_LIST_NEXT; /* continue and select next item... */
+ }
+ break;
}
- return 1;
+ break;
/* continue and update... */
case CMD_SCREEN_UPDATE:
return browse_handle_mouse_event(screen,c,lw,filelist);
default:
- if( filelist )
- return list_window_cmd(lw, filelist->length, cmd);
- else if( metalist )
- return list_window_cmd(lw, metalist_length, cmd);
+ break;
}
+
+ if( filelist )
+ return list_window_cmd(lw, filelist->length, cmd);
+ else if( metalist )
+ return list_window_cmd(lw, metalist_length, cmd);
+
return 0;
}
diff --git a/src/screen_search.c b/src/screen_search.c
index 06677bf06463c1a02694c0e898c4e27e7c66bd6a..03ce11ad6370e7d8b83f01cacf31f1886862b966 100644 (file)
--- a/src/screen_search.c
+++ b/src/screen_search.c
}
filelist = mpdclient_filelist_search(c,
+ FALSE,
mode[options.search_mode].table,
pattern);
sync_highlights(c, filelist);
{
search_clear(screen, c, FALSE);
filelist = mpdclient_filelist_search(c,
+ FALSE,
mode[options.search_mode].table,
pattern);
sync_highlights(c, filelist);