Code

utils: move format_duration_*() to time_format.c
[ncmpc.git] / src / filelist.h
index 3b33eb44960fd75eb29fb6caf4d6222d0daf91c1..f8ada59e3ad8cdeecb22abb9215f648c92f41280 100644 (file)
@@ -1,6 +1,6 @@
-/*
- * (c) 2004 by Kalle Wallin <kaw@linux.se>
- * (c) 2008 Max Kellermann <max@duempel.org>
+/* 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
  * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
+ * 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 FILELIST_H
 #define FILELIST_H
 
+#include "Compiler.h"
+
 #include <glib.h>
 
+struct mpd_connection;
 struct mpd_song;
 
-typedef struct filelist_entry {
+struct filelist_entry {
        guint flags;
-       struct mpd_InfoEntity *entity;
-} filelist_entry_t;
-
-typedef struct filelist {
-       /* path */
-       gchar *path;
-
-       /* list length */
-       guint length;
-
-       /* true if the list is updated */
-       gboolean updated;
+       struct mpd_entity *entity;
+};
 
+struct filelist {
        /* the list */
-       GList *list;
-} mpdclient_filelist_t;
+       GPtrArray *entries;
+};
+
+struct filelist *
+filelist_new(void);
 
 void
 filelist_free(struct filelist *filelist);
 
+static inline guint
+filelist_length(const struct filelist *filelist)
+{
+       return filelist->entries->len;
+}
+
+static inline gboolean
+filelist_is_empty(const struct filelist *filelist)
+{
+       return filelist_length(filelist) == 0;
+}
+
+gcc_pure
+static inline struct filelist_entry *
+filelist_get(const struct filelist *filelist, guint i)
+{
+       return g_ptr_array_index(filelist->entries, i);
+}
+
 struct filelist_entry *
-filelist_find_song(struct filelist *flist, const struct mpd_song *song);
+filelist_append(struct filelist *filelist, struct mpd_entity *entity);
+
+void
+filelist_move(struct filelist *filelist, struct filelist *from);
+
+gcc_pure
+gint
+compare_filelist_entry_path(gconstpointer filelist_entry1,
+                           gconstpointer filelist_entry2);
+
+/* Sorts the whole filelist, at the moment used by filelist_search */
+void
+filelist_sort_all(struct filelist *filelist, GCompareFunc compare_func);
+
+/* Only sorts the directories and playlist files.
+ * The songs stay in the order it came from mpd. */
+void
+filelist_sort_dir_play(struct filelist *filelist, GCompareFunc compare_func);
+
+/**
+ * Eliminates duplicate songs from the filelist.
+ */
+void
+filelist_no_duplicates(struct filelist *filelist);
+
+gcc_pure
+int
+filelist_find_song(const struct filelist *flist, const struct mpd_song *song);
+
+gcc_pure
+int
+filelist_find_directory(const struct filelist *filelist, const char *name);
+
+/**
+ * Receives entities from the connection, and appends them to the
+ * specified filelist.  This does not finish the response, and does
+ * not check for errors.
+ */
+void
+filelist_recv(struct filelist *filelist, struct mpd_connection *connection);
+
+/**
+ * Creates a new filelist and receives entities from the connection.
+ * This does not finish the response, and does not check for errors.
+ */
+struct filelist *
+filelist_new_recv(struct mpd_connection *connection);
 
 #endif