File indexing completed on 2025-01-19 04:46:45
0001 /* 0002 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-only 0005 */ 0006 0007 #include "mailmergewidget.h" 0008 #include "../widgets/addressbookwidget.h" 0009 #include "../widgets/csvwidget.h" 0010 0011 #include "attachmentlistwidget.h" 0012 0013 #include <KLocalizedString> 0014 #include <QComboBox> 0015 0016 #include <QHBoxLayout> 0017 #include <QLabel> 0018 #include <QStackedWidget> 0019 #include <QVBoxLayout> 0020 0021 using namespace MailMerge; 0022 0023 MailMergeWidget::MailMergeWidget(QWidget *parent) 0024 : QWidget(parent) 0025 , mSource(new QComboBox(this)) 0026 , mStackedWidget(new QStackedWidget(this)) 0027 , mCsvWidget(new MailMerge::CsvWidget(this)) 0028 , mAddressbookWidget(new MailMerge::AddressBookWidget(this)) 0029 { 0030 auto mainLayout = new QVBoxLayout(this); 0031 mainLayout->setObjectName(QLatin1StringView("mainLayout")); 0032 0033 auto hbox = new QHBoxLayout; 0034 mainLayout->addLayout(hbox); 0035 0036 auto lab = new QLabel(i18n("Source:"), this); 0037 lab->setObjectName(QLatin1StringView("lab")); 0038 hbox->addWidget(lab); 0039 0040 mSource->setObjectName(QLatin1StringView("source")); 0041 mSource->addItem(i18n("Address Book"), AddressBook); 0042 mSource->addItem(i18n("CSV"), CSV); 0043 connect(mSource, &QComboBox::currentIndexChanged, this, &MailMergeWidget::slotSourceChanged); 0044 connect(mSource, &QComboBox::activated, this, &MailMergeWidget::slotSourceChanged); 0045 0046 hbox->addWidget(mSource); 0047 0048 mStackedWidget->setObjectName(QLatin1StringView("stackedwidget")); 0049 mainLayout->addWidget(mStackedWidget); 0050 0051 mAddressbookWidget->setObjectName(QLatin1StringView("addressbookwidget")); 0052 mStackedWidget->addWidget(mAddressbookWidget); 0053 0054 mCsvWidget->setObjectName(QLatin1StringView("csvwidget")); 0055 0056 mStackedWidget->addWidget(mCsvWidget); 0057 0058 lab = new QLabel(i18n("Attachment:"), this); 0059 mainLayout->addWidget(lab); 0060 0061 auto buttonCode = static_cast<PimCommon::SimpleStringListEditor::ButtonCode>( 0062 PimCommon::SimpleStringListEditor::Add | PimCommon::SimpleStringListEditor::Remove | PimCommon::SimpleStringListEditor::Modify); 0063 mAttachment = new AttachmentListWidget(this, buttonCode, i18n("A&dd..."), i18n("Re&move"), i18n("Mod&ify...")); 0064 mAttachment->setObjectName(QLatin1StringView("attachment-list")); 0065 0066 mainLayout->addWidget(mAttachment); 0067 mainLayout->addStretch(); 0068 } 0069 0070 MailMergeWidget::~MailMergeWidget() = default; 0071 0072 void MailMergeWidget::slotSourceChanged(int index) 0073 { 0074 if (index != -1) { 0075 Q_EMIT sourceModeChanged(static_cast<SourceType>(mSource->itemData(index).toInt())); 0076 mStackedWidget->setCurrentIndex(index); 0077 } 0078 } 0079 0080 #include "moc_mailmergewidget.cpp"