Exemple #1
0
void TorrentGroup::policyChanged()
{
    if (policy.only_apply_on_new_torrents)
        return;

    std::set<TorrentInterface*>::iterator i = torrents.begin();
    while (i != torrents.end())
    {
        TorrentInterface* tor = *i;
        tor->setMaxShareRatio(policy.max_share_ratio);
        tor->setMaxSeedTime(policy.max_seed_time);
        tor->setTrafficLimits(policy.max_upload_rate * 1024, policy.max_download_rate * 1024);
        i++;
    }
}
Exemple #2
0
void TorrentGroup::save(bt::BEncoder* enc)
{
    enc->beginDict();
    enc->write(QString("name"));
    enc->write(name.toLocal8Bit());
    enc->write(QString("icon"));
    enc->write(icon_name.toLocal8Bit());
    enc->write(QString("hashes"));
    enc->beginList();
    std::set<TorrentInterface*>::iterator i = torrents.begin();
    while (i != torrents.end())
    {
        TorrentInterface* tc = *i;
        // write the info hash, because that will be unique for each torrent
        const bt::SHA1Hash& h = tc->getInfoHash();
        enc->write(h.getData(), 20);
        i++;
    }
    std::set<bt::SHA1Hash>::iterator j = hashes.begin();
    while (j != hashes.end())
    {
        enc->write(j->getData(), 20);
        j++;
    }
    enc->end();
    enc->write(QString("policy"));
    enc->beginDict();
    enc->write(QString("default_save_location"));
    enc->write(policy.default_save_location);
    enc->write(QString("max_share_ratio"));
    enc->write(QString::number(policy.max_share_ratio));
    enc->write(QString("max_seed_time"));
    enc->write(QString::number(policy.max_seed_time));
    enc->write(QString("max_upload_rate"));
    enc->write(policy.max_upload_rate);
    enc->write(QString("max_download_rate"));
    enc->write(policy.max_download_rate);
    enc->write(QString("only_apply_on_new_torrents"));
    enc->write((bt::Uint32)(policy.only_apply_on_new_torrents ? 1 : 0));
    enc->write(QString("default_move_on_completion_location"));
    enc->write(policy.default_move_on_completion_location);
    enc->end();
    enc->end();
}
Exemple #3
0
QueueDialog::QueueDialog(bt::QueueManager* qm, QWidget *parent, const char *name)
	:QueueDlg(parent, name)
{
	KIconLoader* iload = KGlobal::iconLoader();
	
	m_tabs->setTabIconSet(m_tabs->page(0), iload->loadIconSet("down", KIcon::Small));
	m_tabs->setTabIconSet(m_tabs->page(1), iload->loadIconSet("up", KIcon::Small));
	
 	logo->setPixmap(iload->loadIcon("ktqueuemanager", KIcon::Desktop));
	
	connect(downloadList, SIGNAL(selectionChanged(QListViewItem*)), this, SLOT(downloadList_currentChanged( QListViewItem* )));
	connect(seedList, SIGNAL(selectionChanged(QListViewItem*)), this, SLOT(seedList_currentChanged( QListViewItem* )));
	
	if(downloadList->firstChild())
		downloadList->setCurrentItem(downloadList->firstChild());
	
	if(seedList->firstChild())
		seedList->setCurrentItem(seedList->firstChild());
	
	btnMoveUp->setPixmap(iload->loadIcon("up", KIcon::Small));
	btnMoveDown->setPixmap(iload->loadIcon("down", KIcon::Small));
	
	this->qman = qm;

	QPtrList<kt::TorrentInterface>::iterator it = qman->begin();
	for( ; it != qman->end(); ++it)
	{
		TorrentInterface* tc = *it;
		TorrentStatus ts = tc->getStats().status;
		
		if(ts == kt::SEEDING || ts == kt::DOWNLOAD_COMPLETE || 
			ts == kt::SEEDING_COMPLETE || tc->getStats().completed)
		{
			QueueItem* item = new QueueItem(tc, seedList);
			seedList->insertItem(item);
		}
		else
		{
			QueueItem* item = new QueueItem(tc, downloadList);
			downloadList->insertItem(item);
		}
	}
}
Exemple #4
0
int KTorrentViewItem::compare(QListViewItem * i,int col,bool) const
{
	KTorrentViewItem* other = (KTorrentViewItem*)i;
	TorrentInterface* otc = other->tc;
	const TorrentStats & s = tc->getStats();
	const TorrentStats & os = otc->getStats();
	switch (col)
	{
		case 0: return QString::compare(s.torrent_name,os.torrent_name);
		case 1: return QString::compare(tc->statusToString(),otc->statusToString());
		case 2: return CompareVal(s.bytes_downloaded,os.bytes_downloaded);
		case 3: return CompareVal(s.total_bytes_to_download,os.total_bytes_to_download);
		case 4: return CompareVal(s.bytes_uploaded,os.bytes_uploaded);
		case 5: return CompareVal(s.download_rate,os.download_rate);
		case 6: return CompareVal(s.upload_rate,os.upload_rate);
		case 7: 
			if (eta == other->eta)
				return 0;
			else if (eta >= 0 && other->eta >= 0)
				return CompareVal(eta,other->eta);
			else if (eta == -1) // finsihed is minux one
				return -1;
			else if (other->eta == -1)
				return 1;
			else if (eta == -2) // infinity is minus 2
				return 1;
			else if (other->eta == -2)
				return -1;
			else
				return CompareVal(eta,other->eta);
		case 8: return CompareVal(s.seeders_total,os.seeders_total);
		case 9: return CompareVal(s.leechers_total,os.leechers_total);
		case 10:
		{
			double perc = s.total_bytes_to_download == 0 ? 100.0 : ((double)s.bytes_downloaded / s.total_bytes_to_download) * 100.0;
			if (perc > 100.0)
				perc = 100.0;
			double operc = os.total_bytes_to_download == 0 ? 100.0 : ((double)os.bytes_downloaded / os.total_bytes_to_download) * 100.0;
			if (operc > 100.0)
				operc = 100.0;
			return CompareVal(perc,operc);
		}
		case 11:
		{
			float r1 = kt::ShareRatio(s);
			float r2 = kt::ShareRatio(os);
			return CompareVal(r1,r2);
		}
		case 12:
			return CompareVal(tc->getRunningTimeDL(),otc->getRunningTimeDL());
		case 13:
		{
			Uint32 t = tc->getRunningTimeUL() - tc->getRunningTimeDL();
			Uint32 ot = otc->getRunningTimeUL() - otc->getRunningTimeDL();
			return CompareVal(t,ot);
		}
	}

	return 0;
}