File indexing completed on 2024-04-28 04:57:32
0001 /* This file is part of the KDE project 0002 0003 Copyright (C) 2004 Dario Massarin <nekkar@libero.it> 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 METALINK_H 0012 #define METALINK_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 Metalink : public Transfer 0022 { 0023 Q_OBJECT 0024 0025 public: 0026 Metalink(TransferGroup *parent, TransferFactory *factory, Scheduler *scheduler, const QUrl &src, const QUrl &dest, const QDomElement *e = nullptr); 0027 0028 ~Metalink(); 0029 0030 void save(const QDomElement &element); 0031 void load(const QDomElement *e); 0032 0033 /** 0034 * Reimplemented to return a time based on the average of the last three speeds 0035 */ 0036 int remainingTime() const; 0037 0038 bool repair(const QUrl &file = QUrl()); 0039 0040 /** 0041 * Move the download to the new destination 0042 * @param newDirectory is a directory where the download should be stored 0043 * @returns true if newDestination can be used 0044 */ 0045 virtual bool setDirectory(const QUrl &newDirectory); 0046 0047 QHash<QUrl, QPair<bool, int>> availableMirrors(const QUrl &file) const; 0048 void setAvailableMirrors(const QUrl &file, const QHash<QUrl, QPair<bool, int>> &mirrors); 0049 0050 /** 0051 * @param file for which to get the verifier 0052 * @return Verifier that allows you to add checksums manually verify a file etc. 0053 */ 0054 virtual Verifier *verifier(const QUrl &file); 0055 0056 /** 0057 * @param file for which to get the signature 0058 * @return Signature that allows you to add signatures and verify them 0059 */ 0060 virtual Signature *signature(const QUrl &file); 0061 0062 virtual QList<QUrl> files() const; 0063 0064 FileModel *fileModel(); 0065 0066 public Q_SLOTS: 0067 // --- Job virtual functions --- 0068 void start(); 0069 void stop(); 0070 0071 void deinit(Transfer::DeleteOptions options); 0072 0073 private Q_SLOTS: 0074 /** 0075 * @return true if initialising worked 0076 * @note false does not mean that an error happened, it could mean, that the user 0077 * decided to update the metalink 0078 */ 0079 bool metalinkInit(const QUrl &url = QUrl(), const QByteArray &data = QByteArray()); 0080 0081 void fileDlgFinished(int result); 0082 /** 0083 * Checks if the ticked (not started yet) files exist already on the hd and asks 0084 * the user how to proceed in that case. Also calls the according DataSourceFactories 0085 * setDoDownload(bool) methods. 0086 */ 0087 void filesSelected(); 0088 void slotUpdateCapabilities(); 0089 void slotDataSourceFactoryChange(Transfer::ChangesFlags change); 0090 void slotRename(const QUrl &oldUrl, const QUrl &newUrl); 0091 void slotVerified(bool isVerified); 0092 void slotSignatureVerified(); 0093 0094 private: 0095 void downloadMetalink(); 0096 void startMetalink(); 0097 void untickAllFiles(); 0098 void recalculateTotalSize(DataSourceFactory *sender); 0099 void recalculateProcessedSize(); 0100 void recalculateSpeed(); 0101 void updateStatus(DataSourceFactory *sender, bool *changeStatus); 0102 0103 private: 0104 FileModel *m_fileModel; 0105 int m_currentFiles; 0106 bool m_metalinkJustDownloaded; 0107 QUrl m_localMetalinkLocation; 0108 KGetMetalink::Metalink m_metalink; 0109 QHash<QUrl, DataSourceFactory *> m_dataSourceFactory; 0110 bool m_ready; 0111 int m_speedCount; 0112 int m_tempAverageSpeed; 0113 mutable int m_averageSpeed; 0114 int m_numFilesSelected; // The number of files that are ticked and should be downloaded 0115 }; 0116 0117 #endif