1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2015 by Mathieu Tarral <mathieu.tarral@gmail.com> *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
22 #include "dbusinterface.h"
23 #include "dolphin_generalsettings.h"
24 #include "dolphin_version.h"
25 #include "dolphindebug.h"
26 #include "dolphinmainwindow.h"
31 #include <KDBusService>
32 #include <KLocalizedString>
33 #include <Kdelibs4ConfigMigrator>
36 #include <QApplication>
37 #include <QCommandLineParser>
38 #include <QDBusConnection>
39 #include <QDBusInterface>
40 #include <QDBusAbstractInterface>
41 #include <QDBusConnectionInterface>
48 extern "C" Q_DECL_EXPORT
int kdemain(int argc
, char **argv
)
51 // Prohibit using sudo or kdesu (but allow using the root user directly)
53 if (!qEnvironmentVariableIsEmpty("SUDO_USER")) {
54 std::cout
<< "Executing Dolphin with sudo is not possible due to unfixable security vulnerabilities." << std::endl
;
56 } else if (!qEnvironmentVariableIsEmpty("KDESU_USER")) {
57 std::cout
<< "Executing Dolphin with kdesu is not possible due to unfixable security vulnerabilities." << std::endl
;
64 * enable high dpi support
66 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps
, true);
67 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling
, true);
69 QApplication
app(argc
, argv
);
70 app
.setWindowIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"), app
.windowIcon()));
74 Kdelibs4ConfigMigrator
migrate(QStringLiteral("dolphin"));
75 migrate
.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
76 migrate
.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
79 KLocalizedString::setApplicationDomain("dolphin");
81 KAboutData
aboutData(QStringLiteral("dolphin"), i18n("Dolphin"), QStringLiteral(DOLPHIN_VERSION_STRING
),
82 i18nc("@title", "File Manager"),
84 i18nc("@info:credit", "(C) 2006-2018 Peter Penz, Frank Reininghaus, Emmanuel Pescosta and Elvis Angelaccio"));
85 aboutData
.setHomepage(QStringLiteral("https://kde.org/applications/system/org.kde.dolphin"));
86 aboutData
.addAuthor(i18nc("@info:credit", "Elvis Angelaccio"),
87 i18nc("@info:credit", "Maintainer (since 2018) and developer"),
88 QStringLiteral("elvis.angelaccio@kde.org"));
89 aboutData
.addAuthor(i18nc("@info:credit", "Emmanuel Pescosta"),
90 i18nc("@info:credit", "Maintainer (2014-2018) and developer"),
91 QStringLiteral("emmanuelpescosta099@gmail.com"));
92 aboutData
.addAuthor(i18nc("@info:credit", "Frank Reininghaus"),
93 i18nc("@info:credit", "Maintainer (2012-2014) and developer"),
94 QStringLiteral("frank78ac@googlemail.com"));
95 aboutData
.addAuthor(i18nc("@info:credit", "Peter Penz"),
96 i18nc("@info:credit", "Maintainer and developer (2006-2012)"),
97 QStringLiteral("peter.penz19@gmail.com"));
98 aboutData
.addAuthor(i18nc("@info:credit", "Sebastian Trüg"),
99 i18nc("@info:credit", "Developer"),
100 QStringLiteral("trueg@kde.org"));
101 aboutData
.addAuthor(i18nc("@info:credit", "David Faure"),
102 i18nc("@info:credit", "Developer"),
103 QStringLiteral("faure@kde.org"));
104 aboutData
.addAuthor(i18nc("@info:credit", "Aaron J. Seigo"),
105 i18nc("@info:credit", "Developer"),
106 QStringLiteral("aseigo@kde.org"));
107 aboutData
.addAuthor(i18nc("@info:credit", "Rafael Fernández López"),
108 i18nc("@info:credit", "Developer"),
109 QStringLiteral("ereslibre@kde.org"));
110 aboutData
.addAuthor(i18nc("@info:credit", "Kevin Ottens"),
111 i18nc("@info:credit", "Developer"),
112 QStringLiteral("ervin@kde.org"));
113 aboutData
.addAuthor(i18nc("@info:credit", "Holger Freyther"),
114 i18nc("@info:credit", "Developer"),
115 QStringLiteral("freyther@gmx.net"));
116 aboutData
.addAuthor(i18nc("@info:credit", "Max Blazejak"),
117 i18nc("@info:credit", "Developer"),
118 QStringLiteral("m43ksrocks@gmail.com"));
119 aboutData
.addAuthor(i18nc("@info:credit", "Michael Austin"),
120 i18nc("@info:credit", "Documentation"),
121 QStringLiteral("tuxedup@users.sourceforge.net"));
123 KAboutData::setApplicationData(aboutData
);
125 QCommandLineParser parser
;
126 aboutData
.setupCommandLine(&parser
);
128 // command line options
129 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"), i18nc("@info:shell", "The files and folders passed as arguments "
130 "will be selected.")));
131 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
132 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("new-window"), i18nc("@info:shell", "Dolphin will explicitly open in a new window.")));
133 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface)")));
134 parser
.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open"));
137 aboutData
.processCommandLine(&parser
);
139 const bool splitView
= parser
.isSet(QStringLiteral("split")) || GeneralSettings::splitView();
140 const bool openFiles
= parser
.isSet(QStringLiteral("select"));
141 const QStringList args
= parser
.positionalArguments();
142 QList
<QUrl
> urls
= Dolphin::validateUris(args
);
143 // We later mutate urls, so we need to store if it was empty originally
144 const bool startedWithURLs
= !urls
.isEmpty();
147 if (parser
.isSet(QStringLiteral("daemon"))) {
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 if (!app
.isSessionRestored()) {
182 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
185 // Only restore session if:
186 // 1. Dolphin was not started with command line args
187 // 2. The "remember state" setting is enabled or session restoration after
189 // 3. There is a session available to restore
190 if (!startedWithURLs
&& (app
.isSessionRestored() || GeneralSettings::rememberOpenedTabs()) ) {
191 // Get saved state data for the last-closed Dolphin instance
192 const QString serviceName
= QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid());
193 if (Dolphin::dolphinGuiInstances(serviceName
).size() > 0) {
194 const QString className
= KXmlGuiWindow::classNameOfToplevel(1);
195 if (className
== QLatin1String("DolphinMainWindow")) {
196 mainWindow
->restore(1);
198 qCWarning(DolphinDebug
) << "Unknown class " << className
<< " in session saved data!";
203 KDBusService dolphinDBusService
;
204 DBusInterface interface
;
206 return app
.exec(); // krazy:exclude=crash;