-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
56 lines (52 loc) · 1.89 KB
/
main.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
#include "mainwindow.h"
#include <iostream>
#include <QApplication>
#include <QFileInfo>
#include <QDir>
#include <QDirIterator>
#define WRONG_NUMBER_OF_PARAMETERS_ERROR 1
#define NON_EXISTENT_FILE_ERROR 2
#define NON_EXISTENT_DIRECTORY_ERROR 3
#define NO_SUBTITLE_FILE_FOUND_ERROR 4
using namespace std;
int main(int argc, char *argv[])
{
if (argc != 2) {
// NOTE: Currently I do not have a file picker ready. So I have to expect a file name in command line arguments.
// TODO: Add function to start with no file open and open file with FilePicker
cerr << "Wrong number of parameters. Read manual" << endl;
return WRONG_NUMBER_OF_PARAMETERS_ERROR;
} else {
QString filename(argv[1]);
QFileInfo videoFile(filename);
if (!videoFile.exists()) {
cerr << "Targeted file does not exist! Read manual" << endl;
return NON_EXISTENT_FILE_ERROR;
}
QString basename = videoFile.baseName();
QDir dir = videoFile.absoluteDir();
if (!dir.exists()) {
cerr << "You are in a non-existent directory! This should not happen" << endl;
return NON_EXISTENT_DIRECTORY_ERROR;
}
QDirIterator it(dir, QDirIterator::Subdirectories);
QString subfilename = "";
while (it.hasNext()) {
it.next();
QFileInfo subfile = it.fileInfo();
if (subfile.exists() && subfile.suffix() == "srt") {
if (subfile.baseName().startsWith(basename,Qt::CaseInsensitive)) {
subfilename = subfile.filePath();
}
}
}
if (subfilename == "") {
cerr << "No correct subtitle file found! Exiting" << endl;
return NO_SUBTITLE_FILE_FOUND_ERROR;
}
QApplication a(argc, argv);
MainWindow w(subfilename);
w.show();
return a.exec();
}
}