]> cloud.milkyroute.net Git - dolphin.git/blob - src/main.cpp
Fix includes
[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 "dolphinmainwindow.h"
23 #include "dolphin_generalsettings.h"
24
25 #include <KDBusService>
26 #include <KAboutData>
27 #include <QCommandLineParser>
28 #include <QCommandLineOption>
29 #include <QApplication>
30 #include <KLocalizedString>
31 #include <KDebug>
32 #include <kdelibs4configmigrator.h>
33
34 extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
35 {
36 QApplication app(argc, argv);
37 Kdelibs4ConfigMigrator migrate(QStringLiteral("dolphin"));
38 migrate.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
39 migrate.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
40 migrate.migrate();
41
42 app.setWindowIcon(QIcon::fromTheme("system-file-manager"));
43
44 KAboutData aboutData("dolphin", i18n("Dolphin"), "4.60",
45 i18nc("@title", "File Manager"),
46 KAboutLicense::GPL,
47 i18nc("@info:credit", "(C) 2006-2014 Peter Penz, Frank Reininghaus, and Emmanuel Pescosta"));
48 aboutData.setHomepage("http://dolphin.kde.org");
49 aboutData.addAuthor(i18nc("@info:credit", "Emmanuel Pescosta"),
50 i18nc("@info:credit", "Maintainer (since 2014) and developer"),
51 "emmanuelpescosta099@gmail.com");
52 aboutData.addAuthor(i18nc("@info:credit", "Frank Reininghaus"),
53 i18nc("@info:credit", "Maintainer (2012-2014) and developer"),
54 "frank78ac@googlemail.com");
55 aboutData.addAuthor(i18nc("@info:credit", "Peter Penz"),
56 i18nc("@info:credit", "Maintainer and developer (2006-2012)"),
57 "peter.penz19@gmail.com");
58 aboutData.addAuthor(i18nc("@info:credit", "Sebastian Trüg"),
59 i18nc("@info:credit", "Developer"),
60 "trueg@kde.org");
61 aboutData.addAuthor(i18nc("@info:credit", "David Faure"),
62 i18nc("@info:credit", "Developer"),
63 "faure@kde.org");
64 aboutData.addAuthor(i18nc("@info:credit", "Aaron J. Seigo"),
65 i18nc("@info:credit", "Developer"),
66 "aseigo@kde.org");
67 aboutData.addAuthor(i18nc("@info:credit", "Rafael Fernández López"),
68 i18nc("@info:credit", "Developer"),
69 "ereslibre@kde.org");
70 aboutData.addAuthor(i18nc("@info:credit", "Kevin Ottens"),
71 i18nc("@info:credit", "Developer"),
72 "ervin@kde.org");
73 aboutData.addAuthor(i18nc("@info:credit", "Holger Freyther"),
74 i18nc("@info:credit", "Developer"),
75 "freyther@gmx.net");
76 aboutData.addAuthor(i18nc("@info:credit", "Max Blazejak"),
77 i18nc("@info:credit", "Developer"),
78 "m43ksrocks@gmail.com");
79 aboutData.addAuthor(i18nc("@info:credit", "Michael Austin"),
80 i18nc("@info:credit", "Documentation"),
81 "tuxedup@users.sourceforge.net");
82
83 KAboutData::setApplicationData(aboutData);
84
85 KDBusService dolphinDBusService;
86
87 QCommandLineParser parser;
88 parser.addVersionOption();
89 parser.addHelpOption();
90 aboutData.setupCommandLine(&parser);
91
92 // command line options
93 parser.addOption(QCommandLineOption(QStringList() << QLatin1String("select"), i18nc("@info:shell", "The files and directories passed as arguments "
94 "will be selected.")));
95 parser.addOption(QCommandLineOption(QStringList() << QLatin1String("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
96 parser.addPositionalArgument(QLatin1String("+[Url]"), i18nc("@info:shell", "Document to open"));
97
98 parser.process(app);
99 aboutData.processCommandLine(&parser);
100
101
102 DolphinMainWindow* m_mainWindow = new DolphinMainWindow();
103 m_mainWindow->setAttribute(Qt::WA_DeleteOnClose);
104
105 QList<QUrl> urls;
106 const QStringList args = parser.positionalArguments();
107 foreach (const QString& str, args) {
108 const QUrl url(str);
109 if (url.isValid()) {
110 urls.append(url);
111 }
112 }
113
114 bool resetSplitSettings = false;
115 if (parser.isSet("split") && !GeneralSettings::splitView()) {
116 // Dolphin should be opened with a split view although this is not
117 // set in the GeneralSettings. Temporary adjust the setting until
118 // all passed URLs have been opened.
119 GeneralSettings::setSplitView(true);
120 resetSplitSettings = true;
121
122 // We need 2 URLs to open Dolphin in split view mode
123 if (urls.isEmpty()) { // No URL given - Open home URL in all two views
124 urls.append(GeneralSettings::homeUrl());
125 urls.append(GeneralSettings::homeUrl());
126 } else if (urls.length() == 1) { // Only 1 URL given - Open given URL in all two views
127 urls.append(urls.at(0));
128 }
129 }
130
131 if (!urls.isEmpty()) {
132 if (parser.isSet("select")) {
133 m_mainWindow->openFiles(urls);
134 } else {
135 m_mainWindow->openDirectories(urls);
136 }
137 } else {
138 const QUrl homeUrl(QUrl::fromLocalFile(GeneralSettings::homeUrl()));
139 m_mainWindow->openNewActivatedTab(homeUrl);
140 }
141
142 if (resetSplitSettings) {
143 GeneralSettings::setSplitView(false);
144 }
145
146 m_mainWindow->show();
147
148 if (app.isSessionRestored()) {
149 const QString className = KXmlGuiWindow::classNameOfToplevel(1);
150 if (className == QLatin1String("DolphinMainWindow")) {
151 m_mainWindow->restore(1);
152 } else {
153 kWarning() << "Unknown class " << className << " in session saved data!";
154 }
155 }
156
157 return app.exec(); // krazy:exclude=crash;
158 }