summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b316776)
raw | patch | inline | side by side (parent: b316776)
author | Max Kellermann <max.kellermann@gmail.com> | |
Mon, 20 Mar 2017 20:45:50 +0000 (21:45 +0100) | ||
committer | Max Kellermann <max.kellermann@gmail.com> | |
Mon, 20 Mar 2017 20:45:50 +0000 (21:45 +0100) |
Makefile.am | patch | blob | history | |
po/POTFILES.in | patch | blob | history | |
src/save_playlist.c | [new file with mode: 0644] | patch | blob |
src/save_playlist.h | [new file with mode: 0644] | patch | blob |
src/screen_file.c | patch | blob | history | |
src/screen_queue.c | patch | blob | history | |
src/screen_queue.h | patch | blob | history |
diff --git a/Makefile.am b/Makefile.am
index 46f8be638c38da05741a6b9188316d9240f61c53..a72ecab446fd7f4f21d7f9c08805a66e01744c05 100644 (file)
--- a/Makefile.am
+++ b/Makefile.am
src/screen_browser.c src/screen_browser.h \
src/screen_file.c src/screen_file.h \
src/list_window.c src/list_window.h \
+ src/save_playlist.c src/save_playlist.h \
src/paint.h \
src/song_paint.c src/song_paint.h \
src/colors.c src/colors.h \
diff --git a/po/POTFILES.in b/po/POTFILES.in
index d3af0cb63c588f91557fd0a559c96b67bfc30703..1ea275ca9607858577ebcc9be2cf6cf52dfd2bfb 100644 (file)
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
src/main.c
src/options.c
src/player_command.c
+src/save_playlist.c
src/screen.c
src/screen_artist.c
src/screen_browser.c
diff --git a/src/save_playlist.c b/src/save_playlist.c
--- /dev/null
+++ b/src/save_playlist.c
@@ -0,0 +1,175 @@
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2017 The Music Player Daemon Project
+ * Project homepage: http://musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "save_playlist.h"
+#include "screen_status.h"
+#include "config.h"
+#include "i18n.h"
+#include "charset.h"
+#include "mpdclient.h"
+#include "utils.h"
+#include "wreadln.h"
+#include "screen_utils.h"
+#include "Compiler.h"
+
+#include <mpd/client.h>
+
+#include <glib.h>
+
+#include <string.h>
+
+#ifndef NCMPC_MINI
+
+typedef struct
+{
+ GList **list;
+ struct mpdclient *c;
+} completion_callback_data_t;
+
+/**
+ * Wrapper for strncmp(). We are not allowed to pass &strncmp to
+ * g_completion_set_compare(), because strncmp() takes size_t where
+ * g_completion_set_compare passes a gsize value.
+ */
+static gint
+completion_strncmp(const gchar *s1, const gchar *s2, gsize n)
+{
+ return strncmp(s1, s2, n);
+}
+
+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
+
+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,
+ .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;
+}
diff --git a/src/save_playlist.h b/src/save_playlist.h
--- /dev/null
+++ b/src/save_playlist.h
@@ -0,0 +1,28 @@
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2017 The Music Player Daemon Project
+ * Project homepage: http://musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef SAVE_PLAYLIST_H
+#define SAVE_PLAYLIST_H
+
+struct mpdclient;
+
+int
+playlist_save(struct mpdclient *c, char *name, char *defaultname);
+
+#endif
diff --git a/src/screen_file.c b/src/screen_file.c
index 2af1655d3b3eca3e89c425c831ce3d7182a77865..b23a1c84a1363126d3a55aeb2d119997407500da 100644 (file)
--- a/src/screen_file.c
+++ b/src/screen_file.c
#include "screen_browser.h"
#include "screen_interface.h"
#include "screen_status.h"
-#include "screen_queue.h"
+#include "save_playlist.h"
#include "screen.h"
#include "config.h"
#include "i18n.h"
diff --git a/src/screen_queue.c b/src/screen_queue.c
index 45505eee015fd51252eb4e29c2200269bc099dd4..3d20da3bc999ad10f62e13dfb3a9aa9c7e0471f5 100644 (file)
--- a/src/screen_queue.c
+++ b/src/screen_queue.c
#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"
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
}
#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)
diff --git a/src/screen_queue.h b/src/screen_queue.h
index f37f1d53d519ca30561bde72fbe72fcd8c101831..d7d135adadaa0b26d1463e16f2b6a092302356e1 100644 (file)
--- a/src/screen_queue.h
+++ b/src/screen_queue.h
#ifndef NCMPC_SCREEN_QUEUE_H
#define NCMPC_SCREEN_QUEUE_H
-struct mpdclient;
-
extern const struct screen_functions screen_queue;
-int
-playlist_save(struct mpdclient *c, char *name, char *defaultname);
-
#endif