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