本文整理汇总了C++中QTorrentHandle类的典型用法代码示例。如果您正苦于以下问题:C++ QTorrentHandle类的具体用法?C++ QTorrentHandle怎么用?C++ QTorrentHandle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTorrentHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleTorrentUpdate
void TorrentModel::handleTorrentUpdate(const QTorrentHandle &h)
{
const int row = torrentRow(h.hash());
if (row >= 0) {
// This line changes the torrent name when magnet is retrieved.
// When magnet link is added, "dn" parameter is used as name, but when metadata is retrieved
// we change the name with the retrieved torrent name.
m_torrents[row]->setData(TorrentModelItem::TR_NAME, h.name(), Qt::DisplayRole);
m_torrents[row]->refreshStatus(h.status(torrent_handle::query_accurate_download_counters));
notifyTorrentChanged(row);
}
}
示例2: CACHED_VARIABLE_FOR_HASH
/**
* Returns the files in a torrent in JSON format.
*
* The return value is a JSON-formatted list of dictionaries.
* The dictionary keys are:
* - "name": File name
* - "size": File size
* - "progress": File progress
* - "priority": File priority
* - "is_seed": Flag indicating if torrent is seeding/complete
*/
QByteArray btjson::getFilesForTorrent(const QString& hash)
{
CACHED_VARIABLE_FOR_HASH(QVariantList, file_list, CACHE_DURATION_MS, hash);
try {
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
if (!h.has_metadata())
return json::toJson(file_list);
const std::vector<int> priorities = h.file_priorities();
std::vector<size_type> fp;
h.file_progress(fp);
for (int i = 0; i < h.num_files(); ++i) {
QVariantMap file_dict;
QString fileName = h.filepath_at(i);
if (fileName.endsWith(".!qB", Qt::CaseInsensitive))
fileName.chop(4);
file_dict[KEY_FILE_NAME] = fsutils::toNativePath(fileName);
const size_type size = h.filesize_at(i);
file_dict[KEY_FILE_SIZE] = static_cast<qlonglong>(size);
file_dict[KEY_FILE_PROGRESS] = (size > 0) ? (fp[i] / (double) size) : 1.;
file_dict[KEY_FILE_PRIORITY] = priorities[i];
if (i == 0)
file_dict[KEY_FILE_IS_SEED] = h.is_seed();
file_list.append(file_dict);
}
}
catch (const std::exception& e) {
qWarning() << Q_FUNC_INFO << "Invalid torrent: " << misc::toQStringU(e.what());
return QByteArray();
}
return json::toJson(file_list);
}
示例3: CACHED_VARIABLE_FOR_HASH
/**
* Returns the files in a torrent in JSON format.
*
* The return value is a JSON-formatted list of dictionaries.
* The dictionary keys are:
* - "name": File name
* - "size": File size
* - "progress": File progress
* - "priority": File priority
* - "is_seed": Flag indicating if torrent is seeding/complete
*/
QString btjson::getFilesForTorrent(const QString& hash)
{
CACHED_VARIABLE_FOR_HASH(JsonList, file_list, CACHE_DURATION_MS, hash);
try {
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
if (!h.has_metadata())
return QString();
const std::vector<int> priorities = h.file_priorities();
std::vector<size_type> fp;
h.file_progress(fp);
for (int i = 0; i < h.num_files(); ++i) {
JsonDict file_dict;
QString fileName = h.filename_at(i);
if (fileName.endsWith(".!qB", Qt::CaseInsensitive))
fileName.chop(4);
file_dict.add(KEY_FILE_NAME, fileName);
const size_type size = h.filesize_at(i);
file_dict.add(KEY_FILE_SIZE, misc::friendlyUnit(size));
file_dict.add(KEY_FILE_PROGRESS, (size > 0) ? (fp[i] / (double) size) : 1.);
file_dict.add(KEY_FILE_PRIORITY, priorities[i]);
if (i == 0)
file_dict.add(KEY_FILE_IS_SEED, h.is_seed());
file_list.append(file_dict);
}
} catch (const std::exception& e) {
qWarning() << Q_FUNC_INFO << "Invalid torrent: " << e.what();
return QString();
}
return file_list.toString();
}
示例4: isTorrentResumed
bool QTorrentFilter::isTorrentResumed(const QTorrentHandle &h) const
{
const QTorrentState state = h.torrentState();
return state != QTorrentState::PausedUploading
&& state != QTorrentState::PausedDownloading;
}
示例5: moveSelectionUp
void TrackerList::moveSelectionUp() {
QTorrentHandle h = properties->getCurrentTorrent();
if (!h.is_valid()) {
clear();
return;
}
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
if (selected_items.isEmpty()) return;
bool change = false;
foreach (QTreeWidgetItem *item, selected_items) {
int index = indexOfTopLevelItem(item);
if (index > NB_STICKY_ITEM) {
insertTopLevelItem(index-1, takeTopLevelItem(index));
change = true;
}
}
示例6: handleTorrentAboutToBeRemoved
void TorrentModel::handleTorrentAboutToBeRemoved(const QTorrentHandle &h)
{
const int row = torrentRow(h.hash());
if (row >= 0) {
emit torrentAboutToBeRemoved(m_torrents.at(row));
}
}
示例7: torrentHasLabel
bool QTorrentFilter::torrentHasLabel(const QTorrentHandle &h) const
{
if (label_.isNull())
return true;
else
return TorrentPersistentData::instance()->getLabel(h.hash()) == label_;
}
示例8: isTorrentActive
bool QTorrentFilter::isTorrentActive(const QTorrentHandle &h) const
{
const QTorrentState state = h.torrentState();
return state == QTorrentState::Downloading
|| state == QTorrentState::Uploading;
}
示例9: handleTorrentUpdate
void TorrentModel::handleTorrentUpdate(const QTorrentHandle &h)
{
const int row = torrentRow(h.hash());
if (row >= 0) {
notifyTorrentChanged(row);
}
}
示例10: isTorrentPaused
bool QTorrentFilter::isTorrentPaused(const QTorrentHandle &h) const
{
const QTorrentState state = h.torrentState();
return state == QTorrentState::PausedUploading
|| state == QTorrentState::Error;
}
示例11: mapToSource
void TransferListWidget::torrentDoubleClicked(const QModelIndex& index) {
const int row = mapToSource(index).row();
const QString hash = getHashFromRow(row);
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if (!h.is_valid()) return;
int action;
if (h.is_seed()) {
action = Preferences().getActionOnDblClOnTorrentFn();
} else {
action = Preferences().getActionOnDblClOnTorrentDl();
}
switch(action) {
case TOGGLE_PAUSE:
if (h.is_paused()) {
h.resume();
} else {
h.pause();
}
break;
case OPEN_DEST:
const QString path = h.root_path();
openUrl(path);
}
}
示例12: isTorrentSeeding
bool QTorrentFilter::isTorrentSeeding(const QTorrentHandle &h) const
{
const QTorrentState state = h.torrentState();
return state == QTorrentState::Uploading
|| state == QTorrentState::StalledUploading
|| state == QTorrentState::CheckingUploading
|| state == QTorrentState::QueuedUploading;
}
示例13: handleFinishedTorrent
void TorrentModel::handleFinishedTorrent(const QTorrentHandle& h)
{
const int row = torrentRow(h.hash());
if (row < 0)
return;
// Update completion date
m_torrents[row]->setData(TorrentModelItem::TR_SEED_DATE, QDateTime::currentDateTime(), Qt::DisplayRole);
notifyTorrentChanged(row);
}
示例14: addTorrent
void TorrentModel::addTorrent(const QTorrentHandle &h)
{
if (torrentRow(h.hash()) < 0) {
beginInsertTorrent(m_torrents.size());
TorrentModelItem *item = new TorrentModelItem(h);
connect(item, SIGNAL(labelChanged(QString,QString)), SLOT(handleTorrentLabelChange(QString,QString)));
m_torrents << item;
emit torrentAdded(item);
endInsertTorrent();
}
}
示例15: isTorrentDownloading
bool QTorrentFilter::isTorrentDownloading(const QTorrentHandle &h) const
{
const QTorrentState state = h.torrentState();
return state == QTorrentState::Downloading
|| state == QTorrentState::StalledDownloading
|| state == QTorrentState::CheckingDownloading
|| state == QTorrentState::PausedDownloading
|| state == QTorrentState::QueuedDownloading
|| state == QTorrentState::Error;
}