2009-11-08 17:20:58 +03:00
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt4 and libtorrent.
|
|
|
|
* Copyright (C) 2006 Christophe Dumez
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give permission to
|
|
|
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
|
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
|
|
* and distribute the linked executables. You must obey the GNU General Public
|
|
|
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
|
|
* modify file(s), you may extend this exception to your version of the file(s),
|
|
|
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
|
|
|
* exception statement from your version.
|
|
|
|
*
|
|
|
|
* Contact : chris@qbittorrent.org
|
|
|
|
*/
|
|
|
|
|
2009-11-08 18:41:32 +03:00
|
|
|
#include <QTimer>
|
2009-11-08 19:19:21 +03:00
|
|
|
#include <QListWidgetItem>
|
2009-11-08 18:41:32 +03:00
|
|
|
#include <QVBoxLayout>
|
2009-11-08 19:19:21 +03:00
|
|
|
#include <QStackedWidget>
|
2009-11-08 22:09:10 +03:00
|
|
|
#include <QSplitter>
|
2009-11-29 00:46:46 +03:00
|
|
|
#include <QHeaderView>
|
2009-11-09 11:56:21 +03:00
|
|
|
#include <QAction>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QInputDialog>
|
2009-11-08 17:20:58 +03:00
|
|
|
#include "propertieswidget.h"
|
2009-11-20 10:48:44 +03:00
|
|
|
#include "transferlistwidget.h"
|
|
|
|
#include "torrentpersistentdata.h"
|
2009-11-08 19:19:21 +03:00
|
|
|
#include "bittorrent.h"
|
2009-11-20 10:48:44 +03:00
|
|
|
#include "proplistdelegate.h"
|
|
|
|
#include "torrentfilesmodel.h"
|
2009-11-14 13:37:45 +03:00
|
|
|
#include "peerlistwidget.h"
|
2009-11-19 14:09:03 +03:00
|
|
|
#include "trackerlist.h"
|
2009-11-21 17:16:54 +03:00
|
|
|
#include "GUI.h"
|
2009-11-21 21:36:12 +03:00
|
|
|
#include "downloadedpiecesbar.h"
|
2009-11-21 22:40:24 +03:00
|
|
|
#include "pieceavailabilitybar.h"
|
2009-11-08 17:20:58 +03:00
|
|
|
|
2009-11-17 11:32:52 +03:00
|
|
|
#ifdef Q_WS_MAC
|
2009-11-23 00:50:05 +03:00
|
|
|
#define DEFAULT_BUTTON_CSS "QPushButton {border: 1px solid rgb(85, 81, 91);border-radius: 3px;padding: 2px; margin-left: 8px; margin-right: 8px;}"
|
|
|
|
#define SELECTED_BUTTON_CSS "QPushButton {border: 1px solid rgb(85, 81, 91);border-radius: 3px;padding: 2px;background-color: rgb(255, 208, 105); margin-left: 8px; margin-right: 8px;}"
|
2009-11-17 11:32:52 +03:00
|
|
|
#else
|
2009-11-17 13:03:07 +03:00
|
|
|
#define DEFAULT_BUTTON_CSS "QPushButton {border: 1px solid rgb(85, 81, 91);border-radius: 3px;padding: 2px; margin-left: 3px; margin-right: 3px;}"
|
|
|
|
#define SELECTED_BUTTON_CSS "QPushButton {border: 1px solid rgb(85, 81, 91);border-radius: 3px;padding: 2px;background-color: rgb(255, 208, 105); margin-left: 3px; margin-right: 3px;}"
|
2009-11-17 11:32:52 +03:00
|
|
|
#endif
|
2009-11-08 19:39:17 +03:00
|
|
|
|
2009-11-21 17:16:54 +03:00
|
|
|
PropertiesWidget::PropertiesWidget(QWidget *parent, GUI* main_window, TransferListWidget *transferList, Bittorrent* BTSession):
|
|
|
|
QWidget(parent), transferList(transferList), main_window(main_window), BTSession(BTSession) {
|
2009-11-08 17:20:58 +03:00
|
|
|
setupUi(this);
|
2009-11-08 22:09:10 +03:00
|
|
|
state = VISIBLE;
|
2009-11-25 00:38:11 +03:00
|
|
|
setEnabled(false);
|
2009-11-17 11:32:52 +03:00
|
|
|
// Buttons stylesheet
|
|
|
|
trackers_button->setStyleSheet(DEFAULT_BUTTON_CSS);
|
|
|
|
peers_button->setStyleSheet(DEFAULT_BUTTON_CSS);
|
|
|
|
url_seeds_button->setStyleSheet(DEFAULT_BUTTON_CSS);
|
|
|
|
files_button->setStyleSheet(DEFAULT_BUTTON_CSS);
|
|
|
|
main_infos_button->setStyleSheet(DEFAULT_BUTTON_CSS);
|
2009-11-18 15:11:15 +03:00
|
|
|
main_infos_button->setShortcut(QKeySequence(QString::fromUtf8("Alt+P")));
|
2009-11-17 11:32:52 +03:00
|
|
|
|
2009-11-09 11:56:21 +03:00
|
|
|
// Set Properties list model
|
2009-11-11 15:22:48 +03:00
|
|
|
PropListModel = new TorrentFilesModel();
|
2009-11-09 11:56:21 +03:00
|
|
|
filesList->setModel(PropListModel);
|
2009-11-24 18:38:47 +03:00
|
|
|
PropDelegate = new PropListDelegate(this);
|
2009-11-09 11:56:21 +03:00
|
|
|
filesList->setItemDelegate(PropDelegate);
|
|
|
|
|
|
|
|
// QActions
|
2009-11-11 15:22:48 +03:00
|
|
|
actionIgnored = new QAction(tr("Ignored"), this);
|
|
|
|
actionNormal = new QAction(tr("Normal"), this);
|
|
|
|
actionMaximum = new QAction(tr("Maximum"), this);
|
|
|
|
actionHigh = new QAction(tr("High"), this);
|
2009-11-09 11:56:21 +03:00
|
|
|
|
|
|
|
// SIGNAL/SLOTS
|
|
|
|
connect(filesList, SIGNAL(clicked(const QModelIndex&)), filesList, SLOT(edit(const QModelIndex&)));
|
|
|
|
connect(collapseAllButton, SIGNAL(clicked()), filesList, SLOT(collapseAll()));
|
|
|
|
connect(expandAllButton, SIGNAL(clicked()), filesList, SLOT(expandAll()));
|
|
|
|
connect(filesList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayFilesListMenu(const QPoint&)));
|
|
|
|
connect(actionIgnored, SIGNAL(triggered()), this, SLOT(ignoreSelection()));
|
|
|
|
connect(actionNormal, SIGNAL(triggered()), this, SLOT(normalSelection()));
|
|
|
|
connect(actionHigh, SIGNAL(triggered()), this, SLOT(highSelection()));
|
|
|
|
connect(actionMaximum, SIGNAL(triggered()), this, SLOT(maximumSelection()));
|
|
|
|
connect(addWS_button, SIGNAL(clicked()), this, SLOT(askWebSeed()));
|
|
|
|
connect(deleteWS_button, SIGNAL(clicked()), this, SLOT(deleteSelectedUrlSeeds()));
|
2009-11-08 18:41:32 +03:00
|
|
|
connect(transferList, SIGNAL(currentTorrentChanged(QTorrentHandle&)), this, SLOT(loadTorrentInfos(QTorrentHandle &)));
|
2009-11-09 11:56:21 +03:00
|
|
|
connect(PropDelegate, SIGNAL(filteredFilesChanged()), this, SLOT(filteredFilesChanged()));
|
2009-11-15 16:10:31 +03:00
|
|
|
connect(stackedProperties, SIGNAL(currentChanged(int)), this, SLOT(loadDynamicData()));
|
2009-11-08 22:09:10 +03:00
|
|
|
|
2009-11-08 18:41:32 +03:00
|
|
|
// Downloaded pieces progress bar
|
2009-11-21 21:36:12 +03:00
|
|
|
downloaded_pieces = new DownloadedPiecesBar(this);
|
|
|
|
ProgressHLayout->insertWidget(1, downloaded_pieces);
|
2009-11-21 22:40:24 +03:00
|
|
|
// Pieces availability bar
|
|
|
|
pieces_availability = new PieceAvailabilityBar(this);
|
|
|
|
ProgressHLayout_2->insertWidget(1, pieces_availability);
|
2009-11-19 14:09:03 +03:00
|
|
|
// Tracker list
|
|
|
|
trackerList = new TrackerList(this);
|
|
|
|
verticalLayout_trackers->addWidget(trackerList);
|
2009-11-14 13:37:45 +03:00
|
|
|
// Peers list
|
2009-11-15 13:00:07 +03:00
|
|
|
peersList = new PeerListWidget(this);
|
2009-11-14 13:37:45 +03:00
|
|
|
peerpage_layout->addWidget(peersList);
|
2009-11-08 18:41:32 +03:00
|
|
|
// Dynamic data refresher
|
|
|
|
refreshTimer = new QTimer(this);
|
|
|
|
connect(refreshTimer, SIGNAL(timeout()), this, SLOT(loadDynamicData()));
|
2009-11-19 14:09:03 +03:00
|
|
|
refreshTimer->start(3000); // 3sec
|
2009-11-08 17:20:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PropertiesWidget::~PropertiesWidget() {
|
2009-11-09 22:30:13 +03:00
|
|
|
saveSettings();
|
2009-11-08 18:41:32 +03:00
|
|
|
delete refreshTimer;
|
2009-11-19 14:09:03 +03:00
|
|
|
delete trackerList;
|
2009-11-14 13:37:45 +03:00
|
|
|
delete peersList;
|
2009-11-21 21:36:12 +03:00
|
|
|
delete downloaded_pieces;
|
2009-11-21 22:40:24 +03:00
|
|
|
delete pieces_availability;
|
2009-11-09 11:56:21 +03:00
|
|
|
delete PropListModel;
|
2009-11-14 22:28:35 +03:00
|
|
|
delete PropDelegate;
|
2009-11-09 11:56:21 +03:00
|
|
|
// Delete QActions
|
|
|
|
delete actionIgnored;
|
|
|
|
delete actionNormal;
|
|
|
|
delete actionMaximum;
|
|
|
|
delete actionHigh;
|
2009-11-08 18:41:32 +03:00
|
|
|
}
|
|
|
|
|
2009-11-21 22:47:54 +03:00
|
|
|
void PropertiesWidget::showPieceBars(bool show) {
|
|
|
|
avail_pieces_lbl->setVisible(show);
|
|
|
|
pieces_availability->setVisible(show);
|
|
|
|
downloaded_pieces_lbl->setVisible(show);
|
|
|
|
downloaded_pieces->setVisible(show);
|
|
|
|
progress_lbl->setVisible(show);
|
|
|
|
line_2->setVisible(show);
|
2009-11-21 23:01:09 +03:00
|
|
|
avail_average_lbl->setVisible(show);
|
2009-11-21 22:47:54 +03:00
|
|
|
}
|
|
|
|
|
2009-11-08 22:09:10 +03:00
|
|
|
void PropertiesWidget::reduce() {
|
|
|
|
if(state == VISIBLE) {
|
2009-11-11 19:22:57 +03:00
|
|
|
QSplitter *hSplitter = static_cast<QSplitter*>(parentWidget());
|
|
|
|
slideSizes = hSplitter->sizes();
|
|
|
|
stackedProperties->setVisible(false);
|
|
|
|
QList<int> sizes;
|
|
|
|
sizes << hSplitter->geometry().height()-30 << 30;
|
|
|
|
hSplitter->setSizes(sizes);
|
|
|
|
hSplitter->handle(1)->setVisible(false);
|
|
|
|
hSplitter->handle(1)->setDisabled(true);
|
2009-11-08 22:09:10 +03:00
|
|
|
state = REDUCED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertiesWidget::slide() {
|
|
|
|
if(state == REDUCED) {
|
2009-11-11 19:22:57 +03:00
|
|
|
stackedProperties->setVisible(true);
|
|
|
|
QSplitter *hSplitter = static_cast<QSplitter*>(parentWidget());
|
|
|
|
hSplitter->handle(1)->setDisabled(false);
|
|
|
|
hSplitter->handle(1)->setVisible(true);
|
|
|
|
hSplitter->setSizes(slideSizes);
|
2009-11-08 22:09:10 +03:00
|
|
|
state = VISIBLE;
|
2009-11-16 18:29:44 +03:00
|
|
|
// Force refresh
|
|
|
|
loadDynamicData();
|
2009-11-08 22:09:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-08 22:54:22 +03:00
|
|
|
void PropertiesWidget::clear() {
|
2009-11-15 13:00:07 +03:00
|
|
|
qDebug("Clearing torrent properties");
|
2009-11-08 22:54:22 +03:00
|
|
|
save_path->clear();
|
2009-11-12 10:42:21 +03:00
|
|
|
lbl_creationDate->clear();
|
2009-11-08 22:54:22 +03:00
|
|
|
hash_lbl->clear();
|
2009-11-19 15:17:51 +03:00
|
|
|
comment_text->clear();
|
2009-11-21 21:36:12 +03:00
|
|
|
progress_lbl->clear();
|
2009-11-19 14:09:03 +03:00
|
|
|
trackerList->clear();
|
2009-11-21 21:36:12 +03:00
|
|
|
downloaded_pieces->clear();
|
2009-11-21 22:40:24 +03:00
|
|
|
pieces_availability->clear();
|
2009-11-21 23:01:09 +03:00
|
|
|
avail_average_lbl->clear();
|
2009-11-12 10:42:21 +03:00
|
|
|
wasted->clear();
|
2009-11-08 22:54:22 +03:00
|
|
|
upTotal->clear();
|
|
|
|
dlTotal->clear();
|
2009-11-15 13:00:07 +03:00
|
|
|
peersList->clear();
|
2009-11-12 10:42:21 +03:00
|
|
|
lbl_uplimit->clear();
|
|
|
|
lbl_dllimit->clear();
|
|
|
|
lbl_elapsed->clear();
|
|
|
|
lbl_connections->clear();
|
2009-11-08 22:54:22 +03:00
|
|
|
shareRatio->clear();
|
2009-11-09 14:49:18 +03:00
|
|
|
listWebSeeds->clear();
|
2009-11-11 15:22:48 +03:00
|
|
|
PropListModel->clear();
|
2009-11-21 22:47:54 +03:00
|
|
|
showPieceBars(false);
|
2009-11-08 22:54:22 +03:00
|
|
|
setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2009-11-15 13:00:07 +03:00
|
|
|
const QTorrentHandle& PropertiesWidget::getCurrentTorrent() const {
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2009-11-20 11:01:59 +03:00
|
|
|
Bittorrent* PropertiesWidget::getBTSession() const {
|
2009-11-17 19:02:35 +03:00
|
|
|
return BTSession;
|
|
|
|
}
|
|
|
|
|
2009-11-08 18:41:32 +03:00
|
|
|
void PropertiesWidget::loadTorrentInfos(QTorrentHandle &_h) {
|
|
|
|
h = _h;
|
2009-11-08 22:54:22 +03:00
|
|
|
if(!h.is_valid()) {
|
|
|
|
clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setEnabled(true);
|
2009-11-11 15:22:48 +03:00
|
|
|
|
2009-11-08 18:41:32 +03:00
|
|
|
try {
|
2009-11-21 22:47:54 +03:00
|
|
|
if(!h.is_seed())
|
|
|
|
showPieceBars(true);
|
|
|
|
else
|
|
|
|
showPieceBars(false);
|
2009-11-08 18:41:32 +03:00
|
|
|
// Save path
|
|
|
|
save_path->setText(TorrentPersistentData::getSavePath(h.hash()));
|
2009-11-12 10:42:21 +03:00
|
|
|
// Creation date
|
|
|
|
lbl_creationDate->setText(h.creation_date());
|
2009-11-08 18:41:32 +03:00
|
|
|
// Hash
|
|
|
|
hash_lbl->setText(h.hash());
|
|
|
|
// Comment
|
2009-11-19 15:17:51 +03:00
|
|
|
comment_text->setHtml(h.comment());
|
2009-11-08 23:23:02 +03:00
|
|
|
// URL seeds
|
|
|
|
loadUrlSeeds();
|
2009-11-09 11:56:21 +03:00
|
|
|
// List files in torrent
|
2009-11-11 15:22:48 +03:00
|
|
|
PropListModel->clear();
|
|
|
|
PropListModel->setupModelData(h.get_torrent_info());
|
|
|
|
// Expand first item if possible
|
2009-11-11 15:30:46 +03:00
|
|
|
filesList->expand(PropListModel->index(0, 0));
|
2009-11-08 18:41:32 +03:00
|
|
|
} catch(invalid_handle e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
// Load dynamic data
|
|
|
|
loadDynamicData();
|
|
|
|
}
|
2009-11-08 17:20:58 +03:00
|
|
|
|
2009-11-09 22:30:13 +03:00
|
|
|
void PropertiesWidget::readSettings() {
|
|
|
|
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
|
|
|
QVariantList contentColsWidths = settings.value(QString::fromUtf8("TorrentProperties/filesColsWidth"), QVariantList()).toList();
|
|
|
|
if(contentColsWidths.empty()) {
|
|
|
|
filesList->header()->resizeSection(0, filesList->width()/2.);
|
|
|
|
} else {
|
|
|
|
for(int i=0; i<contentColsWidths.size(); ++i) {
|
|
|
|
filesList->setColumnWidth(i, contentColsWidths.at(i).toInt());
|
|
|
|
}
|
|
|
|
}
|
2009-11-11 19:22:57 +03:00
|
|
|
// Restore splitter sizes
|
|
|
|
QStringList sizes_str = settings.value(QString::fromUtf8("TorrentProperties/SplitterSizes"), QString()).toString().split(",");
|
|
|
|
if(sizes_str.size() == 2) {
|
|
|
|
slideSizes << sizes_str.first().toInt();
|
|
|
|
slideSizes << sizes_str.last().toInt();
|
|
|
|
QSplitter *hSplitter = static_cast<QSplitter*>(parentWidget());
|
|
|
|
hSplitter->setSizes(slideSizes);
|
|
|
|
}
|
|
|
|
if(!settings.value("TorrentProperties/Visible", false).toBool()) {
|
|
|
|
reduce();
|
|
|
|
} else {
|
|
|
|
main_infos_button->setStyleSheet(SELECTED_BUTTON_CSS);
|
2009-11-12 10:42:21 +03:00
|
|
|
//setEnabled(false);
|
2009-11-11 19:22:57 +03:00
|
|
|
}
|
2009-11-09 22:30:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void PropertiesWidget::saveSettings() {
|
|
|
|
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
|
|
|
settings.setValue("TorrentProperties/Visible", state==VISIBLE);
|
|
|
|
QVariantList contentColsWidths;
|
2009-11-11 17:19:44 +03:00
|
|
|
for(int i=0; i<PropListModel->columnCount(); ++i) {
|
2009-11-09 22:30:13 +03:00
|
|
|
contentColsWidths.append(filesList->columnWidth(i));
|
|
|
|
}
|
2009-11-15 11:40:26 +03:00
|
|
|
settings.setValue(QString::fromUtf8("TorrentProperties/filesColsWidth"), contentColsWidths);
|
|
|
|
// Splitter sizes
|
2009-11-11 19:22:57 +03:00
|
|
|
QSplitter *hSplitter = static_cast<QSplitter*>(parentWidget());
|
|
|
|
QList<int> sizes;
|
|
|
|
if(state == VISIBLE)
|
|
|
|
sizes = hSplitter->sizes();
|
|
|
|
else
|
|
|
|
sizes = slideSizes;
|
|
|
|
if(state == VISIBLE)
|
|
|
|
qDebug("Visible");
|
|
|
|
qDebug("Sizes: %d", sizes.size());
|
|
|
|
if(sizes.size() == 2) {
|
|
|
|
settings.setValue(QString::fromUtf8("TorrentProperties/SplitterSizes"), QString::number(sizes.first())+','+QString::number(sizes.last()));
|
|
|
|
}
|
2009-11-09 22:30:13 +03:00
|
|
|
}
|
|
|
|
|
2009-11-15 13:00:07 +03:00
|
|
|
void PropertiesWidget::reloadPreferences() {
|
|
|
|
// Take program preferences into consideration
|
|
|
|
peersList->updatePeerHostNameResolutionState();
|
2009-11-15 15:57:25 +03:00
|
|
|
peersList->updatePeerCountryResolutionState();
|
2009-11-12 22:44:47 +03:00
|
|
|
}
|
|
|
|
|
2009-11-08 18:41:32 +03:00
|
|
|
void PropertiesWidget::loadDynamicData() {
|
2009-11-21 17:16:54 +03:00
|
|
|
// Refresh only if the torrent handle is valid and if visible
|
|
|
|
if(!h.is_valid() || main_window->getCurrentTabIndex() != TAB_TRANSFER || state != VISIBLE) return;
|
2009-11-08 18:41:32 +03:00
|
|
|
try {
|
2009-11-12 10:42:21 +03:00
|
|
|
// Transfer infos
|
2009-11-15 16:10:31 +03:00
|
|
|
if(stackedProperties->currentIndex() == MAIN_TAB) {
|
|
|
|
wasted->setText(misc::friendlyUnit(h.total_failed_bytes()+h.total_redundant_bytes()));
|
|
|
|
upTotal->setText(misc::friendlyUnit(h.all_time_upload()) + " ("+misc::friendlyUnit(h.total_payload_upload())+" "+tr("this session")+")");
|
|
|
|
dlTotal->setText(misc::friendlyUnit(h.all_time_download()) + " ("+misc::friendlyUnit(h.total_payload_download())+" "+tr("this session")+")");
|
2009-11-22 19:28:42 +03:00
|
|
|
if(h.upload_limit() <= 0)
|
2009-11-23 10:37:06 +03:00
|
|
|
lbl_uplimit->setText(QString::fromUtf8("∞"));
|
2009-11-22 19:28:42 +03:00
|
|
|
else
|
2009-11-23 10:34:14 +03:00
|
|
|
lbl_uplimit->setText(misc::friendlyUnit(h.upload_limit())+tr("/s", "/second (i.e. per second)"));
|
2009-11-22 19:28:42 +03:00
|
|
|
if(h.download_limit() <= 0)
|
2009-11-23 10:37:06 +03:00
|
|
|
lbl_dllimit->setText(QString::fromUtf8("∞"));
|
2009-11-22 19:28:42 +03:00
|
|
|
else
|
2009-11-23 10:34:14 +03:00
|
|
|
lbl_dllimit->setText(misc::friendlyUnit(h.download_limit())+tr("/s", "/second (i.e. per second)"));
|
2009-11-15 16:10:31 +03:00
|
|
|
QString elapsed_txt = misc::userFriendlyDuration(h.active_time());
|
|
|
|
if(h.is_seed()) {
|
2009-11-22 19:28:42 +03:00
|
|
|
elapsed_txt += " ("+tr("Seeded for %1", "e.g. Seeded for 3m10s").arg(misc::userFriendlyDuration(h.seeding_time()))+")";
|
2009-11-15 16:10:31 +03:00
|
|
|
}
|
|
|
|
lbl_elapsed->setText(elapsed_txt);
|
2009-11-26 16:52:05 +03:00
|
|
|
if(h.connections_limit() > 0)
|
|
|
|
lbl_connections->setText(QString::number(h.num_connections())+" ("+tr("%1 max", "e.g. 10 max").arg(QString::number(h.connections_limit()))+")");
|
|
|
|
else
|
|
|
|
lbl_connections->setText(QString::number(h.num_connections()));
|
2009-11-15 16:10:31 +03:00
|
|
|
// Update ratio info
|
2009-11-27 18:59:49 +03:00
|
|
|
double ratio = BTSession->getRealRatio(h.hash());
|
|
|
|
if(ratio > 100.)
|
|
|
|
shareRatio->setText(QString::fromUtf8("∞"));
|
|
|
|
else
|
|
|
|
shareRatio->setText(QString(QByteArray::number(ratio, 'f', 1)));
|
2009-11-21 22:47:54 +03:00
|
|
|
if(!h.is_seed()) {
|
2009-11-29 17:29:48 +03:00
|
|
|
showPieceBars(true);
|
2009-11-21 22:47:54 +03:00
|
|
|
// Downloaded pieces
|
|
|
|
downloaded_pieces->setProgress(h.pieces());
|
|
|
|
// Pieces availability
|
|
|
|
std::vector<int> avail;
|
|
|
|
h.piece_availability(avail);
|
2009-11-21 23:01:09 +03:00
|
|
|
double avail_average = pieces_availability->setAvailability(avail);
|
|
|
|
avail_average_lbl->setText(QString::number(avail_average, 'f', 1));
|
2009-11-21 22:47:54 +03:00
|
|
|
// Progress
|
|
|
|
progress_lbl->setText(QString::number(h.progress()*100., 'f', 1)+"%");
|
2009-11-29 17:29:48 +03:00
|
|
|
} else {
|
|
|
|
showPieceBars(false);
|
2009-11-21 22:47:54 +03:00
|
|
|
}
|
2009-11-15 16:10:31 +03:00
|
|
|
return;
|
|
|
|
}
|
2009-11-19 14:09:03 +03:00
|
|
|
if(stackedProperties->currentIndex() == TRACKERS_TAB) {
|
|
|
|
// Trackers
|
|
|
|
trackerList->loadTrackers();
|
|
|
|
return;
|
|
|
|
}
|
2009-11-15 16:10:31 +03:00
|
|
|
if(stackedProperties->currentIndex() == PEERS_TAB) {
|
|
|
|
// Load peers
|
|
|
|
peersList->loadPeers(h);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(stackedProperties->currentIndex() == FILES_TAB) {
|
|
|
|
// Files progress
|
|
|
|
std::vector<size_type> fp;
|
|
|
|
h.file_progress(fp);
|
|
|
|
PropListModel->updateFilesProgress(fp);
|
2009-11-24 18:38:47 +03:00
|
|
|
PropListModel->updateFilesPriorities(h.file_priorities());
|
2009-11-08 18:41:32 +03:00
|
|
|
}
|
|
|
|
} catch(invalid_handle e) {}
|
2009-11-08 17:20:58 +03:00
|
|
|
}
|
2009-11-08 18:50:00 +03:00
|
|
|
|
2009-11-08 23:23:02 +03:00
|
|
|
void PropertiesWidget::loadUrlSeeds(){
|
|
|
|
QStringList already_added;
|
|
|
|
listWebSeeds->clear();
|
2009-11-20 21:29:13 +03:00
|
|
|
QStringList url_seeds = h.url_seeds();
|
|
|
|
foreach(const QString &url_seed, url_seeds){
|
2009-11-08 23:23:02 +03:00
|
|
|
if(!url_seed.isEmpty()) {
|
|
|
|
new QListWidgetItem(url_seed, listWebSeeds);
|
|
|
|
already_added << url_seed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Load the hard-coded url seeds
|
|
|
|
QStringList hc_seeds = h.url_seeds();
|
|
|
|
// Add hard coded url seeds
|
|
|
|
foreach(const QString &hc_seed, hc_seeds){
|
|
|
|
if(!already_added.contains(hc_seed)){
|
|
|
|
new QListWidgetItem(hc_seed, listWebSeeds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-08 19:19:21 +03:00
|
|
|
/* Tab buttons */
|
2009-11-08 19:39:17 +03:00
|
|
|
QPushButton* PropertiesWidget::getButtonFromIndex(int index) {
|
|
|
|
switch(index) {
|
2009-11-08 19:48:38 +03:00
|
|
|
case TRACKERS_TAB:
|
2009-11-08 19:39:17 +03:00
|
|
|
return trackers_button;
|
2009-11-12 22:44:47 +03:00
|
|
|
case PEERS_TAB:
|
|
|
|
return peers_button;
|
2009-11-08 19:48:38 +03:00
|
|
|
case URLSEEDS_TAB:
|
|
|
|
return url_seeds_button;
|
|
|
|
case FILES_TAB:
|
|
|
|
return files_button;
|
2009-11-08 19:39:17 +03:00
|
|
|
default:
|
|
|
|
return main_infos_button;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-08 19:19:21 +03:00
|
|
|
void PropertiesWidget::on_main_infos_button_clicked() {
|
2009-11-08 22:09:10 +03:00
|
|
|
if(state == VISIBLE && stackedProperties->currentIndex() == MAIN_TAB) {
|
|
|
|
reduce();
|
|
|
|
} else {
|
|
|
|
slide();
|
|
|
|
getButtonFromIndex(stackedProperties->currentIndex())->setStyleSheet(DEFAULT_BUTTON_CSS);
|
|
|
|
stackedProperties->setCurrentIndex(MAIN_TAB);
|
|
|
|
main_infos_button->setStyleSheet(SELECTED_BUTTON_CSS);
|
|
|
|
}
|
2009-11-08 19:19:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void PropertiesWidget::on_trackers_button_clicked() {
|
2009-11-08 22:09:10 +03:00
|
|
|
if(state == VISIBLE && stackedProperties->currentIndex() == TRACKERS_TAB) {
|
|
|
|
reduce();
|
|
|
|
} else {
|
|
|
|
slide();
|
|
|
|
getButtonFromIndex(stackedProperties->currentIndex())->setStyleSheet(DEFAULT_BUTTON_CSS);
|
|
|
|
stackedProperties->setCurrentIndex(TRACKERS_TAB);
|
|
|
|
trackers_button->setStyleSheet(SELECTED_BUTTON_CSS);
|
|
|
|
}
|
2009-11-08 19:19:21 +03:00
|
|
|
}
|
2009-11-08 19:48:38 +03:00
|
|
|
|
2009-11-12 22:44:47 +03:00
|
|
|
void PropertiesWidget::on_peers_button_clicked() {
|
|
|
|
if(state == VISIBLE && stackedProperties->currentIndex() == PEERS_TAB) {
|
|
|
|
reduce();
|
|
|
|
} else {
|
|
|
|
slide();
|
|
|
|
getButtonFromIndex(stackedProperties->currentIndex())->setStyleSheet(DEFAULT_BUTTON_CSS);
|
|
|
|
stackedProperties->setCurrentIndex(PEERS_TAB);
|
|
|
|
peers_button->setStyleSheet(SELECTED_BUTTON_CSS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-08 19:48:38 +03:00
|
|
|
void PropertiesWidget::on_url_seeds_button_clicked() {
|
2009-11-08 22:09:10 +03:00
|
|
|
if(state == VISIBLE && stackedProperties->currentIndex() == URLSEEDS_TAB) {
|
|
|
|
reduce();
|
|
|
|
} else {
|
|
|
|
slide();
|
|
|
|
getButtonFromIndex(stackedProperties->currentIndex())->setStyleSheet(DEFAULT_BUTTON_CSS);
|
|
|
|
stackedProperties->setCurrentIndex(URLSEEDS_TAB);
|
|
|
|
url_seeds_button->setStyleSheet(SELECTED_BUTTON_CSS);
|
|
|
|
}
|
2009-11-08 19:48:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void PropertiesWidget::on_files_button_clicked() {
|
2009-11-08 22:09:10 +03:00
|
|
|
if(state == VISIBLE && stackedProperties->currentIndex() == FILES_TAB) {
|
|
|
|
reduce();
|
|
|
|
} else {
|
|
|
|
slide();
|
|
|
|
getButtonFromIndex(stackedProperties->currentIndex())->setStyleSheet(DEFAULT_BUTTON_CSS);
|
|
|
|
stackedProperties->setCurrentIndex(FILES_TAB);
|
|
|
|
files_button->setStyleSheet(SELECTED_BUTTON_CSS);
|
|
|
|
}
|
2009-11-08 19:48:38 +03:00
|
|
|
}
|
2009-11-09 11:56:21 +03:00
|
|
|
|
|
|
|
void PropertiesWidget::displayFilesListMenu(const QPoint&){
|
2009-11-11 15:22:48 +03:00
|
|
|
//if(h.get_torrent_info().num_files() == 1) return;
|
2009-11-09 11:56:21 +03:00
|
|
|
QMenu myFilesLlistMenu(this);
|
2009-11-11 15:22:48 +03:00
|
|
|
//QModelIndex index;
|
2009-11-09 11:56:21 +03:00
|
|
|
// Enable/disable pause/start action given the DL state
|
2009-11-11 15:22:48 +03:00
|
|
|
//QModelIndexList selectedIndexes = filesList->selectionModel()->selectedIndexes();
|
2009-11-09 11:56:21 +03:00
|
|
|
myFilesLlistMenu.setTitle(tr("Priority"));
|
|
|
|
myFilesLlistMenu.addAction(actionIgnored);
|
|
|
|
myFilesLlistMenu.addAction(actionNormal);
|
|
|
|
myFilesLlistMenu.addAction(actionHigh);
|
|
|
|
myFilesLlistMenu.addAction(actionMaximum);
|
|
|
|
// Call menu
|
|
|
|
myFilesLlistMenu.exec(QCursor::pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertiesWidget::ignoreSelection(){
|
|
|
|
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedIndexes();
|
|
|
|
foreach(const QModelIndex &index, selectedIndexes){
|
|
|
|
if(index.column() == PRIORITY){
|
|
|
|
if(PropListModel->data(index) != QVariant(IGNORED)){
|
|
|
|
PropListModel->setData(index, QVariant(IGNORED));
|
2009-11-09 21:01:54 +03:00
|
|
|
filteredFilesChanged();
|
2009-11-09 11:56:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertiesWidget::normalSelection(){
|
|
|
|
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedIndexes();
|
|
|
|
foreach(const QModelIndex &index, selectedIndexes){
|
|
|
|
if(index.column() == PRIORITY){
|
|
|
|
if(PropListModel->data(index) != QVariant(NORMAL)){
|
|
|
|
PropListModel->setData(index, QVariant(NORMAL));
|
2009-11-09 21:01:54 +03:00
|
|
|
filteredFilesChanged();
|
2009-11-09 11:56:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertiesWidget::highSelection(){
|
|
|
|
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedIndexes();
|
|
|
|
foreach(const QModelIndex &index, selectedIndexes){
|
|
|
|
if(index.column() == PRIORITY){
|
|
|
|
if(PropListModel->data(index) != QVariant(HIGH)){
|
|
|
|
PropListModel->setData(index, QVariant(HIGH));
|
2009-11-09 21:01:54 +03:00
|
|
|
filteredFilesChanged();
|
2009-11-09 11:56:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertiesWidget::maximumSelection(){
|
|
|
|
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedIndexes();
|
|
|
|
foreach(const QModelIndex &index, selectedIndexes){
|
|
|
|
if(index.column() == PRIORITY){
|
|
|
|
if(PropListModel->data(index) != QVariant(MAXIMUM)){
|
|
|
|
PropListModel->setData(index, QVariant(MAXIMUM));
|
2009-11-09 21:01:54 +03:00
|
|
|
filteredFilesChanged();
|
2009-11-09 11:56:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertiesWidget::askWebSeed(){
|
|
|
|
bool ok;
|
|
|
|
// Ask user for a new url seed
|
|
|
|
QString url_seed = QInputDialog::getText(this, tr("New url seed", "New HTTP source"),
|
|
|
|
tr("New url seed:"), QLineEdit::Normal,
|
|
|
|
QString::fromUtf8("http://www."), &ok);
|
|
|
|
if(!ok) return;
|
|
|
|
qDebug("Adding %s web seed", url_seed.toLocal8Bit().data());
|
|
|
|
if(!listWebSeeds->findItems(url_seed, Qt::MatchFixedString).empty()) {
|
|
|
|
QMessageBox::warning(this, tr("qBittorrent"),
|
|
|
|
tr("This url seed is already in the list."),
|
|
|
|
QMessageBox::Ok);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
h.add_url_seed(url_seed);
|
|
|
|
// Refresh the seeds list
|
|
|
|
loadUrlSeeds();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertiesWidget::deleteSelectedUrlSeeds(){
|
|
|
|
QList<QListWidgetItem *> selectedItems = listWebSeeds->selectedItems();
|
|
|
|
bool change = false;
|
|
|
|
foreach(QListWidgetItem *item, selectedItems){
|
|
|
|
QString url_seed = item->text();
|
|
|
|
h.remove_url_seed(url_seed);
|
|
|
|
change = true;
|
|
|
|
}
|
|
|
|
if(change){
|
|
|
|
// Refresh list
|
|
|
|
loadUrlSeeds();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-24 18:38:47 +03:00
|
|
|
bool PropertiesWidget::applyPriorities() {
|
2009-11-09 21:01:54 +03:00
|
|
|
qDebug("Saving pieces priorities");
|
2009-11-11 15:22:48 +03:00
|
|
|
std::vector<int> priorities = PropListModel->getFilesPriorities(h.get_torrent_info().num_files());
|
2009-11-21 15:43:08 +03:00
|
|
|
bool first_last_piece_first = false;
|
2009-11-24 18:38:47 +03:00
|
|
|
// Save first/last piece first option state
|
2009-11-21 15:43:08 +03:00
|
|
|
if(h.first_last_piece_first())
|
|
|
|
first_last_piece_first = true;
|
2009-11-24 18:38:47 +03:00
|
|
|
// Prioritize the files
|
|
|
|
qDebug("prioritize files: %d", priorities[0]);
|
2009-11-11 15:22:48 +03:00
|
|
|
h.prioritize_files(priorities);
|
2009-11-24 18:38:47 +03:00
|
|
|
// Restore first/last piece first option if necessary
|
2009-11-21 15:43:08 +03:00
|
|
|
if(first_last_piece_first)
|
|
|
|
h.prioritize_first_last_piece(true);
|
2009-11-09 21:01:54 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-09 11:56:21 +03:00
|
|
|
void PropertiesWidget::on_changeSavePathButton_clicked() {
|
2009-11-25 00:35:22 +03:00
|
|
|
if(!h.is_valid()) return;
|
2009-11-09 11:56:21 +03:00
|
|
|
QString dir;
|
|
|
|
QDir saveDir(h.save_path());
|
|
|
|
if(saveDir.exists()){
|
|
|
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), h.save_path());
|
|
|
|
}else{
|
|
|
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath());
|
|
|
|
}
|
|
|
|
if(!dir.isNull()){
|
|
|
|
// Check if savePath exists
|
|
|
|
QDir savePath(dir);
|
|
|
|
if(!savePath.exists()){
|
|
|
|
if(!savePath.mkpath(savePath.path())){
|
|
|
|
QMessageBox::critical(0, tr("Save path creation error"), tr("Could not create the save path"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Save savepath
|
|
|
|
TorrentPersistentData::saveSavePath(h.hash(), savePath.path());
|
|
|
|
// Actually move storage
|
|
|
|
if(!BTSession->useTemporaryFolder() || h.is_seed())
|
|
|
|
h.move_storage(savePath.path());
|
|
|
|
// Update save_path in dialog
|
|
|
|
save_path->setText(savePath.path());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertiesWidget::filteredFilesChanged() {
|
2009-11-09 21:01:54 +03:00
|
|
|
if(h.is_valid()) {
|
2009-11-24 18:38:47 +03:00
|
|
|
applyPriorities();
|
2009-11-09 21:01:54 +03:00
|
|
|
}
|
2009-11-09 11:56:21 +03:00
|
|
|
}
|