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) 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,54 @@ * 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(TerminalInterfaceV2) +#else +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,38 @@ 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) +{ + auto 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/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