summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1ba6283)
raw | patch | inline | side by side (parent: 1ba6283)
author | Max Kellermann <max.kellermann@gmail.com> | |
Tue, 21 Mar 2017 21:29:59 +0000 (22:29 +0100) | ||
committer | Max Kellermann <max.kellermann@gmail.com> | |
Tue, 21 Mar 2017 21:29:59 +0000 (22:29 +0100) |
Makefile.am | patch | blob | history | |
src/db_completion.c | [new file with mode: 0644] | patch | blob |
src/db_completion.h | [new file with mode: 0644] | patch | blob |
src/save_playlist.c | patch | blob | history | |
src/screen_queue.c | patch | blob | history | |
src/utils.c | patch | blob | history | |
src/utils.h | patch | blob | history |
diff --git a/Makefile.am b/Makefile.am
index a72ecab446fd7f4f21d7f9c08805a66e01744c05..a70f478c9c6eb0e75a45b823a92ca8ab9e0bca88 100644 (file)
--- a/Makefile.am
+++ b/Makefile.am
if NCMPC_MINI
else
src_ncmpc_SOURCES += \
+ src/db_completion.c src/db_completion.h \
src/xterm_title.c src/xterm_title.h \
src/hscroll.c src/hscroll.h \
src/match.c src/match.h \
diff --git a/src/db_completion.c b/src/db_completion.c
--- /dev/null
+++ b/src/db_completion.c
@@ -0,0 +1,71 @@
+/* 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 "db_completion.h"
+#include "charset.h"
+#include "mpdclient.h"
+
+#include <string.h>
+
+GList *
+gcmp_list_from_path(struct mpdclient *c, const gchar *path,
+ GList *list, gint types)
+{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ return list;
+
+ mpd_send_list_meta(connection, path);
+
+ struct mpd_entity *entity;
+ while ((entity = mpd_recv_entity(connection)) != NULL) {
+ char *name;
+
+ if (mpd_entity_get_type(entity) == MPD_ENTITY_TYPE_DIRECTORY &&
+ types & GCMP_TYPE_DIR) {
+ const struct mpd_directory *dir =
+ mpd_entity_get_directory(entity);
+ gchar *tmp = utf8_to_locale(mpd_directory_get_path(dir));
+ gsize size = strlen(tmp)+2;
+
+ name = g_malloc(size);
+ g_strlcpy(name, tmp, size);
+ g_strlcat(name, "/", size);
+ g_free(tmp);
+ } else if (mpd_entity_get_type(entity) == MPD_ENTITY_TYPE_SONG &&
+ types & GCMP_TYPE_FILE) {
+ const struct mpd_song *song =
+ mpd_entity_get_song(entity);
+ name = utf8_to_locale(mpd_song_get_uri(song));
+ } else if (mpd_entity_get_type(entity) == MPD_ENTITY_TYPE_PLAYLIST &&
+ types & GCMP_TYPE_PLAYLIST) {
+ const struct mpd_playlist *playlist =
+ mpd_entity_get_playlist(entity);
+ name = utf8_to_locale(mpd_playlist_get_path(playlist));
+ } else {
+ mpd_entity_free(entity);
+ continue;
+ }
+
+ list = g_list_append(list, name);
+ mpd_entity_free(entity);
+ }
+
+ return list;
+}
diff --git a/src/db_completion.h b/src/db_completion.h
--- /dev/null
+++ b/src/db_completion.h
@@ -0,0 +1,40 @@
+/* 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 DB_COMPLETION_H
+#define DB_COMPLETION_H
+
+#include <glib.h>
+
+struct mpdclient;
+
+#define GCMP_TYPE_DIR (0x01 << 0)
+#define GCMP_TYPE_FILE (0x01 << 1)
+#define GCMP_TYPE_PLAYLIST (0x01 << 2)
+#define GCMP_TYPE_RFILE (GCMP_TYPE_DIR | GCMP_TYPE_FILE)
+#define GCMP_TYPE_RPLAYLIST (GCMP_TYPE_DIR | GCMP_TYPE_PLAYLIST)
+
+/**
+ * Create a list suitable for GCompletion from path.
+ */
+GList *
+gcmp_list_from_path(struct mpdclient *c, const gchar *path,
+ GList *list, gint types);
+
+#endif
diff --git a/src/save_playlist.c b/src/save_playlist.c
index 118d11aeb519f880398d80711439ae1511c99d28..ed2134d280e69215af7e63b2c5289dd756ce830c 100644 (file)
--- a/src/save_playlist.c
+++ b/src/save_playlist.c
*/
#include "save_playlist.h"
+#include "db_completion.h"
#include "screen_status.h"
#include "config.h"
#include "i18n.h"
diff --git a/src/screen_queue.c b/src/screen_queue.c
index 3d20da3bc999ad10f62e13dfb3a9aa9c7e0471f5..d98445ded49bc0a1a6b3f8e2406e191dcd69dc27 100644 (file)
--- a/src/screen_queue.c
+++ b/src/screen_queue.c
#include "screen_utils.h"
#include "screen_song.h"
#include "screen_lyrics.h"
+#include "db_completion.h"
#include "Compiler.h"
#ifndef NCMPC_MINI
diff --git a/src/utils.c b/src/utils.c
index 3f327f4b0b80914025e6e925452114ed56ef1417..8f867ad36b87130d339b803bdde1ca2f4d366238 100644 (file)
--- a/src/utils.c
+++ b/src/utils.c
*/
#include "utils.h"
-#include "options.h"
-#include "charset.h"
#include "i18n.h"
-#include "mpdclient.h"
-#include <ctype.h>
#include <stdlib.h>
#include <string.h>
return list;
}
-/* create a list suitable for GCompletion from path */
-GList *
-gcmp_list_from_path(struct mpdclient *c, const gchar *path,
- GList *list, gint types)
-{
- struct mpd_connection *connection = mpdclient_get_connection(c);
- if (connection == NULL)
- return list;
-
- mpd_send_list_meta(connection, path);
-
- struct mpd_entity *entity;
- while ((entity = mpd_recv_entity(connection)) != NULL) {
- char *name;
-
- if (mpd_entity_get_type(entity) == MPD_ENTITY_TYPE_DIRECTORY &&
- types & GCMP_TYPE_DIR) {
- const struct mpd_directory *dir =
- mpd_entity_get_directory(entity);
- gchar *tmp = utf8_to_locale(mpd_directory_get_path(dir));
- gsize size = strlen(tmp)+2;
-
- name = g_malloc(size);
- g_strlcpy(name, tmp, size);
- g_strlcat(name, "/", size);
- g_free(tmp);
- } else if (mpd_entity_get_type(entity) == MPD_ENTITY_TYPE_SONG &&
- types & GCMP_TYPE_FILE) {
- const struct mpd_song *song =
- mpd_entity_get_song(entity);
- name = utf8_to_locale(mpd_song_get_uri(song));
- } else if (mpd_entity_get_type(entity) == MPD_ENTITY_TYPE_PLAYLIST &&
- types & GCMP_TYPE_PLAYLIST) {
- const struct mpd_playlist *playlist =
- mpd_entity_get_playlist(entity);
- name = utf8_to_locale(mpd_playlist_get_path(playlist));
- } else {
- mpd_entity_free(entity);
- continue;
- }
-
- list = g_list_append(list, name);
- mpd_entity_free(entity);
- }
-
- return list;
-}
-
void
format_duration_short(char *buffer, size_t length, unsigned duration)
{
diff --git a/src/utils.h b/src/utils.h
index 46f5ba51997ff7950b6e5ba434ba43a8f047dfc0..ecd68bbf6e4b4f35e34bf6220fa85ef3a0f9aeab 100644 (file)
--- a/src/utils.h
+++ b/src/utils.h
#include <glib.h>
-struct mpdclient;
-
/* functions for lists containing strings */
GList *string_list_free(GList *string_list);
GList *string_list_find(GList *string_list, const gchar *str);
GList *string_list_remove(GList *string_list, const gchar *str);
-/* create a string list from path - used for completion */
-#define GCMP_TYPE_DIR (0x01 << 0)
-#define GCMP_TYPE_FILE (0x01 << 1)
-#define GCMP_TYPE_PLAYLIST (0x01 << 2)
-#define GCMP_TYPE_RFILE (GCMP_TYPE_DIR | GCMP_TYPE_FILE)
-#define GCMP_TYPE_RPLAYLIST (GCMP_TYPE_DIR | GCMP_TYPE_PLAYLIST)
-
-GList *
-gcmp_list_from_path(struct mpdclient *c, const gchar *path,
- GList *list, gint types);
-
void
format_duration_short(char *buffer, size_t length, unsigned duration);