forked from magnus-ISU/selectdefaultapplication
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
74 lines (63 loc) · 2.22 KB
/
main.cpp
File metadata and controls
74 lines (63 loc) · 2.22 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
69
70
71
72
73
74
#include "selectdefaultapplication.h"
#include <QApplication>
#include <QCoreApplication>
#include <QCommandLineParser>
#include <QLoggingCategory>
#include <QString>
int main(int argc, char *argv[])
{
// Check for help/version flags to avoid loading QWidget/Gui logic for CLI tasks
bool isGui = true;
for (int i = 1; i < argc; ++i) {
QString arg = QString::fromLocal8Bit(argv[i]);
if (arg == "-h" || arg == "--help" || arg == "--help-all" || arg == "-v" || arg == "--version") {
isGui = false;
break;
}
}
if (!isGui) {
QCoreApplication a(argc, argv);
a.setApplicationVersion("2.1");
a.setApplicationName("Select Default Application"); // Console apps use Name usually
QCommandLineParser parser;
parser.setApplicationDescription(QCoreApplication::translate(
"main", "A simple application to manage default MIME type associations on Linux."));
parser.addHelpOption();
parser.addVersionOption();
QCommandLineOption verbose({ "V", "verbose" },
QCoreApplication::translate(
"main",
"Print verbose information about how the desktop files are parsed"));
parser.addOption(verbose);
parser.parse(a.arguments());
if (parser.isSet("help")) {
puts(qPrintable(parser.helpText()));
return 0;
}
if (parser.isSet("version")) {
printf("%s %s\n", qPrintable(a.applicationName()), qPrintable(a.applicationVersion()));
return 0;
}
// Fallback if loop detected help/version but parser didn't see it (unlikely)
return 0;
}
QApplication a(argc, argv);
a.setApplicationVersion("2.1");
a.setApplicationDisplayName("Select Default Application");
QCommandLineParser parser;
parser.setApplicationDescription(QCoreApplication::translate(
"main", "A simple application to manage default MIME type associations on Linux."));
parser.addHelpOption();
parser.addVersionOption();
QCommandLineOption verbose({ "V", "verbose" },
QCoreApplication::translate(
"main", "Print verbose information about how the desktop files are parsed"));
parser.addOption(verbose);
parser.process(a);
if (parser.isSet(verbose)) {
QLoggingCategory::setFilterRules(QStringLiteral("sda.log.debug=true"));
}
SelectDefaultApplication w(nullptr, parser.isSet(verbose));
w.show();
return a.exec();
}