diff options
Diffstat (limited to 'kget/transfer.cpp')
-rw-r--r-- | kget/transfer.cpp | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/kget/transfer.cpp b/kget/transfer.cpp index d1ff6f0b..f8ef34f3 100644 --- a/kget/transfer.cpp +++ b/kget/transfer.cpp @@ -24,6 +24,7 @@ ***************************************************************************/ #include <tqheader.h> +#include <tqtimer.h> #include <kurl.h> #include <tdemessagebox.h> @@ -43,11 +44,13 @@ #include "dlgIndividual.h" #include "transferlist.h" #include "transfer.h" +#include "getfilejob.h" #include <tdeapplication.h> #include <tdeio/passdlg.h> #include <tdeio/global.h> #include <tdeio/netaccess.h> +#include <tdeio/scheduler.h> extern Settings ksettings; @@ -117,7 +120,6 @@ Transfer::init(const uint _id) status = ST_STOPPED; - connect(this, TQT_SIGNAL(statusChanged(Transfer *, int)), tdemain, TQT_SLOT(slotStatusChanged(Transfer *, int))); connect(this, TQT_SIGNAL(statusChanged(Transfer *, int)), this, TQT_SLOT(slotUpdateActions())); @@ -160,6 +162,7 @@ void Transfer::synchronousAbort() { if ( m_pSlave->running() ) { + destroyGetFileJob(); m_pSlave->Op(Slave::KILL); m_pSlave->wait(); } @@ -281,14 +284,13 @@ void Transfer::updateAll() // destination setText(view->lv_filename, dest.fileName()); - if(dlgIndividual) - { - dlgIndividual->setCopying(src, dest); - dlgIndividual->setCanResume(canResume); - dlgIndividual->setTotalSize(totalSize); - dlgIndividual->setPercent(0); - dlgIndividual->setProcessedSize(0); - } + if (dlgIndividual) { + dlgIndividual->setCopying(src, dest); + dlgIndividual->setCanResume(canResume); + dlgIndividual->setTotalSize(totalSize); + dlgIndividual->setPercent(0); + dlgIndividual->setProcessedSize(0); + } if (totalSize != 0) { //logMessage(i18n("Total size is %1 bytes").arg((double)totalSize)); @@ -389,6 +391,7 @@ void Transfer::slotResume() logMessage(i18n("Attempt number %1").arg(retryCount)); sDebug << "sending Resume to slave " << endl; + createGetFileJob(m_pSlave->m_src, m_pSlave->m_dest, false); m_pSlave->Op(Slave::RETR); sDebugOut << endl; @@ -403,6 +406,7 @@ void Transfer::slotResume() assert(status <= ST_RUNNING && ksettings.b_offline); + destroyGetFileJob(); m_pSlave->Op(Slave::KILL); // KILL doesn't post a Message sDebug << "Killing Slave" << endl; @@ -430,7 +434,7 @@ void Transfer::slotRequestPause() m_paPause->setEnabled(false); m_paRestart->setEnabled(false); - + destroyGetFileJob(); m_pSlave->Op(Slave::PAUSE); sDebug << "Requesting Pause.." << endl; @@ -443,6 +447,8 @@ void Transfer::slotRequestPause() void Transfer::slotRequestRestart() { sDebugIn << endl; + destroyGetFileJob(); + createGetFileJob(m_pSlave->m_src, m_pSlave->m_dest, true); m_pSlave->Op(Slave::RESTART); slotSpeed(0); sDebugOut << endl; @@ -477,10 +483,13 @@ void Transfer::slotRequestRemove() SafeDelete::deleteFile( file ); // ### messagebox on failure? } } - if (status == ST_RUNNING) + if (status == ST_RUNNING) { + destroyGetFileJob(); m_pSlave->Op(Slave::REMOVE); - else + } + else { emit statusChanged(this, OP_REMOVED); + } sDebugOut << endl; } @@ -517,6 +526,7 @@ void Transfer::slotRequestSchedule() if (status == ST_RUNNING) { m_paPause->setEnabled(false); m_paRestart->setEnabled(false); + destroyGetFileJob(); m_pSlave->Op(Slave::SCHEDULE); } else @@ -535,6 +545,7 @@ void Transfer::slotRequestDelay() if (status == ST_RUNNING) { m_paPause->setEnabled(false); m_paRestart->setEnabled(false); + destroyGetFileJob(); m_pSlave->Op(Slave::DELAY); } else slotExecDelay(); @@ -894,6 +905,7 @@ void Transfer::slotExecConnected() if (ksettings.b_offline)// when we're offline and arrive here, then the file is in cache return; // Slave::slotResult will be called immediately, so we do nothing here status = ST_STOPPED; + destroyGetFileJob(); m_pSlave->Op(Slave::KILL); if (ksettings.b_addQueued) { @@ -1006,6 +1018,7 @@ void Transfer::checkCache() if (src.protocol()=="http") { status = ST_TRYING; + createGetFileJob(m_pSlave->m_src, m_pSlave->m_dest, true); m_pSlave->Op(Slave::RETR_CACHE); } else @@ -1021,5 +1034,24 @@ void Transfer::NotInCache() mode = MD_DELAYED; status = ST_STOPPED; } + +void Transfer::destroyGetFileJob() +{ + if (m_pSlave->copyjob) { + m_pSlave->copyjob->kill(true); + m_pSlave->copyjob = 0L; + } +} + +void Transfer::createGetFileJob(KURL m_src, KURL m_dest, bool cache) +{ + TDEIO::Scheduler::checkSlaveOnHold( true ); + m_pSlave->copyjob = new TDEIO::GetFileJob(m_src, m_dest); + if (cache) { + m_pSlave->copyjob->addMetaData("cache", "cacheonly"); + } + m_pSlave->Connect(); +} + #include "transfer.moc" |