Skip to content

Commit 13b8166

Browse files
authored
feat: Drag and drop to load subtitle
linuxdeepin/developer-center#927 (#38)
1 parent b4e511d commit 13b8166

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/common/mainwindow.cpp

+24-2
Original file line numberDiff line numberDiff line change
@@ -2794,8 +2794,30 @@ void MainWindow::dropEvent(QDropEvent *ev)
27942794
return;
27952795
}
27962796

2797-
auto urls = ev->mimeData()->urls();
2798-
auto valids = _engine->addPlayFiles(urls);
2797+
QList<QUrl> urls = ev->mimeData()->urls();
2798+
QList<QUrl> valids = _engine->addPlayFiles(urls);
2799+
2800+
if (urls.count() == 1 && valids.count() == 0) {
2801+
// check if the dropped file is a subtitle.
2802+
QFileInfo fileInfo(urls.first().toLocalFile());
2803+
if (_engine->subtitle_suffixs.contains(fileInfo.suffix())) {
2804+
bool succ = _engine->loadSubtitle(fileInfo);
2805+
// notice that the file loaded but won't automatically selected.
2806+
const PlayingMovieInfo& pmf = _engine->playingMovieInfo();
2807+
for (const SubtitleInfo& sub: pmf.subs) {
2808+
if (sub["external"].toBool()) {
2809+
QString path = sub["external-filename"].toString();
2810+
if (path == fileInfo.canonicalFilePath()) {
2811+
_engine->selectSubtitle(pmf.subs.indexOf(sub));
2812+
break;
2813+
}
2814+
}
2815+
}
2816+
QPixmap icon = utils::LoadHiDPIPixmap(QString(":/resources/icons/%1.svg").arg(succ ? "success" : "fail"));
2817+
_nwComm->popupWithIcon(succ ? tr("Load successfully") : tr("Load failed"), icon);
2818+
}
2819+
return;
2820+
}
27992821

28002822
{
28012823
auto all = urls.toSet();

src/libdmr/player_engine.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class PlayerEngine: public QWidget {
7070
"*.3g2","*.3ga","*.3gp","*.3gp2","*.3gpp","*.amv","*.asf","*.asx","*.avf","*.avi","*.bdm","*.bdmv","*.bik","*.clpi", "*.cpi","*.dat","*.divx","*.drc","*.dv","*.dvr-ms","*.f4v","*.flv","*.gvi","*.gxf","*.hdmov","*.hlv","*.iso","*.letv", "*.lrv","*.m1v","*.m2p","*.m2t","*.m2ts","*.m2v","*.m3u","*.m3u8","*.m4v","*.mkv","*.moov", "*.mov","*.mov","*.mp2","*.mp2v","*.mp4","*.mp4v","*.mpe","*.mpeg","*.mpeg1","*.mpeg2","*.mpeg4","*.mpg","*.mpl","*.mpls","*.mpv","*.mpv2","*.mqv", "*.mts","*.mts","*.mtv","*.mxf","*.mxg","*.nsv","*.nuv","*.ogg","*.ogm","*.ogv","*.ogx","*.ps","*.qt","*.qtvr","*.ram","*.rec", "*.rm","*.rm","*.rmj","*.rmm","*.rms","*.rmvb","*.rmx","*.rp","*.rpl","*.rv","*.rvx","*.thp","*.tod","*.tp","*.trp","*.ts","*.tts","*.txd","*.vcd", "*.vdr","*.vob","*.vp8","*.vro","*.webm","*.wm","*.wmv","*.wtv","*.xesc" ,"*.xspf"
7171
};
7272

73-
const QStringList subtitle_filetypes {"*.sub","*.srt","*.ass","*.ssa","*.smi","*.rt","*.txt","*.mks","*.vtt","*.sup"};
73+
const QStringList subtitle_suffixs {"ass", "sub", "srt", "aqt", "jss", "gsub", "ssf", "ssa", "smi", "usf", "idx"};
7474

7575
/* backend like mpv will asynchronously report end of playback.
7676
* there are situations when we need to see the end-event before

0 commit comments

Comments
 (0)