This repository was archived by the owner on Jun 27, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
102 lines (87 loc) · 3.45 KB
/
Copy pathmain.cpp
File metadata and controls
102 lines (87 loc) · 3.45 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
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
/*
* This file is part of PlantUML QEditor.
*
* PlantUML QEditor 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.
*
* PlantUML QEditor 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 PlantUML QEditor. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QtSingleApplication>
#include <QFileInfo>
#include <QDebug>
#include <QTranslator>
#include "mainwindow.h"
namespace {
const char* APPLICATION_NAME = "PlantUML Editor";
const char* ORGANIZATION_NAME = APPLICATION_NAME;
const char* OPTION_HELP_SHORT = "-h";
const char* OPTION_HELP_LONG = "--help";
const char* OPTION_SINGLE_INSTANCE_SHORT = "-s";
const char* OPTION_SINGLE_INSTANCE_LONG = "--single-instance";
void displayHelp(const char* app_name) {
qDebug() << qPrintable(QString("Usage: %1 [options] [FILE]").arg(QFileInfo(app_name).fileName()));
qDebug() << qPrintable(QString("\n"
"%1 %2 Display this help\n"
"%3 %4 Single-instance mode\n"
"\n"
"If FILE is provided, load it on start. If running in single\n"
"instance mode, the instance is signaled to load FILE.\n")
.arg(OPTION_HELP_SHORT)
.arg(OPTION_HELP_LONG)
.arg(OPTION_SINGLE_INSTANCE_SHORT)
.arg(OPTION_SINGLE_INSTANCE_LONG)
)
;
}
bool singleInstanceModeRequested(QStringList& options) {
bool ret = options.contains("-s") || options.contains("--single-instance");
options.removeAll(OPTION_SINGLE_INSTANCE_LONG);
options.removeAll(OPTION_SINGLE_INSTANCE_SHORT);
return ret;
}
}
int main(int argc, char *argv[])
{
QCoreApplication::setOrganizationName(ORGANIZATION_NAME);
QCoreApplication::setApplicationName(APPLICATION_NAME);
QtSingleApplication a(argc, argv);
QStringList options;
for (int i = 1; i < argc; ++i) {
options << argv[i];
}
if (options.contains(OPTION_HELP_SHORT) || options.contains(OPTION_HELP_LONG)) {
displayHelp(argv[0]);
return 0;
}
bool single_instance_mode = singleInstanceModeRequested(options);
QString open_document_path;
if (options.size() > 0) {
open_document_path = options.last();
}
if (a.isRunning() && single_instance_mode) {
a.sendMessage(open_document_path);
qDebug() << qPrintable(QObject::tr("%1 already running. Requested instance to open: %2. Now exitting...")
.arg(APPLICATION_NAME)
.arg(open_document_path));
return 0;
}
QTranslator appTranslator;
appTranslator.load("plantumlqeditor_" + QLocale::system().name(), "translations");
a.installTranslator(&appTranslator);
MainWindow w;
if (open_document_path.isEmpty()) {
w.newDocument();
} else {
w.openDocument(open_document_path);
}
w.show();
return a.exec();
}