summaryrefslogtreecommitdiff
path: root/apps/filetree.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/filetree.c')
-rw-r--r--apps/filetree.c47
1 files changed, 21 insertions, 26 deletions
diff --git a/apps/filetree.c b/apps/filetree.c
index 37a66c60ee..e8b8df73ad 100644
--- a/apps/filetree.c
+++ b/apps/filetree.c
@@ -79,12 +79,12 @@ static void check_file_thumbnails(struct tree_context* c)
79 struct dircache_entry *entry; 79 struct dircache_entry *entry;
80 struct entry* dircache = c->dircache; 80 struct entry* dircache = c->dircache;
81 DIRCACHED *dir; 81 DIRCACHED *dir;
82 82
83 dir = opendir_cached(c->currdir); 83 dir = opendir_cached(c->currdir);
84 if(!dir) 84 if(!dir)
85 return; 85 return;
86 86 /* mark all files as non talking, except the .talk ones */
87 for (i=0; i < c->filesindir; i++) /* mark all files as non talking, except the .talk ones */ 87 for (i=0; i < c->filesindir; i++)
88 { 88 {
89 if (dircache[i].attr & ATTR_DIRECTORY) 89 if (dircache[i].attr & ATTR_DIRECTORY)
90 continue; /* we're not touching directories */ 90 continue; /* we're not touching directories */
@@ -100,7 +100,7 @@ static void check_file_thumbnails(struct tree_context* c)
100 dircache[i].attr |= TREE_ATTR_THUMBNAIL; /* set */ 100 dircache[i].attr |= TREE_ATTR_THUMBNAIL; /* set */
101 } 101 }
102 } 102 }
103 103
104 while((entry = readdir_cached(dir)) != 0) /* walk directory */ 104 while((entry = readdir_cached(dir)) != 0) /* walk directory */
105 { 105 {
106 int ext_pos; 106 int ext_pos;
@@ -110,13 +110,13 @@ static void check_file_thumbnails(struct tree_context* c)
110 || (entry->attribute & ATTR_DIRECTORY) /* no file */ 110 || (entry->attribute & ATTR_DIRECTORY) /* no file */
111 || strcasecmp(&entry->d_name[ext_pos], file_thumbnail_ext)) 111 || strcasecmp(&entry->d_name[ext_pos], file_thumbnail_ext))
112 { /* or doesn't end with ".talk", no candidate */ 112 { /* or doesn't end with ".talk", no candidate */
113 continue; 113 continue;
114 } 114 }
115 115
116 /* terminate the (disposable) name in dir buffer, 116 /* terminate the (disposable) name in dir buffer,
117 this truncates off the ".talk" without needing an extra buffer */ 117 this truncates off the ".talk" without needing an extra buffer */
118 entry->d_name[ext_pos] = '\0'; 118 entry->d_name[ext_pos] = '\0';
119 119
120 /* search corresponding file in dir cache */ 120 /* search corresponding file in dir cache */
121 for (i=0; i < c->filesindir; i++) 121 for (i=0; i < c->filesindir; i++)
122 { 122 {
@@ -187,7 +187,7 @@ static int compare(const void* p1, const void* p2)
187 return 0; /* never reached */ 187 return 0; /* never reached */
188} 188}
189 189
190/* load and sort directory into dircache. returns NULL on failure. */ 190/* load and sort directory into dircache. returns NULL on failure. */
191int ft_load(struct tree_context* c, const char* tempdir) 191int ft_load(struct tree_context* c, const char* tempdir)
192{ 192{
193 int i; 193 int i;
@@ -256,7 +256,7 @@ int ft_load(struct tree_context* c, const char* tempdir)
256 boot_cluster = entry->startcluster; 256 boot_cluster = entry->startcluster;
257 } 257 }
258#endif 258#endif
259 259
260 /* filter out non-visible files */ 260 /* filter out non-visible files */
261 if ((!(dptr->attr & ATTR_DIRECTORY) && ( 261 if ((!(dptr->attr & ATTR_DIRECTORY) && (
262 (*c->dirfilter == SHOW_PLAYLIST && 262 (*c->dirfilter == SHOW_PLAYLIST &&
@@ -289,7 +289,7 @@ int ft_load(struct tree_context* c, const char* tempdir)
289 name_buffer_used += len + 1; 289 name_buffer_used += len + 1;
290 290
291 if (dptr->attr & ATTR_DIRECTORY) /* count the remaining dirs */ 291 if (dptr->attr & ATTR_DIRECTORY) /* count the remaining dirs */
292 c->dirsindir++; 292 c->dirsindir++;
293 } 293 }
294 c->filesindir = i; 294 c->filesindir = i;
295 c->dirlength = i; 295 c->dirlength = i;
@@ -297,7 +297,7 @@ int ft_load(struct tree_context* c, const char* tempdir)
297 297
298 qsort(c->dircache,i,sizeof(struct entry),compare); 298 qsort(c->dircache,i,sizeof(struct entry),compare);
299 299
300 /* If thumbnail talking is enabled, make an extra run to mark files with 300 /* If thumbnail talking is enabled, make an extra run to mark files with
301 associated thumbnails, so we don't do unsuccessful spinups later. */ 301 associated thumbnails, so we don't do unsuccessful spinups later. */
302 if (global_settings.talk_file == 3) 302 if (global_settings.talk_file == 3)
303 check_file_thumbnails(c); /* map .talk to ours */ 303 check_file_thumbnails(c); /* map .talk to ours */
@@ -310,7 +310,7 @@ int ft_enter(struct tree_context* c)
310 int rc = 0; 310 int rc = 0;
311 char buf[MAX_PATH]; 311 char buf[MAX_PATH];
312 struct entry *dircache = c->dircache; 312 struct entry *dircache = c->dircache;
313 struct entry* file = &dircache[c->dircursor + c->dirstart]; 313 struct entry* file = &dircache[c->selected_item];
314 bool reload_dir = false; 314 bool reload_dir = false;
315 bool start_wps = false; 315 bool start_wps = false;
316 bool exit_func = false; 316 bool exit_func = false;
@@ -322,13 +322,10 @@ int ft_enter(struct tree_context* c)
322 322
323 if (file->attr & ATTR_DIRECTORY) { 323 if (file->attr & ATTR_DIRECTORY) {
324 memcpy(c->currdir, buf, sizeof(c->currdir)); 324 memcpy(c->currdir, buf, sizeof(c->currdir));
325 if ( c->dirlevel < MAX_DIR_LEVELS ) { 325 if ( c->dirlevel < MAX_DIR_LEVELS )
326 c->dirpos[c->dirlevel] = c->dirstart; 326 c->selected_item_history[c->dirlevel] = c->selected_item;
327 c->cursorpos[c->dirlevel] = c->dircursor;
328 }
329 c->dirlevel++; 327 c->dirlevel++;
330 c->dircursor=0; 328 c->selected_item=0;
331 c->dirstart=0;
332 } 329 }
333 else { 330 else {
334 int seed = current_tick; 331 int seed = current_tick;
@@ -357,8 +354,7 @@ int ft_enter(struct tree_context* c)
357 354
358 if (playlist_create(c->currdir, NULL) != -1) 355 if (playlist_create(c->currdir, NULL) != -1)
359 { 356 {
360 start_index = 357 start_index = ft_build_playlist(c, c->selected_item);
361 ft_build_playlist(c, c->dircursor + c->dirstart);
362 if (global_settings.playlist_shuffle) 358 if (global_settings.playlist_shuffle)
363 { 359 {
364 start_index = playlist_shuffle(seed, start_index); 360 start_index = playlist_shuffle(seed, start_index);
@@ -497,14 +493,13 @@ int ft_exit(struct tree_context* c)
497 exit_func = true; 493 exit_func = true;
498 494
499 c->dirlevel--; 495 c->dirlevel--;
500 if ( c->dirlevel < MAX_DIR_LEVELS ) { 496 if ( c->dirlevel < MAX_DIR_LEVELS )
501 c->dirstart = c->dirpos[c->dirlevel]; 497 c->selected_item=c->selected_item_history[c->dirlevel];
502 c->dircursor = c->cursorpos[c->dirlevel];
503 }
504 else 498 else
505 c->dirstart = c->dircursor = 0; 499 c->selected_item=0;
506 500
507 if (c->dirstart == -1) 501 /* if undefined position */
502 if (c->selected_item == -1)
508 strcpy(lastfile, buf); 503 strcpy(lastfile, buf);
509 } 504 }
510 else 505 else