Code

utils: move gcmp_list_from_path() to db_completion.c
authorMax Kellermann <max.kellermann@gmail.com>
Tue, 21 Mar 2017 21:29:59 +0000 (22:29 +0100)
committerMax Kellermann <max.kellermann@gmail.com>
Tue, 21 Mar 2017 21:29:59 +0000 (22:29 +0100)
Makefile.am
src/db_completion.c [new file with mode: 0644]
src/db_completion.h [new file with mode: 0644]
src/save_playlist.c
src/screen_queue.c
src/utils.c
src/utils.h

index a72ecab446fd7f4f21d7f9c08805a66e01744c05..a70f478c9c6eb0e75a45b823a92ca8ab9e0bca88 100644 (file)
@@ -93,6 +93,7 @@ endif
 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
new file mode 100644 (file)
index 0000000..739e145
--- /dev/null
@@ -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
new file mode 100644 (file)
index 0000000..57a8b1f
--- /dev/null
@@ -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
index 118d11aeb519f880398d80711439ae1511c99d28..ed2134d280e69215af7e63b2c5289dd756ce830c 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include "save_playlist.h"
+#include "db_completion.h"
 #include "screen_status.h"
 #include "config.h"
 #include "i18n.h"
index 3d20da3bc999ad10f62e13dfb3a9aa9c7e0471f5..d98445ded49bc0a1a6b3f8e2406e191dcd69dc27 100644 (file)
@@ -36,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
index 3f327f4b0b80914025e6e925452114ed56ef1417..8f867ad36b87130d339b803bdde1ca2f4d366238 100644 (file)
  */
 
 #include "utils.h"
-#include "options.h"
-#include "charset.h"
 #include "i18n.h"
-#include "mpdclient.h"
 
-#include <ctype.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -63,54 +59,6 @@ string_list_remove(GList *string_list, const gchar *str)
        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)
 {
index 46f5ba51997ff7950b6e5ba434ba43a8f047dfc0..ecd68bbf6e4b4f35e34bf6220fa85ef3a0f9aeab 100644 (file)
 
 #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);