Browse Source

Merge pull request #2467 from buinsky/master

Some canges in WebUI
adaptive-webui-19844
sledgehammer999 10 years ago
parent
commit
0058abeefa
  1. 2
      src/gui/torrentfilterenum.h
  2. 736
      src/gui/transferlistfilterswidget.cpp
  3. 89
      src/gui/transferlistfilterswidget.h
  4. 51
      src/webui/btjson.cpp
  5. 1
      src/webui/btjson.h
  6. 22
      src/webui/jsonutils.h
  7. 12
      src/webui/qtorrentfilter.cpp
  8. 2
      src/webui/qtorrentfilter.h
  9. 80
      src/webui/webapplication.cpp
  10. 9
      src/webui/webapplication.h
  11. 1
      src/webui/www/private/index.html
  12. 10
      src/webui/www/public/downloadlimit.html
  13. 1
      src/webui/www/public/filters.html
  14. 70
      src/webui/www/public/scripts/client.js
  15. 11
      src/webui/www/public/scripts/contextmenu.js
  16. 15
      src/webui/www/public/scripts/dynamicTable.js
  17. 4
      src/webui/www/public/scripts/misc.js
  18. 29
      src/webui/www/public/scripts/mocha-init.js
  19. 44
      src/webui/www/public/scripts/parametrics.js
  20. 4
      src/webui/www/public/scripts/progressbar.js
  21. 3
      src/webui/www/public/transferlist.html
  22. 10
      src/webui/www/public/uploadlimit.html

2
src/gui/torrentfilterenum.h

@ -32,6 +32,6 @@
#define TORRENTFILTERENUM_H #define TORRENTFILTERENUM_H
namespace TorrentFilter { namespace TorrentFilter {
enum TorrentFilter {ALL, DOWNLOADING, COMPLETED, PAUSED, RESUMED, ACTIVE, INACTIVE}; enum TorrentFilter {ALL, DOWNLOADING, COMPLETED, RESUMED, PAUSED, ACTIVE, INACTIVE};
} }
#endif // TORRENTFILTERENUM_H #endif // TORRENTFILTERENUM_H

736
src/gui/transferlistfilterswidget.cpp

