This repository was archived by the owner on Oct 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
149 lines (124 loc) · 4.27 KB
/
mainwindow.cpp
File metadata and controls
149 lines (124 loc) · 4.27 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
core = new manage(this);
ui->tableW_Input->setColumnCount(1);
ui->tableW_Input->verticalHeader()->resizeSections(QHeaderView::Stretch);
ui->tableW_Input->verticalHeader()->setVisible(false);
ui->tableW_Input->setHorizontalHeaderLabels((QStringList)tr("File"));
ui->lable_Status->setText(tr("Status: Waiting"));
allDisabled(false);
started = false;
connect(core->pt_zip_7,&QProcess::stateChanged,this,&MainWindow::statusChanged);
connect(core->pt_zip_7,&QProcess::readyReadStandardOutput,this,&MainWindow::readSTDOUT);
connect(core->pt_zip_7,&QProcess::readyReadStandardError,this,&MainWindow::readSTDER);
connect(core->pt_zip_7,SIGNAL(finished(int)),this,SLOT(justFinished(int)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::allDisabled(bool rule)
{
rule = !rule;
ui->pb_AddFile->setEnabled(rule);
ui->pb_Browse->setEnabled(rule);
ui->pb_Compress->setEnabled(rule);
ui->pb_RemoveAll->setEnabled(rule);
ui->tableW_Input->setEnabled(rule);
ui->le_Output->setEnabled(rule);
}
void MainWindow::on_pb_Compress_clicked()
{
started = false;
int run = core->archiveEverything();
if(run == -1)QMessageBox::warning(this,tr("Error 111"),tr("No Files to compress"));
else if(run == 0)QMessageBox::warning(this,tr("Error 101"),tr("No Output File specified"));
else if(run == -2)QMessageBox::warning(this,tr("Error 100"),tr("Something broke !"));
else if(run == -3)QMessageBox::warning(this,tr("Error 010"),tr("Compression not yet finished"));
else started = true;
}
void MainWindow::on_pb_RemoveAll_clicked()
{
core->clearAllFiles();
while(ui->tableW_Input->rowCount() > 0){
for(int i = 0; i < ui->tableW_Input->rowCount(); i++)
{
ui->tableW_Input->cellWidget(i,0)->deleteLater();
ui->tableW_Input->removeRow(i);
}
}
}
void MainWindow::on_pb_AddFile_clicked()
{
QStringList files = core->addInputFiles(this);
ui->tableW_Input->setRowCount(files.count());
for(int i = 0; i < files.count(); i++)
{
ui->tableW_Input->setCellWidget(i,0,new QLabel(files.at(i)));
}
ui->tableW_Input->horizontalHeader()->resizeSections(QHeaderView::Stretch);
}
void MainWindow::on_pb_Browse_clicked()
{
ui->le_Output->setText(core->setOutput(this));
}
void MainWindow::statusChanged(QProcess::ProcessState state)
{
switch (state) {
case QProcess::NotRunning:
allDisabled(false);
if(started == true)QMessageBox::about(this,tr("Success"),tr("Sucessfully Finished"));
ui->lable_Status->setText(tr("Status: Waiting"));
break;
case QProcess::Running:
case QProcess::Starting:
ui->lable_Status->setText(tr("Status: Working..."));
allDisabled(true);
break;
default:
allDisabled(false);
ui->lable_Status->setText(tr("Status: WHAT THE HELL JUST HAPPENED ???"));
break;
}
}
void MainWindow::readSTDOUT()
{
std::cout << core->pt_zip_7->readAllStandardOutput().toStdString();
}
void MainWindow::readSTDER()
{
std::cout << core->pt_zip_7->readAllStandardError().toStdString();
}
void MainWindow::justFinished(int)
{
started = false;
}
void MainWindow::closeEvent(QCloseEvent *event)
{
if(started == true){
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this,tr("Are you sure?"),tr("7Zip is still working on something. Do you really want to quit?"),
QMessageBox::Yes|QMessageBox::No);
if(reply == QMessageBox::Yes){
core->pt_zip_7->terminate();
event->accept();
}else event->ignore();
}else event->accept();
}
void MainWindow::on_pb_Close_clicked()
{
if(started == true){
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this,tr("Are you sure?"),tr("7Zip is still working on something. Do you really want to quit?"),
QMessageBox::Yes|QMessageBox::No);
if(reply == QMessageBox::Yes){
core->pt_zip_7->terminate();
this->close();
}
}else this->close();
}