read more than one certificate from a file; take file names in command line arguments
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include <QMainWindow>
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QMessageBox>
|
||||
#include <QRegExp>
|
||||
|
||||
#include <QDebug>
|
||||
@@ -33,24 +34,34 @@ class CertMan: public QMainWindow, protected Ui::CertMan {
|
||||
connect(&_openFromURL, SIGNAL(certificate(QUrl, QSslCertificate)),
|
||||
SLOT(certificate(QUrl, QSslCertificate)));
|
||||
}
|
||||
bool open(const QString& fileName) {
|
||||
bool status(true);
|
||||
QFile file(fileName);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
while (!file.atEnd()) {
|
||||
QSslCertificate c(&file);
|
||||
if (!c.isNull()) {
|
||||
Certificate* win(new Certificate(_mdi));
|
||||
_mdi->addSubWindow(win)->setWindowTitle(QFileInfo(fileName).fileName());
|
||||
win->show();
|
||||
win->certificate(c);
|
||||
} else {
|
||||
status = false;
|
||||
qDebug()<<QObject::trUtf8("Cannot read PEM certificate from file: %1")
|
||||
.arg(fileName);
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
return status;
|
||||
}
|
||||
virtual ~CertMan() {}
|
||||
protected slots:
|
||||
void on__actionOpenCertificate_triggered() {
|
||||
QString fileName = QFileDialog::getOpenFileName(this);
|
||||
if (fileName.isEmpty()) return;
|
||||
QFile file(fileName);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
QSslCertificate c(&file);
|
||||
file.close();
|
||||
if (c.isNull()) {
|
||||
qDebug()<<QObject::trUtf8("Cannot read PEM certificate from file: %1")
|
||||
.arg(fileName);
|
||||
return;
|
||||
}
|
||||
Certificate* win(new Certificate(_mdi));
|
||||
_mdi->addSubWindow(win)->setWindowTitle(QFileInfo(fileName).fileName());
|
||||
win->show();
|
||||
win->certificate(c);
|
||||
if (!open(fileName))
|
||||
QMessageBox::warning(this, "Error Loading File",
|
||||
QString("Error loading file:\n%1").arg(fileName));
|
||||
}
|
||||
void on__actionOpenFromURL_triggered() {
|
||||
if (_openFromURL.exec()==QDialog::Accepted) {
|
||||
|
||||
@@ -18,8 +18,12 @@ int main(int argc, char *argv[]) try {
|
||||
QCommandLineParser parser;
|
||||
parser.addHelpOption();
|
||||
parser.process(a);
|
||||
QStringList scripts(parser.positionalArguments());
|
||||
QStringList files(parser.positionalArguments());
|
||||
CertMan w;
|
||||
for (const QString& file: files) {
|
||||
if (!w.open(file))
|
||||
std::cerr<<"Error reading file: "<<file.toStdString()<<std::endl;
|
||||
}
|
||||
w.show();
|
||||
return a.exec();
|
||||
} catch (std::exception &x) {
|
||||
|
||||
Reference in New Issue
Block a user