mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-10 14:57:52 +00:00
- Label counters are now properly updated (and labeling seems to work fine)
This commit is contained in:
parent
ed803fb994
commit
edb6857de0
@ -40,6 +40,7 @@
|
||||
#include <QMenu>
|
||||
#include <QInputDialog>
|
||||
|
||||
#include "transferlistdelegate.h"
|
||||
#include "transferlistwidget.h"
|
||||
|
||||
class TransferListFiltersWidget: public QFrame {
|
||||
@ -47,13 +48,16 @@ class TransferListFiltersWidget: public QFrame {
|
||||
|
||||
private:
|
||||
QStringList customLabels;
|
||||
QList<int> labelCounters;
|
||||
QListWidget* statusFilters;
|
||||
QListWidget* labelFilters;
|
||||
QVBoxLayout* vLayout;
|
||||
TransferListWidget *transferList;
|
||||
int nb_labeled;
|
||||
int nb_torrents;
|
||||
|
||||
public:
|
||||
TransferListFiltersWidget(QWidget *parent, TransferListWidget *transferList): QFrame(parent), transferList(transferList) {
|
||||
TransferListFiltersWidget(QWidget *parent, TransferListWidget *transferList): QFrame(parent), transferList(transferList), nb_labeled(0), nb_torrents(0) {
|
||||
// Construct lists
|
||||
vLayout = new QVBoxLayout();
|
||||
statusFilters = new QListWidget();
|
||||
@ -86,7 +90,8 @@ public:
|
||||
connect(statusFilters, SIGNAL(currentRowChanged(int)), transferList, SLOT(applyStatusFilter(int)));
|
||||
connect(transferList, SIGNAL(torrentStatusUpdate(uint,uint,uint,uint)), this, SLOT(updateTorrentNumbers(uint, uint, uint, uint)));
|
||||
connect(labelFilters, SIGNAL(currentRowChanged(int)), this, SLOT(applyLabelFilter(int)));
|
||||
connect(transferList, SIGNAL(newLabel(QString)), this, SLOT(addLabel(QString)));
|
||||
connect(transferList, SIGNAL(torrentAdded(QModelIndex)), this, SLOT(torrentAdded(QModelIndex)));
|
||||
connect(transferList, SIGNAL(torrentAboutToBeRemoved(QModelIndex)), this, SLOT(torrentAboutToBeDeleted(QModelIndex)));
|
||||
|
||||
// Load settings
|
||||
loadSettings();
|
||||
@ -131,6 +136,9 @@ public:
|
||||
settings.beginGroup(QString::fromUtf8("TransferListFilters"));
|
||||
statusFilters->setCurrentRow(settings.value("selectedFilterIndex", 0).toInt());
|
||||
customLabels = settings.value("customLabels", QStringList()).toStringList();
|
||||
for(int i=0; i<customLabels.size(); ++i) {
|
||||
labelCounters << 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected slots:
|
||||
@ -148,6 +156,7 @@ protected slots:
|
||||
QListWidgetItem *newLabel = new QListWidgetItem(labelFilters);
|
||||
newLabel->setText(label + " (0)");
|
||||
customLabels << label;
|
||||
labelCounters << 0;
|
||||
saveCustomLabels();
|
||||
}
|
||||
|
||||
@ -179,6 +188,7 @@ protected slots:
|
||||
int row = labelFilters->row(labelFilters->selectedItems().first());
|
||||
Q_ASSERT(row > 1);
|
||||
QString label = customLabels.takeAt(row - 2);
|
||||
labelCounters.removeAt(row-2);
|
||||
labelFilters->removeItemWidget(labelFilters->selectedItems().first());
|
||||
transferList->removeLabelFromRows(label);
|
||||
// Select first label
|
||||
@ -199,6 +209,69 @@ protected slots:
|
||||
}
|
||||
}
|
||||
|
||||
void torrentChangedLabel(QString old_label, QString new_label) {
|
||||
if(!old_label.isEmpty()) {
|
||||
int i = customLabels.indexOf(old_label);
|
||||
int new_count = labelCounters[i]-1;
|
||||
Q_ASSERT(new_count >= 0);
|
||||
labelCounters.replace(i, new_count);
|
||||
labelFilters->item(i+2)->setText(old_label + " ("+ QString::number(new_count) +")");
|
||||
}
|
||||
if(!new_label.isEmpty()) {
|
||||
if(!customLabels.contains(new_label))
|
||||
addLabel(new_label);
|
||||
int i = customLabels.indexOf(new_label);
|
||||
int new_count = labelCounters[i]+1;
|
||||
labelCounters.replace(i, new_count);
|
||||
labelFilters->item(i+2)->setText(new_label + " ("+ QString::number(new_count) +")");
|
||||
}
|
||||
}
|
||||
|
||||
void torrentAdded(QModelIndex index) {
|
||||
Q_ASSERT(index.isValid());
|
||||
QString label = transferList->model()->index(index.row(), TR_LABEL).data(Qt::DisplayRole).toString().trimmed();
|
||||
if(!label.isEmpty()) {
|
||||
if(!customLabels.contains(label)) {
|
||||
addLabel(label);
|
||||
}
|
||||
// Update label counter
|
||||
int i = customLabels.indexOf(label);
|
||||
int new_count = labelCounters[i]+1;
|
||||
labelCounters.replace(i, new_count);
|
||||
labelFilters->item(i+2)->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();
|
||||
}
|
||||
|
||||
void torrentAboutToBeDeleted(QModelIndex index) {
|
||||
Q_ASSERT(index.isValid());
|
||||
QString label = transferList->model()->index(index.row(), TR_LABEL).data(Qt::DisplayRole).toString().trimmed();
|
||||
if(!label.isEmpty()) {
|
||||
// Update label counter
|
||||
int i = customLabels.indexOf(label);
|
||||
Q_ASSERT(i >= 0);
|
||||
int new_count = labelCounters[i]-1;
|
||||
labelCounters.replace(i, new_count);
|
||||
labelFilters->item(i+2)->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();
|
||||
}
|
||||
|
||||
void updateStickyLabelCounters() {
|
||||
labelFilters->item(0)->setText(tr("All labels") + " ("+QString::number(nb_torrents)+")");
|
||||
labelFilters->item(1)->setText(tr("No label") + " ("+QString::number(nb_torrents-nb_labeled)+")");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // TRANSFERLISTFILTERSWIDGET_H
|
||||
|
@ -163,7 +163,6 @@ void TransferListWidget::addTorrent(QTorrentHandle& h) {
|
||||
listModel->setData(listModel->index(row, TR_SEEDS), QVariant((double)0.0));
|
||||
listModel->setData(listModel->index(row, TR_PEERS), QVariant((double)0.0));
|
||||
QString label = TorrentPersistentData::getLabel(h.hash());
|
||||
emit newLabel(label);
|
||||
listModel->setData(listModel->index(row, TR_LABEL), QVariant(label));
|
||||
if(BTSession->isQueueingEnabled())
|
||||
listModel->setData(listModel->index(row, TR_PRIORITY), QVariant((int)h.queue_position()));
|
||||
@ -191,6 +190,9 @@ void TransferListWidget::addTorrent(QTorrentHandle& h) {
|
||||
// Select first torrent to be added
|
||||
if(listModel->rowCount() == 1)
|
||||
selectionModel()->setCurrentIndex(proxyModel->index(row, TR_NAME), QItemSelectionModel::SelectCurrent|QItemSelectionModel::Rows);
|
||||
// Emit signal
|
||||
emit torrentAdded(listModel->index(row, 0));
|
||||
// Refresh the list
|
||||
refreshList();
|
||||
} catch(invalid_handle e) {
|
||||
// Remove added torrent
|
||||
@ -206,6 +208,7 @@ void TransferListWidget::setRowColor(int row, QColor color) {
|
||||
}
|
||||
|
||||
void TransferListWidget::deleteTorrent(int row, bool refresh_list) {
|
||||
emit torrentAboutToBeRemoved(listModel->index(row, 0));
|
||||
listModel->removeRow(row);
|
||||
if(refresh_list)
|
||||
refreshList();
|
||||
@ -235,6 +238,11 @@ void TransferListWidget::pauseTorrent(int row, bool refresh_list) {
|
||||
refreshList();
|
||||
}
|
||||
|
||||
|
||||
int TransferListWidget::getNbTorrents() const {
|
||||
return listModel->rowCount();
|
||||
}
|
||||
|
||||
// Wrapper slot for bittorrent signal
|
||||
void TransferListWidget::resumeTorrent(QTorrentHandle &h) {
|
||||
resumeTorrent(getRowFromHash(h.hash()));
|
||||
@ -418,7 +426,9 @@ void TransferListWidget::setFinished(QTorrentHandle &h) {
|
||||
listModel->setData(listModel->index(row, TR_PRIORITY), QVariant((int)-1));
|
||||
}
|
||||
} catch(invalid_handle e) {
|
||||
if(row >= 0) deleteTorrent(row);
|
||||
if(row >= 0) {
|
||||
deleteTorrent(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -580,7 +590,8 @@ void TransferListWidget::deleteSelectedTorrents() {
|
||||
hashes << getHashFromRow(mapToSource(index).row());
|
||||
}
|
||||
foreach(const QString &hash, hashes) {
|
||||
deleteTorrent(getRowFromHash(hash), false);
|
||||
int row = getRowFromHash(hash);
|
||||
deleteTorrent(row, false);
|
||||
BTSession->deleteTorrent(hash, delete_local_files);
|
||||
}
|
||||
refreshList();
|
||||
@ -849,7 +860,6 @@ void TransferListWidget::askNewLabelForSelection() {
|
||||
bool ok;
|
||||
QString label = QInputDialog::getText(this, tr("New Label"), tr("Label:"), QLineEdit::Normal, "", &ok);
|
||||
if (ok && !label.isEmpty()) {
|
||||
emit newLabel(label);
|
||||
// Assign label to selection
|
||||
setSelectionLabel(label);
|
||||
}
|
||||
@ -859,8 +869,10 @@ void TransferListWidget::setSelectionLabel(QString label) {
|
||||
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||||
foreach(const QModelIndex &index, selectedIndexes) {
|
||||
QString hash = getHashFromRow(mapToSource(index).row());
|
||||
QString old_label = proxyModel->data(proxyModel->index(index.row(), TR_LABEL)).toString();
|
||||
proxyModel->setData(proxyModel->index(index.row(), TR_LABEL), QVariant(label));
|
||||
TorrentPersistentData::saveLabel(hash, label);
|
||||
emit torrentChangedLabel(old_label, label);
|
||||
}
|
||||
}
|
||||
|
||||
@ -868,6 +880,7 @@ void TransferListWidget::removeLabelFromRows(QString label) {
|
||||
for(int i=0; i<listModel->rowCount(); ++i) {
|
||||
if(label == listModel->data(listModel->index(i, TR_LABEL), Qt::DisplayRole))
|
||||
listModel->setData(listModel->index(i, TR_LABEL), "", Qt::DisplayRole);
|
||||
emit torrentChangedLabel(label, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,7 @@ private:
|
||||
public:
|
||||
TransferListWidget(QWidget *parent, GUI *main_window, Bittorrent* BTSession);
|
||||
~TransferListWidget();
|
||||
int getNbTorrents() const;
|
||||
|
||||
protected:
|
||||
int getRowFromHash(QString hash) const;
|
||||
@ -120,8 +121,9 @@ public slots:
|
||||
signals:
|
||||
void currentTorrentChanged(QTorrentHandle &h);
|
||||
void torrentStatusUpdate(unsigned int nb_downloading, unsigned int nb_seeding, unsigned int nb_active, unsigned int nb_inactive);
|
||||
void newLabel(QString label);
|
||||
|
||||
void torrentAdded(QModelIndex index);
|
||||
void torrentAboutToBeRemoved(QModelIndex index);
|
||||
void torrentChangedLabel(QString old_label, QString new_label);
|
||||
};
|
||||
|
||||
#endif // TRANSFERLISTWIDGET_H
|
||||
|
Loading…
Reference in New Issue
Block a user