Changeset View
Changeset View
Standalone View
Standalone View
templates/kpartsapp/src/shell/main.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) %{CURRENT_YEAR} by %{AUTHOR} <%{EMAIL}> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU General Public License as published by | ||||
6 | * the Free Software Foundation; either version 2 of the License, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU General Public License | ||||
15 | * along with this program; if not, write to the | ||||
16 | * Free Software Foundation, Inc., | ||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . | ||||
18 | */ | ||||
19 | | ||||
20 | #include "%{APPNAMELC}shell.h" | ||||
21 | | ||||
22 | // KF headers | ||||
23 | #include <KAboutData> | ||||
24 | #include <KLocalizedString> | ||||
25 | | ||||
26 | // Qt headers | ||||
27 | #include <QApplication> | ||||
28 | #include <QCommandLineParser> | ||||
29 | #include <QUrl> | ||||
30 | #include <QDir> | ||||
31 | #include <QIcon> | ||||
32 | | ||||
33 | int main(int argc, char **argv) | ||||
34 | { | ||||
35 | QApplication app(argc, argv); | ||||
36 | | ||||
37 | KLocalizedString::setApplicationDomain("%{APPNAMELC}"); | ||||
38 | | ||||
39 | KAboutData aboutData(QStringLiteral("%{APPNAMELC}"), | ||||
40 | i18n("%{APPNAME}"), | ||||
41 | QStringLiteral("%{VERSION}"), | ||||
42 | i18n("A KPart Application"), | ||||
43 | KAboutLicense::GPL, | ||||
44 | i18n("Copyright %{CURRENT_YEAR} %{AUTHOR}")); | ||||
45 | aboutData.addAuthor(i18n("%{AUTHOR}"), i18n("Author"), QStringLiteral("%{EMAIL}")); | ||||
46 | aboutData.setOrganizationDomain("example.org"); | ||||
47 | aboutData.setDesktopFileName(QStringLiteral("org.example.%{APPNAMELC}")); | ||||
48 | | ||||
49 | KAboutData::setApplicationData(aboutData); | ||||
50 | app.setWindowIcon(QIcon::fromTheme(QStringLiteral("%{APPNAMELC}"))); | ||||
51 | | ||||
52 | QCommandLineParser parser; | ||||
53 | parser.addHelpOption(); | ||||
54 | parser.addVersionOption(); | ||||
55 | aboutData.setupCommandLine(&parser); | ||||
56 | parser.addPositionalArgument(QStringLiteral("urls"), i18n("Document(s) to load."), QStringLiteral("[urls...]")); | ||||
57 | | ||||
58 | parser.process(app); | ||||
59 | aboutData.processCommandLine(&parser); | ||||
60 | | ||||
61 | const auto urls = parser.positionalArguments(); | ||||
62 | | ||||
63 | if (urls.isEmpty()) { | ||||
64 | auto window = new %{APPNAME}Shell; | ||||
65 | window->show(); | ||||
66 | } else { | ||||
67 | for (const auto &url : urls) { | ||||
68 | auto window = new %{APPNAME}Shell; | ||||
69 | window->show(); | ||||
70 | window->loadDocument(QUrl::fromUserInput(url, QDir::currentPath(), QUrl::AssumeLocalFile)); | ||||
71 | } | ||||
72 | } | ||||
73 | | ||||
74 | return app.exec(); | ||||
75 | } |