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 can cause bugs and expose you to security vulnerabilities." << std::endl
;
59 } else if (!qEnvironmentVariableIsEmpty("KDESU_USER")) {
60 std::cout
<< "Running Dolphin with kdesu can cause bugs and expose you to security vulnerabilities." << std::endl
;
67 * enable high dpi support
69 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
70 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps
, true);
71 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling
, true);
73 QApplication
app(argc
, argv
);
74 app
.setWindowIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"), app
.windowIcon()));
76 KIO::PreviewJob::setDefaultDevicePixelRatio(app
.devicePixelRatio());
80 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
81 Kdelibs4ConfigMigrator
migrate(QStringLiteral("dolphin"));
82 migrate
.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
83 migrate
.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
87 KLocalizedString::setApplicationDomain("dolphin");
89 KAboutData
aboutData(QStringLiteral("dolphin"),
91 QStringLiteral(DOLPHIN_VERSION_STRING
),
92 i18nc("@title", "File Manager"),
94 i18nc("@info:credit", "(C) 2006-2022 The Dolphin Developers"));
95 aboutData
.setHomepage(QStringLiteral("https://kde.org/applications/system/org.kde.dolphin"));
96 aboutData
.addAuthor(i18nc("@info:credit", "Felix Ernst"),
97 i18nc("@info:credit", "Maintainer (since 2021) and developer"),
98 QStringLiteral("felixernst@kde.org"));
99 aboutData
.addAuthor(i18nc("@info:credit", "Méven Car"),
100 i18nc("@info:credit", "Maintainer (since 2021) and developer (since 2019)"),
101 QStringLiteral("meven@kde.org"));
102 aboutData
.addAuthor(i18nc("@info:credit", "Elvis Angelaccio"),
103 i18nc("@info:credit", "Maintainer (2018-2021) and developer"),
104 QStringLiteral("elvis.angelaccio@kde.org"));
105 aboutData
.addAuthor(i18nc("@info:credit", "Emmanuel Pescosta"),
106 i18nc("@info:credit", "Maintainer (2014-2018) and developer"),
107 QStringLiteral("emmanuelpescosta099@gmail.com"));
108 aboutData
.addAuthor(i18nc("@info:credit", "Frank Reininghaus"),
109 i18nc("@info:credit", "Maintainer (2012-2014) and developer"),
110 QStringLiteral("frank78ac@googlemail.com"));
111 aboutData
.addAuthor(i18nc("@info:credit", "Peter Penz"),
112 i18nc("@info:credit", "Maintainer and developer (2006-2012)"),
113 QStringLiteral("peter.penz19@gmail.com"));
114 aboutData
.addAuthor(i18nc("@info:credit", "Sebastian Trüg"), i18nc("@info:credit", "Developer"), QStringLiteral("trueg@kde.org"));
115 aboutData
.addAuthor(i18nc("@info:credit", "David Faure"), i18nc("@info:credit", "Developer"), QStringLiteral("faure@kde.org"));
116 aboutData
.addAuthor(i18nc("@info:credit", "Aaron J. Seigo"), i18nc("@info:credit", "Developer"), QStringLiteral("aseigo@kde.org"));
117 aboutData
.addAuthor(i18nc("@info:credit", "Rafael Fernández López"), i18nc("@info:credit", "Developer"), QStringLiteral("ereslibre@kde.org"));
118 aboutData
.addAuthor(i18nc("@info:credit", "Kevin Ottens"), i18nc("@info:credit", "Developer"), QStringLiteral("ervin@kde.org"));
119 aboutData
.addAuthor(i18nc("@info:credit", "Holger Freyther"), i18nc("@info:credit", "Developer"), QStringLiteral("freyther@gmx.net"));
120 aboutData
.addAuthor(i18nc("@info:credit", "Max Blazejak"), i18nc("@info:credit", "Developer"), QStringLiteral("m43ksrocks@gmail.com"));
121 aboutData
.addAuthor(i18nc("@info:credit", "Michael Austin"), i18nc("@info:credit", "Documentation"), QStringLiteral("tuxedup@users.sourceforge.net"));
123 KAboutData::setApplicationData(aboutData
);
125 QCommandLineParser parser
;
126 aboutData
.setupCommandLine(&parser
);
128 // command line options
129 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"),
131 "The files and folders passed as arguments "
132 "will be selected.")));
133 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
134 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("new-window"), i18nc("@info:shell", "Dolphin will explicitly open in a new window.")));
136 QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface).")));
137 parser
.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open"));
140 aboutData
.processCommandLine(&parser
);
142 const bool splitView
= parser
.isSet(QStringLiteral("split")) || GeneralSettings::splitView();
143 const bool openFiles
= parser
.isSet(QStringLiteral("select"));
144 const QStringList args
= parser
.positionalArguments();
145 QList
<QUrl
> urls
= Dolphin::validateUris(args
);
146 // We later mutate urls, so we need to store if it was empty originally
147 const bool startedWithURLs
= !urls
.isEmpty();
149 if (parser
.isSet(QStringLiteral("daemon"))) {
150 // Disable session management for the daemonized version
151 // See https://bugs.kde.org/show_bug.cgi?id=417219
152 auto disableSessionManagement
= [](QSessionManager
&sm
) {
153 sm
.setRestartHint(QSessionManager::RestartNever
);
155 QObject::connect(&app
, &QGuiApplication::commitDataRequest
, disableSessionManagement
);
156 QObject::connect(&app
, &QGuiApplication::saveStateRequest
, disableSessionManagement
);
159 KDBusService
dolphinDBusService(KDBusService::NoExitOnFailure
);
161 KDBusService dolphinDBusService
;
163 DBusInterface interface
;
164 interface
.setAsDaemon();
168 if (!parser
.isSet(QStringLiteral("new-window"))) {
170 if (KWindowSystem::isPlatformWayland()) {
171 token
= qEnvironmentVariable("XDG_ACTIVATION_TOKEN");
172 qunsetenv("XDG_ACTIVATION_TOKEN");
173 } else if (KWindowSystem::isPlatformX11()) {
175 token
= QX11Info::nextStartupId();
179 if (Dolphin::attachToExistingInstance(urls
, openFiles
, splitView
, QString(), token
)) {
180 // Successfully attached to existing instance of Dolphin
185 if (!startedWithURLs
) {
186 // We need at least one URL to open Dolphin
187 urls
.append(Dolphin::homeUrl());
190 if (splitView
&& urls
.size() < 2) {
191 // Split view does only make sense if we have at least 2 URLs
192 urls
.append(urls
.last());
195 DolphinMainWindow
*mainWindow
= new DolphinMainWindow();
198 mainWindow
->openFiles(urls
, splitView
);
200 mainWindow
->openDirectories(urls
, splitView
);
205 // Allow starting Dolphin on a system that is not running DBus:
206 KDBusService::StartupOptions serviceOptions
= KDBusService::Multiple
;
207 if (!QDBusConnection::sessionBus().isConnected()) {
208 serviceOptions
|= KDBusService::NoExitOnFailure
;
210 KDBusService
dolphinDBusService(serviceOptions
);
211 DBusInterface interface
;
213 if (!app
.isSessionRestored()) {
214 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
217 // Only restore session if:
218 // 1. Not explicitly opening a new instance
219 // 2. The "remember state" setting is enabled or session restoration after
221 // 3. There is a session available to restore
222 if (!parser
.isSet(QStringLiteral("new-window")) && (app
.isSessionRestored() || GeneralSettings::rememberOpenedTabs())) {
223 // Get saved state data for the last-closed Dolphin instance
224 const QString serviceName
= QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid());
225 if (Dolphin::dolphinGuiInstances(serviceName
).size() > 0) {
226 const QString className
= KXmlGuiWindow::classNameOfToplevel(1);
227 if (className
== QLatin1String("DolphinMainWindow")) {
228 mainWindow
->restore(1);
229 // If the user passed any URLs to Dolphin, open those in the
230 // window after session-restoring it
231 if (startedWithURLs
) {
233 mainWindow
->openFiles(urls
, splitView
);
235 mainWindow
->openDirectories(urls
, splitView
);
239 qCWarning(DolphinDebug
) << "Unknown class " << className
<< " in session saved data!";
244 #if HAVE_KUSERFEEDBACK
245 auto feedbackProvider
= DolphinFeedbackProvider::instance();
246 Q_UNUSED(feedbackProvider
)
249 return app
.exec(); // krazy:exclude=crash;