New feature for KGet: Webinterface.
[kdenetwork.git] / kget / core / kuiserverjobs.cpp
blobf1704372e15e159b2ee8fb5fa1e19f83feed1079
1 /* This file is part of the KDE project
3 Copyright (C) 2007 by Javier Goday <jgoday@gmail.com>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9 */
11 #include "kuiserverjobs.h"
13 #include "kgetglobaljob.h"
14 #include "settings.h"
16 #include <kuiserverjobtracker.h>
18 KUiServerJobs::KUiServerJobs(QObject *parent)
19 : QObject(parent), m_jobs(), m_globalJob(0)
23 KUiServerJobs::~KUiServerJobs()
27 void KUiServerJobs::registerJob(KJob *job)
29 m_jobs.append(job);
31 if(Settings::enableKUIServerIntegration()) {
32 if(Settings::exportGlobalJob()) {
33 globalJob()->registerJob(job);
35 else {
36 KIO::getJobTracker()->registerJob(job);
41 void KUiServerJobs::unregisterJob(KJob *job)
43 m_jobs.removeAll(job);
45 if(Settings::enableKUIServerIntegration()) {
46 if(Settings::exportGlobalJob()) {
47 globalJob()->unregisterJob(job);
49 else {
50 KIO::getJobTracker()->unregisterJob(job);
55 // every time the configuration changed, check the registered jobs and the state through the ui server
56 void KUiServerJobs::reload()
58 if(m_globalJob && !Settings::exportGlobalJob()) {
59 KIO::getJobTracker()->unregisterJob(globalJob());
60 delete m_globalJob;
61 m_globalJob = 0;
64 if(Settings::exportGlobalJob()) {
65 KIO::getJobTracker()->registerJob(globalJob());
67 foreach(KJob *job, m_jobs) {
68 KIO::getJobTracker()->unregisterJob(job);
71 else {
72 foreach(KJob *job, m_jobs) {
73 if(Settings::enableKUIServerIntegration() && job && job->percent() < 100) {
74 KIO::getJobTracker()->registerJob(job);
76 else {
77 KIO::getJobTracker()->unregisterJob(job);
83 // get the kget global job
84 KGetGlobalJob *KUiServerJobs::globalJob()
86 if(!m_globalJob) {
87 m_globalJob = new KGetGlobalJob();
89 foreach(KJob *job, m_jobs) {
90 m_globalJob->registerJob(job);
94 return m_globalJob;