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 "config-dolphin.h"
10 #include "dbusinterface.h"
11 #include "dolphin_generalsettings.h"
12 #include "dolphin_version.h"
13 #include "dolphindebug.h"
14 #include "dolphinmainwindow.h"
16 #if HAVE_KUSERFEEDBACK
17 #include "userfeedback/dolphinfeedbackprovider.h"
23 #include <KDBusService>
24 #include <KIO/PreviewJob>
25 #include <KLocalizedString>
26 #include <KWindowSystem>
28 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
29 #include <Kdelibs4ConfigMigrator>
32 #include <QApplication>
33 #include <QCommandLineParser>
34 #include <QDBusConnection>
35 #include <QDBusConnectionInterface>
36 #include <QSessionManager>
39 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
40 #include <private/qtx11extras_p.h>
51 int main(int argc
, char **argv
)
54 // Prohibit using sudo or kdesu (but allow using the root user directly)
56 if (!qEnvironmentVariableIsEmpty("SUDO_USER")) {
57 std::cout
<< "Running Dolphin with sudo is not supported as it can cause bugs and expose you to security vulnerabilities. Instead, install the "
58 "`kio-admin` package from your distro and use it to manage root-owned locations by right-clicking on them and selecting \"Open as "
62 } else if (!qEnvironmentVariableIsEmpty("KDESU_USER")) {
63 std::cout
<< "Running Dolphin with kdesu is not supported as it can cause bugs and expose you to security vulnerabilities. Instead, install the "
64 "`kio-admin` package from your distro and use it to manage root-owned locations by right-clicking on them and selecting \"Open as "
73 * enable high dpi support
75 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
76 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps
, true);
77 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling
, true);
79 QApplication
app(argc
, argv
);
80 app
.setWindowIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"), app
.windowIcon()));
82 KIO::PreviewJob::setDefaultDevicePixelRatio(app
.devicePixelRatio());
86 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
87 Kdelibs4ConfigMigrator
migrate(QStringLiteral("dolphin"));
88 migrate
.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
89 migrate
.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
93 KLocalizedString::setApplicationDomain("dolphin");
95 KAboutData
aboutData(QStringLiteral("dolphin"),
97 QStringLiteral(DOLPHIN_VERSION_STRING
),
98 i18nc("@title", "File Manager"),
100 i18nc("@info:credit", "(C) 2006-2022 The Dolphin Developers"));
101 aboutData
.setHomepage(QStringLiteral("https://kde.org/applications/system/org.kde.dolphin"));
102 aboutData
.addAuthor(i18nc("@info:credit", "Felix Ernst"),
103 i18nc("@info:credit", "Maintainer (since 2021) and developer"),
104 QStringLiteral("felixernst@kde.org"));
105 aboutData
.addAuthor(i18nc("@info:credit", "Méven Car"),
106 i18nc("@info:credit", "Maintainer (since 2021) and developer (since 2019)"),
107 QStringLiteral("meven@kde.org"));
108 aboutData
.addAuthor(i18nc("@info:credit", "Elvis Angelaccio"),
109 i18nc("@info:credit", "Maintainer (2018-2021) and developer"),
110 QStringLiteral("elvis.angelaccio@kde.org"));
111 aboutData
.addAuthor(i18nc("@info:credit", "Emmanuel Pescosta"),
112 i18nc("@info:credit", "Maintainer (2014-2018) and developer"),
113 QStringLiteral("emmanuelpescosta099@gmail.com"));
114 aboutData
.addAuthor(i18nc("@info:credit", "Frank Reininghaus"),
115 i18nc("@info:credit", "Maintainer (2012-2014) and developer"),
116 QStringLiteral("frank78ac@googlemail.com"));
117 aboutData
.addAuthor(i18nc("@info:credit", "Peter Penz"),
118 i18nc("@info:credit", "Maintainer and developer (2006-2012)"),
119 QStringLiteral("peter.penz19@gmail.com"));
120 aboutData
.addAuthor(i18nc("@info:credit", "Sebastian Trüg"), i18nc("@info:credit", "Developer"), QStringLiteral("trueg@kde.org"));
121 aboutData
.addAuthor(i18nc("@info:credit", "David Faure"), i18nc("@info:credit", "Developer"), QStringLiteral("faure@kde.org"));
122 aboutData
.addAuthor(i18nc("@info:credit", "Aaron J. Seigo"), i18nc("@info:credit", "Developer"), QStringLiteral("aseigo@kde.org"));
123 aboutData
.addAuthor(i18nc("@info:credit", "Rafael Fernández López"), i18nc("@info:credit", "Developer"), QStringLiteral("ereslibre@kde.org"));
124 aboutData
.addAuthor(i18nc("@info:credit", "Kevin Ottens"), i18nc("@info:credit", "Developer"), QStringLiteral("ervin@kde.org"));
125 aboutData
.addAuthor(i18nc("@info:credit", "Holger Freyther"), i18nc("@info:credit", "Developer"), QStringLiteral("freyther@gmx.net"));
126 aboutData
.addAuthor(i18nc("@info:credit", "Max Blazejak"), i18nc("@info:credit", "Developer"), QStringLiteral("m43ksrocks@gmail.com"));
127 aboutData
.addAuthor(i18nc("@info:credit", "Michael Austin"), i18nc("@info:credit", "Documentation"), QStringLiteral("tuxedup@users.sourceforge.net"));
129 KAboutData::setApplicationData(aboutData
);
131 QCommandLineParser parser
;
132 aboutData
.setupCommandLine(&parser
);
134 // command line options
135 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"),
137 "The files and folders passed as arguments "
138 "will be selected.")));
139 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
140 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("new-window"), i18nc("@info:shell", "Dolphin will explicitly open in a new window.")));
142 QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface).")));
143 parser
.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open"));
146 aboutData
.processCommandLine(&parser
);
148 const bool splitView
= parser
.isSet(QStringLiteral("split")) || GeneralSettings::splitView();
149 const bool openFiles
= parser
.isSet(QStringLiteral("select"));
150 const QStringList args
= parser
.positionalArguments();
151 QList
<QUrl
> urls
= Dolphin::validateUris(args
);
152 // We later mutate urls, so we need to store if it was empty originally
153 const bool startedWithURLs
= !urls
.isEmpty();
155 if (parser
.isSet(QStringLiteral("daemon"))) {
156 // Disable session management for the daemonized version
157 // See https://bugs.kde.org/show_bug.cgi?id=417219
158 auto disableSessionManagement
= [](QSessionManager
&sm
) {
159 sm
.setRestartHint(QSessionManager::RestartNever
);
161 QObject::connect(&app
, &QGuiApplication::commitDataRequest
, disableSessionManagement
);
162 QObject::connect(&app
, &QGuiApplication::saveStateRequest
, disableSessionManagement
);
165 KDBusService
dolphinDBusService(KDBusService::NoExitOnFailure
);
167 KDBusService dolphinDBusService
;
169 DBusInterface interface
;
170 interface
.setAsDaemon();
174 if (!parser
.isSet(QStringLiteral("new-window"))) {
176 if (KWindowSystem::isPlatformWayland()) {
177 token
= qEnvironmentVariable("XDG_ACTIVATION_TOKEN");
178 qunsetenv("XDG_ACTIVATION_TOKEN");
179 } else if (KWindowSystem::isPlatformX11()) {
181 token
= QX11Info::nextStartupId();
185 if (Dolphin::attachToExistingInstance(urls
, openFiles
, splitView
, QString(), token
)) {
186 // Successfully attached to existing instance of Dolphin
191 if (!startedWithURLs
) {
192 // We need at least one URL to open Dolphin
193 urls
.append(Dolphin::homeUrl());
196 if (splitView
&& urls
.size() < 2) {
197 // Split view does only make sense if we have at least 2 URLs
198 urls
.append(urls
.last());
201 DolphinMainWindow
*mainWindow
= new DolphinMainWindow();
204 mainWindow
->openFiles(urls
, splitView
);
206 mainWindow
->openDirectories(urls
, splitView
);
211 // Allow starting Dolphin on a system that is not running DBus:
212 KDBusService::StartupOptions serviceOptions
= KDBusService::Multiple
;
213 if (!QDBusConnection::sessionBus().isConnected()) {
214 serviceOptions
|= KDBusService::NoExitOnFailure
;
216 KDBusService
dolphinDBusService(serviceOptions
);
217 DBusInterface interface
;
219 if (!app
.isSessionRestored()) {
220 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
223 // Only restore session if:
224 // 1. Not explicitly opening a new instance
225 // 2. The "remember state" setting is enabled or session restoration after
227 // 3. There is a session available to restore
228 if (!parser
.isSet(QStringLiteral("new-window")) && (app
.isSessionRestored() || GeneralSettings::rememberOpenedTabs())) {
229 // Get saved state data for the last-closed Dolphin instance
230 const QString serviceName
= QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid());
231 if (Dolphin::dolphinGuiInstances(serviceName
).size() > 0) {
232 const QString className
= KXmlGuiWindow::classNameOfToplevel(1);
233 if (className
== QLatin1String("DolphinMainWindow")) {
234 mainWindow
->restore(1);
235 // If the user passed any URLs to Dolphin, open those in the
236 // window after session-restoring it
237 if (startedWithURLs
) {
239 mainWindow
->openFiles(urls
, splitView
);
241 mainWindow
->openDirectories(urls
, splitView
);
245 qCWarning(DolphinDebug
) << "Unknown class " << className
<< " in session saved data!";
250 #if HAVE_KUSERFEEDBACK
251 auto feedbackProvider
= DolphinFeedbackProvider::instance();
252 Q_UNUSED(feedbackProvider
)
255 return app
.exec(); // krazy:exclude=crash;