OSDN Git Service

kget: fix KIO transfer plugin status on finished transfer
authorIvailo Monev <xakepa10@gmail.com>
Fri, 25 Mar 2022 12:29:07 +0000 (14:29 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Fri, 25 Mar 2022 12:29:07 +0000 (14:29 +0200)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
kget/transfer-plugins/kio/transferKio.cpp
kget/transfer-plugins/kio/transferKio.h

index eefab47..51ddf6d 100644 (file)
@@ -32,12 +32,13 @@ TransferKio::TransferKio(TransferGroup * parent, TransferFactory * factory,
                          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)
@@ -55,7 +56,7 @@ bool TransferKio::setNewDestination(const KUrl &newDestination)
             m_movingFile = true;
             stop();
             setStatus(Job::Moving);
-            setTransferChange(Tc_Status, true);
+            setTransferChange(Transfer::Tc_Status, true);
 
             m_dest = newDestination;
 
@@ -79,22 +80,25 @@ bool TransferKio::setNewDestination(const KUrl &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);
     }
 }
 
@@ -106,8 +110,7 @@ void TransferKio::stop()
 
     m_stopped = true;
 
-    if(m_copyjob)
-    {
+    if (m_copyjob) {
         m_copyjob->kill(KJob::EmitResult);
         m_copyjob=0;
     }
@@ -115,7 +118,7 @@ void TransferKio::stop()
     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)
@@ -124,15 +127,59 @@ 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);
 
@@ -155,27 +202,28 @@ void TransferKio::slotResult( KJob * kioJob )
 {
     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
@@ -209,63 +257,59 @@ void TransferKio::slotResult( KJob * kioJob )
 
 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)
@@ -298,55 +342,7 @@ void TransferKio::slotStatResult(KJob* kioJob)
     }
 
     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"
index 19faa4c..3eaa05b 100644 (file)
@@ -27,54 +27,52 @@ class Verifier;
 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