File indexing completed on 2024-12-01 04:33:13

0001 /* This file is part of the KDE project
0002 
0003    Copyright (C) 2005 Dario Massarin <nekkar@libero.it>
0004    Copyright (C) 2009 Lukas Appelhans <l.appelhans@gmx.de>
0005 
0006    This program is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU General Public
0008    License as published by the Free Software Foundation; either
0009    version 2 of the License, or (at your option) any later version.
0010 */
0011 
0012 #include "core/job.h"
0013 
0014 #include "core/jobqueue.h"
0015 #include "core/scheduler.h"
0016 #include "kget_debug.h"
0017 #include <QDebug>
0018 
0019 Job::Job(Scheduler *scheduler, JobQueue *parent)
0020     : QObject(parent)
0021     , m_jobQueue(parent)
0022     , m_scheduler(scheduler)
0023     , m_status(Stopped)
0024     , m_policy(None)
0025 {
0026     m_error.id = -1;
0027     m_error.type = AutomaticRetry;
0028 }
0029 
0030 Job::~Job()
0031 {
0032 }
0033 
0034 void Job::setStatus(Status jobStatus)
0035 {
0036     if (jobStatus == m_status)
0037         return;
0038     if (m_status == Aborted) {
0039         m_error.id = -1;
0040         m_error.text.clear();
0041         m_error.iconName = QString();
0042         m_error.type = AutomaticRetry;
0043     }
0044     m_status = jobStatus;
0045     m_scheduler->jobChangedEvent(this, m_status);
0046 }
0047 
0048 void Job::setStartStatus(Status jobStatus)
0049 {
0050     qCDebug(KGET_DEBUG) << "Setting start status to " << jobStatus;
0051     m_startStatus = jobStatus;
0052 }
0053 
0054 void Job::setPolicy(Policy jobPolicy)
0055 {
0056     if (jobPolicy == m_policy)
0057         return;
0058 
0059     qCDebug(KGET_DEBUG) << "Job::setPolicy(" << jobPolicy << ")";
0060 
0061     m_policy = jobPolicy;
0062     m_scheduler->jobChangedEvent(this, m_policy);
0063 }
0064 
0065 void Job::setError(const QString &text, const QString &iconName, ErrorType type, int errorId)
0066 {
0067     setStatus(Job::Aborted);
0068     m_error.id = errorId;
0069     m_error.text = text;
0070     m_error.iconName = iconName;
0071     m_error.type = type;
0072 }
0073 
0074 void Job::resolveError(int errorId)
0075 {
0076     Q_UNUSED(errorId)
0077 }
0078 
0079 #include "moc_job.cpp"