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

Fix crash after closing auto subtitles dialog, add config button to speech...

Fix crash after closing auto subtitles dialog, add config button to speech widgets opening the config page
parent 203824f4
Pipeline #50328 canceled with stage
......@@ -22,6 +22,7 @@
#include "core.h"
#include "kdenlivesettings.h"
#include "monitor/monitor.h"
#include "mainwindow.h"
#include "bin/model/subtitlemodel.hpp"
#include "kdenlive_debug.h"
......@@ -43,8 +44,13 @@ SpeechDialog::SpeechDialog(const std::shared_ptr<TimelineItemModel> &timeline, Q
setupUi(this);
buttonBox->button(QDialogButtonBox::Apply)->setText(i18n("Process"));
speech_info->hide();
connect(pCore.get(), &Core::updateVoskAvailability, this, &SpeechDialog::updateAvailability);
connect(pCore.get(), &Core::voskModelUpdate, [&](QStringList models) {
vosk_config->setIcon(QIcon::fromTheme(QStringLiteral("configure")));
vosk_config->setToolTip(i18n("Configure speech recognition"));
connect(vosk_config, &QToolButton::clicked, [this]() {
pCore->window()->slotPreferences(8);
});
m_availableConnection = connect(pCore.get(), &Core::updateVoskAvailability, this, &SpeechDialog::updateAvailability);
m_modelsConnection = connect(pCore.get(), &Core::voskModelUpdate, [&](QStringList models) {
language_box->clear();
language_box->addItems(models);
updateAvailability();
......@@ -52,7 +58,11 @@ SpeechDialog::SpeechDialog(const std::shared_ptr<TimelineItemModel> &timeline, Q
speech_info->setMessageType(KMessageWidget::Information);
speech_info->setText(i18n("Please install speech recognition models"));
speech_info->animatedShow();
vosk_config->setVisible(true);
} else {
if (KdenliveSettings::vosk_found() && KdenliveSettings::vosk_srt_found()) {
vosk_config->setVisible(false);
}
if (!KdenliveSettings::vosk_srt_model().isEmpty() && models.contains(KdenliveSettings::vosk_srt_model())) {
int ix = language_box->findText(KdenliveSettings::vosk_srt_model());
if (ix > -1) {
......@@ -70,9 +80,17 @@ SpeechDialog::SpeechDialog(const std::shared_ptr<TimelineItemModel> &timeline, Q
parseVoskDictionaries();
}
SpeechDialog::~SpeechDialog()
{
QObject::disconnect(m_availableConnection);
QObject::disconnect(m_modelsConnection);
}
void SpeechDialog::updateAvailability()
{
buttonBox->button(QDialogButtonBox::Apply)->setEnabled(KdenliveSettings::vosk_found() && KdenliveSettings::vosk_srt_found() && language_box->count() > 0);
bool enabled = KdenliveSettings::vosk_found() && KdenliveSettings::vosk_srt_found() && language_box->count() > 0;
buttonBox->button(QDialogButtonBox::Apply)->setEnabled(enabled);
vosk_config->setVisible(!enabled);
}
void SpeechDialog::slotProcessSpeech(const std::shared_ptr<TimelineItemModel> &timeline, QPoint zone)
......
......@@ -36,8 +36,11 @@ class SpeechDialog : public QDialog, public Ui::SpeechDialog_UI
public:
explicit SpeechDialog(const std::shared_ptr<TimelineItemModel> &timeline, QPoint zone, bool activeTrackOnly = false, bool selectionOnly = false, QWidget *parent = nullptr);
~SpeechDialog() override;
private:
QMetaObject::Connection m_availableConnection;
QMetaObject::Connection m_modelsConnection;
void parseVoskDictionaries();
private slots:
......
......@@ -25,6 +25,7 @@
#include "bin/projectclip.h"
#include "bin/projectitemmodel.h"
#include "core.h"
#include "mainwindow.h"
#include "kdenlivesettings.h"
#include "timecodedisplay.h"
......@@ -45,6 +46,11 @@ TextBasedEdit::TextBasedEdit(QWidget *parent)
m_speechJob->kill();
}
});
vosk_config->setIcon(QIcon::fromTheme(QStringLiteral("configure")));
vosk_config->setToolTip(i18n("Configure speech recognition"));
connect(vosk_config, &QToolButton::clicked, [this]() {
pCore->window()->slotPreferences(8);
});
connect(button_start, &QPushButton::clicked, this, &TextBasedEdit::startRecognition);
listWidget->setWordWrap(true);
search_frame->setVisible(false);
......@@ -57,7 +63,11 @@ TextBasedEdit::TextBasedEdit(QWidget *parent)
info_message->setMessageType(KMessageWidget::Information);
info_message->setText(i18n("Please install speech recognition models"));
info_message->animatedShow();
vosk_config->setVisible(true);
} else {
if (KdenliveSettings::vosk_found()) {
vosk_config->setVisible(false);
}
if (!KdenliveSettings::vosk_text_model().isEmpty() && models.contains(KdenliveSettings::vosk_text_model())) {
int ix = language_box->findText(KdenliveSettings::vosk_text_model());
if (ix > -1) {
......@@ -160,7 +170,9 @@ void TextBasedEdit::startRecognition()
void TextBasedEdit::updateAvailability()
{
button_start->setEnabled(KdenliveSettings::vosk_found() && language_box->count() > 0);
bool enabled = KdenliveSettings::vosk_found() && language_box->count() > 0;
button_start->setEnabled(enabled);
vosk_config->setVisible(!enabled);
}
void TextBasedEdit::slotProcessSpeechStatus(int, QProcess::ExitStatus status)
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>248</width>
<height>244</height>
<width>318</width>
<height>283</height>
</rect>
</property>
<property name="windowTitle">
......@@ -48,6 +48,13 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QRadioButton" name="timeline_clips">
<property name="text">
<string>Selected clips</string>
</property>
</widget>
</item>
<item row="4" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
......@@ -61,7 +68,10 @@
</property>
</spacer>
</item>
<item row="6" column="0" colspan="2">
<item row="5" column="0" colspan="2">
<widget class="KMessageWidget" name="speech_info"/>
</item>
<item row="6" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
......@@ -71,13 +81,10 @@
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="KMessageWidget" name="speech_info"/>
</item>
<item row="3" column="0" colspan="2">
<widget class="QRadioButton" name="timeline_clips">
<item row="6" column="0">
<widget class="QToolButton" name="vosk_config">
<property name="text">
<string>Selected clips</string>
<string>...</string>
</property>
</widget>
</item>
......
......@@ -19,7 +19,7 @@
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QToolButton" name="button_delete">
<property name="text">
......@@ -54,6 +54,13 @@
</property>
</spacer>
</item>
<item row="0" column="4">
<widget class="QToolButton" name="vosk_config">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
......
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