-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcryptionwindow.cpp
More file actions
103 lines (93 loc) · 3.8 KB
/
cryptionwindow.cpp
File metadata and controls
103 lines (93 loc) · 3.8 KB
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
#include "cryptionwindow.h"
#include "ui_cryptionwindow.h"
#include <QFileDialog>
#include <QMessageBox>
Logger CryptionWindow::log;
CryptionWindow::CryptionWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::CryptionWindow),
set(this)
{
iC = new ImageCryption();
ui->setupUi(this);
connect(ui->changeFileToEncryptPathButton, SIGNAL(clicked()), this, SLOT(changeFileToEncryptPath()));
connect(ui->changeFileEncryptedSavePathButton, SIGNAL(clicked()), this, SLOT(changeFileEncryptedPath()));
connect(ui->changeFileToDecryptPathButton, SIGNAL(clicked()), this, SLOT(changeFileToDecryptPath()));
connect(ui->changeFileDecryptedSavePathButton, SIGNAL(clicked()), this, SLOT(changeFileDecryptedPath()));
connect(ui->settingsButton, SIGNAL(clicked()), this, SLOT(changeSettings()));
connect(ui->encryptButton, SIGNAL(clicked()), this, SLOT(startEncrypt()));
connect(ui->decryptButton, SIGNAL(clicked()), this, SLOT(startDecrypt()));
connect(iC->iE, SIGNAL(finished()), this, SLOT(finishedEncrypt()));
connect(iC->iD, SIGNAL(finished()), this, SLOT(finishedDecrypt()));
}
void CryptionWindow::changeFileToEncryptPath() {
QString returnVal = QFileDialog::getOpenFileName(this, "Choose a file to encrypt...");
if(!returnVal.isNull())
ui->fileToEncryptPath->setText(returnVal);
}
void CryptionWindow::changeFileEncryptedPath() {
QString returnVal = QFileDialog::getSaveFileName(this, "Choose a location to save the encrypted data...");
if(!returnVal.isNull())
ui->encryptedFileSavePath->setText(returnVal);
}
void CryptionWindow::startEncrypt() {
if(ui->fileToEncryptPath->text() == "" || ui->encryptedFileSavePath->text() == "") {
QMessageBox::information(this, "Information", "Please complete the encryption form before trying to start.");
return;
}
QFile* fileToRead = new QFile(ui->fileToEncryptPath->text());
QFile* fileToWrite = new QFile(ui->encryptedFileSavePath->text());
if(!fileToRead->exists()) {
QMessageBox::information(this, "File not found", "The file to be read for encryption could not be found.");
return;
}
ui->encryptButton->setEnabled(false);
iC->iE->initSettings(fileToRead, fileToWrite, set.alphaEnabled(), set.alphaBitEnabled());
iC->iE->start();
}
void CryptionWindow::finishedEncrypt() {
ui->encryptButton->setEnabled(true);
}
void CryptionWindow::changeFileToDecryptPath() {
QString returnVal = QFileDialog::getOpenFileName(this, "Choose a file to decrypt...");
if(!returnVal.isNull())
ui->fileToDecryptPath->setText(returnVal);
}
void CryptionWindow::changeFileDecryptedPath() {
QString returnVal = QFileDialog::getSaveFileName(this, "Choose a location to save the decrypted data...");
if(!returnVal.isNull())
ui->decryptedFileSavePath->setText(returnVal);
}
void CryptionWindow::startDecrypt() {
if(ui->fileToDecryptPath->text() == "" || ui->decryptedFileSavePath->text() == "") {
QMessageBox::information(this, "Information", "Please complete the decryption form before trying to start.");
return;
}
QFile* fileToRead = new QFile(ui->fileToDecryptPath->text());
QFile* fileToWrite = new QFile(ui->decryptedFileSavePath->text());
if(!fileToRead->exists()) {
QMessageBox::information(this, "File not found", "The file to be read for encryption could not be found.");
return;
}
QImage* nowImage = new QImage();
if(!nowImage->load(fileToRead->fileName())) {
QMessageBox::information(this, "Incorrect file", "There was either a error reading or this is not a proper image.\nI'm too lazy to properly handle this error.");
return;
}
ui->decryptButton->setEnabled(false);
iC->iD->initSettings(nowImage, fileToWrite);
iC->iD->start();
}
void CryptionWindow::finishedDecrypt() {
ui->decryptButton->setEnabled(true);
}
void CryptionWindow::changeSettings() {
if(set.isVisible())
set.setFocus(Qt::PopupFocusReason);
else
set.show();
}
CryptionWindow::~CryptionWindow()
{
delete ui;
}