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
wilder
Carlos Alves 5 years ago
parent 5cb2121751
commit 5bbb433494
  1. 5
      src/autotests/PtyTest.cpp
  2. 17
      src/session/Session.cpp
  3. 13
      src/session/SessionController.cpp
  4. 5
      src/widgets/EditProfileDialog.cpp

@ -13,6 +13,7 @@
// KDE
#include <qtest.h>
#include <kcoreaddons_version.h>
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)

@ -28,6 +28,7 @@
#include <KProcess>
#include <KConfigGroup>
#include <KIO/DesktopExecParser>
#include <kcoreaddons_version.h>
// Konsole
#include <sessionadaptor.h>
@ -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()

@ -48,6 +48,9 @@
#include <KIO/JobUiDelegate>
#include <KIO/OpenUrlJob>
#include <kwidgetsaddons_version.h>
#include <kconfigwidgets_version.h>
// 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<QTextCodec*>::of(&KCodecAction::triggered), this,
#if KCONFIGWIDGETS_VERSION >= QT_VERSION_CHECK(5, 78, 0)
QOverload<QTextCodec *>::of(&KCodecAction::codecTriggered), this,
#else
QOverload<QTextCodec *>::of(&KCodecAction::triggered), this,
#endif
&Konsole::SessionController::changeCodec);
// Read-only

@ -31,6 +31,7 @@
#include <KMessageBox>
#include <KNSCore/DownloadManager>
#include <KWindowSystem>
#include <kconfigwidgets_version.h>
// 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<QTextCodec *>::of(&KCodecAction::codecTriggered), this,
#else
QOverload<QTextCodec *>::of(&KCodecAction::triggered), this,
#endif
&Konsole::EditProfileDialog::setDefaultCodec);
_advancedUi->selectEncodingButton->setText(profile->defaultEncoding());

Loading…
Cancel
Save