@ -48,332 +48,353 @@
#include "autoexpandabledialog.h" #include "autoexpandabledialog.h"
#include "torrentfilterenum.h" #include "torrentfilterenum.h"
LabelFiltersList::LabelFiltersList(QWidget *parent): QListWidget(parent) { LabelFiltersList::LabelFiltersList(QWidget *parent): QListWidget(parent)
itemHover = 0; {
// Accept drop itemHover = 0;
setAcceptDrops(true); // Accept drop
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); setAcceptDrops(true);
setStyleSheet("QListWidget { background: transparent; border: 0 }"); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
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
} }
void LabelFiltersList::addItem(QListWidgetItem *it) { void LabelFiltersList::addItem(QListWidgetItem *it)
Q_ASSERT(count() >= 2); {
for (int i=2; i<count(); ++i) { Q_ASSERT(count() >= 2);
if (item(i)->text().localeAwareCompare(it->text()) >= 0) { for (int i = 2; i<count(); ++i) {
insertItem(i, it); if (item(i)->text().localeAwareCompare(it->text()) >= 0) {
return; insertItem(i, it);
return;
}
} }
} QListWidget::addItem(it);
QListWidget::addItem(it);
} }
QString LabelFiltersList::labelFromRow(int row) const { QString LabelFiltersList::labelFromRow(int row) const
Q_ASSERT(row > 1); {
const QString &label = item(row)->text(); Q_ASSERT(row > 1);
QStringList parts = label.split(" "); const QString &label = item(row)->text();
Q_ASSERT(parts.size() >= 2); QStringList parts = label.split(" ");
parts.removeLast(); // Remove trailing number Q_ASSERT(parts.size() >= 2);
return parts.join(" "); parts.removeLast(); // Remove trailing number
return parts.join(" ");
} }
int LabelFiltersList::rowFromLabel(QString label) const { int LabelFiltersList::rowFromLabel(QString label) const
Q_ASSERT(!label.isEmpty()); {
for (int i=2; i<count(); ++i) { Q_ASSERT(!label.isEmpty());
if (label == labelFromRow(i)) return i; for (int i = 2; i<count(); ++i)
} if (label == labelFromRow(i)) return i;
return -1; return -1;
} }
void LabelFiltersList::dragMoveEvent(QDragMoveEvent *event) { void LabelFiltersList::dragMoveEvent(QDragMoveEvent *event)
if (itemAt(event->pos()) && row(itemAt(event->pos())) > 0) { {
if (itemHover) { if (itemAt(event->pos()) && row(itemAt(event->pos())) > 0) {
if (itemHover != itemAt(event->pos())) { if (itemHover) {
setItemHover(false); if (itemHover != itemAt(event->pos())) {
itemHover = itemAt(event->pos()); setItemHover(false);
setItemHover(true); itemHover = itemAt(event->pos());
} setItemHover(true);
} else { }
itemHover = itemAt(event->pos()); }
setItemHover(true); else {
itemHover = itemAt(event->pos());
setItemHover(true);
}
event->acceptProposedAction();
}
else {
if (itemHover)
setItemHover(false);
event->ignore();
} }
event->acceptProposedAction();
} else {
if (itemHover)
setItemHover(false);
event->ignore();
}
} }
void LabelFiltersList::dropEvent(QDropEvent *event) { void LabelFiltersList::dropEvent(QDropEvent *event)
qDebug("Drop Event in labels list"); {
if (itemAt(event->pos())) { qDebug("Drop Event in labels list");
emit torrentDropped(row(itemAt(event->pos()))); if (itemAt(event->pos()))
} emit torrentDropped(row(itemAt(event->pos())));
event->ignore(); event->ignore();
setItemHover(false); setItemHover(false);
// Select current item again // Select current item again
currentItem()->setSelected(true); currentItem()->setSelected(true);
} }
void LabelFiltersList::dragLeaveEvent(QDragLeaveEvent*) { void LabelFiltersList::dragLeaveEvent(QDragLeaveEvent*)
if (itemHover) {
setItemHover(false); if (itemHover)
// Select current item again setItemHover(false);
currentItem()->setSelected(true); // Select current item again
currentItem()->setSelected(true);
} }
void LabelFiltersList::setItemHover(bool hover) { void LabelFiltersList::setItemHover(bool hover)
Q_ASSERT(itemHover); {
if (hover) { Q_ASSERT(itemHover);
itemHover->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("folder-documents.png")); if (hover) {
itemHover->setSelected(true); itemHover->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("folder-documents.png"));
//setCurrentItem(itemHover); itemHover->setSelected(true);
} else { //setCurrentItem(itemHover);
itemHover->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("inode-directory.png")); }
//itemHover->setSelected(false); else {
itemHover = 0; itemHover->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("inode-directory.png"));
} //itemHover->setSelected(false);
itemHover = 0;
}
} }
StatusFiltersWidget::StatusFiltersWidget(QWidget *parent) : QListWidget(parent), m_shown(false) { StatusFiltersWidget::StatusFiltersWidget(QWidget *parent): QListWidget(parent), m_shown(false)
setUniformItemSizes(true); {
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setUniformItemSizes(true);
// Height is fixed (sizeHint().height() is used) setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); // Height is fixed (sizeHint().height() is used)
setStyleSheet("QListWidget { background: transparent; border: 0 }"); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
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
} }
QSize StatusFiltersWidget::sizeHint() const { QSize StatusFiltersWidget::sizeHint() const
QSize size = QListWidget::sizeHint(); {
// Height should be exactly the height of the content QSize size = QListWidget::sizeHint();
size.setHeight(contentsSize().height() + 2 * frameWidth()+6); // Height should be exactly the height of the content
return size; size.setHeight(contentsSize().height() + 2 * frameWidth() + 6);
return size;
} }
TransferListFiltersWidget::TransferListFiltersWidget(QWidget *parent, TransferListWidget *transferList): QFrame(parent), transferList(transferList), nb_labeled(0), nb_torrents(0) { TransferListFiltersWidget::TransferListFiltersWidget(QWidget *parent, TransferListWidget *transferList): QFrame(parent), transferList(transferList), nb_labeled(0), nb_torrents(0)
// Construct lists {
vLayout = new QVBoxLayout(); // Construct lists
vLayout->setContentsMargins(0, 4, 0, 0); vLayout = new QVBoxLayout();
QFont font; vLayout->setContentsMargins(0, 4, 0, 0);
font.setBold(true); QFont font;
font.setCapitalization(QFont::SmallCaps); font.setBold(true);
QLabel *torrentsLabel = new QLabel(tr("Torrents")); font.setCapitalization(QFont::SmallCaps);
torrentsLabel->setIndent(2); QLabel *torrentsLabel = new QLabel(tr("Torrents"));
torrentsLabel->setFont(font); torrentsLabel->setIndent(2);
vLayout->addWidget(torrentsLabel); torrentsLabel->setFont(font);
statusFilters = new StatusFiltersWidget(this); vLayout->addWidget(torrentsLabel);
vLayout->addWidget(statusFilters); statusFilters = new StatusFiltersWidget(this);
QLabel *labelsLabel = new QLabel(tr("Labels")); vLayout->addWidget(statusFilters);
labelsLabel->setIndent(2); QLabel *labelsLabel = new QLabel(tr("Labels"));
labelsLabel->setFont(font); labelsLabel->setIndent(2);
vLayout->addWidget(labelsLabel); labelsLabel->setFont(font);
labelFilters = new LabelFiltersList(this); vLayout->addWidget(labelsLabel);
vLayout->addWidget(labelFilters); labelFilters = new LabelFiltersList(this);
setLayout(vLayout); vLayout->addWidget(labelFilters);
labelFilters->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setLayout(vLayout);
statusFilters->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); labelFilters->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
statusFilters->setSpacing(0); statusFilters->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setContentsMargins(0,0,0,0); statusFilters->setSpacing(0);
vLayout->setSpacing(2); setContentsMargins(0,0,0,0);
// Add status filters vLayout->setSpacing(2);
QListWidgetItem *all = new QListWidgetItem(statusFilters); // Add status filters
all->setData(Qt::DisplayRole, QVariant(tr("All") + " (0)")); QListWidgetItem *all = new QListWidgetItem(statusFilters);
all->setData(Qt::DecorationRole, QIcon(":/icons/skin/filterall.png")); all->setData(Qt::DisplayRole, QVariant(tr("All") + " (0)"));
QListWidgetItem *downloading = new QListWidgetItem(statusFilters); all->setData(Qt::DecorationRole, QIcon(":/Icons/skin/filterall.png"));
downloading->setData(Qt::DisplayRole, QVariant(tr("Downloading") + " (0)")); QListWidgetItem *downloading = new QListWidgetItem(statusFilters);
downloading->setData(Qt::DecorationRole, QIcon(":/icons/skin/downloading.png")); downloading->setData(Qt::DisplayRole, QVariant(tr("Downloading") + " (0)"));
QListWidgetItem *completed = new QListWidgetItem(statusFilters); downloading->setData(Qt::DecorationRole, QIcon(":/Icons/skin/downloading.png"));
completed->setData(Qt::DisplayRole, QVariant(tr("Completed") + " (0)")); QListWidgetItem *completed = new QListWidgetItem(statusFilters);
completed->setData(Qt::DecorationRole, QIcon(":/icons/skin/uploading.png")); completed->setData(Qt::DisplayRole, QVariant(tr("Completed") + " (0)"));
QListWidgetItem *paused = new QListWidgetItem(statusFilters); completed->setData(Qt::DecorationRole, QIcon(":/Icons/skin/uploading.png"));
paused->setData(Qt::DisplayRole, QVariant(tr("Paused") + " (0)")); QListWidgetItem *resumed = new QListWidgetItem(statusFilters);
paused->setData(Qt::DecorationRole, QIcon(":/icons/skin/paused.png")); resumed->setData(Qt::DisplayRole, QVariant(tr("Resumed") + " (0)"));
QListWidgetItem *resumed = new QListWidgetItem(statusFilters); resumed->setData(Qt::DecorationRole, QIcon(":/Icons/skin/resumed.png"));
resumed->setData(Qt::DisplayRole, QVariant(tr("Resumed") + " (0)")); QListWidgetItem *paused = new QListWidgetItem(statusFilters);
resumed->setData(Qt::DecorationRole, QIcon(":/icons/skin/resumed.png")); paused->setData(Qt::DisplayRole, QVariant(tr("Paused") + " (0)"));
QListWidgetItem *active = new QListWidgetItem(statusFilters); paused->setData(Qt::DecorationRole, QIcon(":/Icons/skin/paused.png"));
active->setData(Qt::DisplayRole, QVariant(tr("Active") + " (0)")); QListWidgetItem *active = new QListWidgetItem(statusFilters);
active->setData(Qt::DecorationRole, QIcon(":/icons/skin/filteractive.png")); active->setData(Qt::DisplayRole, QVariant(tr("Active") + " (0)"));
QListWidgetItem *inactive = new QListWidgetItem(statusFilters); active->setData(Qt::DecorationRole, QIcon(":/Icons/skin/filteractive.png"));
inactive->setData(Qt::DisplayRole, QVariant(tr("Inactive") + " (0)")); QListWidgetItem *inactive = new QListWidgetItem(statusFilters);
inactive->setData(Qt::DecorationRole, QIcon(":/icons/skin/filterinactive.png")); 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))); // SIGNAL/SLOT
connect(transferList->getSourceModel(), SIGNAL(modelRefreshed()), SLOT(updateTorrentNumbers())); connect(statusFilters, SIGNAL(currentRowChanged(int)), transferList, SLOT(applyStatusFilter(int)));
connect(transferList->getSourceModel(), SIGNAL(torrentAdded(TorrentModelItem*)), SLOT(handleNewTorrent(TorrentModelItem*))); connect(transferList->getSourceModel(), SIGNAL(modelRefreshed()), SLOT(updateTorrentNumbers()));
connect(labelFilters, SIGNAL(currentRowChanged(int)), this, SLOT(applyLabelFilter(int))); connect(transferList->getSourceModel(), SIGNAL(torrentAdded(TorrentModelItem*)), SLOT(handleNewTorrent(TorrentModelItem*)));
connect(labelFilters, SIGNAL(torrentDropped(int)), this, SLOT(torrentDropped(int))); connect(labelFilters, SIGNAL(currentRowChanged(int)), this, SLOT(applyLabelFilter(int)));
connect(transferList->getSourceModel(), SIGNAL(torrentAboutToBeRemoved(TorrentModelItem*)), SLOT(torrentAboutToBeDeleted(TorrentModelItem*))); connect(labelFilters, SIGNAL(torrentDropped(int)), this, SLOT(torrentDropped(int)));
connect(transferList->getSourceModel(), SIGNAL(torrentChangedLabel(TorrentModelItem*,QString,QString)), SLOT(torrentChangedLabel(TorrentModelItem*, QString, QString))); 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); // Add Label filters
allLabels->setData(Qt::DisplayRole, QVariant(tr("All labels") + " (0)")); QListWidgetItem *allLabels = new QListWidgetItem(labelFilters);
allLabels->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("inode-directory")); allLabels->setData(Qt::DisplayRole, QVariant(tr("All labels") + " (0)"));
QListWidgetItem *noLabel = new QListWidgetItem(labelFilters); allLabels->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("inode-directory"));
noLabel->setData(Qt::DisplayRole, QVariant(tr("Unlabeled") + " (0)")); QListWidgetItem *noLabel = new QListWidgetItem(labelFilters);
noLabel->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("inode-directory")); noLabel->setData(Qt::DisplayRole, QVariant(tr("Unlabeled") + " (0)"));
noLabel->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("inode-directory"));
// Load settings
loadSettings(); // Load settings
loadSettings();
labelFilters->setCurrentRow(0);
//labelFilters->selectionModel()->select(labelFilters->model()->index(0,0), QItemSelectionModel::Select); labelFilters->setCurrentRow(0);
//labelFilters->selectionModel()->select(labelFilters->model()->index(0,0), QItemSelectionModel::Select);
// Label menu
labelFilters->setContextMenuPolicy(Qt::CustomContextMenu); // Label menu
connect(labelFilters, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showLabelMenu(QPoint))); labelFilters->setContextMenuPolicy(Qt::CustomContextMenu);
connect(labelFilters, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showLabelMenu(QPoint)));
} }
TransferListFiltersWidget::~TransferListFiltersWidget() { TransferListFiltersWidget::~TransferListFiltersWidget()
saveSettings(); {
delete statusFilters; saveSettings();
delete labelFilters; delete statusFilters;
delete vLayout; delete labelFilters;
delete vLayout;
} }
StatusFiltersWidget* TransferListFiltersWidget::getStatusFilters() const { StatusFiltersWidget* TransferListFiltersWidget::getStatusFilters() const
return statusFilters; {
return statusFilters;
} }
void TransferListFiltersWidget::saveSettings() const { void TransferListFiltersWidget::saveSettings() const
Preferences* const pref = Preferences::instance(); {
pref->setTransSelFilter(statusFilters->currentRow()); Preferences* const pref = Preferences::instance();
pref->setTorrentLabels(customLabels.keys()); pref->setTransSelFilter(statusFilters->currentRow());
pref->setTorrentLabels(customLabels.keys());
} }
void TransferListFiltersWidget::loadSettings() { void TransferListFiltersWidget::loadSettings()
statusFilters->setCurrentRow(Preferences::instance()->getTransSelFilter()); {
const QStringList label_list = Preferences::instance()->getTorrentLabels(); statusFilters->setCurrentRow(Preferences::instance()->getTransSelFilter());
foreach (const QString &label, label_list) { const QStringList label_list = Preferences::instance()->getTorrentLabels();
customLabels.insert(label, 0); foreach (const QString &label, label_list) {
qDebug("Creating label QListWidgetItem: %s", qPrintable(label)); customLabels.insert(label, 0);
QListWidgetItem *newLabel = new QListWidgetItem(); qDebug("Creating label QListWidgetItem: %s", qPrintable(label));
newLabel->setText(label + " (0)"); QListWidgetItem *newLabel = new QListWidgetItem();
newLabel->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("inode-directory")); newLabel->setText(label + " (0)");
labelFilters->addItem(newLabel); newLabel->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("inode-directory"));
} labelFilters->addItem(newLabel);
}
} }
void TransferListFiltersWidget::updateTorrentNumbers() { 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)+")")); const TorrentStatusReport report = transferList->getSourceModel()->getTorrentStatusReport();
statusFilters->item(TorrentFilter::DOWNLOADING)->setData(Qt::DisplayRole, QVariant(tr("Downloading")+" ("+QString::number(report.nb_downloading)+")")); statusFilters->item(TorrentFilter::ALL)->setData(Qt::DisplayRole, QVariant(tr("All") + " (" + QString::number(report.nb_active + report.nb_inactive) + ")"));
statusFilters->item(TorrentFilter::COMPLETED)->setData(Qt::DisplayRole, QVariant(tr("Completed")+" ("+QString::number(report.nb_seeding)+")")); statusFilters->item(TorrentFilter::DOWNLOADING)->setData(Qt::DisplayRole, QVariant(tr("Downloading") + " (" + QString::number(report.nb_downloading) + ")"));
statusFilters->item(TorrentFilter::PAUSED)->setData(Qt::DisplayRole, QVariant(tr("Paused")+" ("+QString::number(report.nb_paused)+")")); statusFilters->item(TorrentFilter::COMPLETED)->setData(Qt::DisplayRole, QVariant(tr("Completed") + " (" + QString::number(report.nb_seeding) + ")"));
statusFilters->item(TorrentFilter::RESUMED)->setData(Qt::DisplayRole, QVariant(tr("Resumed")+" ("+QString::number(report.nb_active+report.nb_inactive-report.nb_paused)+")")); statusFilters->item(TorrentFilter::PAUSED)->setData(Qt::DisplayRole, QVariant(tr("Paused") + " (" + QString::number(report.nb_paused) + ")"));
statusFilters->item(TorrentFilter::ACTIVE)->setData(Qt::DisplayRole, QVariant(tr("Active")+" ("+QString::number(report.nb_active)+")")); statusFilters->item(TorrentFilter::RESUMED)->setData(Qt::DisplayRole, QVariant(tr("Resumed") + " (" + QString::number(report.nb_active + report.nb_inactive - report.nb_paused) + ")"));
statusFilters->item(TorrentFilter::INACTIVE)->setData(Qt::DisplayRole, QVariant(tr("Inactive")+" ("+QString::number(report.nb_inactive)+")")); 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::torrentDropped(int row) { void TransferListFiltersWidget::torrentDropped(int row)
Q_ASSERT(row > 0); {
if (row == 1) { Q_ASSERT(row > 0);
transferList->setSelectionLabel(""); if (row == 1)
} else { transferList->setSelectionLabel("");
transferList->setSelectionLabel(labelFilters->labelFromRow(row)); else
} transferList->setSelectionLabel(labelFilters->labelFromRow(row));
} }
void TransferListFiltersWidget::addLabel(QString& label) { void TransferListFiltersWidget::addLabel(QString& label)
label = fsutils::toValidFileSystemName(label.trimmed()); {
if (label.isEmpty() || customLabels.contains(label)) return; label = fsutils::toValidFileSystemName(label.trimmed());
QListWidgetItem *newLabel = new QListWidgetItem(); if (label.isEmpty() || customLabels.contains(label)) return;
newLabel->setText(label + " (0)"); QListWidgetItem *newLabel = new QListWidgetItem();
newLabel->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("inode-directory")); newLabel->setText(label + " (0)");
labelFilters->addItem(newLabel); newLabel->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("inode-directory"));
customLabels.insert(label, 0); labelFilters->addItem(newLabel);
Preferences::instance()->addTorrentLabel(label); customLabels.insert(label, 0);
Preferences::instance()->addTorrentLabel(label);
} }
void TransferListFiltersWidget::showLabelMenu(QPoint) { void TransferListFiltersWidget::showLabelMenu(QPoint)
QMenu labelMenu(labelFilters); {
QAction *addAct = labelMenu.addAction(IconProvider::instance()->getIcon("list-add"), tr("Add label...")); QMenu labelMenu(labelFilters);
QAction *removeAct = 0; QAction *addAct = labelMenu.addAction(IconProvider::instance()->getIcon("list-add"), tr("Add label..."));
QAction *removeUnusedAct = 0; QAction *removeAct = 0;
if (!labelFilters->selectedItems().empty() && labelFilters->row(labelFilters->selectedItems().first()) > 1) QAction *removeUnusedAct = 0;
removeAct = labelMenu.addAction(IconProvider::instance()->getIcon("list-remove"), tr("Remove label")); if (!labelFilters->selectedItems().empty() && labelFilters->row(labelFilters->selectedItems().first()) > 1)
else removeAct = labelMenu.addAction(IconProvider::instance()->getIcon("list-remove"), tr("Remove label"));
removeUnusedAct = labelMenu.addAction(IconProvider::instance()->getIcon("list-remove"), tr("Remove unused labels")); else
labelMenu.addSeparator(); removeUnusedAct = labelMenu.addAction(IconProvider::instance()->getIcon("list-remove"), tr("Remove unused labels"));
QAction *startAct = labelMenu.addAction(IconProvider::instance()->getIcon("media-playback-start"), tr("Resume torrents")); labelMenu.addSeparator();
QAction *pauseAct = labelMenu.addAction(IconProvider::instance()->getIcon("media-playback-pause"), tr("Pause torrents")); QAction *startAct = labelMenu.addAction(IconProvider::instance()->getIcon("media-playback-start"), tr("Resume torrents"));
QAction *deleteTorrentsAct = labelMenu.addAction(IconProvider::instance()->getIcon("edit-delete"), tr("Delete torrents")); QAction *pauseAct = labelMenu.addAction(IconProvider::instance()->getIcon("media-playback-pause"), tr("Pause torrents"));
QAction *act = 0; QAction *deleteTorrentsAct = labelMenu.addAction(IconProvider::instance()->getIcon("edit-delete"), tr("Delete torrents"));
act = labelMenu.exec(QCursor::pos()); QAction *act = 0;
if (act) { act = labelMenu.exec(QCursor::pos());
if (act == removeAct) { if (act) {
removeSelectedLabel(); if (act == removeAct) {
return; removeSelectedLabel();
} return;
if (act == removeUnusedAct) { }
removeUnusedLabels(); if (act == removeUnusedAct) {
return; removeUnusedLabels();
} return;
if (act == deleteTorrentsAct) { }
transferList->deleteVisibleTorrents(); if (act == deleteTorrentsAct) {
return; transferList->deleteVisibleTorrents();
} return;
if (act == startAct) { }
transferList->startVisibleTorrents(); if (act == startAct) {
return; transferList->startVisibleTorrents();
} return;
if (act == pauseAct) { }
transferList->pauseVisibleTorrents(); if (act == pauseAct) {
return; transferList->pauseVisibleTorrents();
} return;
if (act == addAct) { }
bool ok; if (act == addAct) {
QString label = ""; bool ok;
bool invalid; QString label = "";
do { bool invalid;
invalid = false; do {
label = AutoExpandableDialog::getText(this, tr("New Label"), tr("Label:"), QLineEdit::Normal, label, &ok); invalid = false;
if (ok && !label.isEmpty()) { label = AutoExpandableDialog::getText(this, tr("New Label"), tr("Label:"), QLineEdit::Normal, label, &ok);
if (fsutils::isValidFileSystemName(label)) { if (ok && !label.isEmpty()) {
addLabel(label); if (fsutils::isValidFileSystemName(label)) {
} else { addLabel(label);
QMessageBox::warning(this, tr("Invalid label name"), tr("Please don't use any special characters in the label name.")); }
invalid = true; 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;
} }
} while(invalid);
return;
} }
}
} }
void TransferListFiltersWidget::removeSelectedLabel() { void TransferListFiltersWidget::removeSelectedLabel()
const int row = labelFilters->row(labelFilters->selectedItems().first()); {
Q_ASSERT(row > 1); const int row = labelFilters->row(labelFilters->selectedItems().first());
const QString &label = labelFilters->labelFromRow(row); Q_ASSERT(row > 1);
Q_ASSERT(customLabels.contains(label)); const QString &label = labelFilters->labelFromRow(row);
customLabels.remove(label); Q_ASSERT(customLabels.contains(label));
transferList->removeLabelFromRows(label); customLabels.remove(label);
// Select first label transferList->removeLabelFromRows(label);
labelFilters->setCurrentItem(labelFilters->item(0)); // Select first label
labelFilters->selectionModel()->select(labelFilters->model()->index(0,0), QItemSelectionModel::Select); labelFilters->setCurrentItem(labelFilters->item(0));
applyLabelFilter(0); labelFilters->selectionModel()->select(labelFilters->model()->index(0,0), QItemSelectionModel::Select);
// Un display filter applyLabelFilter(0);
delete labelFilters->takeItem(row); // Un display filter
// Save custom labels to remember it was deleted delete labelFilters->takeItem(row);
Preferences::instance()->removeTorrentLabel(label); // Save custom labels to remember it was deleted
Preferences::instance()->removeTorrentLabel(label);
} }
void TransferListFiltersWidget::removeUnusedLabels() { void TransferListFiltersWidget::removeUnusedLabels()
{
QStringList unusedLabels; QStringList unusedLabels;
QHash<QString, int>::const_iterator i; QHash<QString, int>::const_iterator i;
for (i = customLabels.begin(); i != customLabels.end(); ++i) { for (i = customLabels.begin(); i != customLabels.end(); ++i)
if (i.value() == 0) if (i.value() == 0)
unusedLabels << i.key(); unusedLabels << i.key();
}
foreach (const QString &label, unusedLabels) { foreach (const QString &label, unusedLabels) {
customLabels.remove(label); customLabels.remove(label);
delete labelFilters->takeItem(labelFilters->rowFromLabel(label)); delete labelFilters->takeItem(labelFilters->rowFromLabel(label));
@ -381,95 +402,100 @@ void TransferListFiltersWidget::removeUnusedLabels() {
} }
} }
void TransferListFiltersWidget::applyLabelFilter(int row) { void TransferListFiltersWidget::applyLabelFilter(int row)
switch(row) { {
case 0: switch (row) {
transferList->applyLabelFilterAll(); case 0:
break; transferList->applyLabelFilterAll();
case 1: break;
transferList->applyLabelFilter(QString()); case 1:
break; transferList->applyLabelFilter(QString());
default: break;
transferList->applyLabelFilter(labelFilters->labelFromRow(row)); default:
} transferList->applyLabelFilter(labelFilters->labelFromRow(row));
}
} }
void TransferListFiltersWidget::torrentChangedLabel(TorrentModelItem *torrentItem, QString old_label, QString new_label) { 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)); Q_UNUSED(torrentItem);
if (!old_label.isEmpty()) { qDebug("Torrent label changed from %s to %s", qPrintable(old_label), qPrintable(new_label));
if (customLabels.contains(old_label)) { if (!old_label.isEmpty()) {
const int new_count = customLabels.value(old_label, 0) - 1; if (customLabels.contains(old_label)) {
Q_ASSERT(new_count >= 0); const int new_count = customLabels.value(old_label, 0) - 1;
customLabels.insert(old_label, new_count); Q_ASSERT(new_count >= 0);
const int row = labelFilters->rowFromLabel(old_label); customLabels.insert(old_label, new_count);
Q_ASSERT(row >= 2); const int row = labelFilters->rowFromLabel(old_label);
labelFilters->item(row)->setText(old_label + " ("+ QString::number(new_count) +")"); Q_ASSERT(row >= 2);
labelFilters->item(row)->setText(old_label + " (" + QString::number(new_count) + ")");
}
--nb_labeled;
} }
--nb_labeled; if (!new_label.isEmpty()) {
} if (!customLabels.contains(new_label))
if (!new_label.isEmpty()) { addLabel(new_label);
if (!customLabels.contains(new_label)) const int new_count = customLabels.value(new_label, 0) + 1;
addLabel(new_label); Q_ASSERT(new_count >= 1);
const int new_count = customLabels.value(new_label, 0) + 1; customLabels.insert(new_label, new_count);
Q_ASSERT(new_count >= 1); const int row = labelFilters->rowFromLabel(new_label);
customLabels.insert(new_label, new_count); Q_ASSERT(row >= 2);
const int row = labelFilters->rowFromLabel(new_label); labelFilters->item(row)->setText(new_label + " (" + QString::number(new_count) + ")");
Q_ASSERT(row >= 2); ++nb_labeled;
labelFilters->item(row)->setText(new_label + " ("+ QString::number(new_count) +")"); }
++nb_labeled; updateStickyLabelCounters();
}
updateStickyLabelCounters();
} }
void TransferListFiltersWidget::handleNewTorrent(TorrentModelItem* torrentItem) { void TransferListFiltersWidget::handleNewTorrent(TorrentModelItem* torrentItem)
QString label = torrentItem->data(TorrentModelItem::TR_LABEL).toString(); {
qDebug("New torrent was added with label: %s", qPrintable(label)); QString label = torrentItem->data(TorrentModelItem::TR_LABEL).toString();
if (!label.isEmpty()) { qDebug("New torrent was added with label: %s", qPrintable(label));
if (!customLabels.contains(label)) { if (!label.isEmpty()) {
addLabel(label); if (!customLabels.contains(label)) {
// addLabel may have changed the label, update the model accordingly. addLabel(label);
torrentItem->setData(TorrentModelItem::TR_LABEL, 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;
} }
// Update label counter ++nb_torrents;
Q_ASSERT(customLabels.contains(label)); Q_ASSERT(nb_torrents >= 0);
const int new_count = customLabels.value(label, 0) + 1; Q_ASSERT(nb_labeled >= 0);
customLabels.insert(label, new_count); Q_ASSERT(nb_labeled <= nb_torrents);
const int row = labelFilters->rowFromLabel(label); updateStickyLabelCounters();
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();
} }
void TransferListFiltersWidget::torrentAboutToBeDeleted(TorrentModelItem* torrentItem) { void TransferListFiltersWidget::torrentAboutToBeDeleted(TorrentModelItem* torrentItem)
Q_ASSERT(torrentItem); {
QString label = torrentItem->data(TorrentModelItem::TR_LABEL).toString(); Q_ASSERT(torrentItem);
if (!label.isEmpty()) { QString label = torrentItem->data(TorrentModelItem::TR_LABEL).toString();
// Update label counter if (!label.isEmpty()) {
const int new_count = customLabels.value(label, 0) - 1; // Update label counter
customLabels.insert(label, new_count); const int new_count = customLabels.value(label, 0) - 1;
const int row = labelFilters->rowFromLabel(label); customLabels.insert(label, new_count);
Q_ASSERT(row >= 2); const int row = labelFilters->rowFromLabel(label);
labelFilters->item(row)->setText(label + " ("+ QString::number(new_count) +")"); Q_ASSERT(row >= 2);
--nb_labeled; labelFilters->item(row)->setText(label + " (" + QString::number(new_count) + ")");
} --nb_labeled;
--nb_torrents; }
qDebug("nb_torrents: %d, nb_labeled: %d", nb_torrents, nb_labeled); --nb_torrents;
Q_ASSERT(nb_torrents >= 0); qDebug("nb_torrents: %d, nb_labeled: %d", nb_torrents, nb_labeled);
Q_ASSERT(nb_labeled >= 0); Q_ASSERT(nb_torrents >= 0);
Q_ASSERT(nb_labeled <= nb_torrents); Q_ASSERT(nb_labeled >= 0);
updateStickyLabelCounters(); Q_ASSERT(nb_labeled <= nb_torrents);
updateStickyLabelCounters();
} }
void TransferListFiltersWidget::updateStickyLabelCounters() { 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)+")"); labelFilters->item(0)->setText(tr("All labels") + " (" + QString::number(nb_torrents) + ")");
labelFilters->item(1)->setText(tr("Unlabeled") + " (" + QString::number(nb_torrents - nb_labeled) + ")");
} }

