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>
27 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
28 #include <Kdelibs4ConfigMigrator>
31 #include <QApplication>
32 #include <QCommandLineParser>
33 #include <QDBusConnection>
34 #include <QDBusConnectionInterface>
35 #include <QSessionManager>
42 int main(int argc
, char **argv
)
45 // Prohibit using sudo or kdesu (but allow using the root user directly)
47 if (!qEnvironmentVariableIsEmpty("SUDO_USER")) {
48 std::cout
<< "Running Dolphin with sudo can cause bugs and expose you to security vulnerabilities. "
49 "Instead use Dolphin normally and you will be prompted for elevated privileges when "
50 "performing file operations that require them."
53 } else if (!qEnvironmentVariableIsEmpty("KDESU_USER")) {
54 std::cout
<< "Running Dolphin with kdesu can cause bugs and expose you to security vulnerabilities. "
55 "Instead use Dolphin normally and you will be prompted for elevated privileges when "
56 "performing file operations that require them."
64 * enable high dpi support
66 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
67 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps
, true);
68 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling
, true);
70 QApplication
app(argc
, argv
);
71 app
.setWindowIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"), app
.windowIcon()));
73 KIO::PreviewJob::setDefaultDevicePixelRatio(app
.devicePixelRatio());
77 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
78 Kdelibs4ConfigMigrator
migrate(QStringLiteral("dolphin"));
79 migrate
.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
80 migrate
.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
84 KLocalizedString::setApplicationDomain("dolphin");
86 KAboutData
aboutData(QStringLiteral("dolphin"), i18n("Dolphin"), QStringLiteral(DOLPHIN_VERSION_STRING
),
87 i18nc("@title", "File Manager"),
89 i18nc("@info:credit", "(C) 2006-2022 The Dolphin Developers"));
90 aboutData
.setHomepage(QStringLiteral("https://kde.org/applications/system/org.kde.dolphin"));
91 aboutData
.addAuthor(i18nc("@info:credit", "Felix Ernst"),
92 i18nc("@info:credit", "Maintainer (since 2021) and developer"),
93 QStringLiteral("felixernst@kde.org"));
94 aboutData
.addAuthor(i18nc("@info:credit", "Méven Car"),
95 i18nc("@info:credit", "Maintainer (since 2021) and developer (since 2019)"),
96 QStringLiteral("meven@kde.org"));
97 aboutData
.addAuthor(i18nc("@info:credit", "Elvis Angelaccio"),
98 i18nc("@info:credit", "Maintainer (2018-2021) and developer"),
99 QStringLiteral("elvis.angelaccio@kde.org"));
100 aboutData
.addAuthor(i18nc("@info:credit", "Emmanuel Pescosta"),
101 i18nc("@info:credit", "Maintainer (2014-2018) and developer"),
102 QStringLiteral("emmanuelpescosta099@gmail.com"));
103 aboutData
.addAuthor(i18nc("@info:credit", "Frank Reininghaus"),
104 i18nc("@info:credit", "Maintainer (2012-2014) and developer"),
105 QStringLiteral("frank78ac@googlemail.com"));
106 aboutData
.addAuthor(i18nc("@info:credit", "Peter Penz"),
107 i18nc("@info:credit", "Maintainer and developer (2006-2012)"),
108 QStringLiteral("peter.penz19@gmail.com"));
109 aboutData
.addAuthor(i18nc("@info:credit", "Sebastian Trüg"),
110 i18nc("@info:credit", "Developer"),
111 QStringLiteral("trueg@kde.org"));
112 aboutData
.addAuthor(i18nc("@info:credit", "David Faure"),
113 i18nc("@info:credit", "Developer"),
114 QStringLiteral("faure@kde.org"));
115 aboutData
.addAuthor(i18nc("@info:credit", "Aaron J. Seigo"),
116 i18nc("@info:credit", "Developer"),
117 QStringLiteral("aseigo@kde.org"));
118 aboutData
.addAuthor(i18nc("@info:credit", "Rafael Fernández López"),
119 i18nc("@info:credit", "Developer"),
120 QStringLiteral("ereslibre@kde.org"));
121 aboutData
.addAuthor(i18nc("@info:credit", "Kevin Ottens"),
122 i18nc("@info:credit", "Developer"),
123 QStringLiteral("ervin@kde.org"));
124 aboutData
.addAuthor(i18nc("@info:credit", "Holger Freyther"),
125 i18nc("@info:credit", "Developer"),
126 QStringLiteral("freyther@gmx.net"));
127 aboutData
.addAuthor(i18nc("@info:credit", "Max Blazejak"),
128 i18nc("@info:credit", "Developer"),
129 QStringLiteral("m43ksrocks@gmail.com"));
130 aboutData
.addAuthor(i18nc("@info:credit", "Michael Austin"),
131 i18nc("@info:credit", "Documentation"),
132 QStringLiteral("tuxedup@users.sourceforge.net"));
134 KAboutData::setApplicationData(aboutData
);
136 QCommandLineParser parser
;
137 aboutData
.setupCommandLine(&parser
);
139 // command line options
140 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"), i18nc("@info:shell", "The files and folders passed as arguments "
141 "will be selected.")));
142 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
143 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("new-window"), i18nc("@info:shell", "Dolphin will explicitly open in a new window.")));
144 parser
.addOption(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();
158 if (parser
.isSet(QStringLiteral("daemon"))) {
159 // Disable session management for the daemonized version
160 // See https://bugs.kde.org/show_bug.cgi?id=417219
161 auto disableSessionManagement
= [](QSessionManager
&sm
) {
162 sm
.setRestartHint(QSessionManager::RestartNever
);
164 QObject::connect(&app
, &QGuiApplication::commitDataRequest
, disableSessionManagement
);
165 QObject::connect(&app
, &QGuiApplication::saveStateRequest
, disableSessionManagement
);
168 KDBusService
dolphinDBusService(KDBusService::NoExitOnFailure
);
170 KDBusService dolphinDBusService
;
172 DBusInterface interface
;
173 interface
.setAsDaemon();
177 if (!parser
.isSet(QStringLiteral("new-window"))) {
178 if (Dolphin::attachToExistingInstance(urls
, openFiles
, splitView
)) {
179 // Successfully attached to existing instance of Dolphin
184 if (!startedWithURLs
) {
185 // We need at least one URL to open Dolphin
186 urls
.append(Dolphin::homeUrl());
189 if (splitView
&& urls
.size() < 2) {
190 // Split view does only make sense if we have at least 2 URLs
191 urls
.append(urls
.last());
194 DolphinMainWindow
* mainWindow
= new DolphinMainWindow();
197 mainWindow
->openFiles(urls
, splitView
);
199 mainWindow
->openDirectories(urls
, splitView
);
204 // Allow starting Dolphin on a system that is not running DBus:
205 KDBusService::StartupOptions serviceOptions
= KDBusService::Multiple
;
206 if (!QDBusConnection::sessionBus().isConnected()) {
207 serviceOptions
|= KDBusService::NoExitOnFailure
;
209 KDBusService
dolphinDBusService(serviceOptions
);
210 DBusInterface interface
;
212 if (!app
.isSessionRestored()) {
213 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
216 // Only restore session if:
217 // 1. Not explicitly opening a new instance
218 // 2. The "remember state" setting is enabled or session restoration after
220 // 3. There is a session available to restore
221 if (!parser
.isSet(QStringLiteral("new-window"))
222 && (app
.isSessionRestored() || GeneralSettings::rememberOpenedTabs())
224 // Get saved state data for the last-closed Dolphin instance
225 const QString serviceName
= QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid());
226 if (Dolphin::dolphinGuiInstances(serviceName
).size() > 0) {
227 const QString className
= KXmlGuiWindow::classNameOfToplevel(1);
228 if (className
== QLatin1String("DolphinMainWindow")) {
229 mainWindow
->restore(1);
230 // If the user passed any URLs to Dolphin, open those in the
231 // window after session-restoring it
232 if (startedWithURLs
) {
234 mainWindow
->openFiles(urls
, splitView
);
236 mainWindow
->openDirectories(urls
, splitView
);
240 qCWarning(DolphinDebug
) << "Unknown class " << className
<< " in session saved data!";
245 #if HAVE_KUSERFEEDBACK
246 auto feedbackProvider
= DolphinFeedbackProvider::instance();
247 Q_UNUSED(feedbackProvider
)
250 return app
.exec(); // krazy:exclude=crash;