Messagelib

attachmentdialog.cpp
1 /*
2 This file is part of KMail, the KDE mail client.
3 SPDX-FileCopyrightText: 2009 Martin Koller <[email protected]>
4 
5 SPDX-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>
18 using namespace MessageViewer;
19 
20 //---------------------------------------------------------------------
21 
22 AttachmentDialog::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(QStringLiteral("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 
59 int AttachmentDialog::exec()
60 {
61  KConfigGroup cg(KSharedConfig::openConfig().data(), "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(), "Notification Messages");
76  configGroup.writeEntry(dontAskName, static_cast<int>(ret), flags);
77  configGroup.sync();
78  }
79  return ret;
80  }
81 }
82 
83 //---------------------------------------------------------------------
84 
85 void AttachmentDialog::saveClicked()
86 {
87  dialog->done(Save);
88 }
89 
90 //---------------------------------------------------------------------
91 
92 void AttachmentDialog::openClicked()
93 {
94  dialog->done(Open);
95 }
96 
97 //---------------------------------------------------------------------
98 
99 void AttachmentDialog::openWithClicked()
100 {
101  dialog->done(OpenWith);
102 }
103 
104 //---------------------------------------------------------------------
QString xi18nc(const char *context, const char *text, const TYPE &arg...)
KGuiItem saveAs()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void clicked(bool checked)
static void assign(QPushButton *button, const KGuiItem &item)
QDialogButtonBox::StandardButton createKMessageBox(QDialog *dialog, QDialogButtonBox *buttons, QMessageBox::Icon icon, const QString &text, const QStringList &strlist, const QString &ask, bool *checkboxReturn, Options options, const QString &details=QString())
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
QString i18n(const char *text, const TYPE &arg...)
void setText(const QString &text)
QIcon fromTheme(const QString &name)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Dec 5 2021 23:04:52 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.