Menu

[r27]: / trunk / mainwindow.cpp  Maximize  Restore  History

Download this file

118 lines (102 with data), 3.6 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
ui->checkEncode->setChecked(true);
ui->btnGoFile->setText("Encode");
}
MainWindow::~MainWindow() {
delete ui;
}
void MainWindow::UpdateProgress(qint64 Position, qint64 Size) {
QString pos = QString::number(Position);
QString size = QString::number(Size);
QString msg = "["+ QString::number(CurrentIndex) + "/" + QString::number(FileCount) + "] Processing " + pos + " of " + size + " bytes";
ui->statusBar->showMessage(msg);
}
void MainWindow::FileComplete(int index, int count) {
CurrentIndex = index;
FileCount = count;
}
void MainWindow::OperationComplete() {
ui->statusBar->showMessage("Done");
ui->btnGoFile->setEnabled(true);
}
void MainWindow::on_btnGoFile_clicked(){
ui->btnGoFile->setEnabled(false);
QThread* thread = new QThread;
WorkThread* worker = new WorkThread();
CurrentIndex = 1;
FileCount = 0;
int i;
for(i = 0; i < ui->listFiles->count(); i++) {
QListWidgetItem *item = ui->listFiles->item(i);
QFileInfo fi(item->text());
if(fi.exists()) {
worker->AddFile(item->text());
FileCount++;
}
}
if(ui->checkEncode->isChecked()) {
worker->SetMode(wmEncode);
}
else {
worker->SetMode(wmDecode);
}
worker->SetOutputPath(ui->textOutputDirectory->text());
worker->moveToThread(thread);
connect(thread, SIGNAL(started()), worker, SLOT(Process()));
connect(worker, SIGNAL(Finished()), thread, SLOT(quit()));
connect(worker, SIGNAL(Finished()), worker, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
connect(worker, SIGNAL(UpdateProgress(qint64,qint64)), this, SLOT(UpdateProgress(qint64,qint64)));
connect(worker, SIGNAL(FileComplete(int,int)), this, SLOT(FileComplete(int,int)));
connect(worker, SIGNAL(Finished()), this, SLOT(OperationComplete()));
thread->start();
}
void MainWindow::on_checkEncode_toggled(bool checked) {
if(checked) {
ui->btnGoFile->setText("Encode");
}
}
void MainWindow::on_checkDecode_toggled(bool checked) {
if(checked) {
ui->btnGoFile->setText("Decode");
}
}
void MainWindow::on_btnAddFile_clicked() {
QStringList filenames = QFileDialog::getOpenFileNames(this, "Select files", "", "*.*");
if(filenames.isEmpty()) return;
ui->listFiles->addItems(filenames);
}
void MainWindow::on_btnDeleteFile_clicked() {
qDeleteAll(ui->listFiles->selectedItems());
}
void MainWindow::on_btnClearList_clicked() {
ui->listFiles->clear();
}
void MainWindow::on_btnPickDir_clicked() {
QString outputdir = QFileDialog::getExistingDirectory(this, "Select directory");
if(outputdir.isEmpty()) return;
ui->textOutputDirectory->setText(outputdir);
}
void MainWindow::on_checkEncodeText_toggled(bool checked) {
if(checked) {
ui->btnGoText->setText("Encode");
}
}
void MainWindow::on_checkDecodeText_toggled(bool checked) {
if(checked) {
ui->btnGoText->setText("Decode");
}
}
void MainWindow::on_btnGoText_clicked() {
QByteArray ba;
ba.append(ui->textInput->toPlainText());
if(ui->checkEncodeText->isChecked()) {
ui->textOutput->setPlainText(ba.toBase64());
}
else {
ui->textOutput->setPlainText(ba.fromBase64(ba));
}
}
MongoDB Logo MongoDB