]> cloud.milkyroute.net Git - dolphin.git/blob - src/main.cpp
Set empty value for packagekit transaction flags
[dolphin.git] / src / main.cpp
1 /*
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>
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9 #include "dbusinterface.h"
10 #include "dolphin_generalsettings.h"
11 #include "dolphin_version.h"
12 #include "dolphindebug.h"
13 #include "dolphinmainwindow.h"
14 #include "global.h"
15 #include "config-kuserfeedback.h"
16 #ifdef HAVE_KUSERFEEDBACK
17 #include "userfeedback/dolphinfeedbackprovider.h"
18 #endif
19
20 #include <KAboutData>
21 #include <KCrash>
22 #include <KDBusService>
23 #include <KLocalizedString>
24 #include <KToolBar>
25 #include <Kdelibs4ConfigMigrator>
26 #include <KConfigGui>
27
28 #include <QApplication>
29 #include <QCommandLineParser>
30 #include <QDBusConnection>
31 #include <QDBusInterface>
32 #include <QDBusAbstractInterface>
33 #include <QDBusConnectionInterface>
34 #include <QSessionManager>
35
36 #ifndef Q_OS_WIN
37 #include <unistd.h>
38 #endif
39 #include <iostream>
40
41 extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
42 {
43 #ifndef Q_OS_WIN
44 // Prohibit using sudo or kdesu (but allow using the root user directly)
45 if (getuid() == 0) {
46 if (!qEnvironmentVariableIsEmpty("SUDO_USER")) {
47 std::cout << "Executing Dolphin with sudo is not possible due to unfixable security vulnerabilities." << std::endl;
48 return EXIT_FAILURE;
49 } else if (!qEnvironmentVariableIsEmpty("KDESU_USER")) {
50 std::cout << "Executing Dolphin with kdesu is not possible due to unfixable security vulnerabilities." << std::endl;
51 return EXIT_FAILURE;
52 }
53 }
54 #endif
55
56 /**
57 * enable high dpi support
58 */
59 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
60 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
61
62 QApplication app(argc, argv);
63 app.setWindowIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"), app.windowIcon()));
64
65 KCrash::initialize();
66
67 Kdelibs4ConfigMigrator migrate(QStringLiteral("dolphin"));
68 migrate.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
69 migrate.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
70 migrate.migrate();
71
72 KLocalizedString::setApplicationDomain("dolphin");
73
74 KAboutData aboutData(QStringLiteral("dolphin"), i18n("Dolphin"), QStringLiteral(DOLPHIN_VERSION_STRING),
75 i18nc("@title", "File Manager"),
76 KAboutLicense::GPL,
77 i18nc("@info:credit", "(C) 2006-2018 Peter Penz, Frank Reininghaus, Emmanuel Pescosta and Elvis Angelaccio"));
78 aboutData.setHomepage(QStringLiteral("https://kde.org/applications/system/org.kde.dolphin"));
79 aboutData.addAuthor(i18nc("@info:credit", "Elvis Angelaccio"),
80 i18nc("@info:credit", "Maintainer (since 2018) and developer"),
81 QStringLiteral("elvis.angelaccio@kde.org"));
82 aboutData.addAuthor(i18nc("@info:credit", "Emmanuel Pescosta"),
83 i18nc("@info:credit", "Maintainer (2014-2018) and developer"),
84 QStringLiteral("emmanuelpescosta099@gmail.com"));
85 aboutData.addAuthor(i18nc("@info:credit", "Frank Reininghaus"),
86 i18nc("@info:credit", "Maintainer (2012-2014) and developer"),
87 QStringLiteral("frank78ac@googlemail.com"));
88 aboutData.addAuthor(i18nc("@info:credit", "Peter Penz"),
89 i18nc("@info:credit", "Maintainer and developer (2006-2012)"),
90 QStringLiteral("peter.penz19@gmail.com"));
91 aboutData.addAuthor(i18nc("@info:credit", "Sebastian Trüg"),
92 i18nc("@info:credit", "Developer"),
93 QStringLiteral("trueg@kde.org"));
94 aboutData.addAuthor(i18nc("@info:credit", "David Faure"),
95 i18nc("@info:credit", "Developer"),
96 QStringLiteral("faure@kde.org"));
97 aboutData.addAuthor(i18nc("@info:credit", "Aaron J. Seigo"),
98 i18nc("@info:credit", "Developer"),
99 QStringLiteral("aseigo@kde.org"));
100 aboutData.addAuthor(i18nc("@info:credit", "Rafael Fernández López"),
101 i18nc("@info:credit", "Developer"),
102 QStringLiteral("ereslibre@kde.org"));
103 aboutData.addAuthor(i18nc("@info:credit", "Kevin Ottens"),
104 i18nc("@info:credit", "Developer"),
105 QStringLiteral("ervin@kde.org"));
106 aboutData.addAuthor(i18nc("@info:credit", "Holger Freyther"),
107 i18nc("@info:credit", "Developer"),
108 QStringLiteral("freyther@gmx.net"));
109 aboutData.addAuthor(i18nc("@info:credit", "Max Blazejak"),
110 i18nc("@info:credit", "Developer"),
111 QStringLiteral("m43ksrocks@gmail.com"));
112 aboutData.addAuthor(i18nc("@info:credit", "Michael Austin"),
113 i18nc("@info:credit", "Documentation"),
114 QStringLiteral("tuxedup@users.sourceforge.net"));
115
116 KAboutData::setApplicationData(aboutData);
117
118 QCommandLineParser parser;
119 aboutData.setupCommandLine(&parser);
120
121 // command line options
122 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"), i18nc("@info:shell", "The files and folders passed as arguments "
123 "will be selected.")));
124 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
125 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("new-window"), i18nc("@info:shell", "Dolphin will explicitly open in a new window.")));
126 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface)")));
127 parser.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open"));
128
129 parser.process(app);
130 aboutData.processCommandLine(&parser);
131
132 const bool splitView = parser.isSet(QStringLiteral("split")) || GeneralSettings::splitView();
133 const bool openFiles = parser.isSet(QStringLiteral("select"));
134 const QStringList args = parser.positionalArguments();
135 QList<QUrl> urls = Dolphin::validateUris(args);
136 // We later mutate urls, so we need to store if it was empty originally
137 const bool startedWithURLs = !urls.isEmpty();
138
139
140 if (parser.isSet(QStringLiteral("daemon"))) {
141 // Disable session management for the daemonized version
142 // See https://bugs.kde.org/show_bug.cgi?id=417219
143 auto disableSessionManagement = [](QSessionManager &sm) {
144 sm.setRestartHint(QSessionManager::RestartNever);
145 };
146 QObject::connect(&app, &QGuiApplication::commitDataRequest, disableSessionManagement);
147 QObject::connect(&app, &QGuiApplication::saveStateRequest, disableSessionManagement);
148
149 KDBusService dolphinDBusService;
150 DBusInterface interface;
151 interface.setAsDaemon();
152 return app.exec();
153 }
154
155 if (!parser.isSet(QStringLiteral("new-window"))) {
156 if (Dolphin::attachToExistingInstance(urls, openFiles, splitView)) {
157 // Successfully attached to existing instance of Dolphin
158 return 0;
159 }
160 }
161
162 if (!startedWithURLs) {
163 // We need at least one URL to open Dolphin
164 urls.append(Dolphin::homeUrl());
165 }
166
167 if (splitView && urls.size() < 2) {
168 // Split view does only make sense if we have at least 2 URLs
169 urls.append(urls.last());
170 }
171
172 DolphinMainWindow* mainWindow = new DolphinMainWindow();
173
174 if (openFiles) {
175 mainWindow->openFiles(urls, splitView);
176 } else {
177 mainWindow->openDirectories(urls, splitView);
178 }
179
180 mainWindow->show();
181
182 KDBusService dolphinDBusService;
183 DBusInterface interface;
184
185 if (!app.isSessionRestored()) {
186 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
187 }
188
189 // Only restore session if:
190 // 1. Not explicitly opening a new instance
191 // 2. The "remember state" setting is enabled or session restoration after
192 // reboot is in use
193 // 3. There is a session available to restore
194 if (!parser.isSet(QStringLiteral("new-window"))
195 && (app.isSessionRestored() || GeneralSettings::rememberOpenedTabs())
196 ) {
197 // Get saved state data for the last-closed Dolphin instance
198 const QString serviceName = QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid());
199 if (Dolphin::dolphinGuiInstances(serviceName).size() > 0) {
200 const QString className = KXmlGuiWindow::classNameOfToplevel(1);
201 if (className == QLatin1String("DolphinMainWindow")) {
202 mainWindow->restore(1);
203 // If the user passed any URLs to Dolphin, open those in the
204 // window after session-restoring it
205 if (startedWithURLs) {
206 mainWindow->openDirectories(urls, splitView);
207 }
208
209 // Now handle invalid locations in the set of active views to
210 // avoid issues like https://bugs.kde.org/show_bug.cgi?id=427619
211 mainWindow->setViewsWithInvalidPathsToHome();
212 } else {
213 qCWarning(DolphinDebug) << "Unknown class " << className << " in session saved data!";
214 }
215 }
216 }
217 Qt::ToolBarArea area = mainWindow->toolBarArea(mainWindow->toolBar());
218 if (area != Qt::TopToolBarArea && area != Qt::BottomToolBarArea) {
219 // Migrate users with disabled tool bar positions.
220 // Remove this a few years from now (2020).
221 mainWindow->addToolBar(Qt::TopToolBarArea, mainWindow->toolBar());
222 }
223
224 #ifdef HAVE_KUSERFEEDBACK
225 auto feedbackProvider = DolphinFeedbackProvider::instance();
226 Q_UNUSED(feedbackProvider)
227 #endif
228
229 return app.exec(); // krazy:exclude=crash;
230 }