• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

mailcommon

  • sources
  • kde-4.12
  • kdepim
  • mailcommon
  • search
textrulerwidgethandler.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "textrulerwidgethandler.h"
19 #include <pimcommon/widgets/minimumcombobox.h>
20 
21 #include "search/searchpattern.h"
22 #include "widgets/regexplineedit.h"
23 using MailCommon::RegExpLineEdit;
24 
25 #include <KDebug>
26 #include <KLocale>
27 
28 #include <QLineEdit>
29 #include <QStackedWidget>
30 
31 
32 using namespace MailCommon;
33 
34 #include <QLabel>
35 
36 // also see SearchRule::matches() and SearchRule::Function
37 // if you change the following strings!
38 static const struct {
39  SearchRule::Function id;
40  const char *displayName;
41 } TextFunctions[] = {
42  { SearchRule::FuncContains, I18N_NOOP( "contains" ) },
43  { SearchRule::FuncContainsNot, I18N_NOOP( "does not contain" ) },
44  { SearchRule::FuncEquals, I18N_NOOP( "equals" ) },
45  { SearchRule::FuncNotEqual, I18N_NOOP( "does not equal" ) },
46  { SearchRule::FuncStartWith, I18N_NOOP( "starts with" ) },
47  { SearchRule::FuncNotStartWith, I18N_NOOP( "does not start with" )},
48  { SearchRule::FuncEndWith, I18N_NOOP( "ends with" ) },
49  { SearchRule::FuncNotEndWith, I18N_NOOP( "does not end with" ) },
50 
51  { SearchRule::FuncRegExp, I18N_NOOP( "matches regular expr." ) },
52  { SearchRule::FuncNotRegExp, I18N_NOOP( "does not match reg. expr." ) }
53 };
54 static const int TextFunctionCount =
55  sizeof( TextFunctions ) / sizeof( *TextFunctions );
56 
57 //---------------------------------------------------------------------------
58 
59 QWidget *TextRuleWidgetHandler::createFunctionWidget(
60  int number, QStackedWidget *functionStack, const QObject *receiver, bool /*isNepomukSearch*/ ) const
61 {
62  if ( number != 0 ) {
63  return 0;
64  }
65 
66  PimCommon::MinimumComboBox *funcCombo = new PimCommon::MinimumComboBox( functionStack );
67  funcCombo->setObjectName( QLatin1String("textRuleFuncCombo") );
68  for ( int i = 0; i < TextFunctionCount; ++i ) {
69  funcCombo->addItem( i18n( TextFunctions[i].displayName ) );
70  }
71  funcCombo->adjustSize();
72  QObject::connect( funcCombo, SIGNAL(activated(int)),
73  receiver, SLOT(slotFunctionChanged()) );
74  return funcCombo;
75 }
76 
77 //---------------------------------------------------------------------------
78 
79 QWidget *TextRuleWidgetHandler::createValueWidget( int number,
80  QStackedWidget *valueStack,
81  const QObject *receiver ) const
82 {
83  if ( number == 0 ) {
84  RegExpLineEdit *lineEdit = new RegExpLineEdit( valueStack );
85  lineEdit->setObjectName( QLatin1String("regExpLineEdit") );
86  QObject::connect( lineEdit, SIGNAL(textChanged(QString)),
87  receiver, SLOT(slotValueChanged()) );
88  QObject::connect( lineEdit, SIGNAL(returnPressed()),
89  receiver, SLOT(slotReturnPressed()) );
90  return lineEdit;
91  }
92 
93  // blank QLabel to hide value widget for in-address-book rule
94  if ( number == 1 ) {
95  QLabel *label = new QLabel( valueStack );
96  label->setObjectName( QLatin1String("textRuleValueHider") );
97  label->setBuddy( valueStack );
98  return label;
99  }
100  return 0;
101 }
102 
103 //---------------------------------------------------------------------------
104 
105 SearchRule::Function TextRuleWidgetHandler::currentFunction(
106  const QStackedWidget *functionStack ) const
107 {
108  const PimCommon::MinimumComboBox *funcCombo =
109  functionStack->findChild<PimCommon::MinimumComboBox*>( QLatin1String( "textRuleFuncCombo" ) );
110 
111  if ( funcCombo && funcCombo->currentIndex() >= 0 ) {
112  return TextFunctions[funcCombo->currentIndex()].id;
113  }
114 
115  return SearchRule::FuncNone;
116 }
117 
118 //---------------------------------------------------------------------------
119 
120 SearchRule::Function TextRuleWidgetHandler::function( const QByteArray &,
121  const QStackedWidget *functionStack ) const
122 {
123  return currentFunction( functionStack );
124 }
125 
126 //---------------------------------------------------------------------------
127 
128 QString TextRuleWidgetHandler::currentValue( const QStackedWidget *valueStack,
129  SearchRule::Function ) const
130 {
131  //in other cases of func it is a lineedit
132  const RegExpLineEdit *lineEdit = valueStack->findChild<RegExpLineEdit*>( QLatin1String("regExpLineEdit") );
133 
134  if ( lineEdit ) {
135  return lineEdit->text();
136  }
137 
138  // or anything else, like addressbook
139  return QString();
140 }
141 
142 //---------------------------------------------------------------------------
143 
144 QString TextRuleWidgetHandler::value( const QByteArray &,
145  const QStackedWidget *functionStack,
146  const QStackedWidget *valueStack ) const
147 {
148  SearchRule::Function func = currentFunction( functionStack );
149  return currentValue( valueStack, func );
150 }
151 
152 //---------------------------------------------------------------------------
153 
154 QString TextRuleWidgetHandler::prettyValue( const QByteArray &,
155  const QStackedWidget *functionStack,
156  const QStackedWidget *valueStack ) const
157 {
158  SearchRule::Function func = currentFunction( functionStack );
159  return currentValue( valueStack, func );
160 }
161 
162 //---------------------------------------------------------------------------
163 
164 bool TextRuleWidgetHandler::handlesField( const QByteArray & ) const
165 {
166  return true; // we handle all fields (as fallback)
167 }
168 
169 //---------------------------------------------------------------------------
170 
171 void TextRuleWidgetHandler::reset( QStackedWidget *functionStack,
172  QStackedWidget *valueStack ) const
173 {
174  // reset the function combo box
175  PimCommon::MinimumComboBox *funcCombo = functionStack->findChild<PimCommon::MinimumComboBox*>( QLatin1String("textRuleFuncCombo") );
176 
177  if ( funcCombo ) {
178  funcCombo->blockSignals( true );
179  funcCombo->setCurrentIndex( 0 );
180  funcCombo->blockSignals( false );
181  }
182 
183  // reset the value widget
184  RegExpLineEdit *lineEdit = valueStack->findChild<RegExpLineEdit*>( QLatin1String("regExpLineEdit") );
185  if ( lineEdit ) {
186  lineEdit->blockSignals( true );
187  lineEdit->clear();
188  lineEdit->blockSignals( false );
189  lineEdit->showEditButton( false );
190  valueStack->setCurrentWidget( lineEdit );
191  }
192 }
193 
194 //---------------------------------------------------------------------------
195 
196 bool TextRuleWidgetHandler::setRule( QStackedWidget *functionStack,
197  QStackedWidget *valueStack,
198  const SearchRule::Ptr rule, bool /*isNepomukSearch*/ ) const
199 {
200  if ( !rule ) {
201  reset( functionStack, valueStack );
202  return false;
203  }
204 
205  const SearchRule::Function func = rule->function();
206  int i = 0;
207  for ( ; i < TextFunctionCount; ++i ) {
208  if ( func == TextFunctions[i].id ) {
209  break;
210  }
211  }
212 
213  PimCommon::MinimumComboBox *funcCombo = functionStack->findChild<PimCommon::MinimumComboBox*>( QLatin1String("textRuleFuncCombo") );
214 
215  if ( funcCombo ) {
216  funcCombo->blockSignals( true );
217  if ( i < TextFunctionCount ) {
218  funcCombo->setCurrentIndex( i );
219  } else {
220  funcCombo->setCurrentIndex( 0 );
221  }
222  funcCombo->blockSignals( false );
223  functionStack->setCurrentWidget( funcCombo );
224  }
225  RegExpLineEdit *lineEdit =
226  valueStack->findChild<RegExpLineEdit*>( QLatin1String("regExpLineEdit") );
227 
228  if ( lineEdit ) {
229  lineEdit->blockSignals( true );
230  lineEdit->setText( rule->contents() );
231  lineEdit->blockSignals( false );
232  lineEdit->showEditButton( func == SearchRule::FuncRegExp ||
233  func == SearchRule::FuncNotRegExp );
234  valueStack->setCurrentWidget( lineEdit );
235  }
236  return true;
237 }
238 
239 //---------------------------------------------------------------------------
240 
241 bool TextRuleWidgetHandler::update( const QByteArray &,
242  QStackedWidget *functionStack,
243  QStackedWidget *valueStack ) const
244 {
245  // raise the correct function widget
246  functionStack->setCurrentWidget( functionStack->findChild<QWidget*>( QLatin1String("textRuleFuncCombo") ) );
247 
248  // raise the correct value widget
249  SearchRule::Function func = currentFunction( functionStack );
250  if ( func == SearchRule::FuncIsInAddressbook ||
251  func == SearchRule::FuncIsNotInAddressbook ) {
252  valueStack->setCurrentWidget( valueStack->findChild<QWidget*>( QLatin1String("textRuleValueHider") ) );
253  } else {
254  RegExpLineEdit *lineEdit =
255  valueStack->findChild<RegExpLineEdit*>( QLatin1String("regExpLineEdit") );
256 
257  if ( lineEdit ) {
258  lineEdit->showEditButton( func == SearchRule::FuncRegExp ||
259  func == SearchRule::FuncNotRegExp );
260  valueStack->setCurrentWidget( lineEdit );
261  }
262  }
263  return true;
264 }
265 
MailCommon::SearchRule::FuncIsInAddressbook
Definition: searchpattern.h:92
MailCommon::SearchRule::FuncEndWith
Definition: searchpattern.h:100
MailCommon::SearchRule::FuncNotEndWith
Definition: searchpattern.h:101
MailCommon::TextRuleWidgetHandler::createFunctionWidget
QWidget * createFunctionWidget(int number, QStackedWidget *functionStack, const QObject *receiver, bool isNepomukSearch) const
Definition: textrulerwidgethandler.cpp:59
MailCommon::TextRuleWidgetHandler::prettyValue
QString prettyValue(const QByteArray &field, const QStackedWidget *functionStack, const QStackedWidget *valueStack) const
Definition: textrulerwidgethandler.cpp:154
MailCommon::SearchRule::FuncContainsNot
Definition: searchpattern.h:83
MailCommon::SearchRule::FuncIsNotInAddressbook
Definition: searchpattern.h:93
TextFunctionCount
static const int TextFunctionCount
Definition: textrulerwidgethandler.cpp:54
MailCommon::RegExpLineEdit::setText
void setText(const QString &)
Definition: regexplineedit.cpp:102
MailCommon::SearchRule::FuncNotStartWith
Definition: searchpattern.h:99
QWidget
MailCommon::RegExpLineEdit
Definition: regexplineedit.h:46
MailCommon::RegExpLineEdit::clear
void clear()
Definition: regexplineedit.cpp:92
MailCommon::SearchRule::Ptr
boost::shared_ptr< SearchRule > Ptr
Defines a pointer to a search rule.
Definition: searchpattern.h:69
QObject
MailCommon::SearchRule::FuncStartWith
Definition: searchpattern.h:98
MailCommon::SearchRule::FuncNotRegExp
Definition: searchpattern.h:87
MailCommon::SearchRule::Function
Function
Describes operators for comparison of field and contents.
Definition: searchpattern.h:80
MailCommon::SearchRule::FuncNotEqual
Definition: searchpattern.h:85
MailCommon::TextRuleWidgetHandler::createValueWidget
QWidget * createValueWidget(int number, QStackedWidget *valueStack, const QObject *receiver) const
Definition: textrulerwidgethandler.cpp:79
MailCommon::TextRuleWidgetHandler::setRule
bool setRule(QStackedWidget *functionStack, QStackedWidget *valueStack, const SearchRule::Ptr rule, bool isNepomukSearch) const
Definition: textrulerwidgethandler.cpp:196
MailCommon::TextRuleWidgetHandler::update
bool update(const QByteArray &field, QStackedWidget *functionStack, QStackedWidget *valueStack) const
Definition: textrulerwidgethandler.cpp:241
textrulerwidgethandler.h
TextFunctions
static const struct @10 TextFunctions[]
MailCommon::SearchRule::FuncNone
Definition: searchpattern.h:81
MailCommon::TextRuleWidgetHandler::function
SearchRule::Function function(const QByteArray &field, const QStackedWidget *functionStack) const
Definition: textrulerwidgethandler.cpp:120
id
SearchRule::Function id
Definition: textrulerwidgethandler.cpp:39
MailCommon::SearchRule::FuncRegExp
Definition: searchpattern.h:86
searchpattern.h
displayName
const char * displayName
Definition: textrulerwidgethandler.cpp:40
regexplineedit.h
MailCommon::SearchRule::FuncContains
Definition: searchpattern.h:82
I18N_NOOP
#define I18N_NOOP(t)
Definition: searchpatternedit.cpp:46
MailCommon::TextRuleWidgetHandler::value
QString value(const QByteArray &field, const QStackedWidget *functionStack, const QStackedWidget *valueStack) const
Definition: textrulerwidgethandler.cpp:144
MailCommon::RegExpLineEdit::showEditButton
void showEditButton(bool)
Definition: regexplineedit.cpp:107
MailCommon::TextRuleWidgetHandler::reset
void reset(QStackedWidget *functionStack, QStackedWidget *valueStack) const
Definition: textrulerwidgethandler.cpp:171
MailCommon::SearchRule::FuncEquals
Definition: searchpattern.h:84
MailCommon::RegExpLineEdit::text
QString text() const
Definition: regexplineedit.cpp:97
MailCommon::TextRuleWidgetHandler::handlesField
bool handlesField(const QByteArray &field) const
Definition: textrulerwidgethandler.cpp:164
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:15 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

mailcommon

Skip menu "mailcommon"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal