|
|
@ -51,13 +51,21 @@ |
|
|
|
#include "downloadthread.h" |
|
|
|
#include "downloadthread.h" |
|
|
|
#include "logger.h" |
|
|
|
#include "logger.h" |
|
|
|
|
|
|
|
|
|
|
|
FiltersBase::FiltersBase(QWidget *parent) |
|
|
|
FiltersBase::FiltersBase(QWidget *parent, TransferListWidget *transferList) |
|
|
|
: QListWidget(parent) |
|
|
|
: QListWidget(parent) |
|
|
|
|
|
|
|
, transferList(transferList) |
|
|
|
{ |
|
|
|
{ |
|
|
|
setStyleSheet("QListWidget { background: transparent; border: 0 }"); |
|
|
|
setStyleSheet("QListWidget { background: transparent; border: 0 }"); |
|
|
|
#if defined(Q_OS_MAC) |
|
|
|
#if defined(Q_OS_MAC) |
|
|
|
setAttribute(Qt::WA_MacShowFocusRect, false); |
|
|
|
setAttribute(Qt::WA_MacShowFocusRect, false); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
|
|
|
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showMenu(QPoint))); |
|
|
|
|
|
|
|
connect(this, SIGNAL(currentRowChanged(int)), SLOT(applyFilter(int))); |
|
|
|
|
|
|
|
connect(transferList->getSourceModel(), SIGNAL(torrentAdded(TorrentModelItem*)), SLOT(handleNewTorrent(TorrentModelItem*))); |
|
|
|
|
|
|
|
connect(transferList->getSourceModel(), SIGNAL(torrentAboutToBeRemoved(TorrentModelItem*)), SLOT(torrentAboutToBeDeleted(TorrentModelItem*))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QSize FiltersBase::sizeHint() const |
|
|
|
QSize FiltersBase::sizeHint() const |
|
|
@ -76,26 +84,298 @@ QSize FiltersBase::minimumSizeHint() const |
|
|
|
return size; |
|
|
|
return size; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LabelFiltersList::LabelFiltersList(QWidget *parent) |
|
|
|
StatusFiltersWidget::StatusFiltersWidget(QWidget *parent, TransferListWidget *transferList) |
|
|
|
: FiltersBase(parent) |
|
|
|
: FiltersBase(parent, transferList) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
setUniformItemSizes(true); |
|
|
|
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
|
|
|
|
|
|
// Height is fixed (sizeHint().height() is used)
|
|
|
|
|
|
|
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); |
|
|
|
|
|
|
|
setSpacing(0); |
|
|
|
|
|
|
|
connect(transferList->getSourceModel(), SIGNAL(modelRefreshed()), SLOT(updateTorrentNumbers())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add status filters
|
|
|
|
|
|
|
|
QListWidgetItem *all = new QListWidgetItem(this); |
|
|
|
|
|
|
|
all->setData(Qt::DisplayRole, QVariant(tr("All") + " (0)")); |
|
|
|
|
|
|
|
all->setData(Qt::DecorationRole, QIcon(":/icons/skin/filterall.png")); |
|
|
|
|
|
|
|
QListWidgetItem *downloading = new QListWidgetItem(this); |
|
|
|
|
|
|
|
downloading->setData(Qt::DisplayRole, QVariant(tr("Downloading") + " (0)")); |
|
|
|
|
|
|
|
downloading->setData(Qt::DecorationRole, QIcon(":/icons/skin/downloading.png")); |
|
|
|
|
|
|
|
QListWidgetItem *completed = new QListWidgetItem(this); |
|
|
|
|
|
|
|
completed->setData(Qt::DisplayRole, QVariant(tr("Completed") + " (0)")); |
|
|
|
|
|
|
|
completed->setData(Qt::DecorationRole, QIcon(":/icons/skin/uploading.png")); |
|
|
|
|
|
|
|
QListWidgetItem *resumed = new QListWidgetItem(this); |
|
|
|
|
|
|
|
resumed->setData(Qt::DisplayRole, QVariant(tr("Resumed") + " (0)")); |
|
|
|
|
|
|
|
resumed->setData(Qt::DecorationRole, QIcon(":/icons/skin/resumed.png")); |
|
|
|
|
|
|
|
QListWidgetItem *paused = new QListWidgetItem(this); |
|
|
|
|
|
|
|
paused->setData(Qt::DisplayRole, QVariant(tr("Paused") + " (0)")); |
|
|
|
|
|
|
|
paused->setData(Qt::DecorationRole, QIcon(":/icons/skin/paused.png")); |
|
|
|
|
|
|
|
QListWidgetItem *active = new QListWidgetItem(this); |
|
|
|
|
|
|
|
active->setData(Qt::DisplayRole, QVariant(tr("Active") + " (0)")); |
|
|
|
|
|
|
|
active->setData(Qt::DecorationRole, QIcon(":/icons/skin/filteractive.png")); |
|
|
|
|
|
|
|
QListWidgetItem *inactive = new QListWidgetItem(this); |
|
|
|
|
|
|
|
inactive->setData(Qt::DisplayRole, QVariant(tr("Inactive") + " (0)")); |
|
|
|
|
|
|
|
inactive->setData(Qt::DecorationRole, QIcon(":/icons/skin/filterinactive.png")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setCurrentRow(Preferences::instance()->getTransSelFilter(), QItemSelectionModel::SelectCurrent); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StatusFiltersWidget::~StatusFiltersWidget() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Preferences::instance()->setTransSelFilter(currentRow()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void StatusFiltersWidget::updateTorrentNumbers() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const TorrentStatusReport report = transferList->getSourceModel()->getTorrentStatusReport(); |
|
|
|
|
|
|
|
item(TorrentFilter::ALL)->setData(Qt::DisplayRole, QVariant(tr("All (%1)").arg(report.nb_active + report.nb_inactive))); |
|
|
|
|
|
|
|
item(TorrentFilter::DOWNLOADING)->setData(Qt::DisplayRole, QVariant(tr("Downloading (%1)").arg(report.nb_downloading))); |
|
|
|
|
|
|
|
item(TorrentFilter::COMPLETED)->setData(Qt::DisplayRole, QVariant(tr("Completed (%1)").arg(report.nb_seeding))); |
|
|
|
|
|
|
|
item(TorrentFilter::PAUSED)->setData(Qt::DisplayRole, QVariant(tr("Paused (%1)").arg(report.nb_paused))); |
|
|
|
|
|
|
|
item(TorrentFilter::RESUMED)->setData(Qt::DisplayRole, QVariant(tr("Resumed (%1)").arg(report.nb_active + report.nb_inactive - report.nb_paused))); |
|
|
|
|
|
|
|
item(TorrentFilter::ACTIVE)->setData(Qt::DisplayRole, QVariant(tr("Active (%1)").arg(report.nb_active))); |
|
|
|
|
|
|
|
item(TorrentFilter::INACTIVE)->setData(Qt::DisplayRole, QVariant(tr("Inactive (%1)").arg(report.nb_inactive))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void StatusFiltersWidget::showMenu(QPoint) {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void StatusFiltersWidget::applyFilter(int row) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
transferList->applyStatusFilter(row); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void StatusFiltersWidget::handleNewTorrent(TorrentModelItem*) {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void StatusFiltersWidget::torrentAboutToBeDeleted(TorrentModelItem*) {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LabelFiltersList::LabelFiltersList(QWidget *parent, TransferListWidget *transferList) |
|
|
|
|
|
|
|
: FiltersBase(parent, transferList) |
|
|
|
|
|
|
|
, m_totalTorrents(0) |
|
|
|
|
|
|
|
, m_totalLabeled(0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); |
|
|
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); |
|
|
|
|
|
|
|
connect(transferList->getSourceModel(), SIGNAL(torrentChangedLabel(TorrentModelItem*,QString,QString)), SLOT(torrentChangedLabel(TorrentModelItem*, QString, QString))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add Label filters
|
|
|
|
|
|
|
|
QListWidgetItem *allLabels = new QListWidgetItem(this); |
|
|
|
|
|
|
|
allLabels->setData(Qt::DisplayRole, QVariant(tr("All (0)", "this is for the label filter"))); |
|
|
|
|
|
|
|
allLabels->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("inode-directory")); |
|
|
|
|
|
|
|
QListWidgetItem *noLabel = new QListWidgetItem(this); |
|
|
|
|
|
|
|
noLabel->setData(Qt::DisplayRole, QVariant(tr("Unlabeled (0)"))); |
|
|
|
|
|
|
|
noLabel->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("inode-directory")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QStringList labelList = Preferences::instance()->getTorrentLabels(); |
|
|
|
|
|
|
|
for (int i=0; i < labelList.size(); ++i) |
|
|
|
|
|
|
|
addItem(labelList[i], false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setCurrentRow(0, QItemSelectionModel::SelectCurrent); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LabelFiltersList::~LabelFiltersList() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Preferences::instance()->setTorrentLabels(m_labels.keys()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void LabelFiltersList::addItem(QListWidgetItem *it) |
|
|
|
void LabelFiltersList::addItem(QString &label, bool hasTorrent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
int labelCount = 0; |
|
|
|
|
|
|
|
QListWidgetItem *labelItem = 0; |
|
|
|
|
|
|
|
label = fsutils::toValidFileSystemName(label.trimmed()); |
|
|
|
|
|
|
|
item(0)->setText(tr("All (%1)", "this is for the label filter").arg(m_totalTorrents)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (label.isEmpty()) { |
|
|
|
|
|
|
|
item(1)->setText(tr("Unlabeled (%1)").arg(m_totalTorrents - m_totalLabeled)); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool exists = m_labels.contains(label); |
|
|
|
|
|
|
|
if (exists) { |
|
|
|
|
|
|
|
labelCount = m_labels.value(label); |
|
|
|
|
|
|
|
labelItem = item(rowFromLabel(label)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
labelItem = new QListWidgetItem(); |
|
|
|
|
|
|
|
labelItem->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("inode-directory")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hasTorrent) { |
|
|
|
|
|
|
|
++m_totalLabeled; |
|
|
|
|
|
|
|
++labelCount; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
item(1)->setText(tr("Unlabeled (%1)").arg(m_totalTorrents - m_totalLabeled)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Preferences::instance()->addTorrentLabel(label); |
|
|
|
|
|
|
|
m_labels.insert(label, labelCount); |
|
|
|
|
|
|
|
labelItem->setText(tr("%1 (%2)", "label_name (10)").arg(label).arg(labelCount)); |
|
|
|
|
|
|
|
if (exists) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
Q_ASSERT(count() >= 2); |
|
|
|
Q_ASSERT(count() >= 2); |
|
|
|
for (int i = 2; i<count(); ++i) { |
|
|
|
for (int i = 2; i<count(); ++i) { |
|
|
|
if (item(i)->text().localeAwareCompare(it->text()) >= 0) { |
|
|
|
bool less = false; |
|
|
|
insertItem(i, it); |
|
|
|
if (!(misc::naturalSort(label, item(i)->text(), less))) |
|
|
|
|
|
|
|
less = (label.localeAwareCompare(item(i)->text()) < 0); |
|
|
|
|
|
|
|
if (less) { |
|
|
|
|
|
|
|
insertItem(i, labelItem); |
|
|
|
updateGeometry(); |
|
|
|
updateGeometry(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
QListWidget::addItem(it); |
|
|
|
QListWidget::addItem(labelItem); |
|
|
|
|
|
|
|
updateGeometry(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LabelFiltersList::removeItem(const QString &label) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
item(0)->setText(tr("All (%1)", "this is for the label filter").arg(m_totalTorrents)); |
|
|
|
|
|
|
|
if (label.isEmpty()) { |
|
|
|
|
|
|
|
// In case we here from torrentAboutToBeDeleted()
|
|
|
|
|
|
|
|
item(1)->setText(tr("Unlabeled (%1)").arg(m_totalTorrents - m_totalLabeled)); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--m_totalLabeled; |
|
|
|
|
|
|
|
item(1)->setText(tr("Unlabeled (%1)").arg(m_totalTorrents - m_totalLabeled)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int labelCount = m_labels.value(label) - 1; |
|
|
|
|
|
|
|
int row = rowFromLabel(label); |
|
|
|
|
|
|
|
if (row < 2) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QListWidgetItem *labelItem = item(row); |
|
|
|
|
|
|
|
labelItem->setText(tr("%1 (%2)", "label_name (10)").arg(label).arg(labelCount)); |
|
|
|
|
|
|
|
m_labels.insert(label, labelCount); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LabelFiltersList::removeSelectedLabel() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const int labelRow = row(selectedItems().first()); |
|
|
|
|
|
|
|
if (labelRow < 2) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
const QString &label = labelFromRow(labelRow); |
|
|
|
|
|
|
|
Q_ASSERT(m_labels.contains(label)); |
|
|
|
|
|
|
|
m_labels.remove(label); |
|
|
|
|
|
|
|
// Select first label
|
|
|
|
|
|
|
|
setCurrentRow(0, QItemSelectionModel::SelectCurrent); |
|
|
|
|
|
|
|
applyFilter(0); |
|
|
|
|
|
|
|
// Un display filter
|
|
|
|
|
|
|
|
delete takeItem(labelRow); |
|
|
|
|
|
|
|
transferList->removeLabelFromRows(label); |
|
|
|
|
|
|
|
// Save custom labels to remember it was deleted
|
|
|
|
|
|
|
|
Preferences::instance()->removeTorrentLabel(label); |
|
|
|
updateGeometry(); |
|
|
|
updateGeometry(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LabelFiltersList::removeUnusedLabels() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QStringList unusedLabels; |
|
|
|
|
|
|
|
QHash<QString, int>::const_iterator i; |
|
|
|
|
|
|
|
for (i = m_labels.begin(); i != m_labels.end(); ++i) { |
|
|
|
|
|
|
|
if (i.value() == 0) |
|
|
|
|
|
|
|
unusedLabels << i.key(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
foreach (const QString &label, unusedLabels) { |
|
|
|
|
|
|
|
m_labels.remove(label); |
|
|
|
|
|
|
|
delete takeItem(rowFromLabel(label)); |
|
|
|
|
|
|
|
Preferences::instance()->removeTorrentLabel(label); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!unusedLabels.isEmpty()) |
|
|
|
|
|
|
|
updateGeometry(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LabelFiltersList::torrentChangedLabel(TorrentModelItem *torrentItem, QString old_label, QString new_label) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Q_UNUSED(torrentItem); |
|
|
|
|
|
|
|
qDebug("Torrent label changed from %s to %s", qPrintable(old_label), qPrintable(new_label)); |
|
|
|
|
|
|
|
removeItem(old_label); |
|
|
|
|
|
|
|
addItem(new_label, true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LabelFiltersList::showMenu(QPoint) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QMenu menu(this); |
|
|
|
|
|
|
|
QAction *addAct = menu.addAction(IconProvider::instance()->getIcon("list-add"), tr("Add label...")); |
|
|
|
|
|
|
|
QAction *removeAct = 0; |
|
|
|
|
|
|
|
QAction *removeUnusedAct = 0; |
|
|
|
|
|
|
|
if (!selectedItems().empty() && row(selectedItems().first()) > 1) |
|
|
|
|
|
|
|
removeAct = menu.addAction(IconProvider::instance()->getIcon("list-remove"), tr("Remove label")); |
|
|
|
|
|
|
|
removeUnusedAct = menu.addAction(IconProvider::instance()->getIcon("list-remove"), tr("Remove unused labels")); |
|
|
|
|
|
|
|
menu.addSeparator(); |
|
|
|
|
|
|
|
QAction *startAct = menu.addAction(IconProvider::instance()->getIcon("media-playback-start"), tr("Resume torrents")); |
|
|
|
|
|
|
|
QAction *pauseAct = menu.addAction(IconProvider::instance()->getIcon("media-playback-pause"), tr("Pause torrents")); |
|
|
|
|
|
|
|
QAction *deleteTorrentsAct = menu.addAction(IconProvider::instance()->getIcon("edit-delete"), tr("Delete torrents")); |
|
|
|
|
|
|
|
QAction *act = 0; |
|
|
|
|
|
|
|
act = menu.exec(QCursor::pos()); |
|
|
|
|
|
|
|
if (!act) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (act == removeAct) { |
|
|
|
|
|
|
|
removeSelectedLabel(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (act == removeUnusedAct) { |
|
|
|
|
|
|
|
removeUnusedLabels(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (act == deleteTorrentsAct) { |
|
|
|
|
|
|
|
transferList->deleteVisibleTorrents(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (act == startAct) { |
|
|
|
|
|
|
|
transferList->startVisibleTorrents(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (act == pauseAct) { |
|
|
|
|
|
|
|
transferList->pauseVisibleTorrents(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (act == addAct) { |
|
|
|
|
|
|
|
bool ok; |
|
|
|
|
|
|
|
QString label = ""; |
|
|
|
|
|
|
|
bool invalid; |
|
|
|
|
|
|
|
do { |
|
|
|
|
|
|
|
invalid = false; |
|
|
|
|
|
|
|
label = AutoExpandableDialog::getText(this, tr("New Label"), tr("Label:"), QLineEdit::Normal, label, &ok); |
|
|
|
|
|
|
|
if (ok && !label.isEmpty()) { |
|
|
|
|
|
|
|
if (fsutils::isValidFileSystemName(label)) { |
|
|
|
|
|
|
|
addItem(label, false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
QMessageBox::warning(this, tr("Invalid label name"), tr("Please don't use any special characters in the label name.")); |
|
|
|
|
|
|
|
invalid = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} while (invalid); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LabelFiltersList::applyFilter(int row) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
switch (row) { |
|
|
|
|
|
|
|
case 0: |
|
|
|
|
|
|
|
transferList->applyLabelFilterAll(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 1: |
|
|
|
|
|
|
|
transferList->applyLabelFilter(QString()); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
transferList->applyLabelFilter(labelFromRow(row)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LabelFiltersList::handleNewTorrent(TorrentModelItem* torrentItem) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
++m_totalTorrents; |
|
|
|
|
|
|
|
QString label = torrentItem->data(TorrentModelItem::TR_LABEL).toString(); |
|
|
|
|
|
|
|
addItem(label, true); |
|
|
|
|
|
|
|
// labelFilters->addItem() may have changed the label, update the model accordingly.
|
|
|
|
|
|
|
|
torrentItem->setData(TorrentModelItem::TR_LABEL, label); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LabelFiltersList::torrentAboutToBeDeleted(TorrentModelItem* torrentItem) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
--m_totalTorrents; |
|
|
|
|
|
|
|
Q_ASSERT(torrentItem); |
|
|
|
|
|
|
|
QString label = torrentItem->data(TorrentModelItem::TR_LABEL).toString(); |
|
|
|
|
|
|
|
removeItem(label); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QString LabelFiltersList::labelFromRow(int row) const |
|
|
|
QString LabelFiltersList::labelFromRow(int row) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
Q_ASSERT(row > 1); |
|
|
|
Q_ASSERT(row > 1); |
|
|
@ -106,7 +386,7 @@ QString LabelFiltersList::labelFromRow(int row) const |
|
|
|
return parts.join(" "); |
|
|
|
return parts.join(" "); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int LabelFiltersList::rowFromLabel(QString label) const |
|
|
|
int LabelFiltersList::rowFromLabel(const QString &label) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
Q_ASSERT(!label.isEmpty()); |
|
|
|
Q_ASSERT(!label.isEmpty()); |
|
|
|
for (int i = 2; i<count(); ++i) |
|
|
|
for (int i = 2; i<count(); ++i) |
|
|
@ -114,27 +394,22 @@ int LabelFiltersList::rowFromLabel(QString label) const |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
StatusFiltersWidget::StatusFiltersWidget(QWidget *parent) |
|
|
|
TrackerFiltersList::TrackerFiltersList(QWidget *parent, TransferListWidget *transferList) |
|
|
|
: FiltersBase(parent) |
|
|
|
: FiltersBase(parent, transferList) |
|
|
|
{ |
|
|
|
|
|
|
|
setUniformItemSizes(true); |
|
|
|
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
|
|
|
|
|
|
// Height is fixed (sizeHint().height() is used)
|
|
|
|
|
|
|
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TrackerFiltersList::TrackerFiltersList(QWidget *parent) |
|
|
|
|
|
|
|
: FiltersBase(parent) |
|
|
|
|
|
|
|
, m_downloader(new DownloadThread(this)) |
|
|
|
, m_downloader(new DownloadThread(this)) |
|
|
|
|
|
|
|
, m_totalTorrents(0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
|
|
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
|
|
|
|
|
|
|
|
|
|
|
QListWidgetItem *allTrackers = new QListWidgetItem(this); |
|
|
|
QListWidgetItem *allTrackers = new QListWidgetItem(this); |
|
|
|
allTrackers->setData(Qt::DisplayRole, QVariant(tr("All trackers (0)"))); |
|
|
|
allTrackers->setData(Qt::DisplayRole, QVariant(tr("All (0)", "this is for the label filter"))); |
|
|
|
allTrackers->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("network-server")); |
|
|
|
allTrackers->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("network-server")); |
|
|
|
QListWidgetItem *noTracker = new QListWidgetItem(this); |
|
|
|
QListWidgetItem *noTracker = new QListWidgetItem(this); |
|
|
|
noTracker->setData(Qt::DisplayRole, QVariant(tr("Trackerless (0)"))); |
|
|
|
noTracker->setData(Qt::DisplayRole, QVariant(tr("Trackerless (0)"))); |
|
|
|
noTracker->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("network-server")); |
|
|
|
noTracker->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("network-server")); |
|
|
|
m_trackers.insert("", QStringList()); |
|
|
|
m_trackers.insert("", QStringList()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setCurrentRow(0, QItemSelectionModel::SelectCurrent); |
|
|
|
connect(m_downloader, SIGNAL(downloadFinished(QString, QString)), SLOT(handleFavicoDownload(QString, QString))); |
|
|
|
connect(m_downloader, SIGNAL(downloadFinished(QString, QString)), SLOT(handleFavicoDownload(QString, QString))); |
|
|
|
connect(m_downloader, SIGNAL(downloadFailure(QString, QString)), SLOT(handleFavicoFailure(QString, QString))); |
|
|
|
connect(m_downloader, SIGNAL(downloadFailure(QString, QString)), SLOT(handleFavicoFailure(QString, QString))); |
|
|
|
} |
|
|
|
} |
|
|
@ -151,8 +426,9 @@ void TrackerFiltersList::addItem(const QString &tracker, const QString &hash) |
|
|
|
QStringList tmp; |
|
|
|
QStringList tmp; |
|
|
|
QListWidgetItem *trackerItem = 0; |
|
|
|
QListWidgetItem *trackerItem = 0; |
|
|
|
QString host = getHost(tracker); |
|
|
|
QString host = getHost(tracker); |
|
|
|
|
|
|
|
bool exists = m_trackers.contains(host); |
|
|
|
|
|
|
|
|
|
|
|
if (m_trackers.contains(host)) { |
|
|
|
if (exists) { |
|
|
|
tmp = m_trackers.value(host); |
|
|
|
tmp = m_trackers.value(host); |
|
|
|
if (tmp.contains(hash)) |
|
|
|
if (tmp.contains(hash)) |
|
|
|
return; |
|
|
|
return; |
|
|
@ -178,6 +454,11 @@ void TrackerFiltersList::addItem(const QString &tracker, const QString &hash) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
trackerItem->setText(tr("%1 (%2)", "openbittorrent.com (10)").arg(host).arg(tmp.size())); |
|
|
|
trackerItem->setText(tr("%1 (%2)", "openbittorrent.com (10)").arg(host).arg(tmp.size())); |
|
|
|
|
|
|
|
if (exists) { |
|
|
|
|
|
|
|
if (currentRow() == rowFromTracker(host)) |
|
|
|
|
|
|
|
emit currentRowChanged(currentRow()); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Q_ASSERT(count() >= 2); |
|
|
|
Q_ASSERT(count() >= 2); |
|
|
|
for (int i = 2; i<count(); ++i) { |
|
|
|
for (int i = 2; i<count(); ++i) { |
|
|
@ -186,24 +467,12 @@ void TrackerFiltersList::addItem(const QString &tracker, const QString &hash) |
|
|
|
less = (host.localeAwareCompare(item(i)->text()) < 0); |
|
|
|
less = (host.localeAwareCompare(item(i)->text()) < 0); |
|
|
|
if (less) { |
|
|
|
if (less) { |
|
|
|
insertItem(i, trackerItem); |
|
|
|
insertItem(i, trackerItem); |
|
|
|
if (currentRow() == i) |
|
|
|
updateGeometry(); |
|
|
|
emit currentRowChanged(i); |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
QListWidget::addItem(trackerItem); |
|
|
|
QListWidget::addItem(trackerItem); |
|
|
|
} |
|
|
|
updateGeometry(); |
|
|
|
|
|
|
|
|
|
|
|
void TrackerFiltersList::addItem(const QTorrentHandle& handle) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QString hash = handle.hash(); |
|
|
|
|
|
|
|
std::vector<libtorrent::announce_entry> trackers = handle.trackers(); |
|
|
|
|
|
|
|
for (std::vector<libtorrent::announce_entry>::iterator i = trackers.begin(), e = trackers.end(); i != e; ++i) |
|
|
|
|
|
|
|
addItem(misc::toQStringU(i->url), hash); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Check for trackerless torrent
|
|
|
|
|
|
|
|
if (trackers.size() == 0) |
|
|
|
|
|
|
|
addItem("", hash); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TrackerFiltersList::removeItem(const QString &tracker, const QString &hash) |
|
|
|
void TrackerFiltersList::removeItem(const QString &tracker, const QString &hash) |
|
|
@ -222,9 +491,10 @@ void TrackerFiltersList::removeItem(const QString &tracker, const QString &hash) |
|
|
|
trackerItem = item(row); |
|
|
|
trackerItem = item(row); |
|
|
|
if (tmp.empty()) { |
|
|
|
if (tmp.empty()) { |
|
|
|
if (currentRow() == row) |
|
|
|
if (currentRow() == row) |
|
|
|
setCurrentRow(0); |
|
|
|
setCurrentRow(0, QItemSelectionModel::SelectCurrent); |
|
|
|
delete trackerItem; |
|
|
|
delete trackerItem; |
|
|
|
m_trackers.remove(host); |
|
|
|
m_trackers.remove(host); |
|
|
|
|
|
|
|
updateGeometry(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
trackerItem->setText(tr("%1 (%2)", "openbittorrent.com (10)").arg(host).arg(tmp.size())); |
|
|
|
trackerItem->setText(tr("%1 (%2)", "openbittorrent.com (10)").arg(host).arg(tmp.size())); |
|
|
@ -240,29 +510,12 @@ void TrackerFiltersList::removeItem(const QString &tracker, const QString &hash) |
|
|
|
emit currentRowChanged(row); |
|
|
|
emit currentRowChanged(row); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TrackerFiltersList::removeItem(const QTorrentHandle& handle) |
|
|
|
void TrackerFiltersList::changeTrackerless(bool trackerless, const QString &hash) |
|
|
|
{ |
|
|
|
|
|
|
|
QString hash = handle.hash(); |
|
|
|
|
|
|
|
std::vector<libtorrent::announce_entry> trackers = handle.trackers(); |
|
|
|
|
|
|
|
for (std::vector<libtorrent::announce_entry>::iterator i = trackers.begin(), e = trackers.end(); i != e; ++i) |
|
|
|
|
|
|
|
removeItem(misc::toQStringU(i->url), hash); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Check for trackerless torrent
|
|
|
|
|
|
|
|
if (trackers.size() == 0) |
|
|
|
|
|
|
|
removeItem("", hash); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TrackerFiltersList::setTorrentCount(int all) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
item(0)->setText(tr("All trackers (%1)").arg(all)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QStringList TrackerFiltersList::getHashes(int row) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if (row == 1) |
|
|
|
if (trackerless) |
|
|
|
return m_trackers.value(""); |
|
|
|
addItem("", hash); |
|
|
|
else |
|
|
|
else |
|
|
|
return m_trackers.value(trackerFromRow(row)); |
|
|
|
removeItem("", hash); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TrackerFiltersList::handleFavicoDownload(const QString& url, const QString& filePath) |
|
|
|
void TrackerFiltersList::handleFavicoDownload(const QString& url, const QString& filePath) |
|
|
@ -300,12 +553,62 @@ void TrackerFiltersList::handleFavicoFailure(const QString& url, const QString& |
|
|
|
Log::WARNING); |
|
|
|
Log::WARNING); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TrackerFiltersList::changeTrackerless(bool trackerless, const QString &hash) |
|
|
|
void TrackerFiltersList::showMenu(QPoint) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (trackerless) |
|
|
|
QMenu menu(this); |
|
|
|
addItem("", hash); |
|
|
|
QAction *startAct = menu.addAction(IconProvider::instance()->getIcon("media-playback-start"), tr("Resume torrents")); |
|
|
|
|
|
|
|
QAction *pauseAct = menu.addAction(IconProvider::instance()->getIcon("media-playback-pause"), tr("Pause torrents")); |
|
|
|
|
|
|
|
QAction *deleteTorrentsAct = menu.addAction(IconProvider::instance()->getIcon("edit-delete"), tr("Delete torrents")); |
|
|
|
|
|
|
|
QAction *act = 0; |
|
|
|
|
|
|
|
act = menu.exec(QCursor::pos()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!act) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (act == startAct) |
|
|
|
|
|
|
|
transferList->startVisibleTorrents(); |
|
|
|
|
|
|
|
else if (act == pauseAct) |
|
|
|
|
|
|
|
transferList->pauseVisibleTorrents(); |
|
|
|
|
|
|
|
else if (act == deleteTorrentsAct) |
|
|
|
|
|
|
|
transferList->deleteVisibleTorrents(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TrackerFiltersList::applyFilter(int row) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (row == 0) |
|
|
|
|
|
|
|
transferList->applyTrackerFilterAll(); |
|
|
|
else |
|
|
|
else |
|
|
|
|
|
|
|
transferList->applyTrackerFilter(getHashes(row)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TrackerFiltersList::handleNewTorrent(TorrentModelItem* torrentItem) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QTorrentHandle handle = torrentItem->torrentHandle(); |
|
|
|
|
|
|
|
QString hash = handle.hash(); |
|
|
|
|
|
|
|
std::vector<libtorrent::announce_entry> trackers = handle.trackers(); |
|
|
|
|
|
|
|
for (std::vector<libtorrent::announce_entry>::iterator i = trackers.begin(), e = trackers.end(); i != e; ++i) |
|
|
|
|
|
|
|
addItem(misc::toQStringU(i->url), hash); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Check for trackerless torrent
|
|
|
|
|
|
|
|
if (trackers.size() == 0) |
|
|
|
|
|
|
|
addItem("", hash); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
item(0)->setText(tr("All (%1)", "this is for the tracker filter").arg(++m_totalTorrents)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TrackerFiltersList::torrentAboutToBeDeleted(TorrentModelItem* torrentItem) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QTorrentHandle handle = torrentItem->torrentHandle(); |
|
|
|
|
|
|
|
QString hash = handle.hash(); |
|
|
|
|
|
|
|
std::vector<libtorrent::announce_entry> trackers = handle.trackers(); |
|
|
|
|
|
|
|
for (std::vector<libtorrent::announce_entry>::iterator i = trackers.begin(), e = trackers.end(); i != e; ++i) |
|
|
|
|
|
|
|
removeItem(misc::toQStringU(i->url), hash); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Check for trackerless torrent
|
|
|
|
|
|
|
|
if (trackers.size() == 0) |
|
|
|
removeItem("", hash); |
|
|
|
removeItem("", hash); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
item(0)->setText(tr("All (%1)", "this is for the tracker filter").arg(--m_totalTorrents)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QString TrackerFiltersList::trackerFromRow(int row) const |
|
|
|
QString TrackerFiltersList::trackerFromRow(int row) const |
|
|
@ -338,102 +641,47 @@ QString TrackerFiltersList::getHost(const QString &trakcer) const |
|
|
|
return longHost.mid(index + 1); |
|
|
|
return longHost.mid(index + 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TransferListFiltersWidget::TransferListFiltersWidget(QWidget *parent, TransferListWidget *transferList): QFrame(parent), transferList(transferList), nb_labeled(0), nb_torrents(0) |
|
|
|
QStringList TrackerFiltersList::getHashes(int row) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (row == 1) |
|
|
|
|
|
|
|
return m_trackers.value(""); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return m_trackers.value(trackerFromRow(row)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TransferListFiltersWidget::TransferListFiltersWidget(QWidget *parent, TransferListWidget *transferList) |
|
|
|
|
|
|
|
: QFrame(parent) |
|
|
|
|
|
|
|
, statusFilters(0) |
|
|
|
|
|
|
|
, trackerFilters(0) |
|
|
|
|
|
|
|
, torrentsLabel(0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Construct lists
|
|
|
|
// Construct lists
|
|
|
|
vLayout = new QVBoxLayout(); |
|
|
|
QVBoxLayout *vLayout = new QVBoxLayout(this); |
|
|
|
vLayout->setContentsMargins(0, 4, 0, 0); |
|
|
|
vLayout->setContentsMargins(0, 4, 0, 0); |
|
|
|
QFont font; |
|
|
|
QFont font; |
|
|
|
font.setBold(true); |
|
|
|
font.setBold(true); |
|
|
|
font.setCapitalization(QFont::SmallCaps); |
|
|
|
font.setCapitalization(QFont::SmallCaps); |
|
|
|
torrentsLabel = new QLabel(tr("Torrents")); |
|
|
|
torrentsLabel = new QLabel(tr("Torrents"), this); |
|
|
|
torrentsLabel->setIndent(2); |
|
|
|
torrentsLabel->setIndent(2); |
|
|
|
torrentsLabel->setFont(font); |
|
|
|
torrentsLabel->setFont(font); |
|
|
|
vLayout->addWidget(torrentsLabel); |
|
|
|
vLayout->addWidget(torrentsLabel); |
|
|
|
statusFilters = new StatusFiltersWidget(this); |
|
|
|
statusFilters = new StatusFiltersWidget(this, transferList); |
|
|
|
vLayout->addWidget(statusFilters); |
|
|
|
vLayout->addWidget(statusFilters); |
|
|
|
QLabel *labelsLabel = new QLabel(tr("Labels")); |
|
|
|
QLabel *labelsLabel = new QLabel(tr("Labels"), this); |
|
|
|
labelsLabel->setIndent(2); |
|
|
|
labelsLabel->setIndent(2); |
|
|
|
labelsLabel->setFont(font); |
|
|
|
labelsLabel->setFont(font); |
|
|
|
vLayout->addWidget(labelsLabel); |
|
|
|
vLayout->addWidget(labelsLabel); |
|
|
|
labelFilters = new LabelFiltersList(this); |
|
|
|
LabelFiltersList *labelFilters = new LabelFiltersList(this, transferList); |
|
|
|
vLayout->addWidget(labelFilters); |
|
|
|
vLayout->addWidget(labelFilters); |
|
|
|
QLabel *trackersLabel = new QLabel(tr("Trackers")); |
|
|
|
QLabel *trackersLabel = new QLabel(tr("Trackers"), this); |
|
|
|
trackersLabel->setIndent(2); |
|
|
|
trackersLabel->setIndent(2); |
|
|
|
trackersLabel->setFont(font); |
|
|
|
trackersLabel->setFont(font); |
|
|
|
vLayout->addWidget(trackersLabel); |
|
|
|
vLayout->addWidget(trackersLabel); |
|
|
|
trackerFilters = new TrackerFiltersList(this); |
|
|
|
trackerFilters = new TrackerFiltersList(this, transferList); |
|
|
|
vLayout->addWidget(trackerFilters); |
|
|
|
vLayout->addWidget(trackerFilters); |
|
|
|
setLayout(vLayout); |
|
|
|
setLayout(vLayout); |
|
|
|
labelFilters->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
|
|
|
|
|
|
trackerFilters->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
|
|
|
|
|
|
statusFilters->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
|
|
|
|
|
|
statusFilters->setSpacing(0); |
|
|
|
|
|
|
|
setContentsMargins(0,0,0,0); |
|
|
|
setContentsMargins(0,0,0,0); |
|
|
|
vLayout->setSpacing(2); |
|
|
|
vLayout->setSpacing(2); |
|
|
|
// Add status filters
|
|
|
|
|
|
|
|
QListWidgetItem *all = new QListWidgetItem(statusFilters); |
|
|
|
|
|
|
|
all->setData(Qt::DisplayRole, QVariant(tr("All") + " (0)")); |
|
|
|
|
|
|
|
all->setData(Qt::DecorationRole, QIcon(":/icons/skin/filterall.png")); |
|
|
|
|
|
|
|
QListWidgetItem *downloading = new QListWidgetItem(statusFilters); |
|
|
|
|
|
|
|
downloading->setData(Qt::DisplayRole, QVariant(tr("Downloading") + " (0)")); |
|
|
|
|
|
|
|
downloading->setData(Qt::DecorationRole, QIcon(":/icons/skin/downloading.png")); |
|
|
|
|
|
|
|
QListWidgetItem *completed = new QListWidgetItem(statusFilters); |
|
|
|
|
|
|
|
completed->setData(Qt::DisplayRole, QVariant(tr("Completed") + " (0)")); |
|
|
|
|
|
|
|
completed->setData(Qt::DecorationRole, QIcon(":/icons/skin/uploading.png")); |
|
|
|
|
|
|
|
QListWidgetItem *resumed = new QListWidgetItem(statusFilters); |
|
|
|
|
|
|
|
resumed->setData(Qt::DisplayRole, QVariant(tr("Resumed") + " (0)")); |
|
|
|
|
|
|
|
resumed->setData(Qt::DecorationRole, QIcon(":/icons/skin/resumed.png")); |
|
|
|
|
|
|
|
QListWidgetItem *paused = new QListWidgetItem(statusFilters); |
|
|
|
|
|
|
|
paused->setData(Qt::DisplayRole, QVariant(tr("Paused") + " (0)")); |
|
|
|
|
|
|
|
paused->setData(Qt::DecorationRole, QIcon(":/icons/skin/paused.png")); |
|
|
|
|
|
|
|
QListWidgetItem *active = new QListWidgetItem(statusFilters); |
|
|
|
|
|
|
|
active->setData(Qt::DisplayRole, QVariant(tr("Active") + " (0)")); |
|
|
|
|
|
|
|
active->setData(Qt::DecorationRole, QIcon(":/icons/skin/filteractive.png")); |
|
|
|
|
|
|
|
QListWidgetItem *inactive = new QListWidgetItem(statusFilters); |
|
|
|
|
|
|
|
inactive->setData(Qt::DisplayRole, QVariant(tr("Inactive") + " (0)")); |
|
|
|
|
|
|
|
inactive->setData(Qt::DecorationRole, QIcon(":/icons/skin/filterinactive.png")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SIGNAL/SLOT
|
|
|
|
|
|
|
|
connect(statusFilters, SIGNAL(currentRowChanged(int)), transferList, SLOT(applyStatusFilter(int))); |
|
|
|
|
|
|
|
connect(transferList->getSourceModel(), SIGNAL(modelRefreshed()), SLOT(updateTorrentNumbers())); |
|
|
|
|
|
|
|
connect(transferList->getSourceModel(), SIGNAL(torrentAdded(TorrentModelItem*)), SLOT(handleNewTorrent(TorrentModelItem*))); |
|
|
|
|
|
|
|
connect(labelFilters, SIGNAL(currentRowChanged(int)), this, SLOT(applyLabelFilter(int))); |
|
|
|
|
|
|
|
connect(trackerFilters, SIGNAL(currentRowChanged(int)), this, SLOT(applyTrackerFilter(int))); |
|
|
|
|
|
|
|
connect(transferList->getSourceModel(), SIGNAL(torrentAboutToBeRemoved(TorrentModelItem*)), SLOT(torrentAboutToBeDeleted(TorrentModelItem*))); |
|
|
|
|
|
|
|
connect(transferList->getSourceModel(), SIGNAL(torrentChangedLabel(TorrentModelItem*,QString,QString)), SLOT(torrentChangedLabel(TorrentModelItem*, QString, QString))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add Label filters
|
|
|
|
|
|
|
|
QListWidgetItem *allLabels = new QListWidgetItem(labelFilters); |
|
|
|
|
|
|
|
allLabels->setData(Qt::DisplayRole, QVariant(tr("All labels") + " (0)")); |
|
|
|
|
|
|
|
allLabels->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("inode-directory")); |
|
|
|
|
|
|
|
QListWidgetItem *noLabel = new QListWidgetItem(labelFilters); |
|
|
|
|
|
|
|
noLabel->setData(Qt::DisplayRole, QVariant(tr("Unlabeled") + " (0)")); |
|
|
|
|
|
|
|
noLabel->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("inode-directory")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Load settings
|
|
|
|
|
|
|
|
loadSettings(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
labelFilters->setCurrentRow(0); |
|
|
|
|
|
|
|
trackerFilters->setCurrentRow(0); |
|
|
|
|
|
|
|
//labelFilters->selectionModel()->select(labelFilters->model()->index(0,0), QItemSelectionModel::Select);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Label menu
|
|
|
|
|
|
|
|
labelFilters->setContextMenuPolicy(Qt::CustomContextMenu); |
|
|
|
|
|
|
|
connect(labelFilters, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showLabelMenu(QPoint))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Tracker menu
|
|
|
|
|
|
|
|
trackerFilters->setContextMenuPolicy(Qt::CustomContextMenu); |
|
|
|
|
|
|
|
connect(trackerFilters, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showTrackerMenu(QPoint))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TransferListFiltersWidget::~TransferListFiltersWidget() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
saveSettings(); |
|
|
|
|
|
|
|
delete statusFilters; |
|
|
|
|
|
|
|
delete labelFilters; |
|
|
|
|
|
|
|
delete trackerFilters; |
|
|
|
|
|
|
|
delete vLayout; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TransferListFiltersWidget::resizeEvent(QResizeEvent *event) |
|
|
|
void TransferListFiltersWidget::resizeEvent(QResizeEvent *event) |
|
|
@ -443,56 +691,6 @@ void TransferListFiltersWidget::resizeEvent(QResizeEvent *event) |
|
|
|
trackerFilters->setMinimumHeight((height - minHeight) / 2); |
|
|
|
trackerFilters->setMinimumHeight((height - minHeight) / 2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
StatusFiltersWidget* TransferListFiltersWidget::getStatusFilters() const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return statusFilters; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TransferListFiltersWidget::saveSettings() const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Preferences* const pref = Preferences::instance(); |
|
|
|
|
|
|
|
pref->setTransSelFilter(statusFilters->currentRow()); |
|
|
|
|
|
|
|
pref->setTorrentLabels(customLabels.keys()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TransferListFiltersWidget::loadSettings() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
statusFilters->setCurrentRow(Preferences::instance()->getTransSelFilter()); |
|
|
|
|
|
|
|
const QStringList label_list = Preferences::instance()->getTorrentLabels(); |
|
|
|
|
|
|
|
foreach (const QString &label, label_list) { |
|
|
|
|
|
|
|
customLabels.insert(label, 0); |
|
|
|
|
|
|
|
qDebug("Creating label QListWidgetItem: %s", qPrintable(label)); |
|
|
|
|
|
|
|
QListWidgetItem *newLabel = new QListWidgetItem(); |
|
|
|
|
|
|
|
newLabel->setText(label + " (0)"); |
|
|
|
|
|
|
|
newLabel->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("inode-directory")); |
|
|
|
|
|
|
|
labelFilters->addItem(newLabel); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TransferListFiltersWidget::updateTorrentNumbers() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const TorrentStatusReport report = transferList->getSourceModel()->getTorrentStatusReport(); |
|
|
|
|
|
|
|
statusFilters->item(TorrentFilter::ALL)->setData(Qt::DisplayRole, QVariant(tr("All") + " (" + QString::number(report.nb_active + report.nb_inactive) + ")")); |
|
|
|
|
|
|
|
statusFilters->item(TorrentFilter::DOWNLOADING)->setData(Qt::DisplayRole, QVariant(tr("Downloading") + " (" + QString::number(report.nb_downloading) + ")")); |
|
|
|
|
|
|
|
statusFilters->item(TorrentFilter::COMPLETED)->setData(Qt::DisplayRole, QVariant(tr("Completed") + " (" + QString::number(report.nb_seeding) + ")")); |
|
|
|
|
|
|
|
statusFilters->item(TorrentFilter::PAUSED)->setData(Qt::DisplayRole, QVariant(tr("Paused") + " (" + QString::number(report.nb_paused) + ")")); |
|
|
|
|
|
|
|
statusFilters->item(TorrentFilter::RESUMED)->setData(Qt::DisplayRole, QVariant(tr("Resumed") + " (" + QString::number(report.nb_active + report.nb_inactive - report.nb_paused) + ")")); |
|
|
|
|
|
|
|
statusFilters->item(TorrentFilter::ACTIVE)->setData(Qt::DisplayRole, QVariant(tr("Active") + " (" + QString::number(report.nb_active) + ")")); |
|
|
|
|
|
|
|
statusFilters->item(TorrentFilter::INACTIVE)->setData(Qt::DisplayRole, QVariant(tr("Inactive") + " (" + QString::number(report.nb_inactive) + ")")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TransferListFiltersWidget::addLabel(QString& label) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
label = fsutils::toValidFileSystemName(label.trimmed()); |
|
|
|
|
|
|
|
if (label.isEmpty() || customLabels.contains(label)) return; |
|
|
|
|
|
|
|
QListWidgetItem *newLabel = new QListWidgetItem(); |
|
|
|
|
|
|
|
newLabel->setText(label + " (0)"); |
|
|
|
|
|
|
|
newLabel->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("inode-directory")); |
|
|
|
|
|
|
|
labelFilters->addItem(newLabel); |
|
|
|
|
|
|
|
customLabels.insert(label, 0); |
|
|
|
|
|
|
|
Preferences::instance()->addTorrentLabel(label); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TransferListFiltersWidget::addTrackers(const QStringList &trackers, const QString &hash) |
|
|
|
void TransferListFiltersWidget::addTrackers(const QStringList &trackers, const QString &hash) |
|
|
|
{ |
|
|
|
{ |
|
|
|
foreach (const QString &tracker, trackers) |
|
|
|
foreach (const QString &tracker, trackers) |
|
|
@ -509,226 +707,3 @@ void TransferListFiltersWidget::changeTrackerless(bool trackerless, const QStrin |
|
|
|
{ |
|
|
|
{ |
|
|
|
trackerFilters->changeTrackerless(trackerless, hash); |
|
|
|
trackerFilters->changeTrackerless(trackerless, hash); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TransferListFiltersWidget::showLabelMenu(QPoint) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QMenu labelMenu(labelFilters); |
|
|
|
|
|
|
|
QAction *addAct = labelMenu.addAction(IconProvider::instance()->getIcon("list-add"), tr("Add label...")); |
|
|
|
|
|
|
|
QAction *removeAct = 0; |
|
|
|
|
|
|
|
QAction *removeUnusedAct = 0; |
|
|
|
|
|
|
|
if (!labelFilters->selectedItems().empty() && labelFilters->row(labelFilters->selectedItems().first()) > 1) |
|
|
|
|
|
|
|
removeAct = labelMenu.addAction(IconProvider::instance()->getIcon("list-remove"), tr("Remove label")); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
removeUnusedAct = labelMenu.addAction(IconProvider::instance()->getIcon("list-remove"), tr("Remove unused labels")); |
|
|
|
|
|
|
|
labelMenu.addSeparator(); |
|
|
|
|
|
|
|
QAction *startAct = labelMenu.addAction(IconProvider::instance()->getIcon("media-playback-start"), tr("Resume torrents")); |
|
|
|
|
|
|
|
QAction *pauseAct = labelMenu.addAction(IconProvider::instance()->getIcon("media-playback-pause"), tr("Pause torrents")); |
|
|
|
|
|
|
|
QAction *deleteTorrentsAct = labelMenu.addAction(IconProvider::instance()->getIcon("edit-delete"), tr("Delete torrents")); |
|
|
|
|
|
|
|
QAction *act = 0; |
|
|
|
|
|
|
|
act = labelMenu.exec(QCursor::pos()); |
|
|
|
|
|
|
|
if (act) { |
|
|
|
|
|
|
|
if (act == removeAct) { |
|
|
|
|
|
|
|
removeSelectedLabel(); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (act == removeUnusedAct) { |
|
|
|
|
|
|
|
removeUnusedLabels(); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (act == deleteTorrentsAct) { |
|
|
|
|
|
|
|
transferList->deleteVisibleTorrents(); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (act == startAct) { |
|
|
|
|
|
|
|
transferList->startVisibleTorrents(); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (act == pauseAct) { |
|
|
|
|
|
|
|
transferList->pauseVisibleTorrents(); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (act == addAct) { |
|
|
|
|
|
|
|
bool ok; |
|
|
|
|
|
|
|
QString label = ""; |
|
|
|
|
|
|
|
bool invalid; |
|
|
|
|
|
|
|
do { |
|
|
|
|
|
|
|
invalid = false; |
|
|
|
|
|
|
|
label = AutoExpandableDialog::getText(this, tr("New Label"), tr("Label:"), QLineEdit::Normal, label, &ok); |
|
|
|
|
|
|
|
if (ok && !label.isEmpty()) { |
|
|
|
|
|
|
|
if (fsutils::isValidFileSystemName(label)) { |
|
|
|
|
|
|
|
addLabel(label); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
QMessageBox::warning(this, tr("Invalid label name"), tr("Please don't use any special characters in the label name.")); |
|
|
|
|
|
|
|
invalid = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} while (invalid); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TransferListFiltersWidget::showTrackerMenu(QPoint) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QMenu trackerMenu(trackerFilters); |
|
|
|
|
|
|
|
QAction *startAct = trackerMenu.addAction(IconProvider::instance()->getIcon("media-playback-start"), tr("Resume torrents")); |
|
|
|
|
|
|
|
QAction *pauseAct = trackerMenu.addAction(IconProvider::instance()->getIcon("media-playback-pause"), tr("Pause torrents")); |
|
|
|
|
|
|
|
QAction *deleteTorrentsAct = trackerMenu.addAction(IconProvider::instance()->getIcon("edit-delete"), tr("Delete torrents")); |
|
|
|
|
|
|
|
QAction *act = 0; |
|
|
|
|
|
|
|
act = trackerMenu.exec(QCursor::pos()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (act) { |
|
|
|
|
|
|
|
if (act == startAct) |
|
|
|
|
|
|
|
transferList->startVisibleTorrents(); |
|
|
|
|
|
|
|
else if (act == pauseAct) |
|
|
|
|
|
|
|
transferList->pauseVisibleTorrents(); |
|
|
|
|
|
|
|
else if (act == deleteTorrentsAct) |
|
|
|
|
|
|
|
transferList->deleteVisibleTorrents(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TransferListFiltersWidget::removeSelectedLabel() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const int row = labelFilters->row(labelFilters->selectedItems().first()); |
|
|
|
|
|
|
|
Q_ASSERT(row > 1); |
|
|
|
|
|
|
|
const QString &label = labelFilters->labelFromRow(row); |
|
|
|
|
|
|
|
Q_ASSERT(customLabels.contains(label)); |
|
|
|
|
|
|
|
customLabels.remove(label); |
|
|
|
|
|
|
|
transferList->removeLabelFromRows(label); |
|
|
|
|
|
|
|
// Select first label
|
|
|
|
|
|
|
|
labelFilters->setCurrentItem(labelFilters->item(0)); |
|
|
|
|
|
|
|
labelFilters->selectionModel()->select(labelFilters->model()->index(0,0), QItemSelectionModel::Select); |
|
|
|
|
|
|
|
applyLabelFilter(0); |
|
|
|
|
|
|
|
// Un display filter
|
|
|
|
|
|
|
|
delete labelFilters->takeItem(row); |
|
|
|
|
|
|
|
labelFilters->updateGeometry(); |
|
|
|
|
|
|
|
// Save custom labels to remember it was deleted
|
|
|
|
|
|
|
|
Preferences::instance()->removeTorrentLabel(label); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TransferListFiltersWidget::removeUnusedLabels() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QStringList unusedLabels; |
|
|
|
|
|
|
|
QHash<QString, int>::const_iterator i; |
|
|
|
|
|
|
|
for (i = customLabels.begin(); i != customLabels.end(); ++i) |
|
|
|
|
|
|
|
if (i.value() == 0) |
|
|
|
|
|
|
|
unusedLabels << i.key(); |
|
|
|
|
|
|
|
foreach (const QString &label, unusedLabels) { |
|
|
|
|
|
|
|
customLabels.remove(label); |
|
|
|
|
|
|
|
delete labelFilters->takeItem(labelFilters->rowFromLabel(label)); |
|
|
|
|
|
|
|
Preferences::instance()->removeTorrentLabel(label); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!unusedLabels.empty()) |
|
|
|
|
|
|
|
labelFilters->updateGeometry(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TransferListFiltersWidget::applyLabelFilter(int row) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
switch (row) { |
|
|
|
|
|
|
|
case 0: |
|
|
|
|
|
|
|
transferList->applyLabelFilterAll(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 1: |
|
|
|
|
|
|
|
transferList->applyLabelFilter(QString()); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
transferList->applyLabelFilter(labelFilters->labelFromRow(row)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TransferListFiltersWidget::applyTrackerFilter(int row) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (row == 0) |
|
|
|
|
|
|
|
transferList->applyTrackerFilterAll(); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
transferList->applyTrackerFilter(trackerFilters->getHashes(row)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TransferListFiltersWidget::torrentChangedLabel(TorrentModelItem *torrentItem, QString old_label, QString new_label) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Q_UNUSED(torrentItem); |
|
|
|
|
|
|
|
qDebug("Torrent label changed from %s to %s", qPrintable(old_label), qPrintable(new_label)); |
|
|
|
|
|
|
|
if (!old_label.isEmpty()) { |
|
|
|
|
|
|
|
if (customLabels.contains(old_label)) { |
|
|
|
|
|
|
|
const int new_count = customLabels.value(old_label, 0) - 1; |
|
|
|
|
|
|
|
Q_ASSERT(new_count >= 0); |
|
|
|
|
|
|
|
customLabels.insert(old_label, new_count); |
|
|
|
|
|
|
|
const int row = labelFilters->rowFromLabel(old_label); |
|
|
|
|
|
|
|
Q_ASSERT(row >= 2); |
|
|
|
|
|
|
|
labelFilters->item(row)->setText(old_label + " (" + QString::number(new_count) + ")"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
--nb_labeled; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!new_label.isEmpty()) { |
|
|
|
|
|
|
|
if (!customLabels.contains(new_label)) |
|
|
|
|
|
|
|
addLabel(new_label); |
|
|
|
|
|
|
|
const int new_count = customLabels.value(new_label, 0) + 1; |
|
|
|
|
|
|
|
Q_ASSERT(new_count >= 1); |
|
|
|
|
|
|
|
customLabels.insert(new_label, new_count); |
|
|
|
|
|
|
|
const int row = labelFilters->rowFromLabel(new_label); |
|
|
|
|
|
|
|
Q_ASSERT(row >= 2); |
|
|
|
|
|
|
|
labelFilters->item(row)->setText(new_label + " (" + QString::number(new_count) + ")"); |
|
|
|
|
|
|
|
++nb_labeled; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
updateStickyLabelCounters(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TransferListFiltersWidget::handleNewTorrent(TorrentModelItem* torrentItem) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QString label = torrentItem->data(TorrentModelItem::TR_LABEL).toString(); |
|
|
|
|
|
|
|
qDebug("New torrent was added with label: %s", qPrintable(label)); |
|
|
|
|
|
|
|
if (!label.isEmpty()) { |
|
|
|
|
|
|
|
if (!customLabels.contains(label)) { |
|
|
|
|
|
|
|
addLabel(label); |
|
|
|
|
|
|
|
// addLabel may have changed the label, update the model accordingly.
|
|
|
|
|
|
|
|
torrentItem->setData(TorrentModelItem::TR_LABEL, label); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Update label counter
|
|
|
|
|
|
|
|
Q_ASSERT(customLabels.contains(label)); |
|
|
|
|
|
|
|
const int new_count = customLabels.value(label, 0) + 1; |
|
|
|
|
|
|
|
customLabels.insert(label, new_count); |
|
|
|
|
|
|
|
const int row = labelFilters->rowFromLabel(label); |
|
|
|
|
|
|
|
qDebug("torrentAdded, Row: %d", row); |
|
|
|
|
|
|
|
Q_ASSERT(row >= 2); |
|
|
|
|
|
|
|
Q_ASSERT(labelFilters->item(row)); |
|
|
|
|
|
|
|
labelFilters->item(row)->setText(label + " (" + QString::number(new_count) + ")"); |
|
|
|
|
|
|
|
++nb_labeled; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
++nb_torrents; |
|
|
|
|
|
|
|
Q_ASSERT(nb_torrents >= 0); |
|
|
|
|
|
|
|
Q_ASSERT(nb_labeled >= 0); |
|
|
|
|
|
|
|
Q_ASSERT(nb_labeled <= nb_torrents); |
|
|
|
|
|
|
|
updateStickyLabelCounters(); |
|
|
|
|
|
|
|
trackerFilters->addItem(torrentItem->torrentHandle()); |
|
|
|
|
|
|
|
trackerFilters->setTorrentCount(nb_torrents); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TransferListFiltersWidget::torrentAboutToBeDeleted(TorrentModelItem* torrentItem) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Q_ASSERT(torrentItem); |
|
|
|
|
|
|
|
QString label = torrentItem->data(TorrentModelItem::TR_LABEL).toString(); |
|
|
|
|
|
|
|
if (!label.isEmpty()) { |
|
|
|
|
|
|
|
// Update label counter
|
|
|
|
|
|
|
|
const int new_count = customLabels.value(label, 0) - 1; |
|
|
|
|
|
|
|
customLabels.insert(label, new_count); |
|
|
|
|
|
|
|
const int row = labelFilters->rowFromLabel(label); |
|
|
|
|
|
|
|
Q_ASSERT(row >= 2); |
|
|
|
|
|
|
|
labelFilters->item(row)->setText(label + " (" + QString::number(new_count) + ")"); |
|
|
|
|
|
|
|
--nb_labeled; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
--nb_torrents; |
|
|
|
|
|
|
|
qDebug("nb_torrents: %d, nb_labeled: %d", nb_torrents, nb_labeled); |
|
|
|
|
|
|
|
Q_ASSERT(nb_torrents >= 0); |
|
|
|
|
|
|
|
Q_ASSERT(nb_labeled >= 0); |
|
|
|
|
|
|
|
Q_ASSERT(nb_labeled <= nb_torrents); |
|
|
|
|
|
|
|
updateStickyLabelCounters(); |
|
|
|
|
|
|
|
trackerFilters->removeItem(torrentItem->torrentHandle()); |
|
|
|
|
|
|
|
trackerFilters->setTorrentCount(nb_torrents); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TransferListFiltersWidget::updateStickyLabelCounters() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
labelFilters->item(0)->setText(tr("All labels") + " (" + QString::number(nb_torrents) + ")"); |
|
|
|
|
|
|
|
labelFilters->item(1)->setText(tr("Unlabeled") + " (" + QString::number(nb_torrents - nb_labeled) + ")"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|