Changeset View
Changeset View
Standalone View
Standalone View
src/Application.cpp
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 51 | Application::Application(QSharedPointer<QCommandLineParser> parser, | |||
---|---|---|---|---|---|
53 | _backgroundInstance(nullptr), | 53 | _backgroundInstance(nullptr), | ||
54 | m_parser(parser), | 54 | m_parser(parser), | ||
55 | m_customCommand(customCommand) | 55 | m_customCommand(customCommand) | ||
56 | { | 56 | { | ||
57 | } | 57 | } | ||
58 | 58 | | |||
59 | void Application::populateCommandLineParser(QCommandLineParser *parser) | 59 | void Application::populateCommandLineParser(QCommandLineParser *parser) | ||
60 | { | 60 | { | ||
61 | auto options = QVector<QCommandLineOption> { | 61 | const auto options = QVector<QCommandLineOption> { | ||
62 | { { QStringLiteral("profile") }, | 62 | { { QStringLiteral("profile") }, | ||
63 | i18nc("@info:shell", "Name of profile to use for new Konsole instance"), | 63 | i18nc("@info:shell", "Name of profile to use for new Konsole instance"), | ||
64 | QStringLiteral("name") | 64 | QStringLiteral("name") | ||
65 | }, | 65 | }, | ||
66 | { { QStringLiteral("fallback-profile") }, | 66 | { { QStringLiteral("fallback-profile") }, | ||
67 | i18nc("@info:shell", "Use the internal FALLBACK profile") | 67 | i18nc("@info:shell", "Use the internal FALLBACK profile") | ||
68 | }, | 68 | }, | ||
69 | { { QStringLiteral("workdir") }, | 69 | { { QStringLiteral("workdir") }, | ||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 113 | { { QStringLiteral("p") }, | |||
114 | i18nc("@info:shell", "Change the value of a profile property."), | 114 | i18nc("@info:shell", "Change the value of a profile property."), | ||
115 | QStringLiteral("property=value") | 115 | QStringLiteral("property=value") | ||
116 | }, | 116 | }, | ||
117 | { { QStringLiteral("e") }, | 117 | { { QStringLiteral("e") }, | ||
118 | i18nc("@info:shell", "Command to execute. This option will catch all following arguments, so use it as the last option."), | 118 | i18nc("@info:shell", "Command to execute. This option will catch all following arguments, so use it as the last option."), | ||
119 | QStringLiteral("cmd") | 119 | QStringLiteral("cmd") | ||
120 | } | 120 | } | ||
121 | }; | 121 | }; | ||
122 | foreach(const auto& option, options) { | 122 | for (const auto& option : options) { | ||
123 | parser->addOption(option); | 123 | parser->addOption(option); | ||
124 | } | 124 | } | ||
125 | 125 | | |||
126 | parser->addPositionalArgument(QStringLiteral("[args]"), | 126 | parser->addPositionalArgument(QStringLiteral("[args]"), | ||
127 | i18nc("@info:shell", "Arguments passed to command")); | 127 | i18nc("@info:shell", "Arguments passed to command")); | ||
128 | 128 | | |||
129 | // Add a no-op compatibility option to make Konsole compatible with | 129 | // Add a no-op compatibility option to make Konsole compatible with | ||
130 | // Debian's policy on X terminal emulators. | 130 | // Debian's policy on X terminal emulators. | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | |||||
183 | } | 183 | } | ||
184 | 184 | | |||
185 | void Application::detachTerminals(ViewSplitter *splitter,const QHash<TerminalDisplay*, Session*>& sessionsMap) | 185 | void Application::detachTerminals(ViewSplitter *splitter,const QHash<TerminalDisplay*, Session*>& sessionsMap) | ||
186 | { | 186 | { | ||
187 | MainWindow *currentWindow = qobject_cast<MainWindow*>(sender()); | 187 | MainWindow *currentWindow = qobject_cast<MainWindow*>(sender()); | ||
188 | MainWindow *window = newMainWindow(); | 188 | MainWindow *window = newMainWindow(); | ||
189 | ViewManager *manager = window->viewManager(); | 189 | ViewManager *manager = window->viewManager(); | ||
190 | 190 | | |||
191 | foreach(TerminalDisplay* terminal, splitter->findChildren<TerminalDisplay*>()) { | 191 | for(auto* terminal : splitter->findChildren<TerminalDisplay*>()) { | ||
192 | manager->attachView(terminal, sessionsMap[terminal]); | 192 | manager->attachView(terminal, sessionsMap[terminal]); | ||
193 | } | 193 | } | ||
194 | manager->activeContainer()->addSplitter(splitter); | 194 | manager->activeContainer()->addSplitter(splitter); | ||
195 | 195 | | |||
196 | window->show(); | 196 | window->show(); | ||
197 | window->resize(currentWindow->width(), currentWindow->height()); | 197 | window->resize(currentWindow->width(), currentWindow->height()); | ||
198 | window->move(QCursor::pos()); | 198 | window->move(QCursor::pos()); | ||
199 | } | 199 | } | ||
▲ Show 20 Lines • Show All 268 Lines • ▼ Show 20 Line(s) | 467 | } else if (m_parser->isSet(QStringLiteral("list-profile-properties"))) { | |||
468 | listProfilePropertyInfo(); | 468 | listProfilePropertyInfo(); | ||
469 | return true; | 469 | return true; | ||
470 | } | 470 | } | ||
471 | return false; | 471 | return false; | ||
472 | } | 472 | } | ||
473 | 473 | | |||
474 | void Application::listAvailableProfiles() | 474 | void Application::listAvailableProfiles() | ||
475 | { | 475 | { | ||
476 | QStringList paths = ProfileManager::instance()->availableProfilePaths(); | 476 | for (const auto &path : ProfileManager::instance()->availableProfilePaths()) { | ||
477 | | ||||
478 | foreach (const QString &path, paths) { | | |||
479 | QFileInfo info(path); | 477 | QFileInfo info(path); | ||
480 | printf("%s\n", info.completeBaseName().toLocal8Bit().constData()); | 478 | printf("%s\n", info.completeBaseName().toLocal8Bit().constData()); | ||
481 | } | 479 | } | ||
482 | } | 480 | } | ||
483 | 481 | | |||
484 | void Application::listProfilePropertyInfo() | 482 | void Application::listProfilePropertyInfo() | ||
485 | { | 483 | { | ||
486 | Profile::Ptr tempProfile = ProfileManager::instance()->defaultProfile(); | 484 | Profile::Ptr tempProfile = ProfileManager::instance()->defaultProfile(); | ||
487 | const QStringList names = tempProfile->propertiesInfoList(); | 485 | for (const auto &name : tempProfile->propertiesInfoList()) { | ||
488 | | ||||
489 | foreach (const QString &name, names) { | | |||
490 | printf("%s\n", name.toLocal8Bit().constData()); | 486 | printf("%s\n", name.toLocal8Bit().constData()); | ||
491 | } | 487 | } | ||
492 | } | 488 | } | ||
493 | 489 | | |||
494 | Profile::Ptr Application::processProfileChangeArgs(Profile::Ptr baseProfile) | 490 | Profile::Ptr Application::processProfileChangeArgs(Profile::Ptr baseProfile) | ||
495 | { | 491 | { | ||
496 | bool shouldUseNewProfile = false; | 492 | bool shouldUseNewProfile = false; | ||
497 | 493 | | |||
498 | Profile::Ptr newProfile = Profile::Ptr(new Profile(baseProfile)); | 494 | Profile::Ptr newProfile = Profile::Ptr(new Profile(baseProfile)); | ||
499 | newProfile->setHidden(true); | 495 | newProfile->setHidden(true); | ||
500 | 496 | | |||
501 | // change the initial working directory | 497 | // change the initial working directory | ||
502 | if (m_parser->isSet(QStringLiteral("workdir"))) { | 498 | if (m_parser->isSet(QStringLiteral("workdir"))) { | ||
503 | newProfile->setProperty(Profile::Directory, m_parser->value(QStringLiteral("workdir"))); | 499 | newProfile->setProperty(Profile::Directory, m_parser->value(QStringLiteral("workdir"))); | ||
504 | shouldUseNewProfile = true; | 500 | shouldUseNewProfile = true; | ||
505 | } | 501 | } | ||
506 | 502 | | |||
507 | // temporary changes to profile options specified on the command line | 503 | // temporary changes to profile options specified on the command line | ||
508 | const QStringList profileProperties = m_parser->values(QStringLiteral("p")); | 504 | for (const auto &value : m_parser->values(QStringLiteral("p"))) { | ||
509 | foreach (const QString &value, profileProperties) { | | |||
510 | ProfileCommandParser parser; | 505 | ProfileCommandParser parser; | ||
511 | 506 | | |||
512 | QHashIterator<Profile::Property, QVariant> iter(parser.parse(value)); | 507 | QHashIterator<Profile::Property, QVariant> iter(parser.parse(value)); | ||
513 | while (iter.hasNext()) { | 508 | while (iter.hasNext()) { | ||
514 | iter.next(); | 509 | iter.next(); | ||
515 | newProfile->setProperty(iter.key(), iter.value()); | 510 | newProfile->setProperty(iter.key(), iter.value()); | ||
516 | } | 511 | } | ||
517 | 512 | | |||
▲ Show 20 Lines • Show All 88 Lines • Show Last 20 Lines |