Beispiel #1
0
bool StorageHandler::replaceItem( const ItemId& aItemId,
                                  StoragePlugin& aPlugin,
                                  const QString& aLocalKey,
                                  const SyncItemKey& aParentKey,
                                  const QString& aType,
                                  const QString& aFormat,
                                  const QString& aVersion,
                                  const QString& aData )
{
    FUNCTION_CALL_TRACE;

    LOG_DEBUG( "Processing item for replace:" << aItemId.iCmdId <<"/" << aItemId.iItemIndex );

    if( iLargeObject ) {
        LOG_CRITICAL( "Already processing large object, aborting" );
        return false;
    }

    SyncItem* item = NULL;

    // If local key is empty, this Replace should be handled as Add (this is allowed by the protocol)

    if( !aLocalKey.isEmpty() ) {
        item = aPlugin.getSyncItem( aLocalKey );
    }

    if( !item ) {
        LOG_DEBUG( "Could not find item, processing as Add" );
        return addItem( aItemId, aPlugin, aLocalKey, aParentKey, aType, aFormat, aVersion, aData );
    }

    item->setParentKey( aParentKey );
    item->setType( aType );
    item->setFormat( aFormat );
    item->setVersion( aVersion );

    if( !item->write( 0, aData.toUtf8() ) ) {
        delete item;
        LOG_CRITICAL( "Could not write to item" );
        return false;
    }

    iReplaceList.insert( aItemId, item );
    LOG_DEBUG( "Item queued for replace" );

    return true;
}
Beispiel #2
0
bool StorageHandler::addItem( const ItemId& aItemId,
                              StoragePlugin& aPlugin,
                              const SyncItemKey& aLocalKey,
                              const SyncItemKey& aParentKey,
                              const QString& aType,
                              const QString& aFormat,
                              const QString& aVersion,
                              const QString& aData )
{
    FUNCTION_CALL_TRACE;

    LOG_DEBUG( "Processing item for add:" << aItemId.iCmdId <<"/" << aItemId.iItemIndex );

    if( iLargeObject ) {
        LOG_CRITICAL( "Already processing large object, aborting" );
        return false;
    }

    SyncItem* newItem = aPlugin.newItem();

    if( !newItem ) {
        LOG_CRITICAL( "Could not create new item" );
        return false;
    }

    //Setting empty string as we dont have any local key for it.
    newItem->setKey( aLocalKey );
    newItem->setParentKey( aParentKey );
    newItem->setType( aType );
    newItem->setFormat( aFormat );
    newItem->setVersion( aVersion );

    if( !newItem->write( 0, aData.toUtf8() ) ) {
        delete newItem;
        LOG_CRITICAL( "Could not write to item" );
        return false;
    }

    iAddList.insert( aItemId, newItem );
    LOG_DEBUG( "Item queued for addition" );

    return true;
}