summaryrefslogtreecommitdiffstats
path: root/pica-client/dialogs/addaccountdialog.cpp
blob: 39c2ef31734db7043f9f74c28fc1ad0ba2b58606 (plain) (blame)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "addaccountdialog.h"
#include <QGridLayout>
#include <QLabel>
#include <QFile>
#include <QFileDialog>
#include <QMessageBox>
#include <QProcess>
#include "../../PICA_client.h"

AddAccountDialog::AddAccountDialog(QWidget *parent) :
	QDialog(parent)
{
	QGridLayout *grid = new QGridLayout(this);

	QLabel *lb_cert_file = new QLabel(tr("Pica Pica Certificate File:"));
	QLabel *lb_pkey_file = new QLabel(tr("Private Key File:"));

	btOK = new QPushButton(tr("OK"));
	btCancel = new QPushButton(tr("Cancel"));

	cert_filename = new QLineEdit();
	pkey_filename = new QLineEdit();

	bt_browse_cert = new QPushButton("...");
	bt_browse_pkey = new QPushButton("...");

	rb_copyfiles = new QRadioButton(tr("Copy files to config directory"));
	rb_readinplace = new QRadioButton(tr("Read files from selected place"));

	grid->addWidget(lb_cert_file, 0, 0, 1, 1);

	grid->addWidget(cert_filename, 1, 0, 1, 1);
	grid->addWidget(bt_browse_cert, 1, 1, 1, 1);

	grid->addWidget(lb_pkey_file, 2, 0, 1, 1);

	grid->addWidget(pkey_filename, 3, 0, 1, 1);
	grid->addWidget(bt_browse_pkey, 3, 1, 1, 1);

	grid->addWidget(rb_copyfiles, 4, 0, 1, 1);
	grid->addWidget(rb_readinplace, 5, 0, 1, 1);

	grid->addWidget(btOK, 6, 0, 1, 1, Qt::AlignRight);
	grid->addWidget(btCancel, 6, 1, 1, 1, Qt::AlignLeft);
	//===========
	rb_copyfiles->setChecked(true);

	btOK->setMaximumWidth(90);
	btCancel->setMaximumWidth(90);

	connect(btOK, SIGNAL(clicked()), this, SLOT(OK()));
	connect(btCancel, SIGNAL(clicked()), this, SLOT(Cancel()));
	connect(bt_browse_cert, SIGNAL(clicked()), this, SLOT(browse_cert()));
	connect(bt_browse_pkey, SIGNAL(clicked()), this, SLOT(browse_pkey()));

	setLayout(grid);
}

void AddAccountDialog::OK()
{
	{
		QString s;
		if (!QFile::exists(s = cert_filename->text()) || !QFile::exists(s = pkey_filename->text()) )
		{
			QMessageBox mbx;
			mbx.setText(tr("File %1 does not exist").arg(s));
			mbx.exec();
			return;
		}

		QByteArray id(PICA_ID_SIZE, 0);

		if (!PICA_get_id_from_cert_file(cert_filename->text().toUtf8().constData(), (unsigned char*)id.data()))
		{
			QMessageBox mbx;
			mbx.setText(tr("Invalid certificate file"));
			mbx.exec();
			return;
		}
	}

	done(1);

}

void AddAccountDialog::Cancel()
{
	done(0);
}

void AddAccountDialog::browse_cert()
{
	cert_filename->setText(QFileDialog::getOpenFileName(this, tr("Select Pica Pica Certificate"), "", "PEM file (*.pem)"));
}

void AddAccountDialog::browse_pkey()
{
	pkey_filename->setText(QFileDialog::getOpenFileName(this, tr("Select Private Key"), "", "PEM file (*.pem)"));
}

QString AddAccountDialog::GetCertFilename()
{
	return cert_filename->text();
}

QString AddAccountDialog::GetPkeyFilename()
{
	return pkey_filename->text();
}

bool AddAccountDialog::isCopyFilesChecked()
{
	return rb_copyfiles->isChecked();
}