File indexing completed on 2025-01-05 04:49:34

0001 /*
0002   SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-only
0005 */
0006 
0007 #include "selectattachmentdialog.h"
0008 #include <KLocalizedString>
0009 #include <KUrlRequester>
0010 #include <QDialogButtonBox>
0011 #include <QLabel>
0012 #include <QVBoxLayout>
0013 using namespace MailMerge;
0014 
0015 SelectAttachmentDialog::SelectAttachmentDialog(QWidget *parent)
0016     : QDialog(parent)
0017     , mUrlRequester(new KUrlRequester(this))
0018 {
0019     setWindowTitle(i18nc("@title:window", "Attachment"));
0020     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
0021     auto mainLayout = new QVBoxLayout(this);
0022     QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0023     okButton->setDefault(true);
0024     okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0025     connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
0026     connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
0027 
0028     auto w = new QWidget;
0029     auto vbox = new QVBoxLayout(w);
0030     vbox->setContentsMargins({});
0031     auto lab = new QLabel(i18n("Select attachment:"), this);
0032     lab->setObjectName(QLatin1StringView("selectattachment_label"));
0033     vbox->addWidget(lab);
0034     mUrlRequester->setMode(KFile::LocalOnly | KFile::ExistingOnly);
0035     mUrlRequester->setObjectName(QLatin1StringView("urlrequester"));
0036     vbox->addWidget(mUrlRequester);
0037     mainLayout->addWidget(w);
0038     mainLayout->addWidget(buttonBox);
0039 }
0040 
0041 SelectAttachmentDialog::~SelectAttachmentDialog() = default;
0042 
0043 void SelectAttachmentDialog::setAttachmentPath(const QUrl &path)
0044 {
0045     mUrlRequester->setUrl(path);
0046 }
0047 
0048 QString SelectAttachmentDialog::attachmentPath() const
0049 {
0050     return mUrlRequester->url().path();
0051 }
0052 
0053 #include "moc_selectattachmentdialog.cpp"