-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainmenu.cpp
executable file
·210 lines (178 loc) · 5.68 KB
/
mainmenu.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include<iostream>
#include<QFileDialog>
#include<QMessageBox>
#include "mainmenu.h"
#include "ui_mainmenu.h"
#include "settingmenu.h"
#include <QList>
#include <QDirIterator>
using namespace std;
MainMenu::MainMenu(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainMenu)
{
ui->setupUi(this);
smenu=new SettingMenu(this,settings);
if(!settings->value("hasSavedSettings").toBool())
{
//first run time!
cerr<<"Showing first Run wizard"<<endl;
smenu->ShowWizard();
}
ui->lbl_version->setText("Version: " + QString::number(this->versionNumber));
//create combo box values
ui->qualBox->addItem("High");
ui->qualBox->addItem("Medium");
ui->qualBox->addItem("Low");
ui->sizeBox->addItem("Small (slow conversion)");
ui->sizeBox->addItem("Med (med conversion)");
ui->sizeBox->addItem("Large (fast conversion)");
//create connections
connect(ui->action_Quit,SIGNAL(triggered(bool)),this,SLOT(Quit()));
connect(ui->action_Prefrences,SIGNAL(triggered(bool)),this,SLOT(ShowPref()));
connect(ui->BTNConvert,SIGNAL(clicked(bool)),this,SLOT(ConvertClick()));
connect(ui->BTNOpen,SIGNAL(clicked(bool)),this,SLOT(diaglogBatch()));
connect(ui->chkBatch,SIGNAL(clicked(bool)),this,SLOT(toggleBatch(bool)));
}
MainMenu::~MainMenu()
{
delete ui;
}
void MainMenu::Quit()
{
cerr<<"Jerry-Rig is Exiting"<<endl;
qApp->quit();
}
void MainMenu::ShowPref()
{
smenu->show();
}
void MainMenu::ConvertClick()
{
if(this->inputLocal.count()==0)
{
QMessageBox::warning(this,"","You must first open a file to convert");
return;
}
if(ui->chkBatch->checkState()!=Qt::Checked)
{
if(QFile::exists(inputLocal+"_converted.mkv"))
{
cerr<<"File Exits warning"<<endl;
QMessageBox overwriteDialog;
int retVal=overwriteDialog.warning(this,"File Exists", inputLocal+"_converted.mkv" + " already exists. Overwrite?",QMessageBox::Yes,QMessageBox::No);
if(retVal!=QMessageBox::Yes)
{
return;
}
QFile::remove(inputLocal+"_converted.mkv");
}
}else{
convertDir=QDir(inputLocal).absoluteFilePath(QDir(inputLocal).dirName()+"_converted");
if(QDir().mkdir(convertDir) ==false)
{
QMessageBox overwriteDialog;
int retVal=overwriteDialog.warning(this,"Convert DirectoryExists", inputLocal+"_converted" + " already exists. Overwrite?",QMessageBox::Yes,QMessageBox::No);
if(retVal!=QMessageBox::Yes)
{
return;
}
QDir(convertDir).removeRecursively();
QDir().mkdir(convertDir);
}
batchFiles=FetchFileList(inputLocal);
}
BeginWork();
}
void MainMenu::BeginWork()
{
convParams params;
params.Quality=ui->qualBox->currentIndex();
params.Size=ui->sizeBox->currentIndex();
if(this->batchFiles.count()>0)
{
params.input=batchFiles.first();
batchFiles.removeFirst();
}else{
params.input=this->inputLocal;
}
params.batchDir=this->convertDir;
manager=new ProcessManager(this,settings,¶ms);
//remove pesky close buttons and such
manager->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
manager->show();
}
void MainMenu::disposeProcess(int status)
{
manager->close();
if(this->batchFiles.count()>0)
{
//if batch, swallow errors and continue
if(status!=0)
{
cerr<<"Last video failed"<<endl;
}
//repeat until there are no more items
BeginWork();
}else{
QString output;
if(status!=0)
{
output="Processed failed";
QMessageBox::information(this,"Failure","Video Conversion Failed!");
}
else
{
output="Conversion Complete";
QMessageBox::information(this,"Finished","Video Converted!");
}
cerr<<output.toStdString()<<endl;
}
}
void MainMenu::diaglogBatch()
{
if(ui->chkBatch->checkState()==Qt::Checked)
{
inputLocal=QFileDialog::getExistingDirectory(this,"Select directory for batch processing",QDir::homePath());
}else{
inputLocal=QFileDialog::getOpenFileName(this,tr("Select video to convert"),QDir::homePath(),tr("Video Files (*.avi *.mpg *.mkv *.mpeg *.qt *.wmv *.mp4)"));
}
}
void MainMenu::toggleBatch(bool isBatch)
{
if(isBatch)
{
ui->BTNOpen->setText("Choose Directory");
}else{
ui->BTNOpen->setText("Open");
}
if(inputLocal!="")
{
QMessageBox::information(this,"FYI","Current selected file/directory cleared");
inputLocal="";
//just in case..
batchFiles.clear();
convertDir="";
}
}
QList<QString> MainMenu::FetchFileList(QString path)
{
QList<QString> fileList;
if(QDir(path).exists())
{
QDirIterator it(path);
cerr<<"Traversing directory..."<<endl;
QFileInfo info;
while(it.hasNext())
{
it.next();
info=it.fileInfo();
if(!info.isDir() && (info.suffix()=="mkv" || info.suffix()=="avi" || info.suffix()=="mpg" || info.suffix()=="mpeg" || info.suffix()=="qt" || info.suffix()=="wmv" || info.suffix()=="mp4" ))
{
fileList.append(QDir(path).absoluteFilePath(info.fileName()));
cerr<<it.fileName().toStdString()<<endl;
}
}
}
return fileList;
}