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>
27 #include <QApplication>
28 #include <QCommandLineParser>
29 #include <QDBusConnection>
30 #include <QDBusInterface>
31 #include <QDBusAbstractInterface>
32 #include <QDBusConnectionInterface>
33 #include <QSessionManager>
40 int main(int argc
, char **argv
)
43 // Prohibit using sudo or kdesu (but allow using the root user directly)
45 if (!qEnvironmentVariableIsEmpty("SUDO_USER")) {
46 std::cout
<< "Executing Dolphin with sudo is not possible due to unfixable security vulnerabilities." << std::endl
;
48 } else if (!qEnvironmentVariableIsEmpty("KDESU_USER")) {
49 std::cout
<< "Executing Dolphin with kdesu is not possible due to unfixable security vulnerabilities." << std::endl
;
56 * enable high dpi support
58 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps
, true);
59 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling
, true);
61 QApplication
app(argc
, argv
);
62 app
.setWindowIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"), app
.windowIcon()));
66 Kdelibs4ConfigMigrator
migrate(QStringLiteral("dolphin"));
67 migrate
.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
68 migrate
.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
71 KLocalizedString::setApplicationDomain("dolphin");
73 KAboutData
aboutData(QStringLiteral("dolphin"), i18n("Dolphin"), QStringLiteral(DOLPHIN_VERSION_STRING
),
74 i18nc("@title", "File Manager"),
76 i18nc("@info:credit", "(C) 2006-2018 Peter Penz, Frank Reininghaus, Emmanuel Pescosta and Elvis Angelaccio"));
77 aboutData
.setHomepage(QStringLiteral("https://kde.org/applications/system/org.kde.dolphin"));
78 aboutData
.addAuthor(i18nc("@info:credit", "Elvis Angelaccio"),
79 i18nc("@info:credit", "Maintainer (since 2018) and developer"),
80 QStringLiteral("elvis.angelaccio@kde.org"));
81 aboutData
.addAuthor(i18nc("@info:credit", "Emmanuel Pescosta"),
82 i18nc("@info:credit", "Maintainer (2014-2018) and developer"),
83 QStringLiteral("emmanuelpescosta099@gmail.com"));
84 aboutData
.addAuthor(i18nc("@info:credit", "Frank Reininghaus"),
85 i18nc("@info:credit", "Maintainer (2012-2014) and developer"),
86 QStringLiteral("frank78ac@googlemail.com"));
87 aboutData
.addAuthor(i18nc("@info:credit", "Peter Penz"),
88 i18nc("@info:credit", "Maintainer and developer (2006-2012)"),
89 QStringLiteral("peter.penz19@gmail.com"));
90 aboutData
.addAuthor(i18nc("@info:credit", "Sebastian Trüg"),
91 i18nc("@info:credit", "Developer"),
92 QStringLiteral("trueg@kde.org"));
93 aboutData
.addAuthor(i18nc("@info:credit", "David Faure"),
94 i18nc("@info:credit", "Developer"),
95 QStringLiteral("faure@kde.org"));
96 aboutData
.addAuthor(i18nc("@info:credit", "Aaron J. Seigo"),
97 i18nc("@info:credit", "Developer"),
98 QStringLiteral("aseigo@kde.org"));
99 aboutData
.addAuthor(i18nc("@info:credit", "Rafael Fernández López"),
100 i18nc("@info:credit", "Developer"),
101 QStringLiteral("ereslibre@kde.org"));
102 aboutData
.addAuthor(i18nc("@info:credit", "Kevin Ottens"),
103 i18nc("@info:credit", "Developer"),
104 QStringLiteral("ervin@kde.org"));
105 aboutData
.addAuthor(i18nc("@info:credit", "Holger Freyther"),
106 i18nc("@info:credit", "Developer"),
107 QStringLiteral("freyther@gmx.net"));
108 aboutData
.addAuthor(i18nc("@info:credit", "Max Blazejak"),
109 i18nc("@info:credit", "Developer"),
110 QStringLiteral("m43ksrocks@gmail.com"));
111 aboutData
.addAuthor(i18nc("@info:credit", "Michael Austin"),
112 i18nc("@info:credit", "Documentation"),
113 QStringLiteral("tuxedup@users.sourceforge.net"));
115 KAboutData::setApplicationData(aboutData
);
117 QCommandLineParser parser
;
118 aboutData
.setupCommandLine(&parser
);
120 // command line options
121 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"), i18nc("@info:shell", "The files and folders passed as arguments "
122 "will be selected.")));
123 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
124 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("new-window"), i18nc("@info:shell", "Dolphin will explicitly open in a new window.")));
125 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface)")));
126 parser
.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open"));
129 aboutData
.processCommandLine(&parser
);
131 const bool splitView
= parser
.isSet(QStringLiteral("split")) || GeneralSettings::splitView();
132 const bool openFiles
= parser
.isSet(QStringLiteral("select"));
133 const QStringList args
= parser
.positionalArguments();
134 QList
<QUrl
> urls
= Dolphin::validateUris(args
);
135 // We later mutate urls, so we need to store if it was empty originally
136 const bool startedWithURLs
= !urls
.isEmpty();
139 if (parser
.isSet(QStringLiteral("daemon"))) {
140 // Disable session management for the daemonized version
141 // See https://bugs.kde.org/show_bug.cgi?id=417219
142 auto disableSessionManagement
= [](QSessionManager
&sm
) {
143 sm
.setRestartHint(QSessionManager::RestartNever
);
145 QObject::connect(&app
, &QGuiApplication::commitDataRequest
, disableSessionManagement
);
146 QObject::connect(&app
, &QGuiApplication::saveStateRequest
, disableSessionManagement
);
148 KDBusService dolphinDBusService
;
149 DBusInterface interface
;
150 interface
.setAsDaemon();
154 if (!parser
.isSet(QStringLiteral("new-window"))) {
155 if (Dolphin::attachToExistingInstance(urls
, openFiles
, splitView
)) {
156 // Successfully attached to existing instance of Dolphin
161 if (!startedWithURLs
) {
162 // We need at least one URL to open Dolphin
163 urls
.append(Dolphin::homeUrl());
166 if (splitView
&& urls
.size() < 2) {
167 // Split view does only make sense if we have at least 2 URLs
168 urls
.append(urls
.last());
171 DolphinMainWindow
* mainWindow
= new DolphinMainWindow();
174 mainWindow
->openFiles(urls
, splitView
);
176 mainWindow
->openDirectories(urls
, splitView
);
181 KDBusService dolphinDBusService
;
182 DBusInterface interface
;
184 if (!app
.isSessionRestored()) {
185 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
188 // Only restore session if:
189 // 1. Not explicitly opening a new instance
190 // 2. The "remember state" setting is enabled or session restoration after
192 // 3. There is a session available to restore
193 if (!parser
.isSet(QStringLiteral("new-window"))
194 && (app
.isSessionRestored() || GeneralSettings::rememberOpenedTabs())
196 // Get saved state data for the last-closed Dolphin instance
197 const QString serviceName
= QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid());
198 if (Dolphin::dolphinGuiInstances(serviceName
).size() > 0) {
199 const QString className
= KXmlGuiWindow::classNameOfToplevel(1);
200 if (className
== QLatin1String("DolphinMainWindow")) {
201 mainWindow
->restore(1);
202 // If the user passed any URLs to Dolphin, open those in the
203 // window after session-restoring it
204 if (startedWithURLs
) {
205 mainWindow
->openDirectories(urls
, splitView
);
208 // Now handle invalid locations in the set of active views to
209 // avoid issues like https://bugs.kde.org/show_bug.cgi?id=427619
210 mainWindow
->setViewsWithInvalidPathsToHome();
212 qCWarning(DolphinDebug
) << "Unknown class " << className
<< " in session saved data!";
217 #ifdef HAVE_KUSERFEEDBACK
218 auto feedbackProvider
= DolphinFeedbackProvider::instance();
219 Q_UNUSED(feedbackProvider
)
222 return app
.exec(); // krazy:exclude=crash;