| 532 | bool PlayerContext::LoadExternalSubtitles(NuppelVideoPlayer *nvp, |
| 533 | const QString &videoFile) |
| 534 | { |
| 535 | if (videoFile.isEmpty()) |
| 536 | return false; |
| 537 | |
| 538 | QString fileName = videoFile; |
| 539 | QString dirName = "."; |
| 540 | |
| 541 | int dirPos = videoFile.lastIndexOf(QChar('/')); |
| 542 | if (dirPos > 0) |
| 543 | { |
| 544 | fileName = videoFile.mid(dirPos + 1); |
| 545 | dirName = videoFile.left(dirPos); |
| 546 | } |
| 547 | |
| 548 | QString baseName = fileName; |
| 549 | int suffixPos = fileName.lastIndexOf(QChar('.')); |
| 550 | if (suffixPos > 0) |
| 551 | baseName = fileName.left(suffixPos); |
| 552 | |
| 553 | // The dir listing does not work if the filename has the following chars, |
| 554 | // so we convert them to the wildcard '?' |
| 555 | baseName = baseName.replace("[", "?").replace("]", "?"); |
| 556 | baseName = baseName.replace("(", "?").replace(")", "?"); |
| 557 | |
| 558 | // Some Qt versions do not accept paths in the search string of |
| 559 | // entryList() so we have to set the dir first |
| 560 | QDir dir; |
| 561 | dir.setPath(dirName); |
| 562 | |
| 563 | // Try to find files with the same base name, but ending with |
| 564 | // '.srt', '.sub', or '.txt' |
| 565 | QStringList el; |
| 566 | el += baseName + "*.srt"; |
| 567 | el += baseName + "*.sub"; |
| 568 | el += baseName + "*.txt"; |
| 569 | QStringList candidates = dir.entryList(el); |
| 570 | |
| 571 | bool found = false; |
| 572 | QString candidate = ""; |
| 573 | QStringList::const_iterator it = candidates.begin(); |
| 574 | for (; (it != candidates.end()) && !found; ++it) |
| 575 | { |
| 576 | candidate = dirName + "/" + *it; |
| 577 | if (nvp->LoadExternalSubtitles(candidate)) |
| 578 | found = true; |
| 579 | } |
| 580 | |
| 581 | if (found) |
| 582 | { |
| 583 | VERBOSE(VB_PLAYBACK, LOC + |
| 584 | QString("Loaded text subtitles from '%1'.").arg(candidate)); |
| 585 | } |
| 586 | |
| 587 | return found; |
| 588 | } |
| 589 | |