X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fscreen_queue.c;h=47eb7165eee0404db24505cf1b659124f7c012e6;hb=23041f39c7c7e1d119ffe2f6239cc3a2f1248e1a;hp=45505eee015fd51252eb4e29c2200269bc099dd4;hpb=642bdd04cb9c093689ddacdb6b2784b017382c3a;p=ncmpc.git diff --git a/src/screen_queue.c b/src/screen_queue.c index 45505ee..47eb716 100644 --- a/src/screen_queue.c +++ b/src/screen_queue.c @@ -22,6 +22,7 @@ #include "screen_file.h" #include "screen_status.h" #include "screen_find.h" +#include "save_playlist.h" #include "config.h" #include "i18n.h" #include "charset.h" @@ -35,6 +36,7 @@ #include "screen_utils.h" #include "screen_song.h" #include "screen_lyrics.h" +#include "db_completion.h" #include "Compiler.h" #ifndef NCMPC_MINI @@ -180,32 +182,6 @@ screen_queue_song_change(const struct mpd_status *status) return true; } -#ifndef NCMPC_MINI -static void -save_pre_completion_cb(GCompletion *gcmp, gcc_unused gchar *line, - void *data) -{ - completion_callback_data_t *tmp = (completion_callback_data_t *)data; - GList **list = tmp->list; - struct mpdclient *c = tmp->c; - - if( *list == NULL ) { - /* create completion list */ - *list = gcmp_list_from_path(c, "", NULL, GCMP_TYPE_PLAYLIST); - g_completion_add_items(gcmp, *list); - } -} - -static void -save_post_completion_cb(gcc_unused GCompletion *gcmp, - gcc_unused gchar *line, GList *items, - gcc_unused void *data) -{ - if (g_list_length(items) >= 1) - screen_display_completion_list(items); -} -#endif - #ifndef NCMPC_MINI /** * Wrapper for strncmp(). We are not allowed to pass &strncmp to @@ -219,102 +195,6 @@ completion_strncmp(const gchar *s1, const gchar *s2, gsize n) } #endif -int -playlist_save(struct mpdclient *c, char *name, char *defaultname) -{ - struct mpd_connection *connection; - gchar *filename; - -#ifdef NCMPC_MINI - (void)defaultname; -#endif - -#ifndef NCMPC_MINI - if (name == NULL) { - /* initialize completion support */ - GCompletion *gcmp = g_completion_new(NULL); - g_completion_set_compare(gcmp, completion_strncmp); - GList *list = NULL; - completion_callback_data_t data = { - .list = &list, - .dir_list = NULL, - .c = c, - }; - wrln_completion_callback_data = &data; - wrln_pre_completion_callback = save_pre_completion_cb; - wrln_post_completion_callback = save_post_completion_cb; - - - /* query the user for a filename */ - filename = screen_readln(_("Save queue as"), - defaultname, - NULL, - gcmp); - - /* destroy completion support */ - wrln_completion_callback_data = NULL; - wrln_pre_completion_callback = NULL; - wrln_post_completion_callback = NULL; - g_completion_free(gcmp); - list = string_list_free(list); - if( filename ) - filename=g_strstrip(filename); - } else -#endif - filename=g_strdup(name); - - if (filename == NULL) - return -1; - - /* send save command to mpd */ - - connection = mpdclient_get_connection(c); - if (connection == NULL) { - g_free(filename); - return -1; - } - - char *filename_utf8 = locale_to_utf8(filename); - if (!mpd_run_save(connection, filename_utf8)) { - if (mpd_connection_get_error(connection) == MPD_ERROR_SERVER && - mpd_connection_get_server_error(connection) == MPD_SERVER_ERROR_EXIST && - mpd_connection_clear_error(connection)) { - char *buf = g_strdup_printf(_("Replace %s?"), filename); - bool replace = screen_get_yesno(buf, false); - g_free(buf); - - if (!replace) { - g_free(filename_utf8); - g_free(filename); - screen_status_printf(_("Aborted")); - return -1; - } - - if (!mpd_run_rm(connection, filename_utf8) || - !mpd_run_save(connection, filename_utf8)) { - mpdclient_handle_error(c); - g_free(filename_utf8); - g_free(filename); - return -1; - } - } else { - mpdclient_handle_error(c); - g_free(filename_utf8); - g_free(filename); - return -1; - } - } - - c->events |= MPD_IDLE_STORED_PLAYLIST; - - g_free(filename_utf8); - - /* success */ - screen_status_printf(_("Saved %s"), filename); - g_free(filename); - return 0; -} - #ifndef NCMPC_MINI static void add_dir(GCompletion *gcmp, gchar *dir, GList **dir_list, GList **list, struct mpdclient *c) @@ -490,13 +370,28 @@ screen_queue_exit(void) list_window_free(lw); } +/** + * Extract the host portion (without the optional password) from the + * MPD_HOST string. + */ +static const char * +host_without_password(const char *host) +{ + const char *separator = strchr(host, '@'); + if (separator != NULL && separator != host && separator[1] != 0) + host = separator + 1; + + return host; +} + static const char * screen_queue_title(char *str, size_t size) { if (options.host == NULL) return _("Queue"); - g_snprintf(str, size, _("Queue on %s"), options.host); + g_snprintf(str, size, _("Queue on %s"), + host_without_password(options.host)); return str; }