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>
|
2010-01-05 23:57:33 +03:00
|
|
|
#include <QDesktopServices>
|
2009-11-09 11:56:21 +03:00
|
|
|
#include <QInputDialog>
|
2010-06-07 12:32:41 +04:00
|
|
|
#include <libtorrent/version.hpp>
|
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"
|
2010-10-09 18:06:35 +04:00
|
|
|
#include "qbtsession.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"
|
2010-11-14 00:15:52 +03:00
|
|
|
#include "mainwindow.h"
|
2009-11-21 21:36:12 +03:00
|
|
|
#include "downloadedpiecesbar.h"
|
2009-11-21 22:40:24 +03:00
|
|
|
#include "pieceavailabilitybar.h"
|
2010-07-16 19:03:18 +04:00
|
|
|
#include "qinisettings.h"
|
2010-10-22 22:59:18 +04:00
|
|
|
#include "proptabbar.h"
|
2011-01-01 16:05:28 +03:00
|
|
|
#include "iconprovider.h"
|
2011-02-27 17:40:46 +03:00
|
|
|
#include "lineedit.h"
|
2009-11-08 19:39:17 +03:00
|
|
|
|
2010-11-23 00:55:32 +03:00
|
|
|
using namespace libtorrent;
|
|
|
|
|
2010-11-14 00:15:52 +03:00
|
|
|
PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, TransferListWidget *transferList):
|
2010-12-04 23:47:20 +03:00
|
|
|
QWidget(parent), transferList(transferList), main_window(main_window) {
|
2009-11-08 17:20:58 +03:00
|
|
|
setupUi(this);
|
2011-03-13 13:09:31 +03:00
|
|
|
|
2010-12-12 22:37:59 +03:00
|
|
|
// Icons
|
2011-01-01 16:05:28 +03:00
|
|
|
deleteWS_button->setIcon(IconProvider::instance()->getIcon("list-remove"));
|
|
|
|
addWS_button->setIcon(IconProvider::instance()->getIcon("list-add"));
|
|
|
|
trackerUpButton->setIcon(IconProvider::instance()->getIcon("go-up"));
|
|
|
|
trackerDownButton->setIcon(IconProvider::instance()->getIcon("go-down"));
|
2010-12-12 22:37:59 +03:00
|
|
|
|
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
|
|
|
|
2009-11-09 11:56:21 +03:00
|
|
|
// Set Properties list model
|
2011-02-27 17:40:46 +03:00
|
|
|
PropListModel = new TorrentFilesFilterModel();
|
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);
|
2011-03-10 21:58:35 +03:00
|
|
|
filesList->setSortingEnabled(true);
|
2011-02-27 17:40:46 +03:00
|
|
|
// Torrent content filtering
|
|
|
|
m_contentFilerLine = new LineEdit(this);
|
|
|
|
connect(m_contentFilerLine, SIGNAL(textChanged(QString)), PropListModel, SLOT(setFilterFixedString(QString)));
|
|
|
|
contentFilterLayout->insertWidget(1, m_contentFilerLine);
|
2009-11-09 11:56:21 +03:00
|
|
|
|
|
|
|
// SIGNAL/SLOTS
|
|
|
|
connect(filesList, SIGNAL(clicked(const QModelIndex&)), filesList, SLOT(edit(const QModelIndex&)));
|
2011-02-27 17:40:46 +03:00
|
|
|
connect(selectAllButton, SIGNAL(clicked()), PropListModel, SLOT(selectAll()));
|
|
|
|
connect(selectNoneButton, SIGNAL(clicked()), PropListModel, SLOT(selectNone()));
|
2009-11-09 11:56:21 +03:00
|
|
|
connect(filesList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayFilesListMenu(const QPoint&)));
|
2010-01-05 23:57:33 +03:00
|
|
|
connect(filesList, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(openDoubleClickedFile(QModelIndex)));
|
2009-12-19 21:55:04 +03:00
|
|
|
connect(PropListModel, SIGNAL(filteredFilesChanged()), this, SLOT(filteredFilesChanged()));
|
2009-11-09 11:56:21 +03:00
|
|
|
connect(addWS_button, SIGNAL(clicked()), this, SLOT(askWebSeed()));
|
|
|
|
connect(deleteWS_button, SIGNAL(clicked()), this, SLOT(deleteSelectedUrlSeeds()));
|
2010-11-24 23:31:14 +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()));
|
2010-11-24 23:31:14 +03:00
|
|
|
connect(QBtSession::instance(), SIGNAL(savePathChanged(QTorrentHandle)), this, SLOT(updateSavePath(QTorrentHandle)));
|
|
|
|
connect(QBtSession::instance(), SIGNAL(metadataReceived(QTorrentHandle)), this, SLOT(updateTorrentInfos(QTorrentHandle)));
|
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);
|
2010-01-05 22:59:25 +03:00
|
|
|
connect(trackerUpButton, SIGNAL(clicked()), trackerList, SLOT(moveSelectionUp()));
|
|
|
|
connect(trackerDownButton, SIGNAL(clicked()), trackerList, SLOT(moveSelectionDown()));
|
|
|
|
horizontalLayout_trackers->insertWidget(0, 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);
|
2010-10-22 22:59:18 +04:00
|
|
|
// Tab bar
|
|
|
|
m_tabBar = new PropTabBar();
|
|
|
|
verticalLayout->addLayout(m_tabBar);
|
|
|
|
connect(m_tabBar, SIGNAL(tabChanged(int)), stackedProperties, SLOT(setCurrentIndex(int)));
|
|
|
|
connect(m_tabBar, SIGNAL(visibilityToggled(bool)), SLOT(setVisibility(bool)));
|
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() {
|
2011-03-14 22:18:52 +03:00
|
|
|
qDebug() << Q_FUNC_INFO << "ENTER";
|
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;
|
2010-10-22 22:59:18 +04:00
|
|
|
delete m_tabBar;
|
2011-03-14 22:18:52 +03:00
|
|
|
qDebug() << Q_FUNC_INFO << "EXIT";
|
2009-11-08 18:41:32 +03:00
|
|
|
}
|
|
|
|
|
2009-12-02 23:41:59 +03:00
|
|
|
void PropertiesWidget::showPiecesAvailability(bool show) {
|
2009-11-21 22:47:54 +03:00
|
|
|
avail_pieces_lbl->setVisible(show);
|
|
|
|
pieces_availability->setVisible(show);
|
2009-12-02 23:41:59 +03:00
|
|
|
avail_average_lbl->setVisible(show);
|
|
|
|
if(show || (!show && !downloaded_pieces->isVisible()))
|
|
|
|
line_2->setVisible(show);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertiesWidget::showPiecesDownloaded(bool show) {
|
2009-11-21 22:47:54 +03:00
|
|
|
downloaded_pieces_lbl->setVisible(show);
|
|
|
|
downloaded_pieces->setVisible(show);
|
|
|
|
progress_lbl->setVisible(show);
|
2009-12-02 23:41:59 +03:00
|
|
|
if(show || (!show && !pieces_availability->isVisible()))
|
|
|
|
line_2->setVisible(show);
|
2009-11-21 22:47:54 +03:00
|
|
|
}
|
|
|
|
|
2010-10-22 22:59:18 +04:00
|
|
|
void PropertiesWidget::setVisibility(bool visible) {
|
|
|
|
if(!visible && state == VISIBLE) {
|
2009-11-11 19:22:57 +03:00
|
|
|
QSplitter *hSplitter = static_cast<QSplitter*>(parentWidget());
|
|
|
|
stackedProperties->setVisible(false);
|
2011-02-05 20:45:32 +03:00
|
|
|
slideSizes = hSplitter->sizes();
|
2009-11-11 19:22:57 +03:00
|
|
|
hSplitter->handle(1)->setVisible(false);
|
|
|
|
hSplitter->handle(1)->setDisabled(true);
|
2011-02-05 20:45:32 +03:00
|
|
|
QList<int> sizes = QList<int>() << hSplitter->geometry().height()-30 << 30;
|
|
|
|
hSplitter->setSizes(sizes);
|
2009-11-08 22:09:10 +03:00
|
|
|
state = REDUCED;
|
2011-02-05 20:45:32 +03:00
|
|
|
return;
|
2009-11-08 22:09:10 +03:00
|
|
|
}
|
|
|
|
|
2010-10-22 22:59:18 +04:00
|
|
|
if(visible && 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();
|
2010-12-21 20:52:49 +03:00
|
|
|
pieceSize_lbl->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();
|
2010-05-18 13:35:55 +04:00
|
|
|
reannounce_lbl->clear();
|
2009-11-08 22:54:22 +03:00
|
|
|
shareRatio->clear();
|
2009-11-09 14:49:18 +03:00
|
|
|
listWebSeeds->clear();
|
2011-02-27 17:40:46 +03:00
|
|
|
m_contentFilerLine->clear();
|
|
|
|
PropListModel->model()->clear();
|
2009-12-02 23:41:59 +03:00
|
|
|
showPiecesAvailability(false);
|
|
|
|
showPiecesDownloaded(false);
|
2009-11-08 22:54:22 +03:00
|
|
|
setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2010-06-28 01:18:41 +04:00
|
|
|
QTorrentHandle PropertiesWidget::getCurrentTorrent() const {
|
2009-11-15 13:00:07 +03:00
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2010-11-24 23:31:14 +03:00
|
|
|
void PropertiesWidget::updateSavePath(const QTorrentHandle& _h) {
|
2009-12-18 19:56:57 +03:00
|
|
|
if(h.is_valid() && h == _h) {
|
2010-06-27 21:58:08 +04:00
|
|
|
QString p;
|
|
|
|
if(h.has_metadata() && h.num_files() == 1) {
|
|
|
|
p = h.firstFileSavePath();
|
|
|
|
} else {
|
|
|
|
p = TorrentPersistentData::getSavePath(h.hash());
|
|
|
|
if(p.isEmpty())
|
|
|
|
p = h.save_path();
|
|
|
|
}
|
2010-06-22 23:17:47 +04:00
|
|
|
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
2010-06-04 01:08:28 +04:00
|
|
|
p = p.replace("/", "\\");
|
|
|
|
#endif
|
2010-02-14 18:22:34 +03:00
|
|
|
save_path->setText(p);
|
2009-12-18 19:56:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-24 23:31:14 +03:00
|
|
|
void PropertiesWidget::updateTorrentInfos(const QTorrentHandle& _h) {
|
2010-07-19 22:17:37 +04:00
|
|
|
if(h.is_valid() && h == _h) {
|
|
|
|
loadTorrentInfos(h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-24 23:31:14 +03:00
|
|
|
void PropertiesWidget::loadTorrentInfos(const QTorrentHandle &_h) {
|
2009-12-02 23:13:10 +03:00
|
|
|
clear();
|
2009-11-08 18:41:32 +03:00
|
|
|
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 {
|
|
|
|
// Save path
|
2010-07-19 22:17:37 +04:00
|
|
|
updateSavePath(h);
|
|
|
|
changeSavePathButton->setEnabled(h.has_metadata());
|
2009-11-08 18:41:32 +03:00
|
|
|
// Hash
|
|
|
|
hash_lbl->setText(h.hash());
|
2011-02-27 17:40:46 +03:00
|
|
|
PropListModel->model()->clear();
|
2010-10-28 20:22:40 +04:00
|
|
|
if(h.has_metadata()) {
|
|
|
|
// Creation date
|
|
|
|
lbl_creationDate->setText(h.creation_date());
|
2010-12-21 20:52:49 +03:00
|
|
|
// Pieces size
|
|
|
|
pieceSize_lbl->setText(misc::friendlyUnit(h.piece_length()));
|
2010-10-28 20:22:40 +04:00
|
|
|
// Comment
|
2011-04-04 21:16:34 +04:00
|
|
|
comment_text->setHtml(misc::parseHtmlLinks(h.comment()));
|
2010-10-28 20:22:40 +04:00
|
|
|
// URL seeds
|
|
|
|
loadUrlSeeds();
|
|
|
|
// List files in torrent
|
2011-02-27 17:40:46 +03:00
|
|
|
PropListModel->model()->setupModelData(h.get_torrent_info());
|
2010-10-28 20:22:40 +04:00
|
|
|
}
|
2010-11-23 00:55:32 +03:00
|
|
|
} catch(invalid_handle& e) {
|
2009-11-08 18:41:32 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
// Load dynamic data
|
|
|
|
loadDynamicData();
|
|
|
|
}
|
2009-11-08 17:20:58 +03:00
|
|
|
|
2009-11-09 22:30:13 +03:00
|
|
|
void PropertiesWidget::readSettings() {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
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);
|
|
|
|
}
|
2011-06-05 20:08:30 +04:00
|
|
|
if (!filesList->header()->restoreState(settings.value("TorrentProperties/FilesListState").toByteArray())) {
|
|
|
|
filesList->header()->resizeSection(0, 400); //Default
|
|
|
|
}
|
2011-01-22 22:39:43 +03:00
|
|
|
const int current_tab = settings.value("TorrentProperties/CurrentTab", -1).toInt();
|
|
|
|
m_tabBar->setCurrentIndex(current_tab);
|
2009-11-11 19:22:57 +03:00
|
|
|
if(!settings.value("TorrentProperties/Visible", false).toBool()) {
|
2010-10-22 22:59:18 +04:00
|
|
|
setVisibility(false);
|
2009-11-11 19:22:57 +03:00
|
|
|
}
|
2009-11-09 22:30:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void PropertiesWidget::saveSettings() {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
2009-11-09 22:30:13 +03:00
|
|
|
settings.setValue("TorrentProperties/Visible", state==VISIBLE);
|
2009-11-15 11:40:26 +03:00
|
|
|
// 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;
|
|
|
|
qDebug("Sizes: %d", sizes.size());
|
|
|
|
if(sizes.size() == 2) {
|
2010-03-07 00:11:47 +03:00
|
|
|
settings.setValue(QString::fromUtf8("TorrentProperties/SplitterSizes"), QVariant(QString::number(sizes.first())+','+QString::number(sizes.last())));
|
2009-11-11 19:22:57 +03:00
|
|
|
}
|
2011-06-05 20:08:30 +04:00
|
|
|
settings.setValue("TorrentProperties/FilesListState", filesList->header()->saveState());
|
2010-10-22 21:30:17 +04:00
|
|
|
// Remember current tab
|
2010-10-22 22:59:18 +04:00
|
|
|
settings.setValue("TorrentProperties/CurrentTab", m_tabBar->currentIndex());
|
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
|
2010-07-19 22:49:53 +04:00
|
|
|
if(!h.is_valid() || main_window->getCurrentTabWidget() != transferList || state != VISIBLE) return;
|
2009-11-08 18:41:32 +03:00
|
|
|
try {
|
2009-11-12 10:42:21 +03:00
|
|
|
// Transfer infos
|
2010-10-22 22:59:18 +04:00
|
|
|
if(stackedProperties->currentIndex() == PropTabBar::MAIN_TAB) {
|
2009-11-15 16:10:31 +03:00
|
|
|
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()));
|
2010-05-18 13:35:55 +04:00
|
|
|
// Update next announce time
|
|
|
|
reannounce_lbl->setText(h.next_announce());
|
2009-11-15 16:10:31 +03:00
|
|
|
// Update ratio info
|
2011-01-25 20:01:09 +03:00
|
|
|
const qreal ratio = QBtSession::instance()->getRealRatio(h.hash());
|
2011-02-24 20:36:20 +03:00
|
|
|
if(ratio > QBtSession::MAX_RATIO)
|
2009-11-27 18:59:49 +03:00
|
|
|
shareRatio->setText(QString::fromUtf8("∞"));
|
|
|
|
else
|
2010-06-22 21:46:07 +04:00
|
|
|
shareRatio->setText(QString(QByteArray::number(ratio, 'f', 2)));
|
2009-11-21 22:47:54 +03:00
|
|
|
if(!h.is_seed()) {
|
2009-12-02 23:41:59 +03:00
|
|
|
showPiecesDownloaded(true);
|
2009-11-21 22:47:54 +03:00
|
|
|
// Downloaded pieces
|
2010-03-19 01:58:32 +03:00
|
|
|
bitfield bf(h.get_torrent_info().num_pieces(), 0);
|
|
|
|
h.downloading_pieces(bf);
|
|
|
|
downloaded_pieces->setProgress(h.pieces(), bf);
|
2009-11-21 22:47:54 +03:00
|
|
|
// Pieces availability
|
2009-12-02 23:41:59 +03:00
|
|
|
if(h.has_metadata() && !h.is_paused() && !h.is_queued() && !h.is_checking()) {
|
|
|
|
showPiecesAvailability(true);
|
2009-12-02 23:13:10 +03:00
|
|
|
std::vector<int> avail;
|
|
|
|
h.piece_availability(avail);
|
2010-05-31 18:25:12 +04:00
|
|
|
pieces_availability->setAvailability(avail);
|
2011-04-17 19:00:48 +04:00
|
|
|
avail_average_lbl->setText(QString::number(h.distributed_copies(), 'f', 3));
|
2009-12-02 23:41:59 +03:00
|
|
|
} else {
|
|
|
|
showPiecesAvailability(false);
|
2009-12-02 23:13:10 +03:00
|
|
|
}
|
2009-11-21 22:47:54 +03:00
|
|
|
// Progress
|
2011-01-25 20:01:09 +03:00
|
|
|
qreal progress = h.progress()*100.;
|
2011-01-25 19:55:29 +03:00
|
|
|
if(progress > 99.94 && progress < 100.)
|
|
|
|
progress = 99.9;
|
|
|
|
progress_lbl->setText(QString::number(progress, 'f', 1)+"%");
|
2009-11-29 17:29:48 +03:00
|
|
|
} else {
|
2009-12-02 23:41:59 +03:00
|
|
|
showPiecesAvailability(false);
|
|
|
|
showPiecesDownloaded(false);
|
2009-11-21 22:47:54 +03:00
|
|
|
}
|
2009-11-15 16:10:31 +03:00
|
|
|
return;
|
|
|
|
}
|
2010-10-22 22:59:18 +04:00
|
|
|
if(stackedProperties->currentIndex() == PropTabBar::TRACKERS_TAB) {
|
2009-11-19 14:09:03 +03:00
|
|
|
// Trackers
|
|
|
|
trackerList->loadTrackers();
|
|
|
|
return;
|
|
|
|
}
|
2010-10-22 22:59:18 +04:00
|
|
|
if(stackedProperties->currentIndex() == PropTabBar::PEERS_TAB) {
|
2009-11-15 16:10:31 +03:00
|
|
|
// Load peers
|
|
|
|
peersList->loadPeers(h);
|
|
|
|
return;
|
|
|
|
}
|
2010-10-22 22:59:18 +04:00
|
|
|
if(stackedProperties->currentIndex() == PropTabBar::FILES_TAB) {
|
2009-11-15 16:10:31 +03:00
|
|
|
// Files progress
|
2009-12-13 03:34:54 +03:00
|
|
|
if(h.is_valid() && h.has_metadata()) {
|
2010-07-24 17:16:57 +04:00
|
|
|
qDebug("Updating priorities in files tab");
|
2011-06-05 20:08:30 +04:00
|
|
|
filesList->setUpdatesEnabled(false);
|
2009-12-02 23:13:10 +03:00
|
|
|
std::vector<size_type> fp;
|
|
|
|
h.file_progress(fp);
|
2011-02-27 17:40:46 +03:00
|
|
|
PropListModel->model()->updateFilesPriorities(h.file_priorities());
|
|
|
|
PropListModel->model()->updateFilesProgress(fp);
|
2011-06-05 20:08:30 +04:00
|
|
|
filesList->setUpdatesEnabled(true);
|
2009-12-02 23:13:10 +03:00
|
|
|
}
|
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(){
|
|
|
|
listWebSeeds->clear();
|
2010-01-27 23:34:53 +03:00
|
|
|
qDebug("Loading URL seeds");
|
2010-07-23 18:05:53 +04:00
|
|
|
const QStringList hc_seeds = h.url_seeds();
|
2010-01-27 23:34:53 +03:00
|
|
|
// Add url seeds
|
2009-11-08 23:23:02 +03:00
|
|
|
foreach(const QString &hc_seed, hc_seeds){
|
2010-03-04 21:03:12 +03:00
|
|
|
qDebug("Loading URL seed: %s", qPrintable(hc_seed));
|
2010-01-27 23:34:53 +03:00
|
|
|
new QListWidgetItem(hc_seed, listWebSeeds);
|
2009-11-08 23:23:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-05 23:57:33 +03:00
|
|
|
void PropertiesWidget::openDoubleClickedFile(QModelIndex index) {
|
|
|
|
if(!index.isValid()) return;
|
|
|
|
if(!h.is_valid() || !h.has_metadata()) return;
|
2011-01-25 20:26:25 +03:00
|
|
|
if(PropListModel->getType(index) == TorrentFileItem::TFILE) {
|
2010-01-05 23:57:33 +03:00
|
|
|
int i = PropListModel->getFileIndex(index);
|
2010-07-23 18:05:53 +04:00
|
|
|
const QDir saveDir(h.save_path());
|
2010-11-28 13:29:59 +03:00
|
|
|
const QString filename = h.filepath_at(i);
|
2010-07-23 18:05:53 +04:00
|
|
|
const QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filename));
|
2010-03-04 21:03:12 +03:00
|
|
|
qDebug("Trying to open file at %s", qPrintable(file_path));
|
2010-06-07 12:32:41 +04:00
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14
|
2010-01-10 00:39:17 +03:00
|
|
|
// Flush data
|
|
|
|
h.flush_cache();
|
|
|
|
#endif
|
2010-06-04 00:08:19 +04:00
|
|
|
if(QFile::exists(file_path)) {
|
2010-12-30 22:12:03 +03:00
|
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(file_path));
|
2010-06-04 00:08:19 +04:00
|
|
|
} else {
|
2010-01-05 23:57:33 +03:00
|
|
|
QMessageBox::warning(this, tr("I/O Error"), tr("This file does not exist yet."));
|
2010-06-04 00:08:19 +04:00
|
|
|
}
|
2010-01-07 23:48:52 +03:00
|
|
|
} else {
|
|
|
|
// FOLDER
|
|
|
|
QStringList path_items;
|
|
|
|
path_items << index.data().toString();
|
|
|
|
QModelIndex parent = PropListModel->parent(index);
|
|
|
|
while(parent.isValid()) {
|
|
|
|
path_items.prepend(parent.data().toString());
|
|
|
|
parent = PropListModel->parent(parent);
|
|
|
|
}
|
2010-07-23 18:05:53 +04:00
|
|
|
const QDir saveDir(h.save_path());
|
|
|
|
const QString filename = path_items.join(QDir::separator());
|
|
|
|
const QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filename));
|
2010-03-04 21:03:12 +03:00
|
|
|
qDebug("Trying to open folder at %s", qPrintable(file_path));
|
2010-06-07 12:32:41 +04:00
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14
|
2010-01-10 00:39:17 +03:00
|
|
|
// Flush data
|
|
|
|
h.flush_cache();
|
|
|
|
#endif
|
2010-06-04 00:08:19 +04:00
|
|
|
if(QFile::exists(file_path)) {
|
2010-12-30 22:12:03 +03:00
|
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(file_path));
|
2010-06-04 00:08:19 +04:00
|
|
|
} else {
|
2010-01-07 23:48:52 +03:00
|
|
|
QMessageBox::warning(this, tr("I/O Error"), tr("This folder does not exist yet."));
|
2010-06-04 00:08:19 +04:00
|
|
|
}
|
2010-01-05 23:57:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-09 11:56:21 +03:00
|
|
|
void PropertiesWidget::displayFilesListMenu(const QPoint&){
|
2009-12-19 17:59:38 +03:00
|
|
|
QMenu myFilesLlistMenu;
|
2010-06-06 14:10:45 +04:00
|
|
|
QModelIndexList selectedRows = filesList->selectionModel()->selectedRows(0);
|
2009-12-19 17:59:38 +03:00
|
|
|
QAction *actRename = 0;
|
2009-12-19 18:31:50 +03:00
|
|
|
if(selectedRows.size() == 1) {
|
2011-01-01 16:05:28 +03:00
|
|
|
actRename = myFilesLlistMenu.addAction(IconProvider::instance()->getIcon("edit-rename"), tr("Rename..."));
|
2010-02-16 23:50:44 +03:00
|
|
|
myFilesLlistMenu.addSeparator();
|
2009-12-19 17:59:38 +03:00
|
|
|
}
|
2011-01-15 00:18:45 +03:00
|
|
|
QMenu subMenu;
|
2011-04-17 14:29:44 +04:00
|
|
|
#if LIBTORRENT_VERSION_MINOR > 15
|
|
|
|
if(!h.status(0x0).is_seeding) {
|
|
|
|
#else
|
2011-01-15 00:18:45 +03:00
|
|
|
if(!static_cast<torrent_handle>(h).is_seed()) {
|
2011-04-17 14:29:44 +04:00
|
|
|
#endif
|
2011-01-04 19:58:44 +03:00
|
|
|
subMenu.setTitle(tr("Priority"));
|
|
|
|
subMenu.addAction(actionNot_downloaded);
|
|
|
|
subMenu.addAction(actionNormal);
|
|
|
|
subMenu.addAction(actionHigh);
|
|
|
|
subMenu.addAction(actionMaximum);
|
|
|
|
myFilesLlistMenu.addMenu(&subMenu);
|
|
|
|
}
|
2009-11-09 11:56:21 +03:00
|
|
|
// Call menu
|
2010-03-04 21:03:12 +03:00
|
|
|
const QAction *act = myFilesLlistMenu.exec(QCursor::pos());
|
2009-12-19 17:59:38 +03:00
|
|
|
if(act) {
|
|
|
|
if(act == actRename) {
|
|
|
|
renameSelectedFile();
|
2010-02-16 23:50:44 +03:00
|
|
|
} else {
|
|
|
|
int prio = 1;
|
|
|
|
if(act == actionHigh) {
|
2011-01-25 20:26:25 +03:00
|
|
|
prio = prio::HIGH;
|
2010-02-16 23:50:44 +03:00
|
|
|
} else {
|
|
|
|
if(act == actionMaximum) {
|
2011-01-25 20:26:25 +03:00
|
|
|
prio = prio::MAXIMUM;
|
2010-06-27 20:55:02 +04:00
|
|
|
} else {
|
|
|
|
if(act == actionNot_downloaded) {
|
2011-01-25 20:26:25 +03:00
|
|
|
prio = prio::IGNORED;
|
2010-06-27 20:55:02 +04:00
|
|
|
}
|
2010-02-16 23:50:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
qDebug("Setting files priority");
|
|
|
|
foreach(QModelIndex index, selectedRows) {
|
|
|
|
qDebug("Setting priority(%d) for file at row %d", prio, index.row());
|
|
|
|
PropListModel->setData(PropListModel->index(index.row(), PRIORITY, index.parent()), prio);
|
|
|
|
}
|
|
|
|
// Save changes
|
|
|
|
filteredFilesChanged();
|
2009-12-19 17:59:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertiesWidget::renameSelectedFile() {
|
2010-07-23 18:05:53 +04:00
|
|
|
const QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(0);
|
2009-12-19 17:59:38 +03:00
|
|
|
Q_ASSERT(selectedIndexes.size() == 1);
|
2010-07-23 18:05:53 +04:00
|
|
|
const QModelIndex index = selectedIndexes.first();
|
2009-12-19 17:59:38 +03:00
|
|
|
// Ask for new name
|
|
|
|
bool ok;
|
2010-01-01 16:38:23 +03:00
|
|
|
QString new_name_last = QInputDialog::getText(this, tr("Rename the file"),
|
2009-12-19 18:31:50 +03:00
|
|
|
tr("New name:"), QLineEdit::Normal,
|
|
|
|
index.data().toString(), &ok);
|
2009-12-19 17:59:38 +03:00
|
|
|
if (ok && !new_name_last.isEmpty()) {
|
2010-01-05 15:28:42 +03:00
|
|
|
if(!misc::isValidFileSystemName(new_name_last)) {
|
|
|
|
QMessageBox::warning(this, tr("The file could not be renamed"),
|
|
|
|
tr("This file name contains forbidden characters, please choose a different one."),
|
|
|
|
QMessageBox::Ok);
|
|
|
|
return;
|
|
|
|
}
|
2011-01-25 20:26:25 +03:00
|
|
|
if(PropListModel->getType(index) == TorrentFileItem::TFILE) {
|
2009-12-19 18:31:50 +03:00
|
|
|
// File renaming
|
2010-03-04 21:03:12 +03:00
|
|
|
const int file_index = PropListModel->getFileIndex(index);
|
2009-12-19 18:31:50 +03:00
|
|
|
if(!h.is_valid() || !h.has_metadata()) return;
|
2010-11-28 13:29:59 +03:00
|
|
|
QString old_name = h.filepath_at(file_index);
|
2010-06-06 17:58:43 +04:00
|
|
|
old_name = old_name.replace("\\", "/");
|
2009-12-19 18:31:50 +03:00
|
|
|
if(old_name.endsWith(".!qB") && !new_name_last.endsWith(".!qB")) {
|
|
|
|
new_name_last += ".!qB";
|
|
|
|
}
|
2010-06-06 17:58:43 +04:00
|
|
|
QStringList path_items = old_name.split("/");
|
2009-12-19 18:31:50 +03:00
|
|
|
path_items.removeLast();
|
|
|
|
path_items << new_name_last;
|
2010-06-06 17:58:43 +04:00
|
|
|
QString new_name = path_items.join("/");
|
2009-12-19 18:31:50 +03:00
|
|
|
if(old_name == new_name) {
|
|
|
|
qDebug("Name did not change");
|
2009-12-19 17:59:38 +03:00
|
|
|
return;
|
|
|
|
}
|
2010-06-06 17:58:43 +04:00
|
|
|
new_name = QDir::cleanPath(new_name);
|
2009-12-19 18:31:50 +03:00
|
|
|
// Check if that name is already used
|
|
|
|
for(int i=0; i<h.num_files(); ++i) {
|
|
|
|
if(i == file_index) continue;
|
2010-03-30 15:35:20 +04:00
|
|
|
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
|
2010-11-28 13:29:59 +03:00
|
|
|
if(h.filepath_at(i).compare(new_name, Qt::CaseSensitive) == 0) {
|
2009-12-19 18:39:39 +03:00
|
|
|
#else
|
2010-12-04 23:47:20 +03:00
|
|
|
if(h.filepath_at(i).compare(new_name, Qt::CaseInsensitive) == 0) {
|
2009-12-19 18:39:39 +03:00
|
|
|
#endif
|
2010-12-04 23:47:20 +03:00
|
|
|
// Display error message
|
|
|
|
QMessageBox::warning(this, tr("The file could not be renamed"),
|
|
|
|
tr("This name is already in use in this folder. Please use a different name."),
|
|
|
|
QMessageBox::Ok);
|
|
|
|
return;
|
2009-12-19 19:53:27 +03:00
|
|
|
}
|
2010-12-04 23:47:20 +03:00
|
|
|
}
|
|
|
|
const bool force_recheck = QFile::exists(h.save_path()+QDir::separator()+new_name);
|
|
|
|
qDebug("Renaming %s to %s", qPrintable(old_name), qPrintable(new_name));
|
|
|
|
h.rename_file(file_index, new_name);
|
|
|
|
// Force recheck
|
|
|
|
if(force_recheck) h.force_recheck();
|
|
|
|
// Rename if torrent files model too
|
|
|
|
if(new_name_last.endsWith(".!qB"))
|
|
|
|
new_name_last.chop(4);
|
|
|
|
PropListModel->setData(index, new_name_last);
|
|
|
|
} else {
|
|
|
|
// Folder renaming
|
|
|
|
QStringList path_items;
|
|
|
|
path_items << index.data().toString();
|
|
|
|
QModelIndex parent = PropListModel->parent(index);
|
|
|
|
while(parent.isValid()) {
|
|
|
|
path_items.prepend(parent.data().toString());
|
|
|
|
parent = PropListModel->parent(parent);
|
|
|
|
}
|
|
|
|
const QString old_path = path_items.join("/");
|
|
|
|
path_items.removeLast();
|
|
|
|
path_items << new_name_last;
|
|
|
|
QString new_path = path_items.join("/");
|
|
|
|
if(!new_path.endsWith("/")) new_path += "/";
|
|
|
|
// Check for overwriting
|
|
|
|
const int num_files = h.num_files();
|
|
|
|
for(int i=0; i<num_files; ++i) {
|
|
|
|
const QString current_name = h.filepath_at(i);
|
2010-03-30 15:35:20 +04:00
|
|
|
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
|
2010-12-04 23:47:20 +03:00
|
|
|
if(current_name.startsWith(new_path, Qt::CaseSensitive)) {
|
2009-12-19 18:39:39 +03:00
|
|
|
#else
|
2010-12-04 23:47:20 +03:00
|
|
|
if(current_name.startsWith(new_path, Qt::CaseInsensitive)) {
|
2009-12-19 18:39:39 +03:00
|
|
|
#endif
|
2010-12-04 23:47:20 +03:00
|
|
|
QMessageBox::warning(this, tr("The folder could not be renamed"),
|
|
|
|
tr("This name is already in use in this folder. Please use a different name."),
|
|
|
|
QMessageBox::Ok);
|
|
|
|
return;
|
2009-12-19 18:39:39 +03:00
|
|
|
}
|
|
|
|
}
|
2010-12-04 23:47:20 +03:00
|
|
|
bool force_recheck = false;
|
|
|
|
// Replace path in all files
|
|
|
|
for(int i=0; i<num_files; ++i) {
|
|
|
|
const QString current_name = h.filepath_at(i);
|
|
|
|
if(current_name.startsWith(old_path)) {
|
|
|
|
QString new_name = current_name;
|
|
|
|
new_name.replace(0, old_path.length(), new_path);
|
|
|
|
if(!force_recheck && QDir(h.save_path()).exists(new_name))
|
|
|
|
force_recheck = true;
|
|
|
|
new_name = QDir::cleanPath(new_name);
|
|
|
|
qDebug("Rename %s to %s", qPrintable(current_name), qPrintable(new_name));
|
|
|
|
h.rename_file(i, new_name);
|
|
|
|
}
|
2009-12-19 19:53:27 +03:00
|
|
|
}
|
2010-12-04 23:47:20 +03:00
|
|
|
// Force recheck
|
|
|
|
if(force_recheck) h.force_recheck();
|
|
|
|
// Rename folder in torrent files model too
|
|
|
|
PropListModel->setData(index, new_name_last);
|
|
|
|
// Remove old folder
|
|
|
|
const QDir old_folder(h.save_path()+"/"+old_path);
|
|
|
|
int timeout = 10;
|
2010-12-29 23:29:55 +03:00
|
|
|
while(!QDir().rmpath(old_folder.absolutePath()) && timeout > 0) {
|
|
|
|
// XXX: We should not sleep here (freezes the UI for 1 second)
|
2010-12-04 23:47:20 +03:00
|
|
|
SleeperThread::msleep(100);
|
|
|
|
--timeout;
|
2009-12-19 19:53:27 +03:00
|
|
|
}
|
|
|
|
}
|
2010-12-04 23:47:20 +03:00
|
|
|
}
|
|
|
|
}
|
2009-11-09 11:56:21 +03:00
|
|
|
|
2010-12-04 23:47:20 +03:00
|
|
|
void PropertiesWidget::askWebSeed(){
|
|
|
|
bool ok;
|
|
|
|
// Ask user for a new url seed
|
|
|
|
const 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", qPrintable(url_seed));
|
|
|
|
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(){
|
|
|
|
const QList<QListWidgetItem *> selectedItems = listWebSeeds->selectedItems();
|
|
|
|
bool change = false;
|
|
|
|
foreach(const QListWidgetItem *item, selectedItems){
|
|
|
|
QString url_seed = item->text();
|
|
|
|
h.remove_url_seed(url_seed);
|
|
|
|
change = true;
|
|
|
|
}
|
|
|
|
if(change){
|
|
|
|
// Refresh list
|
|
|
|
loadUrlSeeds();
|
|
|
|
}
|
|
|
|
}
|
2009-11-09 21:01:54 +03:00
|
|
|
|
2010-12-04 23:47:20 +03:00
|
|
|
bool PropertiesWidget::applyPriorities() {
|
|
|
|
qDebug("Saving files priorities");
|
2011-02-27 17:40:46 +03:00
|
|
|
const std::vector<int> priorities = PropListModel->model()->getFilesPriorities(h.get_torrent_info().num_files());
|
2010-12-04 23:47:20 +03:00
|
|
|
// Save first/last piece first option state
|
|
|
|
bool first_last_piece_first = h.first_last_piece_first();
|
|
|
|
// Prioritize the files
|
|
|
|
qDebug("prioritize files: %d", priorities[0]);
|
|
|
|
h.prioritize_files(priorities);
|
|
|
|
// Restore first/last piece first option if necessary
|
|
|
|
if(first_last_piece_first)
|
|
|
|
h.prioritize_first_last_piece(true);
|
|
|
|
return true;
|
|
|
|
}
|
2009-11-09 21:01:54 +03:00
|
|
|
|
2010-12-04 23:47:20 +03:00
|
|
|
|
|
|
|
void PropertiesWidget::on_changeSavePathButton_clicked() {
|
|
|
|
if(!h.is_valid()) return;
|
|
|
|
QString new_path;
|
|
|
|
if(h.has_metadata() && h.num_files() == 1) {
|
|
|
|
new_path = QFileDialog::getSaveFileName(this, tr("Choose save path"), h.firstFileSavePath());
|
|
|
|
} else {
|
|
|
|
const QDir saveDir(TorrentPersistentData::getSavePath(h.hash()));
|
2011-01-27 20:30:27 +03:00
|
|
|
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), saveDir.absolutePath(),
|
|
|
|
QFileDialog::DontConfirmOverwrite|QFileDialog::ShowDirsOnly|QFileDialog::HideNameFilterDetails);
|
2010-12-04 23:47:20 +03:00
|
|
|
}
|
|
|
|
if(!new_path.isEmpty()){
|
|
|
|
// Check if savePath exists
|
|
|
|
QString save_path_dir = new_path.replace("\\", "/");
|
|
|
|
QString new_file_name;
|
|
|
|
if(h.has_metadata() && h.num_files() == 1) {
|
2011-01-23 11:34:57 +03:00
|
|
|
new_file_name = misc::fileName(save_path_dir); // New file name
|
2010-12-30 22:38:53 +03:00
|
|
|
save_path_dir = misc::branchPath(save_path_dir, true); // Skip file name
|
2010-12-04 23:47:20 +03:00
|
|
|
}
|
|
|
|
QDir savePath(misc::expandPath(save_path_dir));
|
|
|
|
// Actually move storage
|
|
|
|
if(!QBtSession::instance()->useTemporaryFolder() || h.is_seed()) {
|
|
|
|
if(!savePath.exists()) savePath.mkpath(savePath.absolutePath());
|
|
|
|
h.move_storage(savePath.absolutePath());
|
|
|
|
}
|
|
|
|
// Update save_path in dialog
|
|
|
|
QString display_path;
|
|
|
|
if(h.has_metadata() && h.num_files() == 1) {
|
|
|
|
// Rename the file
|
|
|
|
Q_ASSERT(!new_file_name.isEmpty());
|
2010-06-27 21:58:08 +04:00
|
|
|
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
2010-12-04 23:47:20 +03:00
|
|
|
if(h.filename_at(0).compare(new_file_name, Qt::CaseInsensitive) != 0) {
|
2010-06-27 21:58:08 +04:00
|
|
|
#else
|
2010-12-04 23:47:20 +03:00
|
|
|
if(h.filename_at(0).compare(new_file_name, Qt::CaseSensitive) != 0) {
|
2010-06-27 21:58:08 +04:00
|
|
|
#endif
|
2010-12-04 23:47:20 +03:00
|
|
|
qDebug("Renaming single file to %s", qPrintable(new_file_name));
|
|
|
|
h.rename_file(0, new_file_name);
|
|
|
|
// Also rename it in the files list model
|
|
|
|
PropListModel->setData(PropListModel->index(0, 0), new_file_name);
|
2009-11-09 11:56:21 +03:00
|
|
|
}
|
2010-12-04 23:47:20 +03:00
|
|
|
display_path = h.firstFileSavePath();
|
|
|
|
} else {
|
|
|
|
display_path = savePath.absolutePath();
|
2009-11-09 11:56:21 +03:00
|
|
|
}
|
2010-12-04 23:47:20 +03:00
|
|
|
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
|
|
|
display_path = display_path.replace("/", "\\");
|
|
|
|
#endif
|
|
|
|
save_path->setText(display_path);
|
|
|
|
}
|
|
|
|
}
|
2009-11-09 11:56:21 +03:00
|
|
|
|
2010-12-04 23:47:20 +03:00
|
|
|
void PropertiesWidget::filteredFilesChanged() {
|
|
|
|
if(h.is_valid()) {
|
|
|
|
applyPriorities();
|
|
|
|
}
|
|
|
|
}
|