89
src/gui/transferlistfilterswidget.h

@ -43,77 +43,80 @@ QT_END_NAMESPACE
class TransferListWidget; class TransferListWidget;
class TorrentModelItem; class TorrentModelItem;
class LabelFiltersList: public QListWidget { class LabelFiltersList: public QListWidget
Q_OBJECT {
Q_OBJECT
private: private:
QListWidgetItem *itemHover; QListWidgetItem * itemHover;
public: public:
LabelFiltersList(QWidget *parent); LabelFiltersList(QWidget *parent);
// Redefine addItem() to make sure the list stays sorted // Redefine addItem() to make sure the list stays sorted
void addItem(QListWidgetItem *it); void addItem(QListWidgetItem *it);
QString labelFromRow(int row) const; QString labelFromRow(int row) const;
int rowFromLabel(QString label) const; int rowFromLabel(QString label) const;
signals: signals:
void torrentDropped(int label_row); void torrentDropped(int label_row);
protected: protected:
void dragMoveEvent(QDragMoveEvent *event); void dragMoveEvent(QDragMoveEvent *event);
void dropEvent(QDropEvent *event); void dropEvent(QDropEvent *event);
void dragLeaveEvent(QDragLeaveEvent*); void dragLeaveEvent(QDragLeaveEvent*);
void setItemHover(bool hover); void setItemHover(bool hover);
}; };
class StatusFiltersWidget : public QListWidget { class StatusFiltersWidget: public QListWidget
Q_OBJECT {
Q_OBJECT
public: public:
StatusFiltersWidget(QWidget *parent); StatusFiltersWidget(QWidget *parent);
protected: protected:
QSize sizeHint() const; QSize sizeHint() const;
private: private:
bool m_shown; bool m_shown;
}; };
class TransferListFiltersWidget: public QFrame { class TransferListFiltersWidget: public QFrame
Q_OBJECT {
Q_OBJECT
private: private:
QHash<QString, int> customLabels; QHash<QString, int> customLabels;
StatusFiltersWidget* statusFilters; StatusFiltersWidget* statusFilters;
LabelFiltersList* labelFilters; LabelFiltersList* labelFilters;
QVBoxLayout* vLayout; QVBoxLayout* vLayout;
TransferListWidget *transferList; TransferListWidget *transferList;
int nb_labeled; int nb_labeled;
int nb_torrents; int nb_torrents;
public: public:
TransferListFiltersWidget(QWidget *parent, TransferListWidget *transferList); TransferListFiltersWidget(QWidget *parent, TransferListWidget *transferList);
~TransferListFiltersWidget(); ~TransferListFiltersWidget();
StatusFiltersWidget* getStatusFilters() const; StatusFiltersWidget* getStatusFilters() const;
void saveSettings() const; void saveSettings() const;
void loadSettings(); void loadSettings();
protected slots: protected slots:
void updateTorrentNumbers(); void updateTorrentNumbers();
void torrentDropped(int row); void torrentDropped(int row);
void addLabel(QString& label); void addLabel(QString& label);
void showLabelMenu(QPoint); void showLabelMenu(QPoint);
void removeSelectedLabel(); void removeSelectedLabel();
void removeUnusedLabels(); void removeUnusedLabels();
void applyLabelFilter(int row); void applyLabelFilter(int row);
void torrentChangedLabel(TorrentModelItem *torrentItem, QString old_label, QString new_label); void torrentChangedLabel(TorrentModelItem *torrentItem, QString old_label, QString new_label);
void handleNewTorrent(TorrentModelItem* torrentItem); void handleNewTorrent(TorrentModelItem* torrentItem);
void torrentAboutToBeDeleted(TorrentModelItem* torrentItem); void torrentAboutToBeDeleted(TorrentModelItem* torrentItem);
void updateStickyLabelCounters(); void updateStickyLabelCounters();
}; };
#endif // TRANSFERLISTFILTERSWIDGET_H #endif // TRANSFERLISTFILTERSWIDGET_H

