Browse Source

- Removed code that is no longer needed

adaptive-webui-19844
Christophe Dumez 16 years ago
parent
commit
c38a8a2bec
  1. 15
      src/GUI.cpp
  2. 58
      src/bittorrent.cpp
  3. 3
      src/bittorrent.h
  4. 4
      src/downloadingTorrents.cpp

15
src/GUI.cpp

@ -127,7 +127,6 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
connect(BTSession, SIGNAL(newDownloadedTorrent(QString, QString)), this, SLOT(processDownloadedFiles(QString, QString))); connect(BTSession, SIGNAL(newDownloadedTorrent(QString, QString)), this, SLOT(processDownloadedFiles(QString, QString)));
connect(BTSession, SIGNAL(downloadFromUrlFailure(QString, QString)), this, SLOT(handleDownloadFromUrlFailure(QString, QString))); connect(BTSession, SIGNAL(downloadFromUrlFailure(QString, QString)), this, SLOT(handleDownloadFromUrlFailure(QString, QString)));
connect(BTSession, SIGNAL(deletedTorrent(QString)), this, SLOT(deleteTorrent(QString))); connect(BTSession, SIGNAL(deletedTorrent(QString)), this, SLOT(deleteTorrent(QString)));
connect(BTSession, SIGNAL(pausedTorrent(QString)), this, SLOT(pauseTorrent(QString)));
qDebug("create tabWidget"); qDebug("create tabWidget");
tabs = new QTabWidget(); tabs = new QTabWidget();
// Download torrents tab // Download torrents tab
@ -1185,8 +1184,8 @@ void GUI::togglePausedState(QString hash) {
if(tabs->currentIndex() == 1) if(tabs->currentIndex() == 1)
inDownloadList = false; inDownloadList = false;
QTorrentHandle h = BTSession->getTorrentHandle(hash); QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(BTSession->isPaused(hash)) { if(h.is_paused()) {
BTSession->resumeTorrent(hash); h.resume();
if(inDownloadList) { if(inDownloadList) {
downloadingTorrentTab->resumeTorrent(hash); downloadingTorrentTab->resumeTorrent(hash);
updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList()); updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList());
@ -1195,7 +1194,7 @@ void GUI::togglePausedState(QString hash) {
updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList()); updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList());
} }
}else{ }else{
BTSession->pauseTorrent(hash); h.pause();
if(inDownloadList) { if(inDownloadList) {
downloadingTorrentTab->pauseTorrent(hash); downloadingTorrentTab->pauseTorrent(hash);
updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList()); updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList());
@ -1262,7 +1261,9 @@ void GUI::on_actionPause_triggered() {
} }
QString hash; QString hash;
foreach(hash, hashes) { foreach(hash, hashes) {
if(BTSession->pauseTorrent(hash)){ QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(!h.is_paused()){
h.pause();
if(inDownloadList) { if(inDownloadList) {
downloadingTorrentTab->pauseTorrent(hash); downloadingTorrentTab->pauseTorrent(hash);
updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList()); updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList());
@ -1319,7 +1320,9 @@ void GUI::on_actionStart_triggered() {
} }
QString hash; QString hash;
foreach(hash, hashes) { foreach(hash, hashes) {
if(BTSession->resumeTorrent(hash)){ QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(!h.is_paused()){
h.resume();
if(inDownloadList) { if(inDownloadList) {
downloadingTorrentTab->resumeTorrent(hash); downloadingTorrentTab->resumeTorrent(hash);
updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList()); updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList());

58
src/bittorrent.cpp

@ -225,17 +225,6 @@ QTorrentHandle bittorrent::getTorrentHandle(QString hash) const{
return QTorrentHandle(s->find_torrent(misc::fromString<sha1_hash>((hash.toStdString())))); return QTorrentHandle(s->find_torrent(misc::fromString<sha1_hash>((hash.toStdString()))));
} }
// Return true if the torrent corresponding to the
// hash is paused
bool bittorrent::isPaused(QString hash) const{
QTorrentHandle h = getTorrentHandle(hash);
if(!h.is_valid()) {
qDebug("/!\\ Error: Invalid handle");
return true;
}
return h.is_paused();
}
unsigned int bittorrent::getFinishedPausedTorrentsNb() const { unsigned int bittorrent::getFinishedPausedTorrentsNb() const {
unsigned int nbPaused = 0; unsigned int nbPaused = 0;
std::vector<torrent_handle> torrents = getTorrents(); std::vector<torrent_handle> torrents = getTorrents();
@ -298,53 +287,6 @@ void bittorrent::deleteTorrent(QString hash, bool permanent) {
emit deletedTorrent(hash); emit deletedTorrent(hash);
} }
// Pause a running torrent
bool bittorrent::pauseTorrent(QString hash) {
bool change = false;
QTorrentHandle h = getTorrentHandle(hash);
if(h.is_valid() && !h.is_paused()) {
h.pause();
change = true;
// Save fast resume data
saveFastResumeData(hash);
qDebug("Torrent paused successfully");
emit pausedTorrent(hash);
}else{
if(!h.is_valid()) {
qDebug("Could not pause torrent %s, reason: invalid", hash.toUtf8().data());
}else{
qDebug("Could not pause torrent %s, reason: already paused", hash.toUtf8().data());
}
}
// Create .paused file if necessary
QFile paused_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused");
paused_file.open(QIODevice::WriteOnly | QIODevice::Text);
paused_file.write(QByteArray::number((double)h.progress()));
paused_file.close();
if(change) {
addConsoleMessage(tr("'%1' paused.", "e.g: xxx.avi paused.").arg(h.name()));
}
return change;
}
// Resume a torrent in paused state
bool bittorrent::resumeTorrent(QString hash) {
bool change = false;
QTorrentHandle h = getTorrentHandle(hash);
if(h.is_valid() && h.is_paused()) {
h.resume();
change = true;
emit resumedTorrent(hash);
}
// Delete .paused file
if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused"))
QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused");
if(change) {
addConsoleMessage(tr("'%1' resumed.", "e.g: xxx.avi resumed.").arg(h.name()));
}
return change;
}
void bittorrent::pauseAllTorrents() { void bittorrent::pauseAllTorrents() {
std::vector<torrent_handle> torrents = getTorrents(); std::vector<torrent_handle> torrents = getTorrents();
std::vector<torrent_handle>::iterator torrentIT; std::vector<torrent_handle>::iterator torrentIT;

3
src/bittorrent.h

@ -76,7 +76,6 @@ class bittorrent : public QObject {
~bittorrent(); ~bittorrent();
QTorrentHandle getTorrentHandle(QString hash) const; QTorrentHandle getTorrentHandle(QString hash) const;
std::vector<torrent_handle> getTorrents() const; std::vector<torrent_handle> getTorrents() const;
bool isPaused(QString hash) const;
bool isFilePreviewPossible(QString fileHash) const; bool isFilePreviewPossible(QString fileHash) const;
bool isDHTEnabled() const; bool isDHTEnabled() const;
float getPayloadDownloadRate() const; float getPayloadDownloadRate() const;
@ -107,8 +106,6 @@ class bittorrent : public QObject {
void downloadFromUrl(QString url); void downloadFromUrl(QString url);
void downloadFromURLList(const QStringList& url_list); void downloadFromURLList(const QStringList& url_list);
void deleteTorrent(QString hash, bool permanent = false); void deleteTorrent(QString hash, bool permanent = false);
bool pauseTorrent(QString hash);
bool resumeTorrent(QString hash);
void pauseAllTorrents(); void pauseAllTorrents();
void resumeAllTorrents(); void resumeAllTorrents();
void saveDHTEntry(); void saveDHTEntry();

4
src/downloadingTorrents.cpp

@ -589,8 +589,8 @@ void DownloadingTorrents::addTorrent(QString hash) {
if(BTSession->isQueueingEnabled()) if(BTSession->isQueueingEnabled())
DLListModel->setData(DLListModel->index(row, PRIORITY), QVariant((int)BTSession->getDlTorrentPriority(hash))); DLListModel->setData(DLListModel->index(row, PRIORITY), QVariant((int)BTSession->getDlTorrentPriority(hash)));
DLListModel->setData(DLListModel->index(row, HASH), QVariant(hash)); DLListModel->setData(DLListModel->index(row, HASH), QVariant(hash));
// Pause torrent if it was paused last time // Pause torrent if it is
if(BTSession->isPaused(hash)) { if(h.is_paused()) {
DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)BTSession->getUncheckedTorrentProgress(hash))); DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)BTSession->getUncheckedTorrentProgress(hash)));
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/paused.png"))), Qt::DecorationRole); DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/paused.png"))), Qt::DecorationRole);
setRowColor(row, QString::fromUtf8("red")); setRowColor(row, QString::fromUtf8("red"));

Loading…
Cancel
Save