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

usersbatch.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 "usersbatch.h"

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

using namespace WebIssues;

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

00024 UsersBatch::~UsersBatch()
{
}

00028 void UsersBatch::addUser( const QString& login, const QString& name, const QString& password )
{
    Job job( &UsersBatch::addUserJob );
    job.addArg( login );
    job.addArg( name );
    job.addArg( password );
    m_queue.addJob( job );
}

00037 void UsersBatch::setPassword( int userId, const QString& password )
{
    Job job( &UsersBatch::setPasswordJob );
    job.addArg( userId );
    job.addArg( password );
    m_queue.addJob( job );
}

00045 void UsersBatch::grantUser( int userId, Access access )
{
    Job job( &UsersBatch::grantUserJob );
    job.addArg( userId );
    job.addArg( access );
    m_queue.addJob( job );
}

00053 void UsersBatch::renameUser( int userId, const QString& newName )
{
    Job job( &UsersBatch::renameUserJob );
    job.addArg( userId );
    job.addArg( newName );
    m_queue.addJob( job );
}

00061 void UsersBatch::grantMember( int userId, int projectId, Access access )
{
    Job job( &UsersBatch::grantMemberJob );
    job.addArg( userId );
    job.addArg( projectId );
    job.addArg( access );
    m_queue.addJob( job );
}

00070 Command* UsersBatch::fetchNext()
{
    if ( m_queue.moreJobs() )
        return m_queue.callJob( this );

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

    return NULL;
}

Command* UsersBatch::addUserJob( const Job& job )
{
    Command* command = new Command();

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

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

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

    return command;
}

Command* UsersBatch::setPasswordJob( const Job& job )
{
    Command* command = new Command();

    command->setKeyword( "SET PASSWORD" );
    command->setArgs( job.args() );

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

    return command;
}

Command* UsersBatch::grantUserJob( const Job& job )
{
    Command* command = new Command();

    command->setKeyword( "GRANT USER" );
    command->setArgs( job.args() );

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

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

    return command;
}

Command* UsersBatch::renameUserJob( const Job& job )
{
    Command* command = new Command();

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

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

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

    return command;
}

Command* UsersBatch::grantMemberJob( const Job& job )
{
    Command* command = new Command();

    command->setKeyword( "GRANT MEMBER" );
    command->setArgs( job.args() );

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

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

    return command;
}

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

#include "usersbatch.moc"

Generated by  Doxygen 1.6.0   Back to index