51
src/webui/btjson.cpp

@ -102,6 +102,7 @@ static const char KEY_TORRENT_STATE[] = "state";
static const char KEY_TORRENT_SEQUENTIAL_DOWNLOAD[] = "seq_dl"; static const char KEY_TORRENT_SEQUENTIAL_DOWNLOAD[] = "seq_dl";
static const char KEY_TORRENT_FIRST_LAST_PIECE_PRIO[] = "f_l_piece_prio"; static const char KEY_TORRENT_FIRST_LAST_PIECE_PRIO[] = "f_l_piece_prio";
static const char KEY_TORRENT_LABEL[] = "label"; static const char KEY_TORRENT_LABEL[] = "label";
static const char KEY_TORRENT_SUPER_SEEDING[] = "super_seeding";
// Tracker keys // Tracker keys
static const char KEY_TRACKER_URL[] = "url"; static const char KEY_TRACKER_URL[] = "url";
@ -144,6 +145,11 @@ static const char KEY_TRANSFER_UPRATELIMIT[] = "up_rate_limit";
static const char KEY_TRANSFER_DHT_NODES[] = "dht_nodes"; static const char KEY_TRANSFER_DHT_NODES[] = "dht_nodes";
static const char KEY_TRANSFER_CONNECTION_STATUS[] = "connection_status"; static const char KEY_TRANSFER_CONNECTION_STATUS[] = "connection_status";
// Sync main data keys
static const char KEY_SYNC_MAINDATA_QUEUEING[] = "queueing";
static const char KEY_SYNC_MAINDATA_USE_ALT_SPEED_LIMITS[] = "use_alt_speed_limits";
static const char KEY_SYNC_MAINDATA_REFRESH_INTERVAL[] = "refresh_interval";
static const char KEY_FULL_UPDATE[] = "full_update"; static const char KEY_FULL_UPDATE[] = "full_update";
static const char KEY_RESPONSE_ID[] = "rid"; static const char KEY_RESPONSE_ID[] = "rid";
static const char KEY_SUFFIX_REMOVED[] = "_removed"; static const char KEY_SUFFIX_REMOVED[] = "_removed";
@ -151,7 +157,7 @@ static const char KEY_SUFFIX_REMOVED[] = "_removed";
QVariantMap getTranserInfoMap(); QVariantMap getTranserInfoMap();
QVariantMap toMap(const QTorrentHandle& h); QVariantMap toMap(const QTorrentHandle& h);
void processMap(QVariantMap prevData, QVariantMap data, QVariantMap &syncData); void processMap(QVariantMap prevData, QVariantMap data, QVariantMap &syncData);
void processHash(QVariantHash prevData, QVariantHash data, QVariantHash &syncData, QVariantList &removedItems); void processHash(QVariantHash prevData, QVariantHash data, QVariantMap &syncData, QVariantList &removedItems);
void processList(QVariantList prevData, QVariantList data, QVariantList &syncData, QVariantList &removedItems); void processList(QVariantList prevData, QVariantList data, QVariantList &syncData, QVariantList &removedItems);
QVariantMap generateSyncData(int acceptedResponseId, QVariantMap data, QVariantMap &lastAcceptedData, QVariantMap &lastData); QVariantMap generateSyncData(int acceptedResponseId, QVariantMap data, QVariantMap &lastAcceptedData, QVariantMap &lastData);
@ -274,8 +280,7 @@ QByteArray btjson::getTorrents(QString filter, QString label,
* - "torrents_removed": a list of hashes of removed torrents * - "torrents_removed": a list of hashes of removed torrents
* - "labels": list of labels * - "labels": list of labels
* - "labels_removed": list of removed labels * - "labels_removed": list of removed labels
* - "queueing": priority system usage flag * - "server_state": map contains information about the state of the server
* - "server_state": map contains information about the status of the server
* The keys of the 'torrents' dictionary are hashes of torrents. * The keys of the 'torrents' dictionary are hashes of torrents.
* Each value of the 'torrents' dictionary contains map. The map can contain following keys: * Each value of the 'torrents' dictionary contains map. The map can contain following keys:
* - "name": Torrent name * - "name": Torrent name
@ -302,6 +307,8 @@ QByteArray btjson::getTorrents(QString filter, QString label,
* - "up_info_data: bytes uploaded * - "up_info_data: bytes uploaded
* - "up_info_speed: upload speed * - "up_info_speed: upload speed
* - "up_rate_limit: upload speed limit * - "up_rate_limit: upload speed limit
* - "queueing": priority system usage flag
* - "refresh_interval": torrents table refresh interval
*/ */
QByteArray btjson::getSyncMainData(int acceptedResponseId, QVariantMap &lastData, QVariantMap &lastAcceptedData) QByteArray btjson::getSyncMainData(int acceptedResponseId, QVariantMap &lastData, QVariantMap &lastAcceptedData)
{ {
@ -321,14 +328,18 @@ QByteArray btjson::getSyncMainData(int acceptedResponseId, QVariantMap &lastData
} }
data["torrents"] = torrents; data["torrents"] = torrents;
data["queueing"] = QBtSession::instance()->isQueueingEnabled();
QVariantList labels; QVariantList labels;
foreach (QString s, Preferences::instance()->getTorrentLabels()) foreach (QString s, Preferences::instance()->getTorrentLabels())
labels << s; labels << s;
data["labels"] = labels; data["labels"] = labels;
data["server_state"] = getTranserInfoMap();
QVariantMap serverState = getTranserInfoMap();
serverState[KEY_SYNC_MAINDATA_QUEUEING] = QBtSession::instance()->isQueueingEnabled();
serverState[KEY_SYNC_MAINDATA_USE_ALT_SPEED_LIMITS] = Preferences::instance()->isAltBandwidthEnabled();
serverState[KEY_SYNC_MAINDATA_REFRESH_INTERVAL] = Preferences::instance()->getRefreshInterval();
data["server_state"] = serverState;
return json::toJson(generateSyncData(acceptedResponseId, data, lastAcceptedData, lastData)); return json::toJson(generateSyncData(acceptedResponseId, data, lastAcceptedData, lastData));
} }
@ -528,6 +539,21 @@ QVariantMap getTranserInfoMap()
return map; return map;
} }
QByteArray btjson::getTorrentsRatesLimits(QStringList &hashes, bool downloadLimits)
{
QVariantMap map;
foreach (const QString &hash, hashes) {
int limit = -1;
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
if (h.is_valid())
limit = downloadLimits ? h.download_limit() : h.upload_limit();
map[hash] = limit;
}
return json::toJson(map);
}
QVariantMap toMap(const QTorrentHandle& h) QVariantMap toMap(const QTorrentHandle& h)
{ {
libtorrent::torrent_status status = h.status(torrent_handle::query_accurate_download_counters); libtorrent::torrent_status status = h.status(torrent_handle::query_accurate_download_counters);
@ -555,6 +581,7 @@ QVariantMap toMap(const QTorrentHandle& h)
if (h.has_metadata()) if (h.has_metadata())
ret[KEY_TORRENT_FIRST_LAST_PIECE_PRIO] = h.first_last_piece_first(); ret[KEY_TORRENT_FIRST_LAST_PIECE_PRIO] = h.first_last_piece_first();
ret[KEY_TORRENT_LABEL] = TorrentPersistentData::instance()->getLabel(h.hash()); ret[KEY_TORRENT_LABEL] = TorrentPersistentData::instance()->getLabel(h.hash());
ret[KEY_TORRENT_SUPER_SEEDING] = status.super_seeding;
return ret; return ret;
} }
@ -579,10 +606,10 @@ void processMap(QVariantMap prevData, QVariantMap data, QVariantMap &syncData)
} }
break; break;
case QVariant::Hash: { case QVariant::Hash: {
QVariantHash hash; QVariantMap map;
processHash(prevData[key].toHash(), data[key].toHash(), hash, removedItems); processHash(prevData[key].toHash(), data[key].toHash(), map, removedItems);
if (!hash.isEmpty()) if (!map.isEmpty())
syncData[key] = hash; syncData[key] = map;
if (!removedItems.isEmpty()) if (!removedItems.isEmpty())
syncData[key + KEY_SUFFIX_REMOVED] = removedItems; syncData[key + KEY_SUFFIX_REMOVED] = removedItems;
} }
@ -603,6 +630,7 @@ void processMap(QVariantMap prevData, QVariantMap data, QVariantMap &syncData)
case QVariant::Bool: case QVariant::Bool:
case QVariant::Double: case QVariant::Double:
case QVariant::ULongLong: case QVariant::ULongLong:
case QVariant::UInt:
if (prevData[key] != data[key]) if (prevData[key] != data[key])
syncData[key] = data[key]; syncData[key] = data[key];
break; break;
@ -615,7 +643,7 @@ void processMap(QVariantMap prevData, QVariantMap data, QVariantMap &syncData)
// Compare two lists of structures (prevData, data) and calculate difference (syncData, removedItems). // Compare two lists of structures (prevData, data) and calculate difference (syncData, removedItems).
// Structures encoded as map. // Structures encoded as map.
// Lists are encoded as hash table (indexed by structure key value) to improve ease of searching for removed items. // Lists are encoded as hash table (indexed by structure key value) to improve ease of searching for removed items.
void processHash(QVariantHash prevData, QVariantHash data, QVariantHash &syncData, QVariantList &removedItems) void processHash(QVariantHash prevData, QVariantHash data, QVariantMap &syncData, QVariantList &removedItems)
{ {
// initialize output variables // initialize output variables
syncData.clear(); syncData.clear();
@ -623,7 +651,8 @@ void processHash(QVariantHash prevData, QVariantHash data, QVariantHash &syncDat
if (prevData.isEmpty()) { if (prevData.isEmpty()) {
// If list was empty before, then difference is a whole new list. // If list was empty before, then difference is a whole new list.
syncData = data; foreach (QString key, data.keys())
syncData[key] = data[key];
} }
else { else {
foreach (QString key, data.keys()) { foreach (QString key, data.keys()) {

1
src/webui/btjson.h

@ -52,6 +52,7 @@ public:
static QByteArray getPropertiesForTorrent(const QString& hash); static QByteArray getPropertiesForTorrent(const QString& hash);
static QByteArray getFilesForTorrent(const QString& hash); static QByteArray getFilesForTorrent(const QString& hash);
static QByteArray getTransferInfo(); static QByteArray getTransferInfo();
static QByteArray getTorrentsRatesLimits(QStringList& hashes, bool downloadLimits);
}; // class btjson }; // class btjson
#endif // BTJSON_H #endif // BTJSON_H

22
src/webui/jsonutils.h

@ -42,23 +42,25 @@
namespace json { namespace json {
inline QByteArray toJson(const QVariant& var) inline QByteArray toJson(const QVariant& var)
{ {
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
return QJsonDocument::fromVariant(var).toJson(); return QJsonDocument::fromVariant(var).toJson(QJsonDocument::Compact);
#else #else
return QJson::Serializer().serialize(var); QJson::Serializer serializer;
serializer.setIndentMode(QJson::IndentCompact);
return serializer.serialize(var);
#endif #endif
} }
inline QVariant fromJson(const QString& json) inline QVariant fromJson(const QString& json)
{ {
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
return QJsonDocument::fromJson(json.toUtf8()).toVariant(); return QJsonDocument::fromJson(json.toUtf8()).toVariant();
#else #else
return QJson::Parser().parse(json.toUtf8()); return QJson::Parser().parse(json.toUtf8());
#endif #endif
} }
} }

12
src/webui/qtorrentfilter.cpp

@ -39,6 +39,8 @@ QTorrentFilter::QTorrentFilter(QString filter, QString label)
type_ = Completed; type_ = Completed;
else if (filter == "paused") else if (filter == "paused")
type_ = Paused; type_ = Paused;
else if (filter == "resumed")
type_ = Resumed;
else if (filter == "active") else if (filter == "active")
type_ = Active; type_ = Active;
else if (filter == "inactive") else if (filter == "inactive")
@ -57,6 +59,8 @@ bool QTorrentFilter::apply(const QTorrentHandle& h) const
return isTorrentCompleted(h); return isTorrentCompleted(h);
case Paused: case Paused:
return isTorrentPaused(h); return isTorrentPaused(h);
case Resumed:
return isTorrentResumed(h);
case Active: case Active:
return isTorrentActive(h); return isTorrentActive(h);
case Inactive: case Inactive:
@ -98,6 +102,14 @@ bool QTorrentFilter::isTorrentPaused(const QTorrentHandle &h) const
|| state == QTorrentState::Error; || state == QTorrentState::Error;
} }
bool QTorrentFilter::isTorrentResumed(const QTorrentHandle &h) const
{
const QTorrentState state = h.torrentState();
return state != QTorrentState::PausedUploading
&& state != QTorrentState::PausedDownloading;
}
bool QTorrentFilter::isTorrentActive(const QTorrentHandle &h) const bool QTorrentFilter::isTorrentActive(const QTorrentHandle &h) const
{ {
const QTorrentState state = h.torrentState(); const QTorrentState state = h.torrentState();

2
src/webui/qtorrentfilter.h

@ -40,6 +40,7 @@ public:
Downloading, Downloading,
Completed, Completed,
Paused, Paused,
Resumed,
Active, Active,
Inactive Inactive
}; };
@ -55,6 +56,7 @@ private:
bool isTorrentDownloading(const QTorrentHandle &h) const; bool isTorrentDownloading(const QTorrentHandle &h) const;
bool isTorrentCompleted(const QTorrentHandle &h) const; bool isTorrentCompleted(const QTorrentHandle &h) const;
bool isTorrentPaused(const QTorrentHandle &h) const; bool isTorrentPaused(const QTorrentHandle &h) const;
bool isTorrentResumed(const QTorrentHandle &h) const;
bool isTorrentActive(const QTorrentHandle &h) const; bool isTorrentActive(const QTorrentHandle &h) const;
bool isTorrentInactive(const QTorrentHandle &h) const; bool isTorrentInactive(const QTorrentHandle &h) const;
bool torrentHasLabel(const QTorrentHandle &h) const; bool torrentHasLabel(const QTorrentHandle &h) const;

80
src/webui/webapplication.cpp

@ -94,14 +94,15 @@ QMap<QString, QMap<QString, WebApplication::Action> > WebApplication::initialize
ADD_ACTION(command, getGlobalDlLimit); ADD_ACTION(command, getGlobalDlLimit);
ADD_ACTION(command, setGlobalUpLimit); ADD_ACTION(command, setGlobalUpLimit);
ADD_ACTION(command, setGlobalDlLimit); ADD_ACTION(command, setGlobalDlLimit);
ADD_ACTION(command, getTorrentUpLimit); ADD_ACTION(command, getTorrentsUpLimit);
ADD_ACTION(command, getTorrentDlLimit); ADD_ACTION(command, getTorrentsDlLimit);
ADD_ACTION(command, setTorrentUpLimit); ADD_ACTION(command, setTorrentsUpLimit);
ADD_ACTION(command, setTorrentDlLimit); ADD_ACTION(command, setTorrentsDlLimit);
ADD_ACTION(command, alternativeSpeedLimitsEnabled); ADD_ACTION(command, alternativeSpeedLimitsEnabled);
ADD_ACTION(command, toggleAlternativeSpeedLimits); ADD_ACTION(command, toggleAlternativeSpeedLimits);
ADD_ACTION(command, toggleSequentialDownload); ADD_ACTION(command, toggleSequentialDownload);
ADD_ACTION(command, toggleFirstLastPiecePrio); ADD_ACTION(command, toggleFirstLastPiecePrio);
ADD_ACTION(command, setSuperSeeding);
ADD_ACTION(command, delete); ADD_ACTION(command, delete);
ADD_ACTION(command, deletePerm); ADD_ACTION(command, deletePerm);
ADD_ACTION(command, increasePrio); ADD_ACTION(command, increasePrio);
@ -212,7 +213,7 @@ void WebApplication::action_public_images()
} }
// GET params: // GET params:
// - filter (string): all, downloading, completed, paused, active, inactive // - filter (string): all, downloading, completed, paused, resumed, active, inactive
// - label (string): torrent label for filtering by it (empty string means "unlabeled"; no "label" param presented means "any label") // - label (string): torrent label for filtering by it (empty string means "unlabeled"; no "label" param presented means "any label")
// - sort (string): name of column for sorting by its value // - sort (string): name of column for sorting by its value
// - reverse (bool): enable reverse sorting // - reverse (bool): enable reverse sorting
@ -453,52 +454,54 @@ void WebApplication::action_command_setGlobalDlLimit()
Preferences::instance()->setGlobalDownloadLimit(limit / 1024.); Preferences::instance()->setGlobalDownloadLimit(limit / 1024.);
} }
void WebApplication::action_command_getTorrentUpLimit() void WebApplication::action_command_getTorrentsUpLimit()
{ {
CHECK_URI(0); CHECK_URI(0);
CHECK_PARAMETERS("hash"); CHECK_PARAMETERS("hashes");
QString hash = request().posts["hash"]; QStringList hashes = request().posts["hashes"].split("|");
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash); print(btjson::getTorrentsRatesLimits(hashes, false), Http::CONTENT_TYPE_JS);
if (h.is_valid())
print(QByteArray::number(h.upload_limit()));
} }
void WebApplication::action_command_getTorrentDlLimit() void WebApplication::action_command_getTorrentsDlLimit()
{ {
CHECK_URI(0); CHECK_URI(0);
CHECK_PARAMETERS("hash"); CHECK_PARAMETERS("hashes");
QString hash = request().posts["hash"]; QStringList hashes = request().posts["hashes"].split("|");
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash); print(btjson::getTorrentsRatesLimits(hashes, true), Http::CONTENT_TYPE_JS);
if (h.is_valid())
print(QByteArray::number(h.download_limit()));
} }
void WebApplication::action_command_setTorrentUpLimit() void WebApplication::action_command_setTorrentsUpLimit()
{ {
CHECK_URI(0); CHECK_URI(0);
CHECK_PARAMETERS("hash" << "limit"); CHECK_PARAMETERS("hashes" << "limit");
QString hash = request().posts["hash"];
qlonglong limit = request().posts["limit"].toLongLong(); qlonglong limit = request().posts["limit"].toLongLong();
if (limit == 0) limit = -1; if (limit == 0)
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash); limit = -1;
if (h.is_valid()) QStringList hashes = request().posts["hashes"].split("|");
foreach (const QString &hash, hashes) {
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
if (h.is_valid())
h.set_upload_limit(limit); h.set_upload_limit(limit);
}
} }
void WebApplication::action_command_setTorrentDlLimit() void WebApplication::action_command_setTorrentsDlLimit()
{ {
CHECK_URI(0); CHECK_URI(0);
CHECK_PARAMETERS("hash" << "limit"); CHECK_PARAMETERS("hashes" << "limit");
QString hash = request().posts["hash"];
qlonglong limit = request().posts["limit"].toLongLong(); qlonglong limit = request().posts["limit"].toLongLong();
if (limit == 0) limit = -1; if (limit == 0)
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash); limit = -1;
if (h.is_valid()) QStringList hashes = request().posts["hashes"].split("|");
foreach (const QString &hash, hashes) {
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
if (h.is_valid())
h.set_download_limit(limit); h.set_download_limit(limit);
}
} }
void WebApplication::action_command_toggleAlternativeSpeedLimits() void WebApplication::action_command_toggleAlternativeSpeedLimits()
@ -541,6 +544,21 @@ void WebApplication::action_command_toggleFirstLastPiecePrio()
} }
} }
void WebApplication::action_command_setSuperSeeding()
{
CHECK_URI(0);
CHECK_PARAMETERS("hashes" << "value");
bool value = request().posts["value"] == "true";
QStringList hashes = request().posts["hashes"].split("|");
foreach (const QString &hash, hashes) {
try {
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
h.super_seeding(value);
}
catch(invalid_handle&) {}
}
}
void WebApplication::action_command_delete() void WebApplication::action_command_delete()
{ {
CHECK_URI(0); CHECK_URI(0);

9
src/webui/webapplication.h

@ -68,14 +68,15 @@ private:
void action_command_getGlobalDlLimit(); void action_command_getGlobalDlLimit();
void action_command_setGlobalUpLimit(); void action_command_setGlobalUpLimit();
void action_command_setGlobalDlLimit(); void action_command_setGlobalDlLimit();
void action_command_getTorrentUpLimit(); void action_command_getTorrentsUpLimit();
void action_command_getTorrentDlLimit(); void action_command_getTorrentsDlLimit();
void action_command_setTorrentUpLimit(); void action_command_setTorrentsUpLimit();
void action_command_setTorrentDlLimit(); void action_command_setTorrentsDlLimit();
void action_command_alternativeSpeedLimitsEnabled(); void action_command_alternativeSpeedLimitsEnabled();
void action_command_toggleAlternativeSpeedLimits(); void action_command_toggleAlternativeSpeedLimits();
void action_command_toggleSequentialDownload(); void action_command_toggleSequentialDownload();
void action_command_toggleFirstLastPiecePrio(); void action_command_toggleFirstLastPiecePrio();
void action_command_setSuperSeeding();
void action_command_delete(); void action_command_delete();
void action_command_deletePerm(); void action_command_deletePerm();
void action_command_increasePrio(); void action_command_increasePrio();

1
src/webui/www/private/index.html

@ -111,6 +111,7 @@
<li><a href="#UploadLimit"><img src="images/skin/seeding.png" alt="QBT_TR(Limit upload rate...)QBT_TR"/> QBT_TR(Limit upload rate...)QBT_TR</a></li> <li><a href="#UploadLimit"><img src="images/skin/seeding.png" alt="QBT_TR(Limit upload rate...)QBT_TR"/> QBT_TR(Limit upload rate...)QBT_TR</a></li>
<li class="separator"><a href="#SequentialDownload"><img src="theme/checked" alt="QBT_TR(Download in sequential order)QBT_TR"/> QBT_TR(Download in sequential order)QBT_TR</a></li> <li class="separator"><a href="#SequentialDownload"><img src="theme/checked" alt="QBT_TR(Download in sequential order)QBT_TR"/> QBT_TR(Download in sequential order)QBT_TR</a></li>
<li><a href="#FirstLastPiecePrio"><img src="theme/checked" alt="QBT_TR(Download first and last piece first)QBT_TR"/> QBT_TR(Download first and last piece first)QBT_TR</a></li> <li><a href="#FirstLastPiecePrio"><img src="theme/checked" alt="QBT_TR(Download first and last piece first)QBT_TR"/> QBT_TR(Download first and last piece first)QBT_TR</a></li>
<li class="separator"><a href="#SuperSeeding"><img src="theme/checked" alt="QBT_TR(Super seeding mode)QBT_TR"/> QBT_TR(Super seeding mode)QBT_TR</a></li>
<li class="separator"><a href="#ForceRecheck"><img src="theme/document-edit-verify" alt="QBT_TR(Force recheck)QBT_TR"/> QBT_TR(Force recheck)QBT_TR</a></li> <li class="separator"><a href="#ForceRecheck"><img src="theme/document-edit-verify" alt="QBT_TR(Force recheck)QBT_TR"/> QBT_TR(Force recheck)QBT_TR</a></li>
</ul> </ul>
<div id="desktopFooterWrapper"> <div id="desktopFooterWrapper">

10
src/webui/www/public/downloadlimit.html

@ -20,10 +20,10 @@
<div class="clear"></div> <div class="clear"></div>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
var hash = new URI().getData('hash'); var hashes = new URI().getData('hashes').split('|');
setDlLimit = function() { setDlLimit = function() {
var limit = $("dllimitUpdatevalue").value.toInt() * 1024; var limit = $("dllimitUpdatevalue").value.toInt() * 1024;
if (hash == "global") { if (hashes[0] == "global") {
new Request({ new Request({
url: 'command/setGlobalDlLimit', url: 'command/setGlobalDlLimit',
method: 'post', method: 'post',
@ -38,10 +38,10 @@
} }
else { else {
new Request({ new Request({
url: 'command/setTorrentDlLimit', url: 'command/setTorrentsDlLimit',
method: 'post', method: 'post',
data: { data: {
'hash': hash, 'hashes': hashes.join('|'),
'limit': limit 'limit': limit
}, },
onComplete: function() { onComplete: function() {
@ -55,7 +55,7 @@
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
MochaUI.addDlLimitSlider(hash); MochaUI.addDlLimitSlider(hashes);
</script> </script>
</body> </body>

1
src/webui/www/public/filters.html

@ -2,6 +2,7 @@
<li id="all_filter"><a href="#" onclick="setFilter('all');return false;"><img src="images/skin/filterall.png"/>QBT_TR(All)QBT_TR</a></li> <li id="all_filter"><a href="#" onclick="setFilter('all');return false;"><img src="images/skin/filterall.png"/>QBT_TR(All)QBT_TR</a></li>
<li id="downloading_filter"><a href="#" onclick="setFilter('downloading');return false;"><img src="images/skin/downloading.png"/>QBT_TR(Downloading)QBT_TR</a></li> <li id="downloading_filter"><a href="#" onclick="setFilter('downloading');return false;"><img src="images/skin/downloading.png"/>QBT_TR(Downloading)QBT_TR</a></li>
<li id="completed_filter"><a href="#" onclick="setFilter('completed');return false;"><img src="images/skin/uploading.png"/>QBT_TR(Completed)QBT_TR</a></li> <li id="completed_filter"><a href="#" onclick="setFilter('completed');return false;"><img src="images/skin/uploading.png"/>QBT_TR(Completed)QBT_TR</a></li>
<li id="resumed_filter"><a href="#" onclick="setFilter('resumed');return false;"><img src="images/skin/resumed.png"/>QBT_TR(Resumed)QBT_TR</a></li>
<li id="paused_filter"><a href="#" onclick="setFilter('paused');return false;"><img src="images/skin/paused.png"/>QBT_TR(Paused)QBT_TR</a></li> <li id="paused_filter"><a href="#" onclick="setFilter('paused');return false;"><img src="images/skin/paused.png"/>QBT_TR(Paused)QBT_TR</a></li>
<li id="active_filter"><a href="#" onclick="setFilter('active');return false;"><img src="images/skin/filteractive.png"/>QBT_TR(Active)QBT_TR</a></li> <li id="active_filter"><a href="#" onclick="setFilter('active');return false;"><img src="images/skin/filteractive.png"/>QBT_TR(Active)QBT_TR</a></li>
<li id="inactive_filter"><a href="#" onclick="setFilter('inactive');return false;"><img src="images/skin/filterinactive.png"/>QBT_TR(Inactive)QBT_TR</a></li> <li id="inactive_filter"><a href="#" onclick="setFilter('inactive');return false;"><img src="images/skin/filterinactive.png"/>QBT_TR(Inactive)QBT_TR</a></li>

70
src/webui/www/public/scripts/client.js

@ -27,6 +27,8 @@ myTable = new dynamicTable();
var updatePropertiesPanel = function(){}; var updatePropertiesPanel = function(){};
var updateMainData = function(){}; var updateMainData = function(){};
var alternativeSpeedLimits = false; var alternativeSpeedLimits = false;
var queueing_enabled = true;
var syncMainDataTimerPeriod = 1500;
selected_filter = getLocalStorageItem('selected_filter', 'all'); selected_filter = getLocalStorageItem('selected_filter', 'all');
selected_label = null; selected_label = null;
@ -95,6 +97,7 @@ window.addEvent('load', function () {
$("downloading_filter").removeClass("selectedFilter"); $("downloading_filter").removeClass("selectedFilter");
$("completed_filter").removeClass("selectedFilter"); $("completed_filter").removeClass("selectedFilter");
$("paused_filter").removeClass("selectedFilter"); $("paused_filter").removeClass("selectedFilter");
$("resumed_filter").removeClass("selectedFilter");
$("active_filter").removeClass("selectedFilter"); $("active_filter").removeClass("selectedFilter");
$("inactive_filter").removeClass("selectedFilter"); $("inactive_filter").removeClass("selectedFilter");
$(f + "_filter").addClass("selectedFilter"); $(f + "_filter").addClass("selectedFilter");
@ -153,19 +156,6 @@ window.addEvent('load', function () {
myTable.rows.erase(); myTable.rows.erase();
if (response['rid']) if (response['rid'])
syncMainDataLastResponseId = response['rid']; syncMainDataLastResponseId = response['rid'];
if ('queueing' in response) {
var queueing_enabled = response['queueing'];
myTable.columns['priority'].force_hide = !queueing_enabled;
myTable.updateColumn('priority');
if (queueing_enabled) {
$('queueingButtons').removeClass('invisible');
$('queueingMenuItems').removeClass('invisible');
}
else {
$('queueingButtons').addClass('invisible');
$('queueingMenuItems').addClass('invisible');
}
}
if (response['torrents']) if (response['torrents'])
for (var key in response['torrents']) { for (var key in response['torrents']) {
response['torrents'][key]['hash'] = key; response['torrents'][key]['hash'] = key;
@ -185,7 +175,7 @@ window.addEvent('load', function () {
} }
} }
clearTimeout(syncMainDataTimer); clearTimeout(syncMainDataTimer);
syncMainDataTimer = syncMainData.delay(1500); syncMainDataTimer = syncMainData.delay(syncMainDataTimerPeriod);
} }
}).send(); }).send();
}; };
@ -220,6 +210,29 @@ window.addEvent('load', function () {
$('connectionStatus').src = 'images/skin/firewalled.png'; $('connectionStatus').src = 'images/skin/firewalled.png';
else else
$('connectionStatus').src = 'images/skin/disconnected.png'; $('connectionStatus').src = 'images/skin/disconnected.png';
if (queueing_enabled != serverState.queueing) {
queueing_enabled = serverState.queueing;
myTable.columns['priority'].force_hide = !queueing_enabled;
myTable.updateColumn('priority');
if (queueing_enabled) {
$('queueingButtons').removeClass('invisible');
$('queueingMenuItems').removeClass('invisible');
}
else {
$('queueingButtons').addClass('invisible');
$('queueingMenuItems').addClass('invisible');
}
}
if (alternativeSpeedLimits != serverState.use_alt_speed_limits) {
alternativeSpeedLimits = serverState.use_alt_speed_limits;
updateAltSpeedIcon(alternativeSpeedLimits);
}
syncMainDataTimerPeriod = serverState.refresh_interval;
if (syncMainDataTimerPeriod < 500)
syncMainDataTimerPeriod = 500;
}; };
var updateAltSpeedIcon = function(enabled) { var updateAltSpeedIcon = function(enabled) {
@ -229,16 +242,6 @@ window.addEvent('load', function () {
$('alternativeSpeedLimits').src = "images/slow_off.png" $('alternativeSpeedLimits').src = "images/slow_off.png"
} }
// Determine whether the alternative speed limits are enabled or not
new Request({url: 'command/alternativeSpeedLimitsEnabled',
method: 'get',
onSuccess : function (isEnabled) {
alternativeSpeedLimits = !!parseInt(isEnabled);
if (alternativeSpeedLimits)
$('alternativeSpeedLimits').src = "images/slow.png"
}
}).send();
$('alternativeSpeedLimits').addEvent('click', function() { $('alternativeSpeedLimits').addEvent('click', function() {
// Change icon immediately to give some feedback // Change icon immediately to give some feedback
updateAltSpeedIcon(!alternativeSpeedLimits); updateAltSpeedIcon(!alternativeSpeedLimits);
@ -354,11 +357,20 @@ window.addEvent('load', function () {
function closeWindows() { function closeWindows() {
MochaUI.closeAll(); MochaUI.closeAll();
} };
window.addEvent('keydown', function (event) { var keyboardEvents = new Keyboard({
if (event.key == 'a' && event.control) { defaultEventType: 'keydown',
event.stop(); events: {
myTable.selectAll(); 'ctrl+a': function(event) {
myTable.selectAll();
event.preventDefault();
},
'delete': function(event) {
deleteFN();
event.preventDefault();
}
} }
}); });
keyboardEvents.activate();

11
src/webui/www/public/scripts/contextmenu.js

@ -136,6 +136,7 @@ var ContextMenu = new Class({
all_are_downloaded = true; all_are_downloaded = true;
all_are_paused = true; all_are_paused = true;
there_are_paused = false; there_are_paused = false;
all_are_super_seeding = true;
var h = myTable.selectedIds(); var h = myTable.selectedIds();
h.each(function(item, index){ h.each(function(item, index){
@ -153,6 +154,8 @@ var ContextMenu = new Class({
if (data['progress'] != 1.0) // not downloaded if (data['progress'] != 1.0) // not downloaded
all_are_downloaded = false; all_are_downloaded = false;
else if (data['super_seeding'] != true)
all_are_super_seeding = false;
state = data['state']; state = data['state'];
if ((state != 'pausedUP') && (state != 'pausedDL')) if ((state != 'pausedUP') && (state != 'pausedDL'))
@ -174,6 +177,8 @@ var ContextMenu = new Class({
if (all_are_downloaded) { if (all_are_downloaded) {
this.hideItem('SequentialDownload'); this.hideItem('SequentialDownload');
this.hideItem('FirstLastPiecePrio'); this.hideItem('FirstLastPiecePrio');
this.showItem('SuperSeeding');
this.setItemChecked('SuperSeeding', all_are_super_seeding);
} else { } else {
if (!show_seq_dl && show_f_l_piece_prio) if (!show_seq_dl && show_f_l_piece_prio)
this.menu.getElement('a[href$=FirstLastPiecePrio]').parentNode.addClass('separator'); this.menu.getElement('a[href$=FirstLastPiecePrio]').parentNode.addClass('separator');
@ -192,6 +197,8 @@ var ContextMenu = new Class({
this.setItemChecked('SequentialDownload', all_are_seq_dl); this.setItemChecked('SequentialDownload', all_are_seq_dl);
this.setItemChecked('FirstLastPiecePrio', all_are_f_l_piece_prio); this.setItemChecked('FirstLastPiecePrio', all_are_f_l_piece_prio);
this.hideItem('SuperSeeding');
} }
if (all_are_paused) { if (all_are_paused) {
@ -234,6 +241,10 @@ var ContextMenu = new Class({
return this; return this;
}, },
getItemChecked: function(item) {
return '0' != this.menu.getElement('a[href$=' + item + ']').firstChild.style.opacity;
},
//hide an item //hide an item
hideItem: function(item) { hideItem: function(item) {
this.menu.getElement('a[href$=' + item + ']').parentNode.addClass('invisible'); this.menu.getElement('a[href$=' + item + ']').parentNode.addClass('invisible');

15
src/webui/www/public/scripts/dynamicTable.js

@ -261,6 +261,10 @@ var dynamicTable = new Class({
if (!~state.indexOf('paused')) if (!~state.indexOf('paused'))
return false; return false;
break; break;
case 'resumed':
if (~state.indexOf('paused'))
return false;
break;
case 'active': case 'active':
if ((state != 'uploading') && (state != 'downloading')) if ((state != 'uploading') && (state != 'downloading'))
return false; return false;
@ -352,6 +356,17 @@ var dynamicTable = new Class({
myTable.selectRow(this.hash); myTable.selectRow(this.hash);
return true; return true;
}); });
tr.addEvent('dblclick', function (e) {
e.stop();
myTable.selectRow(this.hash);
var row = myTable.rows.get(this.hash);
var state = row['full_data'].state;
if (~state.indexOf('paused'))
startFN();
else
pauseFN();
return true;
});
tr.addEvent('click', function (e) { tr.addEvent('click', function (e) {
e.stop(); e.stop();
if (e.control) { if (e.control) {

4
src/webui/www/public/scripts/misc.js

@ -38,11 +38,11 @@ function friendlyDuration(seconds) {
if (minutes < 60) if (minutes < 60)
return "QBT_TR(%1m)QBT_TR".replace("%1", parseInt(minutes)); return "QBT_TR(%1m)QBT_TR".replace("%1", parseInt(minutes));
var hours = minutes / 60; var hours = minutes / 60;
minutes = minutes - hours * 60; minutes = minutes % 60;
if (hours < 24) if (hours < 24)
return "QBT_TR(%1h %2m)QBT_TR".replace("%1", parseInt(hours)).replace("%2", parseInt(minutes)) return "QBT_TR(%1h %2m)QBT_TR".replace("%1", parseInt(hours)).replace("%2", parseInt(minutes))
var days = hours / 24; var days = hours / 24;
hours = hours - days * 24; hours = hours % 24;
if (days < 100) if (days < 100)
return "QBT_TR(%1d %2h)QBT_TR".replace("%1", parseInt(days)).replace("%2", parseInt(hours)) return "QBT_TR(%1d %2h)QBT_TR".replace("%1", parseInt(days)).replace("%2", parseInt(hours))
return "∞"; return "∞";

29
src/webui/www/public/scripts/mocha-init.js

@ -29,6 +29,10 @@ function getLocalStorageItem(name, defaultVal) {
return val; return val;
} }
var deleteFN = function() {};
var startFN = function() {};
var pauseFN = function() {};
initializeWindows = function() { initializeWindows = function() {
function addClickEvent(el, fn) { function addClickEvent(el, fn) {
@ -103,7 +107,7 @@ initializeWindows = function() {
id: 'uploadLimitPage', id: 'uploadLimitPage',
title: "QBT_TR(Global Upload Speed Limit)QBT_TR", title: "QBT_TR(Global Upload Speed Limit)QBT_TR",
loadMethod: 'iframe', loadMethod: 'iframe',
contentURL: 'uploadlimit.html?hash=global', contentURL: 'uploadlimit.html?hashes=global',
scrollbars: false, scrollbars: false,
resizable: false, resizable: false,
maximizable: false, maximizable: false,
@ -122,7 +126,7 @@ initializeWindows = function() {
id: 'uploadLimitPage', id: 'uploadLimitPage',
title: "QBT_TR(Torrent Upload Speed Limiting)QBT_TR", title: "QBT_TR(Torrent Upload Speed Limiting)QBT_TR",
loadMethod: 'iframe', loadMethod: 'iframe',
contentURL: 'uploadlimit.html?hash=' + hash, contentURL: 'uploadlimit.html?hashes=' + h.join("|"),
scrollbars: false, scrollbars: false,
resizable: false, resizable: false,
maximizable: false, maximizable: false,
@ -162,12 +166,27 @@ initializeWindows = function() {
} }
}; };
setSuperSeedingFN = function(val) {
var h = myTable.selectedIds();
if (h.length) {
new Request({
url: 'command/setSuperSeeding',
method: 'post',
data: {
value: val,
hashes: h.join("|")
}
}).send();
updateMainData();
}
};
globalDownloadLimitFN = function() { globalDownloadLimitFN = function() {
new MochaUI.Window({ new MochaUI.Window({
id: 'downloadLimitPage', id: 'downloadLimitPage',
title: "QBT_TR(Global Download Speed Limit)QBT_TR", title: "QBT_TR(Global Download Speed Limit)QBT_TR",
loadMethod: 'iframe', loadMethod: 'iframe',
contentURL: 'downloadlimit.html?hash=global', contentURL: 'downloadlimit.html?hashes=global',
scrollbars: false, scrollbars: false,
resizable: false, resizable: false,
maximizable: false, maximizable: false,
@ -186,7 +205,7 @@ initializeWindows = function() {
id: 'downloadLimitPage', id: 'downloadLimitPage',
title: "QBT_TR(Torrent Download Speed Limiting)QBT_TR", title: "QBT_TR(Torrent Download Speed Limiting)QBT_TR",
loadMethod: 'iframe', loadMethod: 'iframe',
contentURL: 'downloadlimit.html?hash=' + hash, contentURL: 'downloadlimit.html?hashes=' + h.join("|"),
scrollbars: false, scrollbars: false,
resizable: false, resizable: false,
maximizable: false, maximizable: false,
@ -274,7 +293,7 @@ initializeWindows = function() {
} }
}; };
['pause', 'resume', 'recheck'].each(function(item) { ['pauseAll', 'resumeAll', 'pause', 'resume', 'recheck'].each(function(item) {
addClickEvent(item, function(e) { addClickEvent(item, function(e) {
new Event(e).stop(); new Event(e).stop();
var h = myTable.selectedIds(); var h = myTable.selectedIds();

44
src/webui/www/public/scripts/parametrics.js

@ -14,7 +14,7 @@ Requires:
*/ */
MochaUI.extend({ MochaUI.extend({
addUpLimitSlider: function(hash) { addUpLimitSlider: function(hashes) {
if ($('uplimitSliderarea')) { if ($('uplimitSliderarea')) {
var windowOptions = MochaUI.Windows.windowOptions; var windowOptions = MochaUI.Windows.windowOptions;
var sliderFirst = true; var sliderFirst = true;
@ -31,15 +31,15 @@ MochaUI.extend({
maximum = tmp / 1024. maximum = tmp / 1024.
} }
else { else {
if (hash == "global") if (hashes[0] == "global")
maximum = 10000; maximum = 10000;
else else
maximum = 1000; maximum = 1000;
} }
} }
// Get torrent upload limit // Get torrents upload limit
// And create slider // And create slider
if (hash == 'global') { if (hashes[0] == 'global') {
var up_limit = maximum; var up_limit = maximum;
if (up_limit < 0) up_limit = 0; if (up_limit < 0) up_limit = 0;
maximum = 10000; maximum = 10000;
@ -69,15 +69,21 @@ MochaUI.extend({
} }
} }
else { else {
var req = new Request({ var req = new Request.JSON({
url: 'command/getTorrentUpLimit', url: 'command/getTorrentsUpLimit',
noCache : true,
method: 'post', method: 'post',
data: { data: {
hash: hash hashes: hashes.join('|')
}, },
onSuccess: function(data) { onSuccess: function(data) {
if (data) { if (data) {
var up_limit = data.toInt(); var up_limit = data[hashes[0]];
for(var key in data)
if (up_limit != data[key]) {
up_limit = 0;
break;
}
if (up_limit < 0) up_limit = 0; if (up_limit < 0) up_limit = 0;
var mochaSlide = new Slider($('uplimitSliderarea'), $('uplimitSliderknob'), { var mochaSlide = new Slider($('uplimitSliderarea'), $('uplimitSliderknob'), {
steps: maximum, steps: maximum,
@ -112,7 +118,7 @@ MochaUI.extend({
} }
}, },
addDlLimitSlider: function(hash) { addDlLimitSlider: function(hashes) {
if ($('dllimitSliderarea')) { if ($('dllimitSliderarea')) {
var windowOptions = MochaUI.Windows.windowOptions; var windowOptions = MochaUI.Windows.windowOptions;
var sliderFirst = true; var sliderFirst = true;
@ -129,15 +135,15 @@ MochaUI.extend({
maximum = tmp / 1024. maximum = tmp / 1024.
} }
else { else {
if (hash == "global") if (hashes[0] == "global")
maximum = 10000; maximum = 10000;
else else
maximum = 1000; maximum = 1000;
} }
} }
// Get torrent download limit // Get torrents download limit
// And create slider // And create slider
if (hash == "global") { if (hashes[0] == 'global') {
var dl_limit = maximum; var dl_limit = maximum;
if (dl_limit < 0) dl_limit = 0; if (dl_limit < 0) dl_limit = 0;
maximum = 10000; maximum = 10000;
@ -167,15 +173,21 @@ MochaUI.extend({
} }
} }
else { else {
var req = new Request({ var req = new Request.JSON({
url: 'command/getTorrentDlLimit', url: 'command/getTorrentsDlLimit',
noCache : true,
method: 'post', method: 'post',
data: { data: {
hash: hash hashes: hashes.join('|')
}, },
onSuccess: function(data) { onSuccess: function(data) {
if (data) { if (data) {
var dl_limit = data.toInt(); var dl_limit = data[hashes[0]];
for(var key in data)
if (dl_limit != data[key]) {
dl_limit = 0;
break;
}
if (dl_limit < 0) dl_limit = 0; if (dl_limit < 0) dl_limit = 0;
var mochaSlide = new Slider($('dllimitSliderarea'), $('dllimitSliderknob'), { var mochaSlide = new Slider($('dllimitSliderarea'), $('dllimitSliderknob'), {
steps: maximum, steps: maximum,

4
src/webui/www/public/scripts/progressbar.js

@ -37,7 +37,7 @@ var ProgressBar = new Class({
'text-align': 'center', 'text-align': 'center',
'left': 0, 'left': 0,
'top': 0, 'top': 0,
'line-height': vals.height - 2 'line-height': vals.height
} }
}); });
obj.vals.light = new Element('div', { obj.vals.light = new Element('div', {
@ -52,7 +52,7 @@ var ProgressBar = new Class({
'text-align': 'center', 'text-align': 'center',
'left': 0, 'left': 0,
'top': 0, 'top': 0,
'line-height': vals.height - 2 'line-height': vals.height
} }
}); });
obj.appendChild(obj.vals.dark); obj.appendChild(obj.vals.dark);

3
src/webui/www/public/transferlist.html

@ -51,6 +51,9 @@
}, },
FirstLastPiecePrio : function (element, ref) { FirstLastPiecePrio : function (element, ref) {
toggleFirstLastPiecePrioFN(); toggleFirstLastPiecePrioFN();
},
SuperSeeding : function (element, ref) {
setSuperSeedingFN(!ref.getItemChecked('SuperSeeding'));
} }
}, },
offsets : { offsets : {

10
src/webui/www/public/uploadlimit.html

@ -20,10 +20,10 @@
<div class="clear"></div> <div class="clear"></div>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
var hash = new URI().getData('hash'); var hashes = new URI().getData('hashes').split('|');
setUpLimit = function() { setUpLimit = function() {
var limit = $("uplimitUpdatevalue").value.toInt() * 1024; var limit = $("uplimitUpdatevalue").value.toInt() * 1024;
if (hash == "global") { if (hashes[0] == "global") {
new Request({ new Request({
url: 'command/setGlobalUpLimit', url: 'command/setGlobalUpLimit',
method: 'post', method: 'post',
@ -38,10 +38,10 @@
} }
else { else {
new Request({ new Request({
url: 'command/setTorrentUpLimit', url: 'command/setTorrentsUpLimit',
method: 'post', method: 'post',
data: { data: {
'hash': hash, 'hashes': hashes.join('|'),
'limit': limit 'limit': limit
}, },
onComplete: function() { onComplete: function() {
@ -55,7 +55,7 @@
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
MochaUI.addUpLimitSlider(hash); MochaUI.addUpLimitSlider(hashes);
</script> </script>
</body> </body>

Loading…
Cancel
Save