Beispiel #1
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;
}
Beispiel #2
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);
		}
	}
}