-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
68 lines (55 loc) · 2.07 KB
/
main.cpp
File metadata and controls
68 lines (55 loc) · 2.07 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
#include "mainwindow.h"
#include "mediawindow.h"
#include <QCommandLineParser>
#include <QApplication>
#include <QFileInfo>
#include <iostream>
#include <cstdio>
#include <QDir>
extern "C" {
#include <libavutil/log.h>
}
int main(int argc, char *argv[]) {
// Hardware & Driver Silence
qputenv("LIBVA_DRIVER_NAME", "i965");
qputenv("LIBVA_MESSAGING_LEVEL", "0");
qputenv("VDPAU_SUPPRESS_OUTPUT", "1");
qputenv("MESA_LOG_LEVEL", "error");
// Media Engine & Logging Rules
qputenv("QT_MEDIA_BACKEND", "ffmpeg");
qputenv("QT_LOGGING_RULES", "qt.multimedia.*=false;*.debug=false;*.info=false");
av_log_set_level(AV_LOG_QUIET); // Or 'AV_LOG_FATAL'
// Sends all driver "noise" (where the driver logs go) to /dev/null
std::freopen("/dev/null", "w", stderr);
QApplication a(argc, argv);
a.setApplicationVersion("1.0.2");
// ---- Command Line Parsing ----
QCommandLineParser parser;
parser.setApplicationDescription("Dause Media");
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("file", "Optional file to open.");
parser.process(a);
const QStringList args = parser.positionalArguments();
// ------------------------------
MainWindow w;
// Args provided: open media handler
if (!args.isEmpty()) {
QString inputPath = args.at(0);
// Handle (~) expansion for Qt
if (inputPath.startsWith("~")) inputPath.replace(0, 1, QDir::homePath());
QFileInfo fileInfo(inputPath);
if (fileInfo.exists() && fileInfo.isFile()) {
if (MediaWindow::isSupported(inputPath)) w.openMediaFile(fileInfo.absoluteFilePath());
else {
std::cout << "Dause: Format '" << fileInfo.suffix().toStdString()
<< "' is not supported." << std::endl;
return 1;
}
} else {
std::cout << "Dause: '" << inputPath.toStdString() << "' not found." << std::endl;
return 0;
}
} else w.show(); // No args: open terminal
return a.exec();
}