void Aggregate::merger() {

    // Just sleep for a while
    // Only for syncronization in main loop
    boost::this_thread::sleep(boost::posix_time::millisec(500));

    // If total size downloaded isn't equal
    // to the size of file downloaded then
    // do not merge the Chunks
    if( m_filesize != bytesTotal())
        Throw(ex::Error,"Downloaded bytes greater than total filesize.");

    fancyprint("Merging!",NOTIFY);
    fancyprint("Do not close this window.",WARNING);
    File tmp(tempName());
    tmp.write(Node::FORCE);
    // TODO try binary appends and storing to "tmp"
    // Append the content to "tmp"
    for(unsigned i=0; i < m_chunk.size(); i++){
        print(i+1 << " of " << m_chunk.size());
        tmp.append(*(m_chunk[i]->file()));
        std::cout << DELETE;
    }
    std::cout << DELETE;
    tmp.move(prettyName(),Node::NEW);
    // Remove the old directory
    Directory(m_hashedUrl).remove(Node::FORCE);

    fancyprint("Complete!",SUCCESS);
}
Exemple #2
0
double DownloadItem::remainingTime() const
{
    if (!downloading())
        return -1.0;

    double timeRemaining = ((double)(bytesTotal() - bytesReceived())) / currentSpeed();

    // When downloading the eta should never be 0
    if (timeRemaining == 0)
        timeRemaining = 1;

    return timeRemaining;
}
Exemple #3
0
double DownloadItem::remainingTime() const {
    if (m_finishedDownloading)
        return -1.0;

    double speed = currentSpeed();
    double timeRemaining = 0.0;
    if (speed > 0.0)
        timeRemaining = ((double)(bytesTotal() - bytesReceived())) / speed;

    // When downloading the eta should never be 0
    if (timeRemaining == 0)
        timeRemaining = 1;

    return timeRemaining;
}
void WindowsPlatformIntegration::updateTaskbarButtons()
{
	const QList<Transfer*> transfers(TransfersManager::getInstance()->getTransfers());
	qint64 bytesTotal(0);
	qint64 bytesReceived(0);
	bool hasActiveTransfers(false);

	for (int i = 0; i < transfers.count(); ++i)
	{
		if (transfers[i]->getState() == Transfer::RunningState && transfers[i]->getBytesTotal() > 0)
		{
			hasActiveTransfers = true;
			bytesTotal += transfers[i]->getBytesTotal();
			bytesReceived += transfers[i]->getBytesReceived();
		}
	}

	const QList<MainWindow*> windows(Application::getInstance()->getWindows());

	for (int i = 0; i < windows.count(); ++i)
	{
		MainWindow *window(windows.at(i));

		if (hasActiveTransfers)
		{
			if (!m_taskbarButtons.contains(window))
			{
				m_taskbarButtons[window] = new QWinTaskbarButton(window);
				m_taskbarButtons[window]->setWindow(window->windowHandle());
				m_taskbarButtons[window]->progress()->show();
			}

			m_taskbarButtons[window]->progress()->setValue((bytesReceived > 0) ? qFloor((static_cast<qreal>(bytesReceived) / bytesTotal) * 100) : 0);
		}
		else if (m_taskbarButtons.contains(window))
		{
			m_taskbarButtons[window]->progress()->reset();
			m_taskbarButtons[window]->progress()->hide();
			m_taskbarButtons[window]->deleteLater();
			m_taskbarButtons.remove(window);
		}
	}
}
// total-done
uintmax_t BasicTransaction::bytesRemaining() const {
    return bytesTotal()-m_bytesDone;
    //return m_bytesTotal-m_bytesDone;
}