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 244 Lines • ▼ Show 20 Line(s) | 346 | #endif | |||
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{"f", "fetch"}, i18n("Open KDevelop and fetch the given project."), QStringLiteral("fetch")}); | 469 | parser.addOption(QCommandLineOption{QStringList{"f", "fetch"}, i18n("Open KDevelop and fetch the given project."), QStringLiteral("fetch")}); | ||
455 | parser.addOption(QCommandLineOption{QStringList{"p", "project"}, i18n("Open KDevelop and load the given project."), QStringLiteral("project")}); | 470 | 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")}); | ||
456 | parser.addOption(QCommandLineOption{QStringList{"d", "debug"}, | 471 | parser.addOption(QCommandLineOption{QStringList{"d", "debug"}, | ||
457 | i18n("Start debugging an application in KDevelop with the given debugger.\n" | 472 | i18n("Start debugging an application in KDevelop with the given debugger.\n" | ||
458 | "The executable that should be debugged must follow - including arguments.\n" | 473 | "The executable that should be debugged must follow - including arguments.\n" | ||
459 | "Example: kdevelop --debug gdb myapp --foo bar"), QStringLiteral("debugger")}); | 474 | "Example: kdevelop --debug gdb myapp --foo bar"), QStringLiteral("debugger")}); | ||
460 | 475 | | |||
461 | // this is used by the 'kdevelop!' script to retrieve the pid of a KDEVELOP | 476 | // this is used by the 'kdevelop!' script to retrieve the pid of a KDEVELOP | ||
462 | // instance. When this is called, then we should just print the PID on the | 477 | // instance. When this is called, then we should just print the PID on the | ||
463 | // standard-output. If a session is specified through open-session, then | 478 | // standard-output. If a session is specified through open-session, then | ||
▲ Show 20 Lines • Show All 205 Lines • ▼ Show 20 Line(s) | 682 | if (pid > 0) { | |||
669 | std::cout << pid << std::endl; | 684 | std::cout << pid << std::endl; | ||
670 | return 0; | 685 | return 0; | ||
671 | } else { | 686 | } else { | ||
672 | qCritical() << sessionData->uuid.toString() << sessionData->name << "is not running"; | 687 | qCritical() << sessionData->uuid.toString() << sessionData->name << "is not running"; | ||
673 | return 5; | 688 | return 5; | ||
674 | } | 689 | } | ||
675 | } | 690 | } | ||
676 | 691 | | |||
692 | if (parser.isSet("project")) { | ||||
693 | const auto project = parser.value(QStringLiteral("project")); | ||||
694 | QFileInfo info(project); | ||||
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: " << project << " - 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 | | ||||
677 | KDevIDEExtension::init(); | 721 | KDevIDEExtension::init(); | ||
678 | 722 | | |||
723 | qDebug(APP) << "Attempting to initialize session:" << session; | ||||
679 | if(!Core::initialize(Core::Default, session)) | 724 | if(!Core::initialize(Core::Default, session)) | ||
680 | return 5; | 725 | return 5; | ||
681 | 726 | | |||
682 | // 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 | ||
683 | QDBusConnection::sessionBus().registerService(QStringLiteral("org.kdevelop.kdevelop-%1").arg(app.applicationPid())); | 728 | QDBusConnection::sessionBus().registerService(QStringLiteral("org.kdevelop.kdevelop-%1").arg(app.applicationPid())); | ||
684 | 729 | | |||
685 | Core* core = Core::self(); | 730 | Core* core = Core::self(); | ||
686 | if (!QProcessEnvironment::systemEnvironment().contains(QStringLiteral("KDEV_DISABLE_WELCOMEPAGE"))) { | 731 | if (!QProcessEnvironment::systemEnvironment().contains(QStringLiteral("KDEV_DISABLE_WELCOMEPAGE"))) { | ||
687 | core->pluginController()->loadPlugin(QStringLiteral("KDevWelcomePage")); | 732 | core->pluginController()->loadPlugin(QStringLiteral("KDevWelcomePage")); | ||
688 | } | 733 | } | ||
689 | 734 | | |||
690 | QStringList projectNames = parser.values(QStringLiteral("project")); | | |||
691 | foreach(const QString& projectName, projectNames) | | |||
692 | { | | |||
693 | QFileInfo info( projectName ); | | |||
694 | if( info.suffix() == QLatin1String("kdev4") ) { | | |||
695 | // make sure the project is not already opened by the session controller | | |||
696 | bool shouldOpen = true; | | |||
697 | Path path(info.absoluteFilePath()); | | |||
698 | foreach(KDevelop::IProject* project, core->projectController()->projects()) { | | |||
699 | if (project->projectFile() == path) { | | |||
700 | shouldOpen = false; | | |||
701 | break; | | |||
702 | } | | |||
703 | } | | |||
704 | if (shouldOpen) { | | |||
705 | core->projectController()->openProject( path.toUrl() ); | | |||
706 | } | | |||
707 | } | | |||
708 | } | | |||
709 | | ||||
710 | const auto fetchUrlStrings = parser.values(QStringLiteral("fetch")); | 735 | const auto fetchUrlStrings = parser.values(QStringLiteral("fetch")); | ||
711 | for (const auto& fetchUrlString : fetchUrlStrings) { | 736 | for (const auto& fetchUrlString : fetchUrlStrings) { | ||
712 | core->projectControllerInternal()->fetchProjectFromUrl(QUrl::fromUserInput(fetchUrlString)); | 737 | core->projectControllerInternal()->fetchProjectFromUrl(QUrl::fromUserInput(fetchUrlString)); | ||
713 | } | 738 | } | ||
714 | 739 | | |||
715 | const QString debugStr = QStringLiteral("debug"); | 740 | const QString debugStr = QStringLiteral("debug"); | ||
716 | if ( parser.isSet(debugStr) ) { | 741 | if ( parser.isSet(debugStr) ) { | ||
717 | Q_ASSERT( !debugeeName.isEmpty() ); | 742 | Q_ASSERT( !debugeeName.isEmpty() ); | ||
▲ Show 20 Lines • Show All 74 Lines • Show Last 20 Lines |