Logo Search packages:      
Sourcecode: webissues version File versions  Download package

typesbatch.cpp

/**************************************************************************
* This file is part of the WebIssues program
* Copyright (C) 2006 Michał Męciński
* Copyright (C) 2007 WebIssues Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
**************************************************************************/

#include "typesbatch.h"

#include "commands/command.h"
#include "datamanager.h"

using namespace WebIssues;

00019 TypesBatch::TypesBatch() : AbstractBatch( 0 ),
    m_update( false )
{
}

00024 TypesBatch::~TypesBatch()
{
}

00028 void TypesBatch::addType( const QString& name )
{
    Job job( &TypesBatch::addTypeJob );
    job.addArg( name );
    m_queue.addJob( job );
}

00035 void TypesBatch::renameType( int typeId, const QString& newName )
{
    Job job( &TypesBatch::renameTypeJob );
    job.addArg( typeId );
    job.addArg( newName );
    m_queue.addJob( job );
}

00043 void TypesBatch::deleteType( int typeId )
{
    Job job( &TypesBatch::deleteTypeJob );
    job.addArg( typeId );
    m_queue.addJob( job );
}

00050 void TypesBatch::addAttribute( int typeId, const QString& name, const QString& definition )
{
    Job job( &TypesBatch::addAttributeJob );
    job.addArg( typeId );
    job.addArg( name );
    job.addArg( definition );
    m_queue.addJob( job );
}

00059 void TypesBatch::renameAttribute( int attributeId, const QString& newName )
{
    Job job( &TypesBatch::renameAttributeJob );
    job.addArg( attributeId );
    job.addArg( newName );
    m_queue.addJob( job );
}

00067 void TypesBatch::modifyAttribute( int attributeId, const QString& definition )
{
    Job job( &TypesBatch::modifyAttributeJob );
    job.addArg( attributeId );
    job.addArg( definition );
    m_queue.addJob( job );
}

00075 void TypesBatch::deleteAttribute( int attributeId )
{
    Job job( &TypesBatch::deleteAttributeJob );
    job.addArg( attributeId );
    m_queue.addJob( job );
}

00082 Command* TypesBatch::fetchNext()
{
    if ( m_queue.moreJobs() )
        return m_queue.callJob( this );

    if ( m_update ) {
        m_update = false;
        return dataManager->updateTypes();
    }

    return NULL;
}

Command* TypesBatch::addTypeJob( const Job& job )
{
    Command* command = new Command();

    command->setKeyword( "ADD TYPE" );
    command->setArgs( job.args() );

    command->addRule( "ID i", ReplyRule::One );

    connect( command, SIGNAL( commandReply( const Reply& ) ), this, SLOT( setUpdate() ) );

    return command;
}

Command* TypesBatch::renameTypeJob( const Job& job )
{
    Command* command = new Command();

    command->setKeyword( "RENAME TYPE" );
    command->setArgs( job.args() );

    command->setAcceptNullReply( true );
    command->addRule( "OK", ReplyRule::One );

    connect( command, SIGNAL( commandReply( const Reply& ) ), this, SLOT( setUpdate() ) );

    return command;
}

Command* TypesBatch::deleteTypeJob( const Job& job )
{
    Command* command = new Command();

    command->setKeyword( "DELETE TYPE" );
    command->setArgs( job.args() );

    command->addRule( "OK", ReplyRule::One );

    connect( command, SIGNAL( commandReply( const Reply& ) ), this, SLOT( setUpdate() ) );

    return command;
}

Command* TypesBatch::addAttributeJob( const Job& job )
{
    Command* command = new Command();

    command->setKeyword( "ADD ATTRIBUTE" );
    command->setArgs( job.args() );

    command->addRule( "ID i", ReplyRule::One );

    connect( command, SIGNAL( commandReply( const Reply& ) ), this, SLOT( setUpdate() ) );

    return command;
}

Command* TypesBatch::renameAttributeJob( const Job& job )
{
    Command* command = new Command();

    command->setKeyword( "RENAME ATTRIBUTE" );
    command->setArgs( job.args() );

    command->setAcceptNullReply( true );
    command->addRule( "OK", ReplyRule::One );

    connect( command, SIGNAL( commandReply( const Reply& ) ), this, SLOT( setUpdate() ) );

    return command;
}

Command* TypesBatch::modifyAttributeJob( const Job& job )
{
    Command* command = new Command();

    command->setKeyword( "MODIFY ATTRIBUTE" );
    command->setArgs( job.args() );

    command->setAcceptNullReply( true );
    command->addRule( "OK", ReplyRule::One );

    connect( command, SIGNAL( commandReply( const Reply& ) ), this, SLOT( setUpdate() ) );

    return command;
}

Command* TypesBatch::deleteAttributeJob( const Job& job )
{
    Command* command = new Command();

    command->setKeyword( "DELETE ATTRIBUTE" );
    command->setArgs( job.args() );

    command->addRule( "OK", ReplyRule::One );

    connect( command, SIGNAL( commandReply( const Reply& ) ), this, SLOT( setUpdate() ) );

    return command;
}

void TypesBatch::setUpdate()
{
    m_update = true;
}

#include "typesbatch.moc"

Generated by  Doxygen 1.6.0   Back to index