mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-19 04:49:47 -07:00
commit
0058abeefa
22 changed files with 711 additions and 543 deletions
|
@ -32,6 +32,6 @@
|
|||
#define TORRENTFILTERENUM_H
|
||||
|
||||
namespace TorrentFilter {
|
||||
enum TorrentFilter {ALL, DOWNLOADING, COMPLETED, PAUSED, RESUMED, ACTIVE, INACTIVE};
|
||||
enum TorrentFilter {ALL, DOWNLOADING, COMPLETED, RESUMED, PAUSED, ACTIVE, INACTIVE};
|
||||
}
|
||||
#endif // TORRENTFILTERENUM_H
|
||||
|
|
|
@ -48,7 +48,8 @@
|
|||
#include "autoexpandabledialog.h"
|
||||
#include "torrentfilterenum.h"
|
||||
|
||||
LabelFiltersList::LabelFiltersList(QWidget *parent): QListWidget(parent) {
|
||||
LabelFiltersList::LabelFiltersList(QWidget *parent): QListWidget(parent)
|
||||
{
|
||||
itemHover = 0;
|
||||
// Accept drop
|
||||
setAcceptDrops(true);
|
||||
|
@ -59,7 +60,8 @@ LabelFiltersList::LabelFiltersList(QWidget *parent): QListWidget(parent) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void LabelFiltersList::addItem(QListWidgetItem *it) {
|
||||
void LabelFiltersList::addItem(QListWidgetItem *it)
|
||||
{
|
||||
Q_ASSERT(count() >= 2);
|
||||
for (int i = 2; i<count(); ++i) {
|
||||
if (item(i)->text().localeAwareCompare(it->text()) >= 0) {
|
||||
|
@ -70,7 +72,8 @@ void LabelFiltersList::addItem(QListWidgetItem *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();
|
||||
QStringList parts = label.split(" ");
|
||||
|
@ -79,15 +82,16 @@ QString LabelFiltersList::labelFromRow(int row) const {
|
|||
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) {
|
||||
for (int i = 2; i<count(); ++i)
|
||||
if (label == labelFromRow(i)) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void LabelFiltersList::dragMoveEvent(QDragMoveEvent *event) {
|
||||
void LabelFiltersList::dragMoveEvent(QDragMoveEvent *event)
|
||||
{
|
||||
if (itemAt(event->pos()) && row(itemAt(event->pos())) > 0) {
|
||||
if (itemHover) {
|
||||
if (itemHover != itemAt(event->pos())) {
|
||||
|
@ -95,50 +99,56 @@ void LabelFiltersList::dragMoveEvent(QDragMoveEvent *event) {
|
|||
itemHover = itemAt(event->pos());
|
||||
setItemHover(true);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
itemHover = itemAt(event->pos());
|
||||
setItemHover(true);
|
||||
}
|
||||
event->acceptProposedAction();
|
||||
} else {
|
||||
}
|
||||
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())) {
|
||||
if (itemAt(event->pos()))
|
||||
emit torrentDropped(row(itemAt(event->pos())));
|
||||
}
|
||||
event->ignore();
|
||||
setItemHover(false);
|
||||
// Select current item again
|
||||
currentItem()->setSelected(true);
|
||||
}
|
||||
|
||||
void LabelFiltersList::dragLeaveEvent(QDragLeaveEvent*) {
|
||||
void LabelFiltersList::dragLeaveEvent(QDragLeaveEvent*)
|
||||
{
|
||||
if (itemHover)
|
||||
setItemHover(false);
|
||||
// Select current item again
|
||||
currentItem()->setSelected(true);
|
||||
}
|
||||
|
||||
void LabelFiltersList::setItemHover(bool hover) {
|
||||
void LabelFiltersList::setItemHover(bool hover)
|
||||
{
|
||||
Q_ASSERT(itemHover);
|
||||
if (hover) {
|
||||
itemHover->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("folder-documents.png"));
|
||||
itemHover->setSelected(true);
|
||||
//setCurrentItem(itemHover);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
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);
|
||||
// Height is fixed (sizeHint().height() is used)
|
||||
|
@ -149,14 +159,16 @@ StatusFiltersWidget::StatusFiltersWidget(QWidget *parent) : QListWidget(parent),
|
|||
#endif
|
||||
}
|
||||
|
||||
QSize StatusFiltersWidget::sizeHint() const {
|
||||
QSize StatusFiltersWidget::sizeHint() const
|
||||
{
|
||||
QSize size = QListWidget::sizeHint();
|
||||
// Height should be exactly the height of the content
|
||||
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();
|
||||
vLayout->setContentsMargins(0, 4, 0, 0);
|
||||
|
@ -184,25 +196,25 @@ TransferListFiltersWidget::TransferListFiltersWidget(QWidget *parent, TransferLi
|
|||
// Add status filters
|
||||
QListWidgetItem *all = new QListWidgetItem(statusFilters);
|
||||
all->setData(Qt::DisplayRole, QVariant(tr("All") + " (0)"));
|
||||
all->setData(Qt::DecorationRole, QIcon(":/icons/skin/filterall.png"));
|
||||
all->setData(Qt::DecorationRole, QIcon(":/Icons/skin/filterall.png"));
|
||||
QListWidgetItem *downloading = new QListWidgetItem(statusFilters);
|
||||
downloading->setData(Qt::DisplayRole, QVariant(tr("Downloading") + " (0)"));
|
||||
downloading->setData(Qt::DecorationRole, QIcon(":/icons/skin/downloading.png"));
|
||||
downloading->setData(Qt::DecorationRole, QIcon(":/Icons/skin/downloading.png"));
|
||||
QListWidgetItem *completed = new QListWidgetItem(statusFilters);
|
||||
completed->setData(Qt::DisplayRole, QVariant(tr("Completed") + " (0)"));
|
||||
completed->setData(Qt::DecorationRole, QIcon(":/icons/skin/uploading.png"));
|
||||
QListWidgetItem *paused = new QListWidgetItem(statusFilters);
|
||||
paused->setData(Qt::DisplayRole, QVariant(tr("Paused") + " (0)"));
|
||||
paused->setData(Qt::DecorationRole, QIcon(":/icons/skin/paused.png"));
|
||||
completed->setData(Qt::DecorationRole, QIcon(":/Icons/skin/uploading.png"));
|
||||
QListWidgetItem *resumed = new QListWidgetItem(statusFilters);
|
||||
resumed->setData(Qt::DisplayRole, QVariant(tr("Resumed") + " (0)"));
|
||||
resumed->setData(Qt::DecorationRole, QIcon(":/icons/skin/resumed.png"));
|
||||
resumed->setData(Qt::DecorationRole, QIcon(":/Icons/skin/resumed.png"));
|
||||
QListWidgetItem *paused = new QListWidgetItem(statusFilters);
|
||||
paused->setData(Qt::DisplayRole, QVariant(tr("Paused") + " (0)"));
|
||||
paused->setData(Qt::DecorationRole, QIcon(":/Icons/skin/paused.png"));
|
||||
QListWidgetItem *active = new QListWidgetItem(statusFilters);
|
||||
active->setData(Qt::DisplayRole, QVariant(tr("Active") + " (0)"));
|
||||
active->setData(Qt::DecorationRole, QIcon(":/icons/skin/filteractive.png"));
|
||||
active->setData(Qt::DecorationRole, QIcon(":/Icons/skin/filteractive.png"));
|
||||
QListWidgetItem *inactive = new QListWidgetItem(statusFilters);
|
||||
inactive->setData(Qt::DisplayRole, QVariant(tr("Inactive") + " (0)"));
|
||||
inactive->setData(Qt::DecorationRole, QIcon(":/icons/skin/filterinactive.png"));
|
||||
inactive->setData(Qt::DecorationRole, QIcon(":/Icons/skin/filterinactive.png"));
|
||||
|
||||
// SIGNAL/SLOT
|
||||
connect(statusFilters, SIGNAL(currentRowChanged(int)), transferList, SLOT(applyStatusFilter(int)));
|
||||
|
@ -232,24 +244,28 @@ TransferListFiltersWidget::TransferListFiltersWidget(QWidget *parent, TransferLi
|
|||
connect(labelFilters, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showLabelMenu(QPoint)));
|
||||
}
|
||||
|
||||
TransferListFiltersWidget::~TransferListFiltersWidget() {
|
||||
TransferListFiltersWidget::~TransferListFiltersWidget()
|
||||
{
|
||||
saveSettings();
|
||||
delete statusFilters;
|
||||
delete labelFilters;
|
||||
delete vLayout;
|
||||
}
|
||||
|
||||
StatusFiltersWidget* TransferListFiltersWidget::getStatusFilters() const {
|
||||
StatusFiltersWidget* TransferListFiltersWidget::getStatusFilters() const
|
||||
{
|
||||
return statusFilters;
|
||||
}
|
||||
|
||||
void TransferListFiltersWidget::saveSettings() const {
|
||||
void TransferListFiltersWidget::saveSettings() const
|
||||
{
|
||||
Preferences* const pref = Preferences::instance();
|
||||
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();
|
||||
foreach (const QString &label, label_list) {
|
||||
|
@ -262,7 +278,8 @@ void TransferListFiltersWidget::loadSettings() {
|
|||
}
|
||||
}
|
||||
|
||||
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) + ")"));
|
||||
statusFilters->item(TorrentFilter::DOWNLOADING)->setData(Qt::DisplayRole, QVariant(tr("Downloading") + " (" + QString::number(report.nb_downloading) + ")"));
|
||||
|
@ -273,16 +290,17 @@ void TransferListFiltersWidget::updateTorrentNumbers() {
|
|||
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) {
|
||||
if (row == 1)
|
||||
transferList->setSelectionLabel("");
|
||||
} else {
|
||||
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;
|
||||
QListWidgetItem *newLabel = new QListWidgetItem();
|
||||
|
@ -293,7 +311,8 @@ void TransferListFiltersWidget::addLabel(QString& label) {
|
|||
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..."));
|
||||
QAction *removeAct = 0;
|
||||
|
@ -339,7 +358,8 @@ void TransferListFiltersWidget::showLabelMenu(QPoint) {
|
|||
if (ok && !label.isEmpty()) {
|
||||
if (fsutils::isValidFileSystemName(label)) {
|
||||
addLabel(label);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
QMessageBox::warning(this, tr("Invalid label name"), tr("Please don't use any special characters in the label name."));
|
||||
invalid = true;
|
||||
}
|
||||
|
@ -350,7 +370,8 @@ void TransferListFiltersWidget::showLabelMenu(QPoint) {
|
|||
}
|
||||
}
|
||||
|
||||
void TransferListFiltersWidget::removeSelectedLabel() {
|
||||
void TransferListFiltersWidget::removeSelectedLabel()
|
||||
{
|
||||
const int row = labelFilters->row(labelFilters->selectedItems().first());
|
||||
Q_ASSERT(row > 1);
|
||||
const QString &label = labelFilters->labelFromRow(row);
|
||||
|
@ -367,13 +388,13 @@ void TransferListFiltersWidget::removeSelectedLabel() {
|
|||
Preferences::instance()->removeTorrentLabel(label);
|
||||
}
|
||||
|
||||
void TransferListFiltersWidget::removeUnusedLabels() {
|
||||
void TransferListFiltersWidget::removeUnusedLabels()
|
||||
{
|
||||
QStringList unusedLabels;
|
||||
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)
|
||||
unusedLabels << i.key();
|
||||
}
|
||||
foreach (const QString &label, unusedLabels) {
|
||||
customLabels.remove(label);
|
||||
delete labelFilters->takeItem(labelFilters->rowFromLabel(label));
|
||||
|
@ -381,7 +402,8 @@ void TransferListFiltersWidget::removeUnusedLabels() {
|
|||
}
|
||||
}
|
||||
|
||||
void TransferListFiltersWidget::applyLabelFilter(int row) {
|
||||
void TransferListFiltersWidget::applyLabelFilter(int row)
|
||||
{
|
||||
switch (row) {
|
||||
case 0:
|
||||
transferList->applyLabelFilterAll();
|
||||
|
@ -394,7 +416,8 @@ void TransferListFiltersWidget::applyLabelFilter(int 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));
|
||||
if (!old_label.isEmpty()) {
|
||||
|
@ -422,7 +445,8 @@ void TransferListFiltersWidget::torrentChangedLabel(TorrentModelItem *torrentIte
|
|||
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));
|
||||
if (!label.isEmpty()) {
|
||||
|
@ -449,7 +473,8 @@ void TransferListFiltersWidget::handleNewTorrent(TorrentModelItem* torrentItem)
|
|||
updateStickyLabelCounters();
|
||||
}
|
||||
|
||||
void TransferListFiltersWidget::torrentAboutToBeDeleted(TorrentModelItem* torrentItem) {
|
||||
void TransferListFiltersWidget::torrentAboutToBeDeleted(TorrentModelItem* torrentItem)
|
||||
{
|
||||
Q_ASSERT(torrentItem);
|
||||
QString label = torrentItem->data(TorrentModelItem::TR_LABEL).toString();
|
||||
if (!label.isEmpty()) {
|
||||
|
@ -469,7 +494,8 @@ void TransferListFiltersWidget::torrentAboutToBeDeleted(TorrentModelItem* torren
|
|||
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) + ")");
|
||||
}
|
||||
|
|
|
@ -43,7 +43,8 @@ QT_END_NAMESPACE
|
|||
class TransferListWidget;
|
||||
class TorrentModelItem;
|
||||
|
||||
class LabelFiltersList: public QListWidget {
|
||||
class LabelFiltersList: public QListWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
|
@ -68,7 +69,8 @@ protected:
|
|||
void setItemHover(bool hover);
|
||||
};
|
||||
|
||||
class StatusFiltersWidget : public QListWidget {
|
||||
class StatusFiltersWidget: public QListWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
@ -81,7 +83,8 @@ private:
|
|||
bool m_shown;
|
||||
};
|
||||
|
||||
class TransferListFiltersWidget: public QFrame {
|
||||
class TransferListFiltersWidget: public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
|
|
|
@ -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_FIRST_LAST_PIECE_PRIO[] = "f_l_piece_prio";
|
||||
static const char KEY_TORRENT_LABEL[] = "label";
|
||||
static const char KEY_TORRENT_SUPER_SEEDING[] = "super_seeding";
|
||||
|
||||
// Tracker keys
|
||||
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_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_RESPONSE_ID[] = "rid";
|
||||
static const char KEY_SUFFIX_REMOVED[] = "_removed";
|
||||
|
@ -151,7 +157,7 @@ static const char KEY_SUFFIX_REMOVED[] = "_removed";
|
|||
QVariantMap getTranserInfoMap();
|
||||
QVariantMap toMap(const QTorrentHandle& h);
|
||||
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);
|
||||
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
|
||||
* - "labels": list of labels
|
||||
* - "labels_removed": list of removed labels
|
||||
* - "queueing": priority system usage flag
|
||||
* - "server_state": map contains information about the status of the server
|
||||
* - "server_state": map contains information about the state of the server
|
||||
* The keys of the 'torrents' dictionary are hashes of torrents.
|
||||
* Each value of the 'torrents' dictionary contains map. The map can contain following keys:
|
||||
* - "name": Torrent name
|
||||
|
@ -302,6 +307,8 @@ QByteArray btjson::getTorrents(QString filter, QString label,
|
|||
* - "up_info_data: bytes uploaded
|
||||
* - "up_info_speed: upload speed
|
||||
* - "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)
|
||||
{
|
||||
|
@ -321,14 +328,18 @@ QByteArray btjson::getSyncMainData(int acceptedResponseId, QVariantMap &lastData
|
|||
}
|
||||
|
||||
data["torrents"] = torrents;
|
||||
data["queueing"] = QBtSession::instance()->isQueueingEnabled();
|
||||
|
||||
QVariantList labels;
|
||||
foreach (QString s, Preferences::instance()->getTorrentLabels())
|
||||
labels << s;
|
||||
|
||||
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));
|
||||
}
|
||||
|
@ -528,6 +539,21 @@ QVariantMap getTranserInfoMap()
|
|||
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)
|
||||
{
|
||||
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())
|
||||
ret[KEY_TORRENT_FIRST_LAST_PIECE_PRIO] = h.first_last_piece_first();
|
||||
ret[KEY_TORRENT_LABEL] = TorrentPersistentData::instance()->getLabel(h.hash());
|
||||
ret[KEY_TORRENT_SUPER_SEEDING] = status.super_seeding;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -579,10 +606,10 @@ void processMap(QVariantMap prevData, QVariantMap data, QVariantMap &syncData)
|
|||
}
|
||||
break;
|
||||
case QVariant::Hash: {
|
||||
QVariantHash hash;
|
||||
processHash(prevData[key].toHash(), data[key].toHash(), hash, removedItems);
|
||||
if (!hash.isEmpty())
|
||||
syncData[key] = hash;
|
||||
QVariantMap map;
|
||||
processHash(prevData[key].toHash(), data[key].toHash(), map, removedItems);
|
||||
if (!map.isEmpty())
|
||||
syncData[key] = map;
|
||||
if (!removedItems.isEmpty())
|
||||
syncData[key + KEY_SUFFIX_REMOVED] = removedItems;
|
||||
}
|
||||
|
@ -603,6 +630,7 @@ void processMap(QVariantMap prevData, QVariantMap data, QVariantMap &syncData)
|
|||
case QVariant::Bool:
|
||||
case QVariant::Double:
|
||||
case QVariant::ULongLong:
|
||||
case QVariant::UInt:
|
||||
if (prevData[key] != data[key])
|
||||
syncData[key] = data[key];
|
||||
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).
|
||||
// Structures encoded as map.
|
||||
// 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
|
||||
syncData.clear();
|
||||
|
@ -623,7 +651,8 @@ void processHash(QVariantHash prevData, QVariantHash data, QVariantHash &syncDat
|
|||
|
||||
if (prevData.isEmpty()) {
|
||||
// If list was empty before, then difference is a whole new list.
|
||||
syncData = data;
|
||||
foreach (QString key, data.keys())
|
||||
syncData[key] = data[key];
|
||||
}
|
||||
else {
|
||||
foreach (QString key, data.keys()) {
|
||||
|
|
|
@ -52,6 +52,7 @@ public:
|
|||
static QByteArray getPropertiesForTorrent(const QString& hash);
|
||||
static QByteArray getFilesForTorrent(const QString& hash);
|
||||
static QByteArray getTransferInfo();
|
||||
static QByteArray getTorrentsRatesLimits(QStringList& hashes, bool downloadLimits);
|
||||
}; // class btjson
|
||||
|
||||
#endif // BTJSON_H
|
||||
|
|
|
@ -45,9 +45,11 @@ namespace json {
|
|||
inline QByteArray toJson(const QVariant& var)
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
return QJsonDocument::fromVariant(var).toJson();
|
||||
return QJsonDocument::fromVariant(var).toJson(QJsonDocument::Compact);
|
||||
#else
|
||||
return QJson::Serializer().serialize(var);
|
||||
QJson::Serializer serializer;
|
||||
serializer.setIndentMode(QJson::IndentCompact);
|
||||
return serializer.serialize(var);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,8 @@ QTorrentFilter::QTorrentFilter(QString filter, QString label)
|
|||
type_ = Completed;
|
||||
else if (filter == "paused")
|
||||
type_ = Paused;
|
||||
else if (filter == "resumed")
|
||||
type_ = Resumed;
|
||||
else if (filter == "active")
|
||||
type_ = Active;
|
||||
else if (filter == "inactive")
|
||||
|
@ -57,6 +59,8 @@ bool QTorrentFilter::apply(const QTorrentHandle& h) const
|
|||
return isTorrentCompleted(h);
|
||||
case Paused:
|
||||
return isTorrentPaused(h);
|
||||
case Resumed:
|
||||
return isTorrentResumed(h);
|
||||
case Active:
|
||||
return isTorrentActive(h);
|
||||
case Inactive:
|
||||
|
@ -98,6 +102,14 @@ bool QTorrentFilter::isTorrentPaused(const QTorrentHandle &h) const
|
|||
|| 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
|
||||
{
|
||||
const QTorrentState state = h.torrentState();
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
Downloading,
|
||||
Completed,
|
||||
Paused,
|
||||
Resumed,
|
||||
Active,
|
||||
Inactive
|
||||
};
|
||||
|
@ -55,6 +56,7 @@ private:
|
|||
bool isTorrentDownloading(const QTorrentHandle &h) const;
|
||||
bool isTorrentCompleted(const QTorrentHandle &h) const;
|
||||
bool isTorrentPaused(const QTorrentHandle &h) const;
|
||||
bool isTorrentResumed(const QTorrentHandle &h) const;
|
||||
bool isTorrentActive(const QTorrentHandle &h) const;
|
||||
bool isTorrentInactive(const QTorrentHandle &h) const;
|
||||
bool torrentHasLabel(const QTorrentHandle &h) const;
|
||||
|
|
|
@ -94,14 +94,15 @@ QMap<QString, QMap<QString, WebApplication::Action> > WebApplication::initialize
|
|||
ADD_ACTION(command, getGlobalDlLimit);
|
||||
ADD_ACTION(command, setGlobalUpLimit);
|
||||
ADD_ACTION(command, setGlobalDlLimit);
|
||||
ADD_ACTION(command, getTorrentUpLimit);
|
||||
ADD_ACTION(command, getTorrentDlLimit);
|
||||
ADD_ACTION(command, setTorrentUpLimit);
|
||||
ADD_ACTION(command, setTorrentDlLimit);
|
||||
ADD_ACTION(command, getTorrentsUpLimit);
|
||||
ADD_ACTION(command, getTorrentsDlLimit);
|
||||
ADD_ACTION(command, setTorrentsUpLimit);
|
||||
ADD_ACTION(command, setTorrentsDlLimit);
|
||||
ADD_ACTION(command, alternativeSpeedLimitsEnabled);
|
||||
ADD_ACTION(command, toggleAlternativeSpeedLimits);
|
||||
ADD_ACTION(command, toggleSequentialDownload);
|
||||
ADD_ACTION(command, toggleFirstLastPiecePrio);
|
||||
ADD_ACTION(command, setSuperSeeding);
|
||||
ADD_ACTION(command, delete);
|
||||
ADD_ACTION(command, deletePerm);
|
||||
ADD_ACTION(command, increasePrio);
|
||||
|
@ -212,7 +213,7 @@ void WebApplication::action_public_images()
|
|||
}
|
||||
|
||||
// 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")
|
||||
// - sort (string): name of column for sorting by its value
|
||||
// - reverse (bool): enable reverse sorting
|
||||
|
@ -453,53 +454,55 @@ void WebApplication::action_command_setGlobalDlLimit()
|
|||
Preferences::instance()->setGlobalDownloadLimit(limit / 1024.);
|
||||
}
|
||||
|
||||
void WebApplication::action_command_getTorrentUpLimit()
|
||||
void WebApplication::action_command_getTorrentsUpLimit()
|
||||
{
|
||||
CHECK_URI(0);
|
||||
CHECK_PARAMETERS("hash");
|
||||
QString hash = request().posts["hash"];
|
||||
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
|
||||
|
||||
if (h.is_valid())
|
||||
print(QByteArray::number(h.upload_limit()));
|
||||
CHECK_PARAMETERS("hashes");
|
||||
QStringList hashes = request().posts["hashes"].split("|");
|
||||
print(btjson::getTorrentsRatesLimits(hashes, false), Http::CONTENT_TYPE_JS);
|
||||
}
|
||||
|
||||
void WebApplication::action_command_getTorrentDlLimit()
|
||||
void WebApplication::action_command_getTorrentsDlLimit()
|
||||
{
|
||||
CHECK_URI(0);
|
||||
CHECK_PARAMETERS("hash");
|
||||
QString hash = request().posts["hash"];
|
||||
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
|
||||
|
||||
if (h.is_valid())
|
||||
print(QByteArray::number(h.download_limit()));
|
||||
CHECK_PARAMETERS("hashes");
|
||||
QStringList hashes = request().posts["hashes"].split("|");
|
||||
print(btjson::getTorrentsRatesLimits(hashes, true), Http::CONTENT_TYPE_JS);
|
||||
}
|
||||
|
||||
void WebApplication::action_command_setTorrentUpLimit()
|
||||
void WebApplication::action_command_setTorrentsUpLimit()
|
||||
{
|
||||
CHECK_URI(0);
|
||||
CHECK_PARAMETERS("hash" << "limit");
|
||||
QString hash = request().posts["hash"];
|
||||
CHECK_PARAMETERS("hashes" << "limit");
|
||||
|
||||
qlonglong limit = request().posts["limit"].toLongLong();
|
||||
if (limit == 0) limit = -1;
|
||||
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
|
||||
if (limit == 0)
|
||||
limit = -1;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void WebApplication::action_command_setTorrentDlLimit()
|
||||
void WebApplication::action_command_setTorrentsDlLimit()
|
||||
{
|
||||
CHECK_URI(0);
|
||||
CHECK_PARAMETERS("hash" << "limit");
|
||||
QString hash = request().posts["hash"];
|
||||
qlonglong limit = request().posts["limit"].toLongLong();
|
||||
if (limit == 0) limit = -1;
|
||||
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
|
||||
CHECK_PARAMETERS("hashes" << "limit");
|
||||
|
||||
qlonglong limit = request().posts["limit"].toLongLong();
|
||||
if (limit == 0)
|
||||
limit = -1;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
CHECK_URI(0);
|
||||
|
|
|
@ -68,14 +68,15 @@ private:
|
|||
void action_command_getGlobalDlLimit();
|
||||
void action_command_setGlobalUpLimit();
|
||||
void action_command_setGlobalDlLimit();
|
||||
void action_command_getTorrentUpLimit();
|
||||
void action_command_getTorrentDlLimit();
|
||||
void action_command_setTorrentUpLimit();
|
||||
void action_command_setTorrentDlLimit();
|
||||
void action_command_getTorrentsUpLimit();
|
||||
void action_command_getTorrentsDlLimit();
|
||||
void action_command_setTorrentsUpLimit();
|
||||
void action_command_setTorrentsDlLimit();
|
||||
void action_command_alternativeSpeedLimitsEnabled();
|
||||
void action_command_toggleAlternativeSpeedLimits();
|
||||
void action_command_toggleSequentialDownload();
|
||||
void action_command_toggleFirstLastPiecePrio();
|
||||
void action_command_setSuperSeeding();
|
||||
void action_command_delete();
|
||||
void action_command_deletePerm();
|
||||
void action_command_increasePrio();
|
||||
|
|
|
@ -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 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 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>
|
||||
</ul>
|
||||
<div id="desktopFooterWrapper">
|
||||
|
|
|
@ -20,10 +20,10 @@
|
|||
<div class="clear"></div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
var hash = new URI().getData('hash');
|
||||
var hashes = new URI().getData('hashes').split('|');
|
||||
setDlLimit = function() {
|
||||
var limit = $("dllimitUpdatevalue").value.toInt() * 1024;
|
||||
if (hash == "global") {
|
||||
if (hashes[0] == "global") {
|
||||
new Request({
|
||||
url: 'command/setGlobalDlLimit',
|
||||
method: 'post',
|
||||
|
@ -38,10 +38,10 @@
|
|||
}
|
||||
else {
|
||||
new Request({
|
||||
url: 'command/setTorrentDlLimit',
|
||||
url: 'command/setTorrentsDlLimit',
|
||||
method: 'post',
|
||||
data: {
|
||||
'hash': hash,
|
||||
'hashes': hashes.join('|'),
|
||||
'limit': limit
|
||||
},
|
||||
onComplete: function() {
|
||||
|
@ -55,7 +55,7 @@
|
|||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
MochaUI.addDlLimitSlider(hash);
|
||||
MochaUI.addDlLimitSlider(hashes);
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
|
|
@ -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="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="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="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>
|
||||
|
|
|
@ -27,6 +27,8 @@ myTable = new dynamicTable();
|
|||
var updatePropertiesPanel = function(){};
|
||||
var updateMainData = function(){};
|
||||
var alternativeSpeedLimits = false;
|
||||
var queueing_enabled = true;
|
||||
var syncMainDataTimerPeriod = 1500;
|
||||
|
||||
selected_filter = getLocalStorageItem('selected_filter', 'all');
|
||||
selected_label = null;
|
||||
|
@ -95,6 +97,7 @@ window.addEvent('load', function () {
|
|||
$("downloading_filter").removeClass("selectedFilter");
|
||||
$("completed_filter").removeClass("selectedFilter");
|
||||
$("paused_filter").removeClass("selectedFilter");
|
||||
$("resumed_filter").removeClass("selectedFilter");
|
||||
$("active_filter").removeClass("selectedFilter");
|
||||
$("inactive_filter").removeClass("selectedFilter");
|
||||
$(f + "_filter").addClass("selectedFilter");
|
||||
|
@ -153,19 +156,6 @@ window.addEvent('load', function () {
|
|||
myTable.rows.erase();
|
||||
if (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'])
|
||||
for (var key in response['torrents']) {
|
||||
response['torrents'][key]['hash'] = key;
|
||||
|
@ -185,7 +175,7 @@ window.addEvent('load', function () {
|
|||
}
|
||||
}
|
||||
clearTimeout(syncMainDataTimer);
|
||||
syncMainDataTimer = syncMainData.delay(1500);
|
||||
syncMainDataTimer = syncMainData.delay(syncMainDataTimerPeriod);
|
||||
}
|
||||
}).send();
|
||||
};
|
||||
|
@ -220,6 +210,29 @@ window.addEvent('load', function () {
|
|||
$('connectionStatus').src = 'images/skin/firewalled.png';
|
||||
else
|
||||
$('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) {
|
||||
|
@ -229,16 +242,6 @@ window.addEvent('load', function () {
|
|||
$('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() {
|
||||
// Change icon immediately to give some feedback
|
||||
updateAltSpeedIcon(!alternativeSpeedLimits);
|
||||
|
@ -354,11 +357,20 @@ window.addEvent('load', function () {
|
|||
|
||||
function closeWindows() {
|
||||
MochaUI.closeAll();
|
||||
}
|
||||
};
|
||||
|
||||
window.addEvent('keydown', function (event) {
|
||||
if (event.key == 'a' && event.control) {
|
||||
event.stop();
|
||||
var keyboardEvents = new Keyboard({
|
||||
defaultEventType: 'keydown',
|
||||
events: {
|
||||
'ctrl+a': function(event) {
|
||||
myTable.selectAll();
|
||||
event.preventDefault();
|
||||
},
|
||||
'delete': function(event) {
|
||||
deleteFN();
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
keyboardEvents.activate();
|
||||
|
|
|
@ -136,6 +136,7 @@ var ContextMenu = new Class({
|
|||
all_are_downloaded = true;
|
||||
all_are_paused = true;
|
||||
there_are_paused = false;
|
||||
all_are_super_seeding = true;
|
||||
|
||||
var h = myTable.selectedIds();
|
||||
h.each(function(item, index){
|
||||
|
@ -153,6 +154,8 @@ var ContextMenu = new Class({
|
|||
|
||||
if (data['progress'] != 1.0) // not downloaded
|
||||
all_are_downloaded = false;
|
||||
else if (data['super_seeding'] != true)
|
||||
all_are_super_seeding = false;
|
||||
|
||||
state = data['state'];
|
||||
if ((state != 'pausedUP') && (state != 'pausedDL'))
|
||||
|
@ -174,6 +177,8 @@ var ContextMenu = new Class({
|
|||
if (all_are_downloaded) {
|
||||
this.hideItem('SequentialDownload');
|
||||
this.hideItem('FirstLastPiecePrio');
|
||||
this.showItem('SuperSeeding');
|
||||
this.setItemChecked('SuperSeeding', all_are_super_seeding);
|
||||
} else {
|
||||
if (!show_seq_dl && show_f_l_piece_prio)
|
||||
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('FirstLastPiecePrio', all_are_f_l_piece_prio);
|
||||
|
||||
this.hideItem('SuperSeeding');
|
||||
}
|
||||
|
||||
if (all_are_paused) {
|
||||
|
@ -234,6 +241,10 @@ var ContextMenu = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
getItemChecked: function(item) {
|
||||
return '0' != this.menu.getElement('a[href$=' + item + ']').firstChild.style.opacity;
|
||||
},
|
||||
|
||||
//hide an item
|
||||
hideItem: function(item) {
|
||||
this.menu.getElement('a[href$=' + item + ']').parentNode.addClass('invisible');
|
||||
|
|
|
@ -261,6 +261,10 @@ var dynamicTable = new Class({
|
|||
if (!~state.indexOf('paused'))
|
||||
return false;
|
||||
break;
|
||||
case 'resumed':
|
||||
if (~state.indexOf('paused'))
|
||||
return false;
|
||||
break;
|
||||
case 'active':
|
||||
if ((state != 'uploading') && (state != 'downloading'))
|
||||
return false;
|
||||
|
@ -352,6 +356,17 @@ var dynamicTable = new Class({
|
|||
myTable.selectRow(this.hash);
|
||||
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) {
|
||||
e.stop();
|
||||
if (e.control) {
|
||||
|
|
|
@ -38,11 +38,11 @@ function friendlyDuration(seconds) {
|
|||
if (minutes < 60)
|
||||
return "QBT_TR(%1m)QBT_TR".replace("%1", parseInt(minutes));
|
||||
var hours = minutes / 60;
|
||||
minutes = minutes - hours * 60;
|
||||
minutes = minutes % 60;
|
||||
if (hours < 24)
|
||||
return "QBT_TR(%1h %2m)QBT_TR".replace("%1", parseInt(hours)).replace("%2", parseInt(minutes))
|
||||
var days = hours / 24;
|
||||
hours = hours - days * 24;
|
||||
hours = hours % 24;
|
||||
if (days < 100)
|
||||
return "QBT_TR(%1d %2h)QBT_TR".replace("%1", parseInt(days)).replace("%2", parseInt(hours))
|
||||
return "∞";
|
||||
|
|
|
@ -29,6 +29,10 @@ function getLocalStorageItem(name, defaultVal) {
|
|||
return val;
|
||||
}
|
||||
|
||||
var deleteFN = function() {};
|
||||
var startFN = function() {};
|
||||
var pauseFN = function() {};
|
||||
|
||||
initializeWindows = function() {
|
||||
|
||||
function addClickEvent(el, fn) {
|
||||
|
@ -103,7 +107,7 @@ initializeWindows = function() {
|
|||
id: 'uploadLimitPage',
|
||||
title: "QBT_TR(Global Upload Speed Limit)QBT_TR",
|
||||
loadMethod: 'iframe',
|
||||
contentURL: 'uploadlimit.html?hash=global',
|
||||
contentURL: 'uploadlimit.html?hashes=global',
|
||||
scrollbars: false,
|
||||
resizable: false,
|
||||
maximizable: false,
|
||||
|
@ -122,7 +126,7 @@ initializeWindows = function() {
|
|||
id: 'uploadLimitPage',
|
||||
title: "QBT_TR(Torrent Upload Speed Limiting)QBT_TR",
|
||||
loadMethod: 'iframe',
|
||||
contentURL: 'uploadlimit.html?hash=' + hash,
|
||||
contentURL: 'uploadlimit.html?hashes=' + h.join("|"),
|
||||
scrollbars: false,
|
||||
resizable: 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() {
|
||||
new MochaUI.Window({
|
||||
id: 'downloadLimitPage',
|
||||
title: "QBT_TR(Global Download Speed Limit)QBT_TR",
|
||||
loadMethod: 'iframe',
|
||||
contentURL: 'downloadlimit.html?hash=global',
|
||||
contentURL: 'downloadlimit.html?hashes=global',
|
||||
scrollbars: false,
|
||||
resizable: false,
|
||||
maximizable: false,
|
||||
|
@ -186,7 +205,7 @@ initializeWindows = function() {
|
|||
id: 'downloadLimitPage',
|
||||
title: "QBT_TR(Torrent Download Speed Limiting)QBT_TR",
|
||||
loadMethod: 'iframe',
|
||||
contentURL: 'downloadlimit.html?hash=' + hash,
|
||||
contentURL: 'downloadlimit.html?hashes=' + h.join("|"),
|
||||
scrollbars: false,
|
||||
resizable: 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) {
|
||||
new Event(e).stop();
|
||||
var h = myTable.selectedIds();
|
||||
|
|
|
@ -14,7 +14,7 @@ Requires:
|
|||
|
||||
*/
|
||||
MochaUI.extend({
|
||||
addUpLimitSlider: function(hash) {
|
||||
addUpLimitSlider: function(hashes) {
|
||||
if ($('uplimitSliderarea')) {
|
||||
var windowOptions = MochaUI.Windows.windowOptions;
|
||||
var sliderFirst = true;
|
||||
|
@ -31,15 +31,15 @@ MochaUI.extend({
|
|||
maximum = tmp / 1024.
|
||||
}
|
||||
else {
|
||||
if (hash == "global")
|
||||
if (hashes[0] == "global")
|
||||
maximum = 10000;
|
||||
else
|
||||
maximum = 1000;
|
||||
}
|
||||
}
|
||||
// Get torrent upload limit
|
||||
// Get torrents upload limit
|
||||
// And create slider
|
||||
if (hash == 'global') {
|
||||
if (hashes[0] == 'global') {
|
||||
var up_limit = maximum;
|
||||
if (up_limit < 0) up_limit = 0;
|
||||
maximum = 10000;
|
||||
|
@ -69,15 +69,21 @@ MochaUI.extend({
|
|||
}
|
||||
}
|
||||
else {
|
||||
var req = new Request({
|
||||
url: 'command/getTorrentUpLimit',
|
||||
var req = new Request.JSON({
|
||||
url: 'command/getTorrentsUpLimit',
|
||||
noCache : true,
|
||||
method: 'post',
|
||||
data: {
|
||||
hash: hash
|
||||
hashes: hashes.join('|')
|
||||
},
|
||||
onSuccess: function(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;
|
||||
var mochaSlide = new Slider($('uplimitSliderarea'), $('uplimitSliderknob'), {
|
||||
steps: maximum,
|
||||
|
@ -112,7 +118,7 @@ MochaUI.extend({
|
|||
}
|
||||
},
|
||||
|
||||
addDlLimitSlider: function(hash) {
|
||||
addDlLimitSlider: function(hashes) {
|
||||
if ($('dllimitSliderarea')) {
|
||||
var windowOptions = MochaUI.Windows.windowOptions;
|
||||
var sliderFirst = true;
|
||||
|
@ -129,15 +135,15 @@ MochaUI.extend({
|
|||
maximum = tmp / 1024.
|
||||
}
|
||||
else {
|
||||
if (hash == "global")
|
||||
if (hashes[0] == "global")
|
||||
maximum = 10000;
|
||||
else
|
||||
maximum = 1000;
|
||||
}
|
||||
}
|
||||
// Get torrent download limit
|
||||
// Get torrents download limit
|
||||
// And create slider
|
||||
if (hash == "global") {
|
||||
if (hashes[0] == 'global') {
|
||||
var dl_limit = maximum;
|
||||
if (dl_limit < 0) dl_limit = 0;
|
||||
maximum = 10000;
|
||||
|
@ -167,15 +173,21 @@ MochaUI.extend({
|
|||
}
|
||||
}
|
||||
else {
|
||||
var req = new Request({
|
||||
url: 'command/getTorrentDlLimit',
|
||||
var req = new Request.JSON({
|
||||
url: 'command/getTorrentsDlLimit',
|
||||
noCache : true,
|
||||
method: 'post',
|
||||
data: {
|
||||
hash: hash
|
||||
hashes: hashes.join('|')
|
||||
},
|
||||
onSuccess: function(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;
|
||||
var mochaSlide = new Slider($('dllimitSliderarea'), $('dllimitSliderknob'), {
|
||||
steps: maximum,
|
||||
|
|
|
@ -37,7 +37,7 @@ var ProgressBar = new Class({
|
|||
'text-align': 'center',
|
||||
'left': 0,
|
||||
'top': 0,
|
||||
'line-height': vals.height - 2
|
||||
'line-height': vals.height
|
||||
}
|
||||
});
|
||||
obj.vals.light = new Element('div', {
|
||||
|
@ -52,7 +52,7 @@ var ProgressBar = new Class({
|
|||
'text-align': 'center',
|
||||
'left': 0,
|
||||
'top': 0,
|
||||
'line-height': vals.height - 2
|
||||
'line-height': vals.height
|
||||
}
|
||||
});
|
||||
obj.appendChild(obj.vals.dark);
|
||||
|
|
|
@ -51,6 +51,9 @@
|
|||
},
|
||||
FirstLastPiecePrio : function (element, ref) {
|
||||
toggleFirstLastPiecePrioFN();
|
||||
},
|
||||
SuperSeeding : function (element, ref) {
|
||||
setSuperSeedingFN(!ref.getItemChecked('SuperSeeding'));
|
||||
}
|
||||
},
|
||||
offsets : {
|
||||
|
|
|
@ -20,10 +20,10 @@
|
|||
<div class="clear"></div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
var hash = new URI().getData('hash');
|
||||
var hashes = new URI().getData('hashes').split('|');
|
||||
setUpLimit = function() {
|
||||
var limit = $("uplimitUpdatevalue").value.toInt() * 1024;
|
||||
if (hash == "global") {
|
||||
if (hashes[0] == "global") {
|
||||
new Request({
|
||||
url: 'command/setGlobalUpLimit',
|
||||
method: 'post',
|
||||
|
@ -38,10 +38,10 @@
|
|||
}
|
||||
else {
|
||||
new Request({
|
||||
url: 'command/setTorrentUpLimit',
|
||||
url: 'command/setTorrentsUpLimit',
|
||||
method: 'post',
|
||||
data: {
|
||||
'hash': hash,
|
||||
'hashes': hashes.join('|'),
|
||||
'limit': limit
|
||||
},
|
||||
onComplete: function() {
|
||||
|
@ -55,7 +55,7 @@
|
|||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
MochaUI.addUpLimitSlider(hash);
|
||||
MochaUI.addUpLimitSlider(hashes);
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue