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

messagelist

  • sources
  • kde-4.12
  • kdepim
  • messagelist
  • core
item_p.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Copyright 2008 Szymon Tomasz Stefanek <pragma@kvirc.net>
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,
11  * but 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
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  *******************************************************************************/
20 
21 #ifndef __MESSAGELIST_CORE_ITEM_P_H__
22 #define __MESSAGELIST_CORE_ITEM_P_H__
23 
24 #include "core/item.h"
25 
26 #include "messagecore/utils/stringutil.h"
27 
28 // See the MessageList::ItemPrivate::insertChildItem() function below for an explaination of this macro.
29 #if __GNUC__ >= 3 //krazy:exclude=cpp
30  #define GCC_DONT_INLINE_THIS __attribute__((noinline))
31 #else
32  #define GCC_DONT_INLINE_THIS
33 #endif
34 
35 namespace MessageList
36 {
37 
38 namespace Core
39 {
40 
41 class ItemPrivate
42 {
43 public:
44  explicit ItemPrivate( Item *owner )
45  : q( owner ),
46  mChildItems( 0 ),
47  mParent( 0 ),
48  mThisItemIndexGuess( 0 ),
49  mInitialExpandStatus( Item::NoExpandNeeded ),
50  mIsViewable( false ),
51  mUseReceiver( false )
52  {
53  }
54  virtual ~ItemPrivate() {}
55 
92  template< class ItemComparator, bool bAscending > int GCC_DONT_INLINE_THIS insertChildItem( Model *model, Item *child )
93  {
94  if ( !mChildItems )
95  return q->appendChildItem( model, child );
96 
97  int cnt = mChildItems->count();
98  if ( cnt < 1 )
99  return q->appendChildItem( model, child );
100 
101  int idx;
102  Item * pivot;
103 
104  if ( bAscending )
105  {
106  pivot = mChildItems->at( cnt - 1 );
107 
108  if ( ItemComparator::firstGreaterOrEqual( child, pivot ) ) // gcc: <-- inline this instead, thnx
109  return q->appendChildItem( model, child ); // this is very likely in date based comparisons (FIXME: not in other ones)
110 
111  // Binary search based insertion
112  int l = 0;
113  int h = cnt - 1;
114 
115  for(;;)
116  {
117  idx = (l + h) / 2;
118  pivot = mChildItems->at( idx );
119  if ( ItemComparator::firstGreaterOrEqual( pivot, child ) ) // gcc: <-- inline this instead, thnx
120  {
121  if ( l < h )
122  h = idx - 1;
123  else
124  break;
125  } else {
126  if ( l < h )
127  l = idx + 1;
128  else {
129  idx++;
130  break;
131  }
132  }
133  }
134  } else {
135 
136  pivot = mChildItems->at( 0 );
137  if ( ItemComparator::firstGreaterOrEqual( child, pivot ) ) // gcc: <-- inline this instead, thnx
138  idx = 0; // this is very likely in date based comparisons (FIXME: not in other ones)
139  else {
140 
141  // Binary search based insertion
142  int l = 0;
143  int h = cnt - 1;
144 
145  for(;;)
146  {
147  idx = (l + h) / 2;
148  pivot = mChildItems->at( idx );
149  if ( ItemComparator::firstGreaterOrEqual( child, pivot ) ) // gcc: <-- inline this instead, thnx
150  {
151  if ( l < h )
152  h = idx - 1;
153  else
154  break;
155  } else {
156  if ( l < h )
157  l = idx + 1;
158  else {
159  idx++;
160  break;
161  }
162  }
163  }
164  }
165  }
166 
167  Q_ASSERT( idx >= 0 );
168  Q_ASSERT( idx <= mChildItems->count() );
169 
170  if ( mIsViewable && model )
171  model->beginInsertRows( model->index( q, 0 ), idx, idx ); // BLEAH :D
172 
173  mChildItems->insert( idx, child );
174  child->setIndexGuess( idx );
175  if ( mIsViewable )
176  {
177  if ( model )
178  model->endInsertRows(); // BLEAH :D
179  child->setViewable( model, true );
180  }
181 
182  return idx;
183  }
184 
191  template< class ItemComparator, bool bAscending > bool childItemNeedsReSorting( Item * child )
192  {
193  if ( !mChildItems )
194  return false; // not my child! (ugh... should assert ?)
195 
196  const int idx = q->indexOfChildItem(child);
197 
198  if ( idx > 0 )
199  {
200  Item * prev = mChildItems->at( idx - 1 );
201  if ( bAscending )
202  {
203  // child must be greater or equal to the previous item
204  if ( !ItemComparator::firstGreaterOrEqual( child, prev ) )
205  return true; // wrong order: needs re-sorting
206  } else {
207  // previous must be greater or equal to the child item
208  if ( !ItemComparator::firstGreaterOrEqual( prev, child ) )
209  return true; // wrong order: needs re-sorting
210  }
211  }
212 
213  if ( idx < ( mChildItems->count() - 1 ) )
214  {
215  Item * next = mChildItems->at( idx + 1 );
216  if ( bAscending )
217  {
218  // next must be greater or equal to child
219  if ( !ItemComparator::firstGreaterOrEqual( next, child ) )
220  return true; // wrong order: needs re-sorting
221  } else {
222  // child must be greater or equal to next
223  if ( !ItemComparator::firstGreaterOrEqual( child, next ) )
224  return true; // wrong order: needs re-sorting
225  }
226  }
227 
228  return false;
229  }
230 
234  void childItemDead( Item * child );
235 
236  Item * const q;
237 
238  QList< Item * > *mChildItems;
239  Item * mParent;
240  time_t mMaxDate;
241  time_t mDate;
242  size_t mSize;
243  QString mSender;
244  QString mReceiver;
245  int mThisItemIndexGuess;
246  QString mSubject;
247  Akonadi::MessageStatus mStatus;
248  qint64 mItemId;
249  Item::Type mType : 4;
250  Item::InitialExpandStatus mInitialExpandStatus : 4;
251  bool mIsViewable : 1;
252  bool mUseReceiver : 1;
253 };
254 
259 class ItemSizeComparator
260 {
261 public:
262  static inline bool firstGreaterOrEqual( Item * first, Item * second )
263  {
264  if ( first->size() < second->size() )
265  return false;
266  // When the sizes are equal compare by date too
267  if ( first->size() == second->size() )
268  return first->date() >= second->date();
269  return true;
270  }
271 };
272 
277 class ItemDateComparator
278 {
279 public:
280  static inline bool firstGreaterOrEqual( Item * first, Item * second )
281  {
282  // When the dates are equal compare by subject too
283  // This is useful, for example, in kernel mailing list where people
284  // send out multiple messages with patch parts at exactly the same time.
285  if ( first->date() == second->date() )
286  return first->subject() >= second->subject();
287  if ( first->date() == static_cast<uint>( -1 ) ) // invalid is always smaller
288  return false;
289  if ( second->date() == static_cast<uint>( -1 ) )
290  return true;
291  if ( first->date() < second->date() )
292  return false;
293  return true;
294  }
295 };
296 
301 class ItemMaxDateComparator
302 {
303 public:
304  static inline bool firstGreaterOrEqual( Item * first, Item * second )
305  {
306  if ( first->maxDate() < second->maxDate() )
307  return false;
308  if ( first->maxDate() == second->maxDate() )
309  return first->subject() >= second->subject();
310  return true;
311  }
312 };
313 
318 class ItemSubjectComparator
319 {
320 public:
321  static inline bool firstGreaterOrEqual( Item * first, Item * second )
322  {
323  const int ret = MessageCore::StringUtil::stripOffPrefixes( first->subject() ).
324  compare( MessageCore::StringUtil::stripOffPrefixes( second->subject() ), Qt::CaseInsensitive );
325  if ( ret < 0 )
326  return false;
327  // compare by date when subjects are equal
328  if ( ret == 0 )
329  return first->date() >= second->date();
330  return true;
331  }
332 };
333 
338 class ItemSenderComparator
339 {
340 public:
341  static inline bool firstGreaterOrEqual( Item * first, Item * second )
342  {
343  const int ret = MessageCore::StringUtil::stripEmailAddr( first->sender() ).compare(
344  MessageCore::StringUtil::stripEmailAddr( second->sender() ), Qt::CaseInsensitive );
345  if ( ret < 0 )
346  return false;
347  // compare by date when senders are equal
348  if ( ret == 0 )
349  return first->date() >= second->date();
350  return true;
351  }
352 };
353 
358 class ItemReceiverComparator
359 {
360 public:
361  static inline bool firstGreaterOrEqual( Item * first, Item * second )
362  {
363  const int ret = MessageCore::StringUtil::stripEmailAddr( first->receiver() ).compare(
364  MessageCore::StringUtil::stripEmailAddr( second->receiver() ), Qt::CaseInsensitive );
365  if ( ret < 0 )
366  return false;
367  // compare by date when receivers are equal
368  if ( ret == 0 )
369  return first->date() >= second->date();
370  return true;
371  }
372 };
373 
378 class ItemSenderOrReceiverComparator
379 {
380 public:
381  static inline bool firstGreaterOrEqual( Item * first, Item * second )
382  {
383  const int ret = MessageCore::StringUtil::stripEmailAddr( first->senderOrReceiver() ).compare(
384  MessageCore::StringUtil::stripEmailAddr( second->senderOrReceiver() ), Qt::CaseInsensitive );
385  if ( ret < 0 )
386  return false;
387  // compare by date when sender/receiver are equal
388  if ( ret == 0 )
389  return first->date() >= second->date();
390  return true;
391  }
392 };
393 
398 class ItemActionItemStatusComparator
399 {
400 public:
401  static inline bool firstGreaterOrEqual( Item * first, Item * second )
402  {
403  if ( first->status().isToAct() )
404  {
405  if ( second->status().isToAct() )
406  return first->date() >= second->date();
407  return true;
408  }
409  if ( second->status().isToAct() )
410  return false;
411  return first->date() >= second->date();
412  }
413 };
414 
419 class ItemUnreadStatusComparator
420 {
421 public:
422  static inline bool firstGreaterOrEqual( Item * first, Item * second )
423  {
424  if ( !first->status().isRead() )
425  {
426  // fist is unread
427  if ( !second->status().isRead() )
428  return first->date() >= second->date(); // both are unread
429  // unread comes always first with respect to non-unread
430  return true;
431  }
432  if ( !second->status().isRead() )
433  return false;
434  // both are read
435  return first->date() >= second->date();
436  }
437 };
438 
443 class ItemImportantStatusComparator
444 {
445 public:
446  static inline bool firstGreaterOrEqual( Item * first, Item * second )
447  {
448  if ( !first->status().isImportant() )
449  {
450  // fist is unread
451  if ( !second->status().isImportant() )
452  return first->date() >= second->date(); // both are unread
453  // unread comes always first with respect to non-unread
454  return true;
455  }
456  if ( !second->status().isImportant() )
457  return false;
458  // both are read
459  return first->date() >= second->date();
460  }
461 };
462 
463 } // namespace Core
464 
465 } // namespace MessageList
466 
467 #endif
MessageList::Core::ItemPrivate::childItemNeedsReSorting
bool childItemNeedsReSorting(Item *child)
Checks if the specified child item is actually in the wrong position in the child list and returns tr...
Definition: item_p.h:191
MessageList::Core::ItemPrivate::mStatus
Akonadi::MessageStatus mStatus
The status of the message (may be extended to groups in the future)
Definition: item_p.h:247
MessageList::Core::ItemPrivate::mDate
time_t mDate
The date of the message (or group date)
Definition: item_p.h:241
MessageList::Core::Item::Type
Type
The type of the Item.
Definition: item.h:61
MessageList::Core::ItemPrivate::mSize
size_t mSize
The size of the message in bytes.
Definition: item_p.h:242
MessageList::Core::Item::setIndexGuess
void setIndexGuess(int index)
Sets the cached guess for the index of this item in the parent's child list.
Definition: item.cpp:187
MessageList::Core::Item::date
time_t date() const
Returns the date of this item.
Definition: item.cpp:422
MessageList::Core::Item::senderOrReceiver
const QString & senderOrReceiver() const
Returns the sender or the receiver, depending on the underlying StorageModel settings.
Definition: item.cpp:462
MessageList::Core::ItemPrivate::mParent
Item * mParent
The parent view item.
Definition: item_p.h:239
MessageList::Core::ItemPrivate::mReceiver
QString mReceiver
The receiver of the message (or group receiver)
Definition: item_p.h:244
MessageList::Core::ItemPrivate
Definition: item_p.h:41
MessageList::Core::Item::receiver
const QString & receiver() const
Returns the receiver associated to this item.
Definition: item.cpp:452
MessageList::Core::Item::setViewable
void setViewable(Model *model, bool bViewable)
Makes this item viewable, that is, notifies its existence to any listener attacched to the "rowsInser...
Definition: item.cpp:323
MessageList::Core::ItemDateComparator::firstGreaterOrEqual
static bool firstGreaterOrEqual(Item *first, Item *second)
Definition: item_p.h:280
MessageList::Core::ItemMaxDateComparator
A helper class used with MessageList::Item::childItemNeedsReSorting() and MessageList::Item::insertCh...
Definition: item_p.h:301
MessageList::Core::Item::subject
const QString & subject() const
Returns the subject associated to this Item.
Definition: item.cpp:472
MessageList::Core::Item::size
size_t size() const
Returns the size of this item (size of the Message, mainly)
Definition: item.cpp:412
MessageList::Core::ItemSizeComparator::firstGreaterOrEqual
static bool firstGreaterOrEqual(Item *first, Item *second)
Definition: item_p.h:262
MessageList::Core::ItemSenderComparator
A helper class used with MessageList::Item::childItemNeedsReSorting() and MessageList::Item::insertCh...
Definition: item_p.h:338
MessageList::Core::ItemImportantStatusComparator::firstGreaterOrEqual
static bool firstGreaterOrEqual(Item *first, Item *second)
Definition: item_p.h:446
MessageList::Core::ItemSubjectComparator::firstGreaterOrEqual
static bool firstGreaterOrEqual(Item *first, Item *second)
Definition: item_p.h:321
MessageList::Core::ItemPrivate::mType
Item::Type mType
The type of this item.
Definition: item_p.h:249
MessageList::Core::Model
This class manages the huge tree of displayable objects: GroupHeaderItems and MessageItems.
Definition: model.h:77
MessageList::Core::ItemPrivate::mIsViewable
bool mIsViewable
Is this item attacched to the viewable root ?
Definition: item_p.h:251
MessageList::Core::ItemSizeComparator
A helper class used with MessageList::Item::childItemNeedsReSorting() and MessageList::Item::insertCh...
Definition: item_p.h:259
MessageList::Core::ItemActionItemStatusComparator
A helper class used with MessageList::Item::childItemNeedsReSorting() and MessageList::Item::insertCh...
Definition: item_p.h:398
MessageList::Core::ItemReceiverComparator::firstGreaterOrEqual
static bool firstGreaterOrEqual(Item *first, Item *second)
Definition: item_p.h:361
MessageList::Core::Item::appendChildItem
int appendChildItem(Model *model, Item *child)
Appends an Item to this item's child list.
Definition: item.cpp:521
MessageList::Core::ItemPrivate::q
Item *const q
Definition: item_p.h:236
MessageList::Core::ItemUnreadStatusComparator
A helper class used with MessageList::Item::childItemNeedsReSorting() and MessageList::Item::insertCh...
Definition: item_p.h:419
MessageList::Core::ItemSenderOrReceiverComparator
A helper class used with MessageList::Item::childItemNeedsReSorting() and MessageList::Item::insertCh...
Definition: item_p.h:378
MessageList::Core::ItemDateComparator
A helper class used with MessageList::Item::childItemNeedsReSorting() and MessageList::Item::insertCh...
Definition: item_p.h:277
MessageList::Core::ItemMaxDateComparator::firstGreaterOrEqual
static bool firstGreaterOrEqual(Item *first, Item *second)
Definition: item_p.h:304
MessageList::Core::ItemPrivate::mInitialExpandStatus
Item::InitialExpandStatus mInitialExpandStatus
The expand status we have to honor when we attach to the viewable root.
Definition: item_p.h:250
MessageList::Core::ItemPrivate::insertChildItem
int GCC_DONT_INLINE_THIS insertChildItem(Model *model, Item *child)
Implements "in the middle" insertions of child items.
Definition: item_p.h:92
MessageList::Core::Item::InitialExpandStatus
InitialExpandStatus
Specifies the initial expand status for the item that should be applied when it's attached to the vie...
Definition: item.h:73
MessageList::Core::Item
A single item of the MessageList tree managed by MessageList::Model.
Definition: item.h:52
item.h
MessageList::Core::ItemSubjectComparator
A helper class used with MessageList::Item::childItemNeedsReSorting() and MessageList::Item::insertCh...
Definition: item_p.h:318
MessageList::Core::ItemImportantStatusComparator
A helper class used with MessageList::Item::childItemNeedsReSorting() and MessageList::Item::insertCh...
Definition: item_p.h:443
MessageList::Core::ItemReceiverComparator
A helper class used with MessageList::Item::childItemNeedsReSorting() and MessageList::Item::insertCh...
Definition: item_p.h:358
MessageList::Core::ItemPrivate::mThisItemIndexGuess
int mThisItemIndexGuess
The guess for the index in the parent's child list.
Definition: item_p.h:245
MessageList::Core::ItemPrivate::mUseReceiver
bool mUseReceiver
senderOrReceiver() returns receiver rather than sender
Definition: item_p.h:252
MessageList::Core::ItemPrivate::mItemId
qint64 mItemId
The Akonadi item id.
Definition: item_p.h:248
MessageList::Core::ItemSenderComparator::firstGreaterOrEqual
static bool firstGreaterOrEqual(Item *first, Item *second)
Definition: item_p.h:341
MessageList::Core::Item::maxDate
time_t maxDate() const
Returns the maximum date in the subtree originating from this item.
Definition: item.cpp:432
MessageList::Core::ItemPrivate::mSubject
QString mSubject
The subject of the message (or group subject)
Definition: item_p.h:246
MessageList::Core::ItemActionItemStatusComparator::firstGreaterOrEqual
static bool firstGreaterOrEqual(Item *first, Item *second)
Definition: item_p.h:401
MessageList::Core::ItemPrivate::ItemPrivate
ItemPrivate(Item *owner)
Definition: item_p.h:44
MessageList::Core::ItemPrivate::~ItemPrivate
virtual ~ItemPrivate()
Definition: item_p.h:54
MessageList::Core::Item::sender
const QString & sender() const
Returns the sender associated to this item.
Definition: item.cpp:442
MessageList::Core::Model::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: model.cpp:545
MessageList::Core::Item::status
const Akonadi::MessageStatus & status() const
Returns the status associated to this Item.
Definition: item.cpp:402
GCC_DONT_INLINE_THIS
#define GCC_DONT_INLINE_THIS
Definition: item_p.h:32
MessageList::Core::ItemPrivate::mMaxDate
time_t mMaxDate
The maximum date in the subtree.
Definition: item_p.h:240
MessageList::Core::ItemUnreadStatusComparator::firstGreaterOrEqual
static bool firstGreaterOrEqual(Item *first, Item *second)
Definition: item_p.h:422
MessageList::Core::ItemSenderOrReceiverComparator::firstGreaterOrEqual
static bool firstGreaterOrEqual(Item *first, Item *second)
Definition: item_p.h:381
MessageList::Core::ItemPrivate::mChildItems
QList< Item * > * mChildItems
List of children, may be 0.
Definition: item_p.h:238
MessageList::Core::Item::indexOfChildItem
int indexOfChildItem(Item *item) const
Returns the actual index of the child Item item or -1 if item is not a child of this Item...
Definition: item.cpp:173
MessageList::Core::ItemPrivate::mSender
QString mSender
The sender of the message (or group sender)
Definition: item_p.h:243
MessageList::Core::ItemPrivate::childItemDead
void childItemDead(Item *child)
Internal handler for managing the children list.
Definition: item.cpp:604
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:32 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

messagelist

Skip menu "messagelist"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

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