view ui/createcertlistdialog.cpp @ 427:d08e39b913ee

Added about dialog content and open the dialog via administration app.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 17 Apr 2014 12:56:23 +0200
parents d7cda835abd6
children d1819cd56dee
line wrap: on
line source
/* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU GPL (v>=2)
 * and comes with ABSOLUTELY NO WARRANTY!
 * See LICENSE.txt for details.
 */
#include "createcertlistdialog.h"
#include <QDebug>
#include <QDir>
#include <QPushButton>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QFileDialog>
#include <QStandardPaths>

CreateCertListDialog::CreateCertListDialog(QMainWindow *parent) :
    QDialog(parent)
{
    setWindowTitle(tr("Save certificate list"));
    setupGUI();
    resize(500, 200);
}

void CreateCertListDialog::setupGUI()
{
    /* Top level layout / widgets */
    QVBoxLayout *topLayout = new QVBoxLayout;
    QVBoxLayout *headerLayout = new QVBoxLayout;
    QHBoxLayout *headerSubLayout = new QHBoxLayout;
    QVBoxLayout *centerLayout = new QVBoxLayout;
    QHBoxLayout *bottomLayout = new QHBoxLayout;
    QHBoxLayout *certLayout = new QHBoxLayout;
    QHBoxLayout *saveLayout = new QHBoxLayout;

    QLabel *header = new QLabel("<h3>" + tr("Save certificate list") + "</h3>");
    QLabel *description = new QLabel(
        tr("Save all managed root certificates in a new, signed certificate list."));
    headerSubLayout->insertSpacing(0, 40);
    headerSubLayout->addWidget(description);
    QFrame *headerSeparator = new QFrame();
    headerSeparator->setFrameShape(QFrame::HLine);
    headerSeparator->setFrameShadow(QFrame::Sunken);
    headerLayout->addWidget(header);
    headerLayout->addLayout(headerSubLayout);
    headerLayout->addWidget(headerSeparator);

    QLabel *certLabel = new QLabel("Select signature certificate (secret key):");
    certLabel->setFixedWidth(205);
    mCertFile = new QLineEdit();
    QPushButton *certSelect = new QPushButton("...");
    connect(certSelect, SIGNAL(clicked()), this, SLOT(openCertificateSelect()));
    certSelect->setFixedWidth(30);
    certLayout->addWidget(certLabel);
    certLayout->addWidget(mCertFile);
    certLayout->addWidget(certSelect);

    QLabel *saveLabel = new QLabel("Select output folder:");
    saveLabel->setFixedWidth(205);
    mSaveFile = new QLineEdit();
    QPushButton *saveSelect = new QPushButton("...");
    connect(saveSelect, SIGNAL(clicked()), this, SLOT(openSaveLocation()));
    saveSelect->setFixedWidth(30);

    QString footerText = tr("In addition, each certificate list will be saved "
        "automatically in the archive directory:\n");
    // TODO print out the path, not the displayName.
    footerText.append(QStandardPaths::writableLocation(
        QStandardPaths::DataLocation));
    //footerText.append(QStandardPaths::displayName(QStandardPaths::DataLocation));
    QLabel *footer = new QLabel(footerText);
    saveLayout->addWidget(saveLabel);
    saveLayout->addWidget(mSaveFile);
    saveLayout->addWidget(saveSelect);

    centerLayout->insertSpacing(0, 10);
    centerLayout->addLayout(certLayout);
    centerLayout->addLayout(saveLayout);
    centerLayout->insertSpacing(3, 10);

    QPushButton *create = new QPushButton(tr("Sign list"));
    connect(create, SIGNAL(clicked()), this, SLOT(createList()));
    QPushButton *cancel = new QPushButton(tr("Cancel"));
    connect(cancel, SIGNAL(clicked()), this, SLOT(close()));
    bottomLayout->insertStretch(0, 10);
    bottomLayout->addWidget(create);
    bottomLayout->addWidget(cancel);

    QFrame *bottomSeparator = new QFrame();
    bottomSeparator->setFrameShape(QFrame::HLine);
    bottomSeparator->setFrameShadow(QFrame::Sunken);

    topLayout->addLayout(headerLayout);
    topLayout->addLayout(centerLayout);
    topLayout->insertStretch(2, 10);
    topLayout->addWidget(footer);
    topLayout->addWidget(bottomSeparator);
    topLayout->addLayout(bottomLayout);

    setLayout(topLayout);

    return;
}

void CreateCertListDialog::openCertificateSelect()
{
    QString certFile = QFileDialog::getOpenFileName(
        this, tr("Select certificate"), QDir::homePath(), "*.pem *.der *.crt");
    mCertFile->setText(certFile);
}

void CreateCertListDialog::openSaveLocation()
{
    QString saveFile = QFileDialog::getExistingDirectory(
        this, tr("Select target location"), QDir::homePath());
    mSaveFile->setText(saveFile);
}

void CreateCertListDialog::createList()
{
    qDebug() << "and now create the certificate list using:";
    qDebug() << "certificate: " << mCertFile->text();
    qDebug() << "target" << mSaveFile->text();
    // TODO
}

http://wald.intevation.org/projects/trustbridge/