Bug 74731 - Allow reordering of filtering rules
Summary: Allow reordering of filtering rules
Status: RESOLVED FIXED
Alias: None
Product: knode
Classification: Unmaintained
Component: general (show other bugs)
Version: unspecified
Platform: Debian testing Linux
: NOR wishlist
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
: 100121 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-02-09 18:33 UTC by Dominique Devriese
Modified: 2005-07-17 14:40 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dominique Devriese 2004-02-09 18:33:28 UTC
Version:            (using KDE KDE 3.1.5)
Installed from:    Debian testing/unstable Packages

Hi,

This is a forward of the following Debian bug report:
http://bugs.debian.org/230490

Currently it's not possible to reorder scoring rules from within the
scooring rules edit dialog.

As rules are applied in the order in which they appear in the scoring
file, this is missing functionality, and grossly affects scoring
utility.

It's not clear whether or not external edits to the scoreing file can be
made while a Knode session is open.  Currently the only safe workaround
is to exit Knode, edit the scorefile manually, and restart the
application.

thanks
domi
Comment 1 Volker Krause 2005-02-24 10:14:39 UTC
*** Bug 100121 has been marked as a duplicate of this bug. ***
Comment 2 Volker Krause 2005-07-17 14:40:38 UTC
SVN commit 435558 by vkrause:

Allow to reorder scoring rules.

FEATURE: 74731


 M  +24 -0     kscoring.cpp  
 M  +2 -0      kscoring.h  
 M  +55 -4     kscoringeditor.cpp  
 M  +5 -0      kscoringeditor.h  


--- trunk/KDE/kdepim/libkdepim/kscoring.cpp #435557:435558
@@ -984,6 +984,30 @@
   delete edit;
 }
 
+void KScoringManager::moveRuleAbove( KScoringRule *above, KScoringRule *below )
+{
+  int aindex = allRules.findRef( above );
+  int bindex = allRules.findRef( below );
+  if ( aindex <= 0 || bindex < 0 )
+    return;
+  if ( aindex < bindex )
+    --bindex;
+  allRules.take( aindex );
+  allRules.insert( bindex, above );
+}
+
+void KScoringManager::moveRuleBelow( KScoringRule *below, KScoringRule *above )
+{
+  int bindex = allRules.findRef( below );
+  int aindex = allRules.findRef( above );
+  if ( bindex < 0 || bindex >= (int)allRules.count() - 1 || aindex < 0 )
+    return;
+  if ( bindex < aindex )
+    --aindex;
+  allRules.take( bindex );
+  allRules.insert( aindex + 1, below );
+}
+
 void KScoringManager::editorReady()
 {
   kdDebug(5100) << "emitting signal finishedEditing" << endl;
--- trunk/KDE/kdepim/libkdepim/kscoring.h #435557:435558
@@ -328,6 +328,8 @@
   void deleteRule(KScoringRule *);
   void editRule(KScoringRule *e, QWidget *w=0);
   KScoringRule* copyRule(KScoringRule *);
+  void moveRuleAbove( KScoringRule *above, KScoringRule *below );
+  void moveRuleBelow( KScoringRule *below, KScoringRule *above );
   void setGroup(const QString& g);
   // has to be called after setGroup() or initCache()
   bool hasRulesForCurrentGroup();
--- trunk/KDE/kdepim/libkdepim/kscoringeditor.cpp #435557:435558
@@ -593,9 +593,20 @@
   connect(ruleList, SIGNAL(currentChanged(QListBoxItem*)),
           this, SLOT(slotRuleSelected(QListBoxItem*)));
   topL->addWidget(ruleList);
-  updateRuleList();
-  QHBoxLayout *btnL = new QHBoxLayout(topL,KDialog::spacingHint());
 
+  QHBoxLayout *btnL = new QHBoxLayout( topL, KDialog::spacingHint() );
+  mRuleUp = new QPushButton( this );
+  mRuleUp->setPixmap( BarIcon( "up", KIcon::SizeSmall ) );
+  QToolTip::add( mRuleUp, i18n("Move rule up") );
+  btnL->addWidget( mRuleUp );
+  connect( mRuleUp, SIGNAL( clicked() ), SLOT( slotRuleUp() ) );
+  mRuleDown = new QPushButton( this );
+  mRuleDown->setPixmap( BarIcon( "down", KIcon::SizeSmall ) );
+  QToolTip::add( mRuleDown, i18n("Move rule down") );
+  btnL->addWidget( mRuleDown );
+  connect( mRuleDown, SIGNAL( clicked() ), SLOT( slotRuleDown() ) );
+
+  btnL = new QHBoxLayout( topL, KDialog::spacingHint() );
   editRule=0L;
   newRule = new QPushButton(this);
   newRule->setPixmap( BarIcon( "filenew", KIcon::SizeSmall ) );
@@ -639,6 +650,8 @@
           this,SLOT(updateRuleList()));
   connect(manager,SIGNAL(changedRuleName(const QString&,const QString&)),
           this,SLOT(slotRuleNameChanged(const QString&,const QString&)));
