-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
executable file
·106 lines (89 loc) · 3.69 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
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
/* Copyright 2016 Pascal COMBES <[email protected]>
*
* This file is part of ProSlideShower.
*
* ProSlideShower is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ProSlideShower is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProSlideShower. If not, see <http://www.gnu.org/licenses/>
*/
#include "projmanager.h"
#include "presmodel.h"
#include <QTranslator>
#include <QApplication>
#include <QCommandLineParser>
#include <QtDebug>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
app.setOrganizationName("Pascom");
app.setApplicationName("ProSlideShower");
app.setApplicationVersion("0.0.1");
// Command line arguments parsing
QCommandLineParser parser;
parser.setApplicationDescription(QCoreApplication::translate("main", "A small software to show your slides like a professional"));
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("filepath", QCoreApplication::translate("main", "Presentation file path."));
QCommandLineOption minutesOption(QStringList() << "m" << "minues", QCoreApplication::translate("main", "Presentation duration in minutes (adds up with hours)."), "0");
parser.addOption(minutesOption);
QCommandLineOption hoursOption(QStringList() << "o" << "hours", QCoreApplication::translate("main", "Presentation duration in hours (adds up with minutes)."), "0");
parser.addOption(hoursOption);
QCommandLineOption screensOption(QStringList() << "s" << "screens", QCoreApplication::translate("main", "Number of horizontal virtual screens in presentation file."), "1");
parser.addOption(screensOption);
parser.process(qApp->arguments());
// Total time from command line
bool ok;
QTime totalTime(0, 0, 0);
ok = false;
int minutes = parser.value(minutesOption).toInt(&ok, 10);
if (ok)
totalTime = totalTime.addSecs(minutes * 60);
ok = false;
int hours = parser.value(hoursOption).toInt(&ok, 10);
if (ok)
totalTime = totalTime.addSecs(hours * 3600);
qDebug() << hours << minutes << totalTime;
// Screens from command line
ok = false;
int screens = parser.value(screensOption).toInt(&ok, 10);
if (!ok)
screens = 0;
// Translator
QTranslator translator(NULL);
foreach (QString lang, QLocale::system().uiLanguages()) {
QString qmFile = QString(QLatin1String("proslideshower_%1.qm")).arg(lang);
if (translator.load(qmFile, ".."))
break;
if (lang.length() > 2) {
qmFile = QString(QLatin1String("proslideshower_%1.qm")).arg(lang.left(2));
if (translator.load(qmFile, ".."))
break;
}
}
// GUI style
app.setStyle(new PresStyle());
if (!translator.isEmpty())
app.installTranslator(&translator);
else
qWarning() << "Could not find a translator.";
ProjManager manager(NULL);
if ((totalTime.hour() != 0) || (totalTime.minute() != 0))
manager.setTotalTime(totalTime);
if (parser.positionalArguments().size() >= 1) {
PresModel* model = new PresModel(parser.positionalArguments().at(0));
if (screens != 0)
model->setVirtualScreens(screens);
manager.setModel(model);
}
Q_UNUSED(manager);
return app.exec();
}