diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,6 +9,10 @@ set(HAVE_OS_DRAGONFLYBSD 0) endif() +IF(NOT (${KF5_VERSION} VERSION_LESS "5.60.0")) + set(USE_TERMINALINTERFACEV2 1) +endif() + include(CheckIncludeFiles) include(ECMAddAppIcon) @@ -73,17 +77,17 @@ Pty.cpp RenameTabDialog.cpp RenameTabWidget.cpp - SaveHistoryTask.cpp - SearchHistoryTask.cpp - Screen.cpp + SaveHistoryTask.cpp + SearchHistoryTask.cpp + Screen.cpp ScreenWindow.cpp ScrollState.cpp Session.cpp SessionController.cpp SessionManager.cpp SessionListModel.cpp - SessionTask.cpp - ShellCommand.cpp + SessionTask.cpp + ShellCommand.cpp TabTitleFormatButton.cpp TerminalCharacterDecoder.cpp ExtendedCharTable.cpp diff --git a/src/Part.h b/src/Part.h --- a/src/Part.h +++ b/src/Part.h @@ -29,6 +29,7 @@ #include // Konsole +#include "config-konsole.h" #include "Profile.h" class QAction; @@ -45,33 +46,55 @@ * A re-usable terminal emulator component using the KParts framework which can * be used to embed terminal emulators into other applications. */ -class Part : public KParts::ReadOnlyPart, public TerminalInterface +#ifdef USE_TERMINALINTERFACEV2 +class Part : public KParts::ReadOnlyPart, public TerminalInterfaceV2 +{ + Q_OBJECT + Q_INTERFACES(TerminalInterface TerminalInterfaceV2) +#else +class TerminalInterfaceV2; +class Part : public KParts::ReadOnlyPart, public TerminalInterface { Q_OBJECT Q_INTERFACES(TerminalInterface) +#endif public: /** Constructs a new Konsole part with the specified parent. */ explicit Part(QWidget *parentWidget, QObject *parent, const QVariantList &); ~Part() Q_DECL_OVERRIDE; /** Reimplemented from TerminalInterface. */ - void startProgram(const QString &program, const QStringList &arguments) Q_DECL_OVERRIDE; + void startProgram(const QString &program, const QStringList &arguments) override; /** Reimplemented from TerminalInterface. */ - void showShellInDir(const QString &dir) Q_DECL_OVERRIDE; + void showShellInDir(const QString &dir) override; /** Reimplemented from TerminalInterface. */ - void sendInput(const QString &text) Q_DECL_OVERRIDE; + void sendInput(const QString &text) override; /** Reimplemented from TerminalInterface. */ - int terminalProcessId() Q_DECL_OVERRIDE; + int terminalProcessId() override; /** Reimplemented from TerminalInterface. */ - int foregroundProcessId() Q_DECL_OVERRIDE; + int foregroundProcessId() override; /** Reimplemented from TerminalInterface. */ - QString foregroundProcessName() Q_DECL_OVERRIDE; + QString foregroundProcessName() override; /** Reimplemented from TerminalInterface. */ - QString currentWorkingDirectory() const Q_DECL_OVERRIDE; + QString currentWorkingDirectory() const override; + +#ifdef USE_TERMINALINTERFACEV2 + /** Reimplemented from TerminalInterfaceV2 */ + QStringList availableProfiles() const override; + + /** Reimplemented from TerminalInterfaceV2 */ + QString currentProfileName() const override; + + /** Reimplemented from TerminalInterfaceV2 */ + bool setCurrentProfile(const QString &profileName) override; + + /** Reimplemented from TerminalInterfaceV2 */ + QVariant profileProperty(const QString &profileProperty) const override; +#endif public Q_SLOTS: /** diff --git a/src/Part.cpp b/src/Part.cpp --- a/src/Part.cpp +++ b/src/Part.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include // KDE @@ -197,6 +198,50 @@ return activeSession()->currentWorkingDirectory(); } +#ifdef USE_TERMINALINTERFACEV2 +QVariant Part::profileProperty(const QString &profileProperty) const +{ + const auto metaEnum = QMetaEnum::fromType(); + const auto value = metaEnum.keyToValue(profileProperty.toStdString().c_str()); + + if (value == -1) { + return QString(); + } + + const Profile::Property p = static_cast(value); + return SessionManager::instance()->sessionProfile(activeSession())->property(p); +} + +QStringList Part::availableProfiles() const +{ + return ProfileManager::instance()->availableProfileNames(); +} + +QString Part::currentProfileName() const +{ + return SessionManager::instance()->sessionProfile(activeSession())->name(); +} + +bool Part::setCurrentProfile(const QString &profileName) +{ + + Profile::Ptr profile; + for(auto p : ProfileManager::instance()->allProfiles()) { + if (p->name() == profileName) { + profile = p; + break; + } + } + + if (!profile) { + profile = ProfileManager::instance()->loadProfile(profileName); + } + + SessionManager::instance()->setSessionProfile(activeSession(), profile); + return currentProfileName() == profileName; +} +#endif + void Part::createSession(const QString &profileName, const QString &directory) { Profile::Ptr profile = ProfileManager::instance()->defaultProfile(); diff --git a/src/Profile.h b/src/Profile.h --- a/src/Profile.h +++ b/src/Profile.h @@ -55,6 +55,8 @@ */ class KONSOLEPRIVATE_EXPORT Profile : public QSharedData { + Q_GADGET + friend class ProfileReader; friend class ProfileWriter; friend class ProfileGroup; @@ -296,6 +298,8 @@ ReverseUrlHints }; + Q_ENUM(Property) + /** * Constructs a new profile * diff --git a/src/autotests/TerminalInterfaceTest.h b/src/autotests/TerminalInterfaceTest.h --- a/src/autotests/TerminalInterfaceTest.h +++ b/src/autotests/TerminalInterfaceTest.h @@ -35,6 +35,7 @@ private Q_SLOTS: void testTerminalInterfaceNoShell(); void testTerminalInterface(); + void testTerminalInterfaceV2(); private: KParts::Part* createPart(); diff --git a/src/autotests/TerminalInterfaceTest.cpp b/src/autotests/TerminalInterfaceTest.cpp --- a/src/autotests/TerminalInterfaceTest.cpp +++ b/src/autotests/TerminalInterfaceTest.cpp @@ -19,6 +19,9 @@ // Own #include "TerminalInterfaceTest.h" +#include "../Profile.h" +#include "../ProfileManager.h" +#include "config-konsole.h" // Qt #include @@ -168,6 +171,35 @@ QCOMPARE(destroyedSpy.count(), 1); } +void TerminalInterfaceTest::testTerminalInterfaceV2() +{ +#ifdef USE_TERMINALINTERFACEV2 + Profile::Ptr testProfile(new Profile); + testProfile->useFallback(); + ProfileManager::instance()->addProfile(testProfile); + + _terminalPart = createPart(); + if (_terminalPart == nullptr) { + QSKIP("konsolepart not found.", SkipSingle); + } + + TerminalInterfaceV2 *terminal = qobject_cast(_terminalPart); + + QVERIFY(terminal); + QVERIFY(terminal->setCurrentProfile(testProfile->name())); + QCOMPARE(terminal->currentProfileName(), testProfile->name()); + + QCOMPARE(terminal->profileProperty(QStringLiteral("Path")), testProfile->path()); + QCOMPARE(terminal->profileProperty(QStringLiteral("SilenceSeconds")), testProfile->silenceSeconds()); + QCOMPARE(terminal->profileProperty(QStringLiteral("Icon")), testProfile->icon()); + QCOMPARE(terminal->profileProperty(QStringLiteral("ShowTerminalSizeHint")), testProfile->showTerminalSizeHint()); + QCOMPARE(terminal->profileProperty(QStringLiteral("Environment")), testProfile->environment()); + QCOMPARE(terminal->profileProperty(QStringLiteral("BellMode")), testProfile->property(Profile::Property::BellMode)); +#else + QSKIP("TerminalInterfaceV2 not enabled", SkipSingle); +#endif +} + KParts::Part *TerminalInterfaceTest::createPart() { KService::Ptr service = KService::serviceByDesktopName(QStringLiteral("konsolepart")); diff --git a/src/config-konsole.h.cmake b/src/config-konsole.h.cmake --- a/src/config-konsole.h.cmake +++ b/src/config-konsole.h.cmake @@ -7,3 +7,5 @@ /* If defined, remove public access to dbus sendInput/runCommand */ #cmakedefine REMOVE_SENDTEXT_RUNCOMMAND_DBUS_METHODS + +#cmakedefine USE_TERMINALINTERFACEV2