+
+  updateRuleList();
   updateButton();
 }
 
@@ -648,11 +661,17 @@
 
 void RuleListWidget::updateButton()
 {
-  bool state=ruleList->count()>0;
+  bool state = ruleList->count() > 0;
   if(editRule)
     editRule->setEnabled(state);
   delRule->setEnabled(state);
   copyRule->setEnabled(state);
+
+  QListBoxItem *item = ruleList->item( ruleList->currentItem() );
+  if ( item ) {
+    mRuleUp->setEnabled( item->prev() != 0 );
+    mRuleDown->setEnabled( item->next() != 0 );
+  }
 }
 
 void RuleListWidget::updateRuleList()
@@ -731,6 +750,7 @@
   if (ruleName != ruleList->currentText()) {
     setCurrentItem(ruleList,ruleName);
   }
+  updateButton();
   emit ruleSelected(ruleName);
 }
 
@@ -747,7 +767,6 @@
   if (idx >= ruleList->count()) return;
   QString ruleName = ruleList->text(index);
   slotRuleSelected(ruleName);
-  updateButton();
 }
 
 void RuleListWidget::slotNewRule()
@@ -782,6 +801,38 @@
   updateButton();
 }
 
+void RuleListWidget::slotRuleUp()
+{
+  KScoringRule *rule = 0, *below = 0;
+  QListBoxItem *item = ruleList->item( ruleList->currentItem() );
+  if ( item ) {
+    rule = manager->findRule( item->text() );
+    item = item->prev();
+    if ( item )
+      below = manager->findRule( item->text() );
+  }
+  if ( rule && below )
+    manager->moveRuleAbove( rule, below );
+  updateRuleList();
+  updateButton();
+}
+
+void RuleListWidget::slotRuleDown()
+{
+  KScoringRule *rule = 0, *above = 0;
+  QListBoxItem *item = ruleList->item( ruleList->currentItem() );
+  if ( item ) {
+    rule = manager->findRule( item->text() );
+    item = item->next();
+    if ( item )
+      above = manager->findRule( item->text() );
+  }
+  if ( rule && above )
+    manager->moveRuleBelow( rule, above );
+  updateRuleList();
+  updateButton();
+}
+
 //============================================================================
 //
 // class KScoringEditor (the score edit dialog)
--- trunk/KDE/kdepim/libkdepim/kscoringeditor.h #435557:435558
@@ -221,6 +221,9 @@
   void slotDelRule();
   void slotNewRule();
   void slotCopyRule();
+  void slotRuleUp();
+  void slotRuleDown();
+
 private:
   /** the list of rules */
   KListBox *ruleList;
@@ -235,6 +238,8 @@
   QPushButton *newRule;
   QPushButton *delRule;
   QPushButton *copyRule;
+  QPushButton *mRuleUp;
+  QPushButton *mRuleDown;
 };
 
 class KDE_EXPORT KScoringEditor : public KDialogBase