From 49c107966bbea1e7f57329bf281cd0cabffc5280 Mon Sep 17 00:00:00 2001 From: Jekyll Wu Date: Wed, 14 Sep 2011 23:31:23 +0800 Subject: [PATCH] Konsole should never save a profile with empty name into disk. BUG: 281268 FIXED-IN: 4.8 REVIEW:102559 --- src/EditProfileDialog.cpp | 21 +++++++++++++++++++++ src/EditProfileDialog.ui | 38 +++++++++++++++++++++----------------- src/SessionManager.cpp | 6 +++++- 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/EditProfileDialog.cpp b/src/EditProfileDialog.cpp index d1edc005c..235d0096e 100644 --- a/src/EditProfileDialog.cpp +++ b/src/EditProfileDialog.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include @@ -127,6 +128,18 @@ void EditProfileDialog::reject() } void EditProfileDialog::accept() { + Q_ASSERT( _profile ); + Q_ASSERT( _tempProfile ); + + if ( ( _tempProfile->isPropertySet(Profile::Name) && + _tempProfile->name().isEmpty() ) + || ( _profile->name().isEmpty() && _tempProfile->name().isEmpty() ) ) + { + KMessageBox::sorry(this, + i18n("

Each profile must have a name before it can be saved" + "into disk.

")); + return; + } save(); unpreviewAll(); KDialog::accept(); @@ -240,15 +253,21 @@ void EditProfileDialog::setupGeneralPage(const Profile::Ptr info) { _ui->profileNameEdit->setText( info->name() ); _ui->profileNameEdit->setClearButtonShown(true); + + _ui->emptyNameWarningWidget->setVisible( info->name().isEmpty() ); + _ui->emptyNameWarningWidget->setText(i18n("Profile name is empty.")); } else { _ui->profileNameEdit->setText( groupProfileNames(group,-1) ); _ui->profileNameEdit->setEnabled(false); _ui->profileNameLabel->setEnabled(false); + + _ui->emptyNameWarningWidget->setVisible(false); } } + ShellCommand command( info->command() , info->arguments() ); _ui->commandEdit->setText( command.fullCommand() ); KUrlCompletion* exeCompletion = new KUrlCompletion(KUrlCompletion::ExeCompletion); @@ -423,6 +442,8 @@ void EditProfileDialog::selectIcon() } void EditProfileDialog::profileNameChanged(const QString& text) { + _ui->emptyNameWarningWidget->setVisible(text.isEmpty()); + updateTempProfileProperty(Profile::Name,text); updateCaption(_tempProfile); } diff --git a/src/EditProfileDialog.ui b/src/EditProfileDialog.ui index 8883298dc..4d7d17531 100644 --- a/src/EditProfileDialog.ui +++ b/src/EditProfileDialog.ui @@ -59,7 +59,11 @@ - + + + + + Command: @@ -69,7 +73,7 @@ - + The command to execute when new terminal sessions are created using this profile @@ -79,7 +83,7 @@ - + Initial directory: @@ -89,7 +93,7 @@ - + The initial working directory for new terminal sessions using this profile @@ -99,7 +103,7 @@ - + Browse for initial directory @@ -109,7 +113,14 @@ - + + + + Start in same directory as current tab + + + + Icon: @@ -119,7 +130,7 @@ - + @@ -153,7 +164,7 @@ - + Qt::Horizontal @@ -166,7 +177,7 @@ - + Environment: @@ -176,7 +187,7 @@ - + Edit the list of environment variables and associated values @@ -186,13 +197,6 @@ - - - - Start in same directory as current tab - - - diff --git a/src/SessionManager.cpp b/src/SessionManager.cpp index d782b71d3..573fc3d03 100644 --- a/src/SessionManager.cpp +++ b/src/SessionManager.cpp @@ -397,6 +397,7 @@ void SessionManager::changeProfile(Profile::Ptr info , { Q_ASSERT(info); + // insert the changes into the existing Profile instance QListIterator iter(propertyMap.keys()); while ( iter.hasNext() ) @@ -404,7 +405,10 @@ void SessionManager::changeProfile(Profile::Ptr info , const Profile::Property property = iter.next(); info->setProperty(property,propertyMap[property]); } - + + // never save a profile with empty name into disk! + persistent = persistent && !info->name().isEmpty() ; + // when changing a group, iterate through the profiles // in the group and call changeProfile() on each of them //