-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathextractwindow.cpp
69 lines (58 loc) · 2.43 KB
/
extractwindow.cpp
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
#include "extractwindow.h"
#include "ui_extractwindow.h"
#include <QFileDialog>
ExtractWindow::ExtractWindow(QWidget *parent)
: QDialog(parent), ui(new Ui::ExtractWindow) {
ui->setupUi(this);
setModal(true);
connect(ui->extractButton, &QPushButton::clicked, this, &ExtractWindow::Extract);
connect(ui->inputButton, &QPushButton::clicked, this, &ExtractWindow::pickInputFile);
connect(ui->outputDirButton, &QPushButton::clicked, this, &ExtractWindow::pickOutputPath);
huffmanDecoding = new HuffmanDecoding();
connect(huffmanDecoding, &HuffmanDecoding::started, this,
[this] { ui->progressBar->setHidden(false); });
connect(huffmanDecoding, &HuffmanDecoding::finished, this,
[this] { ui->progressBar->setHidden(true); });
connect(huffmanDecoding, &HuffmanDecoding::progressChanged, ui->textEdit, &QTextEdit::append);
connect(huffmanDecoding, &HuffmanDecoding::progressCounted, ui->progressBar, &QProgressBar::setValue);
connect(huffmanDecoding, &HuffmanDecoding::setEnabled, ui->extractButton, &QPushButton::setEnabled);
connect(huffmanDecoding, &HuffmanDecoding::setEnabled, ui->inputButton, &QPushButton::setEnabled);
connect(huffmanDecoding, &HuffmanDecoding::setEnabled, ui->outputDirButton, &QPushButton::setEnabled);
}
void ExtractWindow::showEvent(QShowEvent *) {
if (!huffmanDecoding->isRunning()) {
ui->progressBar->setHidden(true);
ui->progressBar->setValue(0);
ui->inputFile->clear();
ui->extractPosition->clear();
ui->textEdit->clear();
}
}
ExtractWindow::~ExtractWindow() {
delete ui;
delete huffmanDecoding;
}
void ExtractWindow::Extract() {
ui->progressBar->setValue(0);
QString filename = ui->inputFile->text();
QString output = ui->extractPosition->text();
if (!filename.isEmpty() && !output.isEmpty()) {
ui->textEdit->clear();
huffmanDecoding->setInputFile(filename);
huffmanDecoding->setOutputFile(output);
huffmanDecoding->start();
}
}
void ExtractWindow::pickInputFile() {
QString filename =
QFileDialog::getOpenFileName(this, tr("Open File to Extract..."),
QDir::homePath(), tr("Frog File (*.frog)"));
if (!filename.isEmpty())
ui->inputFile->setText(filename);
}
void ExtractWindow::pickOutputPath() {
QString outputdir = QFileDialog::getExistingDirectory(
this, tr("Choose Directory to Extract"), QDir::homePath());
if (!outputdir.isEmpty())
ui->extractPosition->setText(outputdir);
}