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