File indexing completed on 2024-12-22 05:00:50

0001 /*
0002    SPDX-FileCopyrightText: 2012-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "addarchivemaildialog.h"
0008 
0009 #include "addarchivemailwidget.h"
0010 #include <KLocalizedString>
0011 #include <KSeparator>
0012 #include <QDialogButtonBox>
0013 #include <QPushButton>
0014 #include <QVBoxLayout>
0015 
0016 AddArchiveMailDialog::AddArchiveMailDialog(ArchiveMailInfo *info, QWidget *parent)
0017     : QDialog(parent)
0018     , mAddArchiveMailWidget(new AddArchiveMailWidget(info, this))
0019 {
0020     if (info) {
0021         setWindowTitle(i18nc("@title:window", "Modify Archive Mail"));
0022     } else {
0023         setWindowTitle(i18nc("@title:window", "Add Archive Mail"));
0024     }
0025     setModal(true);
0026     setWindowIcon(QIcon::fromTheme(QStringLiteral("kmail")));
0027 
0028     auto topLayout = new QVBoxLayout(this);
0029     topLayout->setObjectName(QStringLiteral("topLayout"));
0030 
0031     mAddArchiveMailWidget->setObjectName(QStringLiteral("mAddArchiveMailWidget"));
0032     topLayout->addWidget(mAddArchiveMailWidget);
0033     connect(mAddArchiveMailWidget, &AddArchiveMailWidget::enableOkButton, this, [this](bool state) {
0034         mOkButton->setEnabled(state);
0035     });
0036 
0037     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
0038     mOkButton = buttonBox->button(QDialogButtonBox::Ok);
0039     mOkButton->setDefault(true);
0040     mOkButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0041     connect(buttonBox, &QDialogButtonBox::accepted, this, &AddArchiveMailDialog::accept);
0042     connect(buttonBox, &QDialogButtonBox::rejected, this, &AddArchiveMailDialog::reject);
0043 
0044     if (!info) {
0045         mOkButton->setEnabled(false);
0046     }
0047     topLayout->addWidget(new KSeparator);
0048     topLayout->addWidget(buttonBox);
0049 
0050     // Make it a bit bigger, else the folder requester cuts off the text too early
0051     resize(500, minimumSize().height());
0052 }
0053 
0054 AddArchiveMailDialog::~AddArchiveMailDialog() = default;
0055 
0056 ArchiveMailInfo *AddArchiveMailDialog::info()
0057 {
0058     return mAddArchiveMailWidget->info();
0059 }
0060 
0061 #include "moc_addarchivemaildialog.cpp"