30 m_amountThreads(amountsThread),
31 m_connectionsFails(0),
32 m_connectionsSuccefully(0),
36 m_speedTimer =
new QTimer(
this);
47 m_speedTimer->deleteLater();
63 bool MmsDownload::isWorkingUrl()
66 m_mms = mmsx_connect(NULL, NULL, qstrdup(m_sourceUrl.toAscii()), 1e9);
70 void MmsDownload::splitTransfer()
76 m_amountThreads = mmsx_get_seekable(m_mms) ? m_amountThreads : 0;
77 if (m_amountThreads == 0) {
80 QFile::remove(m_fileTemp);
83 const qulonglong total = mmsx_get_length(m_mms);
86 if (QFile::exists(m_fileTemp)) {
89 int part = mmsx_get_length(m_mms) / m_amountThreads;
92 for (
int i = 0; i < m_amountThreads; i++) {
93 if (i + 1 == m_amountThreads) {
97 m_mapEndIni.insert(end, ini);
103 void MmsDownload::startTransfer()
105 m_speedTimer->start();
106 QMap<int, int>::const_iterator iterator = m_mapEndIni.constBegin();
107 while (iterator != m_mapEndIni.constEnd()) {
109 iterator.value(), iterator.key());
110 m_threadList.append(thread);
113 connect(thread, SIGNAL(signReading(
int,
int,
int)),
this, SLOT(
slotRead(
int,
int,
int)));
125 if (m_prevDownloadedSizes.size()) {
126 speed = (m_downloadedSize - m_prevDownloadedSizes.first()) / (
SPEEDTIMER *
127 m_prevDownloadedSizes.size() / 1000);
132 m_prevDownloadedSizes.append(m_downloadedSize);
133 if(m_prevDownloadedSizes.size() > 10)
134 m_prevDownloadedSizes.removeFirst();
147 foreach (
MmsThread* thread, m_threadList) {
155 return m_threadList.size();
162 m_threadList.removeAll(thread);
163 thread->deleteLater();
165 if (m_threadList.isEmpty()) {
176 if (thread_in == thread_end) {
177 m_mapEndIni.remove(thread_end);
179 m_mapEndIni[thread_end] = thread_in;
181 m_downloadedSize += reading;
194 m_connectionsSuccefully++;
196 m_connectionsFails++;
198 if ((m_connectionsFails != 0) &&
199 (m_connectionsFails + m_connectionsSuccefully == m_amountThreads)) {
204 void MmsDownload::serialization()
209 QFile file(m_fileTemp);
210 file.open(QIODevice::WriteOnly);
211 QDataStream out(&file);
212 out << m_mapEndIni << m_downloadedSize << m_prevDownloadedSizes;
216 void MmsDownload::unSerialization()
220 QFile file(m_fileTemp);
221 file.open(QIODevice::ReadOnly);
222 QDataStream in(&file);
223 in >> m_mapEndIni >> m_downloadedSize >> m_prevDownloadedSizes;
void slotRead(int reading, int thread_end, int thead_ini)
qulonglong signDownloaded(qulonglong reading)
void signRestartDownload(int connections)
unsigned long signSpeed(unsigned long bytes_per_second)
MmsDownload(const QString &url, const QString &name, const QString &temp, int amountsThread)
void slotIsThreadConnected(bool connected)
qulonglong signTotalSize(qulonglong size)
void signNotAllowMultiDownload()