File indexing completed on 2024-12-22 05:02:29

0001 /*
0002    SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "gravatarconfiguresettingsdialog.h"
0008 #include "gravatarconfiguresettingswidget.h"
0009 #include "misc/gravatarcache.h"
0010 
0011 #include "gravatarsettings.h"
0012 #include <KLocalizedString>
0013 #include <QDialogButtonBox>
0014 #include <QPushButton>
0015 #include <QVBoxLayout>
0016 using namespace Gravatar;
0017 
0018 GravatarConfigureSettingsDialog::GravatarConfigureSettingsDialog(QWidget *parent)
0019     : QDialog(parent)
0020 {
0021     setWindowTitle(i18nc("@title:window", "Configure Gravatar"));
0022     auto topLayout = new QVBoxLayout(this);
0023     topLayout->setObjectName(QLatin1StringView("toplayout"));
0024 
0025     mGravatarConfigureSettings = new GravatarConfigureSettingsWidget(this);
0026     mGravatarConfigureSettings->setObjectName(QLatin1StringView("gravatarconfiguresettings"));
0027     topLayout->addWidget(mGravatarConfigureSettings);
0028 
0029     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::RestoreDefaults, this);
0030     buttonBox->setObjectName(QLatin1StringView("buttonbox"));
0031     QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0032     okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0033     connect(buttonBox, &QDialogButtonBox::accepted, this, &GravatarConfigureSettingsDialog::save);
0034     connect(buttonBox, &QDialogButtonBox::rejected, this, &GravatarConfigureSettingsDialog::reject);
0035     connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, this, &GravatarConfigureSettingsDialog::slotRestoreDefault);
0036     okButton->setDefault(true);
0037 
0038     topLayout->addWidget(buttonBox);
0039     load();
0040 }
0041 
0042 GravatarConfigureSettingsDialog::~GravatarConfigureSettingsDialog() = default;
0043 
0044 void GravatarConfigureSettingsDialog::slotRestoreDefault()
0045 {
0046     mGravatarConfigureSettings->load();
0047 }
0048 
0049 void GravatarConfigureSettingsDialog::save()
0050 {
0051     mGravatarConfigureSettings->save();
0052     accept();
0053 }
0054 
0055 void GravatarConfigureSettingsDialog::load()
0056 {
0057     mGravatarConfigureSettings->load();
0058 }
0059 
0060 #include "moc_gravatarconfiguresettingsdialog.cpp"