Changeset View
Changeset View
Standalone View
Standalone View
app/main.cpp
Show First 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | 83 | { | |||
---|---|---|---|---|---|
86 | stream << QByteArrayLiteral("open"); | 86 | stream << QByteArrayLiteral("open"); | ||
87 | stream << infos; | 87 | stream << infos; | ||
88 | return QString::fromLatin1(message.toHex()); | 88 | return QString::fromLatin1(message.toHex()); | ||
89 | } | 89 | } | ||
90 | #endif | 90 | #endif | ||
91 | 91 | | |||
92 | void openFiles(const QVector<UrlInfo>& infos) | 92 | void openFiles(const QVector<UrlInfo>& infos) | ||
93 | { | 93 | { | ||
94 | foreach (const UrlInfo& file, infos) { | 94 | foreach (const UrlInfo& info, infos) { | ||
95 | if (!ICore::self()->documentController()->openDocument(file.url, file.cursor)) { | 95 | if (!ICore::self()->documentController()->openDocument(info.url, info.cursor)) { | ||
96 | qWarning() << i18n("Could not open %1", file.url.toDisplayString(QUrl::PreferLocalFile)); | 96 | qWarning() << i18n("Could not open %1", info.url.toDisplayString(QUrl::PreferLocalFile)); | ||
97 | } | 97 | } | ||
98 | } | 98 | } | ||
99 | } | 99 | } | ||
100 | 100 | | |||
101 | } | 101 | } | ||
102 | 102 | | |||
103 | class KDevelopApplication: | 103 | class KDevelopApplication: | ||
104 | #if KDEVELOP_SINGLE_APP | 104 | #if KDEVELOP_SINGLE_APP | ||
Show All 25 Lines | 125 | { | |||
130 | QByteArray command; | 130 | QByteArray command; | ||
131 | stream >> command; | 131 | stream >> command; | ||
132 | 132 | | |||
133 | qCDebug(APP) << "Received remote command: " << command; | 133 | qCDebug(APP) << "Received remote command: " << command; | ||
134 | 134 | | |||
135 | if (command == "open") { | 135 | if (command == "open") { | ||
136 | QVector<UrlInfo> infos; | 136 | QVector<UrlInfo> infos; | ||
137 | stream >> infos; | 137 | stream >> infos; | ||
138 | openFiles(infos); | 138 | | ||
139 | QVector<UrlInfo> files, directories; | ||||
kfunk: Consistency: `info` | |||||
140 | for (const auto& info : infos) | ||||
kfunk: Style: `for (const auto& info : ...)` | |||||
141 | if (info.isDirectory()) | ||||
142 | directories << info; | ||||
143 | else | ||||
144 | files << info; | ||||
145 | | ||||
146 | openFiles(files); | ||||
147 | for(const auto &urlinfo : directories) | ||||
148 | ICore::self()->projectController()->openProjectForUrl(urlinfo.url); | ||||
139 | } else { | 149 | } else { | ||
140 | qCWarning(APP) << "Unknown remote command: " << command; | 150 | qCWarning(APP) << "Unknown remote command: " << command; | ||
141 | } | 151 | } | ||
142 | } | 152 | } | ||
143 | 153 | | |||
144 | void fileOpenRequested(const QString &file) | 154 | void fileOpenRequested(const QString &file) | ||
145 | { | 155 | { | ||
146 | openFiles({UrlInfo(file)}); | 156 | openFiles({UrlInfo(file)}); | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | 198 | { | |||
190 | QDBusInterface iface(service, QStringLiteral("/org/kdevelop/DocumentController"), QStringLiteral("org.kdevelop.DocumentController")); | 200 | QDBusInterface iface(service, QStringLiteral("/org/kdevelop/DocumentController"), QStringLiteral("org.kdevelop.DocumentController")); | ||
191 | 201 | | |||
192 | QStringList urls; | 202 | QStringList urls; | ||
193 | bool errors_occured = false; | 203 | bool errors_occured = false; | ||
194 | foreach ( const UrlInfo& file, files ) { | 204 | foreach ( const UrlInfo& file, files ) { | ||
195 | QDBusReply<bool> result = iface.call(QStringLiteral("openDocumentSimple"), file.url.toString(), file.cursor.line(), file.cursor.column()); | 205 | QDBusReply<bool> result = iface.call(QStringLiteral("openDocumentSimple"), file.url.toString(), file.cursor.line(), file.cursor.column()); | ||
196 | if ( ! result.value() ) { | 206 | if ( ! result.value() ) { | ||
197 | QTextStream err(stderr); | 207 | QTextStream err(stderr); | ||
198 | err << i18n("Could not open file %1.", file.url.toDisplayString(QUrl::PreferLocalFile)) << "\n"; | 208 | err << i18n("Could not open file '%1'.", file.url.toDisplayString(QUrl::PreferLocalFile)) << "\n"; | ||
199 | errors_occured = true; | 209 | errors_occured = true; | ||
200 | } | 210 | } | ||
201 | } | 211 | } | ||
202 | // make the window visible | 212 | // make the window visible | ||
203 | QDBusMessage makeVisible = QDBusMessage::createMethodCall( service, QStringLiteral("/kdevelop/MainWindow"), QStringLiteral("org.kdevelop.MainWindow"), | 213 | QDBusMessage makeVisible = QDBusMessage::createMethodCall( service, QStringLiteral("/kdevelop/MainWindow"), QStringLiteral("org.kdevelop.MainWindow"), | ||
204 | QStringLiteral("ensureVisible") ); | 214 | QStringLiteral("ensureVisible") ); | ||
205 | QDBusConnection::sessionBus().asyncCall( makeVisible ); | 215 | QDBusConnection::sessionBus().asyncCall( makeVisible ); | ||
206 | return errors_occured; | 216 | return errors_occured; | ||
207 | } | 217 | } | ||
208 | 218 | | |||
219 | /// Performs a DBus call to open the given @p files in the running kdev instance identified by @p pid | ||||
220 | /// Returns the exit status | ||||
221 | static int openProjectInRunningInstance(const QVector<UrlInfo>& paths, qint64 pid) | ||||
222 | { | ||||
223 | const QString service = QStringLiteral("org.kdevelop.kdevelop-%1").arg(pid); | ||||
224 | QDBusInterface iface(service, QStringLiteral("/org/kdevelop/ProjectController"), QStringLiteral("org.kdevelop.ProjectController")); | ||||
225 | int errors = 0; | ||||
226 | | ||||
227 | foreach ( const UrlInfo& path, paths ) { | ||||
228 | QDBusReply<void> result = iface.call(QStringLiteral("openProjectForUrl"), path.url.toString()); | ||||
229 | if ( !result.isValid() ) { | ||||
230 | QTextStream err(stderr); | ||||
231 | err << i18n("Could not open project '%1': %2", path.url.toDisplayString(QUrl::PreferLocalFile), result.error().message()) << "\n"; | ||||
232 | ++errors; | ||||
233 | } | ||||
234 | } | ||||
235 | // make the window visible | ||||
236 | QDBusMessage makeVisible = QDBusMessage::createMethodCall( service, QStringLiteral("/kdevelop/MainWindow"), QStringLiteral("org.kdevelop.MainWindow"), | ||||
237 | QStringLiteral("ensureVisible") ); | ||||
238 | QDBusConnection::sessionBus().asyncCall( makeVisible ); | ||||
239 | return errors; | ||||
240 | } | ||||
241 | | ||||
209 | /// Gets the PID of a running KDevelop instance, eventually asking the user if there is more than one. | 242 | /// Gets the PID of a running KDevelop instance, eventually asking the user if there is more than one. | ||
210 | /// Returns -1 in case there are no running sessions. | 243 | /// Returns -1 in case there are no running sessions. | ||
211 | static qint64 getRunningSessionPid() | 244 | static qint64 getRunningSessionPid() | ||
212 | { | 245 | { | ||
213 | SessionInfos candidates; | 246 | SessionInfos candidates; | ||
214 | foreach( const KDevelop::SessionInfo& si, KDevelop::SessionController::availableSessionInfos() ) { | 247 | foreach( const KDevelop::SessionInfo& si, KDevelop::SessionController::availableSessionInfos() ) { | ||
215 | if( KDevelop::SessionController::isSessionRunning(si.uuid.toString()) ) { | 248 | if( KDevelop::SessionController::isSessionRunning(si.uuid.toString()) ) { | ||
216 | candidates << si; | 249 | candidates << si; | ||
▲ Show 20 Lines • Show All 240 Lines • ▼ Show 20 Line(s) | 482 | { | |||
457 | 490 | | |||
458 | qout << endl; | 491 | qout << endl; | ||
459 | } | 492 | } | ||
460 | return 0; | 493 | return 0; | ||
461 | } | 494 | } | ||
462 | 495 | | |||
463 | // Handle extra arguments, which stand for files to open | 496 | // Handle extra arguments, which stand for files to open | ||
464 | QVector<UrlInfo> initialFiles; | 497 | QVector<UrlInfo> initialFiles; | ||
498 | QVector<UrlInfo> initialDirectories; | ||||
465 | foreach (const QString &file, parser.positionalArguments()) { | 499 | foreach (const QString &file, parser.positionalArguments()) { | ||
466 | initialFiles.append(UrlInfo(file)); | 500 | const UrlInfo info(file); | ||
501 | if (info.isDirectory()) { | ||||
502 | initialDirectories.append(info); | ||||
503 | } else { | ||||
504 | initialFiles.append(info); | ||||
505 | } | ||||
kfunk: `uinfo` -> `urlInfo` or `info` | |||||
467 | } | 506 | } | ||
468 | 507 | | |||
469 | const auto availableSessionInfos = KDevelop::SessionController::availableSessionInfos(); | 508 | const auto availableSessionInfos = KDevelop::SessionController::availableSessionInfos(); | ||
470 | 509 | | |||
471 | if (!initialFiles.isEmpty() && !parser.isSet(QStringLiteral("new-session"))) { | 510 | if ((!initialFiles.isEmpty() || !initialDirectories.isEmpty()) && !parser.isSet(QStringLiteral("new-session"))) { | ||
472 | #if KDEVELOP_SINGLE_APP | 511 | #if KDEVELOP_SINGLE_APP | ||
473 | if (app.isRunning()) { | 512 | if (app.isRunning()) { | ||
474 | bool success = app.sendMessage(serializeOpenFilesMessage(initialFiles)); | 513 | bool success = app.sendMessage(serializeOpenFilesMessage(initialFiles << initialDirectories)); | ||
475 | if (success) { | 514 | if (success) { | ||
476 | return 0; | 515 | return 0; | ||
477 | } | 516 | } | ||
478 | } | 517 | } | ||
479 | #else | 518 | #else | ||
480 | qint64 pid = -1; | 519 | qint64 pid = -1; | ||
481 | if (parser.isSet(QStringLiteral("open-session"))) { | 520 | if (parser.isSet(QStringLiteral("open-session"))) { | ||
482 | const QString session = findSessionId(availableSessionInfos, parser.value(QStringLiteral("open-session"))); | 521 | const QString session = findSessionId(availableSessionInfos, parser.value(QStringLiteral("open-session"))); | ||
483 | if (session.isEmpty()) { | 522 | if (session.isEmpty()) { | ||
484 | return 1; | 523 | return 1; | ||
485 | } else if (KDevelop::SessionController::isSessionRunning(session)) { | 524 | } else if (KDevelop::SessionController::isSessionRunning(session)) { | ||
486 | pid = findSessionPid(session); | 525 | pid = findSessionPid(session); | ||
487 | } | 526 | } | ||
488 | } else { | 527 | } else { | ||
489 | pid = getRunningSessionPid(); | 528 | pid = getRunningSessionPid(); | ||
490 | } | 529 | } | ||
530 | | ||||
491 | if ( pid > 0 ) { | 531 | if ( pid > 0 ) { | ||
492 | return openFilesInRunningInstance(initialFiles, pid); | 532 | return openFilesInRunningInstance(initialFiles, pid) + openProjectInRunningInstance(initialDirectories, pid); | ||
493 | } | 533 | } | ||
494 | // else there are no running sessions, and the generated list of files will be opened below. | 534 | // else there are no running sessions, and the generated list of files will be opened below. | ||
495 | #endif | 535 | #endif | ||
496 | } | 536 | } | ||
497 | 537 | | |||
498 | // if empty, restart kdevelop with last active session, see SessionController::defaultSessionId | 538 | // if empty, restart kdevelop with last active session, see SessionController::defaultSessionId | ||
499 | QString session; | 539 | QString session; | ||
500 | 540 | | |||
▲ Show 20 Lines • Show All 215 Lines • ▼ Show 20 Line(s) | 708 | if ( parser.isSet(debugStr) ) { | |||
716 | 756 | | |||
717 | type->configureLaunchFromCmdLineArguments(launch->config(), debugArgs); | 757 | type->configureLaunchFromCmdLineArguments(launch->config(), debugArgs); | ||
718 | launch->config().writeEntry("Break on Start", true); | 758 | launch->config().writeEntry("Break on Start", true); | ||
719 | core->runControllerInternal()->setDefaultLaunch(launch); | 759 | core->runControllerInternal()->setDefaultLaunch(launch); | ||
720 | 760 | | |||
721 | core->runControllerInternal()->execute(debugStr, launch); | 761 | core->runControllerInternal()->execute(debugStr, launch); | ||
722 | } else { | 762 | } else { | ||
723 | openFiles(initialFiles); | 763 | openFiles(initialFiles); | ||
764 | | ||||
765 | for(const auto &urlinfo: initialDirectories) | ||||
kfunk: Style & naming: `for (const auto& initialDirectory : ...` | |||||
766 | core->projectController()->openProjectForUrl(urlinfo.url); | ||||
724 | } | 767 | } | ||
725 | 768 | | |||
726 | #if KDEVELOP_SINGLE_APP | 769 | #if KDEVELOP_SINGLE_APP | ||
727 | // Set up remote arguments. | 770 | // Set up remote arguments. | ||
728 | QObject::connect(&app, &SharedTools::QtSingleApplication::messageReceived, | 771 | QObject::connect(&app, &SharedTools::QtSingleApplication::messageReceived, | ||
729 | &app, &KDevelopApplication::remoteArguments); | 772 | &app, &KDevelopApplication::remoteArguments); | ||
730 | 773 | | |||
731 | QObject::connect(&app, &SharedTools::QtSingleApplication::fileOpenRequest, | 774 | QObject::connect(&app, &SharedTools::QtSingleApplication::fileOpenRequest, | ||
Show All 9 Lines |
Consistency: info