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-kuserfeedback.h"
16 #ifdef HAVE_KUSERFEEDBACK
17 #include "userfeedback/dolphinfeedbackprovider.h"
22 #include <KDBusService>
23 #include <KLocalizedString>
24 #include <Kdelibs4ConfigMigrator>
26 #include <KIO/PreviewJob>
28 #include <QApplication>
29 #include <QCommandLineParser>
30 #include <QDBusConnection>
31 #include <QDBusInterface>
32 #include <QDBusAbstractInterface>
33 #include <QDBusConnectionInterface>
34 #include <QSessionManager>
41 int main(int argc
, char **argv
)
44 // Prohibit using sudo or kdesu (but allow using the root user directly)
46 if (!qEnvironmentVariableIsEmpty("SUDO_USER")) {
47 std::cout
<< "Running Dolphin with sudo can cause bugs and expose you to security vulnerabilities. "
48 "Instead use Dolphin normally and you will be prompted for elevated privileges when "
49 "performing file operations that require them."
52 } else if (!qEnvironmentVariableIsEmpty("KDESU_USER")) {
53 std::cout
<< "Running Dolphin with kdesu can cause bugs and expose you to security vulnerabilities. "
54 "Instead use Dolphin normally and you will be prompted for elevated privileges when "
55 "performing file operations that require them."
63 * enable high dpi support
65 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps
, true);
66 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling
, true);
68 QApplication
app(argc
, argv
);
69 app
.setWindowIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"), app
.windowIcon()));
71 KIO::PreviewJob::setDefaultDevicePixelRatio(app
.devicePixelRatio());
75 Kdelibs4ConfigMigrator
migrate(QStringLiteral("dolphin"));
76 migrate
.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
77 migrate
.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
80 KLocalizedString::setApplicationDomain("dolphin");
82 KAboutData
aboutData(QStringLiteral("dolphin"), i18n("Dolphin"), QStringLiteral(DOLPHIN_VERSION_STRING
),
83 i18nc("@title", "File Manager"),
85 i18nc("@info:credit", "(C) 2006-2018 Peter Penz, Frank Reininghaus, Emmanuel Pescosta and Elvis Angelaccio"));
86 aboutData
.setHomepage(QStringLiteral("https://kde.org/applications/system/org.kde.dolphin"));
87 aboutData
.addAuthor(i18nc("@info:credit", "Elvis Angelaccio"),
88 i18nc("@info:credit", "Maintainer (since 2018) and developer"),
89 QStringLiteral("elvis.angelaccio@kde.org"));
90 aboutData
.addAuthor(i18nc("@info:credit", "Emmanuel Pescosta"),
91 i18nc("@info:credit", "Maintainer (2014-2018) and developer"),
92 QStringLiteral("emmanuelpescosta099@gmail.com"));
93 aboutData
.addAuthor(i18nc("@info:credit", "Frank Reininghaus"),
94 i18nc("@info:credit", "Maintainer (2012-2014) and developer"),
95 QStringLiteral("frank78ac@googlemail.com"));
96 aboutData
.addAuthor(i18nc("@info:credit", "Peter Penz"),
97 i18nc("@info:credit", "Maintainer and developer (2006-2012)"),
98 QStringLiteral("peter.penz19@gmail.com"));
99 aboutData
.addAuthor(i18nc("@info:credit", "Sebastian Trüg"),
100 i18nc("@info:credit", "Developer"),
101 QStringLiteral("trueg@kde.org"));
102 aboutData
.addAuthor(i18nc("@info:credit", "David Faure"),
103 i18nc("@info:credit", "Developer"),
104 QStringLiteral("faure@kde.org"));
105 aboutData
.addAuthor(i18nc("@info:credit", "Aaron J. Seigo"),
106 i18nc("@info:credit", "Developer"),
107 QStringLiteral("aseigo@kde.org"));
108 aboutData
.addAuthor(i18nc("@info:credit", "Rafael Fernández López"),
109 i18nc("@info:credit", "Developer"),
110 QStringLiteral("ereslibre@kde.org"));
111 aboutData
.addAuthor(i18nc("@info:credit", "Kevin Ottens"),
112 i18nc("@info:credit", "Developer"),
113 QStringLiteral("ervin@kde.org"));
114 aboutData
.addAuthor(i18nc("@info:credit", "Holger Freyther"),
115 i18nc("@info:credit", "Developer"),
116 QStringLiteral("freyther@gmx.net"));
117 aboutData
.addAuthor(i18nc("@info:credit", "Max Blazejak"),
118 i18nc("@info:credit", "Developer"),
119 QStringLiteral("m43ksrocks@gmail.com"));
120 aboutData
.addAuthor(i18nc("@info:credit", "Michael Austin"),
121 i18nc("@info:credit", "Documentation"),
122 QStringLiteral("tuxedup@users.sourceforge.net"));
124 KAboutData::setApplicationData(aboutData
);
126 QCommandLineParser parser
;
127 aboutData
.setupCommandLine(&parser
);
129 // command line options
130 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"), i18nc("@info:shell", "The files and folders passed as arguments "
131 "will be selected.")));
132 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
133 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("new-window"), i18nc("@info:shell", "Dolphin will explicitly open in a new window.")));
134 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface)")));
135 parser
.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open"));
138 aboutData
.processCommandLine(&parser
);
140 const bool splitView
= parser
.isSet(QStringLiteral("split")) || GeneralSettings::splitView();
141 const bool openFiles
= parser
.isSet(QStringLiteral("select"));
142 const QStringList args
= parser
.positionalArguments();
143 QList
<QUrl
> urls
= Dolphin::validateUris(args
);
144 // We later mutate urls, so we need to store if it was empty originally
145 const bool startedWithURLs
= !urls
.isEmpty();
148 if (parser
.isSet(QStringLiteral("daemon"))) {
149 // Disable session management for the daemonized version
150 // See https://bugs.kde.org/show_bug.cgi?id=417219
151 auto disableSessionManagement
= [](QSessionManager
&sm
) {
152 sm
.setRestartHint(QSessionManager::RestartNever
);
154 QObject::connect(&app
, &QGuiApplication::commitDataRequest
, disableSessionManagement
);
155 QObject::connect(&app
, &QGuiApplication::saveStateRequest
, disableSessionManagement
);
157 KDBusService dolphinDBusService
;
158 DBusInterface interface
;
159 interface
.setAsDaemon();
163 if (!parser
.isSet(QStringLiteral("new-window"))) {
164 if (Dolphin::attachToExistingInstance(urls
, openFiles
, splitView
)) {
165 // Successfully attached to existing instance of Dolphin
170 if (!startedWithURLs
) {
171 // We need at least one URL to open Dolphin
172 urls
.append(Dolphin::homeUrl());
175 if (splitView
&& urls
.size() < 2) {
176 // Split view does only make sense if we have at least 2 URLs
177 urls
.append(urls
.last());
180 DolphinMainWindow
* mainWindow
= new DolphinMainWindow();
183 mainWindow
->openFiles(urls
, splitView
);
185 mainWindow
->openDirectories(urls
, splitView
);
190 // Allow starting Dolphin on a system that is not running DBus:
191 KDBusService::StartupOptions serviceOptions
= KDBusService::Multiple
;
192 if (!QDBusConnection::sessionBus().isConnected()) {
193 serviceOptions
|= KDBusService::NoExitOnFailure
;
195 KDBusService
dolphinDBusService(serviceOptions
);
196 DBusInterface interface
;
198 if (!app
.isSessionRestored()) {
199 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
202 // Only restore session if:
203 // 1. Not explicitly opening a new instance
204 // 2. The "remember state" setting is enabled or session restoration after
206 // 3. There is a session available to restore
207 if (!parser
.isSet(QStringLiteral("new-window"))
208 && (app
.isSessionRestored() || GeneralSettings::rememberOpenedTabs())
210 // Get saved state data for the last-closed Dolphin instance
211 const QString serviceName
= QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid());
212 if (Dolphin::dolphinGuiInstances(serviceName
).size() > 0) {
213 const QString className
= KXmlGuiWindow::classNameOfToplevel(1);
214 if (className
== QLatin1String("DolphinMainWindow")) {
215 mainWindow
->restore(1);
216 // If the user passed any URLs to Dolphin, open those in the
217 // window after session-restoring it
218 if (startedWithURLs
) {
220 mainWindow
->openFiles(urls
, splitView
);
222 mainWindow
->openDirectories(urls
, splitView
);
226 qCWarning(DolphinDebug
) << "Unknown class " << className
<< " in session saved data!";
231 #ifdef HAVE_KUSERFEEDBACK
232 auto feedbackProvider
= DolphinFeedbackProvider::instance();
233 Q_UNUSED(feedbackProvider
)
236 return app
.exec(); // krazy:exclude=crash;