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