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-08 17:20:58 +03:00
|
|
|
#include "propertieswidget.h"
|
2009-11-08 18:41:32 +03:00
|
|
|
#include "TransferListWidget.h"
|
|
|
|
#include "torrentPersistentData.h"
|
|
|
|
#include "realprogressbar.h"
|
|
|
|
#include "realprogressbarthread.h"
|
2009-11-08 19:19:21 +03:00
|
|
|
#include "bittorrent.h"
|
2009-11-08 17:20:58 +03:00
|
|
|
|
2009-11-08 19:39:17 +03:00
|
|
|
#define DEFAULT_BUTTON_CSS "QPushButton {border: 1px solid rgb(85, 81, 91);border-radius: 3px;padding: 2px;}"
|
|
|
|
#define SELECTED_BUTTON_CSS "QPushButton {border: 1px solid rgb(85, 81, 91);border-radius: 3px;padding: 2px;background-color: rgb(255, 208, 105);}"
|
|
|
|
|
2009-11-08 19:19:21 +03:00
|
|
|
PropertiesWidget::PropertiesWidget(QWidget *parent, TransferListWidget *transferList, bittorrent* BTSession): QWidget(parent), transferList(transferList), BTSession(BTSession) {
|
2009-11-08 17:20:58 +03:00
|
|
|
setupUi(this);
|
2009-11-08 22:09:10 +03:00
|
|
|
state = VISIBLE;
|
|
|
|
reduce();
|
|
|
|
|
2009-11-08 18:41:32 +03:00
|
|
|
connect(transferList, SIGNAL(currentTorrentChanged(QTorrentHandle&)), this, SLOT(loadTorrentInfos(QTorrentHandle &)));
|
2009-11-08 18:50:00 +03:00
|
|
|
connect(incrementalDownload, SIGNAL(stateChanged(int)), this, SLOT(setIncrementalDownload(int)));
|
2009-11-08 22:09:10 +03:00
|
|
|
|
2009-11-08 18:41:32 +03:00
|
|
|
// Downloaded pieces progress bar
|
|
|
|
progressBar = new RealProgressBar(this);
|
|
|
|
progressBar->setForegroundColor(Qt::blue);
|
|
|
|
progressBarVbox = new QVBoxLayout(RealProgressBox);
|
|
|
|
progressBarVbox->addWidget(progressBar);
|
|
|
|
progressBarUpdater = 0;
|
|
|
|
// Dynamic data refresher
|
|
|
|
refreshTimer = new QTimer(this);
|
|
|
|
connect(refreshTimer, SIGNAL(timeout()), this, SLOT(loadDynamicData()));
|
|
|
|
refreshTimer->start(10000); // 10sec
|
2009-11-08 17:20:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PropertiesWidget::~PropertiesWidget() {
|
2009-11-08 18:41:32 +03:00
|
|
|
delete refreshTimer;
|
|
|
|
if(progressBarUpdater)
|
|
|
|
delete progressBarUpdater;
|
|
|
|
delete progressBar;
|
|
|
|
delete progressBarVbox;
|
|
|
|
}
|
|
|
|
|
2009-11-08 22:09:10 +03:00
|
|
|
void PropertiesWidget::reduce() {
|
|
|
|
if(state == VISIBLE) {
|
|
|
|
stackedProperties->setFixedHeight(0);
|
|
|
|
state = REDUCED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertiesWidget::slide() {
|
|
|
|
if(state == REDUCED) {
|
|
|
|
stackedProperties->setFixedHeight(232);
|
|
|
|
state = VISIBLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-08 18:41:32 +03:00
|
|
|
void PropertiesWidget::loadTorrentInfos(QTorrentHandle &_h) {
|
|
|
|
h = _h;
|
|
|
|
if(!h.is_valid()) return;
|
|
|
|
if(progressBarUpdater)
|
|
|
|
delete progressBarUpdater;
|
2009-11-08 19:39:17 +03:00
|
|
|
progressBarUpdater = 0;
|
2009-11-08 18:41:32 +03:00
|
|
|
try {
|
|
|
|
// Save path
|
|
|
|
save_path->setText(TorrentPersistentData::getSavePath(h.hash()));
|
|
|
|
// Author
|
|
|
|
QString author = h.creator().trimmed();
|
|
|
|
if(author.isEmpty())
|
|
|
|
author = tr("Unknown");
|
|
|
|
creator->setText(author);
|
|
|
|
// Hash
|
|
|
|
hash_lbl->setText(h.hash());
|
|
|
|
// Comment
|
|
|
|
comment_lbl->setText(h.comment());
|
2009-11-08 18:50:00 +03:00
|
|
|
// Sequential download
|
|
|
|
incrementalDownload->setChecked(TorrentPersistentData::isSequentialDownload(h.hash()));
|
2009-11-08 19:19:21 +03:00
|
|
|
// Trackers
|
|
|
|
loadTrackers();
|
2009-11-08 18:41:32 +03:00
|
|
|
// downloaded pieces updater
|
|
|
|
progressBarUpdater = new RealProgressBarThread(progressBar, h);
|
|
|
|
progressBarUpdater->start();
|
|
|
|
} catch(invalid_handle e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
// Load dynamic data
|
|
|
|
loadDynamicData();
|
|
|
|
}
|
2009-11-08 17:20:58 +03:00
|
|
|
|
2009-11-08 18:41:32 +03:00
|
|
|
void PropertiesWidget::loadDynamicData() {
|
|
|
|
if(!h.is_valid()) return;
|
|
|
|
try {
|
|
|
|
// Session infos
|
|
|
|
failed->setText(misc::friendlyUnit(h.total_failed_bytes()));
|
|
|
|
upTotal->setText(misc::friendlyUnit(h.total_payload_upload()));
|
|
|
|
dlTotal->setText(misc::friendlyUnit(h.total_payload_download()));
|
|
|
|
// Update ratio info
|
|
|
|
float ratio;
|
|
|
|
if(h.total_payload_download() == 0){
|
|
|
|
if(h.total_payload_upload() == 0)
|
|
|
|
ratio = 1.;
|
|
|
|
else
|
|
|
|
ratio = 10.; // Max ratio
|
|
|
|
}else{
|
|
|
|
ratio = (double)h.total_payload_upload()/(double)h.total_payload_download();
|
|
|
|
if(ratio > 10.){
|
|
|
|
ratio = 10.;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
shareRatio->setText(QString(QByteArray::number(ratio, 'f', 1)));
|
|
|
|
// Downloaded pieces
|
|
|
|
if(progressBarUpdater)
|
|
|
|
progressBarUpdater->refresh();
|
|
|
|
} catch(invalid_handle e) {}
|
2009-11-08 17:20:58 +03:00
|
|
|
}
|
2009-11-08 18:50:00 +03:00
|
|
|
|
|
|
|
void PropertiesWidget::setIncrementalDownload(int checkboxState) {
|
|
|
|
if(!h.is_valid()) return;
|
2009-11-08 19:39:17 +03:00
|
|
|
h.set_sequential_download(checkboxState == Qt::Checked);
|
|
|
|
TorrentPersistentData::saveSequentialStatus(h);
|
2009-11-08 18:50:00 +03:00
|
|
|
}
|
2009-11-08 19:19:21 +03:00
|
|
|
|
|
|
|
void PropertiesWidget::loadTrackers() {
|
|
|
|
if(!h.is_valid()) return;
|
|
|
|
//Trackers
|
|
|
|
std::vector<announce_entry> trackers = h.trackers();
|
|
|
|
trackersURLS->clear();
|
|
|
|
QHash<QString, QString> errors = BTSession->getTrackersErrors(h.hash());
|
|
|
|
unsigned int nbTrackers = trackers.size();
|
|
|
|
for(unsigned int i=0; i<nbTrackers; ++i){
|
|
|
|
QString current_tracker = misc::toQString(trackers[i].url);
|
|
|
|
QListWidgetItem *item = new QListWidgetItem(current_tracker, trackersURLS);
|
|
|
|
// IsThere any errors ?
|
|
|
|
if(errors.contains(current_tracker)) {
|
|
|
|
item->setForeground(QBrush(QColor("red")));
|
|
|
|
// Set tooltip
|
|
|
|
QString msg="";
|
|
|
|
unsigned int i=0;
|
|
|
|
foreach(QString word, errors[current_tracker].split(" ")) {
|
|
|
|
if(i > 0 && i%5!=1) msg += " ";
|
|
|
|
msg += word;
|
|
|
|
if(i> 0 && i%5==0) msg += "\n";
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
item->setToolTip(msg);
|
|
|
|
} else {
|
|
|
|
item->setForeground(QBrush(QColor("green")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QString tracker = h.current_tracker().trimmed();
|
|
|
|
if(!tracker.isEmpty()){
|
|
|
|
trackerURL->setText(tracker);
|
|
|
|
}else{
|
|
|
|
trackerURL->setText(tr("None - Unreachable?"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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-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
|
|
|
|
|
|
|
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
|
|
|
}
|