From 60c0049beff9f5508a9e80773a0e65b9942b88cb Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Fri, 20 Jul 2007 13:07:34 +0000 Subject: [PATCH] - Added a popup menu to set priority for multiple files at once --- src/properties.ui | 335 ++++++++++++++++++++++++++++++++--------- src/properties_imp.cpp | 66 +++++++- src/properties_imp.h | 5 + 3 files changed, 336 insertions(+), 70 deletions(-) diff --git a/src/properties.ui b/src/properties.ui index cb3e786fa..072a1b942 100644 --- a/src/properties.ui +++ b/src/properties.ui @@ -13,12 +13,21 @@ Torrent Properties - - 9 - 6 + + 9 + + + 9 + + + 9 + + + 9 + @@ -29,12 +38,21 @@ Main infos - - 9 - 6 + + 9 + + + 9 + + + 9 + + + 9 + @@ -81,28 +99,55 @@ Torrent infos - - 9 - 6 + + 9 + + + 9 + + + 9 + + + 9 + - - 0 - 6 + + 0 + + + 0 + + + 0 + + + 0 + - - 0 - 6 + + 0 + + + 0 + + + 0 + + + 0 + @@ -189,12 +234,21 @@ - - 0 - 6 + + 0 + + + 0 + + + 0 + + + 0 + @@ -276,9 +330,7 @@ - - 5 - 5 + 0 0 @@ -304,28 +356,55 @@ Current session - - 9 - 6 + + 9 + + + 9 + + + 9 + + + 9 + - - 0 - 6 + + 0 + + + 0 + + + 0 + + + 0 + - - 0 - 6 + + 0 + + + 0 + + + 0 + + + 0 + @@ -402,12 +481,21 @@ - - 0 - 6 + + 0 + + + 0 + + + 0 + + + 0 + @@ -481,18 +569,25 @@ Trackers - - 9 - 6 + + 9 + + + 9 + + + 9 + + + 9 + - - 7 - 7 + 0 0 @@ -518,20 +613,38 @@ Tracker - - 9 - 6 + + 9 + + + 9 + + + 9 + + + 9 + - - 0 - 6 + + 0 + + + 0 + + + 0 + + + 0 + @@ -552,18 +665,25 @@ - - 0 - 6 + + 0 + + + 0 + + + 0 + + + 0 + - - 7 - 7 + 0 0 @@ -572,12 +692,21 @@ - - 0 - 6 + + 0 + + + 0 + + + 0 + + + 0 + @@ -648,12 +777,21 @@ - - 0 - 6 + + 0 + + + 0 + + + 0 + + + 0 + @@ -724,12 +862,21 @@ - - 0 - 6 + + 0 + + + 0 + + + 0 + + + 0 + @@ -759,12 +906,21 @@ - - 0 - 6 + + 0 + + + 0 + + + 0 + + + 0 + @@ -827,12 +983,21 @@ Torrent content - - 9 - 6 + + 9 + + + 9 + + + 9 + + + 9 + @@ -859,6 +1024,9 @@ 301 + + Qt::CustomContextMenu + QAbstractItemView::AllEditTriggers @@ -903,12 +1071,21 @@ - - 0 - 6 + + 0 + + + 0 + + + 0 + + + 0 + @@ -945,6 +1122,26 @@ + + + Ignored + + + + + Normal + + + + + Maximum + + + + + High + + diff --git a/src/properties_imp.cpp b/src/properties_imp.cpp index 4126def8a..b03bc12da 100644 --- a/src/properties_imp.cpp +++ b/src/properties_imp.cpp @@ -24,6 +24,7 @@ #include "PropListDelegate.h" #include #include +#include // Constructor properties::properties(QWidget *parent, bittorrent *BTSession, torrent_handle &h, QStringList trackerErrors): QDialog(parent), h(h){ @@ -47,10 +48,15 @@ properties::properties(QWidget *parent, bittorrent *BTSession, torrent_handle &h PropDelegate = new PropListDelegate(0, &changedFilteredfiles); filesList->setItemDelegate(PropDelegate); connect(filesList, SIGNAL(clicked(const QModelIndex&)), filesList, SLOT(edit(const QModelIndex&))); + connect(filesList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayFilesListMenu(const QPoint&))); connect(addTracker_button, SIGNAL(clicked()), this, SLOT(askForTracker())); connect(removeTracker_button, SIGNAL(clicked()), this, SLOT(deleteSelectedTrackers())); connect(riseTracker_button, SIGNAL(clicked()), this, SLOT(riseSelectedTracker())); connect(lowerTracker_button, SIGNAL(clicked()), this, SLOT(lowerSelectedTracker())); + connect(actionIgnored, SIGNAL(triggered()), this, SLOT(ignoreSelection())); + connect(actionNormal, SIGNAL(triggered()), this, SLOT(normalSelection())); + connect(actionHigh, SIGNAL(triggered()), this, SLOT(highSelection())); + connect(actionMaximum, SIGNAL(triggered()), this, SLOT(maximumSelection())); // get Infos from torrent handle fileHash = QString(misc::toString(h.info_hash()).c_str()); torrent_status torrentStatus = h.status(); @@ -58,7 +64,10 @@ properties::properties(QWidget *parent, bittorrent *BTSession, torrent_handle &h fileName->setText(torrentInfo.name().c_str()); // Torrent Infos save_path->setText(QString(h.save_path().string().c_str())); - creator->setText(QString(torrentInfo.creator().c_str())); + QString author = QString(torrentInfo.creator().c_str()).trimmed(); + if(author.isEmpty()) + author = tr("Unknown"); + creator->setText(author); hash_lbl->setText(fileHash); comment_txt->setText(QString(torrentInfo.comment().c_str())); //Trackers @@ -154,6 +163,61 @@ void properties::loadPiecesPriorities(){ } } +void properties::displayFilesListMenu(const QPoint& pos){ + QMenu myFilesLlistMenu(this); + QModelIndex index; + // Enable/disable pause/start action given the DL state + QModelIndexList selectedIndexes = filesList->selectionModel()->selectedIndexes(); + myFilesLlistMenu.setTitle(tr("Priority")); + myFilesLlistMenu.addAction(actionIgnored); + myFilesLlistMenu.addAction(actionNormal); + myFilesLlistMenu.addAction(actionHigh); + myFilesLlistMenu.addAction(actionMaximum); + // Call menu + // XXX: why mapToGlobal() is not enough? + myFilesLlistMenu.exec(mapToGlobal(pos)+QPoint(22,95)); +} + +void properties::ignoreSelection(){ + QModelIndexList selectedIndexes = filesList->selectionModel()->selectedIndexes(); + QModelIndex index; + foreach(index, selectedIndexes){ + if(index.column() == PRIORITY){ + PropListModel->setData(index, QVariant(IGNORED)); + } + } +} + +void properties::normalSelection(){ + QModelIndexList selectedIndexes = filesList->selectionModel()->selectedIndexes(); + QModelIndex index; + foreach(index, selectedIndexes){ + if(index.column() == PRIORITY){ + PropListModel->setData(index, QVariant(NORMAL)); + } + } +} + +void properties::highSelection(){ + QModelIndexList selectedIndexes = filesList->selectionModel()->selectedIndexes(); + QModelIndex index; + foreach(index, selectedIndexes){ + if(index.column() == PRIORITY){ + PropListModel->setData(index, QVariant(HIGH)); + } + } +} + +void properties::maximumSelection(){ + QModelIndexList selectedIndexes = filesList->selectionModel()->selectedIndexes(); + QModelIndex index; + foreach(index, selectedIndexes){ + if(index.column() == PRIORITY){ + PropListModel->setData(index, QVariant(MAXIMUM)); + } + } +} + void properties::loadTrackers(){ //Trackers std::vector trackers = h.trackers(); diff --git a/src/properties_imp.h b/src/properties_imp.h index debfcaa5d..5a5d7f166 100644 --- a/src/properties_imp.h +++ b/src/properties_imp.h @@ -57,6 +57,11 @@ class properties : public QDialog, private Ui::properties{ void deleteSelectedTrackers(); void lowerSelectedTracker(); void riseSelectedTracker(); + void displayFilesListMenu(const QPoint& pos); + void ignoreSelection(); + void normalSelection(); + void highSelection(); + void maximumSelection(); signals: void filteredFilesChanged(const QString& fileHash);