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