20 #include "subscriptionmodel_p.h"
21 #include "collectionfetchjob.h"
22 #include "collectionutils_p.h"
23 #include "specialcollectionattribute_p.h"
25 #include "entityhiddenattribute.h"
29 #include <QtCore/QStringList>
32 using namespace Akonadi;
37 class SubscriptionModel::Private
42 QHash<Collection::Id, bool> subscriptions;
43 QSet<Collection::Id> changes;
50 if ( subscriptions.value(
id ) == subscribed )
56 void listResult( KJob* job )
60 kWarning() << job->errorString();
65 if ( !CollectionUtils::isStructural( col ) )
66 subscriptions[ col.
id() ] =
true;
74 if ( CollectionUtils::isStructural( col ) || col.
isVirtual() )
86 d( new Private( this ) )
90 connect( job, SIGNAL(result(KJob*)),
this, SLOT(listResult(KJob*)) );
98 QVariant SubscriptionModel::data(
const QModelIndex & index,
int role)
const
101 case Qt::CheckStateRole:
104 if ( !d->isSubscribable( col ) )
106 if ( d->subscriptions.value( col ) )
108 return Qt::Unchecked;
113 if ( d->changes.contains( col ) )
121 QFont font = CollectionModel::data( index, role ).value<QFont>();
122 font.setBold( d->changes.contains( col ) );
134 if(d->showHiddenCollection) {
135 return CollectionModel::data( index, role );
140 return CollectionModel::data( index, role );
145 Qt::ItemFlags SubscriptionModel::flags(
const QModelIndex & index)
const
147 Qt::ItemFlags flags = CollectionModel::flags( index );
149 return flags | Qt::ItemIsUserCheckable;
153 bool SubscriptionModel::setData(
const QModelIndex & index,
const QVariant & value,
int role)
155 if ( role == Qt::CheckStateRole ) {
157 if( !d->isSubscribable(col) ) {
160 if ( d->subscriptions.contains( col ) && d->subscriptions.value( col ) == (value == Qt::Checked) )
162 d->subscriptions[ col ] = value == Qt::Checked;
163 if ( d->changes.contains( col ) )
164 d->changes.remove( col );
166 d->changes.insert( col );
167 emit dataChanged( index, index );
170 return CollectionModel::setData( index, value, role );
175 return d->changedSubscriptions(
true );
180 return d->changedSubscriptions(
false );
185 d->showHiddenCollection = showHidden;
188 #include "moc_subscriptionmodel_p.cpp"