Changeset View
Changeset View
Standalone View
Standalone View
app/main.cpp
Show First 20 Lines • Show All 186 Lines • ▼ Show 20 Line(s) | 186 | for( auto it = sessions.constBegin(); it != sessions.constEnd(); ++it ) { | |||
---|---|---|---|---|---|
187 | if ( ( it->name == data ) || ( it->uuid.toString() == data ) ) { | 187 | if ( ( it->name == data ) || ( it->uuid.toString() == data ) ) { | ||
188 | const KDevelop::SessionInfo& sessionRef = *it; | 188 | const KDevelop::SessionInfo& sessionRef = *it; | ||
189 | return &sessionRef; | 189 | return &sessionRef; | ||
190 | } | 190 | } | ||
191 | } | 191 | } | ||
192 | return nullptr; | 192 | return nullptr; | ||
193 | } | 193 | } | ||
194 | 194 | | |||
195 | /// Tries to find sessions containing project @p projectUrl in @p sessions. | ||||
196 | static const KDevelop::SessionInfos findSessionsWithProject(const SessionInfos& sessions, const QUrl& projectUrl) | ||||
197 | { | ||||
198 | if (!projectUrl.isValid()) | ||||
199 | return {}; | ||||
200 | | ||||
201 | KDevelop::SessionInfos infos; | ||||
202 | for (auto it = sessions.constBegin(); it != sessions.constEnd(); ++it) { | ||||
203 | if (it->projects.contains(projectUrl)) { | ||||
204 | infos << *it; | ||||
205 | } | ||||
206 | } | ||||
207 | return infos; | ||||
208 | } | ||||
209 | | ||||
195 | /// Performs a DBus call to open the given @p files in the running kdev instance identified by @p pid | 210 | /// Performs a DBus call to open the given @p files in the running kdev instance identified by @p pid | ||
196 | /// Returns the exit status | 211 | /// Returns the exit status | ||
197 | static int openFilesInRunningInstance(const QVector<UrlInfo>& files, qint64 pid) | 212 | static int openFilesInRunningInstance(const QVector<UrlInfo>& files, qint64 pid) | ||
198 | { | 213 | { | ||
199 | const QString service = QStringLiteral("org.kdevelop.kdevelop-%1").arg(pid); | 214 | const QString service = QStringLiteral("org.kdevelop.kdevelop-%1").arg(pid); | ||
200 | QDBusInterface iface(service, QStringLiteral("/org/kdevelop/DocumentController"), QStringLiteral("org.kdevelop.DocumentController")); | 215 | QDBusInterface iface(service, QStringLiteral("/org/kdevelop/DocumentController"), QStringLiteral("org.kdevelop.DocumentController")); | ||
201 | 216 | | |||
202 | QStringList urls; | 217 | QStringList urls; | ||
▲ Show 20 Lines • Show All 243 Lines • ▼ Show 20 Line(s) | 346 | #endif | |||
446 | parser.addOption(QCommandLineOption{QStringList{"n", "new-session"}, i18n("Open KDevelop with a new session using the given name."), QStringLiteral("name")}); | 461 | parser.addOption(QCommandLineOption{QStringList{"n", "new-session"}, i18n("Open KDevelop with a new session using the given name."), QStringLiteral("name")}); | ||
447 | parser.addOption(QCommandLineOption{QStringList{"s", "open-session"}, i18n("Open KDevelop with the given session.\n" | 462 | parser.addOption(QCommandLineOption{QStringList{"s", "open-session"}, i18n("Open KDevelop with the given session.\n" | ||
448 | "You can pass either hash or the name of the session." ), QStringLiteral("session")}); | 463 | "You can pass either hash or the name of the session." ), QStringLiteral("session")}); | ||
449 | parser.addOption(QCommandLineOption{QStringList{"rm", "remove-session"}, i18n("Delete the given session.\n" | 464 | parser.addOption(QCommandLineOption{QStringList{"rm", "remove-session"}, i18n("Delete the given session.\n" | ||
450 | "You can pass either hash or the name of the session." ), QStringLiteral("session")}); | 465 | "You can pass either hash or the name of the session." ), QStringLiteral("session")}); | ||
451 | parser.addOption(QCommandLineOption{QStringList{"ps", "pick-session"}, i18n("Shows all available sessions and lets you select one to open.")}); | 466 | parser.addOption(QCommandLineOption{QStringList{"ps", "pick-session"}, i18n("Shows all available sessions and lets you select one to open.")}); | ||
452 | parser.addOption(QCommandLineOption{QStringList{"pss", "pick-session-shell"}, i18n("List all available sessions on shell and lets you select one to open.")}); | 467 | parser.addOption(QCommandLineOption{QStringList{"pss", "pick-session-shell"}, i18n("List all available sessions on shell and lets you select one to open.")}); | ||
453 | parser.addOption(QCommandLineOption{QStringList{"l", "list-sessions"}, i18n("List available sessions and quit.")}); | 468 | parser.addOption(QCommandLineOption{QStringList{"l", "list-sessions"}, i18n("List available sessions and quit.")}); | ||
454 | parser.addOption(QCommandLineOption{QStringList{"p", "project"}, i18n("Open KDevelop and load the given project."), QStringLiteral("project")}); | 469 | parser.addOption(QCommandLineOption{QStringList{"p", "project"}, i18n("Open KDevelop and load the given project. Project can be either a .kdev4 file or a directory path."), QStringLiteral("project")}); | ||
455 | parser.addOption(QCommandLineOption{QStringList{"d", "debug"}, | 470 | parser.addOption(QCommandLineOption{QStringList{"d", "debug"}, | ||
456 | i18n("Start debugging an application in KDevelop with the given debugger.\n" | 471 | i18n("Start debugging an application in KDevelop with the given debugger.\n" | ||
457 | "The executable that should be debugged must follow - including arguments.\n" | 472 | "The executable that should be debugged must follow - including arguments.\n" | ||
458 | "Example: kdevelop --debug gdb myapp --foo bar"), QStringLiteral("debugger")}); | 473 | "Example: kdevelop --debug gdb myapp --foo bar"), QStringLiteral("debugger")}); | ||
459 | 474 | | |||
460 | // this is used by the 'kdevelop!' script to retrieve the pid of a KDEVELOP | 475 | // this is used by the 'kdevelop!' script to retrieve the pid of a KDEVELOP | ||
461 | // instance. When this is called, then we should just print the PID on the | 476 | // instance. When this is called, then we should just print the PID on the | ||
462 | // standard-output. If a session is specified through open-session, then | 477 | // standard-output. If a session is specified through open-session, then | ||
▲ Show 20 Lines • Show All 205 Lines • ▼ Show 20 Line(s) | 681 | if (pid > 0) { | |||
668 | std::cout << pid << std::endl; | 683 | std::cout << pid << std::endl; | ||
669 | return 0; | 684 | return 0; | ||
670 | } else { | 685 | } else { | ||
671 | qCritical() << sessionData->uuid.toString() << sessionData->name << "is not running"; | 686 | qCritical() << sessionData->uuid.toString() << sessionData->name << "is not running"; | ||
672 | return 5; | 687 | return 5; | ||
673 | } | 688 | } | ||
674 | } | 689 | } | ||
675 | 690 | | |||
691 | QStringList projectNames = parser.values(QStringLiteral("project")); | ||||
692 | foreach(const QString& projectName, projectNames) | ||||
693 | { | ||||
694 | QFileInfo info( projectName ); | ||||
695 | QUrl projectUrl; | ||||
696 | if (info.suffix() == QLatin1String("kdev4")) { | ||||
697 | projectUrl = QUrl::fromLocalFile(info.absoluteFilePath()); | ||||
698 | } else if (info.isDir()) { | ||||
699 | QDir dir(info.absoluteFilePath()); | ||||
700 | const auto potentialProjectFiles = dir.entryList({QStringLiteral("*.kdev4")}, QDir::Files, QDir::Name); | ||||
701 | qDebug(APP) << "Found these potential project files:" << potentialProjectFiles; | ||||
702 | if (!potentialProjectFiles.isEmpty()) { | ||||
703 | projectUrl = QUrl::fromLocalFile(dir.absoluteFilePath(potentialProjectFiles.value(0))); | ||||
704 | } | ||||
705 | } else { | ||||
706 | QTextStream qerr(stderr); | ||||
707 | qerr << "Invalid project: " << projectName << " - should be either a path to a .kdev4 file or a directory containing a .kdev4 file"; | ||||
708 | return 1; | ||||
709 | } | ||||
710 | | ||||
711 | qDebug(APP) << "Attempting to find a suitable session for project" << projectUrl; | ||||
712 | const auto sessionInfos = findSessionsWithProject(availableSessionInfos, projectUrl); | ||||
713 | qDebug(APP) << "Found matching sessions:" << sessionInfos.size(); | ||||
714 | if (!sessionInfos.isEmpty()) { | ||||
715 | // TODO: If there's more than one match: Allow the user to select which session to open? | ||||
716 | qDebug(APP) << "Attempting to open session:" << sessionInfos.at(0).name; | ||||
717 | session = sessionInfos.at(0).uuid.toString(); | ||||
718 | } | ||||
719 | } | ||||
720 | | ||||
676 | KDevIDEExtension::init(); | 721 | KDevIDEExtension::init(); | ||
677 | 722 | | |||
723 | qDebug(APP) << "Attempting to initialize session:" << session; | ||||
678 | if(!Core::initialize(Core::Default, session)) | 724 | if(!Core::initialize(Core::Default, session)) | ||
679 | return 5; | 725 | return 5; | ||
680 | 726 | | |||
681 | // register a DBUS service for this process, so that we can open files in it from other invocations | 727 | // register a DBUS service for this process, so that we can open files in it from other invocations | ||
682 | QDBusConnection::sessionBus().registerService(QStringLiteral("org.kdevelop.kdevelop-%1").arg(app.applicationPid())); | 728 | QDBusConnection::sessionBus().registerService(QStringLiteral("org.kdevelop.kdevelop-%1").arg(app.applicationPid())); | ||
683 | 729 | | |||
684 | Core* core = Core::self(); | 730 | Core* core = Core::self(); | ||
685 | if (!QProcessEnvironment::systemEnvironment().contains(QStringLiteral("KDEV_DISABLE_WELCOMEPAGE"))) { | 731 | if (!QProcessEnvironment::systemEnvironment().contains(QStringLiteral("KDEV_DISABLE_WELCOMEPAGE"))) { | ||
686 | core->pluginController()->loadPlugin(QStringLiteral("KDevWelcomePage")); | 732 | core->pluginController()->loadPlugin(QStringLiteral("KDevWelcomePage")); | ||
687 | } | 733 | } | ||
688 | 734 | | |||
689 | QStringList projectNames = parser.values(QStringLiteral("project")); | | |||
690 | foreach(const QString& projectName, projectNames) | | |||
691 | { | | |||
692 | QFileInfo info( projectName ); | | |||
693 | if( info.suffix() == QLatin1String("kdev4") ) { | | |||
694 | // make sure the project is not already opened by the session controller | | |||
695 | bool shouldOpen = true; | | |||
696 | Path path(info.absoluteFilePath()); | | |||
697 | foreach(KDevelop::IProject* project, core->projectController()->projects()) { | | |||
698 | if (project->projectFile() == path) { | | |||
699 | shouldOpen = false; | | |||
700 | break; | | |||
701 | } | | |||
702 | } | | |||
703 | if (shouldOpen) { | | |||
704 | core->projectController()->openProject( path.toUrl() ); | | |||
705 | } | | |||
706 | } | | |||
707 | } | | |||
708 | 735 | | |||
709 | const QString debugStr = QStringLiteral("debug"); | 736 | const QString debugStr = QStringLiteral("debug"); | ||
710 | if ( parser.isSet(debugStr) ) { | 737 | if ( parser.isSet(debugStr) ) { | ||
711 | Q_ASSERT( !debugeeName.isEmpty() ); | 738 | Q_ASSERT( !debugeeName.isEmpty() ); | ||
712 | QString launchName = debugeeName; | 739 | QString launchName = debugeeName; | ||
713 | 740 | | |||
714 | KDevelop::LaunchConfiguration* launch = nullptr; | 741 | KDevelop::LaunchConfiguration* launch = nullptr; | ||
715 | qCDebug(APP) << launchName; | 742 | qCDebug(APP) << launchName; | ||
▲ Show 20 Lines • Show All 70 Lines • Show Last 20 Lines |