• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.13.3 API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • akonadi
entitytreemodel.cpp
1 /*
2  Copyright (c) 2008 Stephen Kelly <steveire@gmail.com>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "entitytreemodel.h"
21 #include "entitytreemodel_p.h"
22 
23 #include "monitor_p.h"
24 
25 #include <QtCore/QHash>
26 #include <QtCore/QMimeData>
27 #include <QtCore/QTimer>
28 #include <QAbstractProxyModel>
29 
30 #include <KDE/KIcon>
31 #include <KDE/KLocalizedString>
32 #include <KDE/KMessageBox>
33 #include <KDE/KUrl>
34 
35 #include <akonadi/attributefactory.h>
36 #include <akonadi/changerecorder.h>
37 #include <akonadi/collectionmodifyjob.h>
38 #include <akonadi/entitydisplayattribute.h>
39 #include <akonadi/transactionsequence.h>
40 #include <akonadi/itemmodifyjob.h>
41 #include <akonadi/session.h>
42 #include "collectionfetchscope.h"
43 
44 #include "collectionutils_p.h"
45 
46 #include "kdebug.h"
47 #include "pastehelper_p.h"
48 
49 Q_DECLARE_METATYPE( QSet<QByteArray> )
50 
51 using namespace Akonadi;
52 
53 EntityTreeModel::EntityTreeModel( ChangeRecorder *monitor,
54  QObject *parent
55  )
56  : QAbstractItemModel( parent ),
57  d_ptr( new EntityTreeModelPrivate( this ) )
58 {
59  Q_D( EntityTreeModel );
60  d->init( monitor );
61 }
62 
63 EntityTreeModel::EntityTreeModel( ChangeRecorder *monitor,
64  EntityTreeModelPrivate *d,
65  QObject *parent )
66  : QAbstractItemModel( parent ),
67  d_ptr( d )
68 {
69  d->init( monitor );
70 }
71 
72 EntityTreeModel::~EntityTreeModel()
73 {
74  Q_D( EntityTreeModel );
75 
76  foreach ( const QList<Node*> &list, d->m_childEntities ) {
77  QList<Node*>::const_iterator it = list.constBegin();
78  const QList<Node*>::const_iterator end = list.constEnd();
79  for ( ; it != end; ++it ) {
80  delete *it;
81  }
82  }
83 
84  d->m_rootNode = 0;
85 
86  delete d_ptr;
87 }
88 
89 bool EntityTreeModel::includeUnsubscribed() const
90 {
91  Q_D( const EntityTreeModel );
92  return d->m_includeUnsubscribed;
93 }
94 
95 void EntityTreeModel::setIncludeUnsubscribed( bool show )
96 {
97  Q_D( EntityTreeModel );
98  d->beginResetModel();
99  d->m_includeUnsubscribed = show;
100  d->m_monitor->setAllMonitored( show );
101  d->endResetModel();
102 }
103 
104 bool EntityTreeModel::systemEntitiesShown() const
105 {
106  Q_D( const EntityTreeModel );
107  return d->m_showSystemEntities;
108 }
109 
110 void EntityTreeModel::setShowSystemEntities( bool show )
111 {
112  Q_D( EntityTreeModel );
113  d->m_showSystemEntities = show;
114 }
115 
116 void EntityTreeModel::clearAndReset()
117 {
118  Q_D( EntityTreeModel );
119  d->beginResetModel();
120  d->endResetModel();
121 }
122 
123 int EntityTreeModel::columnCount( const QModelIndex & parent ) const
124 {
125 // TODO: Statistics?
126  if ( parent.isValid() &&
127  parent.column() != 0 ) {
128  return 0;
129  }
130 
131  return qMax( entityColumnCount( CollectionTreeHeaders ), entityColumnCount( ItemListHeaders ) );
132 }
133 
134 QVariant EntityTreeModel::entityData( const Item &item, int column, int role ) const
135 {
136  if ( column == 0 ) {
137  switch ( role ) {
138  case Qt::DisplayRole:
139  case Qt::EditRole:
140  if ( item.hasAttribute<EntityDisplayAttribute>() &&
141  !item.attribute<EntityDisplayAttribute>()->displayName().isEmpty() ) {
142  return item.attribute<EntityDisplayAttribute>()->displayName();
143  } else {
144  if ( !item.remoteId().isEmpty() ) {
145  return item.remoteId();
146  }
147  return QString( QLatin1String( "<" ) + QString::number( item.id() ) + QLatin1String( ">" ) );
148  }
149  break;
150  case Qt::DecorationRole:
151  if ( item.hasAttribute<EntityDisplayAttribute>() &&
152  !item.attribute<EntityDisplayAttribute>()->iconName().isEmpty() ) {
153  return item.attribute<EntityDisplayAttribute>()->icon();
154  }
155  break;
156  default:
157  break;
158  }
159  }
160 
161  return QVariant();
162 }
163 
164 QVariant EntityTreeModel::entityData( const Collection &collection, int column, int role ) const
165 {
166  Q_D( const EntityTreeModel );
167 
168  if ( column > 0 ) {
169  return QString();
170  }
171 
172  if ( collection == Collection::root() ) {
173  // Only display the root collection. It may not be edited.
174  if ( role == Qt::DisplayRole ) {
175  return d->m_rootCollectionDisplayName;
176  }
177 
178  if ( role == Qt::EditRole ) {
179  return QVariant();
180  }
181  }
182 
183  switch ( role ) {
184  case Qt::DisplayRole:
185  case Qt::EditRole:
186  if ( column == 0 ) {
187  const QString displayName = collection.displayName();
188  if ( !displayName.isEmpty() )
189  return displayName;
190  else
191  return i18n( "Loading..." );
192  }
193  break;
194  case Qt::DecorationRole:
195  if ( collection.hasAttribute<EntityDisplayAttribute>() &&
196  !collection.attribute<EntityDisplayAttribute>()->iconName().isEmpty() ) {
197  return collection.attribute<EntityDisplayAttribute>()->icon();
198  }
199  return KIcon( CollectionUtils::defaultIconName( collection ) );
200  default:
201  break;
202  }
203 
204  return QVariant();
205 }
206 
207 QVariant EntityTreeModel::data( const QModelIndex & index, int role ) const
208 {
209  Q_D( const EntityTreeModel );
210  if ( role == SessionRole ) {
211  return QVariant::fromValue( qobject_cast<QObject *>( d->m_session ) );
212  }
213 
214  // Ugly, but at least the API is clean.
215  const HeaderGroup headerGroup = static_cast<HeaderGroup>( ( role / static_cast<int>( TerminalUserRole ) ) );
216 
217  role %= TerminalUserRole;
218  if ( !index.isValid() ) {
219  if ( ColumnCountRole != role ) {
220  return QVariant();
221  }
222 
223  return entityColumnCount( headerGroup );
224  }
225 
226  if ( ColumnCountRole == role ) {
227  return entityColumnCount( headerGroup );
228  }
229 
230  const Node *node = reinterpret_cast<Node *>( index.internalPointer() );
231 
232  if ( ParentCollectionRole == role &&
233  d->m_collectionFetchStrategy != FetchNoCollections ) {
234  const Collection parentCollection = d->m_collections.value( node->parent );
235  Q_ASSERT( parentCollection.isValid() );
236 
237  return QVariant::fromValue( parentCollection );
238  }
239 
240  if ( Node::Collection == node->type ) {
241 
242  const Collection collection = d->m_collections.value( node->id );
243 
244  if ( !collection.isValid() ) {
245  return QVariant();
246  }
247 
248  switch ( role ) {
249  case MimeTypeRole:
250  return collection.mimeType();
251  break;
252  case RemoteIdRole:
253  return collection.remoteId();
254  break;
255  case CollectionIdRole:
256  return collection.id();
257  break;
258  case ItemIdRole:
259  // QVariant().toInt() is 0, not -1, so we have to handle the ItemIdRole
260  // and CollectionIdRole (below) specially
261  return -1;
262  break;
263  case CollectionRole:
264  return QVariant::fromValue( collection );
265  break;
266  case EntityUrlRole:
267  return collection.url().url();
268  break;
269  case UnreadCountRole:
270  {
271  CollectionStatistics statistics = collection.statistics();
272  return statistics.unreadCount();
273  }
274  case FetchStateRole:
275  {
276  return d->m_pendingCollectionRetrieveJobs.contains( collection.id() ) ? FetchingState : IdleState;
277  }
278  case CollectionSyncProgressRole:
279  {
280  return d->m_collectionSyncProgress.value( collection.id() );
281  }
282  case IsPopulatedRole:
283  {
284  return d->m_populatedCols.contains( collection.id() );
285  }
286  case Qt::BackgroundRole:
287  {
288  if ( collection.hasAttribute<EntityDisplayAttribute>() ) {
289  EntityDisplayAttribute *eda = collection.attribute<EntityDisplayAttribute>();
290  QColor color = eda->backgroundColor();
291  if ( color.isValid() ) {
292  return color;
293  }
294  }
295  // fall through.
296  }
297  default:
298  return entityData( collection, index.column(), role );
299  break;
300  }
301 
302  } else if ( Node::Item == node->type ) {
303  const Item item = d->m_items.value( node->id );
304  if ( !item.isValid() ) {
305  return QVariant();
306  }
307 
308  switch ( role ) {
309  case ParentCollectionRole:
310  return QVariant::fromValue( item.parentCollection() );
311  case MimeTypeRole:
312  return item.mimeType();
313  break;
314  case RemoteIdRole:
315  return item.remoteId();
316  break;
317  case ItemRole:
318  return QVariant::fromValue( item );
319  break;
320  case ItemIdRole:
321  return item.id();
322  break;
323  case CollectionIdRole:
324  return -1;
325  break;
326  case LoadedPartsRole:
327  return QVariant::fromValue( item.loadedPayloadParts() );
328  break;
329  case AvailablePartsRole:
330  return QVariant::fromValue( item.availablePayloadParts() );
331  break;
332  case EntityUrlRole:
333  return item.url( Akonadi::Item::UrlWithMimeType ).url();
334  break;
335  case Qt::BackgroundRole:
336  {
337  if ( item.hasAttribute<EntityDisplayAttribute>() ) {
338  EntityDisplayAttribute *eda = item.attribute<EntityDisplayAttribute>();
339  const QColor color = eda->backgroundColor();
340  if ( color.isValid() ) {
341  return color;
342  }
343  }
344  // fall through.
345  }
346  default:
347  return entityData( item, index.column(), role );
348  break;
349  }
350  }
351 
352  return QVariant();
353 }
354 
355 Qt::ItemFlags EntityTreeModel::flags( const QModelIndex & index ) const
356 {
357  Q_D( const EntityTreeModel );
358  // Pass modeltest.
359  if ( !index.isValid() ) {
360  return 0;
361  }
362 
363  Qt::ItemFlags flags = QAbstractItemModel::flags( index );
364 
365  const Node *node = reinterpret_cast<Node *>( index.internalPointer() );
366 
367  if ( Node::Collection == node->type ) {
368  // cut out entities will be shown as inactive
369  if ( d->m_pendingCutCollections.contains( node->id ) ) {
370  return Qt::ItemIsSelectable;
371  }
372 
373  const Collection collection = d->m_collections.value( node->id );
374  if ( collection.isValid() ) {
375 
376  if ( collection == Collection::root() ) {
377  // Selectable and displayable only.
378  return flags;
379  }
380 
381  const int rights = collection.rights();
382 
383  if ( rights & Collection::CanChangeCollection ) {
384  if ( index.column() == 0 ) {
385  flags |= Qt::ItemIsEditable;
386  }
387  // Changing the collection includes changing the metadata (child entityordering).
388  // Need to allow this by drag and drop.
389  flags |= Qt::ItemIsDropEnabled;
390  }
391  if ( rights & ( Collection::CanCreateCollection | Collection::CanCreateItem | Collection::CanLinkItem ) ) {
392  // Can we drop new collections and items into this collection?
393  flags |= Qt::ItemIsDropEnabled;
394  }
395 
396  // dragging is always possible, even for read-only objects, but they can only be copied, not moved.
397  flags |= Qt::ItemIsDragEnabled;
398 
399  }
400  } else if ( Node::Item == node->type ) {
401  if ( d->m_pendingCutItems.contains( node->id ) ) {
402  return Qt::ItemIsSelectable;
403  }
404 
405  // Rights come from the parent collection.
406 
407  Collection parentCollection;
408  if ( !index.parent().isValid() ) {
409  parentCollection = d->m_rootCollection;
410  } else {
411  const Node *parentNode = reinterpret_cast<Node *>( index.parent().internalPointer() );
412 
413  parentCollection = d->m_collections.value( parentNode->id );
414  }
415  if ( parentCollection.isValid() ) {
416  const int rights = parentCollection.rights();
417 
418  // Can't drop onto items.
419  if ( rights & Collection::CanChangeItem && index.column() == 0 ) {
420  flags = flags | Qt::ItemIsEditable;
421  }
422  // dragging is always possible, even for read-only objects, but they can only be copied, not moved.
423  flags |= Qt::ItemIsDragEnabled;
424  }
425  }
426 
427  return flags;
428 }
429 
430 Qt::DropActions EntityTreeModel::supportedDropActions() const
431 {
432  return ( Qt::CopyAction | Qt::MoveAction | Qt::LinkAction );
433 }
434 
435 QStringList EntityTreeModel::mimeTypes() const
436 {
437  // TODO: Should this return the mimetypes that the items provide? Allow dragging a contact from here for example.
438  return QStringList() << QLatin1String( "text/uri-list" );
439 }
440 
441 bool EntityTreeModel::dropMimeData( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent )
442 {
443  Q_UNUSED( row );
444  Q_UNUSED( column );
445  Q_D( EntityTreeModel );
446 
447  // Can't drop onto Collection::root.
448  if ( !parent.isValid() ) {
449  return false;
450  }
451 
452  // TODO Use action and collection rights and return false if necessary
453 
454  // if row and column are -1, then the drop was on parent directly.
455  // data should then be appended on the end of the items of the collections as appropriate.
456  // That will mean begin insert rows etc.
457  // Otherwise it was a sibling of the row^th item of parent.
458  // Needs to be handled when ordering is accounted for.
459 
460  // Handle dropping between items as well as on items.
461 // if ( row != -1 && column != -1 )
462 // {
463 // }
464 
465  if ( action == Qt::IgnoreAction ) {
466  return true;
467  }
468 
469 // Shouldn't do this. Need to be able to drop vcards for example.
470 // if ( !data->hasFormat( "text/uri-list" ) )
471 // return false;
472 
473  Node *node = reinterpret_cast<Node *>( parent.internalId() );
474 
475  Q_ASSERT( node );
476 
477  if ( Node::Item == node->type ) {
478  if ( !parent.parent().isValid() ) {
479  // The drop is somehow on an item with no parent (shouldn't happen)
480  // The drop should be considered handled anyway.
481  kWarning() << "Dropped onto item with no parent collection";
482  return true;
483  }
484 
485  // A drop onto an item should be considered as a drop onto its parent collection
486  node = reinterpret_cast<Node *>( parent.parent().internalId() );
487  }
488 
489  if ( Node::Collection == node->type ) {
490  const Collection destCollection = d->m_collections.value( node->id );
491 
492  // Applications can't create new collections in root. Only resources can.
493  if ( destCollection == Collection::root() ) {
494  // Accept the event so that it doesn't propagate.
495  return true;
496  }
497 
498  if ( data->hasFormat( QLatin1String( "text/uri-list" ) ) ) {
499 
500  MimeTypeChecker mimeChecker;
501  mimeChecker.setWantedMimeTypes( destCollection.contentMimeTypes() );
502 
503  const KUrl::List urls = KUrl::List::fromMimeData( data );
504  foreach ( const KUrl &url, urls ) {
505  const Collection collection = d->m_collections.value( Collection::fromUrl( url ).id() );
506  if ( collection.isValid() ) {
507  if ( collection.parentCollection().id() == destCollection.id() &&
508  action != Qt::CopyAction ) {
509  kDebug() << "Error: source and destination of move are the same.";
510  return false;
511  }
512 
513  if ( !mimeChecker.isWantedCollection( collection ) ) {
514  kDebug() << "unwanted collection" << mimeChecker.wantedMimeTypes() << collection.contentMimeTypes();
515  return false;
516  }
517 
518  if ( url.hasQueryItem( QLatin1String( "name" ) ) ) {
519  const QString collectionName = url.queryItemValue( QLatin1String( "name" ) );
520  const QStringList collectionNames = d->childCollectionNames( destCollection );
521 
522  if ( collectionNames.contains( collectionName ) ) {
523  KMessageBox::error( 0, i18n( "The target collection '%1' contains already\na collection with name '%2'.",
524  destCollection.name(), collection.name() ) );
525  return false;
526  }
527  }
528  } else {
529  const Item item = d->m_items.value( Item::fromUrl( url ).id() );
530  if ( item.isValid() ) {
531  if ( item.parentCollection().id() == destCollection.id() && action != Qt::CopyAction ) {
532  kDebug() << "Error: source and destination of move are the same.";
533  return false;
534  }
535 
536  if ( !mimeChecker.isWantedItem( item ) ) {
537  kDebug() << "unwanted item" << mimeChecker.wantedMimeTypes() << item.mimeType();
538  return false;
539  }
540  }
541  }
542  }
543 
544  KJob *job = PasteHelper::pasteUriList( data, destCollection, action, d->m_session );
545  if ( !job ) {
546  return false;
547  }
548 
549  connect( job, SIGNAL(result(KJob*)), SLOT(pasteJobDone(KJob*)) );
550 
551  // Accpet the event so that it doesn't propagate.
552  return true;
553  } else {
554 // not a set of uris. Maybe vcards etc. Check if the parent supports them, and maybe do
555  // fromMimeData for them. Hmm, put it in the same transaction with the above?
556  // TODO: This should be handled first, not last.
557  }
558  }
559 
560  return false;
561 }
562 
563 QModelIndex EntityTreeModel::index( int row, int column, const QModelIndex & parent ) const
564 {
565 
566  Q_D( const EntityTreeModel );
567 
568  if ( parent.column() > 0 ) {
569  return QModelIndex();
570  }
571 
572  //TODO: don't use column count here? Use some d-> func.
573  if ( column >= columnCount() ||
574  column < 0 ) {
575  return QModelIndex();
576  }
577 
578  QList<Node*> childEntities;
579 
580  const Node *parentNode = reinterpret_cast<Node*>( parent.internalPointer() );
581 
582  if ( !parentNode || !parent.isValid() ) {
583  if ( d->m_showRootCollection ) {
584  childEntities << d->m_childEntities.value( -1 );
585  } else {
586  childEntities = d->m_childEntities.value( d->m_rootCollection.id() );
587  }
588  } else {
589  if ( parentNode->id >= 0 ) {
590  childEntities = d->m_childEntities.value( parentNode->id );
591  }
592  }
593 
594  const int size = childEntities.size();
595  if ( row < 0 || row >= size ) {
596  return QModelIndex();
597  }
598 
599  Node *node = childEntities.at( row );
600 
601  return createIndex( row, column, reinterpret_cast<void*>( node ) );
602 }
603 
604 QModelIndex EntityTreeModel::parent( const QModelIndex & index ) const
605 {
606  Q_D( const EntityTreeModel );
607 
608  if ( !index.isValid() ) {
609  return QModelIndex();
610  }
611 
612  if ( d->m_collectionFetchStrategy == InvisibleCollectionFetch ||
613  d->m_collectionFetchStrategy == FetchNoCollections ) {
614  return QModelIndex();
615  }
616 
617  const Node *node = reinterpret_cast<Node*>( index.internalPointer() );
618 
619  if ( !node ) {
620  return QModelIndex();
621  }
622 
623  const Collection collection = d->m_collections.value( node->parent );
624 
625  if ( !collection.isValid() ) {
626  return QModelIndex();
627  }
628 
629  if ( collection.id() == d->m_rootCollection.id() ) {
630  if ( !d->m_showRootCollection ) {
631  return QModelIndex();
632  } else {
633  return createIndex( 0, 0, reinterpret_cast<void *>( d->m_rootNode ) );
634  }
635  }
636 
637  Q_ASSERT( collection.parentCollection().isValid() );
638  const int row = d->indexOf<Node::Collection>( d->m_childEntities.value( collection.parentCollection().id() ), collection.id() );
639 
640  Q_ASSERT( row >= 0 );
641  Node *parentNode = d->m_childEntities.value( collection.parentCollection().id() ).at( row );
642 
643  return createIndex( row, 0, reinterpret_cast<void*>( parentNode ) );
644 }
645 
646 int EntityTreeModel::rowCount( const QModelIndex & parent ) const
647 {
648  Q_D( const EntityTreeModel );
649 
650  if ( d->m_collectionFetchStrategy == InvisibleCollectionFetch ||
651  d->m_collectionFetchStrategy == FetchNoCollections ) {
652  if ( parent.isValid() ) {
653  return 0;
654  } else {
655  return d->m_items.size();
656  }
657  }
658 
659  if ( !parent.isValid() ) {
660  // If we're showing the root collection then it will be the only child of the root.
661  if ( d->m_showRootCollection ) {
662  return d->m_childEntities.value( -1 ).size();
663  }
664  return d->m_childEntities.value( d->m_rootCollection.id() ).size();
665  }
666 
667  if ( parent.column() != 0 ) {
668  return 0;
669  }
670 
671  const Node *node = reinterpret_cast<Node*>( parent.internalPointer() );
672 
673  if ( !node ) {
674  return 0;
675  }
676 
677  if ( Node::Item == node->type ) {
678  return 0;
679  }
680 
681  Q_ASSERT( parent.isValid() );
682  return d->m_childEntities.value( node->id ).size();
683 }
684 
685 int EntityTreeModel::entityColumnCount( HeaderGroup headerGroup ) const
686 {
687  // Not needed in this model.
688  Q_UNUSED( headerGroup );
689 
690  return 1;
691 }
692 
693 QVariant EntityTreeModel::entityHeaderData( int section, Qt::Orientation orientation, int role, HeaderGroup headerGroup ) const
694 {
695  Q_D( const EntityTreeModel );
696  // Not needed in this model.
697  Q_UNUSED( headerGroup );
698 
699  if ( section == 0 &&
700  orientation == Qt::Horizontal &&
701  role == Qt::DisplayRole ) {
702  if ( d->m_rootCollection == Collection::root() ) {
703  return i18nc( "@title:column Name of a thing", "Name" );
704  }
705  return d->m_rootCollection.name();
706  }
707 
708  return QAbstractItemModel::headerData( section, orientation, role );
709 }
710 
711 QVariant EntityTreeModel::headerData( int section, Qt::Orientation orientation, int role ) const
712 {
713  const HeaderGroup headerGroup = static_cast<HeaderGroup>( ( role / static_cast<int>( TerminalUserRole ) ) );
714 
715  role %= TerminalUserRole;
716  return entityHeaderData( section, orientation, role, headerGroup );
717 }
718 
719 QMimeData *EntityTreeModel::mimeData( const QModelIndexList &indexes ) const
720 {
721  Q_D( const EntityTreeModel );
722 
723  QMimeData *data = new QMimeData();
724  KUrl::List urls;
725  foreach ( const QModelIndex &index, indexes ) {
726  if ( index.column() != 0 ) {
727  continue;
728  }
729 
730  if ( !index.isValid() ) {
731  continue;
732  }
733 
734  const Node *node = reinterpret_cast<Node*>( index.internalPointer() );
735 
736  if ( Node::Collection == node->type ) {
737  urls << d->m_collections.value( node->id ).url( Collection::UrlWithName );
738  } else if ( Node::Item == node->type ) {
739  urls << d->m_items.value( node->id ).url( Item::UrlWithMimeType );
740  } else { // if that happens something went horrible wrong
741  Q_ASSERT( false );
742  }
743  }
744 
745  urls.populateMimeData( data );
746 
747  return data;
748 }
749 
750 // Always return false for actions which take place asyncronously, eg via a Job.
751 bool EntityTreeModel::setData( const QModelIndex &index, const QVariant &value, int role )
752 {
753  Q_D( EntityTreeModel );
754 
755  const Node *node = reinterpret_cast<Node*>( index.internalPointer() );
756 
757  if ( role == PendingCutRole ) {
758  if ( index.isValid() && value.toBool() ) {
759  if ( Node::Collection == node->type ) {
760  d->m_pendingCutCollections.append( node->id );
761  }
762 
763  if ( Node::Item == node->type ) {
764  d->m_pendingCutItems.append( node->id );
765  }
766  } else {
767  d->m_pendingCutCollections.clear();
768  d->m_pendingCutItems.clear();
769  }
770  return true;
771  }
772 
773  if ( index.isValid() &&
774  node->type == Node::Collection &&
775  ( role == CollectionRefRole ||
776  role == CollectionDerefRole ) ) {
777  const Collection collection = index.data( CollectionRole ).value<Collection>();
778  Q_ASSERT( collection.isValid() );
779 
780  if ( role == CollectionDerefRole ) {
781  d->deref( collection.id() );
782  } else if ( role == CollectionRefRole ) {
783  d->ref( collection.id() );
784  }
785  return true;
786  }
787 
788  if ( index.column() == 0 &&
789  ( role & ( Qt::EditRole | ItemRole | CollectionRole ) ) ) {
790  if ( Node::Collection == node->type ) {
791 
792  Collection collection = d->m_collections.value( node->id );
793 
794  if ( !collection.isValid() || !value.isValid() ) {
795  return false;
796  }
797 
798  if ( Qt::EditRole == role ) {
799  collection.setName( value.toString() );
800 
801  if ( collection.hasAttribute<EntityDisplayAttribute>() ) {
802  EntityDisplayAttribute *displayAttribute = collection.attribute<EntityDisplayAttribute>();
803  displayAttribute->setDisplayName( value.toString() );
804  }
805  }
806 
807  if ( Qt::BackgroundRole == role ) {
808  QColor color = value.value<QColor>();
809 
810  if ( !color.isValid() ) {
811  return false;
812  }
813 
814  EntityDisplayAttribute *eda = collection.attribute<EntityDisplayAttribute>( Entity::AddIfMissing );
815  eda->setBackgroundColor( color );
816  }
817 
818  if ( CollectionRole == role ) {
819  collection = value.value<Collection>();
820  }
821 
822  CollectionModifyJob *job = new CollectionModifyJob( collection, d->m_session );
823  connect( job, SIGNAL(result(KJob*)),
824  SLOT(updateJobDone(KJob*)) );
825 
826  return false;
827  } else if ( Node::Item == node->type ) {
828 
829  Item item = d->m_items.value( node->id );
830 
831  if ( !item.isValid() || !value.isValid() ) {
832  return false;
833  }
834 
835  if ( Qt::EditRole == role ) {
836  if ( item.hasAttribute<EntityDisplayAttribute>() ) {
837  EntityDisplayAttribute *displayAttribute = item.attribute<EntityDisplayAttribute>( Entity::AddIfMissing );
838  displayAttribute->setDisplayName( value.toString() );
839  }
840  }
841 
842  if ( Qt::BackgroundRole == role ) {
843  QColor color = value.value<QColor>();
844 
845  if ( !color.isValid() ) {
846  return false;
847  }
848 
849  EntityDisplayAttribute *eda = item.attribute<EntityDisplayAttribute>( Entity::AddIfMissing );
850  eda->setBackgroundColor( color );
851  }
852 
853  if ( ItemRole == role ) {
854  item = value.value<Item>();
855  Q_ASSERT( item.id() == node->id );
856  }
857 
858  ItemModifyJob *itemModifyJob = new ItemModifyJob( item, d->m_session );
859  connect( itemModifyJob, SIGNAL(result(KJob*)),
860  SLOT(updateJobDone(KJob*)) );
861 
862  return false;
863  }
864  }
865 
866  return QAbstractItemModel::setData( index, value, role );
867 }
868 
869 bool EntityTreeModel::canFetchMore( const QModelIndex & parent ) const
870 {
871  Q_UNUSED( parent )
872  return false;
873 }
874 
875 void EntityTreeModel::fetchMore( const QModelIndex & parent )
876 {
877  Q_D( EntityTreeModel );
878 
879  if ( !d->canFetchMore( parent ) ) {
880  return;
881  }
882 
883  if ( d->m_collectionFetchStrategy == InvisibleCollectionFetch ) {
884  return;
885  }
886 
887  if ( d->m_itemPopulation == ImmediatePopulation ) {
888  // Nothing to do. The items are already in the model.
889  return;
890  } else if ( d->m_itemPopulation == LazyPopulation ) {
891  const Collection collection = parent.data( CollectionRole ).value<Collection>();
892 
893  if ( !collection.isValid() ) {
894  return;
895  }
896 
897  d->fetchItems( collection );
898  }
899 }
900 
901 bool EntityTreeModel::hasChildren( const QModelIndex &parent ) const
902 {
903  Q_D( const EntityTreeModel );
904 
905  if ( d->m_collectionFetchStrategy == InvisibleCollectionFetch ||
906  d->m_collectionFetchStrategy == FetchNoCollections ) {
907  return parent.isValid() ? false : !d->m_items.isEmpty();
908  }
909 
910  // TODO: Empty collections right now will return true and get a little + to expand.
911  // There is probably no way to tell if a collection
912  // has child items in akonadi without first attempting an itemFetchJob...
913  // Figure out a way to fix this. (Statistics)
914  return ( ( rowCount( parent ) > 0 ) ||
915  ( canFetchMore( parent ) && d->m_itemPopulation == LazyPopulation ) );
916 }
917 
918 bool EntityTreeModel::isCollectionTreeFetched() const
919 {
920  Q_D( const EntityTreeModel );
921 
922  return d->m_collectionTreeFetched;
923 }
924 
925 bool EntityTreeModel::isCollectionPopulated( Collection::Id id ) const
926 {
927  Q_D( const EntityTreeModel );
928  return d->m_populatedCols.contains( id );
929 }
930 
931 bool EntityTreeModel::entityMatch( const Item &item, const QVariant &value, Qt::MatchFlags flags ) const
932 {
933  Q_UNUSED( item );
934  Q_UNUSED( value );
935  Q_UNUSED( flags );
936  return false;
937 }
938 
939 bool EntityTreeModel::entityMatch( const Collection &collection, const QVariant &value, Qt::MatchFlags flags ) const
940 {
941  Q_UNUSED( collection );
942  Q_UNUSED( value );
943  Q_UNUSED( flags );
944  return false;
945 }
946 
947 QModelIndexList EntityTreeModel::match( const QModelIndex& start, int role, const QVariant& value, int hits, Qt::MatchFlags flags ) const
948 {
949  Q_D( const EntityTreeModel );
950 
951  if ( role == CollectionIdRole || role == CollectionRole ) {
952  Collection::Id id;
953  if ( role == CollectionRole ) {
954  const Collection collection = value.value<Collection>();
955  id = collection.id();
956  } else {
957  id = value.toLongLong();
958  }
959 
960  QModelIndexList list;
961 
962  const Collection collection = d->m_collections.value( id );
963 
964  if ( !collection.isValid() ) {
965  return list;
966  }
967 
968  const QModelIndex collectionIndex = d->indexForCollection( collection );
969  Q_ASSERT( collectionIndex.isValid() );
970  list << collectionIndex;
971 
972  return list;
973  }
974 
975  if ( role == ItemIdRole || role == ItemRole ) {
976  Item::Id id;
977  if ( role == ItemRole ) {
978  const Item item = value.value<Item>();
979  id = item.id();
980  } else {
981  id = value.toLongLong();
982  }
983  QModelIndexList list;
984 
985  const Item item = d->m_items.value( id );
986  if ( !item.isValid() ) {
987  return list;
988  }
989 
990  return d->indexesForItem( item );
991  }
992 
993  if ( role == EntityUrlRole ) {
994  const KUrl url( value.toString() );
995  const Item item = Item::fromUrl( url );
996 
997  if ( item.isValid() ) {
998  return d->indexesForItem( d->m_items.value( item.id() ) );
999  }
1000 
1001  const Collection collection = Collection::fromUrl( url );
1002  QModelIndexList list;
1003  if ( collection.isValid() ) {
1004  list << d->indexForCollection( collection );
1005  }
1006 
1007  return list;
1008  }
1009 
1010  if ( role != AmazingCompletionRole ) {
1011  return QAbstractItemModel::match( start, role, value, hits, flags );
1012  }
1013 
1014  // Try to match names, and email addresses.
1015  QModelIndexList list;
1016 
1017  if ( role < 0 ||
1018  !start.isValid() ||
1019  !value.isValid() ) {
1020  return list;
1021  }
1022 
1023  const int column = 0;
1024  int row = start.row();
1025  const QModelIndex parentIndex = start.parent();
1026  const int parentRowCount = rowCount( parentIndex );
1027 
1028  while ( row < parentRowCount &&
1029  ( hits == -1 || list.size() < hits ) ) {
1030  const QModelIndex idx = index( row, column, parentIndex );
1031  const Item item = idx.data( ItemRole ).value<Item>();
1032 
1033  if ( !item.isValid() ) {
1034  const Collection collection = idx.data( CollectionRole ).value<Collection>();
1035  if ( !collection.isValid() ) {
1036  continue;
1037  }
1038 
1039  if ( entityMatch( collection, value, flags ) ) {
1040  list << idx;
1041  }
1042 
1043  } else {
1044  if ( entityMatch( item, value, flags ) ) {
1045  list << idx;
1046  }
1047  }
1048 
1049  ++row;
1050  }
1051 
1052  return list;
1053 }
1054 
1055 bool EntityTreeModel::insertRows( int, int, const QModelIndex& )
1056 {
1057  return false;
1058 }
1059 
1060 bool EntityTreeModel::insertColumns( int, int, const QModelIndex& )
1061 {
1062  return false;
1063 }
1064 
1065 bool EntityTreeModel::removeRows( int, int, const QModelIndex& )
1066 {
1067  return false;
1068 }
1069 
1070 bool EntityTreeModel::removeColumns( int, int, const QModelIndex& )
1071 {
1072  return false;
1073 }
1074 
1075 void EntityTreeModel::setItemPopulationStrategy( ItemPopulationStrategy strategy )
1076 {
1077  Q_D( EntityTreeModel );
1078  d->beginResetModel();
1079  d->m_itemPopulation = strategy;
1080 
1081  if ( strategy == NoItemPopulation ) {
1082  disconnect( d->m_monitor, SIGNAL(itemAdded(Akonadi::Item,Akonadi::Collection)),
1083  this, SLOT(monitoredItemAdded(Akonadi::Item,Akonadi::Collection)) );
1084  disconnect( d->m_monitor, SIGNAL(itemChanged(Akonadi::Item,QSet<QByteArray>)),
1085  this, SLOT(monitoredItemChanged(Akonadi::Item,QSet<QByteArray>)) );
1086  disconnect( d->m_monitor, SIGNAL(itemRemoved(Akonadi::Item)),
1087  this, SLOT(monitoredItemRemoved(Akonadi::Item)) );
1088  disconnect( d->m_monitor, SIGNAL(itemMoved(Akonadi::Item,Akonadi::Collection,Akonadi::Collection)),
1089  this, SLOT(monitoredItemMoved(Akonadi::Item,Akonadi::Collection,Akonadi::Collection)) );
1090 
1091  disconnect( d->m_monitor, SIGNAL(itemLinked(Akonadi::Item,Akonadi::Collection)),
1092  this, SLOT(monitoredItemLinked(Akonadi::Item,Akonadi::Collection)) );
1093  disconnect( d->m_monitor, SIGNAL(itemUnlinked(Akonadi::Item,Akonadi::Collection)),
1094  this, SLOT(monitoredItemUnlinked(Akonadi::Item,Akonadi::Collection)) );
1095  }
1096 
1097  d->m_monitor->d_ptr->useRefCounting = ( strategy == LazyPopulation );
1098 
1099  d->endResetModel();
1100 }
1101 
1102 EntityTreeModel::ItemPopulationStrategy EntityTreeModel::itemPopulationStrategy() const
1103 {
1104  Q_D( const EntityTreeModel );
1105  return d->m_itemPopulation;
1106 }
1107 
1108 void EntityTreeModel::setIncludeRootCollection( bool include )
1109 {
1110  Q_D( EntityTreeModel );
1111  d->beginResetModel();
1112  d->m_showRootCollection = include;
1113  d->endResetModel();
1114 }
1115 
1116 bool EntityTreeModel::includeRootCollection() const
1117 {
1118  Q_D( const EntityTreeModel );
1119  return d->m_showRootCollection;
1120 }
1121 
1122 void EntityTreeModel::setRootCollectionDisplayName( const QString &displayName )
1123 {
1124  Q_D( EntityTreeModel );
1125  d->m_rootCollectionDisplayName = displayName;
1126 
1127  // TODO: Emit datachanged if it is being shown.
1128 }
1129 
1130 QString EntityTreeModel::rootCollectionDisplayName() const
1131 {
1132  Q_D( const EntityTreeModel );
1133  return d->m_rootCollectionDisplayName;
1134 }
1135 
1136 void EntityTreeModel::setCollectionFetchStrategy( CollectionFetchStrategy strategy )
1137 {
1138  Q_D( EntityTreeModel );
1139  d->beginResetModel();
1140  d->m_collectionFetchStrategy = strategy;
1141 
1142  if ( strategy == FetchNoCollections ||
1143  strategy == InvisibleCollectionFetch ) {
1144  disconnect( d->m_monitor, SIGNAL(collectionChanged(Akonadi::Collection)),
1145  this, SLOT(monitoredCollectionChanged(Akonadi::Collection)) );
1146  disconnect( d->m_monitor, SIGNAL(collectionAdded(Akonadi::Collection,Akonadi::Collection)),
1147  this, SLOT(monitoredCollectionAdded(Akonadi::Collection,Akonadi::Collection)) );
1148  disconnect( d->m_monitor, SIGNAL(collectionRemoved(Akonadi::Collection)),
1149  this, SLOT(monitoredCollectionRemoved(Akonadi::Collection)) );
1150  disconnect( d->m_monitor,
1151  SIGNAL(collectionMoved(Akonadi::Collection,Akonadi::Collection,Akonadi::Collection)),
1152  this, SLOT(monitoredCollectionMoved(Akonadi::Collection,Akonadi::Collection,Akonadi::Collection)) );
1153  d->m_monitor->fetchCollection( false );
1154  } else
1155  d->m_monitor->fetchCollection( true );
1156 
1157  d->endResetModel();
1158 }
1159 
1160 EntityTreeModel::CollectionFetchStrategy EntityTreeModel::collectionFetchStrategy() const
1161 {
1162  Q_D( const EntityTreeModel );
1163  return d->m_collectionFetchStrategy;
1164 }
1165 
1166 static QPair<QList<const QAbstractProxyModel *>, const EntityTreeModel *> proxiesAndModel( const QAbstractItemModel *model )
1167 {
1168  QList<const QAbstractProxyModel *> proxyChain;
1169  const QAbstractProxyModel *proxy = qobject_cast<const QAbstractProxyModel *>( model );
1170  const QAbstractItemModel *_model = model;
1171  while ( proxy ) {
1172  proxyChain.prepend( proxy );
1173  _model = proxy->sourceModel();
1174  proxy = qobject_cast<const QAbstractProxyModel *>( _model );
1175  }
1176 
1177  const EntityTreeModel *etm = qobject_cast<const EntityTreeModel *>( _model );
1178  return qMakePair( proxyChain, etm );
1179 }
1180 
1181 static QModelIndex proxiedIndex( const QModelIndex &idx, QList<const QAbstractProxyModel *> proxyChain )
1182 {
1183  QListIterator<const QAbstractProxyModel *> it( proxyChain );
1184  QModelIndex _idx = idx;
1185  while ( it.hasNext() ) {
1186  _idx = it.next()->mapFromSource( _idx );
1187  }
1188  return _idx;
1189 }
1190 
1191 QModelIndex EntityTreeModel::modelIndexForCollection( const QAbstractItemModel *model, const Collection &collection )
1192 {
1193  QPair<QList<const QAbstractProxyModel *>, const EntityTreeModel*> pair = proxiesAndModel( model );
1194 
1195  Q_ASSERT( pair.second );
1196  QModelIndex idx = pair.second->d_ptr->indexForCollection( collection );
1197  return proxiedIndex( idx, pair.first );
1198 }
1199 
1200 QModelIndexList EntityTreeModel::modelIndexesForItem( const QAbstractItemModel *model, const Item &item )
1201 {
1202  QPair<QList<const QAbstractProxyModel *>, const EntityTreeModel*> pair = proxiesAndModel( model );
1203 
1204  if ( !pair.second ) {
1205  kWarning() << "Couldn't find an EntityTreeModel";
1206  return QModelIndexList();
1207  }
1208 
1209  QModelIndexList list = pair.second->d_ptr->indexesForItem( item );
1210  QModelIndexList proxyList;
1211  foreach ( const QModelIndex &idx, list ) {
1212  const QModelIndex pIdx = proxiedIndex( idx, pair.first );
1213  if ( pIdx.isValid() ) {
1214  proxyList << pIdx;
1215  }
1216  }
1217  return proxyList;
1218 }
1219 
1220 #include "moc_entitytreemodel.cpp"
Akonadi::Monitor::setAllMonitored
void setAllMonitored(bool monitored=true)
Sets whether all items shall be monitored.
Definition: monitor.cpp:188
Akonadi::EntityTreeModel::entityMatch
virtual bool entityMatch(const Item &item, const QVariant &value, Qt::MatchFlags flags) const
Reimplement this in a subclass to return true if item matches value with flags in the AmazingCompleti...
Definition: entitytreemodel.cpp:931
Akonadi::CollectionModifyJob
Job that modifies a collection in the Akonadi storage.
Definition: collectionmodifyjob.h:82
Akonadi::EntityTreeModel::setIncludeRootCollection
void setIncludeRootCollection(bool include)
Sets whether the root collection shall be provided by the model.
Definition: entitytreemodel.cpp:1108
Akonadi::EntityTreeModel::LoadedPartsRole
Parts available in the model for the item.
Definition: entitytreemodel.h:342
Akonadi::EntityTreeModel::systemEntitiesShown
bool systemEntitiesShown() const
Returns true if internal system entities are shown, and false otherwise.
Definition: entitytreemodel.cpp:104
Akonadi::Collection::name
QString name() const
Returns the i18n'ed name of the collection.
Definition: collection.cpp:81
Akonadi::EntityDisplayAttribute::iconName
QString iconName() const
Returns the icon name of the icon returned by icon().
Definition: entitydisplayattribute.cpp:64
Akonadi::EntityTreeModel::CollectionIdRole
The collection id.
Definition: entitytreemodel.h:334
Akonadi::EntityTreeModel::UnreadCountRole
Returns the number of unread items in a collection.
Definition: entitytreemodel.h:349
Akonadi::Collection::displayName
QString displayName() const
Returns the display name (EntityDisplayAttribute::displayName()) if set, and Collection::name() other...
Definition: collection.cpp:86
Akonadi::EntityTreeModel::entityData
virtual QVariant entityData(const Item &item, int column, int role=Qt::DisplayRole) const
Provided for convenience of subclasses.
Definition: entitytreemodel.cpp:134
Akonadi::EntityTreeModel::TerminalUserRole
Last role for user extensions. Don't use a role beyond this or headerData will break.
Definition: entitytreemodel.h:354
Akonadi::EntityTreeModel::CollectionRefRole
Definition: entitytreemodel.h:345
Akonadi::CollectionStatistics
Provides statistics information of a Collection.
Definition: collectionstatistics.h:69
Akonadi::EntityTreeModel::FetchStateRole
Returns the FetchState of a particular item.
Definition: entitytreemodel.h:350
Akonadi::EntityTreeModelPrivate::indexForCollection
QModelIndex indexForCollection(const Collection &collection) const
Returns the model index for the given collection.
Akonadi::EntityTreeModel::InvisibleCollectionFetch
Fetches collections, but does not put them in the model. This can be used to create a list of items i...
Definition: entitytreemodel.h:488
Akonadi::Collection::url
KUrl url() const
Returns the url of the collection.
Definition: collection.cpp:154
Akonadi::EntityTreeModel::ItemPopulationStrategy
ItemPopulationStrategy
Describes how the model should populated its items.
Definition: entitytreemodel.h:406
Akonadi::EntityTreeModelPrivate::indexOf
int indexOf(const QList< Node * > &nodes, Entity::Id id) const
Returns the index of the node in list with the id id.
Definition: entitytreemodel_p.h:193
Akonadi::EntityDisplayAttribute::displayName
QString displayName() const
Returns the name that should be used for display.
Definition: entitydisplayattribute.cpp:49
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::EntityTreeModel::NoItemPopulation
Do not include items in the model.
Definition: entitytreemodel.h:407
Akonadi::Entity::Id
qint64 Id
Describes the unique id type.
Definition: entity.h:65
Akonadi::Collection::mimeType
static QString mimeType()
Returns the mimetype used for collections.
Definition: collection.cpp:197
Akonadi::Collection::CanCreateCollection
Can create new subcollections in this collection.
Definition: collection.h:92
Akonadi::PasteHelper::pasteUriList
KJob * pasteUriList(const QMimeData *mimeData, const Collection &collection, Qt::DropAction action, Session *session=0)
URI list paste/drop.
Definition: pastehelper.cpp:126
Akonadi::Collection::CanChangeItem
Can change items in this collection.
Definition: collection.h:88
Akonadi::MimeTypeChecker
Helper for checking MIME types of Collections and Items.
Definition: mimetypechecker.h:109
Akonadi::EntityTreeModel::entityHeaderData
virtual QVariant entityHeaderData(int section, Qt::Orientation orientation, int role, HeaderGroup headerGroup) const
Reimplement this to provide different header data.
Definition: entitytreemodel.cpp:693
Akonadi::EntityTreeModel::IdleState
There is no fetch of items in this collection in progress.
Definition: entitytreemodel.h:373
Akonadi::EntityTreeModel::isCollectionPopulated
bool isCollectionPopulated(Akonadi::Collection::Id) const
Returns whether the collection has been populated.
Definition: entitytreemodel.cpp:925
Akonadi::Collection::setName
void setName(const QString &name)
Sets the i18n'ed name of the collection.
Definition: collection.cpp:93
Akonadi::EntityTreeModel::CollectionSyncProgressRole
Returns the progress of synchronization in percent for a particular collection.
Definition: entitytreemodel.h:351
Akonadi::EntityTreeModel::CollectionTreeHeaders
Header information for a collection-only tree.
Definition: entitytreemodel.h:383
Akonadi::EntityTreeModel::HeaderGroup
HeaderGroup
Describes what header information the model shall return.
Definition: entitytreemodel.h:381
Akonadi::EntityTreeModel::LazyPopulation
Fetch items only when requested (using canFetchMore/fetchMore)
Definition: entitytreemodel.h:409
Akonadi::EntityTreeModel::IsPopulatedRole
Returns whether a Collection has been populated, i.e. whether its items have been fetched...
Definition: entitytreemodel.h:352
Akonadi::Entity::attribute
Attribute * attribute(const QByteArray &name) const
Returns the attribute of the given type name if available, 0 otherwise.
Definition: entity.cpp:165
Akonadi::EntityTreeModel::setCollectionFetchStrategy
void setCollectionFetchStrategy(CollectionFetchStrategy strategy)
Sets the collection fetch strategy of the model.
Definition: entitytreemodel.cpp:1136
Akonadi::Collection::CanLinkItem
Can create links to existing items in this virtual collection.
Definition: collection.h:94
Akonadi::Entity::parentCollection
Collection parentCollection() const
Returns the parent collection of this object.
Definition: entity.cpp:186
Akonadi::EntityTreeModel::itemPopulationStrategy
ItemPopulationStrategy itemPopulationStrategy() const
Returns the item population strategy of the model.
Definition: entitytreemodel.cpp:1102
Akonadi::Collection::UrlWithName
A url with identifier and name.
Definition: collection.h:266
Akonadi::EntityTreeModel::AmazingCompletionRole
Role used to implement amazing completion.
Definition: entitytreemodel.h:339
Akonadi::EntityTreeModelPrivate::indexesForItem
QModelIndexList indexesForItem(const Item &item) const
Returns the model indexes for the given item.
Akonadi::Entity::remoteId
QString remoteId() const
Returns the remote id of the entity.
Definition: entity.cpp:82
Akonadi::MimeTypeChecker::wantedMimeTypes
QStringList wantedMimeTypes() const
Returns the list of wanted MIME types this instance checks against.
Definition: mimetypechecker.cpp:51
Akonadi::EntityDisplayAttribute::setBackgroundColor
void setBackgroundColor(const QColor &color)
Sets the backgroundColor to color.
Definition: entitydisplayattribute.cpp:158
Akonadi::Collection::CanCreateItem
Can create new items in this collection.
Definition: collection.h:89
Akonadi::Collection::root
static Collection root()
Returns the root collection.
Definition: collection.cpp:192
Akonadi::EntityTreeModel::CollectionRole
The collection.
Definition: entitytreemodel.h:335
Akonadi::EntityTreeModel::ParentCollectionRole
The parent collection of the entity.
Definition: entitytreemodel.h:340
Akonadi::EntityTreeModel::RemoteIdRole
The remoteId of the entity.
Definition: entitytreemodel.h:337
Akonadi::EntityTreeModel::rootCollectionDisplayName
QString rootCollectionDisplayName() const
Returns the display name of the root collection.
Definition: entitytreemodel.cpp:1130
Akonadi::EntityDisplayAttribute::setDisplayName
void setDisplayName(const QString &name)
Sets the name that should be used for display.
Definition: entitydisplayattribute.cpp:54
Akonadi::Monitor::fetchCollection
void fetchCollection(bool enable)
Enables automatic fetching of changed collections from the Akonadi storage.
Definition: monitor.cpp:221
Akonadi::Entity::id
Id id() const
Returns the unique identifier of the entity.
Definition: entity.cpp:72
Akonadi::EntityTreeModel::ImmediatePopulation
Retrieve items immediately when their parent is in the model. This is the default.
Definition: entitytreemodel.h:408
Akonadi::MimeTypeChecker::isWantedCollection
bool isWantedCollection(const Collection &collection) const
Checks whether a given collection has one of the wanted MIME types.
Definition: mimetypechecker.cpp:83
Akonadi::Collection::rights
Rights rights() const
Returns the rights the user has on the collection.
Definition: collection.cpp:99
Akonadi::EntityTreeModel::modelIndexForCollection
static QModelIndex modelIndexForCollection(const QAbstractItemModel *model, const Collection &collection)
Returns a QModelIndex in model which points to collection.
Definition: entitytreemodel.cpp:1191
Akonadi::EntityTreeModel::setRootCollectionDisplayName
void setRootCollectionDisplayName(const QString &name)
Sets the display name of the root collection of the model.
Definition: entitytreemodel.cpp:1122
Akonadi::EntityTreeModel::setItemPopulationStrategy
void setItemPopulationStrategy(ItemPopulationStrategy strategy)
Sets the item population strategy of the model.
Definition: entitytreemodel.cpp:1075
Akonadi::EntityTreeModel::FetchNoCollections
Fetches nothing. This creates an empty model.
Definition: entitytreemodel.h:485
Akonadi::EntityTreeModel::clearAndReset
void clearAndReset()
Clears and resets the model.
Definition: entitytreemodel.cpp:116
Akonadi::EntityTreeModel::ItemListHeaders
Header information for a list of items.
Definition: entitytreemodel.h:384
Akonadi::EntityDisplayAttribute::backgroundColor
QColor backgroundColor() const
Returns the backgroundColor or an invalid color if none is set.
Definition: entitydisplayattribute.cpp:153
Akonadi::EntityTreeModel::AvailablePartsRole
Parts available in the Akonadi server for the item.
Definition: entitytreemodel.h:343
Akonadi::MimeTypeChecker::setWantedMimeTypes
void setWantedMimeTypes(const QStringList &mimeTypes)
Sets the list of wanted MIME types this instance checks against.
Definition: mimetypechecker.cpp:56
Akonadi::EntityTreeModelPrivate::childCollectionNames
QStringList childCollectionNames(const Collection &collection) const
Returns the list of names of the child collections of collection.
Akonadi::EntityTreeModel::collectionFetchStrategy
CollectionFetchStrategy collectionFetchStrategy() const
Returns the collection fetch strategy of the model.
Definition: entitytreemodel.cpp:1160
Akonadi::EntityTreeModel::MimeTypeRole
The mimetype of the entity.
Definition: entitytreemodel.h:332
Akonadi::EntityTreeModel::setShowSystemEntities
void setShowSystemEntities(bool show)
Some Entities are hidden in the model, but exist for internal purposes, for example, custom object directories in groupware resources.
Definition: entitytreemodel.cpp:110
Akonadi::EntityTreeModel::ItemRole
The Item.
Definition: entitytreemodel.h:331
Akonadi::MimeTypeChecker::isWantedItem
bool isWantedItem(const Item &item) const
Checks whether a given item has one of the wanted MIME types.
Definition: mimetypechecker.cpp:71
Akonadi::Entity::hasAttribute
bool hasAttribute(const QByteArray &name) const
Returns true if the entity has an attribute of the given type name, false otherwise.
Definition: entity.cpp:146
Akonadi::EntityTreeModel
A model for collections and items together.
Definition: entitytreemodel.h:317
Akonadi::ItemModifyJob
Job that modifies an existing item in the Akonadi storage.
Definition: itemmodifyjob.h:97
Akonadi::EntityTreeModel::PendingCutRole
Definition: entitytreemodel.h:347
Akonadi::EntityTreeModel::ColumnCountRole
Definition: entitytreemodel.h:341
Akonadi::EntityTreeModel::FetchingState
There is a fetch of items in this collection in progress.
Definition: entitytreemodel.h:374
Akonadi::CollectionStatistics::unreadCount
qint64 unreadCount() const
Returns the number of unread items in this collection or -1 if this information is not available...
Definition: collectionstatistics.cpp:77
Akonadi::Collection::contentMimeTypes
QStringList contentMimeTypes() const
Returns a list of possible content mimetypes, e.g.
Definition: collection.cpp:115
Akonadi::Entity::AddIfMissing
Creates the attribute if it is missing.
Definition: entity.h:205
Akonadi::EntityTreeModel::isCollectionTreeFetched
bool isCollectionTreeFetched() const
Returns whether the collection tree has been fetched at initialisation.
Definition: entitytreemodel.cpp:918
Akonadi::EntityTreeModel::~EntityTreeModel
virtual ~EntityTreeModel()
Destroys the entity tree model.
Definition: entitytreemodel.cpp:72
Akonadi::EntityTreeModelPrivate
Definition: entitytreemodel_p.h:60
Akonadi::EntityTreeModel::modelIndexesForItem
static QModelIndexList modelIndexesForItem(const QAbstractItemModel *model, const Item &item)
Returns a QModelIndex in model which points to item.
Definition: entitytreemodel.cpp:1200
Akonadi::EntityTreeModel::match
virtual QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
Reimplemented to handle the AmazingCompletionRole.
Definition: entitytreemodel.cpp:947
Akonadi::EntityTreeModel::EntityUrlRole
The akonadi:/ Url of the entity as a string. Item urls will contain the mimetype. ...
Definition: entitytreemodel.h:348
Akonadi::Entity::isValid
bool isValid() const
Returns whether the entity is valid.
Definition: entity.cpp:97
Akonadi::EntityTreeModel::CollectionFetchStrategy
CollectionFetchStrategy
Describes what collections shall be fetched by and represent in the model.
Definition: entitytreemodel.h:484
Akonadi::EntityTreeModel::SessionRole
Definition: entitytreemodel.h:344
Akonadi::EntityTreeModel::includeUnsubscribed
bool includeUnsubscribed() const
Returns whether unsubscribed entities will be included in the listing.
Definition: entitytreemodel.cpp:89
Akonadi::Collection::fromUrl
static Collection fromUrl(const KUrl &url)
Creates a collection from the given url.
Definition: collection.cpp:172
Akonadi::Collection::statistics
CollectionStatistics statistics() const
Returns the collection statistics of the collection.
Definition: collection.cpp:238
Akonadi::EntityTreeModel::includeRootCollection
bool includeRootCollection() const
Returns whether the root collection is provided by the model.
Definition: entitytreemodel.cpp:1116
Akonadi::EntityDisplayAttribute
Attribute that stores the properties that are used to display an entity.
Definition: entitydisplayattribute.h:39
Akonadi::Collection::CanChangeCollection
Can change this collection.
Definition: collection.h:91
Akonadi::EntityTreeModel::setIncludeUnsubscribed
void setIncludeUnsubscribed(bool show)
Sets whether unsubscribed entities will be included in the listing.
Definition: entitytreemodel.cpp:95
Akonadi::EntityTreeModel::CollectionDerefRole
Definition: entitytreemodel.h:346
Akonadi::ChangeRecorder
Records and replays change notification.
Definition: changerecorder.h:47
Akonadi::EntityTreeModel::ItemIdRole
The item id.
Definition: entitytreemodel.h:330
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Mon Jul 21 2014 08:03:52 by doxygen 1.8.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

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

kdepimlibs-4.13.3 API Reference

Skip menu "kdepimlibs-4.13.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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