Code

wreadln: moved code to insert_byte()
[ncmpc.git] / src / filelist.c
index 6e4ebed55d84499e126bd9703c00f63c823ecc76..415eec4021a6038c5def9f96a1d05b6871e52f5f 100644 (file)
@@ -29,7 +29,6 @@ filelist_new(const char *path)
        struct filelist *filelist = g_malloc(sizeof(*filelist));
 
        filelist->path = g_strdup(path);
-       filelist->updated = FALSE;
        filelist->entries = g_ptr_array_new();
 
        return filelist;
@@ -101,10 +100,22 @@ filelist_move(struct filelist *filelist, struct filelist *from)
        g_ptr_array_set_size(from->entries, 0);
 }
 
+static gint
+filelist_compare_indirect(gconstpointer ap, gconstpointer bp, gpointer data)
+{
+       GCompareFunc compare_func = data;
+       gconstpointer a = *(const gconstpointer*)ap;
+       gconstpointer b = *(const gconstpointer*)bp;
+
+       return compare_func(a, b);
+}
+
 void
 filelist_sort(struct filelist *filelist, GCompareFunc compare_func)
 {
-       g_ptr_array_sort(filelist->entries, compare_func);
+       g_ptr_array_sort_with_data(filelist->entries,
+                                  filelist_compare_indirect,
+                                  compare_func);
 }
 
 struct filelist_entry *
@@ -128,3 +139,22 @@ filelist_find_song(struct filelist *fl, const struct mpd_song *song)
 
        return NULL;
 }
+
+int
+filelist_find_directory(struct filelist *filelist, const char *name)
+{
+       guint i;
+
+       assert(name != NULL);
+
+       for (i = 0; i < filelist_length(filelist); ++i) {
+               struct filelist_entry *entry = filelist_get(filelist, i);
+               mpd_InfoEntity *entity  = entry->entity;
+
+               if (entity && entity->type == MPD_INFO_ENTITY_TYPE_DIRECTORY &&
+                   strcmp(entity->info.directory->path, name) == 0)
+                       return i;
+       }
+
+       return -1;
+}