Messagelib

attachmentdialog.cpp
1/*
2This file is part of KMail, the KDE mail client.
3SPDX-FileCopyrightText: 2009 Martin Koller <kollix@aon.at>
4
5SPDX-License-Identifier: GPL-2.0-or-later
6*/
7
8#include "attachmentdialog.h"
9
10#include <KConfigGroup>
11#include <KGuiItem>
12#include <KLocalizedString>
13#include <KMessageBox>
14#include <KSharedConfig>
15#include <QDialog>
16#include <QDialogButtonBox>
17#include <QPushButton>
18using namespace MessageViewer;
19
20//---------------------------------------------------------------------
21
22AttachmentDialog::AttachmentDialog(QWidget *parent, const QString &filenameText, const KService::Ptr &offer, const QString &dontAskAgainName)
23 : dontAskName(dontAskAgainName)
24 , dialog(new QDialog(parent))
25{
26 text = xi18nc("@info",
27 "Open attachment <filename>%1</filename>?<nl/>"
28 "Note that opening an attachment may compromise "
29 "your system's security.",
30 filenameText);
31
32 dialog->setWindowTitle(i18nc("@title:window", "Open Attachment?"));
33 dialog->setObjectName(QLatin1StringView("attachmentSaveOpen"));
34 mButtonBox = new QDialogButtonBox(QDialogButtonBox::Cancel, dialog);
35
36 if (offer) {
37 auto user1Button = new QPushButton;
38 mButtonBox->addButton(user1Button, QDialogButtonBox::ActionRole);
39 user1Button->setText(i18n("&Open With '%1'", offer->name()));
40 user1Button->setIcon(QIcon::fromTheme(offer->icon()));
41 connect(user1Button, &QPushButton::clicked, this, &AttachmentDialog::openClicked);
42 }
43
44 auto user2Button = new QPushButton;
45 mButtonBox->addButton(user2Button, QDialogButtonBox::ActionRole);
46 user2Button->setText(i18n("Open &With..."));
47 user2Button->setIcon(QIcon::fromTheme(QStringLiteral("document-open")));
48 connect(user2Button, &QPushButton::clicked, this, &AttachmentDialog::openWithClicked);
49
50 auto user3Button = new QPushButton;
51 mButtonBox->addButton(user3Button, QDialogButtonBox::ActionRole);
53 user3Button->setDefault(true);
54 connect(user3Button, &QPushButton::clicked, this, &AttachmentDialog::saveClicked);
55}
56
57//---------------------------------------------------------------------
58
59int AttachmentDialog::exec()
60{
61 KConfigGroup cg(KSharedConfig::openConfig().data(), QStringLiteral("Notification Messages"));
62 if (cg.hasKey(dontAskName)) {
63 return cg.readEntry(dontAskName, 0);
64 }
65
66 bool again = false;
68 KMessageBox::createKMessageBox(dialog, mButtonBox, QMessageBox::Question, text, QStringList(), i18n("Do not ask again"), &again, KMessageBox::Option());
69
70 if (ret == QDialogButtonBox::Cancel) {
71 return Cancel;
72 } else {
73 if (again) {
75 KConfigGroup configGroup(KSharedConfig::openConfig().data(), QStringLiteral("Notification Messages"));
76 configGroup.writeEntry(dontAskName, static_cast<int>(ret), flags);
77 configGroup.sync();
78 }
79 return ret;
80 }
81}
82
83//---------------------------------------------------------------------
84
85void AttachmentDialog::saveClicked()
86{
87 dialog->done(Save);
88}
89
90//---------------------------------------------------------------------
91
92void AttachmentDialog::openClicked()
93{
94 dialog->done(Open);
95}
96
97//---------------------------------------------------------------------
98
99void AttachmentDialog::openWithClicked()
100{
101 dialog->done(OpenWith);
102}
103
104//---------------------------------------------------------------------
105
106#include "moc_attachmentdialog.cpp"
static void assign(QPushButton *button, const KGuiItem &item)
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
QString xi18nc(const char *context, const char *text, const TYPE &arg...)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
QDialogButtonBox::StandardButton createKMessageBox(QDialog *dialog, QDialogButtonBox *buttons, const QIcon &icon, const QString &text, const QStringList &strlist, const QString &ask, bool *checkboxReturn, Options options, const QString &details=QString(), QMessageBox::Icon notifyType=QMessageBox::Information)
KGuiItem saveAs()
void clicked(bool checked)
void setText(const QString &text)
virtual void done(int r)
QIcon fromTheme(const QString &name)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.