diff options
Diffstat (limited to 'apps/tree.c')
-rw-r--r-- | apps/tree.c | 118 |
1 files changed, 82 insertions, 36 deletions
diff --git a/apps/tree.c b/apps/tree.c index 90ae159418..effb093b41 100644 --- a/apps/tree.c +++ b/apps/tree.c | |||
@@ -221,6 +221,25 @@ static int build_playlist(int start_index) | |||
221 | return start_index; | 221 | return start_index; |
222 | } | 222 | } |
223 | 223 | ||
224 | static int play_filenumber(int pos, int attr) | ||
225 | { | ||
226 | /* try to find a voice ID for the extension, if known */ | ||
227 | unsigned int j; | ||
228 | int ext_id = -1; /* default to none */ | ||
229 | for (j=0; j<sizeof(filetypes)/sizeof(*filetypes); j++) | ||
230 | { | ||
231 | if (attr == filetypes[j].tree_attr) | ||
232 | { | ||
233 | ext_id = filetypes[j].voiceclip; | ||
234 | break; | ||
235 | } | ||
236 | } | ||
237 | |||
238 | talk_id(VOICE_FILE, false); | ||
239 | talk_number(pos, true); | ||
240 | talk_id(ext_id, true); | ||
241 | return 1; | ||
242 | } | ||
224 | 243 | ||
225 | static int play_dirname(int start_index) | 244 | static int play_dirname(int start_index) |
226 | { | 245 | { |
@@ -250,6 +269,41 @@ static int play_dirname(int start_index) | |||
250 | return 1; | 269 | return 1; |
251 | } | 270 | } |
252 | 271 | ||
272 | static int play_filename(char *dir, char *file) | ||
273 | { | ||
274 | int fd; | ||
275 | char name_mp3_filename[MAX_PATH+1]; | ||
276 | |||
277 | if (mpeg_status() & MPEG_STATUS_PLAY) | ||
278 | return 0; | ||
279 | |||
280 | if (strcasecmp(&file[strlen(file) - strlen(TALK_EXT)], TALK_EXT)) | ||
281 | { /* file has no .talk extension */ | ||
282 | snprintf(name_mp3_filename, sizeof(name_mp3_filename), | ||
283 | "%s/%s" TALK_EXT, dir, file); | ||
284 | |||
285 | /* check if a corresponding .talk file exists */ | ||
286 | DEBUGF("Checking for Filename Thumb %s\n", name_mp3_filename); | ||
287 | fd = open(name_mp3_filename, O_RDONLY); | ||
288 | if (fd < 0) | ||
289 | { | ||
290 | DEBUGF("Failed to find: %s\n", name_mp3_filename); | ||
291 | return -1; | ||
292 | } | ||
293 | DEBUGF("Found: %s\n", name_mp3_filename); | ||
294 | close(fd); | ||
295 | talk_file(name_mp3_filename, false); | ||
296 | } | ||
297 | else | ||
298 | { /* it already is a .talk file, play this directly */ | ||
299 | snprintf(name_mp3_filename, sizeof(name_mp3_filename), | ||
300 | "%s/%s", dir, file); | ||
301 | talk_id(LANG_VOICE_DIR_HOVER, false); /* prefix it */ | ||
302 | talk_file(name_mp3_filename, true); | ||
303 | } | ||
304 | |||
305 | return 1; | ||
306 | } | ||
253 | 307 | ||
254 | static int compare(const void* p1, const void* p2) | 308 | static int compare(const void* p1, const void* p2) |
255 | { | 309 | { |
@@ -771,7 +825,6 @@ static bool dirbrowse(const char *root, const int *dirfilter) | |||
771 | int lastdircursor=-1; | 825 | int lastdircursor=-1; |
772 | bool need_update = true; | 826 | bool need_update = true; |
773 | bool exit_func = false; | 827 | bool exit_func = false; |
774 | bool enqueue_next = false; | ||
775 | long thumbnail_time = -1; /* for delaying a thumbnail */ | 828 | long thumbnail_time = -1; /* for delaying a thumbnail */ |
776 | bool update_all = false; /* set this to true when the whole file list | 829 | bool update_all = false; /* set this to true when the whole file list |
777 | has been refreshed on screen */ | 830 | has been refreshed on screen */ |
@@ -926,14 +979,6 @@ static bool dirbrowse(const char *root, const int *dirfilter) | |||
926 | snprintf(buf,sizeof(buf),"/%s",file->name); | 979 | snprintf(buf,sizeof(buf),"/%s",file->name); |
927 | 980 | ||
928 | if (file->attr & ATTR_DIRECTORY) { | 981 | if (file->attr & ATTR_DIRECTORY) { |
929 | if (global_settings.talk_dir == 3) /* enter */ | ||
930 | { | ||
931 | /* play_dirname */ | ||
932 | DEBUGF("Playing directory thumbnail: %s", currdir); | ||
933 | play_dirname(dircursor+dirstart); | ||
934 | /* avoid reading getting cut by next filename */ | ||
935 | enqueue_next = true; | ||
936 | } | ||
937 | memcpy(currdir,buf,sizeof(currdir)); | 982 | memcpy(currdir,buf,sizeof(currdir)); |
938 | if ( dirlevel < MAX_DIR_LEVELS ) { | 983 | if ( dirlevel < MAX_DIR_LEVELS ) { |
939 | dirpos[dirlevel] = dirstart; | 984 | dirpos[dirlevel] = dirstart; |
@@ -1306,12 +1351,26 @@ static bool dirbrowse(const char *root, const int *dirfilter) | |||
1306 | TIME_AFTER(current_tick, thumbnail_time)) | 1351 | TIME_AFTER(current_tick, thumbnail_time)) |
1307 | { /* a delayed hovering thumbnail is due now */ | 1352 | { /* a delayed hovering thumbnail is due now */ |
1308 | int res; | 1353 | int res; |
1309 | DEBUGF("Playing directory thumbnail: %s", currdir); | 1354 | if (dircache[lasti].attr & ATTR_DIRECTORY) |
1310 | res = play_dirname(lasti); | 1355 | { |
1311 | if (res < 0) /* failed, not existing */ | 1356 | DEBUGF("Playing directory thumbnail: %s", currdir); |
1312 | { /* say the number instead, as a fallback */ | 1357 | res = play_dirname(lasti); |
1313 | talk_id(VOICE_DIR, false); | 1358 | if (res < 0) /* failed, not existing */ |
1314 | talk_number(lasti+1, true); | 1359 | { /* say the number instead, as a fallback */ |
1360 | talk_id(VOICE_DIR, false); | ||
1361 | talk_number(lasti+1, true); | ||
1362 | } | ||
1363 | } | ||
1364 | else | ||
1365 | { | ||
1366 | DEBUGF("Playing file thumbnail: %s/%s%s\n", | ||
1367 | currdir, dircache[lasti].name, TALK_EXT); | ||
1368 | res = play_filename(currdir, dircache[lasti].name); | ||
1369 | if (res < 0) /* failed, not existing */ | ||
1370 | { /* say the number instead, as a fallback */ | ||
1371 | play_filenumber(lasti-dirsindir+1, | ||
1372 | dircache[lasti].attr); | ||
1373 | } | ||
1315 | } | 1374 | } |
1316 | thumbnail_time = -1; /* job done */ | 1375 | thumbnail_time = -1; /* job done */ |
1317 | } | 1376 | } |
@@ -1417,7 +1476,7 @@ static bool dirbrowse(const char *root, const int *dirfilter) | |||
1417 | if (dircache[i].attr & ATTR_DIRECTORY) /* directory? */ | 1476 | if (dircache[i].attr & ATTR_DIRECTORY) /* directory? */ |
1418 | { | 1477 | { |
1419 | /* play directory thumbnail */ | 1478 | /* play directory thumbnail */ |
1420 | if (global_settings.talk_dir == 4) /* hover */ | 1479 | if (global_settings.talk_dir == 3) /* hover */ |
1421 | { /* "schedule" a thumbnail, to have a little dalay */ | 1480 | { /* "schedule" a thumbnail, to have a little dalay */ |
1422 | thumbnail_time = current_tick + HOVER_DELAY; | 1481 | thumbnail_time = current_tick + HOVER_DELAY; |
1423 | } | 1482 | } |
@@ -1433,29 +1492,16 @@ static bool dirbrowse(const char *root, const int *dirfilter) | |||
1433 | } | 1492 | } |
1434 | else if (global_settings.talk_file == 1) /* files as numbers */ | 1493 | else if (global_settings.talk_file == 1) /* files as numbers */ |
1435 | { | 1494 | { |
1436 | /* try to find a voice ID for the extension, if known */ | 1495 | play_filenumber(i-dirsindir+1, |
1437 | unsigned int j; | 1496 | dircache[i].attr & TREE_ATTR_MASK); |
1438 | int ext_id = -1; /* default to none */ | ||
1439 | for (j=0; j<sizeof(filetypes)/sizeof(*filetypes); j++) | ||
1440 | { | ||
1441 | if ((dircache[i].attr & TREE_ATTR_MASK) == filetypes[j].tree_attr) | ||
1442 | { | ||
1443 | ext_id = filetypes[j].voiceclip; | ||
1444 | break; | ||
1445 | } | ||
1446 | } | ||
1447 | |||
1448 | /* enqueue_next is true if still talking the dir name */ | ||
1449 | talk_id(VOICE_FILE, enqueue_next); | ||
1450 | talk_number(i-dirsindir+1, true); | ||
1451 | talk_id(ext_id, true); | ||
1452 | enqueue_next = false; | ||
1453 | } | 1497 | } |
1454 | else if (global_settings.talk_file == 2) /* files spelled */ | 1498 | else if (global_settings.talk_file == 2) /* files spelled */ |
1455 | { | 1499 | { |
1456 | /* enqueue_next is true if still talking the dir name */ | 1500 | talk_spell(dircache[i].name, false); |
1457 | talk_spell(dircache[i].name, enqueue_next); | 1501 | } |
1458 | enqueue_next = false; | 1502 | else if (global_settings.talk_file == 3) /* hover */ |
1503 | { /* "schedule" a thumbnail, to have a little dalay */ | ||
1504 | thumbnail_time = current_tick + HOVER_DELAY; | ||
1459 | } | 1505 | } |
1460 | 1506 | ||
1461 | } | 1507 | } |