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
<< "Executing Dolphin with sudo is not possible due to unfixable security vulnerabilities." << std::endl
;
49 } else if (!qEnvironmentVariableIsEmpty("KDESU_USER")) {
50 std::cout
<< "Executing Dolphin with kdesu is not possible due to unfixable security vulnerabilities." << std::endl
;
57 * enable high dpi support
59 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps
, true);
60 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling
, true);
62 QApplication
app(argc
, argv
);
63 app
.setWindowIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"), app
.windowIcon()));
65 KIO::PreviewJob::setDefaultDevicePixelRatio(app
.devicePixelRatio());
69 Kdelibs4ConfigMigrator
migrate(QStringLiteral("dolphin"));
70 migrate
.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
71 migrate
.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
74 KLocalizedString::setApplicationDomain("dolphin");
76 KAboutData
aboutData(QStringLiteral("dolphin"), i18n("Dolphin"), QStringLiteral(DOLPHIN_VERSION_STRING
),
77 i18nc("@title", "File Manager"),
79 i18nc("@info:credit", "(C) 2006-2018 Peter Penz, Frank Reininghaus, Emmanuel Pescosta and Elvis Angelaccio"));
80 aboutData
.setHomepage(QStringLiteral("https://kde.org/applications/system/org.kde.dolphin"));
81 aboutData
.addAuthor(i18nc("@info:credit", "Elvis Angelaccio"),
82 i18nc("@info:credit", "Maintainer (since 2018) and developer"),
83 QStringLiteral("elvis.angelaccio@kde.org"));
84 aboutData
.addAuthor(i18nc("@info:credit", "Emmanuel Pescosta"),
85 i18nc("@info:credit", "Maintainer (2014-2018) and developer"),
86 QStringLiteral("emmanuelpescosta099@gmail.com"));
87 aboutData
.addAuthor(i18nc("@info:credit", "Frank Reininghaus"),
88 i18nc("@info:credit", "Maintainer (2012-2014) and developer"),
89 QStringLiteral("frank78ac@googlemail.com"));
90 aboutData
.addAuthor(i18nc("@info:credit", "Peter Penz"),
91 i18nc("@info:credit", "Maintainer and developer (2006-2012)"),
92 QStringLiteral("peter.penz19@gmail.com"));
93 aboutData
.addAuthor(i18nc("@info:credit", "Sebastian Trüg"),
94 i18nc("@info:credit", "Developer"),
95 QStringLiteral("trueg@kde.org"));
96 aboutData
.addAuthor(i18nc("@info:credit", "David Faure"),
97 i18nc("@info:credit", "Developer"),
98 QStringLiteral("faure@kde.org"));
99 aboutData
.addAuthor(i18nc("@info:credit", "Aaron J. Seigo"),
100 i18nc("@info:credit", "Developer"),
101 QStringLiteral("aseigo@kde.org"));
102 aboutData
.addAuthor(i18nc("@info:credit", "Rafael Fernández López"),
103 i18nc("@info:credit", "Developer"),
104 QStringLiteral("ereslibre@kde.org"));
105 aboutData
.addAuthor(i18nc("@info:credit", "Kevin Ottens"),
106 i18nc("@info:credit", "Developer"),
107 QStringLiteral("ervin@kde.org"));
108 aboutData
.addAuthor(i18nc("@info:credit", "Holger Freyther"),
109 i18nc("@info:credit", "Developer"),
110 QStringLiteral("freyther@gmx.net"));
111 aboutData
.addAuthor(i18nc("@info:credit", "Max Blazejak"),
112 i18nc("@info:credit", "Developer"),
113 QStringLiteral("m43ksrocks@gmail.com"));
114 aboutData
.addAuthor(i18nc("@info:credit", "Michael Austin"),
115 i18nc("@info:credit", "Documentation"),
116 QStringLiteral("tuxedup@users.sourceforge.net"));
118 KAboutData::setApplicationData(aboutData
);
120 QCommandLineParser parser
;
121 aboutData
.setupCommandLine(&parser
);
123 // command line options
124 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"), i18nc("@info:shell", "The files and folders passed as arguments "
125 "will be selected.")));
126 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
127 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("new-window"), i18nc("@info:shell", "Dolphin will explicitly open in a new window.")));
128 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface)")));
129 parser
.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open"));
132 aboutData
.processCommandLine(&parser
);
134 const bool splitView
= parser
.isSet(QStringLiteral("split")) || GeneralSettings::splitView();
135 const bool openFiles
= parser
.isSet(QStringLiteral("select"));
136 const QStringList args
= parser
.positionalArguments();
137 QList
<QUrl
> urls
= Dolphin::validateUris(args
);
138 // We later mutate urls, so we need to store if it was empty originally
139 const bool startedWithURLs
= !urls
.isEmpty();
142 if (parser
.isSet(QStringLiteral("daemon"))) {
143 // Disable session management for the daemonized version
144 // See https://bugs.kde.org/show_bug.cgi?id=417219
145 auto disableSessionManagement
= [](QSessionManager
&sm
) {
146 sm
.setRestartHint(QSessionManager::RestartNever
);
148 QObject::connect(&app
, &QGuiApplication::commitDataRequest
, disableSessionManagement
);
149 QObject::connect(&app
, &QGuiApplication::saveStateRequest
, disableSessionManagement
);
151 KDBusService dolphinDBusService
;
152 DBusInterface interface
;
153 interface
.setAsDaemon();
157 if (!parser
.isSet(QStringLiteral("new-window"))) {
158 if (Dolphin::attachToExistingInstance(urls
, openFiles
, splitView
)) {
159 // Successfully attached to existing instance of Dolphin
164 if (!startedWithURLs
) {
165 // We need at least one URL to open Dolphin
166 urls
.append(Dolphin::homeUrl());
169 if (splitView
&& urls
.size() < 2) {
170 // Split view does only make sense if we have at least 2 URLs
171 urls
.append(urls
.last());
174 DolphinMainWindow
* mainWindow
= new DolphinMainWindow();
177 mainWindow
->openFiles(urls
, splitView
);
179 mainWindow
->openDirectories(urls
, splitView
);
184 // Allow starting Dolphin on a system that is not running DBus:
185 KDBusService::StartupOptions serviceOptions
= KDBusService::Multiple
;
186 if (!QDBusConnection::sessionBus().isConnected()) {
187 serviceOptions
|= KDBusService::NoExitOnFailure
;
189 KDBusService
dolphinDBusService(serviceOptions
);
190 DBusInterface interface
;
192 if (!app
.isSessionRestored()) {
193 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
196 // Only restore session if:
197 // 1. Not explicitly opening a new instance
198 // 2. The "remember state" setting is enabled or session restoration after
200 // 3. There is a session available to restore
201 if (!parser
.isSet(QStringLiteral("new-window"))
202 && (app
.isSessionRestored() || GeneralSettings::rememberOpenedTabs())
204 // Get saved state data for the last-closed Dolphin instance
205 const QString serviceName
= QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid());
206 if (Dolphin::dolphinGuiInstances(serviceName
).size() > 0) {
207 const QString className
= KXmlGuiWindow::classNameOfToplevel(1);
208 if (className
== QLatin1String("DolphinMainWindow")) {
209 mainWindow
->restore(1);
210 // If the user passed any URLs to Dolphin, open those in the
211 // window after session-restoring it
212 if (startedWithURLs
) {
214 mainWindow
->openFiles(urls
, splitView
);
216 mainWindow
->openDirectories(urls
, splitView
);
220 qCWarning(DolphinDebug
) << "Unknown class " << className
<< " in session saved data!";
225 #ifdef HAVE_KUSERFEEDBACK
226 auto feedbackProvider
= DolphinFeedbackProvider::instance();
227 Q_UNUSED(feedbackProvider
)
230 return app
.exec(); // krazy:exclude=crash;