/****************************************************************************
**
** Copyright (C) 2012 Róbert Márki
**
** This file is part of Web Feeds.
**
** Web Feeds 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 3 of the License, or
** (at your option) any later version.
**
** Web Feeds is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Web Feeds.  If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/

#include "webservicereply.h"

/*!
  \class WebServiceReply
  \brief The WebServiceReply class represents a reply of the NewsBlur server.

  It describes the result of a NewsBlur request, and stores the parsed contents
  of a reply.
*/
/*!
  \enum WebServiceReply::Role
  Specifies the role of a request.

  \var WebServiceReply::Role WebServiceReply::RlUndefined
  Undefined role.
  \var WebServiceReply::Role WebServiceReply::RlUpdate
  The role of a request which only retrieves data from the server,
  but doesn't modifies anything.
  \var WebServiceReply::Role WebServiceReply::RlCommit
  The role of a request which alters some data on the server.
*/
/*!
  \enum WebServiceReply::CompletedState
  Specifies the completition state of a request.

  \var WebServiceReply::CompletedState WebServiceReply::CsNotCompleted
  The request is not completed yet.
  \var WebServiceReply::CompletedState WebServiceReply::CsFinished
  The request finished successfuly.
  \var WebServiceReply::CompletedState WebServiceReply::CsAborted
  The request has been aborted.
  \var WebServiceReply::CompletedState WebServiceReply::CsFailed
  Failed to complete request successfuly.
*/
/*!
  \fn WebServiceReply::abortRequested
  The signal is emitted when the network request related
  to this request has to be aborted.
  The \a reply parameter specifies the current reply object.
*/
/*!
  \fn WebServiceReply::finished
  The signal is emitted when the request successfuly finishes.
  The \a reply parameter specifies the current reply object.
*/
/*!
  \fn WebServiceReply::failed
  The signal is emitted when the request has failed.
  The \a reply parameter specifies the current reply object.
*/
/*!
  \fn WebServiceReply::aborted
  The signal is emitted when the request is aborted.
  The \a reply parameter specifies the current reply object.
*/
/*!
  \fn WebServiceReply::completed
  The signal is emitted when the request is completed.
  The requests completition state can be retrieved with
  WebServiceReply::completedState().
  The \a reply parameter specifies the current reply object.
*/

/*!
  Constructs a WebServiceReply object.
*/
WebServiceReply::WebServiceReply() :
    QObject(0),
    m_error(0),
    m_completedState(CsNotCompleted),
    m_requestType(0)
{
}

/*!
  Destroys the WebServiceReply object.
*/
WebServiceReply::~WebServiceReply()
{
}

/*!
  Returns the error type of a request if an error occured,
  otherwise NewsBlurEnum::SreNoError is returned.
*/
int WebServiceReply::error() const
{
    return m_error;
}

/*!
  Sets the \a error identifier of the request.
*/
void WebServiceReply::setError(int error)
{
    m_error = error;
}

/*!
  Aborts the request.
*/
void WebServiceReply::abort()
{
    emit abortRequested(WebServiceReplyWeakRef(this));
}

/*!
  Returns the type of the request.
*/
int WebServiceReply::requestType() const
{
    return m_requestType;
}

///*!
//  Returns the role of the request.
//  The default return value is WebServiceReply::RlCommit.
//*/
//WebServiceReply::Role WebServiceReply::role() const
//{
//    return WebServiceReply::RlCommit;
//}

/*!
  Returns the completition state of the request.
*/
WebServiceReply::CompletedState WebServiceReply::completedState() const
{
    return m_completedState;
}

/*!
  Modifies the completition state of the request.
*/
void WebServiceReply::setCompletedState(WebServiceReply::CompletedState completedState)
{
    if(m_completedState == CsNotCompleted)
    {
        m_completedState = completedState;
        if(m_completedState == CsFinished)
            emit finished(WebServiceReplyWeakRef(this));
        else if(completedState == CsAborted)
            emit aborted(WebServiceReplyWeakRef(this));
        else if(completedState == CsFailed)
            emit failed(WebServiceReplyWeakRef(this));
        emit completed(WebServiceReplyWeakRef(this), m_completedState);
    }
}

void WebServiceReply::setRequestType(int requestType)
{
    m_requestType = requestType;
}

