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

messagelist

  • sources
  • kde-4.14
  • 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  QString mSubject;
246  qint64 mItemId;
247  qint64 mParentCollectionId;
248  Akonadi::MessageStatus mStatus;
249  int mThisItemIndexGuess;
250  Item::Type mType : 4;
251  Item::InitialExpandStatus mInitialExpandStatus : 4;
252  bool mIsViewable : 1;
253  bool mUseReceiver : 1;
254 };
255 
260 class ItemSizeComparator
261 {
262 public:
263  static inline bool firstGreaterOrEqual( Item * first, Item * second )
264  {
265  if ( first->size() < second->size() )
266  return false;
267  // When the sizes are equal compare by date too
268  if ( first->size() == second->size() )
269  return first->date() >= second->date();
270  return true;
271  }
272 };
273 
278 class ItemDateComparator
279 {
280 public:
281  static inline bool firstGreaterOrEqual( Item * first, Item * second )
282  {
283  // When the dates are equal compare by subject too
284  // This is useful, for example, in kernel mailing list where people
285  // send out multiple messages with patch parts at exactly the same time.
286  if ( first->date() == second->date() )
287  return first->subject() >= second->subject();
288  if ( first->date() == static_cast<uint>( -1 ) ) // invalid is always smaller
289  return false;
290  if ( second->date() == static_cast<uint>( -1 ) )
291  return true;
292  if ( first->date() < second->date() )
293  return false;
294  return true;
295  }
296 };
297 
302 class ItemMaxDateComparator
303 {
304 public:
305  static inline bool firstGreaterOrEqual( Item * first, Item * second )
306  {
307  if ( first->maxDate() < second->maxDate() )
308  return false;
309  if ( first->maxDate() == second->maxDate() )
310  return first->subject() >= second->subject();
311  return true;
312  }
313 };
314 
319 class ItemSubjectComparator
320 {
321 public:
322  static inline bool firstGreaterOrEqual( Item * first, Item * second )
323  {
324  const int ret = MessageCore::StringUtil::stripOffPrefixes( first->subject() ).
325  compare( MessageCore::StringUtil::stripOffPrefixes( second->subject() ), Qt::CaseInsensitive );
326  if ( ret < 0 )
327  return false;
328  // compare by date when subjects are equal
329  if ( ret == 0 )
330  return first->date() >= second->date();
331  return true;
332  }
333 };
334 
339 class ItemSenderComparator
340 {
341 public:
342  static inline bool firstGreaterOrEqual( Item * first, Item * second )
343  {
344  const int ret = MessageCore::StringUtil::stripEmailAddr( first->sender() ).compare(
345  MessageCore::StringUtil::stripEmailAddr( second->sender() ), Qt::CaseInsensitive );
346  if ( ret < 0 )
347  return false;
348  // compare by date when senders are equal
349  if ( ret == 0 )
350  return first->date() >= second->date();
351  return true;
352  }
353 };
354 
359 class ItemReceiverComparator
360 {
361 public:
362  static inline bool firstGreaterOrEqual( Item * first, Item * second )
363  {
364  const int ret = MessageCore::StringUtil::stripEmailAddr( first->receiver() ).compare(
365  MessageCore::StringUtil::stripEmailAddr( second->receiver() ), Qt::CaseInsensitive );
366  if ( ret < 0 )
367  return false;
368  // compare by date when receivers are equal
369  if ( ret == 0 )
370  return first->date() >= second->date();
371  return true;
372  }
373 };
374 
379 class ItemSenderOrReceiverComparator
380 {
381 public:
382  static inline bool firstGreaterOrEqual( Item * first, Item * second )
383  {
384  const int ret = MessageCore::StringUtil::stripEmailAddr( first->senderOrReceiver() ).compare(
385  MessageCore::StringUtil::stripEmailAddr( second->senderOrReceiver() ), Qt::CaseInsensitive );
386  if ( ret < 0 )
387  return false;
388  // compare by date when sender/receiver are equal
389  if ( ret == 0 )
390  return first->date() >= second->date();
391  return true;
392  }
393 };
394 
399 class ItemActionItemStatusComparator
400 {
401 public:
402  static inline bool firstGreaterOrEqual( Item * first, Item * second )
403  {
404  if ( first->status().isToAct() )
405  {
406  if ( second->status().isToAct() )
407  return first->date() >= second->date();
408  return true;
409  }
410  if ( second->status().isToAct() )
411  return false;
412  return first->date() >= second->date();
413  }
414 };
415 
420 class ItemUnreadStatusComparator
421 {
422 public:
423  static inline bool firstGreaterOrEqual( Item * first, Item * second )
424  {
425  if ( !first->status().isRead() )
426  {
427  // fist is unread
428  if ( !second->status().isRead() )
429  return first->date() >= second->date(); // both are unread
430  // unread comes always first with respect to non-unread
431  return true;
432  }
433  if ( !second->status().isRead() )
434  return false;
435  // both are read
436  return first->date() >= second->date();
437  }
438 };
439 
444 class ItemImportantStatusComparator
445 {
446 public:
447  static inline bool firstGreaterOrEqual( Item * first, Item * second )
448  {
449  if ( !first->status().isImportant() )
450  {
451  // fist is unread
452  if ( !second->status().isImportant() )
453  return first->date() >= second->date(); // both are unread
454  // unread comes always first with respect to non-unread
455  return true;
456  }
457  if ( !second->status().isImportant() )
458  return false;
459  // both are read
460  return first->date() >= second->date();
461  }
462 };
463 
468 class ItemAttachmentStatusComparator
469 {
470 public:
471  static inline bool firstGreaterOrEqual( Item * first, Item * second )
472  {
473  if ( !first->status().hasAttachment() )
474  {
475  // fist is unread
476  if ( !second->status().hasAttachment() )
477  return first->date() >= second->date(); // both are unread
478  // unread comes always first with respect to non-unread
479  return true;
480  }
481  if ( !second->status().hasAttachment() )
482  return false;
483  // both are read
484  return first->date() >= second->date();
485  }
486 };
487 
488 
489 } // namespace Core
490 
491 } // namespace MessageList
492 
493 #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:248
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:421
MessageList::Core::ItemPrivate::mParentCollectionId
qint64 mParentCollectionId
The Akonadi ID of collection that this particular item comes from (can be virtual collection) ...
Definition: item_p.h:247
MessageList::Core::Item::senderOrReceiver
const QString & senderOrReceiver() const
Returns the sender or the receiver, depending on the underlying StorageModel settings.
Definition: item.cpp:461
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:451
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:322
MessageList::Core::ItemDateComparator::firstGreaterOrEqual
static bool firstGreaterOrEqual(Item *first, Item *second)
Definition: item_p.h:281
MessageList::Core::ItemMaxDateComparator
A helper class used with MessageList::Item::childItemNeedsReSorting() and MessageList::Item::insertCh...
Definition: item_p.h:302
MessageList::Core::Item::subject
const QString & subject() const
Returns the subject associated to this Item.
Definition: item.cpp:471
MessageList::Core::ItemAttachmentStatusComparator
A helper class used with MessageList::Item::childItemNeedsReSorting() and MessageList::Item::insertCh...
Definition: item_p.h:468
MessageList::Core::Item::size
size_t size() const
Returns the size of this item (size of the Message, mainly)
Definition: item.cpp:411
MessageList::Core::ItemSizeComparator::firstGreaterOrEqual
static bool firstGreaterOrEqual(Item *first, Item *second)
Definition: item_p.h:263
MessageList::Core::ItemSenderComparator
A helper class used with MessageList::Item::childItemNeedsReSorting() and MessageList::Item::insertCh...
Definition: item_p.h:339
MessageList::Core::ItemImportantStatusComparator::firstGreaterOrEqual
static bool firstGreaterOrEqual(Item *first, Item *second)
Definition: item_p.h:447
MessageList::Core::ItemSubjectComparator::firstGreaterOrEqual
static bool firstGreaterOrEqual(Item *first, Item *second)
Definition: item_p.h:322
MessageList::Core::ItemPrivate::mType
Item::Type mType
The type of this item.
Definition: item_p.h:250
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:252
MessageList::Core::ItemSizeComparator
A helper class used with MessageList::Item::childItemNeedsReSorting() and MessageList::Item::insertCh...
Definition: item_p.h:260
MessageList::Core::ItemActionItemStatusComparator
A helper class used with MessageList::Item::childItemNeedsReSorting() and MessageList::Item::insertCh...
Definition: item_p.h:399
MessageList::Core::ItemReceiverComparator::firstGreaterOrEqual
static bool firstGreaterOrEqual(Item *first, Item *second)
Definition: item_p.h:362
MessageList::Core::Item::appendChildItem
int appendChildItem(Model *model, Item *child)
Appends an Item to this item's child list.
Definition: item.cpp:530
MessageList::Core::ItemPrivate::q
Item *const q
Definition: item_p.h:236
QAbstractItemModel::endInsertRows
void endInsertRows()
MessageList::Core::ItemUnreadStatusComparator
A helper class used with MessageList::Item::childItemNeedsReSorting() and MessageList::Item::insertCh...
Definition: item_p.h:420
MessageList::Core::ItemSenderOrReceiverComparator
A helper class used with MessageList::Item::childItemNeedsReSorting() and MessageList::Item::insertCh...
Definition: item_p.h:379
MessageList::Core::ItemDateComparator
A helper class used with MessageList::Item::childItemNeedsReSorting() and MessageList::Item::insertCh...
Definition: item_p.h:278
MessageList::Core::ItemMaxDateComparator::firstGreaterOrEqual
static bool firstGreaterOrEqual(Item *first, Item *second)
Definition: item_p.h:305
QString
QList
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:251
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:319
MessageList::Core::ItemImportantStatusComparator
A helper class used with MessageList::Item::childItemNeedsReSorting() and MessageList::Item::insertCh...
Definition: item_p.h:444
QAbstractItemModel::beginInsertRows
void beginInsertRows(const QModelIndex &parent, int first, int last)
MessageList::Core::ItemReceiverComparator
A helper class used with MessageList::Item::childItemNeedsReSorting() and MessageList::Item::insertCh...
Definition: item_p.h:359
MessageList::Core::ItemPrivate::mThisItemIndexGuess
int mThisItemIndexGuess
The guess for the index in the parent's child list.
Definition: item_p.h:249
MessageList::Core::ItemPrivate::mUseReceiver
bool mUseReceiver
senderOrReceiver() returns receiver rather than sender
Definition: item_p.h:253
MessageList::Core::ItemPrivate::mItemId
qint64 mItemId
The Akonadi item id.
Definition: item_p.h:246
MessageList::Core::ItemSenderComparator::firstGreaterOrEqual
static bool firstGreaterOrEqual(Item *first, Item *second)
Definition: item_p.h:342
MessageList::Core::Item::maxDate
time_t maxDate() const
Returns the maximum date in the subtree originating from this item.
Definition: item.cpp:431
MessageList::Core::ItemPrivate::mSubject
QString mSubject
The subject of the message (or group subject)
Definition: item_p.h:245
MessageList::Core::ItemAttachmentStatusComparator::firstGreaterOrEqual
static bool firstGreaterOrEqual(Item *first, Item *second)
Definition: item_p.h:471
MessageList::Core::ItemActionItemStatusComparator::firstGreaterOrEqual
static bool firstGreaterOrEqual(Item *first, Item *second)
Definition: item_p.h:402
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:441
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:401
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:423
MessageList::Core::ItemSenderOrReceiverComparator::firstGreaterOrEqual
static bool firstGreaterOrEqual(Item *first, Item *second)
Definition: item_p.h:382
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:613
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:01 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
  • pimprint

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