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"
18 #include <KDBusService>
19 #include <KLocalizedString>
20 #include <Kdelibs4ConfigMigrator>
23 #include <QApplication>
24 #include <QCommandLineParser>
25 #include <QDBusConnection>
26 #include <QDBusInterface>
27 #include <QDBusAbstractInterface>
28 #include <QDBusConnectionInterface>
35 extern "C" Q_DECL_EXPORT
int kdemain(int argc
, char **argv
)
38 // Prohibit using sudo or kdesu (but allow using the root user directly)
40 if (!qEnvironmentVariableIsEmpty("SUDO_USER")) {
41 std::cout
<< "Executing Dolphin with sudo is not possible due to unfixable security vulnerabilities." << std::endl
;
43 } else if (!qEnvironmentVariableIsEmpty("KDESU_USER")) {
44 std::cout
<< "Executing Dolphin with kdesu is not possible due to unfixable security vulnerabilities." << std::endl
;
51 * enable high dpi support
53 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps
, true);
54 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling
, true);
56 QApplication
app(argc
, argv
);
57 app
.setWindowIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"), app
.windowIcon()));
61 Kdelibs4ConfigMigrator
migrate(QStringLiteral("dolphin"));
62 migrate
.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
63 migrate
.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
66 KLocalizedString::setApplicationDomain("dolphin");
68 KAboutData
aboutData(QStringLiteral("dolphin"), i18n("Dolphin"), QStringLiteral(DOLPHIN_VERSION_STRING
),
69 i18nc("@title", "File Manager"),
71 i18nc("@info:credit", "(C) 2006-2018 Peter Penz, Frank Reininghaus, Emmanuel Pescosta and Elvis Angelaccio"));
72 aboutData
.setHomepage(QStringLiteral("https://kde.org/applications/system/org.kde.dolphin"));
73 aboutData
.addAuthor(i18nc("@info:credit", "Elvis Angelaccio"),
74 i18nc("@info:credit", "Maintainer (since 2018) and developer"),
75 QStringLiteral("elvis.angelaccio@kde.org"));
76 aboutData
.addAuthor(i18nc("@info:credit", "Emmanuel Pescosta"),
77 i18nc("@info:credit", "Maintainer (2014-2018) and developer"),
78 QStringLiteral("emmanuelpescosta099@gmail.com"));
79 aboutData
.addAuthor(i18nc("@info:credit", "Frank Reininghaus"),
80 i18nc("@info:credit", "Maintainer (2012-2014) and developer"),
81 QStringLiteral("frank78ac@googlemail.com"));
82 aboutData
.addAuthor(i18nc("@info:credit", "Peter Penz"),
83 i18nc("@info:credit", "Maintainer and developer (2006-2012)"),
84 QStringLiteral("peter.penz19@gmail.com"));
85 aboutData
.addAuthor(i18nc("@info:credit", "Sebastian Trüg"),
86 i18nc("@info:credit", "Developer"),
87 QStringLiteral("trueg@kde.org"));
88 aboutData
.addAuthor(i18nc("@info:credit", "David Faure"),
89 i18nc("@info:credit", "Developer"),
90 QStringLiteral("faure@kde.org"));
91 aboutData
.addAuthor(i18nc("@info:credit", "Aaron J. Seigo"),
92 i18nc("@info:credit", "Developer"),
93 QStringLiteral("aseigo@kde.org"));
94 aboutData
.addAuthor(i18nc("@info:credit", "Rafael Fernández López"),
95 i18nc("@info:credit", "Developer"),
96 QStringLiteral("ereslibre@kde.org"));
97 aboutData
.addAuthor(i18nc("@info:credit", "Kevin Ottens"),
98 i18nc("@info:credit", "Developer"),
99 QStringLiteral("ervin@kde.org"));
100 aboutData
.addAuthor(i18nc("@info:credit", "Holger Freyther"),
101 i18nc("@info:credit", "Developer"),
102 QStringLiteral("freyther@gmx.net"));
103 aboutData
.addAuthor(i18nc("@info:credit", "Max Blazejak"),
104 i18nc("@info:credit", "Developer"),
105 QStringLiteral("m43ksrocks@gmail.com"));
106 aboutData
.addAuthor(i18nc("@info:credit", "Michael Austin"),
107 i18nc("@info:credit", "Documentation"),
108 QStringLiteral("tuxedup@users.sourceforge.net"));
110 KAboutData::setApplicationData(aboutData
);
112 QCommandLineParser parser
;
113 aboutData
.setupCommandLine(&parser
);
115 // command line options
116 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"), i18nc("@info:shell", "The files and folders passed as arguments "
117 "will be selected.")));
118 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
119 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("new-window"), i18nc("@info:shell", "Dolphin will explicitly open in a new window.")));
120 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface)")));
121 parser
.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open"));
124 aboutData
.processCommandLine(&parser
);
126 const bool splitView
= parser
.isSet(QStringLiteral("split")) || GeneralSettings::splitView();
127 const bool openFiles
= parser
.isSet(QStringLiteral("select"));
128 const QStringList args
= parser
.positionalArguments();
129 QList
<QUrl
> urls
= Dolphin::validateUris(args
);
130 // We later mutate urls, so we need to store if it was empty originally
131 const bool startedWithURLs
= !urls
.isEmpty();
134 if (parser
.isSet(QStringLiteral("daemon"))) {
135 KDBusService dolphinDBusService
;
136 DBusInterface interface
;
137 interface
.setAsDaemon();
141 if (!parser
.isSet(QStringLiteral("new-window"))) {
142 if (Dolphin::attachToExistingInstance(urls
, openFiles
, splitView
)) {
143 // Successfully attached to existing instance of Dolphin
148 if (!startedWithURLs
) {
149 // We need at least one URL to open Dolphin
150 urls
.append(Dolphin::homeUrl());
153 if (splitView
&& urls
.size() < 2) {
154 // Split view does only make sense if we have at least 2 URLs
155 urls
.append(urls
.last());
158 DolphinMainWindow
* mainWindow
= new DolphinMainWindow();
161 mainWindow
->openFiles(urls
, splitView
);
163 mainWindow
->openDirectories(urls
, splitView
);
168 KDBusService dolphinDBusService
;
169 DBusInterface interface
;
171 if (!app
.isSessionRestored()) {
172 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
175 // Only restore session if:
176 // 1. Dolphin was not started with command line args
177 // 2. The "remember state" setting is enabled or session restoration after
179 // 3. There is a session available to restore
180 if (!startedWithURLs
&& (app
.isSessionRestored() || GeneralSettings::rememberOpenedTabs()) ) {
181 // Get saved state data for the last-closed Dolphin instance
182 const QString serviceName
= QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid());
183 if (Dolphin::dolphinGuiInstances(serviceName
).size() > 0) {
184 const QString className
= KXmlGuiWindow::classNameOfToplevel(1);
185 if (className
== QLatin1String("DolphinMainWindow")) {
186 mainWindow
->restore(1);
188 qCWarning(DolphinDebug
) << "Unknown class " << className
<< " in session saved data!";
193 return app
.exec(); // krazy:exclude=crash;