Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 9863b550 authored by Robert Knight's avatar Robert Knight

Bug fixes for the Appearance and Key Bindings tabs in the 
Edit Profile dialog:

* Fix selection of color schemes and key bindings not being
  remembered after the color scheme/key binding list is changed
  (eg. due to adding a new color scheme or editing an existing one).

  This also fixes the preview not being updated when mousing outside 
  the list after adding a new color scheme.

  -> After updates to the color scheme / key bindings list the model
     was being deleted and a new model was created.  This caused the
     selection model to be changed without the signal-slot connections
     from the selection model to the dialog being re-established.

     This commit changes that so that the model is not replaced but
     simply cleared when the color scheme / key binding list is updated.

* Disable the Edit, Remove buttons on the Appearance and 
  Key Bindings tabs when there is no selection.
* Fix crash when clicking 'New' button on the Appearance tab
  if the color scheme list is empty.
* Fix crash when loading the Appearance tab if the color scheme
  associated with the profile does not exist
* Fix crash when loading the Key Bindings tab if the key binding
  associated with the profile does not exist
* Fix crash when attempting to load a color scheme with no name, 
  instead the color scheme is simply not loaded.
* Fix all colors except one being set to black when making changes 
  to a color scheme which was based on the default fallback color scheme.

  -> When creating a new array inside the ColorScheme class to hold color
     entries, initialize its elements with values from the default color
     array.

* Use qWarning() instead of qDebug() to print out error message if attempting
  to delete a color scheme fails.

* Minor formatting changes in Session.cpp,SessionController.h


Known bugs introduced by this commit:
    
* Attempting to create a new keyboard translator when no existing translator
  is selected will crash because KeyboardTranslator::defaultTranslator() has
  not been implemented yet.

