Commit 61a7947a authored by Ahmad Samir's avatar Ahmad Samir Committed by Kurt Hindenburg
Browse files

Show dialogs with show() rather than exec()

exec() creates a nested eventloop, which could lead to some nasty
crashes ...etc.

ProfileSettings::editSelected(): since the dialog is modal, the user
can't interact with the konsole window at all, so no chance of opening
another instance of the EditProfileDialog.
parent 9ec6f0aa
......@@ -948,11 +948,13 @@ void SessionController::editCurrentProfile()
void SessionController::renameSession()
{
const QString &sessionLocalTabTitleFormat = session()->tabTitleFormat(Session::LocalTabTitle);
const QString &sessionRemoteTabTitleFormat = session()->tabTitleFormat(Session::RemoteTabTitle);
const QColor &sessionTabColor = session()->color();
const QString sessionLocalTabTitleFormat = session()->tabTitleFormat(Session::LocalTabTitle);
const QString sessionRemoteTabTitleFormat = session()->tabTitleFormat(Session::RemoteTabTitle);
const QColor sessionTabColor = session()->color();
QScopedPointer<RenameTabDialog> dialog(new RenameTabDialog(QApplication::activeWindow()));
auto *dialog = new RenameTabDialog(QApplication::activeWindow());
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setModal(true);
dialog->setTabTitleText(sessionLocalTabTitleFormat);
dialog->setRemoteTabTitleText(sessionRemoteTabTitleFormat);
dialog->setColor(sessionTabColor);
......@@ -963,16 +965,10 @@ void SessionController::renameSession()
dialog->focusTabTitleText();
}
QPointer<Session> guard(session());
int result = dialog->exec();
if (guard.isNull()) {
return;
}
if (result != 0) {
const QString &tabTitle = dialog->tabTitleText();
const QString &remoteTabTitle = dialog->remoteTabTitleText();
const QColor &tabColor = dialog->color();
connect(dialog, &QDialog::accepted, this, [=]() {
const QString tabTitle = dialog->tabTitleText();
const QString remoteTabTitle = dialog->remoteTabTitleText();
const QColor tabColor = dialog->color();
if (tabTitle != sessionLocalTabTitleFormat) {
session()->setTabTitleFormat(Session::LocalTabTitle, tabTitle);
......@@ -992,7 +988,9 @@ void SessionController::renameSession()
Q_EMIT tabColoredByUser(true);
snapshot();
}
}
});
dialog->show();
}
// This is called upon Menu->Close Sesssion and right-click on tab->Close Tab
......@@ -1198,7 +1196,9 @@ void SessionController::copyInputToSelectedTabs()
_copyToGroup->setMasterMode(SessionGroup::CopyInputToAll);
}
QPointer<CopyInputDialog> dialog = new CopyInputDialog(view());
auto *dialog = new CopyInputDialog(view());
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setModal(true);
dialog->setMasterSession(session());
const QList<Session*> sessionsList = _copyToGroup->sessions();
......@@ -1208,13 +1208,7 @@ void SessionController::copyInputToSelectedTabs()
dialog->setChosenSessions(currentGroup);
QPointer<Session> guard(session());
int result = dialog->exec();
if (guard.isNull()) {
return;
}
if (result == QDialog::Accepted) {
connect(dialog, &QDialog::accepted, this, [=]() {
QSet<Session*> newGroup = dialog->chosenSessions();
newGroup.remove(session());
......@@ -1231,7 +1225,9 @@ void SessionController::copyInputToSelectedTabs()
_copyToGroup->setMasterMode(SessionGroup::CopyInputToAll);
snapshot();
Q_EMIT copyInputChanged(this);
}
});
dialog->show();
}
void SessionController::copyInputToNone()
......@@ -1580,9 +1576,11 @@ void SessionController::changeSearchMatch()
}
void SessionController::showHistoryOptions()
{
QScopedPointer<HistorySizeDialog> dialog(new HistorySizeDialog(QApplication::activeWindow()));
const HistoryType& currentHistory = session()->historyType();
auto *dialog = new HistorySizeDialog(QApplication::activeWindow());
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setModal(true);
const HistoryType &currentHistory = session()->historyType();
if (currentHistory.isEnabled()) {
if (currentHistory.isUnlimited()) {
dialog->setMode(Enum::UnlimitedHistory);
......@@ -1594,15 +1592,11 @@ void SessionController::showHistoryOptions()
dialog->setMode(Enum::NoHistory);
}
QPointer<Session> guard(session());
int result = dialog->exec();
if (guard.isNull()) {
return;
}
if (result != 0) {
connect(dialog, &QDialog::accepted, this, [this, dialog]() {
scrollBackOptionsChanged(dialog->mode(), dialog->lineCount());
}
});
dialog->show();
}
void SessionController::sessionResizeRequest(const QSize& size)
{
......
......@@ -145,16 +145,18 @@ void ProfileSettings::createProfile()
newProfile->setProperty(Profile::Name, uniqueName);
newProfile->setProperty(Profile::UntranslatedName, uniqueName);
// Consider https://blogs.kde.org/2009/03/26/how-crash-almost-every-qtkde-application-and-how-fix-it-0 before changing the below
QPointer<EditProfileDialog> dialog = new EditProfileDialog(this);
dialog.data()->setProfile(newProfile);
dialog.data()->selectProfileName();
auto *dialog = new EditProfileDialog(this);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setModal(true);
dialog->setProfile(newProfile);
dialog->selectProfileName();
if (dialog.data()->exec() == QDialog::Accepted) {
connect(dialog, &QDialog::accepted, this, [newProfile]() {
ProfileManager::instance()->addProfile(newProfile);
ProfileManager::instance()->changeProfile(newProfile, newProfile->setProperties());
}
delete dialog.data();
});
dialog->show();
}
void ProfileSettings::editSelected()
{
......@@ -167,29 +169,11 @@ void ProfileSettings::editSelected()
return;
}
EditProfileDialog *profileDialog = nullptr;
const auto sessionsList = SessionManager::instance()->sessions();
for (const Session *session : sessionsList) {
for (TerminalDisplay *terminalDisplay : session->views()) {
// Searching for already open EditProfileDialog instances
// for this profile
profileDialog = terminalDisplay->sessionController()->profileDialogPointer();
if (profileDialog == nullptr) {
continue;
}
if (profile->name() == profileDialog->lookupProfile()->name()
&& profileDialog->isVisible()) {
// close opened edit dialog
profileDialog->close();
}
}
}
EditProfileDialog dialog(this);
dialog.setProfile(profile);
dialog.exec();
auto *dialog = new EditProfileDialog(this);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setModal(true);
dialog->setProfile(profile);
dialog->show();
}
Profile::Ptr ProfileSettings::currentProfile() const
......
......@@ -1117,6 +1117,7 @@ void EditProfileDialog::showFontDialog()
{
if (_fontDialog == nullptr) {
_fontDialog = new FontDialog(this);
_fontDialog->setModal(true);
connect(_fontDialog, &FontDialog::fontChanged, this, [this](const QFont &font) {
preview(Profile::Font, font);
updateFontPreview(font);
......@@ -1129,13 +1130,12 @@ void EditProfileDialog::showFontDialog()
});
connect(_fontDialog, &FontDialog::rejected, this, [this]() {
unpreview(Profile::Font);
const QFont font = _profile->font();
updateFontPreview(font);
updateFontPreview(_profile->font());
});
}
const QFont font = _profile->font();
_fontDialog->setFont(font);
_fontDialog->exec();
_fontDialog->setFont(_profile->font());
_fontDialog->show();
}
void EditProfileDialog::updateFontPreview(QFont font)
......@@ -1487,9 +1487,9 @@ void EditProfileDialog::showKeyBindingEditor(bool isNewTranslator)
translator = _keyManager->defaultTranslator();
}
Q_ASSERT(translator);
auto editor = new KeyBindingEditor(this);
auto *editor = new KeyBindingEditor(this);
editor->setAttribute(Qt::WA_DeleteOnClose);
editor->setModal(true);
if (translator != nullptr) {
editor->setup(translator, lookupProfile()->keyBindings(), isNewTranslator);
......@@ -1497,11 +1497,10 @@ void EditProfileDialog::showKeyBindingEditor(bool isNewTranslator)
connect(editor, &Konsole::KeyBindingEditor::updateKeyBindingsListRequest,
this, &Konsole::EditProfileDialog::updateKeyBindingsList);
connect(editor, &Konsole::KeyBindingEditor::updateTempProfileKeyBindingsRequest,
this, &Konsole::EditProfileDialog::updateTempProfileProperty);
editor->exec();
editor->show();
}
void EditProfileDialog::newKeyBinding()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment