Scheduler * scheduler, const KUrl & source, const KUrl & dest,
const QDomElement * e)
: Transfer(parent, factory, scheduler, source, dest, e),
- m_copyjob(0),
+ m_copyjob(nullptr),
m_movingFile(false),
- m_verifier(0),
- m_signature(0)
+ m_verifier(nullptr),
+ m_signature(nullptr)
{
- setCapabilities(Transfer::Cap_Moving | Transfer::Cap_Renaming | Transfer::Cap_Resuming);//TODO check if it really can resume
+ // TODO: check if it really can resume
+ setCapabilities(Transfer::Cap_Moving | Transfer::Cap_Renaming | Transfer::Cap_Resuming);
}
bool TransferKio::setDirectory(const KUrl& newDirectory)
m_movingFile = true;
stop();
setStatus(Job::Moving);
- setTransferChange(Tc_Status, true);
+ setTransferChange(Transfer::Tc_Status, true);
m_dest = newDestination;
void TransferKio::newDestResult(KJob *result)
{
- Q_UNUSED(result)//TODO handle errors etc.!
+ //TODO: handle errors etc.!
+ Q_UNUSED(result);
+
m_movingFile = false;
start();
- setTransferChange(Tc_FileName);
+ setTransferChange(Transfer::Tc_FileName);
}
void TransferKio::start()
{
if (!m_movingFile && (status() != Finished)) {
m_stopped = false;
- if(!m_copyjob)
+ if (!m_copyjob) {
createJob();
+ }
kDebug(5001) << "TransferKio::start";
- setStatus(Job::Running, i18nc("transfer state: connecting", "Connecting...."), SmallIcon("network-connect")); // should be "network-connecting", but that doesn't exist for KDE 4.0 yet
- setTransferChange(Tc_Status, true);
+ setStatus(Job::Running);
+ setTransferChange(Transfer::Tc_Status, true);
}
}
m_stopped = true;
- if(m_copyjob)
- {
+ if (m_copyjob) {
m_copyjob->kill(KJob::EmitResult);
m_copyjob=0;
}
kDebug(5001) << "Stop";
setStatus(Job::Stopped);
m_downloadSpeed = 0;
- setTransferChange(Tc_Status | Tc_DownloadSpeed, true);
+ setTransferChange(Transfer::Tc_Status | Transfer::Tc_DownloadSpeed, true);
}
void TransferKio::deinit(Transfer::DeleteOptions options)
{
KIO::Job *del = KIO::del(QString(m_dest.path() + ".part"), KIO::HideProgressInfo);
KIO::NetAccess::synchronousRun(del, 0);
- }//TODO: Ask the user if he/she wants to delete the *.part-file? To discuss (boom1992)
+ }
+ //TODO: Ask the user if he/she wants to delete the *.part-file? To discuss (boom1992)
+}
+
+bool TransferKio::repair(const KUrl &file)
+{
+ Q_UNUSED(file);
+
+ if (verifier()->status() == Verifier::NotVerified) {
+ m_downloadedSize = 0;
+ m_percent = 0;
+ if (m_copyjob) {
+ m_copyjob->kill(KJob::Quietly);
+ m_copyjob = 0;
+ }
+ setTransferChange(Transfer::Tc_DownloadedSize | Transfer::Tc_Percent, true);
+
+ start();
+
+ return true;
+ }
+
+ return false;
+}
+
+Verifier *TransferKio::verifier(const KUrl &file)
+{
+ Q_UNUSED(file);
+
+ if (!m_verifier) {
+ m_verifier = new Verifier(m_dest, this);
+ connect(m_verifier, SIGNAL(verified(bool)), this, SLOT(slotVerified(bool)));
+ }
+
+ return m_verifier;
+}
+
+Signature *TransferKio::signature(const KUrl &file)
+{
+ Q_UNUSED(file);
+
+ if (!m_signature) {
+ m_signature = new Signature(m_dest, this);
+ }
+
+ return m_signature;
}
//NOTE: INTERNAL METHODS
void TransferKio::createJob()
{
- if(!m_copyjob)
- {
+ if (!m_copyjob) {
KIO::Scheduler::checkSlaveOnHold(true);
m_copyjob = KIO::file_copy(m_source, m_dest, -1, KIO::HideProgressInfo);
{
kDebug(5001) << "slotResult (" << kioJob->error() << ")";
switch (kioJob->error()) {
- case 0: //The download has finished
- case KIO::ERR_FILE_ALREADY_EXIST: //The file has already been downloaded.
+ case 0: // The download has finished
+ case KIO::ERR_FILE_ALREADY_EXIST: // The file has already been downloaded.
setStatus(Job::Finished);
- // "ok" icon should probably be "dialog-success", but we don't have that icon in KDE 4.0
m_percent = 100;
m_downloadSpeed = 0;
m_downloadedSize = m_totalSize;
- setTransferChange(Tc_Percent | Tc_DownloadSpeed);
+ setTransferChange(Transfer::Tc_Status | Transfer::Tc_Percent | Transfer::Tc_DownloadSpeed, true);
break;
default:
- //There has been an error
+ // There has been an error
kDebug(5001) << "-- E R R O R (" << kioJob->error() << ")--";
- if (!m_stopped)
+ if (!m_stopped) {
setStatus(Job::Aborted);
+ setTransferChange(Transfer::Tc_Status, true);
+ }
break;
}
// when slotResult gets called, the m_copyjob has already been deleted!
- m_copyjob=0;
+ m_copyjob = 0;
// If it is an ftp file, there's still work to do
- Transfer::ChangesFlags flags = (m_source.protocol() != "ftp") ? Tc_Status : Tc_None;
+ Transfer::ChangesFlags flags = Transfer::Tc_None;
if (status() == Job::Finished) {
if (!m_totalSize) {
//downloaded elsewhere already, e.g. Konqueror
void TransferKio::slotInfoMessage( KJob * kioJob, const QString & msg )
{
- Q_UNUSED(kioJob)
- m_log.append(QString(msg));
+ Q_UNUSED(kioJob);
+
+ setLog(msg, Transfer::Log_Info);
+ setTransferChange(Transfer::Tc_Log, true);
}
void TransferKio::slotPercent( KJob * kioJob, unsigned long percent )
{
kDebug(5001) << "slotPercent";
- Q_UNUSED(kioJob)
+ Q_UNUSED(kioJob);
+
m_percent = percent;
- setTransferChange(Tc_Percent, true);
+ setTransferChange(Transfer::Tc_Percent, true);
}
void TransferKio::slotTotalSize( KJob * kioJob, qulonglong size )
{
- Q_UNUSED(kioJob)
-
kDebug(5001) << "slotTotalSize";
-
- setStatus(Job::Running);
+ Q_UNUSED(kioJob);
m_totalSize = size;
- setTransferChange(Tc_Status | Tc_TotalSize, true);
+ setTransferChange(Transfer::Tc_TotalSize, true);
}
void TransferKio::slotProcessedSize( KJob * kioJob, qulonglong size )
{
- Q_UNUSED(kioJob)
-
-// kDebug(5001) << "slotProcessedSize";
+ kDebug(5001) << "slotProcessedSize";
+ Q_UNUSED(kioJob);
- if(status() != Job::Running)
- {
+ if (status() != Job::Running) {
setStatus(Job::Running);
- setTransferChange(Tc_Status);
+ setTransferChange(Transfer::Tc_Status, true);
}
m_downloadedSize = size;
- setTransferChange(Tc_DownloadedSize, true);
+ setTransferChange(Transfer::Tc_DownloadedSize, true);
}
void TransferKio::slotSpeed( KJob * kioJob, unsigned long bytes_per_second )
{
+ kDebug(5001) << "slotSpeed";
Q_UNUSED(kioJob)
-// kDebug(5001) << "slotSpeed";
-
- if(status() != Job::Running)
- {
+ if (status() != Job::Running) {
if (m_movingFile)
setStatus(Job::Moving);
else
setStatus(Job::Running);
- setTransferChange(Tc_Status);
+ setTransferChange(Transfer::Tc_Status, true);
}
m_downloadSpeed = bytes_per_second;
- setTransferChange(Tc_DownloadSpeed, true);
+ setTransferChange(Transfer::Tc_DownloadSpeed, true);
}
void TransferKio::slotVerified(bool isVerified)
}
setStatus(Job::Finished);
- setTransferChange(Tc_Status, true);
-}
-
-
-bool TransferKio::repair(const KUrl &file)
-{
- Q_UNUSED(file)
-
- if (verifier()->status() == Verifier::NotVerified)
- {
- m_downloadedSize = 0;
- m_percent = 0;
- if(m_copyjob)
- {
- m_copyjob->kill(KJob::Quietly);
- m_copyjob = 0;
- }
- setTransferChange(Tc_DownloadedSize | Tc_Percent, true);
-
- start();
-
- return true;
- }
-
- return false;
-}
-
-Verifier *TransferKio::verifier(const KUrl &file)
-{
- Q_UNUSED(file)
-
- if (!m_verifier)
- {
- m_verifier = new Verifier(m_dest, this);
- connect(m_verifier, SIGNAL(verified(bool)), this, SLOT(slotVerified(bool)));
- }
-
- return m_verifier;
-}
-
-Signature *TransferKio::signature(const KUrl &file)
-{
- Q_UNUSED(file)
-
- if (!m_signature) {
- m_signature = new Signature(m_dest, this);
- }
-
- return m_signature;
+ setTransferChange(Transfer::Tc_Status, true);
}
#include "moc_transferKio.cpp"
class TransferKio : public Transfer
{
Q_OBJECT
-
- public:
- TransferKio(TransferGroup * parent, TransferFactory * factory,
- Scheduler * scheduler, const KUrl & src, const KUrl & dest,
- const QDomElement * e = 0);
-
- /**
- * Move the download to the new destination
- * @param newDirectory is a directory where the download should be stored
- * @returns true if newDestination can be used
- */
- virtual bool setDirectory(const KUrl &newDirectory);
-
- bool repair(const KUrl &file = KUrl());
-
- Verifier *verifier(const KUrl &file = KUrl());
- Signature *signature(const KUrl &file = KUrl());
-
- public slots:
- bool setNewDestination(const KUrl &newDestination);
-
- // --- Job virtual functions ---
- void start();
- void stop();
-
- void deinit(Transfer::DeleteOptions options);
-
- private:
- void createJob();
-
- KIO::FileCopyJob * m_copyjob;
- bool m_stopped;
- bool m_movingFile;
-
- private slots:
- void slotResult( KJob * kioJob );
- void slotInfoMessage( KJob * kioJob, const QString & msg );
- void slotPercent( KJob * kioJob, unsigned long percent );
- void slotTotalSize( KJob * kioJob, qulonglong size );
- void slotProcessedSize( KJob * kioJob, qulonglong size );
- void slotSpeed( KJob * kioJob, unsigned long bytes_per_second );
- void newDestResult(KJob *result);
- void slotVerified(bool isVerified);
- void slotStatResult(KJob * kioJob);
-
- private:
- Verifier *m_verifier;
- Signature *m_signature;
+public:
+ TransferKio(TransferGroup * parent, TransferFactory * factory,
+ Scheduler * scheduler, const KUrl & src, const KUrl & dest,
+ const QDomElement * e = 0);
+
+ // --- Job virtual functions ---
+ void start() final;
+ void stop() final;
+
+ // --- Transfer virtual functions ---
+ void deinit(Transfer::DeleteOptions options);
+
+ /**
+ * Move the download to the new destination
+ * @param newDirectory is a directory where the download should be stored
+ * @returns true if newDestination can be used
+ */
+ bool setDirectory(const KUrl &newDirectory) final;
+
+ bool repair(const KUrl &file = KUrl()) final;
+
+ Verifier *verifier(const KUrl &file = KUrl()) final;
+ Signature *signature(const KUrl &file = KUrl()) final;
+
+private:
+ bool setNewDestination(const KUrl &newDestination);
+ void createJob();
+
+ KIO::FileCopyJob * m_copyjob;
+ bool m_stopped;
+ bool m_movingFile;
+
+private slots:
+ void slotResult( KJob * kioJob );
+ void slotInfoMessage( KJob * kioJob, const QString & msg );
+ void slotPercent( KJob * kioJob, unsigned long percent );
+ void slotTotalSize( KJob * kioJob, qulonglong size );
+ void slotProcessedSize( KJob * kioJob, qulonglong size );
+ void slotSpeed( KJob * kioJob, unsigned long bytes_per_second );
+ void newDestResult(KJob *result);
+ void slotVerified(bool isVerified);
+ void slotStatResult(KJob * kioJob);
+
+private:
+ Verifier *m_verifier;
+ Signature *m_signature;
};
#endif