svn path=/trunk/KDE/kdebase/apps/konsole/; revision=746071
parent 08db4867
......@@ -159,8 +159,13 @@ void ColorScheme::setColorTableEntry(int index , const ColorEntry& entry)
{
Q_ASSERT( index >= 0 && index < TABLE_COLORS );
if ( !_table )
if ( !_table )
{
_table = new ColorEntry[TABLE_COLORS];
for (int i=0;i<TABLE_COLORS;i++)
_table[i] = defaultTable[i];
}
_table[index] = entry;
}
......@@ -593,21 +598,20 @@ bool ColorSchemeManager::loadColorScheme(const QString& filePath)
QFileInfo info(filePath);
//qDebug() << "loading KDE 4 native color scheme from " << filePath;
KConfig config(filePath , KConfig::NoGlobals);
ColorScheme* scheme = new ColorScheme();
scheme->setName(info.baseName());
scheme->read(config);
Q_ASSERT( !scheme->name().isEmpty() );
//qDebug() << "found KDE 4 native color scheme - " << scheme->name();
//qDebug() << "opacity - " << scheme->opacity();
if (scheme->name().isEmpty())
{
qWarning() << "Color scheme in" << filePath << "does not have a valid name and was not loaded.";
delete scheme;
return false;
}
if ( !_colorSchemes.contains(info.baseName()) )
{
//qDebug() << "added color scheme - " << info.baseName();
_colorSchemes.insert(scheme->name(),scheme);
}
else
......@@ -649,7 +653,7 @@ void ColorSchemeManager::deleteColorScheme(const QString& name)
if ( QFile::remove(path) )
qDebug() << "Removed color scheme -" << path;
else
qDebug() << "Failed to remove color scheme -" << path;
qWarning() << "Failed to remove color scheme -" << path;
}
QString ColorSchemeManager::findColorSchemePath(const QString& name) const
{
......
......@@ -377,10 +377,12 @@ void EditProfileDialog::setupAppearancePage(const Profile* info)
SLOT(colorSchemeAnimationUpdate()) );
_ui->transparencyWarningWidget->setVisible(false);
_ui->editColorSchemeButton->setEnabled(false);
_ui->removeColorSchemeButton->setEnabled(false);
// setup color list
updateColorSchemeList(true);
_ui->colorSchemeList->setMouseTracking(true);
_ui->colorSchemeList->installEventFilter(this);
_ui->colorSchemeList->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn );
......@@ -390,6 +392,8 @@ void EditProfileDialog::setupAppearancePage(const Profile* info)
, this , SLOT(colorSchemeSelected()) );
connect( _ui->colorSchemeList , SIGNAL(entered(const QModelIndex&)) , this ,
SLOT(previewColorScheme(const QModelIndex&)) );
updateColorSchemeButtons();
connect( _ui->editColorSchemeButton , SIGNAL(clicked()) , this ,
SLOT(editColorScheme()) );
......@@ -423,12 +427,18 @@ void EditProfileDialog::updateFontPreviewLabel(const QFont& font)
}
void EditProfileDialog::updateColorSchemeList(bool selectCurrentScheme)
{
delete _ui->colorSchemeList->model();
if (!_ui->colorSchemeList->model())
_ui->colorSchemeList->setModel(new QStandardItemModel(this));
const QString& name = lookupProfile()->colorScheme();
const ColorScheme* currentScheme = ColorSchemeManager::instance()->findColorScheme(name);
QStandardItemModel* model = new QStandardItemModel(this);
QStandardItemModel* model = qobject_cast<QStandardItemModel*>(_ui->colorSchemeList->model());
Q_ASSERT(model);
model->clear();
QList<const ColorScheme*> schemeList = ColorSchemeManager::instance()->allColorSchemes();
QListIterator<const ColorScheme*> schemeIter(schemeList);
......@@ -449,12 +459,8 @@ void EditProfileDialog::updateColorSchemeList(bool selectCurrentScheme)
model->sort(0);
_ui->colorSchemeList->setModel(model);
if ( selectCurrentScheme )
if ( selectCurrentScheme && selectedItem )
{
Q_ASSERT( selectedItem );
_ui->colorSchemeList->updateGeometry();
_ui->colorSchemeList->selectionModel()->setCurrentIndex( selectedItem->index() ,
QItemSelectionModel::Select );
......@@ -465,16 +471,21 @@ void EditProfileDialog::updateColorSchemeList(bool selectCurrentScheme)
}
void EditProfileDialog::updateKeyBindingsList(bool selectCurrentTranslator)
{
KeyboardTranslatorManager* keyManager = KeyboardTranslatorManager::instance();
if (!_ui->keyBindingList->model())
_ui->keyBindingList->setModel(new QStandardItemModel(this));
delete _ui->keyBindingList->model();
KeyboardTranslatorManager* keyManager = KeyboardTranslatorManager::instance();
const QString& name = lookupProfile()
->property(Profile::KeyBindings).value<QString>();
const KeyboardTranslator* currentTranslator = keyManager->findTranslator(name);
QStandardItemModel* model = new QStandardItemModel(this);
QStandardItemModel* model = qobject_cast<QStandardItemModel*>(_ui->keyBindingList->model());
Q_ASSERT(model);
model->clear();
QStandardItem* selectedItem = 0;
......@@ -497,12 +508,9 @@ void EditProfileDialog::updateKeyBindingsList(bool selectCurrentTranslator)
}
model->sort(0);
_ui->keyBindingList->setModel(model);
if ( selectCurrentTranslator )
if ( selectCurrentTranslator && selectedItem )
{
Q_ASSERT( selectedItem );
_ui->keyBindingList->selectionModel()->setCurrentIndex( selectedItem->index() ,
QItemSelectionModel::Select );
}
......@@ -597,8 +605,8 @@ void EditProfileDialog::removeColorScheme()
if ( !selected.isEmpty() )
{
const QString& name = selected.first().data(Qt::UserRole+1).value<const ColorScheme*>()->name();
ColorSchemeManager::instance()->deleteColorScheme(name);
_ui->colorSchemeList->model()->removeRow(selected.first().row());
ColorSchemeManager::instance()->deleteColorScheme(name);
}
}
void EditProfileDialog::showColorSchemeEditor(bool isNewScheme)
......@@ -606,13 +614,13 @@ void EditProfileDialog::showColorSchemeEditor(bool isNewScheme)
QModelIndexList selected = _ui->colorSchemeList->selectionModel()->selectedIndexes();
QAbstractItemModel* model = _ui->colorSchemeList->model();
QModelIndex index;
const ColorScheme* colors = 0;
if ( !selected.isEmpty() )
index = selected.first();
colors = model->data(selected.first(),Qt::UserRole+1).value<const ColorScheme*>();
else
index = model->index(0,0); // use the first item in the list
colors = ColorSchemeManager::instance()->defaultColorScheme();
const ColorScheme* colors = model->data(index,Qt::UserRole+1).value<const ColorScheme*>();
Q_ASSERT(colors);
KDialog* dialog = new KDialog(this);
......@@ -660,10 +668,27 @@ void EditProfileDialog::colorSchemeSelected()
QAbstractItemModel* model = _ui->colorSchemeList->model();
const ColorScheme* colors = model->data(selected.first(),Qt::UserRole+1).value<const ColorScheme*>();
qDebug() << "Setting temp profile color to" << colors->name();
_tempProfile->setProperty(Profile::ColorScheme,colors->name());
updateTransparencyWarning();
}
updateColorSchemeButtons();
}
void EditProfileDialog::updateColorSchemeButtons()
{
enableIfNonEmptySelection(_ui->editColorSchemeButton,_ui->colorSchemeList->selectionModel());
enableIfNonEmptySelection(_ui->removeColorSchemeButton,_ui->colorSchemeList->selectionModel());
}
void EditProfileDialog::updateKeyBindingsButtons()
{
enableIfNonEmptySelection(_ui->editKeyBindingsButton,_ui->keyBindingList->selectionModel());
enableIfNonEmptySelection(_ui->removeKeyBindingsButton,_ui->keyBindingList->selectionModel());
}
void EditProfileDialog::enableIfNonEmptySelection(QWidget* widget,QItemSelectionModel* selectionModel)
{
widget->setEnabled(selectionModel->hasSelection());
}
void EditProfileDialog::updateTransparencyWarning()
{
......@@ -686,6 +711,9 @@ void EditProfileDialog::setupKeyboardPage(const Profile* /* info */)
SLOT(keyBindingSelected()) );
connect( _ui->newKeyBindingsButton , SIGNAL(clicked()) , this ,
SLOT(newKeyBinding()) );
updateKeyBindingsButtons();
connect( _ui->editKeyBindingsButton , SIGNAL(clicked()) , this ,
SLOT(editKeyBinding()) );
connect( _ui->removeKeyBindingsButton , SIGNAL(clicked()) , this ,
......@@ -702,6 +730,8 @@ void EditProfileDialog::keyBindingSelected()
.value<const KeyboardTranslator*>();
_tempProfile->setProperty(Profile::KeyBindings,translator->name());
}
updateKeyBindingsButtons();
}
void EditProfileDialog::removeKeyBinding()
{
......@@ -719,15 +749,14 @@ void EditProfileDialog::showKeyBindingEditor(bool isNewTranslator)
QModelIndexList selected = _ui->keyBindingList->selectionModel()->selectedIndexes();
QAbstractItemModel* model = _ui->keyBindingList->model();
QModelIndex index;
const KeyboardTranslator* translator = 0;
if ( !selected.isEmpty() )
index = selected.first();
translator = model->data(selected.first(),Qt::UserRole+1).value<const KeyboardTranslator*>();
else
index = model->index(0,0); // Use first item if there is no selection
translator = KeyboardTranslatorManager::instance()->defaultTranslator();
Q_ASSERT(translator);
const KeyboardTranslator* translator = model->data(index,
Qt::UserRole+1).value<const KeyboardTranslator*>();
KDialog* dialog = new KDialog(this);
if ( isNewTranslator )
......
......@@ -31,6 +31,7 @@
#include <KDialog>
class QAbstractButton;
class QItemSelectionModel;
class QTextCodec;
class QTimeLine;
......@@ -175,7 +176,9 @@ private:
void setupAdvancedPage(const Profile* info);
void updateColorSchemeList(bool selectCurrentScheme = false);
void updateColorSchemeButtons();
void updateKeyBindingsList(bool selectCurrentTranslator = false);
void updateKeyBindingsButtons();
void updateFontPreviewLabel(const QFont& font);
void showColorSchemeEditor(bool newScheme);
......@@ -187,9 +190,9 @@ private:
void delayedPreview(int property , const QVariant& value);
void unpreview(int property);
void unpreviewAll();
void enableIfNonEmptySelection(QWidget* widget,QItemSelectionModel* selectionModel);
void updateCaption(const QString& profileName);
void updateTransparencyWarning();
struct RadioOption
......
......@@ -832,6 +832,11 @@ void KeyboardTranslatorManager::deleteTranslator(const QString& name)
else
qDebug() << "Failed to remove translator - " << path;
}
const KeyboardTranslator* KeyboardTranslatorManager::defaultTranslator() const
{
#warning "FIXME: Implement a default translator to fall back to in case there are no .keytab files available to load."
return 0;
}
void KeyboardTranslatorManager::setInstance(KeyboardTranslatorManager* instance)
{
_instance = instance;
......
......@@ -460,6 +460,9 @@ public:
*/
void deleteTranslator(const QString& name);
/** Returns the default translator for Konsole. */
const KeyboardTranslator* defaultTranslator() const;
/**
* Returns the keyboard translator with the given name or 0 if no translator
* with that name exists.
......
......@@ -320,8 +320,9 @@ void Session::setUserTitle( int what, const QString &caption )
//set to true if anything is actually changed (eg. old _nameTitle != new _nameTitle )
bool modified = false;
// (btw: what=0 changes _nameTitle and icon, what=1 only icon, what=2 only _nameTitle
if ((what == 0) || (what == 2)) {
// (btw: what=0 changes _userTitle and icon, what=1 only icon, what=2 only _nameTitle
if ((what == 0) || (what == 2))
{
if ( _userTitle != caption ) {
_userTitle = caption;
modified = true;
......@@ -336,39 +337,44 @@ void Session::setUserTitle( int what, const QString &caption )
}
}
if (what == 11) {
if (what == 11)
{
QString colorString = caption.section(';',0,0);
kDebug() << __FILE__ << __LINE__ << ": setting background colour to " << colorString;
QColor backColor = QColor(colorString);
if (backColor.isValid()){// change color via \033]11;Color\007
if (backColor != _modifiedBackground)
{
_modifiedBackground = backColor;
if (backColor != _modifiedBackground)
{
_modifiedBackground = backColor;
// bail out here until the code to connect the terminal display
// to the changeBackgroundColor() signal has been written
// and tested - just so we don't forget to do this.
Q_ASSERT( 0 );
// bail out here until the code to connect the terminal display
// to the changeBackgroundColor() signal has been written
// and tested - just so we don't forget to do this.
Q_ASSERT( 0 );
emit changeBackgroundColorRequest(backColor);
}
emit changeBackgroundColorRequest(backColor);
}
}
}
if (what == 30) {
if (what == 30)
{
if ( _nameTitle != caption ) {
setTitle(Session::NameRole,caption);
return;
}
}
if (what == 31) {
if (what == 31)
{
QString cwd=caption;
cwd=cwd.replace( QRegExp("^~"), QDir::homePath() );
emit openUrlRequest(cwd);
}
if (what == 32) { // change icon via \033]32;Icon\007
// change icon via \033]32;Icon\007
if (what == 32)
{
if ( _iconName != caption ) {
_iconName = caption;
......@@ -376,11 +382,9 @@ void Session::setUserTitle( int what, const QString &caption )
}
}
if (what == 50) {
qDebug() << "Profile change command received";
if (what == 50)
{
emit profileChangeCommandReceived(caption);
return;
}
......
......@@ -213,6 +213,9 @@ private:
void setFindNextPrevEnabled(bool enabled);
private:
static KIcon _activityIcon;
static KIcon _silenceIcon;
QPointer<Session> _session;
QPointer<TerminalDisplay> _view;
......@@ -229,9 +232,7 @@ private:
KAction* _findNextAction;
KAction* _findPreviousAction;
static KIcon _activityIcon;
static KIcon _silenceIcon;
bool _urlFilterUpdateRequired;
QPointer<IncrementalSearchBar> _searchBar;
......
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