File indexing completed on 2024-04-28 04:57:31

0001 /* This file is part of the KDE project
0002 
0003    Copyright (C) 2012 by Aish Raj Dahal <dahalaishraj@gmail.com>
0004 
0005    This program is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 */
0010 
0011 #ifndef ABSTRACTMETALINK_H
0012 #define ABSTRACTMETALINK_H
0013 
0014 #include <KIO/Job>
0015 
0016 #include "core/datasourcefactory.h"
0017 #include "core/transfer.h"
0018 
0019 #include "ui/metalinkcreator/metalinker.h"
0020 
0021 class AbstractMetalink : public Transfer
0022 {
0023     Q_OBJECT
0024 
0025 public:
0026     AbstractMetalink(TransferGroup *parent, TransferFactory *factory, Scheduler *scheduler, const QUrl &src, const QUrl &dest, const QDomElement *e = nullptr);
0027     ~AbstractMetalink() override;
0028 
0029     int remainingTime() const override;
0030 
0031     bool repair(const QUrl &file = QUrl()) override;
0032 
0033     /**
0034      * Move the download to the new destination
0035      * @param newDirectory is a directory where the download should be stored
0036      * @returns true if newDestination can be used
0037      */
0038     bool setDirectory(const QUrl &newDirectory) override;
0039 
0040     QHash<QUrl, QPair<bool, int>> availableMirrors(const QUrl &file) const override;
0041     void setAvailableMirrors(const QUrl &file, const QHash<QUrl, QPair<bool, int>> &mirrors) override;
0042 
0043     /**
0044      * @param file for which to get the verifier
0045      * @return Verifier that allows you to add checksums manually verify a file etc.
0046      */
0047     Verifier *verifier(const QUrl &file) override;
0048 
0049     /**
0050      * @param file for which to get the signature
0051      * @return Signature that allows you to add signatures and verify them
0052      */
0053     Signature *signature(const QUrl &file) override;
0054 
0055     QList<QUrl> files() const override;
0056 
0057     FileModel *fileModel() override;
0058 
0059 public Q_SLOTS:
0060     // --- Job virtual functions ---
0061     void start() override = 0;
0062     void stop() override;
0063     void deinit(Transfer::DeleteOptions options) override = 0;
0064 
0065 protected Q_SLOTS:
0066     /**
0067      * @return true if initialising worked
0068      * @note false does not mean that an error happened, it could mean, that the user
0069      * decided to update the metalink
0070      */
0071     void fileDlgFinished(int result);
0072 
0073     /**
0074      * Checks if the ticked (not started yet) files exist already on the hd and asks
0075      * the user how to proceed in that case. Also calls the according DataSourceFactories
0076      * setDoDownload(bool) methods.
0077      */
0078 
0079     void filesSelected();
0080     void slotUpdateCapabilities();
0081     void slotDataSourceFactoryChange(Transfer::ChangesFlags change);
0082     void slotRename(const QUrl &oldUrl, const QUrl &newUrl);
0083     void slotVerified(bool isVerified);
0084     virtual void slotSignatureVerified();
0085 
0086 protected:
0087     /**
0088      * Starts the type of metalink download
0089      */
0090     virtual void startMetalink() = 0;
0091     void untickAllFiles();
0092     void recalculateTotalSize(DataSourceFactory *sender);
0093     void recalculateProcessedSize();
0094     void recalculateSpeed();
0095     void updateStatus(DataSourceFactory *sender, bool *changeStatus);
0096 
0097 protected:
0098     FileModel *m_fileModel;
0099     int m_currentFiles;
0100     QHash<QUrl, DataSourceFactory *> m_dataSourceFactory;
0101     bool m_ready;
0102     int m_speedCount;
0103     int m_tempAverageSpeed;
0104     mutable int m_averageSpeed;
0105     int m_numFilesSelected; // The number of files that are ticked and should be downloaded
0106 };
0107 
0108 #endif