Some code cleanup and style fixing
svn path=/trunk/KDE/kdebase/workspace/; revision=961920
This commit is contained in:
parent
e4a80093b3
commit
07ada33d96
2 changed files with 127 additions and 135 deletions
|
@ -29,173 +29,165 @@
|
|||
namespace KWin
|
||||
{
|
||||
|
||||
KCMRulesList::KCMRulesList( QWidget* parent)
|
||||
: QWidget( parent)
|
||||
{
|
||||
setupUi( this );
|
||||
// connect both current/selected, so that current==selected (stupid QListBox :( )
|
||||
connect( rules_listbox, SIGNAL(itemChanged(QListWidgetItem*)),
|
||||
SLOT(activeChanged()));
|
||||
connect( rules_listbox, SIGNAL(itemSelectionChanged()),
|
||||
SLOT( activeChanged()));
|
||||
connect( new_button, SIGNAL( clicked()),
|
||||
SLOT( newClicked()));
|
||||
connect( modify_button, SIGNAL( clicked()),
|
||||
SLOT( modifyClicked()));
|
||||
connect( delete_button, SIGNAL( clicked()),
|
||||
SLOT( deleteClicked()));
|
||||
connect( moveup_button, SIGNAL( clicked()),
|
||||
SLOT( moveupClicked()));
|
||||
connect( movedown_button, SIGNAL( clicked()),
|
||||
SLOT( movedownClicked()));
|
||||
connect( rules_listbox, SIGNAL(itemDoubleClicked(QListWidgetItem*) ),
|
||||
SLOT( modifyClicked()));
|
||||
KCMRulesList::KCMRulesList(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
connect(rules_listbox, SIGNAL(itemChanged(QListWidgetItem*)), SLOT(activeChanged()));
|
||||
connect(rules_listbox, SIGNAL(itemSelectionChanged()), SLOT(activeChanged()));
|
||||
connect(new_button, SIGNAL(clicked()), SLOT(newClicked()));
|
||||
connect(modify_button, SIGNAL(clicked()), SLOT(modifyClicked()));
|
||||
connect(delete_button, SIGNAL(clicked()), SLOT(deleteClicked()));
|
||||
connect(moveup_button, SIGNAL(clicked()), SLOT(moveUpClicked()));
|
||||
connect(movedown_button, SIGNAL(clicked()), SLOT(moveDownClicked()));
|
||||
connect(rules_listbox, SIGNAL(itemDoubleClicked(QListWidgetItem*)), SLOT(modifyClicked()));
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
||||
KCMRulesList::~KCMRulesList()
|
||||
{
|
||||
for( QVector< Rules* >::Iterator it = rules.begin();
|
||||
it != rules.end();
|
||||
++it )
|
||||
{
|
||||
for (QVector< Rules* >::Iterator it = rules.begin();
|
||||
it != rules.end();
|
||||
++it)
|
||||
delete *it;
|
||||
rules.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void KCMRulesList::activeChanged()
|
||||
{
|
||||
{
|
||||
QListWidgetItem *item = rules_listbox->currentItem();
|
||||
int itemRow = rules_listbox->row(item);
|
||||
|
||||
if( item != NULL ) // make current==selected
|
||||
rules_listbox->setCurrentItem( item, QItemSelectionModel::ClearAndSelect );
|
||||
modify_button->setEnabled( item != NULL );
|
||||
delete_button->setEnabled( item != NULL );
|
||||
moveup_button->setEnabled( item != NULL && itemRow > 0 );
|
||||
movedown_button->setEnabled( item != NULL && itemRow < (rules_listbox->count()-1) );
|
||||
if (item != NULL) {
|
||||
rules_listbox->setCurrentItem(item, QItemSelectionModel::ClearAndSelect);
|
||||
}
|
||||
modify_button->setEnabled(item != NULL);
|
||||
delete_button->setEnabled(item != NULL);
|
||||
moveup_button->setEnabled(item != NULL && itemRow > 0);
|
||||
movedown_button->setEnabled(item != NULL && itemRow < (rules_listbox->count() - 1));
|
||||
}
|
||||
|
||||
void KCMRulesList::newClicked()
|
||||
{
|
||||
{
|
||||
RulesDialog dlg(this);
|
||||
Rules* rule = dlg.edit( NULL, 0, false );
|
||||
if( rule == NULL )
|
||||
Rules* rule = dlg.edit(NULL, 0, false);
|
||||
if (rule == NULL) {
|
||||
return;
|
||||
int pos = rules_listbox->currentRow() + 1;
|
||||
rules_listbox->insertItem( pos , rule->description );
|
||||
rules_listbox->setCurrentRow( pos, QItemSelectionModel::ClearAndSelect );
|
||||
rules.insert( rules.begin() + pos, rule );
|
||||
emit changed( true );
|
||||
}
|
||||
int pos = rules_listbox->currentRow() + 1;
|
||||
rules_listbox->insertItem(pos , rule->description);
|
||||
rules_listbox->setCurrentRow(pos, QItemSelectionModel::ClearAndSelect);
|
||||
rules.insert(rules.begin() + pos, rule);
|
||||
emit changed(true);
|
||||
}
|
||||
|
||||
void KCMRulesList::modifyClicked()
|
||||
{
|
||||
{
|
||||
int pos = rules_listbox->currentRow();
|
||||
if ( pos == -1 )
|
||||
if (pos == -1) {
|
||||
return;
|
||||
}
|
||||
RulesDialog dlg(this);
|
||||
Rules* rule = dlg.edit( rules[ pos ], 0, false );
|
||||
if( rule == rules[ pos ] )
|
||||
Rules* rule = dlg.edit(rules[ pos ], 0, false);
|
||||
if (rule == rules[ pos ]) {
|
||||
return;
|
||||
}
|
||||
delete rules[ pos ];
|
||||
rules[ pos ] = rule;
|
||||
rules_listbox->item(pos)->setText( rule->description );
|
||||
emit changed( true );
|
||||
}
|
||||
rules_listbox->item(pos)->setText(rule->description);
|
||||
emit changed(true);
|
||||
}
|
||||
|
||||
void KCMRulesList::deleteClicked()
|
||||
{
|
||||
{
|
||||
int pos = rules_listbox->currentRow();
|
||||
assert( pos != -1 );
|
||||
delete rules_listbox->takeItem( pos );
|
||||
rules.erase( rules.begin() + pos );
|
||||
emit changed( true );
|
||||
}
|
||||
assert(pos != -1);
|
||||
delete rules_listbox->takeItem(pos);
|
||||
rules.erase(rules.begin() + pos);
|
||||
emit changed(true);
|
||||
}
|
||||
|
||||
void KCMRulesList::moveupClicked()
|
||||
{
|
||||
void KCMRulesList::moveUpClicked()
|
||||
{
|
||||
int pos = rules_listbox->currentRow();
|
||||
assert( pos != -1 );
|
||||
if( pos > 0 )
|
||||
{
|
||||
QListWidgetItem * item = rules_listbox->takeItem( pos );
|
||||
rules_listbox->insertItem( pos - 1 , item );
|
||||
rules_listbox->setCurrentItem( item, QItemSelectionModel::ClearAndSelect );
|
||||
assert(pos != -1);
|
||||
if (pos > 0) {
|
||||
QListWidgetItem * item = rules_listbox->takeItem(pos);
|
||||
rules_listbox->insertItem(pos - 1 , item);
|
||||
rules_listbox->setCurrentItem(item, QItemSelectionModel::ClearAndSelect);
|
||||
Rules* rule = rules[ pos ];
|
||||
rules[ pos ] = rules[ pos - 1 ];
|
||||
rules[ pos - 1 ] = rule;
|
||||
}
|
||||
emit changed( true );
|
||||
}
|
||||
emit changed(true);
|
||||
}
|
||||
|
||||
void KCMRulesList::movedownClicked()
|
||||
{
|
||||
void KCMRulesList::moveDownClicked()
|
||||
{
|
||||
int pos = rules_listbox->currentRow();
|
||||
assert( pos != -1 );
|
||||
if( pos < int( rules_listbox->count()) - 1 )
|
||||
{
|
||||
QListWidgetItem * item = rules_listbox->takeItem( pos );
|
||||
rules_listbox->insertItem( pos + 1 , item );
|
||||
rules_listbox->setCurrentItem( item, QItemSelectionModel::ClearAndSelect );
|
||||
assert(pos != -1);
|
||||
if (pos < int(rules_listbox->count()) - 1) {
|
||||
QListWidgetItem * item = rules_listbox->takeItem(pos);
|
||||
rules_listbox->insertItem(pos + 1 , item);
|
||||
rules_listbox->setCurrentItem(item, QItemSelectionModel::ClearAndSelect);
|
||||
Rules* rule = rules[ pos ];
|
||||
rules[ pos ] = rules[ pos + 1 ];
|
||||
rules[ pos + 1 ] = rule;
|
||||
}
|
||||
emit changed( true );
|
||||
}
|
||||
emit changed(true);
|
||||
}
|
||||
|
||||
void KCMRulesList::load()
|
||||
{
|
||||
{
|
||||
rules_listbox->clear();
|
||||
for( QVector< Rules* >::Iterator it = rules.begin();
|
||||
it != rules.end();
|
||||
++it )
|
||||
for (QVector< Rules* >::Iterator it = rules.begin();
|
||||
it != rules.end();
|
||||
++it)
|
||||
delete *it;
|
||||
rules.clear();
|
||||
KConfig _cfg( "kwinrulesrc" );
|
||||
KConfigGroup cfg(&_cfg, "General" );
|
||||
int count = cfg.readEntry( "count",0 );
|
||||
rules.reserve( count );
|
||||
for( int i = 1;
|
||||
i <= count;
|
||||
++i )
|
||||
{
|
||||
cfg = KConfigGroup(&_cfg,QString::number( i ));
|
||||
Rules* rule = new Rules( cfg );
|
||||
rules.append( rule );
|
||||
rules_listbox->addItem( rule->description );
|
||||
}
|
||||
if( rules.count() > 0 )
|
||||
rules_listbox->setCurrentItem( rules_listbox->item( 0 ));
|
||||
else
|
||||
rules_listbox->setCurrentItem( NULL );
|
||||
activeChanged();
|
||||
KConfig _cfg("kwinrulesrc");
|
||||
KConfigGroup cfg(&_cfg, "General");
|
||||
int count = cfg.readEntry("count", 0);
|
||||
rules.reserve(count);
|
||||
for (int i = 1;
|
||||
i <= count;
|
||||
++i) {
|
||||
cfg = KConfigGroup(&_cfg, QString::number(i));
|
||||
Rules* rule = new Rules(cfg);
|
||||
rules.append(rule);
|
||||
rules_listbox->addItem(rule->description);
|
||||
}
|
||||
if (rules.count() > 0) {
|
||||
rules_listbox->setCurrentItem(rules_listbox->item(0), QItemSelectionModel::ClearAndSelect);
|
||||
} else {
|
||||
rules_listbox->setCurrentItem(NULL);
|
||||
}
|
||||
activeChanged();
|
||||
}
|
||||
|
||||
void KCMRulesList::save()
|
||||
{
|
||||
KConfig cfg( QLatin1String("kwinrulesrc") );
|
||||
{
|
||||
KConfig cfg(QLatin1String("kwinrulesrc"));
|
||||
QStringList groups = cfg.groupList();
|
||||
for( QStringList::ConstIterator it = groups.constBegin();
|
||||
it != groups.constEnd();
|
||||
++it )
|
||||
cfg.deleteGroup( *it );
|
||||
cfg.group("General").writeEntry( "count", rules.count());
|
||||
for (QStringList::ConstIterator it = groups.constBegin();
|
||||
it != groups.constEnd();
|
||||
++it)
|
||||
cfg.deleteGroup(*it);
|
||||
cfg.group("General").writeEntry("count", rules.count());
|
||||
int i = 1;
|
||||
for( QVector< Rules* >::ConstIterator it = rules.constBegin();
|
||||
it != rules.constEnd();
|
||||
++it )
|
||||
{
|
||||
KConfigGroup cg( &cfg, QString::number( i ));
|
||||
(*it)->write( cg );
|
||||
for (QVector< Rules* >::ConstIterator it = rules.constBegin();
|
||||
it != rules.constEnd();
|
||||
++it) {
|
||||
KConfigGroup cg(&cfg, QString::number(i));
|
||||
(*it)->write(cg);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KCMRulesList::defaults()
|
||||
{
|
||||
{
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
*/
|
||||
|
||||
|
||||
#ifndef __RULESLIST_H__
|
||||
#define __RULESLIST_H__
|
||||
#ifndef RULESLIST__H
|
||||
#define RULESLIST__H
|
||||
|
||||
#include "../../rules.h"
|
||||
|
||||
|
@ -28,27 +28,27 @@ namespace KWin
|
|||
{
|
||||
|
||||
class KCMRulesList
|
||||
: public QWidget, Ui_KCMRulesList
|
||||
{
|
||||
: public QWidget, Ui_KCMRulesList
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KCMRulesList( QWidget* parent = NULL );
|
||||
virtual ~KCMRulesList();
|
||||
void load();
|
||||
void save();
|
||||
void defaults();
|
||||
signals:
|
||||
void changed( bool );
|
||||
private slots:
|
||||
void newClicked();
|
||||
void modifyClicked();
|
||||
void deleteClicked();
|
||||
void moveupClicked();
|
||||
void movedownClicked();
|
||||
void activeChanged();
|
||||
private:
|
||||
QVector< Rules* > rules;
|
||||
};
|
||||
public:
|
||||
KCMRulesList(QWidget* parent = NULL);
|
||||
virtual ~KCMRulesList();
|
||||
void load();
|
||||
void save();
|
||||
void defaults();
|
||||
Q_SIGNALS:
|
||||
void changed(bool);
|
||||
private Q_SLOTS:
|
||||
void newClicked();
|
||||
void modifyClicked();
|
||||
void deleteClicked();
|
||||
void moveUpClicked();
|
||||
void moveDownClicked();
|
||||
void activeChanged();
|
||||
private:
|
||||
QVector< Rules* > rules;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
|
|
Loading…
Reference in a new issue