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>
30 #include <QtGui/QFont>
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 ) || CollectionUtils::isVirtual( col ) )
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->subscriptions.contains( col ) && d->subscriptions.value( col ) == (value == Qt::Checked) )
159 d->subscriptions[ col ] = value == Qt::Checked;
160 if ( d->changes.contains( col ) )
161 d->changes.remove( col );
163 d->changes.insert( col );
164 emit dataChanged( index, index );
167 return CollectionModel::setData( index, value, role );
172 return d->changedSubscriptions(
true );
177 return d->changedSubscriptions(
false );
182 d->showHiddenCollection = showHidden;
185 #include "subscriptionmodel_p.moc"