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>
35 #include <QApplication>
36 #include <QCommandLineParser>
37 #include <QDBusConnection>
38 #include <QDBusInterface>
39 #include <QDBusAbstractInterface>
40 #include <QDBusConnectionInterface>
47 extern "C" Q_DECL_EXPORT
int kdemain(int argc
, char **argv
)
50 // Prohibit using sudo or kdesu (but allow using the root user directly)
52 if (!qEnvironmentVariableIsEmpty("SUDO_USER")) {
53 std::cout
<< "Executing Dolphin with sudo is not possible due to unfixable security vulnerabilities." << std::endl
;
55 } else if (!qEnvironmentVariableIsEmpty("KDESU_USER")) {
56 std::cout
<< "Executing Dolphin with kdesu is not possible due to unfixable security vulnerabilities." << std::endl
;
62 QApplication
app(argc
, argv
);
63 app
.setAttribute(Qt::AA_UseHighDpiPixmaps
, true);
64 app
.setWindowIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"), app
.windowIcon()));
68 Kdelibs4ConfigMigrator
migrate(QStringLiteral("dolphin"));
69 migrate
.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
70 migrate
.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
73 KLocalizedString::setApplicationDomain("dolphin");
75 KAboutData
aboutData(QStringLiteral("dolphin"), i18n("Dolphin"), QStringLiteral(DOLPHIN_VERSION_STRING
),
76 i18nc("@title", "File Manager"),
78 i18nc("@info:credit", "(C) 2006-2018 Peter Penz, Frank Reininghaus, Emmanuel Pescosta and Elvis Angelaccio"));
79 aboutData
.setHomepage(QStringLiteral("https://dolphin.kde.org"));
80 aboutData
.addAuthor(i18nc("@info:credit", "Elvis Angelaccio"),
81 i18nc("@info:credit", "Maintainer (since 2018) and developer"),
82 QStringLiteral("elvis.angelaccio@kde.org"));
83 aboutData
.addAuthor(i18nc("@info:credit", "Emmanuel Pescosta"),
84 i18nc("@info:credit", "Maintainer (2014-2018) and developer"),
85 QStringLiteral("emmanuelpescosta099@gmail.com"));
86 aboutData
.addAuthor(i18nc("@info:credit", "Frank Reininghaus"),
87 i18nc("@info:credit", "Maintainer (2012-2014) and developer"),
88 QStringLiteral("frank78ac@googlemail.com"));
89 aboutData
.addAuthor(i18nc("@info:credit", "Peter Penz"),
90 i18nc("@info:credit", "Maintainer and developer (2006-2012)"),
91 QStringLiteral("peter.penz19@gmail.com"));
92 aboutData
.addAuthor(i18nc("@info:credit", "Sebastian Trüg"),
93 i18nc("@info:credit", "Developer"),
94 QStringLiteral("trueg@kde.org"));
95 aboutData
.addAuthor(i18nc("@info:credit", "David Faure"),
96 i18nc("@info:credit", "Developer"),
97 QStringLiteral("faure@kde.org"));
98 aboutData
.addAuthor(i18nc("@info:credit", "Aaron J. Seigo"),
99 i18nc("@info:credit", "Developer"),
100 QStringLiteral("aseigo@kde.org"));
101 aboutData
.addAuthor(i18nc("@info:credit", "Rafael Fernández López"),
102 i18nc("@info:credit", "Developer"),
103 QStringLiteral("ereslibre@kde.org"));
104 aboutData
.addAuthor(i18nc("@info:credit", "Kevin Ottens"),
105 i18nc("@info:credit", "Developer"),
106 QStringLiteral("ervin@kde.org"));
107 aboutData
.addAuthor(i18nc("@info:credit", "Holger Freyther"),
108 i18nc("@info:credit", "Developer"),
109 QStringLiteral("freyther@gmx.net"));
110 aboutData
.addAuthor(i18nc("@info:credit", "Max Blazejak"),
111 i18nc("@info:credit", "Developer"),
112 QStringLiteral("m43ksrocks@gmail.com"));
113 aboutData
.addAuthor(i18nc("@info:credit", "Michael Austin"),
114 i18nc("@info:credit", "Documentation"),
115 QStringLiteral("tuxedup@users.sourceforge.net"));
117 KAboutData::setApplicationData(aboutData
);
119 KDBusService dolphinDBusService
;
120 DBusInterface interface
;
122 QCommandLineParser parser
;
123 aboutData
.setupCommandLine(&parser
);
125 // command line options
126 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"), i18nc("@info:shell", "The files and folders passed as arguments "
127 "will be selected.")));
128 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
129 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("new-window"), i18nc("@info:shell", "Dolphin will explicitly open in a new window.")));
130 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface)")));
131 parser
.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open"));
134 aboutData
.processCommandLine(&parser
);
136 const bool splitView
= parser
.isSet(QStringLiteral("split")) || GeneralSettings::splitView();
137 const bool openFiles
= parser
.isSet(QStringLiteral("select"));
138 const QStringList args
= parser
.positionalArguments();
139 QList
<QUrl
> urls
= Dolphin::validateUris(args
);
141 if (parser
.isSet(QStringLiteral("daemon"))) {
145 if (!parser
.isSet(QStringLiteral("new-window"))) {
146 if (Dolphin::attachToExistingInstance(urls
, openFiles
, splitView
)) {
147 // Successfully attached to existing instance of Dolphin
152 if (urls
.isEmpty()) {
153 // We need at least one URL to open Dolphin
154 urls
.append(Dolphin::homeUrl());
157 if (splitView
&& urls
.size() < 2) {
158 // Split view does only make sense if we have at least 2 URLs
159 urls
.append(urls
.last());
162 DolphinMainWindow
* mainWindow
= new DolphinMainWindow();
165 mainWindow
->openFiles(urls
, splitView
);
167 mainWindow
->openDirectories(urls
, splitView
);
172 if (app
.isSessionRestored()) {
173 const QString className
= KXmlGuiWindow::classNameOfToplevel(1);
174 if (className
== QLatin1String("DolphinMainWindow")) {
175 mainWindow
->restore(1);
177 qCWarning(DolphinDebug
) << "Unknown class " << className
<< " in session saved data!";
181 return app
.exec(); // krazy:exclude=crash;