|
|
@ -39,10 +39,43 @@ |
|
|
|
#include <QVBoxLayout> |
|
|
|
#include <QVBoxLayout> |
|
|
|
#include <QMenu> |
|
|
|
#include <QMenu> |
|
|
|
#include <QInputDialog> |
|
|
|
#include <QInputDialog> |
|
|
|
|
|
|
|
#include <QDragMoveEvent> |
|
|
|
|
|
|
|
|
|
|
|
#include "transferlistdelegate.h" |
|
|
|
#include "transferlistdelegate.h" |
|
|
|
#include "transferlistwidget.h" |
|
|
|
#include "transferlistwidget.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LabelFiltersList: public QListWidget { |
|
|
|
|
|
|
|
Q_OBJECT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
LabelFiltersList(QWidget *parent): QListWidget(parent){ |
|
|
|
|
|
|
|
// Accept drop
|
|
|
|
|
|
|
|
setAcceptDrops(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
signals: |
|
|
|
|
|
|
|
void torrentDropped(int label_row); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
|
|
|
|
void dragMoveEvent(QDragMoveEvent* event) { |
|
|
|
|
|
|
|
//qDebug("filters, dragmoveevent");
|
|
|
|
|
|
|
|
if(itemAt(event->pos()) && row(itemAt(event->pos())) > 0) { |
|
|
|
|
|
|
|
//qDebug("Name: %s", itemAt(event->pos())->text().toLocal8Bit().data());
|
|
|
|
|
|
|
|
event->acceptProposedAction(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
event->ignore(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void dropEvent(QDropEvent *event) { |
|
|
|
|
|
|
|
qDebug("Drop Event in labels list"); |
|
|
|
|
|
|
|
if(itemAt(event->pos())) { |
|
|
|
|
|
|
|
emit torrentDropped(row(itemAt(event->pos()))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
event->ignore(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class TransferListFiltersWidget: public QFrame { |
|
|
|
class TransferListFiltersWidget: public QFrame { |
|
|
|
Q_OBJECT |
|
|
|
Q_OBJECT |
|
|
|
|
|
|
|
|
|
|
@ -50,7 +83,7 @@ private: |
|
|
|
QStringList customLabels; |
|
|
|
QStringList customLabels; |
|
|
|
QList<int> labelCounters; |
|
|
|
QList<int> labelCounters; |
|
|
|
QListWidget* statusFilters; |
|
|
|
QListWidget* statusFilters; |
|
|
|
QListWidget* labelFilters; |
|
|
|
LabelFiltersList* labelFilters; |
|
|
|
QVBoxLayout* vLayout; |
|
|
|
QVBoxLayout* vLayout; |
|
|
|
TransferListWidget *transferList; |
|
|
|
TransferListWidget *transferList; |
|
|
|
int nb_labeled; |
|
|
|
int nb_labeled; |
|
|
@ -60,9 +93,9 @@ public: |
|
|
|
TransferListFiltersWidget(QWidget *parent, TransferListWidget *transferList): QFrame(parent), transferList(transferList), nb_labeled(0), nb_torrents(0) { |
|
|
|
TransferListFiltersWidget(QWidget *parent, TransferListWidget *transferList): QFrame(parent), transferList(transferList), nb_labeled(0), nb_torrents(0) { |
|
|
|
// Construct lists
|
|
|
|
// Construct lists
|
|
|
|
vLayout = new QVBoxLayout(); |
|
|
|
vLayout = new QVBoxLayout(); |
|
|
|
statusFilters = new QListWidget(); |
|
|
|
statusFilters = new QListWidget(this); |
|
|
|
vLayout->addWidget(statusFilters); |
|
|
|
vLayout->addWidget(statusFilters); |
|
|
|
labelFilters = new QListWidget(); |
|
|
|
labelFilters = new LabelFiltersList(this); |
|
|
|
vLayout->addWidget(labelFilters); |
|
|
|
vLayout->addWidget(labelFilters); |
|
|
|
setLayout(vLayout); |
|
|
|
setLayout(vLayout); |
|
|
|
// Limit status filters list height
|
|
|
|
// Limit status filters list height
|
|
|
@ -90,8 +123,10 @@ public: |
|
|
|
connect(statusFilters, SIGNAL(currentRowChanged(int)), transferList, SLOT(applyStatusFilter(int))); |
|
|
|
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(transferList, SIGNAL(torrentStatusUpdate(uint,uint,uint,uint)), this, SLOT(updateTorrentNumbers(uint, uint, uint, uint))); |
|
|
|
connect(labelFilters, SIGNAL(currentRowChanged(int)), this, SLOT(applyLabelFilter(int))); |
|
|
|
connect(labelFilters, SIGNAL(currentRowChanged(int)), this, SLOT(applyLabelFilter(int))); |
|
|
|
|
|
|
|
connect(labelFilters, SIGNAL(torrentDropped(int)), this, SLOT(torrentDropped(int))); |
|
|
|
connect(transferList, SIGNAL(torrentAdded(QModelIndex)), this, SLOT(torrentAdded(QModelIndex))); |
|
|
|
connect(transferList, SIGNAL(torrentAdded(QModelIndex)), this, SLOT(torrentAdded(QModelIndex))); |
|
|
|
connect(transferList, SIGNAL(torrentAboutToBeRemoved(QModelIndex)), this, SLOT(torrentAboutToBeDeleted(QModelIndex))); |
|
|
|
connect(transferList, SIGNAL(torrentAboutToBeRemoved(QModelIndex)), this, SLOT(torrentAboutToBeDeleted(QModelIndex))); |
|
|
|
|
|
|
|
connect(transferList, SIGNAL(torrentChangedLabel(QString,QString)), this, SLOT(torrentChangedLabel(QString, QString))); |
|
|
|
|
|
|
|
|
|
|
|
// Load settings
|
|
|
|
// Load settings
|
|
|
|
loadSettings(); |
|
|
|
loadSettings(); |
|
|
@ -153,6 +188,16 @@ protected slots: |
|
|
|
statusFilters->item(FILTER_INACTIVE)->setData(Qt::DisplayRole, tr("Inactive")+" ("+QString::number(nb_inactive)+")"); |
|
|
|
statusFilters->item(FILTER_INACTIVE)->setData(Qt::DisplayRole, tr("Inactive")+" ("+QString::number(nb_inactive)+")"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void torrentDropped(int row) { |
|
|
|
|
|
|
|
Q_ASSERT(row > 0); |
|
|
|
|
|
|
|
if(row == 1) { |
|
|
|
|
|
|
|
transferList->setSelectionLabel(""); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
QString label = customLabels.at(row-2); |
|
|
|
|
|
|
|
transferList->setSelectionLabel(label); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void addLabel(QString label) { |
|
|
|
void addLabel(QString label) { |
|
|
|
if(label.trimmed().isEmpty()) return; |
|
|
|
if(label.trimmed().isEmpty()) return; |
|
|
|
if(customLabels.contains(label)) return; |
|
|
|
if(customLabels.contains(label)) return; |
|
|
@ -214,12 +259,14 @@ protected slots: |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void torrentChangedLabel(QString old_label, QString new_label) { |
|
|
|
void torrentChangedLabel(QString old_label, QString new_label) { |
|
|
|
|
|
|
|
qDebug("Torrent label changed from %s to %s", old_label.toLocal8Bit().data(), new_label.toLocal8Bit().data()); |
|
|
|
if(!old_label.isEmpty()) { |
|
|
|
if(!old_label.isEmpty()) { |
|
|
|
int i = customLabels.indexOf(old_label); |
|
|
|
int i = customLabels.indexOf(old_label); |
|
|
|
int new_count = labelCounters[i]-1; |
|
|
|
int new_count = labelCounters[i]-1; |
|
|
|
Q_ASSERT(new_count >= 0); |
|
|
|
Q_ASSERT(new_count >= 0); |
|
|
|
labelCounters.replace(i, new_count); |
|
|
|
labelCounters.replace(i, new_count); |
|
|
|
labelFilters->item(i+2)->setText(old_label + " ("+ QString::number(new_count) +")"); |
|
|
|
labelFilters->item(i+2)->setText(old_label + " ("+ QString::number(new_count) +")"); |
|
|
|
|
|
|
|
--nb_labeled; |
|
|
|
} |
|
|
|
} |
|
|
|
if(!new_label.isEmpty()) { |
|
|
|
if(!new_label.isEmpty()) { |
|
|
|
if(!customLabels.contains(new_label)) |
|
|
|
if(!customLabels.contains(new_label)) |
|
|
@ -228,7 +275,9 @@ protected slots: |
|
|
|
int new_count = labelCounters[i]+1; |
|
|
|
int new_count = labelCounters[i]+1; |
|
|
|
labelCounters.replace(i, new_count); |
|
|
|
labelCounters.replace(i, new_count); |
|
|
|
labelFilters->item(i+2)->setText(new_label + " ("+ QString::number(new_count) +")"); |
|
|
|
labelFilters->item(i+2)->setText(new_label + " ("+ QString::number(new_count) +")"); |
|
|
|
|
|
|
|
++nb_labeled; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
updateStickyLabelCounters(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void torrentAdded(QModelIndex index) { |
|
|
|
void torrentAdded(QModelIndex index) { |
|
|
|