diff --git a/src/eventmanager.cpp b/src/eventmanager.cpp index 3406d9625..8764dcb60 100644 --- a/src/eventmanager.cpp +++ b/src/eventmanager.cpp @@ -111,23 +111,7 @@ QList EventManager::getPropFilesInfo(QString hash) const { } file["size"] = misc::friendlyUnit((double)fi->size); file["progress"] = fp[i]/(double)fi->size; - switch(priorities[i]) { - case IGNORED: - file["priority"] = tr("Ignored"); - break; - case NORMAL: - file["priority"] = tr("Normal", "Normal (priority)"); - break; - case HIGH: - file["priority"] = tr("High", "High (priority)"); - break; - case MAXIMUM: - file["priority"] = tr("Maximum", "Maximum (priority)"); - break; - default: - qDebug("Unhandled priority, setting NORMAL, priority was %d", priorities[i]); - file["priority"] = tr("Normal", "Normal (priority)"); - } + file["priority"] = priorities[i]; files << file; ++i; } diff --git a/src/httpconnection.cpp b/src/httpconnection.cpp index 8b56c76e1..8d54f5216 100644 --- a/src/httpconnection.cpp +++ b/src/httpconnection.cpp @@ -310,6 +310,15 @@ void HttpConnection::respondCommand(QString command) emit resumeTorrent(parser.post("hash")); return; } + if(command == "setFilePrio") { + QString hash = parser.post("hash"); + int file_id = parser.post("id").toInt(); + int priority = parser.post("priority").toInt(); + QTorrentHandle h = BTSession->getTorrentHandle(hash); + if(h.is_valid()) { + h.file_priority(file_id, priority); + } + } if(command == "pause") { emit pauseTorrent(parser.post("hash")); return; diff --git a/src/propertieswidget.cpp b/src/propertieswidget.cpp index c87538dc8..123ad5515 100644 --- a/src/propertieswidget.cpp +++ b/src/propertieswidget.cpp @@ -74,7 +74,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, GUI* main_window, TransferLi // Set Properties list model PropListModel = new TorrentFilesModel(); filesList->setModel(PropListModel); - PropDelegate = new PropListDelegate(0); + PropDelegate = new PropListDelegate(this); filesList->setItemDelegate(PropDelegate); // QActions @@ -229,7 +229,6 @@ void PropertiesWidget::loadTorrentInfos(QTorrentHandle &_h) { // List files in torrent PropListModel->clear(); PropListModel->setupModelData(h.get_torrent_info()); - PropListModel->updateFilesPriorities(h.file_priorities()); // Expand first item if possible filesList->expand(PropListModel->index(0, 0)); } catch(invalid_handle e) { @@ -359,6 +358,7 @@ void PropertiesWidget::loadDynamicData() { std::vector fp; h.file_progress(fp); PropListModel->updateFilesProgress(fp); + PropListModel->updateFilesPriorities(h.file_priorities()); } } catch(invalid_handle e) {} } @@ -550,13 +550,17 @@ void PropertiesWidget::deleteSelectedUrlSeeds(){ } } -bool PropertiesWidget::savePiecesPriorities() { +bool PropertiesWidget::applyPriorities() { qDebug("Saving pieces priorities"); std::vector priorities = PropListModel->getFilesPriorities(h.get_torrent_info().num_files()); bool first_last_piece_first = false; + // Save first/last piece first option state if(h.first_last_piece_first()) first_last_piece_first = true; + // Prioritize the files + qDebug("prioritize files: %d", priorities[0]); h.prioritize_files(priorities); + // Restore first/last piece first option if necessary if(first_last_piece_first) h.prioritize_first_last_piece(true); return true; @@ -592,7 +596,6 @@ void PropertiesWidget::on_changeSavePathButton_clicked() { void PropertiesWidget::filteredFilesChanged() { if(h.is_valid()) { - savePiecesPriorities(); - transferList->updateTorrentSizeAndProgress(h.hash()); + applyPriorities(); } } diff --git a/src/propertieswidget.h b/src/propertieswidget.h index 8056dd79f..cbbab14f3 100644 --- a/src/propertieswidget.h +++ b/src/propertieswidget.h @@ -76,7 +76,7 @@ private: protected: QPushButton* getButtonFromIndex(int index); - bool savePiecesPriorities(); + bool applyPriorities(); protected slots: void loadTorrentInfos(QTorrentHandle &h); diff --git a/src/proplistdelegate.h b/src/proplistdelegate.h index ca165c134..dd60caed0 100644 --- a/src/proplistdelegate.h +++ b/src/proplistdelegate.h @@ -41,6 +41,7 @@ #include #include #include "misc.h" +#include "propertieswidget.h" // Defines for properties list columns enum PropColumn {NAME, SIZE, PROGRESS, PRIORITY}; @@ -49,11 +50,14 @@ enum PropPriority {IGNORED=0, NORMAL=1, HIGH=2, MAXIMUM=7}; class PropListDelegate: public QItemDelegate { Q_OBJECT +private: + PropertiesWidget *properties; + signals: void filteredFilesChanged() const; public: - PropListDelegate(QObject *parent=0) : QItemDelegate(parent){ + PropListDelegate(PropertiesWidget* properties=0, QObject *parent=0) : QItemDelegate(parent), properties(properties){ } ~PropListDelegate(){} @@ -116,6 +120,10 @@ public: QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex & index) const { qDebug("CreateEditor called"); if(index.column() != PRIORITY) return 0; + if(properties) { + QTorrentHandle h = properties->getCurrentTorrent(); + if(!h.is_valid() || h.is_seed()) return 0; + } QComboBox* editor = new QComboBox(parent); editor->setFocusPolicy(Qt::StrongFocus); editor->addItem(tr("Ignored")); diff --git a/src/qtorrenthandle.cpp b/src/qtorrenthandle.cpp index 58699ae96..c4e6aabab 100644 --- a/src/qtorrenthandle.cpp +++ b/src/qtorrenthandle.cpp @@ -470,7 +470,9 @@ void QTorrentHandle::set_max_connections(int val) { } void QTorrentHandle::prioritize_files(std::vector v) { + // Does not do anything for seeding torrents Q_ASSERT(h.is_valid()); + Q_ASSERT(v.size() == (unsigned int)h.get_torrent_info().num_files()); h.prioritize_files(v); } @@ -528,6 +530,7 @@ void QTorrentHandle::move_storage(QString new_path) const { void QTorrentHandle::file_priority(int index, int priority) const { Q_ASSERT(h.is_valid()); + if(is_seed()) return; h.file_priority(index, priority); } diff --git a/src/torrentfilesmodel.h b/src/torrentfilesmodel.h index c73621f25..c161215f0 100644 --- a/src/torrentfilesmodel.h +++ b/src/torrentfilesmodel.h @@ -279,6 +279,7 @@ public: void updateFilesPriorities(std::vector fprio) { for(unsigned int i=0; isetPriority(fprio[i]); } emit layoutChanged(); @@ -287,6 +288,7 @@ public: std::vector getFilesPriorities(unsigned int nbFiles) const { std::vector prio; for(unsigned int i=0; igetPriority()); prio.push_back(files_index[i]->getPriority()); } return prio; diff --git a/src/transferlistwidget.cpp b/src/transferlistwidget.cpp index c83dff601..def2e6a99 100644 --- a/src/transferlistwidget.cpp +++ b/src/transferlistwidget.cpp @@ -259,6 +259,23 @@ int TransferListWidget::updateTorrent(int row) { return s; } try { + // Connected_seeds*100000+total_seeds*10 (if total_seeds is available) + // Connected_seeds*100000+1 (if total_seeds is unavailable) + qulonglong seeds = h.num_seeds()*1000000; + if(h.num_complete() >= h.num_seeds()) + seeds += h.num_complete()*10; + else + seeds += 1; + listModel->setData(listModel->index(row, TR_SEEDS), QVariant(seeds)); + qulonglong peers = (h.num_peers()-h.num_seeds())*1000000; + if(h.num_incomplete() >= (h.num_peers()-h.num_seeds())) + peers += h.num_incomplete()*10; + else + peers += 1; + listModel->setData(listModel->index(row, TR_PEERS), QVariant(peers)); + // Update torrent size. It changes when files are filtered from torrent properties + // or Web UI + listModel->setData(listModel->index(row, TR_SIZE), QVariant((qlonglong)h.actual_size())); // Queueing code if(!h.is_seed() && BTSession->isQueueingEnabled()) { listModel->setData(listModel->index(row, TR_PRIORITY), QVariant((int)h.queue_position())); @@ -293,20 +310,7 @@ int TransferListWidget::updateTorrent(int row) { return s; } } - // Connected_seeds*100000+total_seeds*10 (if total_seeds is available) - // Connected_seeds*100000+1 (if total_seeds is unavailable) - qulonglong seeds = h.num_seeds()*1000000; - if(h.num_complete() >= h.num_seeds()) - seeds += h.num_complete()*10; - else - seeds += 1; - listModel->setData(listModel->index(row, TR_SEEDS), QVariant(seeds)); - qulonglong peers = (h.num_peers()-h.num_seeds())*1000000; - if(h.num_incomplete() >= (h.num_peers()-h.num_seeds())) - peers += h.num_incomplete()*10; - else - peers += 1; - listModel->setData(listModel->index(row, TR_PEERS), QVariant(peers)); + if(h.is_paused()) { if(h.is_seed()) return STATE_PAUSED_UP; @@ -1098,10 +1102,3 @@ void TransferListWidget::applyFilter(int f) { selectionModel()->setCurrentIndex(proxyModel->index(0, TR_NAME), QItemSelectionModel::SelectCurrent|QItemSelectionModel::Rows); } -void TransferListWidget::updateTorrentSizeAndProgress(QString hash) { - int row = getRowFromHash(hash); - Q_ASSERT(row != -1); - QTorrentHandle h = BTSession->getTorrentHandle(hash); - listModel->setData(listModel->index(row, TR_SIZE), QVariant((qlonglong)h.actual_size())); - listModel->setData(listModel->index(row, TR_PROGRESS), QVariant((double)h.progress())); -} diff --git a/src/transferlistwidget.h b/src/transferlistwidget.h index 69547f0c9..9442dfd42 100644 --- a/src/transferlistwidget.h +++ b/src/transferlistwidget.h @@ -108,7 +108,6 @@ public slots: void hidePriorityColumn(bool hide); void displayDLHoSMenu(const QPoint&); void applyFilter(int f); - void updateTorrentSizeAndProgress(QString hash); signals: void currentTorrentChanged(QTorrentHandle &h); diff --git a/src/webui/prop-files.html b/src/webui/prop-files.html index eaee0538f..840e206f1 100644 --- a/src/webui/prop-files.html +++ b/src/webui/prop-files.html @@ -13,6 +13,49 @@