2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2006 Stefan Monov <logixoul@gmail.com>
4 * SPDX-FileCopyrightText: 2015 Mathieu Tarral <mathieu.tarral@gmail.com>
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "dbusinterface.h"
10 #include "dolphin_generalsettings.h"
11 #include "dolphin_version.h"
12 #include "dolphindebug.h"
13 #include "dolphinmainwindow.h"
18 #include <KDBusService>
19 #include <KLocalizedString>
20 #include <Kdelibs4ConfigMigrator>
23 #include <QApplication>
24 #include <QCommandLineParser>
25 #include <QDBusConnection>
26 #include <QDBusInterface>
27 #include <QDBusAbstractInterface>
28 #include <QDBusConnectionInterface>
29 #include <QSessionManager>
36 extern "C" Q_DECL_EXPORT
int kdemain(int argc
, char **argv
)
39 // Prohibit using sudo or kdesu (but allow using the root user directly)
41 if (!qEnvironmentVariableIsEmpty("SUDO_USER")) {
42 std::cout
<< "Executing Dolphin with sudo is not possible due to unfixable security vulnerabilities." << std::endl
;
44 } else if (!qEnvironmentVariableIsEmpty("KDESU_USER")) {
45 std::cout
<< "Executing Dolphin with kdesu is not possible due to unfixable security vulnerabilities." << std::endl
;
52 * enable high dpi support
54 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps
, true);
55 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling
, true);
57 QApplication
app(argc
, argv
);
58 app
.setWindowIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"), app
.windowIcon()));
62 Kdelibs4ConfigMigrator
migrate(QStringLiteral("dolphin"));
63 migrate
.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
64 migrate
.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
67 KLocalizedString::setApplicationDomain("dolphin");
69 KAboutData
aboutData(QStringLiteral("dolphin"), i18n("Dolphin"), QStringLiteral(DOLPHIN_VERSION_STRING
),
70 i18nc("@title", "File Manager"),
72 i18nc("@info:credit", "(C) 2006-2018 Peter Penz, Frank Reininghaus, Emmanuel Pescosta and Elvis Angelaccio"));
73 aboutData
.setHomepage(QStringLiteral("https://kde.org/applications/system/org.kde.dolphin"));
74 aboutData
.addAuthor(i18nc("@info:credit", "Elvis Angelaccio"),
75 i18nc("@info:credit", "Maintainer (since 2018) and developer"),
76 QStringLiteral("elvis.angelaccio@kde.org"));
77 aboutData
.addAuthor(i18nc("@info:credit", "Emmanuel Pescosta"),
78 i18nc("@info:credit", "Maintainer (2014-2018) and developer"),
79 QStringLiteral("emmanuelpescosta099@gmail.com"));
80 aboutData
.addAuthor(i18nc("@info:credit", "Frank Reininghaus"),
81 i18nc("@info:credit", "Maintainer (2012-2014) and developer"),
82 QStringLiteral("frank78ac@googlemail.com"));
83 aboutData
.addAuthor(i18nc("@info:credit", "Peter Penz"),
84 i18nc("@info:credit", "Maintainer and developer (2006-2012)"),
85 QStringLiteral("peter.penz19@gmail.com"));
86 aboutData
.addAuthor(i18nc("@info:credit", "Sebastian Trüg"),
87 i18nc("@info:credit", "Developer"),
88 QStringLiteral("trueg@kde.org"));
89 aboutData
.addAuthor(i18nc("@info:credit", "David Faure"),
90 i18nc("@info:credit", "Developer"),
91 QStringLiteral("faure@kde.org"));
92 aboutData
.addAuthor(i18nc("@info:credit", "Aaron J. Seigo"),
93 i18nc("@info:credit", "Developer"),
94 QStringLiteral("aseigo@kde.org"));
95 aboutData
.addAuthor(i18nc("@info:credit", "Rafael Fernández López"),
96 i18nc("@info:credit", "Developer"),
97 QStringLiteral("ereslibre@kde.org"));
98 aboutData
.addAuthor(i18nc("@info:credit", "Kevin Ottens"),
99 i18nc("@info:credit", "Developer"),
100 QStringLiteral("ervin@kde.org"));
101 aboutData
.addAuthor(i18nc("@info:credit", "Holger Freyther"),
102 i18nc("@info:credit", "Developer"),
103 QStringLiteral("freyther@gmx.net"));
104 aboutData
.addAuthor(i18nc("@info:credit", "Max Blazejak"),
105 i18nc("@info:credit", "Developer"),
106 QStringLiteral("m43ksrocks@gmail.com"));
107 aboutData
.addAuthor(i18nc("@info:credit", "Michael Austin"),
108 i18nc("@info:credit", "Documentation"),
109 QStringLiteral("tuxedup@users.sourceforge.net"));
111 KAboutData::setApplicationData(aboutData
);
113 QCommandLineParser parser
;
114 aboutData
.setupCommandLine(&parser
);
116 // command line options
117 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"), i18nc("@info:shell", "The files and folders passed as arguments "
118 "will be selected.")));
119 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
120 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("new-window"), i18nc("@info:shell", "Dolphin will explicitly open in a new window.")));
121 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface)")));
122 parser
.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open"));
125 aboutData
.processCommandLine(&parser
);
127 const bool splitView
= parser
.isSet(QStringLiteral("split")) || GeneralSettings::splitView();
128 const bool openFiles
= parser
.isSet(QStringLiteral("select"));
129 const QStringList args
= parser
.positionalArguments();
130 QList
<QUrl
> urls
= Dolphin::validateUris(args
);
131 // We later mutate urls, so we need to store if it was empty originally
132 const bool startedWithURLs
= !urls
.isEmpty();
135 if (parser
.isSet(QStringLiteral("daemon"))) {
136 // Disable session management for the daemonized version
137 // See https://bugs.kde.org/show_bug.cgi?id=417219
138 auto disableSessionManagement
= [](QSessionManager
&sm
) {
139 sm
.setRestartHint(QSessionManager::RestartNever
);
141 QObject::connect(&app
, &QGuiApplication::commitDataRequest
, disableSessionManagement
);
142 QObject::connect(&app
, &QGuiApplication::saveStateRequest
, disableSessionManagement
);
144 KDBusService dolphinDBusService
;
145 DBusInterface interface
;
146 interface
.setAsDaemon();
150 if (!parser
.isSet(QStringLiteral("new-window"))) {
151 if (Dolphin::attachToExistingInstance(urls
, openFiles
, splitView
)) {
152 // Successfully attached to existing instance of Dolphin
157 if (!startedWithURLs
) {
158 // We need at least one URL to open Dolphin
159 urls
.append(Dolphin::homeUrl());
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());
167 DolphinMainWindow
* mainWindow
= new DolphinMainWindow();
170 mainWindow
->openFiles(urls
, splitView
);
172 mainWindow
->openDirectories(urls
, splitView
);
177 KDBusService dolphinDBusService
;
178 DBusInterface interface
;
180 if (!app
.isSessionRestored()) {
181 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
184 // Only restore session if:
185 // 1. Not explicitly opening a new instance
186 // 2. The "remember state" setting is enabled or session restoration after
188 // 3. There is a session available to restore
189 if (!parser
.isSet(QStringLiteral("new-window"))
190 && (app
.isSessionRestored() || GeneralSettings::rememberOpenedTabs())
192 // Get saved state data for the last-closed Dolphin instance
193 const QString serviceName
= QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid());
194 if (Dolphin::dolphinGuiInstances(serviceName
).size() > 0) {
195 const QString className
= KXmlGuiWindow::classNameOfToplevel(1);
196 if (className
== QLatin1String("DolphinMainWindow")) {
197 mainWindow
->restore(1);
198 // If the user passed any URLs to Dolphin, open those in the
199 // window after session-restoring it
200 if (startedWithURLs
) {
201 mainWindow
->openDirectories(urls
, splitView
);
204 // Now handle invalid locations in the set of active views to
205 // avoid issues like https://bugs.kde.org/show_bug.cgi?id=427619
206 mainWindow
->setViewsWithInvalidPathsToHome();
208 qCWarning(DolphinDebug
) << "Unknown class " << className
<< " in session saved data!";
213 return app
.exec(); // krazy:exclude=crash;