]> cloud.milkyroute.net Git - dolphin.git/blob - src/main.cpp
Making sure that DBus objects are all created before the service
[dolphin.git] / src / main.cpp
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> *
5 * *
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. *
10 * *
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. *
15 * *
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 ***************************************************************************/
21
22 #include "dbusinterface.h"
23 #include "dolphin_generalsettings.h"
24 #include "dolphin_version.h"
25 #include "dolphindebug.h"
26 #include "dolphinmainwindow.h"
27 #include "global.h"
28
29 #include <KAboutData>
30 #include <KCrash>
31 #include <KDBusService>
32 #include <KLocalizedString>
33 #include <Kdelibs4ConfigMigrator>
34
35 #include <QApplication>
36 #include <QCommandLineParser>
37 #include <QDBusConnection>
38 #include <QDBusInterface>
39 #include <QDBusAbstractInterface>
40 #include <QDBusConnectionInterface>
41
42 #ifndef Q_OS_WIN
43 #include <unistd.h>
44 #endif
45 #include <iostream>
46
47 extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
48 {
49 #ifndef Q_OS_WIN
50 // Prohibit using sudo or kdesu (but allow using the root user directly)
51 if (getuid() == 0) {
52 if (!qEnvironmentVariableIsEmpty("SUDO_USER")) {
53 std::cout << "Executing Dolphin with sudo is not possible due to unfixable security vulnerabilities." << std::endl;
54 return EXIT_FAILURE;
55 } else if (!qEnvironmentVariableIsEmpty("KDESU_USER")) {
56 std::cout << "Executing Dolphin with kdesu is not possible due to unfixable security vulnerabilities." << std::endl;
57 return EXIT_FAILURE;
58 }
59 }
60 #endif
61
62 QApplication app(argc, argv);
63 app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
64 app.setWindowIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"), app.windowIcon()));
65
66 KCrash::initialize();
67
68 Kdelibs4ConfigMigrator migrate(QStringLiteral("dolphin"));
69 migrate.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
70 migrate.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
71 migrate.migrate();
72
73 KLocalizedString::setApplicationDomain("dolphin");
74
75 KAboutData aboutData(QStringLiteral("dolphin"), i18n("Dolphin"), QStringLiteral(DOLPHIN_VERSION_STRING),
76 i18nc("@title", "File Manager"),
77 KAboutLicense::GPL,
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"));
116
117 KAboutData::setApplicationData(aboutData);
118
119 QCommandLineParser parser;
120 aboutData.setupCommandLine(&parser);
121
122 // command line options
123 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"), i18nc("@info:shell", "The files and folders passed as arguments "
124 "will be selected.")));
125 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
126 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("new-window"), i18nc("@info:shell", "Dolphin will explicitly open in a new window.")));
127 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface)")));
128 parser.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open"));
129
130 parser.process(app);
131 aboutData.processCommandLine(&parser);
132
133 const bool splitView = parser.isSet(QStringLiteral("split")) || GeneralSettings::splitView();
134 const bool openFiles = parser.isSet(QStringLiteral("select"));
135 const QStringList args = parser.positionalArguments();
136 QList<QUrl> urls = Dolphin::validateUris(args);
137
138 if (parser.isSet(QStringLiteral("daemon"))) {
139 KDBusService dolphinDBusService;
140 DBusInterface interface;
141 return app.exec();
142 }
143
144 if (!parser.isSet(QStringLiteral("new-window"))) {
145 if (Dolphin::attachToExistingInstance(urls, openFiles, splitView)) {
146 // Successfully attached to existing instance of Dolphin
147 return 0;
148 }
149 }
150
151 if (urls.isEmpty()) {
152 // We need at least one URL to open Dolphin
153 urls.append(Dolphin::homeUrl());
154 }
155
156 if (splitView && urls.size() < 2) {
157 // Split view does only make sense if we have at least 2 URLs
158 urls.append(urls.last());
159 }
160
161 DolphinMainWindow* mainWindow = new DolphinMainWindow();
162
163 if (openFiles) {
164 mainWindow->openFiles(urls, splitView);
165 } else {
166 mainWindow->openDirectories(urls, splitView);
167 }
168
169 mainWindow->show();
170
171 if (app.isSessionRestored()) {
172 const QString className = KXmlGuiWindow::classNameOfToplevel(1);
173 if (className == QLatin1String("DolphinMainWindow")) {
174 mainWindow->restore(1);
175 } else {
176 qCWarning(DolphinDebug) << "Unknown class " << className << " in session saved data!";
177 }
178 }
179
180 KDBusService dolphinDBusService;
181 DBusInterface interface;
182
183 return app.exec(); // krazy:exclude=crash;
184 }