Commit d180c984 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix possible crash on .ass subtutle error and dropping subtitle in timeline

parent 05fda675
......@@ -200,7 +200,9 @@ void SubtitleModel::importSubtitle(const QString filePath, int offset, bool exte
styleSection +=line + "\n";
//Style: Name,Fontname,Fontsize,PrimaryColour,SecondaryColour,OutlineColour,BackColour,Bold,Italic,Underline,StrikeOut,ScaleX,ScaleY,Spacing,Angle,BorderStyle,Outline,Shadow,Alignment,MarginL,MarginR,MarginV,Encoding
styleFormat = (line.split(": ")[1].replace(" ","")).split(',');
styleName = styleFormat[0];
if (!styleFormat.isEmpty()) {
styleName = styleFormat.first();
}
}
//qDebug() << "\n turn != 0 " << turn<< line;
......@@ -214,10 +216,13 @@ void SubtitleModel::importSubtitle(const QString filePath, int offset, bool exte
//qDebug() << format << format.count();
maxSplit = format.count();
//TIME
startTime = format[1];
endTime = format[2];
if (maxSplit > 2)
startTime = format.at(1);
if (maxSplit > 3)
endTime = format.at(2);
// Text
text = format[9];
if (maxSplit > 9)
text = format.at(9);
//qDebug()<< startTime << endTime << text;
} else {
QString EventDialogue;
......@@ -225,17 +230,19 @@ void SubtitleModel::importSubtitle(const QString filePath, int offset, bool exte
start = "";end = "";comment = "";
EventDialogue += line;
dialogue = EventDialogue.split(": ")[1].split(',');
QString remainingStr = "," + EventDialogue.split(": ")[1].section(',', maxSplit);
//qDebug()<< dialogue;
//TIME
start = dialogue[1];
startPos= stringtoTime(start);
end = dialogue[2];
endPos= stringtoTime(end);
// Text
comment = dialogue[9]+ remainingStr;
//qDebug()<<"Start: "<< start << "End: "<<end << comment;
addSubtitle(startPos + subtitleOffset, endPos + subtitleOffset, comment, undo, redo, false);
if (dialogue.count() > 9) {
QString remainingStr = "," + EventDialogue.split(": ")[1].section(',', maxSplit);
//qDebug()<< dialogue;
//TIME
start = dialogue.at(1);
startPos= stringtoTime(start);
end = dialogue.at(2);
endPos= stringtoTime(end);
// Text
comment = dialogue.at(9)+ remainingStr;
//qDebug()<<"Start: "<< start << "End: "<<end << comment;
addSubtitle(startPos + subtitleOffset, endPos + subtitleOffset, comment, undo, redo, false);
}
}
}
turn++;
......
......@@ -3555,7 +3555,12 @@ void TimelineController::urlDropped(QStringList droppedFile, int frame, int tid)
m_recordTrack = tid;
m_recordStart = {frame, -1};
qDebug()<<"=== GOT DROPPED FILED: "<<droppedFile<<"\n======";
finishRecording(QUrl(droppedFile.first()).toLocalFile());
if (droppedFile.first().endsWith(QLatin1String(".ass")) || droppedFile.first().endsWith(QLatin1String(".srt"))) {
// Subtitle dropped, import
importSubtitle(droppedFile.first());
} else {
finishRecording(QUrl(droppedFile.first()).toLocalFile());
}
}
void TimelineController::finishRecording(const QString &recordedFile)
......@@ -3860,14 +3865,17 @@ void TimelineController::addSubtitle(int startframe)
}
}
void TimelineController::importSubtitle()
void TimelineController::importSubtitle(const QString path)
{
QPointer<QDialog> d = new QDialog;
Ui::ImportSub_UI view;
view.setupUi(d);
if (!path.isEmpty()) {
view.subtitle_url->setText(path);
}
d->setWindowTitle(i18n("Import Subtitle"));
if (d->exec() == QDialog::Accepted && !view.subtitle_url->url().isEmpty()) {
auto subtitleModel = pCore->getSubtitleModel();
auto subtitleModel = pCore->getSubtitleModel(true);
int offset = 0;
if (view.cursor_pos->isChecked()) {
offset = pCore->getTimelinePosition();
......
......@@ -577,7 +577,7 @@ public:
/** @brief Delete subtitle clip with frame as start position*/
Q_INVOKABLE void deleteSubtitle(int frameframe, int endframe, QString Ctext);
/** @brief Import a subtitle file*/
void importSubtitle();
void importSubtitle(const QString path = QString());
/** @brief Export a subtitle file*/
void exportSubtitle();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment