/* This file is part of the KDE project

   Copyright (C) 2005 Dario Massarin <nekkar@libero.it>
   Copyright (C) 2009 Lukas Appelhans <l.appelhans@gmx.de>

   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 "core/job.h"

#include "core/jobqueue.h"
#include "core/scheduler.h"
#include "kget_debug.h"
#include <QDebug>

Job::Job(Scheduler *scheduler, JobQueue *parent)
    : QObject(parent)
    , m_jobQueue(parent)
    , m_scheduler(scheduler)
    , m_status(Stopped)
    , m_policy(None)
{
    m_error.id = -1;
    m_error.type = AutomaticRetry;
}

Job::~Job()
{
}

void Job::setStatus(Status jobStatus)
{
    if (jobStatus == m_status)
        return;
    if (m_status == Aborted) {
        m_error.id = -1;
        m_error.text.clear();
        m_error.iconName = QString();
        m_error.type = AutomaticRetry;
    }
    m_status = jobStatus;
    m_scheduler->jobChangedEvent(this, m_status);
}

void Job::setStartStatus(Status jobStatus)
{
    qCDebug(KGET_DEBUG) << "Setting start status to " << jobStatus;
    m_startStatus = jobStatus;
}

void Job::setPolicy(Policy jobPolicy)
{
    if (jobPolicy == m_policy)
        return;

    qCDebug(KGET_DEBUG) << "Job::setPolicy(" << jobPolicy << ")";

    m_policy = jobPolicy;
    m_scheduler->jobChangedEvent(this, m_policy);
}

void Job::setError(const QString &text, const QString &iconName, ErrorType type, int errorId)
{
    setStatus(Job::Aborted);
    m_error.id = errorId;
    m_error.text = text;
    m_error.iconName = iconName;
    m_error.type = type;
}

void Job::resolveError(int errorId)
{
    Q_UNUSED(errorId)
}

#include "moc_job.cpp"
