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