From 5bbb433494bdb3996acee59d00ab4e4a6ea30a0d Mon Sep 17 00:00:00 2001 From: Carlos Alves Date: Fri, 1 Jan 2021 09:11:41 -0300 Subject: [PATCH] Adding version checks to deprecated functions Macros to check frameworks versions and switch from deprecated functions to newer versions. KProcess: pid -> processId KCodecAction: setDelayed -> setPopupMode KActionMenu: triggered -> codecTriggered --- src/autotests/PtyTest.cpp | 5 +++++ src/session/Session.cpp | 17 +++++++++++------ src/session/SessionController.cpp | 13 ++++++++++++- src/widgets/EditProfileDialog.cpp | 5 +++++ 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/autotests/PtyTest.cpp b/src/autotests/PtyTest.cpp index 14ca24ae..4d6ff1e2 100644 --- a/src/autotests/PtyTest.cpp +++ b/src/autotests/PtyTest.cpp @@ -13,6 +13,7 @@ // KDE #include +#include using namespace Konsole; @@ -73,7 +74,11 @@ void PtyTest::testRunProgram() // since there is no other processes using this pty, the two methods // should return the same pid. +#if KCOREADDONS_VERSION >= QT_VERSION_CHECK(5, 78, 0) + QCOMPARE(pty.foregroundProcessGroup(), pty.processId()); +#else QCOMPARE(pty.foregroundProcessGroup(), pty.pid()); +#endif } QTEST_GUILESS_MAIN(PtyTest) diff --git a/src/session/Session.cpp b/src/session/Session.cpp index 79916847..bd315a1f 100644 --- a/src/session/Session.cpp +++ b/src/session/Session.cpp @@ -28,6 +28,7 @@ #include #include #include +#include // Konsole #include @@ -437,7 +438,7 @@ void Session::run() { // FIXME: run() is called twice in some instances if (isRunning()) { - qCDebug(KonsoleDebug) << "Attempted to re-run an already running session (" << _shellProcess->pid() << ")"; + qCDebug(KonsoleDebug) << "Attempted to re-run an already running session (" << processId() << ")"; return; } @@ -822,11 +823,11 @@ void Session::reportBackgroundColor(const QColor& c, uint terminator) bool Session::kill(int signal) { - if (_shellProcess->pid() <= 0) { + if (processId() <= 0) { return false; } - int result = ::kill(_shellProcess->pid(), signal); + int result = ::kill(processId(), signal); if (result == 0) { return _shellProcess->waitForFinished(1000); @@ -880,7 +881,7 @@ bool Session::closeInNormalWay() if (kill(SIGHUP)) { return true; } else { - qWarning() << "Process " << _shellProcess->pid() << " did not die with SIGHUP"; + qWarning() << "Process " << processId() << " did not die with SIGHUP"; _shellProcess->closePty(); return (_shellProcess->waitForFinished(1000)); } @@ -894,7 +895,7 @@ bool Session::closeInForceWay() if (kill(SIGKILL)) { return true; } else { - qWarning() << "Process " << _shellProcess->pid() << " did not die with SIGKILL"; + qWarning() << "Process " << processId() << " did not die with SIGKILL"; return false; } } @@ -1528,7 +1529,11 @@ void Session::setPreferredSize(const QSize& size) int Session::processId() const { +#if KCOREADDONS_VERSION >= QT_VERSION_CHECK(5, 78, 0) + return _shellProcess->processId(); +#else return _shellProcess->pid(); +#endif } void Session::setTitle(int role , const QString& title) @@ -1646,7 +1651,7 @@ int Session::foregroundProcessId() bool Session::isForegroundProcessActive() { // foreground process info is always updated after this - return (_shellProcess->pid() != _shellProcess->foregroundProcessGroup()); + return (processId() != _shellProcess->foregroundProcessGroup()); } QString Session::foregroundProcessName() diff --git a/src/session/SessionController.cpp b/src/session/SessionController.cpp index 763b5550..24ece481 100644 --- a/src/session/SessionController.cpp +++ b/src/session/SessionController.cpp @@ -48,6 +48,9 @@ #include #include +#include +#include + // Konsole #include "CopyInputDialog.h" #include "Emulation.h" @@ -694,7 +697,11 @@ void SessionController::setupCommonActions() _switchProfileMenu = new KActionMenu(i18n("Switch Profile"), this); collection->addAction(QStringLiteral("switch-profile"), _switchProfileMenu); connect(_switchProfileMenu->menu(), &QMenu::aboutToShow, this, &Konsole::SessionController::prepareSwitchProfileMenu); +#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 77, 0) + _switchProfileMenu->setPopupMode(QToolButton::MenuButtonPopup); +#else _switchProfileMenu->setDelayed(false); +#endif // History _findAction = KStandardAction::find(this, &SessionController::searchBarEvent, collection); @@ -722,7 +729,11 @@ void SessionController::setupCommonActions() _codecAction->setCurrentCodec(QString::fromUtf8(session()->codec())); connect(session(), &Konsole::Session::sessionCodecChanged, this, &Konsole::SessionController::updateCodecAction); connect(_codecAction, - QOverload::of(&KCodecAction::triggered), this, +#if KCONFIGWIDGETS_VERSION >= QT_VERSION_CHECK(5, 78, 0) + QOverload::of(&KCodecAction::codecTriggered), this, +#else + QOverload::of(&KCodecAction::triggered), this, +#endif &Konsole::SessionController::changeCodec); // Read-only diff --git a/src/widgets/EditProfileDialog.cpp b/src/widgets/EditProfileDialog.cpp index 92ce6329..dccbdce6 100644 --- a/src/widgets/EditProfileDialog.cpp +++ b/src/widgets/EditProfileDialog.cpp @@ -31,6 +31,7 @@ #include #include #include +#include // Konsole #include "ui_EditProfileGeneralPage.h" @@ -1856,7 +1857,11 @@ void EditProfileDialog::setupAdvancedPage(const Profile::Ptr &profile) codecAction->setCurrentCodec(profile->defaultEncoding()); _advancedUi->selectEncodingButton->setMenu(codecAction->menu()); connect(codecAction, +#if KCONFIGWIDGETS_VERSION >= QT_VERSION_CHECK(5, 78, 0) + QOverload::of(&KCodecAction::codecTriggered), this, +#else QOverload::of(&KCodecAction::triggered), this, +#endif &Konsole::EditProfileDialog::setDefaultCodec); _advancedUi->selectEncodingButton->setText(profile->defaultEncoding());