File indexing completed on 2024-05-05 04:59:18

0001 /*
0002     This file is part of the KDE project
0003     Copyright (C) 2011 Ernesto Rodriguez Ortiz <eortiz@uci.cu>
0004 
0005     This program is free software: you can redistribute it and/or modify
0006     it under the terms of the GNU General Public License as published by
0007     the Free Software Foundation, either version 3 of the License, or
0008     (at your option) any later version.
0009 
0010     This program is distributed in the hope that it will be useful,
0011     but WITHOUT ANY WARRANTY; without even the implied warranty of
0012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013     GNU General Public License for more details.
0014 
0015     You should have received a copy of the GNU General Public License
0016     along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 
0018 */
0019 
0020 #ifndef MMSDOWNLOAD_H
0021 #define MMSDOWNLOAD_H
0022 
0023 #include <QDataStream>
0024 #include <QFile>
0025 #include <QMap>
0026 #include <QString>
0027 #include <QTimer>
0028 #include <libmms/mmsx.h>
0029 
0030 #include "mmsthread.h"
0031 
0032 class MmsDownload : public QThread
0033 {
0034     Q_OBJECT
0035 public:
0036     MmsDownload(const QString &url, const QString &name, const QString &temp, int amountsThread);
0037     ~MmsDownload() override;
0038     void run() override;
0039     void stopTransfer();
0040     int threadsAlive();
0041 
0042 public Q_SLOTS:
0043     void slotThreadFinish();
0044     void slotRead(int reading, int thread_end, int thead_ini);
0045     void slotSpeedChanged();
0046     void slotIsThreadConnected(bool connected);
0047 
0048 Q_SIGNALS:
0049     void signBrokenUrl();
0050     void signNotAllowMultiDownload();
0051     void signThreadFinish();
0052     qulonglong signDownloaded(qulonglong reading);
0053     qulonglong signTotalSize(qulonglong size);
0054     unsigned long signSpeed(unsigned long bytes_per_second);
0055     void signRestartDownload(int connections);
0056 
0057 private:
0058     bool isWorkingUrl();
0059     void splitTransfer();
0060     void startTransfer();
0061     void unSerialization();
0062     void serialization();
0063 
0064     QString m_sourceUrl;
0065     QString m_fileName;
0066     QString m_fileTemp;
0067     int m_amountThreads;
0068     int m_connectionsFails;
0069     int m_connectionsSuccessfully;
0070     qulonglong m_downloadedSize;
0071     QList<qulonglong> m_prevDownloadedSizes;
0072     mmsx_t *m_mms;
0073     QTimer *m_speedTimer;
0074     QList<MmsThread *> m_threadList;
0075     QMap<int, int> m_mapEndIni;
0076 };
0077 
0078 #endif // MMSDOWNLOAD_H