Commit 1faa214a authored by Guy Maurel's avatar Guy Maurel
Browse files

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

parent 13c5f2e0
......@@ -34,23 +34,27 @@ using namespace Akonadi;
static bool canCreateSubCollection( const Collection &collection )
{
if ( !( collection.rights() & Collection::CanCreateCollection ) )
if ( !( collection.rights() & Collection::CanCreateCollection ) ) {
return false;
}
if ( !collection.contentMimeTypes().contains( Collection::mimeType() ) )
if ( !collection.contentMimeTypes().contains( Collection::mimeType() ) ) {
return false;
}
return true;
}
static inline bool canContainItems( const Collection &collection )
{
if ( collection.contentMimeTypes().isEmpty() )
if ( collection.contentMimeTypes().isEmpty() ) {
return false;
}
if ( (collection.contentMimeTypes().count() == 1) &&
(collection.contentMimeTypes().first() == Collection::mimeType()) )
if ( ( collection.contentMimeTypes().count() == 1 ) &&
( collection.contentMimeTypes().first() == Collection::mimeType() ) ) {
return false;
}
return true;
}
......@@ -72,22 +76,21 @@ void ActionStateManager::setReceiver( QObject *object )
void ActionStateManager::updateState( const Collection::List &collections, const Item::List &items )
{
const int collectionCount = collections.count();
const bool singleCollectionSelected = (collectionCount == 1);
const bool multipleCollectionsSelected = (collectionCount > 1);
const bool atLeastOneCollectionSelected = (singleCollectionSelected || multipleCollectionsSelected);
const bool singleCollectionSelected = ( collectionCount == 1 );
const bool multipleCollectionsSelected = ( collectionCount > 1 );
const bool atLeastOneCollectionSelected = ( singleCollectionSelected || multipleCollectionsSelected );
const int itemCount = items.count();
const bool singleItemSelected = (itemCount == 1);
const bool multipleItemsSelected = (itemCount > 1);
const bool atLeastOneItemSelected = (singleItemSelected || multipleItemsSelected);
const bool singleItemSelected = ( itemCount == 1 );
const bool multipleItemsSelected = ( itemCount > 1 );
const bool atLeastOneItemSelected = ( singleItemSelected || multipleItemsSelected );
const bool listOfCollectionNotEmpty = collections.isEmpty() ? false : true;
bool canDeleteCollections = listOfCollectionNotEmpty;
if ( canDeleteCollections )
{
if ( canDeleteCollections ) {
foreach ( const Collection &collection, collections ) {
// do we have the necessary rights?
if ( !(collection.rights() & Collection::CanDeleteCollection) ) {
if ( !( collection.rights() & Collection::CanDeleteCollection ) ) {
canDeleteCollections = false;
break;
}
......@@ -190,7 +193,7 @@ void ActionStateManager::updateState( const Collection::List &collections, const
}
}
const Collection collection = (!collections.isEmpty() ? collections.first() : Collection());
const Collection collection = ( !collections.isEmpty() ? collections.first() : Collection() );
// collection specific actions
enableAction( StandardActionManager::CreateCollection, singleCollectionSelected && // we can create only inside one collection
......@@ -246,9 +249,9 @@ void ActionStateManager::updateState( const Collection::List &collections, const
resourceCollectionCount++;
// check that the 'NoConfig' flag is not set for the resource
if ( hasResourceCapability( collection, QLatin1String( "NoConfig" ) ) )
if ( hasResourceCapability( collection, QLatin1String( "NoConfig" ) ) ) {
canConfigureResource = false;
}
} else {
// we selected a non-resource collection
canDeleteResources = false;
......@@ -269,7 +272,7 @@ void ActionStateManager::updateState( const Collection::List &collections, const
enableAction( StandardActionManager::ResourceProperties, canConfigureResource );
enableAction( StandardActionManager::SynchronizeResources, canSynchronizeResources );
if (collectionsAreInTrash) {
if ( collectionsAreInTrash ) {
updateAlternatingAction( StandardActionManager::MoveToTrashRestoreCollectionAlternative );
//updatePluralLabel( StandardActionManager::MoveToTrashRestoreCollectionAlternative, collectionCount );
} else {
......@@ -278,13 +281,14 @@ void ActionStateManager::updateState( const Collection::List &collections, const
enableAction( StandardActionManager::MoveToTrashRestoreCollection, atLeastOneCollectionSelected && canMoveCollections );
// item specific actions
bool canDeleteItems = (items.count() > 0); //TODO: fixme
bool canDeleteItems = ( items.count() > 0 ); //TODO: fixme
foreach ( const Item &item, items ) {
const Collection parentCollection = item.parentCollection();
if ( !parentCollection.isValid() )
if ( !parentCollection.isValid() ) {
continue;
}
canDeleteItems = canDeleteItems && (parentCollection.rights() & Collection::CanDeleteItem);
canDeleteItems = canDeleteItems && ( parentCollection.rights() & Collection::CanDeleteItem );
}
bool itemsAreInTrash = false;
......@@ -317,7 +321,7 @@ void ActionStateManager::updateState( const Collection::List &collections, const
enableAction( StandardActionManager::MoveItemToDialog, atLeastOneItemSelected && // we need items to work with
canDeleteItems ); // we need the necessary rights
if (itemsAreInTrash) {
if ( itemsAreInTrash ) {
updateAlternatingAction( StandardActionManager::MoveToTrashRestoreItemAlternative );
//updatePluralLabel( StandardActionManager::MoveToTrashRestoreItemAlternative, itemCount );
} else {
......@@ -352,9 +356,9 @@ bool ActionStateManager::isResourceCollection( const Collection &collection ) co
bool ActionStateManager::isFolderCollection( const Collection &collection ) const
{
return (CollectionUtils::isFolder( collection ) ||
CollectionUtils::isResource( collection ) ||
CollectionUtils::isStructural( collection ));
return ( CollectionUtils::isFolder( collection ) ||
CollectionUtils::isResource( collection ) ||
CollectionUtils::isStructural( collection ) );
}
bool ActionStateManager::isSpecialCollection( const Collection &collection ) const
......@@ -364,8 +368,9 @@ bool ActionStateManager::isSpecialCollection( const Collection &collection ) con
bool ActionStateManager::isFavoriteCollection( const Collection &collection ) const
{
if ( !mReceiver )
if ( !mReceiver ) {
return false;
}
bool result = false;
QMetaObject::invokeMethod( mReceiver, "isFavoriteCollection", Qt::DirectConnection,
......@@ -389,24 +394,27 @@ bool ActionStateManager::collectionCanHaveItems( const Collection &collection )
void ActionStateManager::enableAction( int action, bool state )
{
if ( !mReceiver )
if ( !mReceiver ) {
return;
}
QMetaObject::invokeMethod( mReceiver, "enableAction", Qt::DirectConnection, Q_ARG( int, action ), Q_ARG( bool, state ) );
}
void ActionStateManager::updatePluralLabel( int action, int count )
{
if ( !mReceiver )
if ( !mReceiver ) {
return;
}
QMetaObject::invokeMethod( mReceiver, "updatePluralLabel", Qt::DirectConnection, Q_ARG( int, action ), Q_ARG( int, count ) );
}
void ActionStateManager::updateAlternatingAction( int action )
{
if ( !mReceiver )
if ( !mReceiver ) {
return;
}
QMetaObject::invokeMethod( mReceiver, "updateAlternatingAction", Qt::DirectConnection, Q_ARG( int, action ));
QMetaObject::invokeMethod( mReceiver, "updateAlternatingAction", Qt::DirectConnection, Q_ARG( int, action ) );
}
......@@ -71,45 +71,51 @@ void AgentBase::Observer::itemAdded( const Item &item, const Collection &collect
{
Q_UNUSED( item );
Q_UNUSED( collection );
if ( sAgentBase != 0 )
if ( sAgentBase != 0 ) {
sAgentBase->d_ptr->changeProcessed();
}
}
void AgentBase::Observer::itemChanged( const Item &item, const QSet<QByteArray> &partIdentifiers )
{
Q_UNUSED( item );
Q_UNUSED( partIdentifiers );
if ( sAgentBase != 0 )
if ( sAgentBase != 0 ) {
sAgentBase->d_ptr->changeProcessed();
}
}
void AgentBase::Observer::itemRemoved( const Item &item )
{
Q_UNUSED( item );
if ( sAgentBase != 0 )
if ( sAgentBase != 0 ) {
sAgentBase->d_ptr->changeProcessed();
}
}
void AgentBase::Observer::collectionAdded( const Akonadi::Collection &collection, const Akonadi::Collection &parent )
{
Q_UNUSED( collection );
Q_UNUSED( parent );
if ( sAgentBase != 0 )
if ( sAgentBase != 0 ) {
sAgentBase->d_ptr->changeProcessed();
}
}
void AgentBase::Observer::collectionChanged( const Collection &collection )
{
Q_UNUSED( collection );
if ( sAgentBase != 0 )
if ( sAgentBase != 0 ) {
sAgentBase->d_ptr->changeProcessed();
}
}
void AgentBase::Observer::collectionRemoved( const Collection &collection )
{
Q_UNUSED( collection );
if ( sAgentBase != 0 )
if ( sAgentBase != 0 ) {
sAgentBase->d_ptr->changeProcessed();
}
}
void AgentBase::ObserverV2::itemMoved( const Akonadi::Item &item, const Akonadi::Collection &source, const Akonadi::Collection &dest )
......@@ -117,8 +123,9 @@ void AgentBase::ObserverV2::itemMoved( const Akonadi::Item &item, const Akonadi:
Q_UNUSED( item );
Q_UNUSED( source );
Q_UNUSED( dest );
if ( sAgentBase != 0 )
if ( sAgentBase != 0 ) {
sAgentBase->d_ptr->changeProcessed();
}
}
void AgentBase::ObserverV2::itemLinked( const Akonadi::Item& item, const Akonadi::Collection& collection )
......@@ -150,8 +157,9 @@ void AgentBase::ObserverV2::collectionMoved( const Akonadi::Collection &collecti
Q_UNUSED( collection );
Q_UNUSED( source );
Q_UNUSED( dest );
if ( sAgentBase != 0 )
if ( sAgentBase != 0 ) {
sAgentBase->d_ptr->changeProcessed();
}
}
void AgentBase::ObserverV2::collectionChanged( const Akonadi::Collection &collection, const QSet<QByteArray> &changedAttributes )
......@@ -173,7 +181,7 @@ AgentBasePrivate::AgentBasePrivate( AgentBase *parent )
mObserver( 0 )
{
#ifdef Q_OS_WINCE
QThread::currentThread()->setPriority(QThread::LowPriority);
QThread::currentThread()->setPriority( QThread::LowPriority );
#endif
Internal::setClientType( Internal::Agent );
}
......@@ -205,7 +213,7 @@ void AgentBasePrivate::init()
new Akonadi__ControlAdaptor( q );
new Akonadi__StatusAdaptor( q );
if ( !DBusConnectionPool::threadConnection().registerObject( QLatin1String( "/" ), q, QDBusConnection::ExportAdaptors ) )
q->error( QString::fromLatin1( "Unable to register object at dbus: %1" ).arg( DBusConnectionPool::threadConnection().lastError().message() ) );
q->error( i18n( "Unable to register object at dbus: %1" ).arg( DBusConnectionPool::threadConnection().lastError().message() ) );
mSettings = new QSettings( QString::fromLatin1( "%1/agent_config_%2" ).arg( Internal::xdgSaveDir( "config" ), mId ), QSettings::IniFormat );
......@@ -265,16 +273,18 @@ void AgentBasePrivate::init()
// Use reference counting to allow agents to finish internal jobs when the
// agent is stopped.
KGlobal::ref();
if ( QThread::currentThread() == QCoreApplication::instance()->thread() )
if ( QThread::currentThread() == QCoreApplication::instance()->thread() ) {
KGlobal::setAllowQuit( true );
}
#ifndef Q_OS_WINCE
// disable session management
if ( KApplication::kApplication() )
if ( KApplication::kApplication() ) {
KApplication::kApplication()->disableSessionManagement();
}
#endif
mResourceTypeName = AgentManager::self()->instance(mId).type().name();
mResourceTypeName = AgentManager::self()->instance( mId ).type().name();
setProgramName();
QTimer::singleShot( 0, q, SLOT(delayedInit()) );
......@@ -284,8 +294,9 @@ void AgentBasePrivate::delayedInit()
{
Q_Q( AgentBase );
const QString serviceId = ServerManager::agentServiceName( ServerManager::Agent, mId );
if ( !DBusConnectionPool::threadConnection().registerService( serviceId ) )
if ( !DBusConnectionPool::threadConnection().registerService( serviceId ) ) {
kFatal() << "Unable to register service" << serviceId << "at dbus:" << DBusConnectionPool::threadConnection().lastError().message();
}
q->setOnline( mOnline );
}
......@@ -301,14 +312,16 @@ void AgentBasePrivate::setProgramName()
void AgentBasePrivate::itemAdded( const Akonadi::Item &item, const Akonadi::Collection &collection )
{
if ( mObserver != 0 )
if ( mObserver != 0 ) {
mObserver->itemAdded( item, collection );
}
}
void AgentBasePrivate::itemChanged( const Akonadi::Item &item, const QSet<QByteArray> &partIdentifiers )
{
if ( mObserver != 0 )
if ( mObserver != 0 ) {
mObserver->itemChanged( item, partIdentifiers );
}
}
void AgentBasePrivate::itemMoved( const Akonadi::Item &item, const Akonadi::Collection &source, const Akonadi::Collection &dest )
......@@ -322,14 +335,14 @@ void AgentBasePrivate::itemMoved( const Akonadi::Item &item, const Akonadi::Coll
Akonadi::Item i( item );
i.setParentCollection( source );
mObserver->itemRemoved( i );
}
else if ( dest.resource() == q_ptr->identifier() ) // moved to us
} else if ( dest.resource() == q_ptr->identifier() ) { // moved to us
mObserver->itemAdded( item, dest );
else if ( observer2 )
} else if ( observer2 ) {
observer2->itemMoved( item, source, dest );
else
} else {
// not for us, not sure if we should get here at all
changeProcessed();
}
return;
}
}
......@@ -348,46 +361,52 @@ void AgentBasePrivate::itemMoved( const Akonadi::Item &item, const Akonadi::Coll
void AgentBasePrivate::itemRemoved( const Akonadi::Item &item )
{
if ( mObserver != 0 )
if ( mObserver != 0 ) {
mObserver->itemRemoved( item );
}
}
void AgentBasePrivate::itemLinked( const Akonadi::Item &item, const Akonadi::Collection &collection )
{
AgentBase::ObserverV2 *observer2 = dynamic_cast<AgentBase::ObserverV2*>( mObserver );
if ( observer2 )
if ( observer2 ) {
observer2->itemLinked( item, collection );
else
} else {
changeProcessed();
}
}
void AgentBasePrivate::itemUnlinked( const Akonadi::Item &item, const Akonadi::Collection &collection )
{
AgentBase::ObserverV2 *observer2 = dynamic_cast<AgentBase::ObserverV2*>( mObserver );
if ( observer2 )
if ( observer2 ) {
observer2->itemUnlinked( item, collection );
else
} else {
changeProcessed();
}
}
void AgentBasePrivate::collectionAdded( const Akonadi::Collection &collection, const Akonadi::Collection &parent )
{
if ( mObserver != 0 )
if ( mObserver != 0 ) {
mObserver->collectionAdded( collection, parent );
}
}
void AgentBasePrivate::collectionChanged( const Akonadi::Collection &collection )
{
AgentBase::ObserverV2 *observer2 = dynamic_cast<AgentBase::ObserverV2*>( mObserver );
if ( mObserver != 0 && observer2 == 0 ) // For ObserverV2 we use the variant with the part identifiers
if ( mObserver != 0 && observer2 == 0 ) { // For ObserverV2 we use the variant with the part identifiers
mObserver->collectionChanged( collection );
}
}
void AgentBasePrivate::collectionChanged( const Akonadi::Collection &collection, const QSet<QByteArray> &changedAttributes )
{
AgentBase::ObserverV2 *observer2 = dynamic_cast<AgentBase::ObserverV2*>( mObserver );
if ( observer2 != 0 )
if ( observer2 != 0 ) {
observer2->collectionChanged( collection, changedAttributes );
}
}
void AgentBasePrivate::collectionMoved( const Akonadi::Collection &collection, const Akonadi::Collection &source, const Akonadi::Collection &dest )
......@@ -407,8 +426,9 @@ void AgentBasePrivate::collectionMoved( const Akonadi::Collection &collection, c
void AgentBasePrivate::collectionRemoved( const Akonadi::Collection &collection )
{
if ( mObserver != 0 )
if ( mObserver != 0 ) {
mObserver->collectionRemoved( collection );
}
}
void AgentBasePrivate::collectionSubscribed( const Akonadi::Collection &collection, const Akonadi::Collection &parent )
......@@ -437,20 +457,23 @@ void AgentBasePrivate::slotStatus( int status, const QString &message )
switch ( status ) {
case AgentBase::Idle:
if ( mStatusMessage.isEmpty() )
if ( mStatusMessage.isEmpty() ) {
mStatusMessage = defaultReadyMessage();
}
mStatusCode = 0;
break;
case AgentBase::Running:
if ( mStatusMessage.isEmpty() )
if ( mStatusMessage.isEmpty() ) {
mStatusMessage = defaultSyncingMessage();
}
mStatusCode = 1;
break;
case AgentBase::Broken:
if ( mStatusMessage.isEmpty() )
if ( mStatusMessage.isEmpty() ) {
mStatusMessage = defaultErrorMessage();
}
mStatusCode = 2;
break;
......@@ -483,8 +506,9 @@ void AgentBasePrivate::slotNetworkStatusChange( Solid::Networking::Status stat )
void AgentBasePrivate::slotResumedFromSuspend()
{
if ( mNeedsNetwork )
if ( mNeedsNetwork ) {
slotNetworkStatusChange( Solid::Networking::status() );
}
}
AgentBase::AgentBase( const QString & id )
......@@ -517,8 +541,9 @@ QString AgentBase::parseArguments( int argc, char **argv )
}
for ( int i = 1; i < argc - 1; ++i ) {
if ( QLatin1String( argv[ i ] ) == QLatin1String( "--identifier" ) )
if ( QLatin1String( argv[ i ] ) == QLatin1String( "--identifier" ) ) {
identifier = QLatin1String( argv[ i + 1 ] );
}
}
if ( identifier.isEmpty() ) {
......@@ -609,8 +634,9 @@ void AgentBase::setOnline( bool state )
d->mOnline = state;
const QString newMessage = d->defaultReadyMessage();
if ( d->mStatusMessage != newMessage && d->mStatusCode != AgentBase::Broken )
if ( d->mStatusMessage != newMessage && d->mStatusCode != AgentBase::Broken ) {
emit status( d->mStatusCode, newMessage );
}
d->mSettings->setValue( QLatin1String( "Agent/Online" ), state );
doSetOnline( state );
......@@ -638,15 +664,17 @@ void AgentBase::configure( qlonglong windowId )
WId AgentBase::winIdForDialogs() const
{
const bool registered = DBusConnectionPool::threadConnection().interface()->isServiceRegistered( QLatin1String( "org.freedesktop.akonaditray" ) );
if ( !registered )
if ( !registered ) {
return 0;
}
QDBusInterface dbus( QLatin1String( "org.freedesktop.akonaditray" ), QLatin1String( "/Actions" ),
QLatin1String( "org.freedesktop.Akonadi.Tray" ) );
const QDBusMessage reply = dbus.call( QLatin1String( "getWinId" ) );
if ( reply.type() == QDBusMessage::ErrorMessage )
if ( reply.type() == QDBusMessage::ErrorMessage ) {
return 0;
}
const WId winid = (WId)reply.arguments().at( 0 ).toLongLong();
......@@ -721,8 +749,9 @@ QString AgentBase::identifier() const
void AgentBase::setAgentName( const QString &name )
{
Q_D( AgentBase );
if ( name == d->mName )
if ( name == d->mName ) {
return;
}
// TODO: rename collection
d->mName = name;
......@@ -743,10 +772,11 @@ void AgentBase::setAgentName( const QString &name )
QString AgentBase::agentName() const
{
Q_D( const AgentBase );
if ( d->mName.isEmpty() )
if ( d->mName.isEmpty() ) {
return d->mId;
else
} else {
return d->mName;
}
}
void AgentBase::changeProcessed()
......@@ -762,10 +792,11 @@ ChangeRecorder * AgentBase::changeRecorder() const
KSharedConfigPtr AgentBase::config()
{
if ( QCoreApplication::instance()->thread() == QThread::currentThread() )
if ( QCoreApplication::instance()->thread() == QThread::currentThread() ) {
return KGlobal::config();
else
} else {
return componentData().config();
}
}
void AgentBase::abort()
......@@ -783,14 +814,15 @@ extern QThreadStorage<KComponentData*> s_agentComponentDatas;
KComponentData AgentBase::componentData()
{
if ( QThread::currentThread() == QCoreApplication::instance()->thread() ) {
if ( s_agentComponentDatas.hasLocalData() )
return *(s_agentComponentDatas.localData());
else
if ( s_agentComponentDatas.hasLocalData() ) {
return *( s_agentComponentDatas.localData() );
} else {
return KGlobal::mainComponent();
}
}
Q_ASSERT( s_agentComponentDatas.hasLocalData() );
return *(s_agentComponentDatas.localData());
return *( s_agentComponentDatas.localData() );
}
#include "agentbase.moc"
......
......@@ -299,8 +299,7 @@ class AKONADI_EXPORT AgentBase : public QObject, protected QDBusContext
* This enum describes the different states the
* agent can be in.
*/
enum Status
{
enum Status {
Idle = 0, ///< The agent does currently nothing.
Running, ///< The agent is working on something.
Broken ///< The agent encountered an error state.
......@@ -337,8 +336,9 @@ class AKONADI_EXPORT AgentBase : public QObject, protected QDBusContext
// check if T also inherits AgentBase::Observer and
// if it does, automatically register it on itself
Observer *observer = dynamic_cast<Observer*>( r );
if ( observer != 0 )
if ( observer != 0 ) {
r->registerObserver( observer );
}
return init( r );
}
......
......@@ -55,8 +55,9 @@ class AgentBasePrivate : public QObject
QString defaultReadyMessage() const
{
if ( mOnline )
if ( mOnline ) {
return i18nc( "@info:status Application ready for work", "Ready" );
}
return i18nc( "@info:status", "Offline" );
}
......
......@@ -43,8 +43,9 @@ AgentFactoryBase::AgentFactoryBase( const char *catalogName, QObject *parent)
: QObject( parent ), d( new AgentFactoryBasePrivate )
{
d->catalogName = QString::fromLatin1( catalogName );
if ( !KGlobal::hasMainComponent() )
if ( !KGlobal::hasMainComponent() ) {
new KComponentData( "AkonadiAgentServer", "libakonadi", KComponentData::RegisterAsMainComponent );
}
KGlobal::locale()->insertCatalog( d->catalogName );
......@@ -62,10 +63,10 @@ void AgentFactoryBase::createComponentData( const QString& identifier ) const
Q_ASSERT( !s_agentComponentDatas.hasLocalData() );
if ( QThread::currentThread() != QCoreApplication::instance()->thread() ) {
s_agentComponentDatas.setLocalData( new KComponentData( ServerManager::addNamespace(identifier).toLatin1(), d->catalogName.toLatin1(),
s_agentComponentDatas.setLocalData( new KComponentData( ServerManager::addNamespace( identifier ).toLatin1(), d->catalogName.toLatin1(),
KComponentData::SkipMainComponentRegistration ) );
} else {