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