Changeset View
Changeset View
Standalone View
Standalone View
src/main.cpp
Show All 33 Lines | |||||
34 | 34 | | |||
35 | #include <QApplication> | 35 | #include <QApplication> | ||
36 | #include <QCommandLineParser> | 36 | #include <QCommandLineParser> | ||
37 | 37 | | |||
38 | #ifndef Q_OS_WIN | 38 | #ifndef Q_OS_WIN | ||
39 | #include <unistd.h> | 39 | #include <unistd.h> | ||
40 | #endif | 40 | #endif | ||
41 | #include <iostream> | 41 | #include <iostream> | ||
42 | #include <QDBusConnection> | ||||
43 | #include <QDBusInterface> | ||||
44 | #include <QDBusAbstractInterface> | ||||
45 | #include <QDBusConnectionInterface> | ||||
elvisangelaccio: Please move these includes after `#include <QCommandLineParser>` | |||||
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 | ||
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; | ||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | 60 | #endif | |||
114 | 118 | | |||
115 | QCommandLineParser parser; | 119 | QCommandLineParser parser; | ||
116 | aboutData.setupCommandLine(&parser); | 120 | aboutData.setupCommandLine(&parser); | ||
117 | 121 | | |||
118 | // command line options | 122 | // command line options | ||
119 | parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"), i18nc("@info:shell", "The files and folders passed as arguments " | 123 | parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"), i18nc("@info:shell", "The files and folders passed as arguments " | ||
120 | "will be selected."))); | 124 | "will be selected."))); | ||
121 | parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view."))); | 125 | parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view."))); | ||
126 | parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("new-window"), i18nc("@info:shell", "Dolphin will explicitly open in a new window."))); | ||||
122 | parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface)"))); | 127 | parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface)"))); | ||
123 | parser.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open")); | 128 | parser.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open")); | ||
124 | 129 | | |||
125 | parser.process(app); | 130 | parser.process(app); | ||
126 | aboutData.processCommandLine(&parser); | 131 | aboutData.processCommandLine(&parser); | ||
127 | 132 | | |||
133 | const bool splitView = parser.isSet(QStringLiteral("split")) || GeneralSettings::splitView(); | ||||
134 | const bool openFiles = parser.isSet(QStringLiteral("select")); | ||||
135 | const QStringList args = parser.positionalArguments(); | ||||
136 | QStringList urls = QUrl::toStringList(Dolphin::validateUris(args)); | ||||
137 | | ||||
128 | if (parser.isSet(QStringLiteral("daemon"))) { | 138 | if (parser.isSet(QStringLiteral("daemon"))) { | ||
129 | return app.exec(); | 139 | return app.exec(); | ||
130 | } | 140 | } | ||
131 | 141 | | |||
132 | const QStringList args = parser.positionalArguments(); | | |||
133 | QList<QUrl> urls = Dolphin::validateUris(args); | | |||
134 | | ||||
135 | if (urls.isEmpty()) { | 142 | if (urls.isEmpty()) { | ||
136 | // We need at least one URL to open Dolphin | 143 | // We need at least one URL to open Dolphin | ||
137 | urls.append(Dolphin::homeUrl()); | 144 | urls.push_back(Dolphin::homeUrl().toString()); | ||
elvisangelaccio: Unrelated change. Please keep `append()`. | |||||
138 | } | 145 | } | ||
139 | 146 | | |||
140 | const bool splitView = parser.isSet(QStringLiteral("split")) || GeneralSettings::splitView(); | | |||
141 | if (splitView && urls.size() < 2) { | 147 | if (splitView && urls.size() < 2) { | ||
142 | // Split view does only make sense if we have at least 2 URLs | 148 | // Split view does only make sense if we have at least 2 URLs | ||
143 | urls.append(urls.last()); | 149 | urls.push_back(urls.last()); | ||
150 | } | ||||
151 | | ||||
152 | if (!parser.isSet(QStringLiteral("new-window"))) { | ||||
153 | if (Dolphin::attachToExistingInstance(urls, openFiles, splitView)) { | ||||
154 | // Successfully attached to existing instance of Dolphin | ||||
155 | return 0; | ||||
156 | } | ||||
144 | } | 157 | } | ||
145 | 158 | | |||
146 | DolphinMainWindow* mainWindow = new DolphinMainWindow(); | 159 | DolphinMainWindow* mainWindow = new DolphinMainWindow(); | ||
147 | 160 | | |||
148 | if (parser.isSet(QStringLiteral("select"))) { | 161 | if (openFiles) { | ||
149 | mainWindow->openFiles(urls, splitView); | 162 | mainWindow->openFiles(urls, splitView); | ||
150 | } else { | 163 | } else { | ||
151 | mainWindow->openDirectories(urls, splitView); | 164 | mainWindow->openDirectories(urls, splitView); | ||
152 | } | 165 | } | ||
153 | 166 | | |||
154 | mainWindow->show(); | 167 | mainWindow->show(); | ||
155 | 168 | | |||
156 | if (app.isSessionRestored()) { | 169 | if (app.isSessionRestored()) { | ||
Show All 10 Lines |
Please move these includes after #include <QCommandLineParser>