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>
43 int main(int argc
, char **argv
)
46 // Prohibit using sudo or kdesu (but allow using the root user directly)
48 if (!qEnvironmentVariableIsEmpty("SUDO_USER")) {
49 std::cout
<< "Running Dolphin with sudo can cause bugs and expose you to security vulnerabilities. "
50 "Instead use Dolphin normally and you will be prompted for elevated privileges when "
51 "performing file operations that require them."
54 } else if (!qEnvironmentVariableIsEmpty("KDESU_USER")) {
55 std::cout
<< "Running Dolphin with kdesu can cause bugs and expose you to security vulnerabilities. "
56 "Instead use Dolphin normally and you will be prompted for elevated privileges when "
57 "performing file operations that require them."
65 * enable high dpi support
67 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
68 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps
, true);
69 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling
, true);
71 QApplication
app(argc
, argv
);
72 app
.setWindowIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"), app
.windowIcon()));
74 KIO::PreviewJob::setDefaultDevicePixelRatio(app
.devicePixelRatio());
78 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
79 Kdelibs4ConfigMigrator
migrate(QStringLiteral("dolphin"));
80 migrate
.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
81 migrate
.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
85 KLocalizedString::setApplicationDomain("dolphin");
87 KAboutData
aboutData(QStringLiteral("dolphin"), i18n("Dolphin"), QStringLiteral(DOLPHIN_VERSION_STRING
),
88 i18nc("@title", "File Manager"),
90 i18nc("@info:credit", "(C) 2006-2022 The Dolphin Developers"));
91 aboutData
.setHomepage(QStringLiteral("https://kde.org/applications/system/org.kde.dolphin"));
92 aboutData
.addAuthor(i18nc("@info:credit", "Felix Ernst"),
93 i18nc("@info:credit", "Maintainer (since 2021) and developer"),
94 QStringLiteral("felixernst@kde.org"));
95 aboutData
.addAuthor(i18nc("@info:credit", "Méven Car"),
96 i18nc("@info:credit", "Maintainer (since 2021) and developer (since 2019)"),
97 QStringLiteral("meven@kde.org"));
98 aboutData
.addAuthor(i18nc("@info:credit", "Elvis Angelaccio"),
99 i18nc("@info:credit", "Maintainer (2018-2021) and developer"),
100 QStringLiteral("elvis.angelaccio@kde.org"));
101 aboutData
.addAuthor(i18nc("@info:credit", "Emmanuel Pescosta"),
102 i18nc("@info:credit", "Maintainer (2014-2018) and developer"),
103 QStringLiteral("emmanuelpescosta099@gmail.com"));
104 aboutData
.addAuthor(i18nc("@info:credit", "Frank Reininghaus"),
105 i18nc("@info:credit", "Maintainer (2012-2014) and developer"),
106 QStringLiteral("frank78ac@googlemail.com"));
107 aboutData
.addAuthor(i18nc("@info:credit", "Peter Penz"),
108 i18nc("@info:credit", "Maintainer and developer (2006-2012)"),
109 QStringLiteral("peter.penz19@gmail.com"));
110 aboutData
.addAuthor(i18nc("@info:credit", "Sebastian Trüg"),
111 i18nc("@info:credit", "Developer"),
112 QStringLiteral("trueg@kde.org"));
113 aboutData
.addAuthor(i18nc("@info:credit", "David Faure"),
114 i18nc("@info:credit", "Developer"),
115 QStringLiteral("faure@kde.org"));
116 aboutData
.addAuthor(i18nc("@info:credit", "Aaron J. Seigo"),
117 i18nc("@info:credit", "Developer"),
118 QStringLiteral("aseigo@kde.org"));
119 aboutData
.addAuthor(i18nc("@info:credit", "Rafael Fernández López"),
120 i18nc("@info:credit", "Developer"),
121 QStringLiteral("ereslibre@kde.org"));
122 aboutData
.addAuthor(i18nc("@info:credit", "Kevin Ottens"),
123 i18nc("@info:credit", "Developer"),
124 QStringLiteral("ervin@kde.org"));
125 aboutData
.addAuthor(i18nc("@info:credit", "Holger Freyther"),
126 i18nc("@info:credit", "Developer"),
127 QStringLiteral("freyther@gmx.net"));
128 aboutData
.addAuthor(i18nc("@info:credit", "Max Blazejak"),
129 i18nc("@info:credit", "Developer"),
130 QStringLiteral("m43ksrocks@gmail.com"));
131 aboutData
.addAuthor(i18nc("@info:credit", "Michael Austin"),
132 i18nc("@info:credit", "Documentation"),
133 QStringLiteral("tuxedup@users.sourceforge.net"));
135 KAboutData::setApplicationData(aboutData
);
137 QCommandLineParser parser
;
138 aboutData
.setupCommandLine(&parser
);
140 // command line options
141 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"), i18nc("@info:shell", "The files and folders passed as arguments "
142 "will be selected.")));
143 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
144 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("new-window"), i18nc("@info:shell", "Dolphin will explicitly open in a new window.")));
145 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface).")));
146 parser
.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open"));
149 aboutData
.processCommandLine(&parser
);
151 const bool splitView
= parser
.isSet(QStringLiteral("split")) || GeneralSettings::splitView();
152 const bool openFiles
= parser
.isSet(QStringLiteral("select"));
153 const QStringList args
= parser
.positionalArguments();
154 QList
<QUrl
> urls
= Dolphin::validateUris(args
);
155 // We later mutate urls, so we need to store if it was empty originally
156 const bool startedWithURLs
= !urls
.isEmpty();
159 if (parser
.isSet(QStringLiteral("daemon"))) {
160 // Disable session management for the daemonized version
161 // See https://bugs.kde.org/show_bug.cgi?id=417219
162 auto disableSessionManagement
= [](QSessionManager
&sm
) {
163 sm
.setRestartHint(QSessionManager::RestartNever
);
165 QObject::connect(&app
, &QGuiApplication::commitDataRequest
, disableSessionManagement
);
166 QObject::connect(&app
, &QGuiApplication::saveStateRequest
, disableSessionManagement
);
169 KDBusService
dolphinDBusService(KDBusService::NoExitOnFailure
);
171 KDBusService dolphinDBusService
;
173 DBusInterface interface
;
174 interface
.setAsDaemon();
178 if (!parser
.isSet(QStringLiteral("new-window"))) {
181 if (KWindowSystem::isPlatformWayland()) {
182 token
= qEnvironmentVariable("XDG_ACTIVATION_TOKEN");
183 qunsetenv("XDG_ACTIVATION_TOKEN");
186 if (Dolphin::attachToExistingInstance(urls
, openFiles
, splitView
, QString(), token
)) {
187 // Successfully attached to existing instance of Dolphin
192 if (!startedWithURLs
) {
193 // We need at least one URL to open Dolphin
194 urls
.append(Dolphin::homeUrl());
197 if (splitView
&& urls
.size() < 2) {
198 // Split view does only make sense if we have at least 2 URLs
199 urls
.append(urls
.last());
202 DolphinMainWindow
* mainWindow
= new DolphinMainWindow();
205 mainWindow
->openFiles(urls
, splitView
);
207 mainWindow
->openDirectories(urls
, splitView
);
212 // Allow starting Dolphin on a system that is not running DBus:
213 KDBusService::StartupOptions serviceOptions
= KDBusService::Multiple
;
214 if (!QDBusConnection::sessionBus().isConnected()) {
215 serviceOptions
|= KDBusService::NoExitOnFailure
;
217 KDBusService
dolphinDBusService(serviceOptions
);
218 DBusInterface interface
;
220 if (!app
.isSessionRestored()) {
221 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
224 // Only restore session if:
225 // 1. Not explicitly opening a new instance
226 // 2. The "remember state" setting is enabled or session restoration after
228 // 3. There is a session available to restore
229 if (!parser
.isSet(QStringLiteral("new-window"))
230 && (app
.isSessionRestored() || GeneralSettings::rememberOpenedTabs())
232 // Get saved state data for the last-closed Dolphin instance
233 const QString serviceName
= QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid());
234 if (Dolphin::dolphinGuiInstances(serviceName
).size() > 0) {
235 const QString className
= KXmlGuiWindow::classNameOfToplevel(1);
236 if (className
== QLatin1String("DolphinMainWindow")) {
237 mainWindow
->restore(1);
238 // If the user passed any URLs to Dolphin, open those in the
239 // window after session-restoring it
240 if (startedWithURLs
) {
242 mainWindow
->openFiles(urls
, splitView
);
244 mainWindow
->openDirectories(urls
, splitView
);
248 qCWarning(DolphinDebug
) << "Unknown class " << className
<< " in session saved data!";
253 #if HAVE_KUSERFEEDBACK
254 auto feedbackProvider
= DolphinFeedbackProvider::instance();
255 Q_UNUSED(feedbackProvider
)
258 return app
.exec(); // krazy:exclude=crash;