Bug 59514 - JJ: integrate kregexpeditor in the knode regexp input fields
Summary: JJ: integrate kregexpeditor in the knode regexp input fields
Status: RESOLVED FIXED
Alias: None
Product: knode
Classification: Miscellaneous
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR wishlist
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-06-08 15:03 UTC by Shift
Modified: 2004-09-06 23:43 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Shift 2003-06-08 15:03:27 UTC
Version:            (using KDE Devel)
Installed from:    Compiled sources

It will be very cool if knode use the regexpeditor field which call kregexpeditor.

It can be used for "searching of newsgroup" field, "filter" field,... because this field can already contain "regular expression".

Thanks,

Franck
Comment 1 Bram Schoenmakers 2004-09-06 23:43:57 UTC
CVS commit by bram: 

Regexp-editor available for setting up scoring filters.

CCMAIL:59514-done@bugs.kde.org


  M +33 -2     kscoringeditor.cpp   1.43
  M +7 -0      kscoringeditor.h   1.20


--- kdepim/libkdenetwork/kscoringeditor.cpp  #1.42:1.43
@@ -25,4 +25,8 @@
 #include <kcolorcombo.h>
 #include <kiconloader.h>
+#include <kregexpeditorinterface.h>
+#include <ktrader.h>
+#include <kparts/componentfactory.h>
+
 
 #include <qlabel.h>
@@ -36,4 +40,5 @@
 #include <qapplication.h>
 #include <qtimer.h>
+#include <qhbox.h>
 
 // works for both ListBox and ComboBox
@@ -73,9 +78,15 @@ SingleConditionWidget::SingleConditionWi
   QToolTip::add(matches,i18n("Select the type of match"));
   firstRow->addWidget(matches,1);
-  expr = new KLineEdit(this);
+  connect( matches, SIGNAL( activated( int ) ), SLOT( toggleRegExpButton( int ) ) );
+  QHBox *secondRow = new QHBox(this);
+  secondRow->setSpacing( 1 );
+  topL->addWidget( secondRow );
+  expr = new KLineEdit(secondRow);
   QToolTip::add(expr,i18n("The condition for the match"));
   // reserve space for at least 20 characters
   expr->setMinimumWidth(fontMetrics().maxWidth()*20);
-  topL->addWidget(expr);
+  regExpButton = new QPushButton( i18n("Edit..."), secondRow );
+  connect( regExpButton, SIGNAL( clicked() ), SLOT( showRegExpDialog() ) );
+
   // occupy at much width as possible
   setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
@@ -92,4 +103,5 @@ void SingleConditionWidget::setCondition
   headers->setCurrentText( e->getHeader() );
   setCurrentItem(matches,KScoringExpression::getNameForCondition(e->getCondition()));
+  toggleRegExpButton( matches->currentItem() );
   expr->setText(e->getExpression());
 }
@@ -112,4 +124,23 @@ void SingleConditionWidget::clear()
 }
 
+void SingleConditionWidget::toggleRegExpButton( int selected )
+{
+  bool isRegExp = KScoringExpression::MATCH == selected &&
+      !KTrader::self()->query("KRegExpEditor/KRegExpEditor").isEmpty();
+  regExpButton->setEnabled( isRegExp );
+}
+
+void SingleConditionWidget::showRegExpDialog()
+{
+  QDialog *editorDialog = KParts::ComponentFactory::createInstanceFromQuery<QDialog>( "KRegExpEditor/KRegExpEditor" );
+  if ( editorDialog ) {
+    KRegExpEditorInterface *editor = static_cast<KRegExpEditorInterface *>( editorDialog->qt_cast( "KRegExpEditorInterface" ) );
+    Q_ASSERT( editor ); // This should not fail!
+    editor->setRegExp( expr->text() );
+    editorDialog->exec();
+    expr->setText( editor->regExp() );
+  }
+}
+
 //============================================================================
 //

--- kdepim/libkdenetwork/kscoringeditor.h  #1.19:1.20
@@ -57,4 +57,9 @@ public:
   KScoringExpression *createCondition() const;
   void clear();
+
+protected slots:
+  void toggleRegExpButton( int );
+  void showRegExpDialog();
+
 private:
   /** marks a condition as negated */
@@ -66,4 +71,6 @@ private:
   /** the expression which will be matched */
   KLineEdit *expr;
+  /** the button to open the regexp-editor */
+  QPushButton *regExpButton;
 
   KScoringManager *manager;