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
;
63 * enable high dpi support
65 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps
, true);
66 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling
, true);
68 QApplication
app(argc
, argv
);
69 app
.setWindowIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"), app
.windowIcon()));
73 Kdelibs4ConfigMigrator
migrate(QStringLiteral("dolphin"));
74 migrate
.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
75 migrate
.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
78 KLocalizedString::setApplicationDomain("dolphin");
80 KAboutData
aboutData(QStringLiteral("dolphin"), i18n("Dolphin"), QStringLiteral(DOLPHIN_VERSION_STRING
),
81 i18nc("@title", "File Manager"),
83 i18nc("@info:credit", "(C) 2006-2018 Peter Penz, Frank Reininghaus, Emmanuel Pescosta and Elvis Angelaccio"));
84 aboutData
.setHomepage(QStringLiteral("https://kde.org/applications/system/org.kde.dolphin"));
85 aboutData
.addAuthor(i18nc("@info:credit", "Elvis Angelaccio"),
86 i18nc("@info:credit", "Maintainer (since 2018) and developer"),
87 QStringLiteral("elvis.angelaccio@kde.org"));
88 aboutData
.addAuthor(i18nc("@info:credit", "Emmanuel Pescosta"),
89 i18nc("@info:credit", "Maintainer (2014-2018) and developer"),
90 QStringLiteral("emmanuelpescosta099@gmail.com"));
91 aboutData
.addAuthor(i18nc("@info:credit", "Frank Reininghaus"),
92 i18nc("@info:credit", "Maintainer (2012-2014) and developer"),
93 QStringLiteral("frank78ac@googlemail.com"));
94 aboutData
.addAuthor(i18nc("@info:credit", "Peter Penz"),
95 i18nc("@info:credit", "Maintainer and developer (2006-2012)"),
96 QStringLiteral("peter.penz19@gmail.com"));
97 aboutData
.addAuthor(i18nc("@info:credit", "Sebastian Trüg"),
98 i18nc("@info:credit", "Developer"),
99 QStringLiteral("trueg@kde.org"));
100 aboutData
.addAuthor(i18nc("@info:credit", "David Faure"),
101 i18nc("@info:credit", "Developer"),
102 QStringLiteral("faure@kde.org"));
103 aboutData
.addAuthor(i18nc("@info:credit", "Aaron J. Seigo"),
104 i18nc("@info:credit", "Developer"),
105 QStringLiteral("aseigo@kde.org"));
106 aboutData
.addAuthor(i18nc("@info:credit", "Rafael Fernández López"),
107 i18nc("@info:credit", "Developer"),
108 QStringLiteral("ereslibre@kde.org"));
109 aboutData
.addAuthor(i18nc("@info:credit", "Kevin Ottens"),
110 i18nc("@info:credit", "Developer"),
111 QStringLiteral("ervin@kde.org"));
112 aboutData
.addAuthor(i18nc("@info:credit", "Holger Freyther"),
113 i18nc("@info:credit", "Developer"),
114 QStringLiteral("freyther@gmx.net"));
115 aboutData
.addAuthor(i18nc("@info:credit", "Max Blazejak"),
116 i18nc("@info:credit", "Developer"),
117 QStringLiteral("m43ksrocks@gmail.com"));
118 aboutData
.addAuthor(i18nc("@info:credit", "Michael Austin"),
119 i18nc("@info:credit", "Documentation"),
120 QStringLiteral("tuxedup@users.sourceforge.net"));
122 KAboutData::setApplicationData(aboutData
);
124 QCommandLineParser parser
;
125 aboutData
.setupCommandLine(&parser
);
127 // command line options
128 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"), i18nc("@info:shell", "The files and folders passed as arguments "
129 "will be selected.")));
130 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
131 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("new-window"), i18nc("@info:shell", "Dolphin will explicitly open in a new window.")));
132 parser
.addOption(QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface)")));
133 parser
.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open"));
136 aboutData
.processCommandLine(&parser
);
138 const bool splitView
= parser
.isSet(QStringLiteral("split")) || GeneralSettings::splitView();
139 const bool openFiles
= parser
.isSet(QStringLiteral("select"));
140 const QStringList args
= parser
.positionalArguments();
141 QList
<QUrl
> urls
= Dolphin::validateUris(args
);
143 if (parser
.isSet(QStringLiteral("daemon"))) {
144 KDBusService dolphinDBusService
;
145 DBusInterface interface
;
146 interface
.setAsDaemon();
150 if (!parser
.isSet(QStringLiteral("new-window"))) {
151 if (Dolphin::attachToExistingInstance(urls
, openFiles
, splitView
)) {
152 // Successfully attached to existing instance of Dolphin
157 if (urls
.isEmpty()) {
158 // We need at least one URL to open Dolphin
159 urls
.append(Dolphin::homeUrl());
162 if (splitView
&& urls
.size() < 2) {
163 // Split view does only make sense if we have at least 2 URLs
164 urls
.append(urls
.last());
167 DolphinMainWindow
* mainWindow
= new DolphinMainWindow();
170 mainWindow
->openFiles(urls
, splitView
);
172 mainWindow
->openDirectories(urls
, splitView
);
177 if (app
.isSessionRestored()) {
178 const QString className
= KXmlGuiWindow::classNameOfToplevel(1);
179 if (className
== QLatin1String("DolphinMainWindow")) {
180 mainWindow
->restore(1);
182 qCWarning(DolphinDebug
) << "Unknown class " << className
<< " in session saved data!";
186 KDBusService dolphinDBusService
;
187 DBusInterface interface
;
189 return app
.exec(); // krazy:exclude=crash;