Commit 8a2c1f7e authored by Guy Maurel's avatar Guy Maurel

some more spaces, some less spaces, some more blocks, part 2 from akonadi

parent 1faa214a
......@@ -70,8 +70,9 @@ bool CollectionFilterProxyModel::Private::collectionAccepted( const QModelIndex
// find the resource
QModelIndex resource = index;
while ( resource.parent().isValid() )
while ( resource.parent().isValid() ) {
resource = resource.parent();
}
// See if that resource is visible, if not, invalidate the filter.
if ( resource != index && !acceptedResources.contains( resource ) ) {
......
......@@ -80,7 +80,7 @@ void ConflictHandler::resolve()
dlg.exec();
const ResolveStrategy strategy = dlg.resolveStrategy();
switch( strategy ) {
switch ( strategy ) {
case UseLocalItem:
useLocalItem();
break;
......
......@@ -342,7 +342,7 @@ class StandardContactActionManager::Private
return Collection();
}
return index.data( EntityTreeModel::CollectionRole).value<Collection>();
return index.data( EntityTreeModel::CollectionRole ).value<Collection>();
}
void slotCreateContact()
......
......@@ -165,8 +165,9 @@ void Akonadi::Entity::clearAttributes()
Attribute * Entity::attribute(const QByteArray & type) const
{
if ( d_ptr->mAttributes.contains( type ) )
if ( d_ptr->mAttributes.contains( type ) ) {
return d_ptr->mAttributes.value( type );
}
return 0;
}
......@@ -177,17 +178,19 @@ uint qHash( const Akonadi::Entity &entity )
Collection& Entity::parentCollection()
{
if ( !d_ptr->mParent )
if ( !d_ptr->mParent ) {
d_ptr->mParent = new Collection();
return *(d_ptr->mParent);
}
return *( d_ptr->mParent );
}
Collection Entity::parentCollection() const
{
if ( !d_ptr->mParent )
return *(s_defaultParentCollection);
else
return *(d_ptr->mParent);
if ( !d_ptr->mParent ) {
return *( s_defaultParentCollection );
} else {
return *( d_ptr->mParent );
}
}
void Entity::setParentCollection( const Collection &parent )
......
......@@ -199,8 +199,7 @@ class AKONADI_EXPORT Entity
/**
* Describes the options that can be passed to access attributes.
*/
enum CreateOption
{
enum CreateOption {
AddIfMissing ///< Creates the attribute if it is missing
};
......@@ -218,8 +217,9 @@ class AKONADI_EXPORT Entity
const T dummy;
if ( hasAttribute( dummy.type() ) ) {
T* attr = dynamic_cast<T*>( attribute( dummy.type() ) );
if ( attr )
if ( attr ) {
return attr;
}
kWarning( 5250 ) << "Found attribute of unknown type" << dummy.type()
<< ". Did you forget to call AttributeFactory::registerAttribute()?";
}
......
......@@ -58,11 +58,13 @@ class EntityPrivate : public QSharedData
mId = other.mId;
mRemoteId = other.mRemoteId;
mRemoteRevision = other.mRemoteRevision;
foreach ( Attribute* attr, other.mAttributes )
foreach ( Attribute *attr, other.mAttributes ) {
mAttributes.insert( attr->type(), attr->clone() );
}
mDeletedAttributes = other.mDeletedAttributes;
if ( other.mParent )
mParent = new Collection( *(other.mParent) );
if ( other.mParent ) {
mParent = new Collection( *( other.mParent ) );
}
}
virtual void resetChangeLog()
......
......@@ -107,8 +107,9 @@ class EntityCache : public EntityCacheBase
virtual T retrieve( typename T::Id id ) const
{
EntityCacheNode<T>* node = cacheNodeForId( id );
if ( node && !node->pending && !node->invalid )
if ( node && !node->pending && !node->invalid ) {
return node->entity;
}
return T();
}
......@@ -116,8 +117,9 @@ class EntityCache : public EntityCacheBase
void invalidate( typename T::Id id )
{
EntityCacheNode<T>* node = cacheNodeForId( id );
if ( node )
if ( node ) {
node->invalid = true;
}
}
/** Triggers a re-fetching of a cache entry, use if it has changed on the server. */
......@@ -126,8 +128,9 @@ class EntityCache : public EntityCacheBase
EntityCacheNode<T>* node = cacheNodeForId( id );
if ( node ) {
mCache.removeAll( node );
if ( node->pending )
if ( node->pending ) {
request( id, scope );
}
delete node;
}
}
......@@ -164,10 +167,10 @@ class EntityCache : public EntityCacheBase
EntityCacheNode<T>* cacheNodeForId( typename T::Id id ) const
{
for ( typename QQueue<EntityCacheNode<T>*>::const_iterator it = mCache.constBegin(), endIt = mCache.constEnd();
it != endIt; ++it )
{
if ( (*it)->entity.id() == id )
it != endIt; ++it ) {
if ( ( *it )->entity.id() == id ) {
return *it;
}
}
return 0;
}
......@@ -177,8 +180,9 @@ class EntityCache : public EntityCacheBase
// Error handling?
typename T::Id id = job->property( "EntityCacheNode" ).template value<typename T::Id>();
EntityCacheNode<T> *node = cacheNodeForId( id );
if ( !node )
if ( !node ) {
return; // got replaced in the meantime
}
node->pending = false;
extractResult( node, job );
......@@ -202,8 +206,9 @@ class EntityCache : public EntityCacheBase
/** Tries to reduce the cache size until at least one more object fits in. */
void shrinkCache()
{
while ( mCache.size() >= mCapacity && !mCache.first()->pending )
while ( mCache.size() >= mCapacity && !mCache.first()->pending ) {
delete mCache.dequeue();
}
}
private:
......@@ -215,20 +220,22 @@ template<> inline void EntityCache<Collection, CollectionFetchJob, CollectionFet
{
CollectionFetchJob* fetch = qobject_cast<CollectionFetchJob*>( job );
Q_ASSERT( fetch );
if ( fetch->collections().isEmpty() )
if ( fetch->collections().isEmpty() ) {
node->entity = Collection();
else
} else {
node->entity = fetch->collections().first();
}
}
template<> inline void EntityCache<Item, ItemFetchJob, ItemFetchScope>::extractResult( EntityCacheNode<Item>* node, KJob *job ) const
{
ItemFetchJob* fetch = qobject_cast<ItemFetchJob*>( job );
Q_ASSERT( fetch );
if ( fetch->items().isEmpty() )
if ( fetch->items().isEmpty() ) {
node->entity = Item();
else
} else {
node->entity = fetch->items().first();
}
}
template<> inline CollectionFetchJob* EntityCache<Collection, CollectionFetchJob, CollectionFetchScope>::createFetchJob( Collection::Id id )
......@@ -248,28 +255,29 @@ public:
{
bool val = true;
if (lhs_.size() != rhs_.size())
if ( lhs_.size() != rhs_.size() ) {
return false;
}
typename T::List lhs = lhs_;
QList<typename T::Id> rhs = rhs_;
qSort(lhs);
qSort(rhs);
qSort( lhs );
qSort( rhs );
return lhs == rhs;
}
static bool compare(const QList<typename T::Id> &l1, const typename T::List &l2)
{
return compare(l2, l1);
return compare( l2, l1 );
}
static bool compare(const typename T::List &l1, const typename T::List &l2)
{
typename T::List l1_ = l1;
typename T::List l2_ = l2;
qSort(l1_);
qSort(l2_);
qSort( l1_ );
qSort( l2_ );
return l1_ == l2_;
}
};
......@@ -280,8 +288,9 @@ struct EntityListCacheNode
{
EntityListCacheNode( const typename T::List &list ) : entityList( list ), pending( false ), invalid( false ) {}
EntityListCacheNode( const QList<typename T::Id> &list ) : pending( false ), invalid( false ) {
foreach( typename T::Id id, list)
entityList.append(T(id));
foreach ( typename T::Id id, list ) {
entityList.append( T( id ) );
}
}
typename T::List entityList;
bool pending;
......@@ -309,8 +318,9 @@ public:
typename T::List retrieve( const QList<TArg> &id ) const
{
EntityListCacheNode<T>* node = cacheNodeForId( id );
if ( node && !node->pending && !node->invalid )
if ( node && !node->pending && !node->invalid ) {
return node->entityList;
}
return typename T::List();
}
......@@ -331,8 +341,9 @@ public:
void invalidate( const QList<TArg> &id )
{
EntityListCacheNode<T>* node = cacheNodeForId( id );
if ( node )
if ( node ) {
node->invalid = true;
}
}
/** Triggers a re-fetching of a cache entry, use if it has changed on the server. */
......@@ -342,8 +353,9 @@ public:
EntityListCacheNode<T>* node = cacheNodeForId( id );
if ( node ) {
mCache.removeAll( node );
if ( node->pending )
if ( node->pending ) {
request( id, scope );
}
delete node;
}
}
......@@ -362,8 +374,9 @@ private:
typename T::List getTList( const QList<typename T::Id> &id )
{
typename T::List ids;
foreach(typename T::Id id_, id)
ids.append(T(id_));
foreach ( typename T::Id id_, id ) {
ids.append( T( id_ ) );
}
return ids;
}
......@@ -393,8 +406,9 @@ private:
/** Tries to reduce the cache size until at least one more object fits in. */
void shrinkCache()
{
while ( mCache.size() >= mCapacity && !mCache.first()->pending )
while ( mCache.size() >= mCapacity && !mCache.first()->pending ) {
delete mCache.dequeue();
}
}
/** Object has been requested but is not yet loaded into the cache or is already available. */
......@@ -408,10 +422,10 @@ private:
EntityListCacheNode<T>* cacheNodeForId( const QList<TArg> &id ) const
{
for ( typename QQueue<EntityListCacheNode<T>*>::const_iterator it = mCache.constBegin(), endIt = mCache.constEnd();
it != endIt; ++it )
{
if ( Comparator<T>::compare( ( *it )->entityList, id ) )
it != endIt; ++it ) {
if ( Comparator<T>::compare( ( *it )->entityList, id ) ) {
return *it;
}
}
return 0;
}
......@@ -427,8 +441,9 @@ private:
typename T::List ids = job->property( "EntityListCacheNode" ).template value<typename T::List>();
EntityListCacheNode<T> *node = cacheNodeForId( ids );
if ( !node )
if ( !node ) {
return; // got replaced in the meantime
}
node->pending = false;
extractResult( node, job );
......
......@@ -117,14 +117,16 @@ void EntityDeletedAttribute::deserialize( const QByteArray &data )
if ( !l[1].isEmpty() ) {
QList<QByteArray> componentData;
ImapParser::parseParenthesizedList( l[1], componentData );
if ( componentData.size() != 1 )
if ( componentData.size() != 1 ) {
return;
}
QList<int> components;
bool ok;
for ( int i = 0; i < 1; ++i ) {
components << componentData.at( i ).toInt( &ok );
if ( !ok )
if ( !ok ) {
return;
}
}
d->restoreCollection = Collection( components.at( 0 ) );
}
......
......@@ -93,8 +93,7 @@ QByteArray EntityDisplayAttribute::serialized() const
l << ImapParser::quote( d->icon.toUtf8() );
l << ImapParser::quote( d->activeIcon.toUtf8() );
QList<QByteArray> components;
if ( d->backgroundColor.isValid() )
{
if ( d->backgroundColor.isValid() ) {
components = QList<QByteArray>() << QByteArray::number( d->backgroundColor.red() )
<< QByteArray::number( d->backgroundColor.green() )
<< QByteArray::number( d->backgroundColor.blue() )
......@@ -115,22 +114,21 @@ void EntityDisplayAttribute::deserialize(const QByteArray &data)
if ( size >= 3 ) {
d->activeIcon = QString::fromUtf8( l[2] );
}
if ( size >= 4 )
{
if ( !l[3].isEmpty() )
{
if ( size >= 4 ) {
if ( !l[3].isEmpty() ) {
QList<QByteArray> componentData;
ImapParser::parseParenthesizedList( l[3], componentData );
if ( componentData.size() != 4 )
if ( componentData.size() != 4 ) {
return;
}
QList<int> components;
bool ok;
for ( int i = 0; i <= 3; ++i )
{
for ( int i = 0; i <= 3; ++i ) {
components << componentData.at( i ).toInt( &ok );
if ( !ok )
if ( !ok ) {
return;
}
}
d->backgroundColor = QColor( components.at( 0 ), components.at( 1 ), components.at( 2 ), components.at( 3 ) );
}
......
......@@ -59,7 +59,7 @@ public:
: mParent( parent )
#ifndef QT_NO_DRAGANDDROP
, mDragDropManager( new DragDropManager( mParent ) )
#endif
#endif
, mXmlGuiClient( 0 )
{
}
......@@ -88,55 +88,61 @@ void EntityListView::Private::init()
mParent->connect( mParent, SIGNAL(doubleClicked(QModelIndex)),
mParent, SLOT(itemDoubleClicked(QModelIndex)) );
DelegateAnimator *animator = new DelegateAnimator(mParent);
ProgressSpinnerDelegate *customDelegate = new ProgressSpinnerDelegate(animator, mParent);
mParent->setItemDelegate(customDelegate);
DelegateAnimator *animator = new DelegateAnimator( mParent );
ProgressSpinnerDelegate *customDelegate = new ProgressSpinnerDelegate( animator, mParent );
mParent->setItemDelegate( customDelegate );
Control::widgetNeedsAkonadi( mParent );
}
void EntityListView::Private::itemClicked( const QModelIndex &index )
{
if ( !index.isValid() )
if ( !index.isValid() ) {
return;
}
const Collection collection = index.model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
if ( collection.isValid() ) {
emit mParent->clicked( collection );
} else {
const Item item = index.model()->data( index, EntityTreeModel::ItemRole ).value<Item>();
if ( item.isValid() )
if ( item.isValid() ) {
emit mParent->clicked( item );
}
}
}
void EntityListView::Private::itemDoubleClicked( const QModelIndex &index )
{
if ( !index.isValid() )
if ( !index.isValid() ) {
return;
}
const Collection collection = index.model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
if ( collection.isValid() ) {
emit mParent->doubleClicked( collection );
} else {
const Item item = index.model()->data( index, EntityTreeModel::ItemRole ).value<Item>();
if ( item.isValid() )
if ( item.isValid() ) {
emit mParent->doubleClicked( item );
}
}
}
void EntityListView::Private::itemCurrentChanged( const QModelIndex &index )
{
if ( !index.isValid() )
if ( !index.isValid() ) {
return;
}
const Collection collection = index.model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
if ( collection.isValid() ) {
emit mParent->currentChanged( collection );
} else {
const Item item = index.model()->data( index, EntityTreeModel::ItemRole ).value<Item>();
if ( item.isValid() )
if ( item.isValid() ) {
emit mParent->currentChanged( item );
}
}
}
......@@ -178,7 +184,8 @@ void EntityListView::setModel( QAbstractItemModel * model )
#ifndef QT_NO_DRAGANDDROP
void EntityListView::dragMoveEvent( QDragMoveEvent * event )
{
if ( d->mDragDropManager->dropAllowed( event ) || qobject_cast<Akonadi::FavoriteCollectionsModel*>( model() ) ) {
if ( d->mDragDropManager->dropAllowed( event ) ||
qobject_cast<Akonadi::FavoriteCollectionsModel*>( model() ) ) {
// All urls are supported. process the event.
QListView::dragMoveEvent( event );
return;
......@@ -190,13 +197,14 @@ void EntityListView::dragMoveEvent( QDragMoveEvent * event )
void EntityListView::dropEvent( QDropEvent * event )
{
bool menuCanceled = false;
if ( d->mDragDropManager->processDropEvent( event, menuCanceled ) && !menuCanceled) {
if ( menuCanceled )
if ( d->mDragDropManager->processDropEvent( event, menuCanceled ) &&
!menuCanceled ) {
if ( menuCanceled ) {
return;
}
QListView::dropEvent( event );
}
else if ( qobject_cast<Akonadi::FavoriteCollectionsModel*>( model() ) &&!menuCanceled )
{
} else if ( qobject_cast<Akonadi::FavoriteCollectionsModel*>( model() ) &&
!menuCanceled ) {
QListView::dropEvent( event );
}
}
......@@ -205,8 +213,9 @@ void EntityListView::dropEvent( QDropEvent * event )
#ifndef QT_NO_CONTEXTMENU
void EntityListView::contextMenuEvent( QContextMenuEvent * event )
{
if ( !d->mXmlGuiClient )
if ( !d->mXmlGuiClient ) {
return;
}
const QModelIndex index = indexAt( event->pos() );
......@@ -219,11 +228,12 @@ void EntityListView::contextMenuEvent( QContextMenuEvent * event )
QLatin1String( "akonadi_favoriteview_contextmenu" ), d->mXmlGuiClient ) );
} else {
popup = static_cast<QMenu*>( d->mXmlGuiClient->factory()->container(
QLatin1String( "akonadi_favoriteview_emptyselection_contextmenu" ), d->mXmlGuiClient) );
QLatin1String( "akonadi_favoriteview_emptyselection_contextmenu" ), d->mXmlGuiClient ) );
}
if ( popup )
if ( popup ) {
popup->exec( event->globalPos() );
}
}
#endif
......
......@@ -189,7 +189,7 @@ class AKONADI_EXPORT EntityListView : public QListView
#ifndef QT_NO_CONTEXTMENU
virtual void contextMenuEvent( QContextMenuEvent *event );
#endif
private:
//@cond PRIVATE
class Private;
......
......@@ -45,7 +45,7 @@ class EntityMimeTypeFilterModelPrivate
{
}
Q_DECLARE_PUBLIC(EntityMimeTypeFilterModel)
Q_DECLARE_PUBLIC( EntityMimeTypeFilterModel )
EntityMimeTypeFilterModel *q_ptr;
QStringList includedMimeTypes;
......@@ -71,43 +71,44 @@ EntityMimeTypeFilterModel::~EntityMimeTypeFilterModel()
void EntityMimeTypeFilterModel::addMimeTypeInclusionFilters(const QStringList &typeList)
{
Q_D(EntityMimeTypeFilterModel);
Q_D( EntityMimeTypeFilterModel );
d->includedMimeTypes << typeList;
invalidateFilter();
}
void EntityMimeTypeFilterModel::addMimeTypeExclusionFilters(const QStringList &typeList)
{
Q_D(EntityMimeTypeFilterModel);
Q_D( EntityMimeTypeFilterModel );
d->excludedMimeTypes << typeList;
invalidateFilter();
}
void EntityMimeTypeFilterModel::addMimeTypeInclusionFilter(const QString &type)
{
Q_D(EntityMimeTypeFilterModel);
Q_D( EntityMimeTypeFilterModel );
d->includedMimeTypes << type;
invalidateFilter();
}
void EntityMimeTypeFilterModel::addMimeTypeExclusionFilter(const QString &type)
{
Q_D(EntityMimeTypeFilterModel);
Q_D( EntityMimeTypeFilterModel );
d->excludedMimeTypes << type;
invalidateFilter();
}
bool EntityMimeTypeFilterModel::filterAcceptsColumn( int sourceColumn, const QModelIndex &sourceParent ) const
{
if (sourceColumn >= columnCount(mapFromSource(sourceParent)))
if ( sourceColumn >= columnCount( mapFromSource( sourceParent ) ) ) {
return false;
}
return QSortFilterProxyModel::filterAcceptsColumn( sourceColumn, sourceParent );
}
bool EntityMimeTypeFilterModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent) const
{
Q_D(const EntityMimeTypeFilterModel);
const QModelIndex idx = sourceModel()->index(sourceRow, 0, sourceParent);
Q_D( const EntityMimeTypeFilterModel );
const QModelIndex idx = sourceModel()->index( sourceRow, 0, sourceParent );
const Akonadi::Item item = idx.data( EntityTreeModel::ItemRole ).value<Akonadi::Item>();
......@@ -118,29 +119,32 @@ bool EntityMimeTypeFilterModel::filterAcceptsRow( int sourceRow, const QModelInd
const QString rowMimetype = idx.data( EntityTreeModel::MimeTypeRole ).toString();
if ( d->excludedMimeTypes.contains( rowMimetype ) )
if ( d->excludedMimeTypes.contains( rowMimetype ) ) {
return false;
if ( d->includedMimeTypes.isEmpty() || d->includedMimeTypes.contains( rowMimetype ) )
}
if ( d->includedMimeTypes.isEmpty() ||
d->includedMimeTypes.contains( rowMimetype ) ) {
return true;
}
return false;
}