forked from erykrutkowski/Steghide-GUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
186 lines (164 loc) · 6.26 KB
/
mainwindow.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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QFileDialog"
#include "QStringListModel"
#include "QMessageBox"
#include "QInputDialog"
#include <QTextStream>
#include <QLabel>
#include <QTextBrowser>
void outcallback( const char* ptr, std::streamsize count, void* pString )
{
(void) count;
QString* p = static_cast< QString* >( pString );
p->append(ptr);
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->FreeSpaceProgressBar->setFormat("Select file in left section.");
ui->centralWidget->setLayout(ui->gridLayout);
sPath="/home/rryk/Pulpit/Discotest";
selected_file=NULL;
dirmodel = new QFileSystemModel(this);
dirmodel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs | QDir::Files);
dirmodel->setNameFilters(QStringList() << "*.jpg" << "*.JPG" << "*.jpeg" << "*.JPEG" << "*.bmp" << "*.BMP" << "*.wav" << "*.WAV" << "*.au" << "*.AU");
dirmodel->setRootPath(sPath);
ui->FilesAndFoldersTreeView->setModel(dirmodel);
ui->FilesAndFoldersTreeView->setRootIndex(dirmodel->index(sPath));
filesmodel = new FilesToAddListModel(filenames);
ui->FileTableView->setModel(filesmodel);
files_v_header= ui->FileTableView->verticalHeader();
connect(files_v_header, SIGNAL(sectionClicked(int)), this, SLOT(on_sectionClicked(int)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_ReloadButton_clicked()
{
sPath=ui->FilesAndFolders_MainPath->text();
if(QDir(sPath).exists()){
dirmodel->setRootPath(sPath);
ui->FilesAndFoldersTreeView->setRootIndex(dirmodel->index(sPath));
}
else{
QWidget tmp;
QMessageBox::critical(&tmp,"Error","WRONG PATH!");
}
}
void MainWindow::on_AddFilesButton_clicked()
{
filenames.clear();
filenames=QFileDialog::getOpenFileNames(this, tr("Open File"), "/", "All files *.*");
filesmodel->setStringList(filenames);
update_FreeSpaceProgressBar();
}
void MainWindow::on_sectionClicked ( int logicalIndex )
{
filesmodel->removeRow(logicalIndex);
update_FreeSpaceProgressBar();
}
void MainWindow::on_SettingsButton_clicked()
{
dialog = new Dialog(this);
dialog->setWindowTitle("Settings");
dialog->setlabeltext("There will be some Settings.");
dialog->setModal(true);
dialog->show();
}
void MainWindow::on_HelpButton_clicked()
{
dialog = new Dialog(this);
dialog->setWindowTitle("Help");
dialog->setlabeltext("There will be some Help.");
dialog->setModal(true);
dialog->show();
}
void MainWindow::on_EncodeButton_clicked()
{
passphrase=QInputDialog::getText(this,"Specify passphrase","Enter passphrase:",QLineEdit::Password);
}
void MainWindow::on_FilesAndFoldersTreeView_clicked(const QModelIndex &index)
{
if((ui->FilesAndFoldersTreeView->selectionModel()->isSelected(index))&&(QFileInfo(dirmodel->filePath(index)).isFile())){
selected_file = CvrStgFile::readFile ((dirmodel->filePath(index)).toUtf8().constData()) ;
update_FreeSpaceProgressBar();
ui->ExtractButton->setEnabled(true);
}
else
{
ui->ExtractButton->setEnabled(false);
selected_file = NULL;
}
}
void MainWindow::update_FreeSpaceProgressBar(){
if(selected_file!=NULL){
int temp=((filesmodel->get_sum_size())/(selected_file->getCapacity()))*100;
ui->FreeSpaceProgressBar->setValue(temp);
ui->FreeSpaceProgressBar->setFormat(QString::number(filesmodel->get_sum_size())+" / "+QString::number(selected_file->getCapacity()));
}
}
void MainWindow::on_FilesAndFolders_MainPath_returnPressed()
{
on_ReloadButton_clicked();
}
void MainWindow::on_ExtractButton_clicked()
{
if(selected_file!=NULL){
ExtractDialog *extract_dialog;
extract_dialog=new ExtractDialog(this);
extract_dialog->setModal(true);
extract_dialog->show();
passphrase=QInputDialog::getText(this,"Specify passphrase","Enter passphrase:",QLineEdit::Password);
QModelIndex index=ui->FilesAndFoldersTreeView->selectionModel()->selectedIndexes().at(0);
std::string dirmodel_path=(dirmodel->filePath(index)).toUtf8().constData();
Extractor ext (dirmodel_path, passphrase.toUtf8().constData()) ;
EmbData* embdata = ext.extract() ;
// write data
std::string fn ;
// write extracted data to file with embedded file name
fn = embdata->getFileName() ;
if (fn.length() == 0) {
fn=(QInputDialog::getText(this,"Please specify a file name for the extracted data (there is no name embedded in the stego file).","Enter filename:",QLineEdit::Normal)).toUtf8().constData();
}
extract_dialog->setlabeltext( QString::fromStdString("Writing extracted data to: "+fn));
QString * myString = new QString();
myString->clear();
StdRedirector<>* myRedirector = new StdRedirector<>( std::cerr, outcallback, myString );
BinaryIO *io;
try{
io = new BinaryIO (dirmodel_path.substr(0,dirmodel_path.find_last_of("//"))+"/"+fn, BinaryIO::WRITE) ;
}
catch(SteghideError e){
QMessageBox::StandardButton reply = QMessageBox::question(this, "Existing file?", myString->toUtf8().constData(),
QMessageBox::Yes|QMessageBox::No);
if (reply == QMessageBox::Yes) {
Args.Force.setValue(true);
io = new BinaryIO (fn, BinaryIO::WRITE) ;
Args.Force.setValue(false);
}
delete myRedirector;
myString->clear();
}
if(io->is_open()){
std::vector<BYTE> data = embdata->getData() ;
float progress=0;
unsigned long k;
unsigned long size=data.size();
for (std::vector<BYTE>::iterator i = data.begin() ; i != data.end() ; i++) {
io->write8 (*i) ;
k=((i-data.begin())/100);
progress=((k/(data.size()/100))*100);
extract_dialog->setprogressbarvalue(progress);
}
io->close() ;
extract_dialog->setlabeltext( QString::fromStdString("wrote extracted data to \""+fn+"\"."));
}
else{
extract_dialog->setlabeltext( "ERROR" );
}
}
}