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