]> cloud.milkyroute.net Git - dolphin.git/blob - src/main.cpp
[KStandardItemListWidget] Pass icon state to overlay painter
[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
38 #ifndef Q_OS_WIN
39 #include <unistd.h>
40 #endif
41 #include <iostream>
42
43 extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
44 {
45 #ifndef Q_OS_WIN
46 // Prohibit using sudo or kdesu (but allow using the root user directly)
47 if (getuid() == 0) {
48 if (!qEnvironmentVariableIsEmpty("SUDO_USER")) {
49 std::cout << "Executing Dolphin with sudo is not possible due to unfixable security vulnerabilities." << std::endl;
50 return EXIT_FAILURE;
51 } else if (!qEnvironmentVariableIsEmpty("KDESU_USER")) {
52 std::cout << "Executing Dolphin with kdesu is not possible due to unfixable security vulnerabilities." << std::endl;
53 return EXIT_FAILURE;
54 }
55 }
56 #endif
57
58 QApplication app(argc, argv);
59 app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
60 app.setWindowIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"), app.windowIcon()));
61
62 KCrash::initialize();
63
64 Kdelibs4ConfigMigrator migrate(QStringLiteral("dolphin"));
65 migrate.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
66 migrate.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
67 migrate.migrate();
68
69 KLocalizedString::setApplicationDomain("dolphin");
70
71 KAboutData aboutData(QStringLiteral("dolphin"), i18n("Dolphin"), QStringLiteral(DOLPHIN_VERSION_STRING),
72 i18nc("@title", "File Manager"),
73 KAboutLicense::GPL,
74 i18nc("@info:credit", "(C) 2006-2016 Peter Penz, Frank Reininghaus, and Emmanuel Pescosta"));
75 aboutData.setHomepage(QStringLiteral("http://dolphin.kde.org"));
76 aboutData.addAuthor(i18nc("@info:credit", "Emmanuel Pescosta"),
77 i18nc("@info:credit", "Maintainer (since 2014) and developer"),
78 QStringLiteral("emmanuelpescosta099@gmail.com"));
79 aboutData.addAuthor(i18nc("@info:credit", "Frank Reininghaus"),
80 i18nc("@info:credit", "Maintainer (2012-2014) and developer"),
81 QStringLiteral("frank78ac@googlemail.com"));
82 aboutData.addAuthor(i18nc("@info:credit", "Peter Penz"),
83 i18nc("@info:credit", "Maintainer and developer (2006-2012)"),
84 QStringLiteral("peter.penz19@gmail.com"));
85 aboutData.addAuthor(i18nc("@info:credit", "Sebastian Trüg"),
86 i18nc("@info:credit", "Developer"),
87 QStringLiteral("trueg@kde.org"));
88 aboutData.addAuthor(i18nc("@info:credit", "David Faure"),
89 i18nc("@info:credit", "Developer"),
90 QStringLiteral("faure@kde.org"));
91 aboutData.addAuthor(i18nc("@info:credit", "Aaron J. Seigo"),
92 i18nc("@info:credit", "Developer"),
93 QStringLiteral("aseigo@kde.org"));
94 aboutData.addAuthor(i18nc("@info:credit", "Rafael Fernández López"),
95 i18nc("@info:credit", "Developer"),
96 QStringLiteral("ereslibre@kde.org"));
97 aboutData.addAuthor(i18nc("@info:credit", "Kevin Ottens"),
98 i18nc("@info:credit", "Developer"),
99 QStringLiteral("ervin@kde.org"));
100 aboutData.addAuthor(i18nc("@info:credit", "Holger Freyther"),
101 i18nc("@info:credit", "Developer"),
102 QStringLiteral("freyther@gmx.net"));
103 aboutData.addAuthor(i18nc("@info:credit", "Max Blazejak"),
104 i18nc("@info:credit", "Developer"),
105 QStringLiteral("m43ksrocks@gmail.com"));
106 aboutData.addAuthor(i18nc("@info:credit", "Michael Austin"),
107 i18nc("@info:credit", "Documentation"),
108 QStringLiteral("tuxedup@users.sourceforge.net"));
109
110 KAboutData::setApplicationData(aboutData);
111
112 KDBusService dolphinDBusService;
113 DBusInterface interface;
114
115 QCommandLineParser parser;
116 aboutData.setupCommandLine(&parser);
117
118 // command line options
119 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"), i18nc("@info:shell", "The files and folders passed as arguments "
120 "will be selected.")));
121 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
122 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface)")));
123 parser.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open"));
124
125 parser.process(app);
126 aboutData.processCommandLine(&parser);
127
128 if (parser.isSet(QStringLiteral("daemon"))) {
129 return app.exec();
130 }
131
132 const QStringList args = parser.positionalArguments();
133 QList<QUrl> urls = Dolphin::validateUris(args);
134
135 if (urls.isEmpty()) {
136 // We need at least one URL to open Dolphin
137 urls.append(Dolphin::homeUrl());
138 }
139
140 const bool splitView = parser.isSet(QStringLiteral("split")) || GeneralSettings::splitView();
141 if (splitView && urls.size() < 2) {
142 // Split view does only make sense if we have at least 2 URLs
143 urls.append(urls.last());
144 }
145
146 DolphinMainWindow* mainWindow = new DolphinMainWindow();
147 mainWindow->setAttribute(Qt::WA_DeleteOnClose);
148
149 if (parser.isSet(QStringLiteral("select"))) {
150 mainWindow->openFiles(urls, splitView);
151 } else {
152 mainWindow->openDirectories(urls, splitView);
153 }
154
155 mainWindow->show();
156
157 if (app.isSessionRestored()) {
158 const QString className = KXmlGuiWindow::classNameOfToplevel(1);
159 if (className == QLatin1String("DolphinMainWindow")) {
160 mainWindow->restore(1);
161 } else {
162 qCWarning(DolphinDebug) << "Unknown class " << className << " in session saved data!";
163 }
164 }
165
166 return app.exec(); // krazy:exclude=crash;
167 }