Browse Source

- Pause / resume in Web UI now updates the GUI

- Code cleanup
adaptive-webui-19844
Christophe Dumez 16 years ago
parent
commit
a848538d66
  1. 7
      src/FinishedTorrents.cpp
  2. 1
      src/FinishedTorrents.h
  3. 46
      src/GUI.cpp
  4. 2
      src/GUI.h
  5. 13
      src/bittorrent.cpp
  6. 2
      src/bittorrent.h
  7. 7
      src/downloadingTorrents.cpp
  8. 1
      src/downloadingTorrents.h

7
src/FinishedTorrents.cpp

@ -289,13 +289,6 @@ void FinishedTorrents::pauseTorrent(QString hash) { @@ -289,13 +289,6 @@ void FinishedTorrents::pauseTorrent(QString hash) {
setRowColor(row, QString::fromUtf8("red"));
}
void FinishedTorrents::resumeTorrent(QString hash) {
int row = getRowFromHash(hash);
Q_ASSERT(row != -1);
finishedListModel->setData(finishedListModel->index(row, F_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/seeding.png"))), Qt::DecorationRole);
setRowColor(row, QString::fromUtf8("orange"));
}
QString FinishedTorrents::getHashFromRow(unsigned int row) const {
Q_ASSERT(row < (unsigned int)finishedListModel->rowCount());
return finishedListModel->data(finishedListModel->index(row, F_HASH)).toString();

1
src/FinishedTorrents.h

@ -78,7 +78,6 @@ class FinishedTorrents : public QWidget, public Ui::seeding { @@ -78,7 +78,6 @@ class FinishedTorrents : public QWidget, public Ui::seeding {
void addTorrent(QString hash);
void updateTorrent(QTorrentHandle h);
void pauseTorrent(QString hash);
void resumeTorrent(QString hash);
void propertiesSelection();
void deleteTorrent(QString hash);
void showPropertiesFromHash(QString hash);

46
src/GUI.cpp

@ -122,6 +122,8 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis @@ -122,6 +122,8 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
connect(BTSession, SIGNAL(fullDiskError(QTorrentHandle&)), this, SLOT(fullDiskError(QTorrentHandle&)));
connect(BTSession, SIGNAL(finishedTorrent(QTorrentHandle&)), this, SLOT(finishedTorrent(QTorrentHandle&)));
connect(BTSession, SIGNAL(addedTorrent(QTorrentHandle&)), this, SLOT(addedTorrent(QTorrentHandle&)));
connect(BTSession, SIGNAL(pausedTorrent(QTorrentHandle&)), this, SLOT(pausedTorrent(QTorrentHandle&)));
connect(BTSession, SIGNAL(resumedTorrent(QTorrentHandle&)), this, SLOT(resumedTorrent(QTorrentHandle&)));
connect(BTSession, SIGNAL(torrentFinishedChecking(QTorrentHandle&)), this, SLOT(checkedTorrent(QTorrentHandle&)));
connect(BTSession, SIGNAL(trackerAuthenticationRequired(QTorrentHandle&)), this, SLOT(trackerAuthenticationRequired(QTorrentHandle&)));
connect(BTSession, SIGNAL(newDownloadedTorrent(QString, QString)), this, SLOT(processDownloadedFiles(QString, QString)));
@ -371,6 +373,22 @@ void GUI::addedTorrent(QTorrentHandle& h) const { @@ -371,6 +373,22 @@ void GUI::addedTorrent(QTorrentHandle& h) const {
}
}
void GUI::pausedTorrent(QTorrentHandle& h) const {
if(h.is_seed()) {
finishedTorrentTab->pauseTorrent(h.hash());
} else {
downloadingTorrentTab->pauseTorrent(h.hash());
}
}
void GUI::resumedTorrent(QTorrentHandle& h) const {
if(h.is_seed()) {
finishedTorrentTab->updateTorrent(h);
} else {
downloadingTorrentTab->updateTorrent(h);
}
}
void GUI::checkedTorrent(QTorrentHandle& h) const {
if(h.is_seed()) {
// Move torrent to finished tab
@ -1193,20 +1211,18 @@ void GUI::togglePausedState(QString hash) { @@ -1193,20 +1211,18 @@ void GUI::togglePausedState(QString hash) {
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(h.is_paused()) {
h.resume();
resumedTorrent(h);
if(inDownloadList) {
downloadingTorrentTab->resumeTorrent(hash);
updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList());
}else{
finishedTorrentTab->resumeTorrent(hash);
updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList());
}
}else{
h.pause();
pausedTorrent(h);
if(inDownloadList) {
downloadingTorrentTab->pauseTorrent(hash);
updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList());
}else{
finishedTorrentTab->pauseTorrent(hash);
updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList());
}
}
@ -1222,13 +1238,7 @@ void GUI::on_actionPause_All_triggered() { @@ -1222,13 +1238,7 @@ void GUI::on_actionPause_All_triggered() {
if(!h.is_valid() || h.is_paused()) continue;
change = true;
h.pause();
if(h.is_seed()) {
// Update in finished list
finishedTorrentTab->pauseTorrent(h.hash());
} else {
// Update in download list
downloadingTorrentTab->pauseTorrent(h.hash());
}
pausedTorrent(h);
}
if(change) {
updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList());
@ -1271,11 +1281,10 @@ void GUI::on_actionPause_triggered() { @@ -1271,11 +1281,10 @@ void GUI::on_actionPause_triggered() {
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(!h.is_paused()){
h.pause();
pausedTorrent(h);
if(inDownloadList) {
downloadingTorrentTab->pauseTorrent(hash);
updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList());
} else {
finishedTorrentTab->pauseTorrent(hash);
updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList());
}
}
@ -1299,13 +1308,7 @@ void GUI::on_actionStart_All_triggered() { @@ -1299,13 +1308,7 @@ void GUI::on_actionStart_All_triggered() {
if(!h.is_valid() || !h.is_paused()) continue;
change = true;
h.resume();
if(h.is_seed()) {
// Update in finished list
finishedTorrentTab->resumeTorrent(h.hash());
} else {
// Update in download list
downloadingTorrentTab->resumeTorrent(h.hash());
}
resumedTorrent(h);
}
if(change) {
updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList());
@ -1330,11 +1333,10 @@ void GUI::on_actionStart_triggered() { @@ -1330,11 +1333,10 @@ void GUI::on_actionStart_triggered() {
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(h.is_paused()){
h.resume();
resumedTorrent(h);
if(inDownloadList) {
downloadingTorrentTab->resumeTorrent(hash);
updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList());
} else {
finishedTorrentTab->resumeTorrent(hash);
updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList());
}
}

2
src/GUI.h

@ -160,6 +160,8 @@ class GUI : public QMainWindow, private Ui::MainWindow{ @@ -160,6 +160,8 @@ class GUI : public QMainWindow, private Ui::MainWindow{
void finishedTorrent(QTorrentHandle& h) const;
void addedTorrent(QTorrentHandle& h) const;
void checkedTorrent(QTorrentHandle& h) const;
void pausedTorrent(QTorrentHandle& h) const;
void resumedTorrent(QTorrentHandle& h) const;
void updateLists(bool force=false);
bool initWebUi(QString username, QString password, int port);
void pauseTorrent(QString hash);

13
src/bittorrent.cpp

@ -287,6 +287,7 @@ void bittorrent::pauseAllTorrents() { @@ -287,6 +287,7 @@ void bittorrent::pauseAllTorrents() {
if(!h.is_valid()) continue;
if(!h.is_paused()) {
h.pause();
emit pausedTorrent(h);
}
}
}
@ -299,20 +300,25 @@ void bittorrent::resumeAllTorrents() { @@ -299,20 +300,25 @@ void bittorrent::resumeAllTorrents() {
if(!h.is_valid()) continue;
if(h.is_paused()) {
h.resume();
emit resumedTorrent(h);
}
}
}
void bittorrent::pauseTorrent(QString hash) {
QTorrentHandle h = getTorrentHandle(hash);
if(!h.is_paused())
if(!h.is_paused()) {
h.pause();
emit pausedTorrent(h);
}
}
void bittorrent::resumeTorrent(QString hash) {
QTorrentHandle h = getTorrentHandle(hash);
if(h.is_paused())
if(h.is_paused()) {
h.resume();
emit resumedTorrent(h);
}
}
void bittorrent::loadWebSeeds(QString hash) {
@ -502,18 +508,17 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bo @@ -502,18 +508,17 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bo
}
// Send torrent addition signal
if(!from_url.isNull()) {
emit addedTorrent(h);
if(fastResume)
addConsoleMessage(tr("'%1' resumed. (fast resume)", "'/home/y/xxx.torrent' was resumed. (fast resume)").arg(from_url));
else
addConsoleMessage(tr("'%1' added to download list.", "'/home/y/xxx.torrent' was added to download list.").arg(from_url));
}else{
emit addedTorrent(h);
if(fastResume)
addConsoleMessage(tr("'%1' resumed. (fast resume)", "'/home/y/xxx.torrent' was resumed. (fast resume)").arg(file));
else
addConsoleMessage(tr("'%1' added to download list.", "'/home/y/xxx.torrent' was added to download list.").arg(file));
}
emit addedTorrent(h);
}
// Check in .priorities file if the user filtered files

2
src/bittorrent.h

@ -165,6 +165,8 @@ class bittorrent : public QObject { @@ -165,6 +165,8 @@ class bittorrent : public QObject {
signals:
void addedTorrent(QTorrentHandle& h);
void deletedTorrent(QString hash);
void pausedTorrent(QTorrentHandle& h);
void resumedTorrent(QTorrentHandle& h);
void finishedTorrent(QTorrentHandle& h);
void fullDiskError(QTorrentHandle& h);
void trackerError(QString hash, QString time, QString msg);

7
src/downloadingTorrents.cpp

@ -168,13 +168,6 @@ void DownloadingTorrents::showPropertiesFromHash(QString hash) { @@ -168,13 +168,6 @@ void DownloadingTorrents::showPropertiesFromHash(QString hash) {
prop->show();
}
void DownloadingTorrents::resumeTorrent(QString hash){
int row = getRowFromHash(hash);
Q_ASSERT(row != -1);
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/stalled.png"))), Qt::DecorationRole);
setRowColor(row, QString::fromUtf8("grey"));
}
// Remove a torrent from the download list but NOT from the BT Session
void DownloadingTorrents::deleteTorrent(QString hash) {
int row = getRowFromHash(hash);

1
src/downloadingTorrents.h

@ -86,7 +86,6 @@ class DownloadingTorrents : public QWidget, public Ui::downloading{ @@ -86,7 +86,6 @@ class DownloadingTorrents : public QWidget, public Ui::downloading{
public slots:
bool updateTorrent(QTorrentHandle h);
void pauseTorrent(QString hash);
void resumeTorrent(QString hash);
void deleteTorrent(QString hash);
void propertiesSelection();
void updateFileSizeAndProgress(QString hash);

Loading…
Cancel
Save