selectattachmentdialog.cpp 1.67 KB
Newer Older
1
/*
Laurent Montel's avatar
Laurent Montel committed
2
  SPDX-FileCopyrightText: 2015-2021 Laurent Montel <montel@kde.org>
3

4
  SPDX-License-Identifier: GPL-2.0-only
5 6 7 8 9
*/

#include "selectattachmentdialog.h"
#include <KLocalizedString>
#include <QDialogButtonBox>
Laurent Montel's avatar
Laurent Montel committed
10
#include <QLabel>
Laurent Montel's avatar
Laurent Montel committed
11
#include <QVBoxLayout>
Laurent Montel's avatar
Laurent Montel committed
12
#include <kurlrequester.h>
13 14 15 16 17
using namespace MailMerge;

SelectAttachmentDialog::SelectAttachmentDialog(QWidget *parent)
    : QDialog(parent)
{
18
    setWindowTitle(i18nc("@title:window", "Attachment"));
Laurent Montel's avatar
Laurent Montel committed
19
    QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
Laurent Montel's avatar
Laurent Montel committed
20
    auto mainLayout = new QVBoxLayout(this);
21 22 23 24 25 26
    QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
    okButton->setDefault(true);
    okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
    connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
    connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);

Laurent Montel's avatar
Laurent Montel committed
27
    auto w = new QWidget;
Laurent Montel's avatar
Laurent Montel committed
28 29
    auto vbox = new QVBoxLayout(w);
    vbox->setContentsMargins({});
Laurent Montel's avatar
Laurent Montel committed
30
    auto lab = new QLabel(i18n("Select attachment:"), this);
31 32
    lab->setObjectName(QStringLiteral("selectattachment_label"));
    vbox->addWidget(lab);
Laurent Montel's avatar
Laurent Montel committed
33
    mUrlRequester = new KUrlRequester(this);
34 35 36 37 38 39 40 41 42 43 44
    mUrlRequester->setMode(KFile::LocalOnly | KFile::ExistingOnly);
    mUrlRequester->setObjectName(QStringLiteral("urlrequester"));
    vbox->addWidget(mUrlRequester);
    mainLayout->addWidget(w);
    mainLayout->addWidget(buttonBox);
}

SelectAttachmentDialog::~SelectAttachmentDialog()
{
}

Laurent Montel's avatar
Laurent Montel committed
45
void SelectAttachmentDialog::setAttachmentPath(const QUrl &path)
46 47 48 49 50 51 52 53
{
    mUrlRequester->setUrl(path);
}

QString SelectAttachmentDialog::attachmentPath() const
{
    return mUrlRequester->url().path();
}