• 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
rulewidgethandlermanager.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-file-style: "gnu" -*-
2 
3  Copyright (c) 2004 Ingo Kloecker <kloecker@kde.org>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 
19  In addition, as a special exception, the copyright holders give
20  permission to link the code of this program with any edition of
21  the Qt library by Trolltech AS, Norway (or with modified versions
22  of Qt that use the same license as Qt), and distribute linked
23  combinations including the two. You must obey the GNU General
24  Public License in all respects for all of the code used other than
25  Qt. If you modify this file, you may extend this exception to
26  your version of the file, but you are not obligated to do so. If
27  you do not wish to do so, delete this exception statement from
28  your version.
29 */
30 
31 #include "rulewidgethandlermanager.h"
32 #include "textrulerwidgethandler.h"
33 #include "statusrulewidgethandler.h"
34 #include "messagerulewidgethandler.h"
35 #include "numericrulewidgethandler.h"
36 #include "tagrulewidgethandler.h"
37 #include "daterulewidgethandler.h"
38 #include "numericdoublerulewidgethandler.h"
39 #include "headersrulerwidgethandler.h"
40 #include "interfaces/rulewidgethandler.h"
41 
42 #include <messageviewer/viewer/stl_util.h>
43 
44 #include <KDebug>
45 #include <QObject>
46 #include <QStackedWidget>
47 
48 #include "search/searchpattern.h"
49 
50 #include <KLocale>
51 
52 
53 #include <algorithm>
54 using std::for_each;
55 using std::remove;
56 
57 using namespace MailCommon;
58 
59 MailCommon::RuleWidgetHandlerManager *MailCommon::RuleWidgetHandlerManager::self = 0;
60 
61 MailCommon::RuleWidgetHandlerManager::RuleWidgetHandlerManager()
62  : mIsNepomukSearch(false)
63 {
64  registerHandler( new MailCommon::TagRuleWidgetHandler() );
65  registerHandler( new MailCommon::DateRuleWidgetHandler() );
66  registerHandler( new MailCommon::NumericRuleWidgetHandler() );
67  registerHandler( new MailCommon::StatusRuleWidgetHandler() );
68  registerHandler( new MailCommon::MessageRuleWidgetHandler() );
69  registerHandler( new MailCommon::NumericDoubleRuleWidgetHandler() );
70  registerHandler( new MailCommon::HeadersRuleWidgetHandler() );
71  // the TextRuleWidgetHandler is the fallback handler, so it has to be added
72  // as last handler
73  registerHandler( new MailCommon::TextRuleWidgetHandler() );
74 }
75 
76 MailCommon::RuleWidgetHandlerManager::~RuleWidgetHandlerManager()
77 {
78  for_each( mHandlers.begin(), mHandlers.end(),
79  MessageViewer::DeleteAndSetToZero<RuleWidgetHandler>() );
80 }
81 
82 void MailCommon::RuleWidgetHandlerManager::setIsNepomukSearch(bool isNepomukSearch)
83 {
84  mIsNepomukSearch = isNepomukSearch;
85 }
86 
87 void MailCommon::RuleWidgetHandlerManager::registerHandler( const RuleWidgetHandler *handler )
88 {
89  if ( !handler ) {
90  return;
91  }
92  unregisterHandler( handler ); // don't produce duplicates
93  mHandlers.push_back( handler );
94 }
95 
96 void MailCommon::RuleWidgetHandlerManager::unregisterHandler( const RuleWidgetHandler *handler )
97 {
98  // don't delete them, only remove them from the list!
99  mHandlers.erase( remove( mHandlers.begin(), mHandlers.end(), handler ), mHandlers.end() );
100 }
101 
102 namespace {
103 
108 int childCount( const QObject *parent, const QString &objName )
109 {
110  QObjectList list = parent->children();
111  QObject *item;
112  int count = 0;
113  foreach ( item, list ) {
114  if ( item->objectName() == objName ) {
115  count++;
116  }
117  }
118  return count;
119 }
120 
121 }
122 
123 void MailCommon::RuleWidgetHandlerManager::createWidgets(QStackedWidget *functionStack,
124  QStackedWidget *valueStack,
125  const QObject *receiver) const
126 {
127  const_iterator end( mHandlers.constEnd() );
128  for ( const_iterator it = mHandlers.constBegin(); it != end; ++it ) {
129  QWidget *w = 0;
130  for ( int i = 0;
131  ( w = (*it)->createFunctionWidget( i, functionStack, receiver, mIsNepomukSearch ) );
132  ++i ) {
133  if ( childCount( functionStack, w->objectName() ) < 2 ) {
134  // there wasn't already a widget with this name, so add this widget
135  functionStack->addWidget( w );
136  } else {
137  // there was already a widget with this name, so discard this widget
138  delete w;
139  w = 0;
140  }
141  }
142  for ( int i = 0;
143  ( w = (*it)->createValueWidget( i, valueStack, receiver ) );
144  ++i ) {
145  if ( childCount( valueStack, w->objectName() ) < 2 ) {
146  // there wasn't already a widget with this name, so add this widget
147  valueStack->addWidget( w );
148  } else {
149  // there was already a widget with this name, so discard this widget
150  delete w;
151  w = 0;
152  }
153  }
154  }
155 }
156 
157 SearchRule::Function MailCommon::RuleWidgetHandlerManager::function(
158  const QByteArray &field, const QStackedWidget *functionStack ) const
159 {
160  const_iterator end( mHandlers.constEnd() );
161  for ( const_iterator it = mHandlers.constBegin(); it != end; ++it ) {
162  const SearchRule::Function func = (*it)->function( field, functionStack );
163  if ( func != SearchRule::FuncNone ) {
164  return func;
165  }
166  }
167  return SearchRule::FuncNone;
168 }
169 
170 QString MailCommon::RuleWidgetHandlerManager::value( const QByteArray &field,
171  const QStackedWidget *functionStack,
172  const QStackedWidget *valueStack ) const
173 {
174  const_iterator end( mHandlers.constEnd() );
175  for ( const_iterator it = mHandlers.constBegin(); it != end; ++it ) {
176  const QString val = (*it)->value( field, functionStack, valueStack );
177  if ( !val.isEmpty() ) {
178  return val;
179  }
180  }
181  return QString();
182 }
183 
184 QString MailCommon::RuleWidgetHandlerManager::prettyValue( const QByteArray &field,
185  const QStackedWidget *functionStack,
186  const QStackedWidget *valueStack ) const
187 {
188  const_iterator end( mHandlers.constEnd() );
189  for ( const_iterator it = mHandlers.constBegin(); it != end; ++it ) {
190  const QString val = (*it)->prettyValue( field, functionStack, valueStack );
191  if ( !val.isEmpty() ) {
192  return val;
193  }
194  }
195  return QString();
196 }
197 
198 void MailCommon::RuleWidgetHandlerManager::reset( QStackedWidget *functionStack,
199  QStackedWidget *valueStack ) const
200 {
201  const_iterator end( mHandlers.constEnd() );
202  for ( const_iterator it = mHandlers.constBegin(); it != end; ++it ) {
203  (*it)->reset( functionStack, valueStack );
204  }
205  update( "", functionStack, valueStack );
206 }
207 
208 void MailCommon::RuleWidgetHandlerManager::setRule( QStackedWidget *functionStack,
209  QStackedWidget *valueStack,
210  const SearchRule::Ptr rule ) const
211 {
212  Q_ASSERT( rule );
213  reset( functionStack, valueStack );
214  const_iterator end( mHandlers.constEnd() );
215  for ( const_iterator it = mHandlers.constBegin(); it != end; ++it ) {
216  if ( (*it)->setRule( functionStack, valueStack, rule, mIsNepomukSearch ) ) {
217  return;
218  }
219  }
220 }
221 
222 void MailCommon::RuleWidgetHandlerManager::update( const QByteArray &field,
223  QStackedWidget *functionStack,
224  QStackedWidget *valueStack ) const
225 {
226  const_iterator end( mHandlers.constEnd() );
227  for ( const_iterator it = mHandlers.constBegin(); it != end; ++it ) {
228  if ( (*it)->update( field, functionStack, valueStack ) ) {
229  return;
230  }
231  }
232 }
rulewidgethandlermanager.h
numericdoublerulewidgethandler.h
MailCommon::RuleWidgetHandlerManager::createWidgets
void createWidgets(QStackedWidget *functionStack, QStackedWidget *valueStack, const QObject *receiver) const
Definition: rulewidgethandlermanager.cpp:123
MailCommon::RuleWidgetHandlerManager::function
MailCommon::SearchRule::Function function(const QByteArray &field, const QStackedWidget *functionStack) const
Definition: rulewidgethandlermanager.cpp:157
MailCommon::RuleWidgetHandlerManager::unregisterHandler
void unregisterHandler(const RuleWidgetHandler *handler)
Definition: rulewidgethandlermanager.cpp:96
messagerulewidgethandler.h
MailCommon::MessageRuleWidgetHandler
Definition: messagerulewidgethandler.h:24
MailCommon::DateRuleWidgetHandler
Definition: daterulewidgethandler.h:25
QWidget
MailCommon::RuleWidgetHandlerManager::~RuleWidgetHandlerManager
~RuleWidgetHandlerManager()
Definition: rulewidgethandlermanager.cpp:76
MailCommon::RuleWidgetHandlerManager::setRule
void setRule(QStackedWidget *functionStack, QStackedWidget *valueStack, const MailCommon::SearchRule::Ptr rule) const
Definition: rulewidgethandlermanager.cpp:208
MailCommon::RuleWidgetHandlerManager::setIsNepomukSearch
void setIsNepomukSearch(bool isNepomukSearch)
Definition: rulewidgethandlermanager.cpp:82
MailCommon::SearchRule::Ptr
boost::shared_ptr< SearchRule > Ptr
Defines a pointer to a search rule.
Definition: searchpattern.h:69
MailCommon::RuleWidgetHandlerManager
Singleton to manage the list of RuleWidgetHandlers.
Definition: rulewidgethandlermanager.h:50
QObject
MailCommon::RuleWidgetHandlerManager::value
QString value(const QByteArray &field, const QStackedWidget *functionStack, const QStackedWidget *valueStack) const
Definition: rulewidgethandlermanager.cpp:170
daterulewidgethandler.h
numericrulewidgethandler.h
MailCommon::SearchRule::Function
Function
Describes operators for comparison of field and contents.
Definition: searchpattern.h:80
statusrulewidgethandler.h
textrulerwidgethandler.h
MailCommon::SearchRule::FuncNone
Definition: searchpattern.h:81
MailCommon::StatusRuleWidgetHandler
Definition: statusrulewidgethandler.h:24
MailCommon::RuleWidgetHandlerManager::reset
void reset(QStackedWidget *functionStack, QStackedWidget *valueStack) const
Definition: rulewidgethandlermanager.cpp:198
searchpattern.h
MailCommon::RuleWidgetHandlerManager::prettyValue
QString prettyValue(const QByteArray &field, const QStackedWidget *functionStack, const QStackedWidget *valueStack) const
Definition: rulewidgethandlermanager.cpp:184
MailCommon::RuleWidgetHandlerManager::update
void update(const QByteArray &field, QStackedWidget *functionStack, QStackedWidget *valueStack) const
Definition: rulewidgethandlermanager.cpp:222
tagrulewidgethandler.h
MailCommon::TagRuleWidgetHandler
Definition: tagrulewidgethandler.h:24
MailCommon::HeadersRuleWidgetHandler
Definition: headersrulerwidgethandler.h:24
MailCommon::RuleWidgetHandler
An interface to filter/search rule widget handlers.
Definition: rulewidgethandler.h:49
MailCommon::NumericRuleWidgetHandler
Definition: numericrulewidgethandler.h:7
MailCommon::NumericDoubleRuleWidgetHandler
Definition: numericdoublerulewidgethandler.h:25
rulewidgethandler.h
headersrulerwidgethandler.h
MailCommon::RuleWidgetHandlerManager::registerHandler
void registerHandler(const RuleWidgetHandler *handler)
Definition: rulewidgethandlermanager.cpp:87
MailCommon::TextRuleWidgetHandler
Definition: textrulerwidgethandler.h:24
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