diff options
Diffstat (limited to 'commands.c')
-rw-r--r-- | commands.c | 46 |
1 files changed, 25 insertions, 21 deletions
@@ -58,33 +58,37 @@ static void commands_find(GSocketConnection *connection, const gchar *cmd, GErro gchar **data = g_strsplit(cmd, " ", 3); if(g_strv_length(data) != 3) { - *error = g_error_new(commands_quark(), 0, "syntax: find artist|title|album search"); + *error = g_error_new(commands_quark(), 0, "syntax: find[r|l] artist|title|album search"); return; } - gboolean remote = g_strncasecmp(data[0], "findr", 5) == 0 ? FALSE : TRUE; - - GSList *list = NULL; - if(g_ascii_strcasecmp(data[1], "artist") == 0) { - list = music_find_artist(data[2]); - } else if(g_ascii_strcasecmp(data[1] , "title") == 0) { - list = music_find_title(data[2]); - } else if(g_ascii_strcasecmp(data[1], "album") == 0) { - list = music_find_album(data[2]); - } else { - *error = g_error_new(commands_quark(), 0, "unknown search method %s", data[1]); - return; - } + gboolean remote = g_strncasecmp(data[0], "findl", 5) == 0 ? FALSE : TRUE; + gboolean local = g_strncasecmp(data[0], "findr", 5) == 0 ? FALSE : TRUE; GString *string = g_string_new(NULL); - for(GSList *node = list; node; node = g_slist_next(node)) { - struct file *f = node->data; - gchar *relpath = g_build_filename(f->parent->path + - strlen(music_root->path), f->name, NULL); - g_string_append_printf(string, "%s\n", relpath); - g_free(relpath); + + if(local == TRUE) { + GSList *list = NULL; + if(g_ascii_strcasecmp(data[1], "artist") == 0) { + list = music_find_artist(data[2]); + } else if(g_ascii_strcasecmp(data[1] , "title") == 0) { + list = music_find_title(data[2]); + } else if(g_ascii_strcasecmp(data[1], "album") == 0) { + list = music_find_album(data[2]); + } else { + *error = g_error_new(commands_quark(), 0, "unknown search method %s", data[1]); + return; + } + + for(GSList *node = list; node; node = g_slist_next(node)) { + struct file *f = node->data; + gchar *relpath = g_build_filename(f->parent->path + + strlen(music_root->path), f->name, NULL); + g_string_append_printf(string, "%s\n", relpath); + g_free(relpath); + } + g_slist_free(list); } - g_slist_free(list); if(remote == TRUE) { for(GSList *node = servers; node; node = g_slist_next(node)) { |