[SessionController] Fix crash caused by text encoding menu

QMenu since 5.15 is hidden when an action is triggered, this caused a
crash in Konsole when trying to access the text encoding menu.

Now Session emits a signal when the text encoding is changed, the
SessionController can connect to that singal to set the current codec in
the KCodecAction object.

Also fix the EditProfileDialog so that when the KCodecAction menu is
shown the currently set codec is selected.

BUG: 419526

FIXED-IN: 20.08
wilder-portage
Ahmad Samir 6 years ago committed by Kurt Hindenburg
parent 1d7142ed24
commit e7e8e9d1a9
  1. 1
      src/EditProfileDialog.cpp
  2. 2
      src/Session.cpp
  3. 5
      src/Session.h
  4. 7
      src/SessionController.cpp
  5. 2
      src/SessionController.h

@ -1725,6 +1725,7 @@ void EditProfileDialog::setupAdvancedPage(const Profile::Ptr &profile)
// encoding options
auto codecAction = new KCodecAction(this);
codecAction->setCurrentCodec(profile->defaultEncoding());
_advancedUi->selectEncodingButton->setMenu(codecAction->menu());
connect(codecAction,
QOverload<QTextCodec *>::of(&KCodecAction::triggered), this,

@ -252,6 +252,8 @@ void Session::setCodec(QTextCodec* codec)
}
emulation()->setCodec(codec);
emit sessionCodecChanged(codec);
}
bool Session::setCodec(const QByteArray& name)

@ -661,6 +661,11 @@ Q_SIGNALS:
*/
void currentDirectoryChanged(const QString &dir);
/**
* Emitted when the session text encoding changes.
*/
void sessionCodecChanged(QTextCodec *codec);
/** Emitted when a bell event occurs in the session. */
void bellRequest(const QString &message);

@ -691,7 +691,8 @@ void SessionController::setupCommonActions()
_codecAction = new KCodecAction(i18n("Set &Encoding"), this);
_codecAction->setIcon(QIcon::fromTheme(QStringLiteral("character-set")));
collection->addAction(QStringLiteral("set-encoding"), _codecAction);
connect(_codecAction->menu(), &QMenu::aboutToShow, this, &Konsole::SessionController::updateCodecAction);
_codecAction->setCurrentCodec(QString::fromUtf8(_session->codec()));
connect(_session.data(), &Konsole::Session::sessionCodecChanged, this, &Konsole::SessionController::updateCodecAction);
connect(_codecAction,
QOverload<QTextCodec*>::of(&KCodecAction::triggered), this,
&Konsole::SessionController::changeCodec);
@ -846,9 +847,9 @@ void SessionController::prepareSwitchProfileMenu()
_switchProfileMenu->menu()->clear();
_switchProfileMenu->menu()->addActions(_profileList->actions());
}
void SessionController::updateCodecAction()
void SessionController::updateCodecAction(QTextCodec *codec)
{
_codecAction->setCurrentCodec(QString::fromUtf8(_session->codec()));
_codecAction->setCurrentCodec(codec);
}
void SessionController::changeCodec(QTextCodec* codec)

@ -260,7 +260,7 @@ private Q_SLOTS:
// other
void setupSearchBar();
void prepareSwitchProfileMenu();
void updateCodecAction();
void updateCodecAction(QTextCodec *codec);
void showDisplayContextMenu(const QPoint &position);
void movementKeyFromSearchBarReceived(QKeyEvent *event);
void sessionNotificationsChanged(Session::Notification notification, bool enabled);

Loading…
Cancel
Save