File indexing completed on 2025-01-19 04:46:44

0001 /*
0002    SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "akonadidatabasetoolsdialog.h"
0008 #include "akonadidatabasetoolswidget.h"
0009 #include <KConfigGroup>
0010 #include <KLocalizedString>
0011 #include <KSharedConfig>
0012 #include <KWindowConfig>
0013 #include <QDialogButtonBox>
0014 #include <QVBoxLayout>
0015 #include <QWindow>
0016 namespace
0017 {
0018 static const char myConfigGroupName[] = "AkonadiDatabaseToolsDialog";
0019 }
0020 
0021 AkonadiDatabaseToolsDialog::AkonadiDatabaseToolsDialog(QWidget *parent)
0022     : QDialog(parent)
0023     , mAkonadiDatabaseToolsWidget(new AkonadiDatabaseToolsWidget(this))
0024 {
0025     setAttribute(Qt::WA_DeleteOnClose);
0026     setWindowTitle(i18nc("@title:window", "Akonadi Database Tool"));
0027     auto mainLayout = new QVBoxLayout(this);
0028     mainLayout->setObjectName(QLatin1StringView("mainLayout"));
0029 
0030     mAkonadiDatabaseToolsWidget->setObjectName(QLatin1StringView("mAkonadiDatabaseToolsWidget"));
0031     mainLayout->addWidget(mAkonadiDatabaseToolsWidget);
0032 
0033     auto box = new QDialogButtonBox(QDialogButtonBox::Close, this);
0034     box->setObjectName(QLatin1StringView("box"));
0035     mainLayout->addWidget(box);
0036     connect(box, &QDialogButtonBox::accepted, this, &AkonadiDatabaseToolsDialog::accept);
0037     connect(box, &QDialogButtonBox::rejected, this, &AkonadiDatabaseToolsDialog::reject);
0038     readConfig();
0039 }
0040 
0041 AkonadiDatabaseToolsDialog::~AkonadiDatabaseToolsDialog()
0042 {
0043     writeConfig();
0044 }
0045 
0046 void AkonadiDatabaseToolsDialog::appendText(const QString &text)
0047 {
0048     mAkonadiDatabaseToolsWidget->appendText(text);
0049 }
0050 
0051 void AkonadiDatabaseToolsDialog::appendErrorText(const QString &text)
0052 {
0053     mAkonadiDatabaseToolsWidget->appendText(QStringLiteral("<font color=#FF0000>%1</font>").arg(text));
0054 }
0055 
0056 void AkonadiDatabaseToolsDialog::writeConfig()
0057 {
0058     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myConfigGroupName));
0059     KWindowConfig::saveWindowSize(windowHandle(), group);
0060 }
0061 
0062 void AkonadiDatabaseToolsDialog::readConfig()
0063 {
0064     create(); // ensure a window is created
0065     windowHandle()->resize(QSize(500, 300));
0066     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myConfigGroupName));
0067     KWindowConfig::restoreWindowSize(windowHandle(), group);
0068     resize(windowHandle()->size()); // workaround for QTBUG-40584
0069 }
0070 
0071 #include "moc_akonadidatabasetoolsdialog.cpp"