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

0001 /*
0002    SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "mailmergeconfiguredialog.h"
0008 #include "kmail-version.h"
0009 #include "mailmergeconfigurewidget.h"
0010 #include <KAboutData>
0011 #include <KConfigGroup>
0012 #include <KHelpMenu>
0013 #include <KLocalizedString>
0014 #include <KSharedConfig>
0015 #include <KWindowConfig>
0016 #include <QApplication>
0017 #include <QDialogButtonBox>
0018 #include <QIcon>
0019 #include <QMenu>
0020 #include <QPushButton>
0021 #include <QVBoxLayout>
0022 #include <QWindow>
0023 
0024 namespace
0025 {
0026 static const char myConfigureMailMergeConfigureDialogGroupName[] = "MailMergeConfigureDialog";
0027 }
0028 
0029 MailMergeConfigureDialog::MailMergeConfigureDialog(QWidget *parent)
0030     : QDialog(parent)
0031     , mWidget(new MailMergeConfigureWidget(this))
0032 {
0033     setWindowTitle(i18nc("@title:window", "Configure"));
0034     setWindowIcon(QIcon::fromTheme(QStringLiteral("kmail")));
0035     auto mainLayout = new QVBoxLayout(this);
0036     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help, this);
0037     QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0038     okButton->setDefault(true);
0039     okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0040     connect(buttonBox, &QDialogButtonBox::rejected, this, &MailMergeConfigureDialog::reject);
0041 
0042     mWidget->setObjectName(QLatin1StringView("mailmergewidget"));
0043     mainLayout->addWidget(mWidget);
0044     mainLayout->addWidget(buttonBox);
0045     connect(okButton, &QPushButton::clicked, this, &MailMergeConfigureDialog::slotSave);
0046 
0047     readConfig();
0048 
0049     KAboutData aboutData = KAboutData(QStringLiteral("mailmergeagent"),
0050                                       i18n("Mail Merge Agent"),
0051                                       QStringLiteral(KDEPIM_VERSION),
0052                                       i18n("Merge email addresses agent."),
0053                                       KAboutLicense::GPL_V2,
0054                                       i18n("Copyright (C) 2021-%1 Laurent Montel", QStringLiteral("2023")));
0055 
0056     aboutData.addAuthor(i18n("Laurent Montel"), i18n("Maintainer"), QStringLiteral("montel@kde.org"));
0057     aboutData.setProductName(QByteArrayLiteral("Akonadi/MailMergeAgent"));
0058     QApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("kmail")));
0059     aboutData.setTranslator(i18nc("NAME OF TRANSLATORS", "Your names"), i18nc("EMAIL OF TRANSLATORS", "Your emails"));
0060 
0061     auto helpMenu = new KHelpMenu(this, aboutData, true);
0062     // Initialize menu
0063     QMenu *menu = helpMenu->menu();
0064     helpMenu->action(KHelpMenu::menuAboutApp)->setIcon(QIcon::fromTheme(QStringLiteral("kmail")));
0065     buttonBox->button(QDialogButtonBox::Help)->setMenu(menu);
0066 }
0067 
0068 MailMergeConfigureDialog::~MailMergeConfigureDialog()
0069 {
0070     writeConfig();
0071 }
0072 
0073 void MailMergeConfigureDialog::slotSave()
0074 {
0075     // TODO
0076 }
0077 
0078 void MailMergeConfigureDialog::readConfig()
0079 {
0080     create(); // ensure a window is created
0081     windowHandle()->resize(QSize(800, 600));
0082     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myConfigureMailMergeConfigureDialogGroupName));
0083     KWindowConfig::restoreWindowSize(windowHandle(), group);
0084     resize(windowHandle()->size()); // workaround for QTBUG-40584
0085 }
0086 
0087 void MailMergeConfigureDialog::writeConfig()
0088 {
0089     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myConfigureMailMergeConfigureDialogGroupName));
0090     KWindowConfig::saveWindowSize(windowHandle(), group);
0091     group.sync();
0092 }
0093 
0094 #include "moc_mailmergeconfiguredialog.cpp"