File indexing completed on 2024-12-22 04:28:22

0001 /*
0002   SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "voskenginedialog.h"
0008 #include "voskenginelanguagewidget.h"
0009 #include <KConfigGroup>
0010 #include <KLocalizedString>
0011 #include <KSharedConfig>
0012 #include <KWindowConfig>
0013 #include <QDialogButtonBox>
0014 #include <QVBoxLayout>
0015 #include <QWindow>
0016 
0017 namespace
0018 {
0019 static const char myConfigGroupName[] = "VoskEngineDialog";
0020 }
0021 
0022 VoskEngineDialog::VoskEngineDialog(QWidget *parent)
0023     : QDialog(parent)
0024     , mVoskEngineWidget(new VoskEngineLanguageWidget(this))
0025 {
0026     setWindowTitle(i18nc("@title:window", "Vosk Plugin Settings"));
0027     auto mainLayout = new QVBoxLayout(this);
0028     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0029 
0030     mVoskEngineWidget->setObjectName(QStringLiteral("mVoskEngineWidget"));
0031     mainLayout->addWidget(mVoskEngineWidget);
0032 
0033     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
0034     buttonBox->setObjectName(QStringLiteral("buttonBox"));
0035     mainLayout->addWidget(buttonBox);
0036     connect(buttonBox, &QDialogButtonBox::accepted, this, &VoskEngineDialog::accept);
0037     connect(buttonBox, &QDialogButtonBox::rejected, this, &VoskEngineDialog::reject);
0038     readConfig();
0039 }
0040 
0041 VoskEngineDialog::~VoskEngineDialog()
0042 {
0043     writeConfig();
0044 }
0045 
0046 void VoskEngineDialog::writeConfig()
0047 {
0048     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myConfigGroupName));
0049     KWindowConfig::saveWindowSize(windowHandle(), group);
0050 }
0051 
0052 void VoskEngineDialog::readConfig()
0053 {
0054     create(); // ensure a window is created
0055     windowHandle()->resize(QSize(500, 300));
0056     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myConfigGroupName));
0057     KWindowConfig::restoreWindowSize(windowHandle(), group);
0058     resize(windowHandle()->size()); // workaround for QTBUG-40584
0059 }
0060 
0061 #include "moc_voskenginedialog.cpp"