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"
15 #include "config-dolphin.h"
16 #if HAVE_KUSERFEEDBACK
17 #include "userfeedback/dolphinfeedbackprovider.h"
22 #include <KDBusService>
23 #include <KLocalizedString>
25 #include <KIO/PreviewJob>
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."
60 } else if (!qEnvironmentVariableIsEmpty("KDESU_USER")) {
61 std::cout
<< "Running Dolphin with kdesu can cause bugs and expose you to security vulnerabilities."
69 * enable high dpi support
71 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
72 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps
, true);
73 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling
, true);
75 QApplication
app(argc
, argv
);
76 app
.setWindowIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"), app
.windowIcon()));
78 KIO::PreviewJob::setDefaultDevicePixelRatio(app
.devicePixelRatio());
82 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
83 Kdelibs4ConfigMigrator
migrate(QStringLiteral("dolphin"));
84 migrate
.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
85 migrate
.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
89 KLocalizedString::setApplicationDomain("dolphin");
91 KAboutData
aboutData(QStringLiteral("dolphin"), i18n("Dolphin"), 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"),
115 i18nc("@info:credit", "Developer"),
116 QStringLiteral("trueg@kde.org"));
117 aboutData
.addAuthor(i18nc("@info:credit", "David Faure"),
118 i18nc("@info:credit", "Developer"),
119 QStringLiteral("faure@kde.org"));
120 aboutData
.addAuthor(i18nc("@info:credit", "Aaron J. Seigo"),
121 i18nc("@info:credit", "Developer"),
122 QStringLiteral("aseigo@kde.org"));
123 aboutData
.addAuthor(i18nc("@info:credit", "Rafael Fernández López"),
124 i18nc("@info:credit", "Developer"),
125 QStringLiteral("ereslibre@kde.org"));
126 aboutData
.addAuthor(i18nc("@info:credit", "Kevin Ottens"),
127 i18nc("@info:credit", "Developer"),
128 QStringLiteral("ervin@kde.org"));
129 aboutData
.addAuthor(i18nc("@info:credit", "Holger Freyther"),
130 i18nc("@info:credit", "Developer"),
131 QStringLiteral("freyther@gmx.net"));
132 aboutData
.addAuthor(i18nc("@info:credit", "Max Blazejak"),
133 i18nc("@info:credit", "Developer"),
134 QStringLiteral("m43ksrocks@gmail.com"));
135 aboutData
.addAuthor(i18nc("@info:credit", "Michael Austin"),
136 i18nc("@info:credit", "Documentation"),
137 QStringLiteral("tuxedup@users.sourceforge.net"));
139 KAboutData::setApplicationData(aboutData
);
141 QCommandLineParser parser
;
142 aboutData
.setupCommandLine(&parser
);
144 // command line options
145 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"), i18nc("@info:shell", "The files and folders passed as arguments "
146 "will be selected.")));
147 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
148 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("new-window"), i18nc("@info:shell", "Dolphin will explicitly open in a new window.")));
149 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface).")));
150 parser
.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open"));
153 aboutData
.processCommandLine(&parser
);
155 const bool splitView
= parser
.isSet(QStringLiteral("split")) || GeneralSettings::splitView();
156 const bool openFiles
= parser
.isSet(QStringLiteral("select"));
157 const QStringList args
= parser
.positionalArguments();
158 QList
<QUrl
> urls
= Dolphin::validateUris(args
);
159 // We later mutate urls, so we need to store if it was empty originally
160 const bool startedWithURLs
= !urls
.isEmpty();
163 if (parser
.isSet(QStringLiteral("daemon"))) {
164 // Disable session management for the daemonized version
165 // See https://bugs.kde.org/show_bug.cgi?id=417219
166 auto disableSessionManagement
= [](QSessionManager
&sm
) {
167 sm
.setRestartHint(QSessionManager::RestartNever
);
169 QObject::connect(&app
, &QGuiApplication::commitDataRequest
, disableSessionManagement
);
170 QObject::connect(&app
, &QGuiApplication::saveStateRequest
, disableSessionManagement
);
173 KDBusService
dolphinDBusService(KDBusService::NoExitOnFailure
);
175 KDBusService dolphinDBusService
;
177 DBusInterface interface
;
178 interface
.setAsDaemon();
182 if (!parser
.isSet(QStringLiteral("new-window"))) {
185 if (KWindowSystem::isPlatformWayland()) {
186 token
= qEnvironmentVariable("XDG_ACTIVATION_TOKEN");
187 qunsetenv("XDG_ACTIVATION_TOKEN");
188 } else if (KWindowSystem::isPlatformX11()) {
190 token
= QX11Info::nextStartupId();
194 if (Dolphin::attachToExistingInstance(urls
, openFiles
, splitView
, QString(), token
)) {
195 // Successfully attached to existing instance of Dolphin
200 if (!startedWithURLs
) {
201 // We need at least one URL to open Dolphin
202 urls
.append(Dolphin::homeUrl());
205 if (splitView
&& urls
.size() < 2) {
206 // Split view does only make sense if we have at least 2 URLs
207 urls
.append(urls
.last());
210 DolphinMainWindow
* mainWindow
= new DolphinMainWindow();
213 mainWindow
->openFiles(urls
, splitView
);
215 mainWindow
->openDirectories(urls
, splitView
);
220 // Allow starting Dolphin on a system that is not running DBus:
221 KDBusService::StartupOptions serviceOptions
= KDBusService::Multiple
;
222 if (!QDBusConnection::sessionBus().isConnected()) {
223 serviceOptions
|= KDBusService::NoExitOnFailure
;
225 KDBusService
dolphinDBusService(serviceOptions
);
226 DBusInterface interface
;
228 if (!app
.isSessionRestored()) {
229 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
232 // Only restore session if:
233 // 1. Not explicitly opening a new instance
234 // 2. The "remember state" setting is enabled or session restoration after
236 // 3. There is a session available to restore
237 if (!parser
.isSet(QStringLiteral("new-window"))
238 && (app
.isSessionRestored() || GeneralSettings::rememberOpenedTabs())
240 // Get saved state data for the last-closed Dolphin instance
241 const QString serviceName
= QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid());
242 if (Dolphin::dolphinGuiInstances(serviceName
).size() > 0) {
243 const QString className
= KXmlGuiWindow::classNameOfToplevel(1);
244 if (className
== QLatin1String("DolphinMainWindow")) {
245 mainWindow
->restore(1);
246 // If the user passed any URLs to Dolphin, open those in the
247 // window after session-restoring it
248 if (startedWithURLs
) {
250 mainWindow
->openFiles(urls
, splitView
);
252 mainWindow
->openDirectories(urls
, splitView
);
256 qCWarning(DolphinDebug
) << "Unknown class " << className
<< " in session saved data!";
261 #if HAVE_KUSERFEEDBACK
262 auto feedbackProvider
= DolphinFeedbackProvider::instance();
263 Q_UNUSED(feedbackProvider
)
266 return app
.exec(); // krazy:exclude=crash;