Changeset View
Changeset View
Standalone View
Standalone View
src/main.cpp
Show All 28 Lines | |||||
29 | #include <KAboutData> | 29 | #include <KAboutData> | ||
30 | #include <KCrash> | 30 | #include <KCrash> | ||
31 | #include <KDBusService> | 31 | #include <KDBusService> | ||
32 | #include <KLocalizedString> | 32 | #include <KLocalizedString> | ||
33 | #include <Kdelibs4ConfigMigrator> | 33 | #include <Kdelibs4ConfigMigrator> | ||
34 | 34 | | |||
35 | #include <QApplication> | 35 | #include <QApplication> | ||
36 | #include <QCommandLineParser> | 36 | #include <QCommandLineParser> | ||
37 | #include <QDBusConnection> | ||||
38 | #include <QDBusInterface> | ||||
39 | #include <QDBusAbstractInterface> | ||||
40 | #include <QDBusConnectionInterface> | ||||
37 | 41 | | |||
38 | #ifndef Q_OS_WIN | 42 | #ifndef Q_OS_WIN | ||
39 | #include <unistd.h> | 43 | #include <unistd.h> | ||
40 | #endif | 44 | #endif | ||
41 | #include <iostream> | 45 | #include <iostream> | ||
42 | 46 | | |||
43 | extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv) | 47 | extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv) | ||
44 | { | 48 | { | ||
45 | #ifndef Q_OS_WIN | 49 | #ifndef Q_OS_WIN | ||
elvisangelaccio: Please move these includes after `#include <QCommandLineParser>` | |||||
46 | // Prohibit using sudo or kdesu (but allow using the root user directly) | 50 | // Prohibit using sudo or kdesu (but allow using the root user directly) | ||
47 | if (getuid() == 0) { | 51 | if (getuid() == 0) { | ||
48 | if (!qEnvironmentVariableIsEmpty("SUDO_USER")) { | 52 | if (!qEnvironmentVariableIsEmpty("SUDO_USER")) { | ||
49 | std::cout << "Executing Dolphin with sudo is not possible due to unfixable security vulnerabilities." << std::endl; | 53 | std::cout << "Executing Dolphin with sudo is not possible due to unfixable security vulnerabilities." << std::endl; | ||
50 | return EXIT_FAILURE; | 54 | return EXIT_FAILURE; | ||
51 | } else if (!qEnvironmentVariableIsEmpty("KDESU_USER")) { | 55 | } else if (!qEnvironmentVariableIsEmpty("KDESU_USER")) { | ||
52 | std::cout << "Executing Dolphin with kdesu is not possible due to unfixable security vulnerabilities." << std::endl; | 56 | std::cout << "Executing Dolphin with kdesu is not possible due to unfixable security vulnerabilities." << std::endl; | ||
53 | return EXIT_FAILURE; | 57 | return EXIT_FAILURE; | ||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | 60 | #endif | |||
117 | 121 | | |||
118 | QCommandLineParser parser; | 122 | QCommandLineParser parser; | ||
119 | aboutData.setupCommandLine(&parser); | 123 | aboutData.setupCommandLine(&parser); | ||
120 | 124 | | |||
121 | // command line options | 125 | // command line options | ||
122 | parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"), i18nc("@info:shell", "The files and folders passed as arguments " | 126 | parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"), i18nc("@info:shell", "The files and folders passed as arguments " | ||
123 | "will be selected."))); | 127 | "will be selected."))); | ||
124 | parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view."))); | 128 | parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view."))); | ||
129 | parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("new-window"), i18nc("@info:shell", "Dolphin will explicitly open in a new window."))); | ||||
125 | parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface)"))); | 130 | parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface)"))); | ||
126 | parser.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open")); | 131 | parser.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open")); | ||
127 | 132 | | |||
128 | parser.process(app); | 133 | parser.process(app); | ||
129 | aboutData.processCommandLine(&parser); | 134 | aboutData.processCommandLine(&parser); | ||
130 | 135 | | |||
136 | const bool splitView = parser.isSet(QStringLiteral("split")) || GeneralSettings::splitView(); | ||||
137 | const bool openFiles = parser.isSet(QStringLiteral("select")); | ||||
138 | const QStringList args = parser.positionalArguments(); | ||||
139 | QList<QUrl> urls = Dolphin::validateUris(args); | ||||
140 | | ||||
131 | if (parser.isSet(QStringLiteral("daemon"))) { | 141 | if (parser.isSet(QStringLiteral("daemon"))) { | ||
132 | return app.exec(); | 142 | return app.exec(); | ||
133 | } | 143 | } | ||
134 | 144 | | |||
135 | const QStringList args = parser.positionalArguments(); | | |||
136 | QList<QUrl> urls = Dolphin::validateUris(args); | | |||
137 | | ||||
138 | if (urls.isEmpty()) { | 145 | if (urls.isEmpty()) { | ||
139 | // We need at least one URL to open Dolphin | 146 | // We need at least one URL to open Dolphin | ||
140 | urls.append(Dolphin::homeUrl()); | 147 | urls.append(Dolphin::homeUrl()); | ||
elvisangelaccio: Unrelated change. Please keep `append()`. | |||||
141 | } | 148 | } | ||
142 | 149 | | |||
143 | const bool splitView = parser.isSet(QStringLiteral("split")) || GeneralSettings::splitView(); | | |||
144 | if (splitView && urls.size() < 2) { | 150 | if (splitView && urls.size() < 2) { | ||
145 | // Split view does only make sense if we have at least 2 URLs | 151 | // Split view does only make sense if we have at least 2 URLs | ||
146 | urls.append(urls.last()); | 152 | urls.append(urls.last()); | ||
147 | } | 153 | } | ||
148 | 154 | | |||
155 | if (!parser.isSet(QStringLiteral("new-window"))) { | ||||
156 | if (Dolphin::attachToExistingInstance(urls, openFiles, splitView)) { | ||||
157 | // Successfully attached to existing instance of Dolphin | ||||
158 | return 0; | ||||
159 | } | ||||
160 | } | ||||
161 | | ||||
149 | DolphinMainWindow* mainWindow = new DolphinMainWindow(); | 162 | DolphinMainWindow* mainWindow = new DolphinMainWindow(); | ||
150 | 163 | | |||
151 | if (parser.isSet(QStringLiteral("select"))) { | 164 | if (openFiles) { | ||
152 | mainWindow->openFiles(urls, splitView); | 165 | mainWindow->openFiles(urls, splitView); | ||
153 | } else { | 166 | } else { | ||
154 | mainWindow->openDirectories(urls, splitView); | 167 | mainWindow->openDirectories(urls, splitView); | ||
155 | } | 168 | } | ||
156 | 169 | | |||
157 | mainWindow->show(); | 170 | mainWindow->show(); | ||
158 | 171 | | |||
159 | if (app.isSessionRestored()) { | 172 | if (app.isSessionRestored()) { | ||
Show All 10 Lines |
Please move these includes after #include <QCommandLineParser>