]> cloud.milkyroute.net Git - dolphin.git/blob - src/main.cpp
Fix indentation
[dolphin.git] / src / main.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2015 by Mathieu Tarral <mathieu.tarral@gmail.com> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #include "dbusinterface.h"
23 #include "dolphin_generalsettings.h"
24 #include "dolphin_version.h"
25 #include "dolphindebug.h"
26 #include "dolphinmainwindow.h"
27 #include "global.h"
28
29 #include <KAboutData>
30 #include <KCrash>
31 #include <KDBusService>
32 #include <KLocalizedString>
33 #include <Kdelibs4ConfigMigrator>
34
35 #include <QApplication>
36 #include <QCommandLineParser>
37
38 #ifndef Q_OS_WIN
39 #include <unistd.h>
40 #endif
41 #include <iostream>
42
43 extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
44 {
45 #ifndef Q_OS_WIN
46 // Prohibit using sudo or kdesu (but allow using the root user directly)
47 if (getuid() == 0) {
48 if (!qEnvironmentVariableIsEmpty("SUDO_USER")) {
49 std::cout << "Executing Dolphin with sudo is not possible due to unfixable security vulnerabilities." << std::endl;
50 return EXIT_FAILURE;
51 } else if (!qEnvironmentVariableIsEmpty("KDESU_USER")) {
52 std::cout << "Executing Dolphin with kdesu is not possible due to unfixable security vulnerabilities." << std::endl;
53 return EXIT_FAILURE;
54 }
55 }
56 #endif
57
58 QApplication app(argc, argv);
59 app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
60 app.setWindowIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"), app.windowIcon()));
61
62 KCrash::initialize();
63
64 Kdelibs4ConfigMigrator migrate(QStringLiteral("dolphin"));
65 migrate.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
66 migrate.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
67 migrate.migrate();
68
69 KLocalizedString::setApplicationDomain("dolphin");
70
71 KAboutData aboutData(QStringLiteral("dolphin"), i18n("Dolphin"), QStringLiteral(DOLPHIN_VERSION_STRING),
72 i18nc("@title", "File Manager"),
73 KAboutLicense::GPL,
74 i18nc("@info:credit", "(C) 2006-2018 Peter Penz, Frank Reininghaus, Emmanuel Pescosta and Elvis Angelaccio"));
75 aboutData.setHomepage(QStringLiteral("https://dolphin.kde.org"));
76 aboutData.addAuthor(i18nc("@info:credit", "Elvis Angelaccio"),
77 i18nc("@info:credit", "Maintainer (since 2018) and developer"),
78 QStringLiteral("elvis.angelaccio@kde.org"));
79 aboutData.addAuthor(i18nc("@info:credit", "Emmanuel Pescosta"),
80 i18nc("@info:credit", "Maintainer (2014-2018) and developer"),
81 QStringLiteral("emmanuelpescosta099@gmail.com"));
82 aboutData.addAuthor(i18nc("@info:credit", "Frank Reininghaus"),
83 i18nc("@info:credit", "Maintainer (2012-2014) and developer"),
84 QStringLiteral("frank78ac@googlemail.com"));
85 aboutData.addAuthor(i18nc("@info:credit", "Peter Penz"),
86 i18nc("@info:credit", "Maintainer and developer (2006-2012)"),
87 QStringLiteral("peter.penz19@gmail.com"));
88 aboutData.addAuthor(i18nc("@info:credit", "Sebastian Trüg"),
89 i18nc("@info:credit", "Developer"),
90 QStringLiteral("trueg@kde.org"));
91 aboutData.addAuthor(i18nc("@info:credit", "David Faure"),
92 i18nc("@info:credit", "Developer"),
93 QStringLiteral("faure@kde.org"));
94 aboutData.addAuthor(i18nc("@info:credit", "Aaron J. Seigo"),
95 i18nc("@info:credit", "Developer"),
96 QStringLiteral("aseigo@kde.org"));
97 aboutData.addAuthor(i18nc("@info:credit", "Rafael Fernández López"),
98 i18nc("@info:credit", "Developer"),
99 QStringLiteral("ereslibre@kde.org"));
100 aboutData.addAuthor(i18nc("@info:credit", "Kevin Ottens"),
101 i18nc("@info:credit", "Developer"),
102 QStringLiteral("ervin@kde.org"));
103 aboutData.addAuthor(i18nc("@info:credit", "Holger Freyther"),
104 i18nc("@info:credit", "Developer"),
105 QStringLiteral("freyther@gmx.net"));
106 aboutData.addAuthor(i18nc("@info:credit", "Max Blazejak"),
107 i18nc("@info:credit", "Developer"),
108 QStringLiteral("m43ksrocks@gmail.com"));
109 aboutData.addAuthor(i18nc("@info:credit", "Michael Austin"),
110 i18nc("@info:credit", "Documentation"),
111 QStringLiteral("tuxedup@users.sourceforge.net"));
112
113 KAboutData::setApplicationData(aboutData);
114
115 KDBusService dolphinDBusService;
116 DBusInterface interface;
117
118 QCommandLineParser parser;
119 aboutData.setupCommandLine(&parser);
120
121 // command line options
122 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"), i18nc("@info:shell", "The files and folders passed as arguments "
123 "will be selected.")));
124 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
125 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface)")));
126 parser.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open"));
127
128 parser.process(app);
129 aboutData.processCommandLine(&parser);
130
131 if (parser.isSet(QStringLiteral("daemon"))) {
132 return app.exec();
133 }
134
135 const QStringList args = parser.positionalArguments();
136 QList<QUrl> urls = Dolphin::validateUris(args);
137
138 if (urls.isEmpty()) {
139 // We need at least one URL to open Dolphin
140 urls.append(Dolphin::homeUrl());
141 }
142
143 const bool splitView = parser.isSet(QStringLiteral("split")) || GeneralSettings::splitView();
144 if (splitView && urls.size() < 2) {
145 // Split view does only make sense if we have at least 2 URLs
146 urls.append(urls.last());
147 }
148
149 DolphinMainWindow* mainWindow = new DolphinMainWindow();
150
151 if (parser.isSet(QStringLiteral("select"))) {
152 mainWindow->openFiles(urls, splitView);
153 } else {
154 mainWindow->openDirectories(urls, splitView);
155 }
156
157 mainWindow->show();
158
159 if (app.isSessionRestored()) {
160 const QString className = KXmlGuiWindow::classNameOfToplevel(1);
161 if (className == QLatin1String("DolphinMainWindow")) {
162 mainWindow->restore(1);
163 } else {
164 qCWarning(DolphinDebug) << "Unknown class " << className << " in session saved data!";
165 }
166 }
167
168 return app.exec(); // krazy:exclude=crash;
169 }