void MeteorShowersMgr::setStatusOfLastUpdate(const int &downloadStatus)
{
	m_statusOfLastUpdate = (DownloadStatus) downloadStatus;
	if (m_statusOfLastUpdate != UPDATING)
	{
		m_conf->setValue(MS_CONFIG_PREFIX + "/last_update_status", downloadStatus);
	}
	emit(downloadStatusChanged(m_statusOfLastUpdate));
}
void DownloadManagerImpl::addUrl(const QString &url, int contactId)
{
    DownloadManager::UrlType urlType = (DownloadManager::UrlType)getUrlTypeByUrl(url);
    if (urlType == DownloadManager::UnknownType) {
        // Emits contact download error signal
        emit contactDownloadError(contactId, DownloadManager::UnknownUrlType);
        return;
    }

    if (isDownloadExistingInQueue(contactId))  {
        // Emits contact download error signal
        emit contactDownloadError(contactId, DownloadManager::DownloadInQueue);
        return;
    }

    if (isDownloadExistingInList(contactId))  {
        // Emits contact download error signal
        emit contactDownloadError(contactId, DownloadManager::FileDownloading);
        return;
    }

    // Create objects and add to the queue
    Contact *contact = new Contact();
    Q_ASSERT(contact != 0);
    contact->setId(contactId);

    DownloadManager::DownloadStatus downloadStatus = DownloadManager::Queueing;
    Download *download = new Download();
    Q_ASSERT(download != 0);
    download->setUrl(url);
    download->setDownloadStatus(downloadStatus);
    download->setUrlType(urlType);
    download->setContact(contact);

    m_mutexLocker.lock();
    // Add download to the queue
    m_downloadQueue.enqueue(download);
    m_mutexLocker.unlock();

    // Add params to the download table
    int downloadId = m_downloadDAO->addDownload(download);

    if (downloadId < 0) {
        emit contactDownloadError(contactId, DownloadManager::CanNotInsertDownloadToDB);
        return;
    }

    download->setId(downloadId);

    // Emit download status change signal
    emit downloadStatusChanged(contactId, downloadId, (int)downloadStatus);

    checkDownloadQueue();
}
void DownloadManagerImpl::checkDownloadQueue()
{
    m_mutexLocker.lock();
    int queueCount = m_downloadQueue.count();
    int downloadingCount = m_downloadingList.count();
    m_mutexLocker.unlock();

    while (downloadingCount < MAX_CONCURRENT_DOWNLOAD_THREADS) {
        if (queueCount == 0)
            return;

        m_mutexLocker.lock();
        Download *download = m_downloadQueue.dequeue();
        // Add the download to the downloading list
        m_downloadingList.append(download);

        // Recalculate params
        queueCount = m_downloadQueue.count();
        downloadingCount = m_downloadingList.count();

        m_mutexLocker.unlock();

        DownloadManager::DownloadStatus downloadStatus = DownloadManager::Downloading;

        // Update status
        download->setDownloadStatus(downloadStatus);
        m_downloadDAO->updateDownload(download);

        // Connect signals
        connectDownloadSignals(download);

        // Start the download
        download->start();

        // Emit download status change signal
        emit downloadStatusChanged(download->getContact()->getId(), download->getId(), (int)downloadStatus);
    }
}
Exemple #4
0
	void ChunkManager::downloadPriorityChanged(TorrentFile* tf,Priority newpriority,Priority oldpriority)
	{
		if (newpriority == EXCLUDED)
		{
			downloadStatusChanged(tf, false);
			return;
		}
		if (oldpriority == EXCLUDED)
		{
			downloadStatusChanged(tf, true);
			return;
		}

		savePriorityInfo();
		
		Uint32 first = tf->getFirstChunk();
		Uint32 last = tf->getLastChunk();
		
		// first and last chunk may be part of multiple files
		// so we can't just exclude them
		QValueList<Uint32> files;

		// get list of files where first chunk lies in
		tor.calcChunkPos(first,files);
		
		Chunk* c = chunks[first];
		// if one file in the list needs to be downloaded,increment first
		for (QValueList<Uint32>::iterator i = files.begin();i != files.end();i++)
		{
			Priority np = tor.getFile(*i).getPriority();
			if (np > newpriority && *i != tf->getIndex())
			{
				// make sure we don't go past last
				if (first == last)
					return;
					
				first++;
				break;
			}
		}
		
		files.clear();
		// get list of files where last chunk lies in
		tor.calcChunkPos(last,files);
		c = chunks[last];
		// if one file in the list needs to be downloaded,decrement last
		for (QValueList<Uint32>::iterator i = files.begin();i != files.end();i++)
		{
			Priority np = tor.getFile(*i).getPriority();
			if (np > newpriority && *i != tf->getIndex())
			{
				// make sure we don't wrap around
				if (last == 0 || last == first)
					return;
					
				last--;
				break;
			}
		}
		
		// last smaller then first is not normal, so just return
		if (last < first)
		{
			return;
		}
		

		prioritise(first,last,newpriority);
		if (newpriority == ONLY_SEED_PRIORITY)
			excluded(first,last);
	}