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>
37class SubscriptionModel::Private
40 Private(
SubscriptionModel* parent ) : q( parent ), showHiddenCollection(false) {}
42 QHash<Collection::Id, bool> subscriptions;
43 QSet<Collection::Id> changes;
44 bool showHiddenCollection;
50 if ( subscriptions.value(
id ) == subscribed )
51 list << Collection(
id );
56 void listResult( KJob* job )
60 kWarning() << job->errorString();
63 Collection::List cols =
static_cast<CollectionFetchJob*
>( job )->collections();
64 foreach (
const Collection &col, cols )
65 if ( !CollectionUtils::isStructural( col ) )
66 subscriptions[ col.
id() ] =
true;
73 Collection col = q->collectionForId(
id );
74 if ( CollectionUtils::isStructural( col ) || col.
isVirtual() )
86 d( new Private( this ) )
90 connect( job, SIGNAL(result(KJob*)),
this, SLOT(listResult(KJob*)) );
93SubscriptionModel::~ SubscriptionModel()
98QVariant 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 ) );
133 if ( collection.hasAttribute<EntityHiddenAttribute>() ) {
134 if (d->showHiddenCollection) {
135 return CollectionModel::data( index, role );
140 return CollectionModel::data( index, role );
145Qt::ItemFlags SubscriptionModel::flags(
const QModelIndex & index)
const
147 Qt::ItemFlags flags = CollectionModel::flags( index );
149 return flags | Qt::ItemIsUserCheckable;
153bool 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"
Job that fetches collections from the Akonadi storage.
@ Recursive
List all sub-collections.
@ CollectionIdRole
The collection identifier.
void includeUnsubscribed(bool include=true)
Sets whether unsubscribed collections shall be listed in the model.
CollectionModel(QObject *parent=0)
Creates a new collection model.
Collection collectionForId(Collection::Id id) const
Returns the collection for a given collection id.
QStringList contentMimeTypes() const
Returns a list of possible content mimetypes, e.g.
static Collection root()
Returns the root collection.
QList< Collection > List
Describes a list of collections.
bool isVirtual() const
Returns whether the collection is virtual, for example a search collection.
bool hasAttribute(const QByteArray &name) const
Returns true if the entity has an attribute of the given type name, false otherwise.
Id id() const
Returns the unique identifier of the entity.
qint64 Id
Describes the unique id type.
void showHiddenCollection(bool showHidden)
SubscriptionModel(QObject *parent=0)
Create a new subscription model.
@ SubscriptionChangedRole
Indicate the subscription status has been changed.
FreeBusyManager::Singleton.