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()));
84 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
85 Kdelibs4ConfigMigrator
migrate(QStringLiteral("dolphin"));
86 migrate
.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
87 migrate
.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
91 KLocalizedString::setApplicationDomain("dolphin");
93 KAboutData
aboutData(QStringLiteral("dolphin"),
95 QStringLiteral(DOLPHIN_VERSION_STRING
),
96 i18nc("@title", "File Manager"),
98 i18nc("@info:credit", "(C) 2006-2022 The Dolphin Developers"));
99 aboutData
.setHomepage(QStringLiteral("https://kde.org/applications/system/org.kde.dolphin"));
100 aboutData
.addAuthor(i18nc("@info:credit", "Felix Ernst"),
101 i18nc("@info:credit", "Maintainer (since 2021) and developer"),
102 QStringLiteral("felixernst@kde.org"));
103 aboutData
.addAuthor(i18nc("@info:credit", "Méven Car"),
104 i18nc("@info:credit", "Maintainer (since 2021) and developer (since 2019)"),
105 QStringLiteral("meven@kde.org"));
106 aboutData
.addAuthor(i18nc("@info:credit", "Elvis Angelaccio"),
107 i18nc("@info:credit", "Maintainer (2018-2021) and developer"),
108 QStringLiteral("elvis.angelaccio@kde.org"));
109 aboutData
.addAuthor(i18nc("@info:credit", "Emmanuel Pescosta"),
110 i18nc("@info:credit", "Maintainer (2014-2018) and developer"),
111 QStringLiteral("emmanuelpescosta099@gmail.com"));
112 aboutData
.addAuthor(i18nc("@info:credit", "Frank Reininghaus"),
113 i18nc("@info:credit", "Maintainer (2012-2014) and developer"),
114 QStringLiteral("frank78ac@googlemail.com"));
115 aboutData
.addAuthor(i18nc("@info:credit", "Peter Penz"),
116 i18nc("@info:credit", "Maintainer and developer (2006-2012)"),
117 QStringLiteral("peter.penz19@gmail.com"));
118 aboutData
.addAuthor(i18nc("@info:credit", "Sebastian Trüg"), i18nc("@info:credit", "Developer"), QStringLiteral("trueg@kde.org"));
119 aboutData
.addAuthor(i18nc("@info:credit", "David Faure"), i18nc("@info:credit", "Developer"), QStringLiteral("faure@kde.org"));
120 aboutData
.addAuthor(i18nc("@info:credit", "Aaron J. Seigo"), i18nc("@info:credit", "Developer"), QStringLiteral("aseigo@kde.org"));
121 aboutData
.addAuthor(i18nc("@info:credit", "Rafael Fernández López"), i18nc("@info:credit", "Developer"), QStringLiteral("ereslibre@kde.org"));
122 aboutData
.addAuthor(i18nc("@info:credit", "Kevin Ottens"), i18nc("@info:credit", "Developer"), QStringLiteral("ervin@kde.org"));
123 aboutData
.addAuthor(i18nc("@info:credit", "Holger Freyther"), i18nc("@info:credit", "Developer"), QStringLiteral("freyther@gmx.net"));
124 aboutData
.addAuthor(i18nc("@info:credit", "Max Blazejak"), i18nc("@info:credit", "Developer"), QStringLiteral("m43ksrocks@gmail.com"));
125 aboutData
.addAuthor(i18nc("@info:credit", "Michael Austin"), i18nc("@info:credit", "Documentation"), QStringLiteral("tuxedup@users.sourceforge.net"));
127 KAboutData::setApplicationData(aboutData
);
129 QCommandLineParser parser
;
130 aboutData
.setupCommandLine(&parser
);
132 // command line options
133 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"),
135 "The files and folders passed as arguments "
136 "will be selected.")));
137 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
138 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("new-window"), i18nc("@info:shell", "Dolphin will explicitly open in a new window.")));
140 QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface).")));
141 parser
.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open"));
144 aboutData
.processCommandLine(&parser
);
146 const bool splitView
= parser
.isSet(QStringLiteral("split")) || GeneralSettings::splitView();
147 const bool openFiles
= parser
.isSet(QStringLiteral("select"));
148 const QStringList args
= parser
.positionalArguments();
149 QList
<QUrl
> urls
= Dolphin::validateUris(args
);
150 // We later mutate urls, so we need to store if it was empty originally
151 const bool startedWithURLs
= !urls
.isEmpty();
153 if (parser
.isSet(QStringLiteral("daemon"))) {
154 // Disable session management for the daemonized version
155 // See https://bugs.kde.org/show_bug.cgi?id=417219
156 auto disableSessionManagement
= [](QSessionManager
&sm
) {
157 sm
.setRestartHint(QSessionManager::RestartNever
);
159 QObject::connect(&app
, &QGuiApplication::commitDataRequest
, disableSessionManagement
);
160 QObject::connect(&app
, &QGuiApplication::saveStateRequest
, disableSessionManagement
);
163 KDBusService
dolphinDBusService(KDBusService::NoExitOnFailure
);
165 KDBusService dolphinDBusService
;
167 DBusInterface interface
;
168 interface
.setAsDaemon();
172 if (!parser
.isSet(QStringLiteral("new-window"))) {
174 if (KWindowSystem::isPlatformWayland()) {
175 token
= qEnvironmentVariable("XDG_ACTIVATION_TOKEN");
176 qunsetenv("XDG_ACTIVATION_TOKEN");
177 } else if (KWindowSystem::isPlatformX11()) {
179 token
= QX11Info::nextStartupId();
183 if (Dolphin::attachToExistingInstance(urls
, openFiles
, splitView
, QString(), token
)) {
184 // Successfully attached to existing instance of Dolphin
189 if (!startedWithURLs
) {
190 // We need at least one URL to open Dolphin
191 urls
.append(Dolphin::homeUrl());
194 if (splitView
&& urls
.size() < 2) {
195 // Split view does only make sense if we have at least 2 URLs
196 urls
.append(urls
.last());
199 DolphinMainWindow
*mainWindow
= new DolphinMainWindow();
202 mainWindow
->openFiles(urls
, splitView
);
204 mainWindow
->openDirectories(urls
, splitView
);
209 // Allow starting Dolphin on a system that is not running DBus:
210 KDBusService::StartupOptions serviceOptions
= KDBusService::Multiple
;
211 if (!QDBusConnection::sessionBus().isConnected()) {
212 serviceOptions
|= KDBusService::NoExitOnFailure
;
214 KDBusService
dolphinDBusService(serviceOptions
);
215 DBusInterface interface
;
217 if (!app
.isSessionRestored()) {
218 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
221 // Only restore session if:
222 // 1. Not explicitly opening a new instance
223 // 2. The "remember state" setting is enabled or session restoration after
225 // 3. There is a session available to restore
226 if (!parser
.isSet(QStringLiteral("new-window")) && (app
.isSessionRestored() || GeneralSettings::rememberOpenedTabs())) {
227 // Get saved state data for the last-closed Dolphin instance
228 const QString serviceName
= QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid());
229 if (Dolphin::dolphinGuiInstances(serviceName
).size() > 0) {
230 const QString className
= KXmlGuiWindow::classNameOfToplevel(1);
231 if (className
== QLatin1String("DolphinMainWindow")) {
232 mainWindow
->restore(1);
233 // If the user passed any URLs to Dolphin, open those in the
234 // window after session-restoring it
235 if (startedWithURLs
) {
237 mainWindow
->openFiles(urls
, splitView
);
239 mainWindow
->openDirectories(urls
, splitView
);
243 qCWarning(DolphinDebug
) << "Unknown class " << className
<< " in session saved data!";
248 #if HAVE_KUSERFEEDBACK
249 auto feedbackProvider
= DolphinFeedbackProvider::instance();
250 Q_UNUSED(feedbackProvider
)
253 return app
.exec(); // krazy:exclude=crash;