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