aboutsummaryrefslogtreecommitdiff
path: root/item.c
diff options
context:
space:
mode:
authorache <ache@ache.one>2017-05-27 18:38:45 +0200
committerache <ache@ache.one>2017-05-27 18:38:45 +0200
commit3889e10610da7915544d8ad865b2f9385c6dc383 (patch)
tree87a8ec3fb8b7b999d52a4a491e6b31a48ab09f14 /item.c
parentInit commit (diff)
New files
Diffstat (limited to 'item.c')
-rw-r--r--item.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/item.c b/item.c
new file mode 100644
index 0000000..b7dc18e
--- /dev/null
+++ b/item.c
@@ -0,0 +1,101 @@
+#include "item.h"
+
+
+
+int sort_i(const void* A, const void* B) {
+ itemC* a = (itemC*)A;
+ itemC* b = (itemC*)B;
+
+ if(a->opt > b->opt)
+ return -1;
+ else if(a->opt < b->opt)
+ return 1;
+ else {
+ return strcmp(a->cstr,b->cstr);
+ }
+}
+void freelitem( itemC* m, int s) {
+ for(int i = 0 ; i < s ; i++) {
+ free(m[i].cstr);
+ if( !m[i].opt) {
+ taglib_file_free(m[i].info.file);
+ }
+ }
+
+ taglib_tag_free_strings();
+ free(m);
+}
+void listdir(int option, itemC** m, int* s) {
+ DIR *dir;
+ int nbitem = 0;
+ itemC* menu = NULL;
+ struct dirent *entry;
+
+ if (!(dir = opendir(".")))
+ return;
+
+ if (!(entry = readdir(dir)))
+ return;
+
+ do {
+ if( entry->d_name[0] == '.' && !(option & HIDDEN) && strcmp(entry->d_name, "..") )
+ continue;
+
+// QUICK FIX OF TAGLIB
+ if( strchr(entry->d_name, '#') )
+ continue;
+#ifdef DEBUG
+ mvprintc(1,1,entry->d_name,COLS/2-5);
+#endif
+
+ refresh();
+
+// fprintf(stderr, "%s\n", entry->d_name);
+ menu = realloc(menu, ++nbitem * sizeof *menu);
+
+ if (entry->d_type == DT_DIR) {
+ char* tmp = malloc( strlen(entry->d_name)+3);
+ sprintf(tmp, "[%s]", entry->d_name);
+ menu[nbitem-1].cstr = tmp;
+ menu[nbitem-1].opt = 1;
+ menu[nbitem-1].id = nbitem-1;
+ menu[nbitem-1].selected = 0;
+ }
+ else {
+ TagLib_File *file;
+ TagLib_Tag *tag;
+ const TagLib_AudioProperties *properties;
+
+ file = taglib_file_new(entry->d_name);
+
+ if(file == NULL) {
+ menu = realloc(menu, --nbitem * sizeof *menu);
+ continue;
+ }
+
+ tag = taglib_file_tag(file);
+ properties = taglib_file_audioproperties(file);
+
+ if( ! properties ) {
+ fprintf(stderr, "ID3 file but not audio");
+ taglib_tag_free_strings();
+ taglib_file_free(file);
+ menu[nbitem-1].opt = 2;
+ }else{
+ menu[nbitem-1].opt = 0;
+ }
+ menu[nbitem-1].cstr = strdup(entry->d_name);
+ menu[nbitem-1].id = nbitem-1;
+ menu[nbitem-1].info = (tagInfo){file, tag, properties};
+ menu[nbitem-1].selected = 0;
+
+ }
+ } while (entry = readdir(dir));
+end:
+
+ closedir(dir);
+ *m = menu;
+ *s = nbitem;
+}
+
+