]> cloud.milkyroute.net Git - dolphin.git/blob - src/main.cpp
Merge branch 'release/20.04'
[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 #include <QDBusConnection>
38 #include <QDBusInterface>
39 #include <QDBusAbstractInterface>
40 #include <QDBusConnectionInterface>
41
42 #ifndef Q_OS_WIN
43 #include <unistd.h>
44 #endif
45 #include <iostream>
46
47 extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
48 {
49 #ifndef Q_OS_WIN
50 // Prohibit using sudo or kdesu (but allow using the root user directly)
51 if (getuid() == 0) {
52 if (!qEnvironmentVariableIsEmpty("SUDO_USER")) {
53 std::cout << "Executing Dolphin with sudo is not possible due to unfixable security vulnerabilities." << std::endl;
54 return EXIT_FAILURE;
55 } else if (!qEnvironmentVariableIsEmpty("KDESU_USER")) {
56 std::cout << "Executing Dolphin with kdesu is not possible due to unfixable security vulnerabilities." << std::endl;
57 return EXIT_FAILURE;
58 }
59 }
60 #endif
61
62 /**
63 * enable high dpi support
64 */
65 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
66 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
67
68 QApplication app(argc, argv);
69 app.setWindowIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"), app.windowIcon()));
70
71 KCrash::initialize();
72
73 Kdelibs4ConfigMigrator migrate(QStringLiteral("dolphin"));
74 migrate.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
75 migrate.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
76 migrate.migrate();
77
78 KLocalizedString::setApplicationDomain("dolphin");
79
80 KAboutData aboutData(QStringLiteral("dolphin"), i18n("Dolphin"), QStringLiteral(DOLPHIN_VERSION_STRING),
81 i18nc("@title", "File Manager"),
82 KAboutLicense::GPL,
83 i18nc("@info:credit", "(C) 2006-2018 Peter Penz, Frank Reininghaus, Emmanuel Pescosta and Elvis Angelaccio"));
84 aboutData.setHomepage(QStringLiteral("https://kde.org/applications/system/org.kde.dolphin"));
85 aboutData.addAuthor(i18nc("@info:credit", "Elvis Angelaccio"),
86 i18nc("@info:credit", "Maintainer (since 2018) and developer"),
87 QStringLiteral("elvis.angelaccio@kde.org"));
88 aboutData.addAuthor(i18nc("@info:credit", "Emmanuel Pescosta"),
89 i18nc("@info:credit", "Maintainer (2014-2018) and developer"),
90 QStringLiteral("emmanuelpescosta099@gmail.com"));
91 aboutData.addAuthor(i18nc("@info:credit", "Frank Reininghaus"),
92 i18nc("@info:credit", "Maintainer (2012-2014) and developer"),
93 QStringLiteral("frank78ac@googlemail.com"));
94 aboutData.addAuthor(i18nc("@info:credit", "Peter Penz"),
95 i18nc("@info:credit", "Maintainer and developer (2006-2012)"),
96 QStringLiteral("peter.penz19@gmail.com"));
97 aboutData.addAuthor(i18nc("@info:credit", "Sebastian Trüg"),
98 i18nc("@info:credit", "Developer"),
99 QStringLiteral("trueg@kde.org"));
100 aboutData.addAuthor(i18nc("@info:credit", "David Faure"),
101 i18nc("@info:credit", "Developer"),
102 QStringLiteral("faure@kde.org"));
103 aboutData.addAuthor(i18nc("@info:credit", "Aaron J. Seigo"),
104 i18nc("@info:credit", "Developer"),
105 QStringLiteral("aseigo@kde.org"));
106 aboutData.addAuthor(i18nc("@info:credit", "Rafael Fernández López"),
107 i18nc("@info:credit", "Developer"),
108 QStringLiteral("ereslibre@kde.org"));
109 aboutData.addAuthor(i18nc("@info:credit", "Kevin Ottens"),
110 i18nc("@info:credit", "Developer"),
111 QStringLiteral("ervin@kde.org"));
112 aboutData.addAuthor(i18nc("@info:credit", "Holger Freyther"),
113 i18nc("@info:credit", "Developer"),
114 QStringLiteral("freyther@gmx.net"));
115 aboutData.addAuthor(i18nc("@info:credit", "Max Blazejak"),
116 i18nc("@info:credit", "Developer"),
117 QStringLiteral("m43ksrocks@gmail.com"));
118 aboutData.addAuthor(i18nc("@info:credit", "Michael Austin"),
119 i18nc("@info:credit", "Documentation"),
120 QStringLiteral("tuxedup@users.sourceforge.net"));
121
122 KAboutData::setApplicationData(aboutData);
123
124 QCommandLineParser parser;
125 aboutData.setupCommandLine(&parser);
126
127 // command line options
128 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"), i18nc("@info:shell", "The files and folders passed as arguments "
129 "will be selected.")));
130 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
131 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("new-window"), i18nc("@info:shell", "Dolphin will explicitly open in a new window.")));
132 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface)")));
133 parser.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open"));
134
135 parser.process(app);
136 aboutData.processCommandLine(&parser);
137
138 const bool splitView = parser.isSet(QStringLiteral("split")) || GeneralSettings::splitView();
139 const bool openFiles = parser.isSet(QStringLiteral("select"));
140 const QStringList args = parser.positionalArguments();
141 QList<QUrl> urls = Dolphin::validateUris(args);
142
143 if (parser.isSet(QStringLiteral("daemon"))) {
144 KDBusService dolphinDBusService;
145 DBusInterface interface;
146 interface.setAsDaemon();
147 return app.exec();
148 }
149
150 if (!parser.isSet(QStringLiteral("new-window"))) {
151 if (Dolphin::attachToExistingInstance(urls, openFiles, splitView)) {
152 // Successfully attached to existing instance of Dolphin
153 return 0;
154 }
155 }
156
157 if (urls.isEmpty()) {
158 // We need at least one URL to open Dolphin
159 urls.append(Dolphin::homeUrl());
160 }
161
162 if (splitView && urls.size() < 2) {
163 // Split view does only make sense if we have at least 2 URLs
164 urls.append(urls.last());
165 }
166
167 DolphinMainWindow* mainWindow = new DolphinMainWindow();
168
169 if (openFiles) {
170 mainWindow->openFiles(urls, splitView);
171 } else {
172 mainWindow->openDirectories(urls, splitView);
173 }
174
175 mainWindow->show();
176
177 if (app.isSessionRestored()) {
178 const QString className = KXmlGuiWindow::classNameOfToplevel(1);
179 if (className == QLatin1String("DolphinMainWindow")) {
180 mainWindow->restore(1);
181 } else {
182 qCWarning(DolphinDebug) << "Unknown class " << className << " in session saved data!";
183 }
184 }
185
186 KDBusService dolphinDBusService;
187 DBusInterface interface;
188
189 return app.exec(); // krazy:exclude=crash;
190 }