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

akonadi

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

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

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