Commit d78dd3da authored by Guy Maurel's avatar Guy Maurel

Coding Style

REVIEWS: 116359 116360 116361 116362 116363 116364 116365 116366 116367 116368 116369 116370 116371 116372 116374 116375 116376 116377 116378 116379 116380
parent 2ecc8dfc
......@@ -39,12 +39,12 @@ namespace Akonadi {
struct ProtocolHelperValuePool
{
typedef Internal::SharedValuePool<QByteArray, QVector> FlagPool;
typedef Internal::SharedValuePool<QString, QVector> MimeTypePool;
typedef Internal::SharedValuePool<QByteArray, QVector> FlagPool;
typedef Internal::SharedValuePool<QString, QVector> MimeTypePool;
FlagPool flagPool;
MimeTypePool mimeTypePool;
QHash<Collection::Id, Collection> ancestorCollections;
FlagPool flagPool;
MimeTypePool mimeTypePool;
QHash<Collection::Id, Collection> ancestorCollections;
};
/**
......@@ -57,12 +57,12 @@ struct ProtocolHelperValuePool
*/
class ProtocolHelper
{
public:
public:
/** Part namespaces. */
enum PartNamespace {
PartGlobal,
PartPayload,
PartAttribute
PartGlobal,
PartPayload,
PartAttribute
};
/**
......@@ -72,17 +72,17 @@ class ProtocolHelper
@param start Start of the data, ie. postion after the label.
@returns Position in data after the cache policy description.
*/
static int parseCachePolicy( const QByteArray &data, CachePolicy &policy, int start = 0 );
static int parseCachePolicy(const QByteArray &data, CachePolicy &policy, int start = 0);
/**
Convert a cache policy object into its protocol representation.
*/
static QByteArray cachePolicyToByteArray( const CachePolicy &policy );
static QByteArray cachePolicyToByteArray(const CachePolicy &policy);
/**
Convert a ancestor chain from its protocol representation into an Entity object.
*/
static void parseAncestors( const QByteArray &data, Entity *entity, int start = 0 );
static void parseAncestors(const QByteArray &data, Entity *entity, int start = 0);
/**
Convert a ancestor chain from its protocol representation into an Entity object.
......@@ -90,7 +90,7 @@ class ProtocolHelper
This method allows to pass a @p valuePool which acts as cache, so ancestor paths for the
same @p parentCollection don't have to be parsed twice.
*/
static void parseAncestorsCached( const QByteArray &data, Entity *entity, Collection::Id parentCollection, ProtocolHelperValuePool *valuePool = 0, int start = 0 );
static void parseAncestorsCached(const QByteArray &data, Entity *entity, Collection::Id parentCollection, ProtocolHelperValuePool *valuePool = 0, int start = 0);
/**
Parse a collection description.
......@@ -99,131 +99,131 @@ class ProtocolHelper
@param start Start of the data.
@returns Position in data after the collection description.
*/
static int parseCollection( const QByteArray &data, Collection &collection, int start = 0 );
static int parseCollection(const QByteArray &data, Collection &collection, int start = 0);
/**
Convert attributes to their protocol representation.
*/
static QByteArray attributesToByteArray( const Entity &entity, bool ns = false );
static QByteArray attributesToByteArray( const AttributeEntity &entity, bool ns = false );
static QByteArray attributesToByteArray(const Entity &entity, bool ns = false);
static QByteArray attributesToByteArray(const AttributeEntity &entity, bool ns = false);
/**
Encodes part label and namespace.
*/
static QByteArray encodePartIdentifier( PartNamespace ns, const QByteArray &label, int version = 0 );
static QByteArray encodePartIdentifier(PartNamespace ns, const QByteArray &label, int version = 0);
/**
Decode part label and namespace.
*/
static QByteArray decodePartIdentifier( const QByteArray &data, PartNamespace &ns );
static QByteArray decodePartIdentifier(const QByteArray &data, PartNamespace &ns);
/**
Converts the given set of items into a protocol representation.
@throws A Akonadi::Exception if the item set contains items with missing/invalid identifiers.
*/
template <typename T>
static QByteArray entitySetToByteArray( const QList<T> &_objects, const QByteArray &command )
static QByteArray entitySetToByteArray(const QList<T> &_objects, const QByteArray &command)
{
if ( _objects.isEmpty() )
throw Exception( "No objects specified" );
typename T::List objects( _objects );
QByteArray rv;
std::sort( objects.begin(), objects.end(), boost::bind( &T::id, _1 ) < boost::bind( &T::id, _2 ) );
if ( objects.first().isValid() ) {
// all items have a uid set
rv += " " AKONADI_CMD_UID " ";
if ( !command.isEmpty() ) {
rv += command;
rv += ' ';
if (_objects.isEmpty()) {
throw Exception("No objects specified");
}
QVector<typename T::Id> uids;
foreach ( const T &object, objects )
uids << object.id();
ImapSet set;
set.add( uids );
rv += set.toImapSequenceSet();
return rv;
}
// check if all items have a remote id
if ( std::find_if( objects.constBegin(), objects.constEnd(),
boost::bind( &QString::isEmpty, boost::bind( &T::remoteId, _1 ) ) )
!= objects.constEnd() )
{
throw Exception( "No remote identifier specified" );
}
// check if we have RIDs or HRIDs
if ( std::find_if( objects.constBegin(), objects.constEnd(),
!boost::bind( static_cast<bool (*)(const T&)>( &CollectionUtils::hasValidHierarchicalRID ), _1 ) )
== objects.constEnd() && objects.size() == 1 ) // ### HRID sets are not yet specified
{
// HRIDs
rv += " " AKONADI_CMD_HRID " ";
if ( !command.isEmpty() ) {
rv += command;
rv += ' ';
typename T::List objects(_objects);
QByteArray rv;
std::sort(objects.begin(), objects.end(), boost::bind(&T::id, _1) < boost::bind(&T::id, _2));
if (objects.first().isValid()) {
// all items have a uid set
rv += " " AKONADI_CMD_UID " ";
if (!command.isEmpty()) {
rv += command;
rv += ' ';
}
QVector<typename T::Id> uids;
foreach (const T &object, objects) {
uids << object.id();
}
ImapSet set;
set.add(uids);
rv += set.toImapSequenceSet();
return rv;
}
// check if all items have a remote id
if (std::find_if(objects.constBegin(), objects.constEnd(),
boost::bind(&QString::isEmpty, boost::bind(&T::remoteId, _1)))
!= objects.constEnd()) {
throw Exception("No remote identifier specified");
}
// check if we have RIDs or HRIDs
if (std::find_if(objects.constBegin(), objects.constEnd(),
!boost::bind(static_cast<bool (*)(const T &)>(&CollectionUtils::hasValidHierarchicalRID), _1))
== objects.constEnd() && objects.size() == 1) { // ### HRID sets are not yet specified
// HRIDs
rv += " " AKONADI_CMD_HRID " ";
if (!command.isEmpty()) {
rv += command;
rv += ' ';
}
rv += '(' + hierarchicalRidToByteArray(objects.first()) + ')';
return rv;
}
// RIDs
QList<QByteArray> rids;
foreach (const T &object, objects) {
rids << ImapParser::quote(object.remoteId().toUtf8());
}
rv += " " AKONADI_CMD_RID " ";
if (!command.isEmpty()) {
rv += command;
rv += ' ';
}
rv += '(' + hierarchicalRidToByteArray( objects.first() ) + ')';
rv += '(';
rv += ImapParser::join(rids, " ");
rv += ')';
return rv;
}
// RIDs
QList<QByteArray> rids;
foreach ( const T &object, objects ) {
rids << ImapParser::quote( object.remoteId().toUtf8() );
}
rv += " " AKONADI_CMD_RID " ";
if ( !command.isEmpty() ) {
rv += command;
rv += ' ';
}
rv += '(';
rv += ImapParser::join( rids, " " );
rv += ')';
return rv;
}
static QByteArray entitySetToByteArray( const QList<Akonadi::Item> &_objects, const QByteArray &command );
static QByteArray entitySetToByteArray(const QList<Akonadi::Item> &_objects, const QByteArray &command);
static QByteArray tagSetToImapSequenceSet( const Akonadi::Tag::List &_objects );
static QByteArray tagSetToByteArray( const Akonadi::Tag::List &_objects, const QByteArray &command );
static QByteArray tagSetToImapSequenceSet(const Akonadi::Tag::List &_objects);
static QByteArray tagSetToByteArray(const Akonadi::Tag::List &_objects, const QByteArray &command);
/**
Converts the given object identifier into a protocol representation.
@throws A Akonadi::Exception if the item set contains items with missing/invalid identifiers.
*/
template <typename T>
static QByteArray entityIdToByteArray( const T &object, const QByteArray &command )
static QByteArray entityIdToByteArray(const T &object, const QByteArray &command)
{
return entitySetToByteArray( typename T::List() << object, command );
return entitySetToByteArray(typename T::List() << object, command);
}
/**
Converts the given collection's hierarchical RID into a protocol representation.
Assumes @p col has a valid hierarchical RID, so check that before!
*/
static QByteArray hierarchicalRidToByteArray( const Collection &col );
static QByteArray hierarchicalRidToByteArray(const Collection &col);
/**
Converts the HRID of the given item into an ASAP protocol representation.
Assumes @p item has a valid HRID.
*/
static QByteArray hierarchicalRidToByteArray( const Item &item );
static QByteArray hierarchicalRidToByteArray(const Item &item);
/**
Converts a given ItemFetchScope object into a protocol representation.
*/
static QByteArray itemFetchScopeToByteArray( const ItemFetchScope &fetchScope );
static QByteArray itemFetchScopeToByteArray(const ItemFetchScope &fetchScope);
/**
Parses a single line from an item fetch job result into an Item object.
*/
static void parseItemFetchResult( const QList<QByteArray> &lineTokens, Item &item, ProtocolHelperValuePool *valuePool = 0 );
static void parseTagFetchResult( const QList<QByteArray> &lineTokens, Tag &tag );
static void parseItemFetchResult(const QList<QByteArray> &lineTokens, Item &item, ProtocolHelperValuePool *valuePool = 0);
static void parseTagFetchResult(const QList<QByteArray> &lineTokens, Tag &tag);
};
......
......@@ -62,18 +62,19 @@ namespace AkonadiTest {
* Checks that the test is running in the proper test environment
*/
void checkTestIsIsolated() {
Q_ASSERT_X( !qgetenv( "TESTRUNNER_DB_ENVIRONMENT" ).isEmpty(),
"AkonadiTest::checkTestIsIsolated",
"This test must be run using ctest, in order to use the testrunner environment. Aborting, to avoid messing up your real akonadi" );
Q_ASSERT_X(!qgetenv("TESTRUNNER_DB_ENVIRONMENT").isEmpty(),
"AkonadiTest::checkTestIsIsolated",
"This test must be run using ctest, in order to use the testrunner environment. Aborting, to avoid messing up your real akonadi");
}
/**
* Switch all resources offline to reduce interference from them
*/
void setAllResourcesOffline() {
// switch all resources offline to reduce interference from them
foreach ( Akonadi::AgentInstance agent, Akonadi::AgentManager::self()->instances() ) //krazy:exclude=foreach
agent.setIsOnline( false );
// switch all resources offline to reduce interference from them
foreach (Akonadi::AgentInstance agent, Akonadi::AgentManager::self()->instances()) { //krazy:exclude=foreach
agent.setIsOnline(false);
}
}
} // namespace
......
......@@ -31,18 +31,18 @@ using namespace Akonadi;
static int s_maximumRecentCollection = 10;
RecentCollectionAction::RecentCollectionAction(const QAbstractItemModel *model, QMenu *menu)
:QObject( menu ),
mMenu( menu ),
mModel( model ),
mRecentAction( 0 )
: QObject(menu)
, mMenu(menu)
, mModel(model)
, mRecentAction(0)
{
mAkonadiConfig = KSharedConfig::openConfig( QLatin1String( "akonadikderc" ) );
KConfigGroup group( mAkonadiConfig, QLatin1String( "Recent Collections" ) );
mAkonadiConfig = KSharedConfig::openConfig(QLatin1String("akonadikderc"));
KConfigGroup group(mAkonadiConfig, QLatin1String("Recent Collections"));
mListRecentCollection = group.readEntry( "Collections", QStringList() );
mRecentAction = mMenu->addAction( i18n( "Recent Folder" ) );
mMenu->addSeparator();
fillRecentCollection();
mListRecentCollection = group.readEntry("Collections", QStringList());
mRecentAction = mMenu->addAction(i18n("Recent Folder"));
mMenu->addSeparator();
fillRecentCollection();
}
RecentCollectionAction::~RecentCollectionAction()
......@@ -51,75 +51,75 @@ RecentCollectionAction::~RecentCollectionAction()
void RecentCollectionAction::fillRecentCollection()
{
delete mRecentAction->menu();
if ( mListRecentCollection.isEmpty() ) {
mRecentAction->setEnabled( false );
return;
}
delete mRecentAction->menu();
if (mListRecentCollection.isEmpty()) {
mRecentAction->setEnabled(false);
return;
}
QMenu* popup = new QMenu;
mRecentAction->setMenu( popup );
QMenu *popup = new QMenu;
mRecentAction->setMenu(popup);
const int numberOfRecentCollection(mListRecentCollection.count());
for ( int i=0; i < numberOfRecentCollection; ++i )
{
const QModelIndex index = Akonadi::EntityTreeModel::modelIndexForCollection( mModel, Akonadi::Collection( mListRecentCollection.at( i ).toLongLong() ) );
const Akonadi::Collection collection = mModel->data( index, Akonadi::CollectionModel::CollectionRole ).value<Akonadi::Collection>();
if ( index.isValid() ) {
const bool canCreateNewItems = (collection.rights() & Collection::CanCreateItem);
QAction *action = popup->addAction( actionName( index ) );
const QIcon icon = mModel->data( index, Qt::DecorationRole ).value<QIcon>();
action->setIcon( icon );
action->setData( QVariant::fromValue<QModelIndex>( index ) );
action->setEnabled(canCreateNewItems);
const int numberOfRecentCollection(mListRecentCollection.count());
for (int i = 0; i < numberOfRecentCollection; ++i) {
const QModelIndex index = Akonadi::EntityTreeModel::modelIndexForCollection(mModel, Akonadi::Collection(mListRecentCollection.at(i).toLongLong()));
const Akonadi::Collection collection = mModel->data(index, Akonadi::CollectionModel::CollectionRole).value<Akonadi::Collection>();
if (index.isValid()) {
const bool canCreateNewItems = (collection.rights() &Collection::CanCreateItem);
QAction *action = popup->addAction(actionName(index));
const QIcon icon = mModel->data(index, Qt::DecorationRole).value<QIcon>();
action->setIcon(icon);
action->setData(QVariant::fromValue<QModelIndex>(index));
action->setEnabled(canCreateNewItems);
}
}
}
}
QString RecentCollectionAction::actionName(QModelIndex index)
{
QString name = index.data().toString();
name.replace( QLatin1String( "&" ), QLatin1String( "&&" ) );
QString name = index.data().toString();
name.replace(QLatin1String("&"), QLatin1String("&&"));
index = index.parent();
QString topLevelName;
while ( index != QModelIndex() ) {
topLevelName = index.data().toString();
index = index.parent();
}
if ( topLevelName.isEmpty() )
return QString::fromLatin1( "%1" ).arg( name );
else {
topLevelName.replace( QLatin1String( "&" ), QLatin1String( "&&" ) );
return QString::fromLatin1( "%1 - %2" ).arg( name ).arg( topLevelName );
}
QString topLevelName;
while (index != QModelIndex()) {
topLevelName = index.data().toString();
index = index.parent();
}
if (topLevelName.isEmpty()) {
return QString::fromLatin1("%1").arg(name);
} else {
topLevelName.replace(QLatin1String("&"), QLatin1String("&&"));
return QString::fromLatin1("%1 - %2").arg(name).arg(topLevelName);
}
}
void RecentCollectionAction::addRecentCollection( Akonadi::Collection::Id id )
void RecentCollectionAction::addRecentCollection(Akonadi::Collection::Id id)
{
const QString newCollectionID = QString::number( id );
if ( mListRecentCollection.isEmpty() ||
!mListRecentCollection.contains( newCollectionID ) ) {
if ( mListRecentCollection.count() == s_maximumRecentCollection )
mListRecentCollection.removeFirst();
mListRecentCollection.append( newCollectionID );
writeConfig();
fillRecentCollection();
}
const QString newCollectionID = QString::number(id);
if (mListRecentCollection.isEmpty() ||
!mListRecentCollection.contains(newCollectionID)) {
if (mListRecentCollection.count() == s_maximumRecentCollection) {
mListRecentCollection.removeFirst();
}
mListRecentCollection.append(newCollectionID);
writeConfig();
fillRecentCollection();
}
}
void RecentCollectionAction::writeConfig()
{
KConfigGroup group( mAkonadiConfig, QLatin1String( "Recent Collections" ) );
group.writeEntry( "Collections", mListRecentCollection );
group.sync();
KConfigGroup group(mAkonadiConfig, QLatin1String("Recent Collections"));
group.writeEntry("Collections", mListRecentCollection);
group.sync();
}
void RecentCollectionAction::cleanRecentCollection()
{
mListRecentCollection.clear();
writeConfig();
fillRecentCollection();
mListRecentCollection.clear();
writeConfig();
fillRecentCollection();
}
#include "moc_recentcollectionaction_p.cpp"
......@@ -36,37 +36,36 @@ class QAction;
namespace Akonadi {
class RecentCollectionAction : public QObject
{
Q_OBJECT
Q_OBJECT
public:
/**
* Creates a new collection recent action
*/
explicit RecentCollectionAction(const QAbstractItemModel *model, QMenu *menu);
/**
* Destroys the collection recent action.
*/
~RecentCollectionAction();
/**
* Creates a new collection recent action
*/
explicit RecentCollectionAction(const QAbstractItemModel *model, QMenu *menu);
/**
* Destroys the collection recent action.
*/
~RecentCollectionAction();
/**
* Add new collection. Will create a new item.
*/
void addRecentCollection( Akonadi::Collection::Id id);
/**
* Add new collection. Will create a new item.
*/
void addRecentCollection(Akonadi::Collection::Id id);
void cleanRecentCollection();
void cleanRecentCollection();
private:
void writeConfig();
void fillRecentCollection();
QString actionName(QModelIndex index);
void writeConfig();
void fillRecentCollection();
QString actionName(QModelIndex index);
private:
QStringList mListRecentCollection;
QMenu *mMenu;
const QAbstractItemModel *mModel;
QAction *mRecentAction;
KSharedConfig::Ptr mAkonadiConfig;
QStringList mListRecentCollection;
QMenu *mMenu;
const QAbstractItemModel *mModel;
QAction *mRecentAction;
KSharedConfig::Ptr mAkonadiConfig;
};
}
#endif /* RECENTCOLLECTIONACTION_P_H */
......@@ -32,113 +32,115 @@ namespace Akonadi
class RecursiveCollectionFilterProxyModelPrivate
{
Q_DECLARE_PUBLIC(RecursiveCollectionFilterProxyModel)
RecursiveCollectionFilterProxyModel *q_ptr;
Q_DECLARE_PUBLIC(RecursiveCollectionFilterProxyModel)
RecursiveCollectionFilterProxyModel *q_ptr;
public:
RecursiveCollectionFilterProxyModelPrivate(RecursiveCollectionFilterProxyModel *model)
: q_ptr(model), checkOnlyChecked( false )
{
RecursiveCollectionFilterProxyModelPrivate(RecursiveCollectionFilterProxyModel *model)
: q_ptr(model)
, checkOnlyChecked(false)
{
}
}
QSet<QString> includedMimeTypes;
Akonadi::MimeTypeChecker checker;
QString pattern;
bool checkOnlyChecked;
QSet<QString> includedMimeTypes;
Akonadi::MimeTypeChecker checker;
QString pattern;
bool checkOnlyChecked;
};
}
RecursiveCollectionFilterProxyModel::RecursiveCollectionFilterProxyModel( QObject* parent )
: KRecursiveFilterProxyModel(parent), d_ptr(new RecursiveCollectionFilterProxyModelPrivate( this ) )
RecursiveCollectionFilterProxyModel::RecursiveCollectionFilterProxyModel(QObject *parent)
: KRecursiveFilterProxyModel(parent)
, d_ptr(new RecursiveCollectionFilterProxyModelPrivate(this))
{
}
RecursiveCollectionFilterProxyModel::~RecursiveCollectionFilterProxyModel()
{
delete d_ptr;
delete d_ptr;
}
bool RecursiveCollectionFilterProxyModel::acceptRow( int sourceRow, const QModelIndex &sourceParent ) const
bool RecursiveCollectionFilterProxyModel::acceptRow(int sourceRow, const QModelIndex &sourceParent) const
{
Q_D( const RecursiveCollectionFilterProxyModel );
const QModelIndex rowIndex = sourceModel()->index( sourceRow, 0, sourceParent );
const Akonadi::Collection collection = rowIndex.data( Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
if ( !collection.isValid() )
return false;
const bool checked = ( rowIndex.data(Qt::CheckStateRole).toInt()==Qt::Checked );
const bool isCheckable = sourceModel()->flags( rowIndex ) & Qt::ItemIsUserCheckable;
if ( isCheckable && (d->checkOnlyChecked && !checked) ) {
return false;
}
const bool collectionWanted = d->checker.isWantedCollection( collection );
if ( collectionWanted )
{
if ( !d->pattern.isEmpty() ) {
const QString text = rowIndex.data(Qt::DisplayRole).toString();
return text.contains( d->pattern, Qt::CaseInsensitive );
Q_D(const RecursiveCollectionFilterProxyModel