File: XcaWarning.cpp

package info (click to toggle)
xca 2.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,328 kB
  • sloc: cpp: 30,584; sh: 341; xml: 74; makefile: 56; python: 34
file content (92 lines) | stat: -rw-r--r-- 2,191 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* vi: set sw=4 ts=4:
 *
 * Copyright (C) 2018 Christian Hohnstaedt.
 *
 * All rights reserved.
 */

#include "XcaWarning.h"
#include "XcaDialog.h"
#include "lib/func.h"

#include <QApplication>
#include <QClipboard>
#include <QPushButton>
#include <QDebug>
#include <QSqlDatabase>
#include <QTextEdit>

xcaWarningBox::xcaWarningBox(QWidget *w, const QString &txt,
				QMessageBox::Icon icn)
	: QMessageBox(icn, XCA_TITLE, txt, QMessageBox::NoButton, w)
{
	setTextFormat(Qt::PlainText);
}

void xcaWarningBox::addButton(QMessageBox::StandardButton button,
				const QString &text)
{
	QPushButton *b = QMessageBox::addButton(button);
	if (b && !text.isEmpty())
		b->setText(text);
}

int xcaWarningGui::showBox(const QString &txt, QMessageBox::Icon icn,
			QMessageBox::StandardButtons b)
{
	QMessageBox w(icn, XCA_TITLE, txt, b, nullptr);
	return w.exec();
}

void xcaWarningGui::information(const QString &msg)
{
	showBox(msg, QMessageBox::Information, QMessageBox::Ok);
}

void xcaWarningGui::warning(const QString &msg)
{
	showBox(msg, QMessageBox::Warning, QMessageBox::Ok);
}

bool xcaWarningGui::yesno(const QString &msg)
{
	return showBox(msg, QMessageBox::Question,
		QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes;
}

bool xcaWarningGui::okcancel(const QString &msg)
{
	return showBox(msg, QMessageBox::Warning,
		QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok;
}

void xcaWarningGui::sqlerror(QSqlError err)
{
	qCritical() << "SQL ERROR:" << err.text();
}

void xcaWarningGui::error(const QString &msg)
{
	xcaWarningBox box(NULL, msg);
	box.addButton(QMessageBox::Apply, tr("Copy to Clipboard"));
	box.addButton(QMessageBox::Ok);
	if (box.exec() == QMessageBox::Apply) {
		QClipboard *cb = QApplication::clipboard();
		cb->setText(msg);
		if (cb->supportsSelection())
			cb->setText(msg, QClipboard::Selection);
	}
}

void xcaWarningGui::warningv3(const QString &msg, const extList &el)
{
	QString etext = QString("<h3>") + msg +
		QString("</h3><hr>") + el.getHtml("<br>");

	QTextEdit *textbox = new QTextEdit(etext);
	XcaDialog *d = new XcaDialog(NULL, x509, textbox,
				QString(), QString());
	d->aboutDialog(QPixmap(":certImg"));
	d->exec();
	delete d;
}