• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • pim API Reference
  • KDE Home
  • Contact Us
 

libkleo

  • kde-4.x
  • pim
  • libkleo
  • src
  • ui
messagebox.cpp
Go to the documentation of this file.
1 /*
2  messagebox.cpp
3 
4  This file is part of libkleopatra, the KDE keymanagement library
5  Copyright (c) 2004 Klarälvdalens Datakonsult AB
6 
7  Libkleopatra is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of the
10  License, or (at your option) any later version.
11 
12  Libkleopatra is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #include "messagebox.h"
34 #include "auditlogviewer.h"
35 
36 #include "kleo_ui_debug.h"
37 
38 #include <gpgme++/signingresult.h>
39 #include <gpgme++/encryptionresult.h>
40 #include <qgpgme/job.h>
41 
42 
43 #include <QPushButton>
44 #include <QDialog>
45 #include <QDialogButtonBox>
46 #include <KLocalizedString>
47 #include <KGuiItem>
48 
49 
50 #include <gpg-error.h>
51 #include <KSharedConfig>
52 
53 using namespace Kleo;
54 using namespace Kleo::Private;
55 using namespace GpgME;
56 using namespace QGpgME;
57 
58 // static
59 void MessageBox::auditLog(QWidget *parent, const Job *job, const QString &caption)
60 {
61 
62  if (!job) {
63  return;
64  }
65 
66  if (!GpgME::hasFeature(AuditLogFeature, 0) || !job->isAuditLogSupported()) {
67  KMessageBox::information(parent, i18n("Your system does not have support for GnuPG Audit Logs"),
68  i18n("System Error"));
69  return;
70  }
71 
72  const GpgME::Error err = job->auditLogError();
73 
74  if (err && err.code() != GPG_ERR_NO_DATA) {
75  KMessageBox::information(parent, i18n("An error occurred while trying to retrieve the GnuPG Audit Log:\n%1",
76  QString::fromLocal8Bit(err.asString())),
77  i18n("GnuPG Audit Log Error"));
78  return;
79  }
80 
81  const QString log = job->auditLogAsHtml();
82 
83  if (log.isEmpty()) {
84  KMessageBox::information(parent, i18n("No GnuPG Audit Log available for this operation."),
85  i18n("No GnuPG Audit Log"));
86  return;
87  }
88 
89  auditLog(parent, log, caption);
90 }
91 
92 // static
93 void MessageBox::auditLog(QWidget *parent, const QString &log, const QString &caption)
94 {
95  AuditLogViewer *const alv = new AuditLogViewer(log, parent);
96  alv->setAttribute(Qt::WA_DeleteOnClose);
97  alv->setObjectName(QStringLiteral("alv"));
98  alv->setWindowTitle(caption);
99  alv->show();
100 }
101 
102 // static
103 void MessageBox::auditLog(QWidget *parent, const Job *job)
104 {
105  auditLog(parent, job, i18n("GnuPG Audit Log Viewer"));
106 }
107 
108 // static
109 void MessageBox::auditLog(QWidget *parent, const QString &log)
110 {
111  auditLog(parent, log, i18n("GnuPG Audit Log Viewer"));
112 }
113 
114 static QString to_information_string(const SigningResult &result)
115 {
116  return result.error()
117  ? i18n("Signing failed: %1", QString::fromLocal8Bit(result.error().asString()))
118  : i18n("Signing successful");
119 }
120 
121 static QString to_error_string(const SigningResult &result)
122 {
123  return to_information_string(result);
124 }
125 
126 static QString to_information_string(const EncryptionResult &result)
127 {
128  return result.error()
129  ? i18n("Encryption failed: %1", QString::fromLocal8Bit(result.error().asString()))
130  : i18n("Encryption successful");
131 }
132 
133 static QString to_error_string(const EncryptionResult &result)
134 {
135  return to_information_string(result);
136 }
137 
138 static QString to_information_string(const SigningResult &sresult, const EncryptionResult &eresult)
139 {
140  return to_information_string(sresult) + QLatin1Char('\n') + to_information_string(eresult);
141 }
142 
143 static QString to_error_string(const SigningResult &sresult, const EncryptionResult &eresult)
144 {
145  return to_information_string(sresult, eresult);
146 }
147 
148 // static
149 void MessageBox::information(QWidget *parent, const SigningResult &result, const Job *job, KMessageBox::Options options)
150 {
151  information(parent, result, job, i18n("Signing Result"), options);
152 }
153 
154 // static
155 void MessageBox::information(QWidget *parent, const SigningResult &result, const Job *job, const QString &caption, KMessageBox::Options options)
156 {
157  make(parent, QMessageBox::Information, to_information_string(result), job, caption, options);
158 }
159 
160 // static
161 void MessageBox::error(QWidget *parent, const SigningResult &result, const Job *job, KMessageBox::Options options)
162 {
163  error(parent, result, job, i18n("Signing Error"), options);
164 }
165 
166 // static
167 void MessageBox::error(QWidget *parent, const SigningResult &result, const Job *job, const QString &caption, KMessageBox::Options options)
168 {
169  make(parent, QMessageBox::Critical, to_error_string(result), job, caption, options);
170 }
171 
172 // static
173 void MessageBox::information(QWidget *parent, const EncryptionResult &result, const Job *job, KMessageBox::Options options)
174 {
175  information(parent, result, job, i18n("Encryption Result"), options);
176 }
177 
178 // static
179 void MessageBox::information(QWidget *parent, const EncryptionResult &result, const Job *job, const QString &caption, KMessageBox::Options options)
180 {
181  make(parent, QMessageBox::Information, to_information_string(result), job, caption, options);
182 }
183 
184 // static
185 void MessageBox::error(QWidget *parent, const EncryptionResult &result, const Job *job, KMessageBox::Options options)
186 {
187  error(parent, result, job, i18n("Encryption Error"), options);
188 }
189 
190 // static
191 void MessageBox::error(QWidget *parent, const EncryptionResult &result, const Job *job, const QString &caption, KMessageBox::Options options)
192 {
193  make(parent, QMessageBox::Critical, to_error_string(result), job, caption, options);
194 }
195 
196 // static
197 void MessageBox::information(QWidget *parent, const SigningResult &sresult, const EncryptionResult &eresult, const Job *job, KMessageBox::Options options)
198 {
199  information(parent, sresult, eresult, job, i18n("Encryption Result"), options);
200 }
201 
202 // static
203 void MessageBox::information(QWidget *parent, const SigningResult &sresult, const EncryptionResult &eresult, const Job *job, const QString &caption, KMessageBox::Options options)
204 {
205  make(parent, QMessageBox::Information, to_information_string(sresult, eresult), job, caption, options);
206 }
207 
208 // static
209 void MessageBox::error(QWidget *parent, const SigningResult &sresult, const EncryptionResult &eresult, const Job *job, KMessageBox::Options options)
210 {
211  error(parent, sresult, eresult, job, i18n("Encryption Error"), options);
212 }
213 
214 // static
215 void MessageBox::error(QWidget *parent, const SigningResult &sresult, const EncryptionResult &eresult, const Job *job, const QString &caption, KMessageBox::Options options)
216 {
217  make(parent, QMessageBox::Critical, to_error_string(sresult, eresult), job, caption, options);
218 }
219 
220 // static
221 bool MessageBox::showAuditLogButton(const QGpgME::Job *job)
222 {
223  if (!job) {
224  qCDebug(KLEO_UI_LOG) << "not showing audit log button (no job instance)";
225  return false;
226  }
227  if (!GpgME::hasFeature(GpgME::AuditLogFeature, 0)) {
228  qCDebug(KLEO_UI_LOG) << "not showing audit log button (gpgme too old)";
229  return false;
230  }
231  if (!job->isAuditLogSupported()) {
232  qCDebug(KLEO_UI_LOG) << "not showing audit log button (not supported)";
233  return false;
234  }
235  if (job->auditLogError().code() == GPG_ERR_NO_DATA) {
236  qCDebug(KLEO_UI_LOG) << "not showing audit log button (GPG_ERR_NO_DATA)";
237  return false;
238  }
239  if (!job->auditLogError() && job->auditLogAsHtml().isEmpty()) {
240  qCDebug(KLEO_UI_LOG) << "not showing audit log button (success, but result empty)";
241  return false;
242  }
243  return true;
244 }
245 
246 // static
247 void MessageBox::make(QWidget *parent, QMessageBox::Icon icon, const QString &text, const Job *job, const QString &caption, KMessageBox::Options options)
248 {
249  QDialog *dialog = new QDialog(parent);
250  dialog->setWindowTitle(caption);
251  QDialogButtonBox *box = new QDialogButtonBox(showAuditLogButton(job) ? (QDialogButtonBox::Yes | QDialogButtonBox::No) : QDialogButtonBox::Yes, parent);
252  QPushButton *yesButton = box->button(QDialogButtonBox::Yes);
253  yesButton->setDefault(true);
254  //dialog->setEscapeButton(KDialog::Yes);
255  dialog->setObjectName(QStringLiteral("error"));
256  dialog->setModal(true);
257  KGuiItem::assign(yesButton, KStandardGuiItem::ok());
258  if (GpgME::hasFeature(GpgME::AuditLogFeature, 0)) {
259  KGuiItem::assign(box->button(QDialogButtonBox::No), KGuiItem(i18n("&Show Audit Log")));
260  }
261 
262  if (QDialogButtonBox::No == KMessageBox::createKMessageBox(dialog, box, icon, text, QStringList(), QString(), nullptr, options)) {
263  auditLog(nullptr, job);
264  }
265 }
QWidget
QDialog::setModal
void setModal(bool modal)
Kleo::MessageBox::showAuditLogButton
static bool showAuditLogButton(const QGpgME::Job *job)
Definition: messagebox.cpp:221
QWidget::setAttribute
void setAttribute(Qt::WidgetAttribute attribute, bool on)
auditlogviewer.h
QString::fromLocal8Bit
QString fromLocal8Bit(const char *str, int size)
Kleo::MessageBox::information
static void information(QWidget *parent, const GpgME::SigningResult &result, const QGpgME::Job *job, const QString &caption, KMessageBox::Options options=KMessageBox::Notify)
Kleo::MessageBox::error
static void error(QWidget *parent, const GpgME::SigningResult &result, const QGpgME::Job *job, const QString &caption, KMessageBox::Options options=KMessageBox::Notify)
QObject::setObjectName
void setObjectName(const QString &name)
QString::isEmpty
bool isEmpty() const
to_information_string
static QString to_information_string(const SigningResult &result)
Definition: messagebox.cpp:114
messagebox.h
QString
Kleo::Private::AuditLogViewer
Definition: auditlogviewer.h:45
QStringList
QLatin1Char
Kleo::MessageBox::auditLog
static void auditLog(QWidget *parent, const QGpgME::Job *job, const QString &caption)
QDialogButtonBox
QWidget::setWindowTitle
void setWindowTitle(const QString &)
QDialog
QDialogButtonBox::button
QPushButton * button(StandardButton which) const
QPushButton
QWidget::show
void show()
QPushButton::setDefault
void setDefault(bool)
to_error_string
static QString to_error_string(const SigningResult &result)
Definition: messagebox.cpp:121
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Sun Dec 15 2019 02:42:48 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkleo

Skip menu "libkleo"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

pim API Reference

Skip menu "pim API Reference"
  • akonadi-calendar-tools
  •   konsolekalendar
  • akregator
  •   src
  • kalarmcal
  •   src
  •     lib
  • kdepim-runtime
  •   agents
  •   src
  • kleopatra
  •   src
  • kmailtransport
  • knotes
  • kontact
  • kontactinterface
  • kpimtextedit
  • ksmtp
  • ktnef
  • libkgapi
  • libkleo
  •   src
  •     src
  •     src

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal