1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-25 14:04:23 +00:00

- Ok. torrentless downloads paused state is now restored properly (once metadata is received)

This commit is contained in:
Christophe Dumez 2009-08-17 08:08:51 +00:00
parent 7e71de558a
commit e429126934
4 changed files with 114 additions and 89 deletions

View File

@ -143,6 +143,7 @@ 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(torrentPaused(QTorrentHandle&)), this, SLOT(setPaused(QTorrentHandle&)));
qDebug("create tabWidget"); qDebug("create tabWidget");
tabs = new QTabWidget(); tabs = new QTabWidget();
// Download torrents tab // Download torrents tab
@ -255,7 +256,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
scrapeTimer->start(20000); scrapeTimer->start(20000);
qDebug("GUI Built"); qDebug("GUI Built");
} }
// Destructor // Destructor
GUI::~GUI() { GUI::~GUI() {
qDebug("GUI destruction"); qDebug("GUI destruction");
@ -308,7 +309,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
delete BTSession; delete BTSession;
qDebug("5"); qDebug("5");
} }
void GUI::displayRSSTab(bool enable) { void GUI::displayRSSTab(bool enable) {
if(enable) { if(enable) {
// RSS tab // RSS tab
@ -324,7 +325,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
} }
} }
void GUI::scrapeTrackers() { void GUI::scrapeTrackers() {
std::vector<torrent_handle> torrents = BTSession->getTorrents(); std::vector<torrent_handle> torrents = BTSession->getTorrents();
std::vector<torrent_handle>::iterator torrentIT; std::vector<torrent_handle>::iterator torrentIT;
@ -334,7 +335,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
h.scrape_tracker(); h.scrape_tracker();
} }
} }
void GUI::updateRatio() { void GUI::updateRatio() {
// Update ratio info // Update ratio info
float ratio = 1.; float ratio = 1.;
@ -353,19 +354,19 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
// Update DHT nodes // Update DHT nodes
DHTLbl->setText(tr("DHT: %1 nodes").arg(QString::number(sessionStatus.dht_nodes))); DHTLbl->setText(tr("DHT: %1 nodes").arg(QString::number(sessionStatus.dht_nodes)));
} }
void GUI::on_actionWebsite_triggered() const { void GUI::on_actionWebsite_triggered() const {
QDesktopServices::openUrl(QUrl(QString::fromUtf8("http://www.qbittorrent.org"))); QDesktopServices::openUrl(QUrl(QString::fromUtf8("http://www.qbittorrent.org")));
} }
void GUI::on_actionDocumentation_triggered() const { void GUI::on_actionDocumentation_triggered() const {
QDesktopServices::openUrl(QUrl(QString::fromUtf8("http://wiki.qbittorrent.org"))); QDesktopServices::openUrl(QUrl(QString::fromUtf8("http://wiki.qbittorrent.org")));
} }
void GUI::on_actionBugReport_triggered() const { void GUI::on_actionBugReport_triggered() const {
QDesktopServices::openUrl(QUrl(QString::fromUtf8("http://bugs.qbittorrent.org"))); QDesktopServices::openUrl(QUrl(QString::fromUtf8("http://bugs.qbittorrent.org")));
} }
void GUI::writeSettings() { void GUI::writeSettings() {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
settings.beginGroup(QString::fromUtf8("MainWindow")); settings.beginGroup(QString::fromUtf8("MainWindow"));
@ -373,7 +374,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
settings.setValue(QString::fromUtf8("pos"), pos()); settings.setValue(QString::fromUtf8("pos"), pos());
settings.endGroup(); settings.endGroup();
} }
// called when a torrent has finished // called when a torrent has finished
void GUI::finishedTorrent(QTorrentHandle& h) const { void GUI::finishedTorrent(QTorrentHandle& h) const {
qDebug("In GUI, a torrent has finished"); qDebug("In GUI, a torrent has finished");
@ -393,7 +394,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
myTrayIcon->showMessage(tr("Download finished"), tr("%1 has finished downloading.", "e.g: xxx.avi has finished downloading.").arg(fileName), QSystemTrayIcon::Information, TIME_TRAY_BALLOON); myTrayIcon->showMessage(tr("Download finished"), tr("%1 has finished downloading.", "e.g: xxx.avi has finished downloading.").arg(fileName), QSystemTrayIcon::Information, TIME_TRAY_BALLOON);
} }
} }
void GUI::addedTorrent(QTorrentHandle& h) const { void GUI::addedTorrent(QTorrentHandle& h) const {
if(h.is_seed()) { if(h.is_seed()) {
finishedTorrentTab->addTorrent(h.hash()); finishedTorrentTab->addTorrent(h.hash());
@ -401,7 +402,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
downloadingTorrentTab->addTorrent(h.hash()); downloadingTorrentTab->addTorrent(h.hash());
} }
} }
void GUI::pausedTorrent(QTorrentHandle& h) const { void GUI::pausedTorrent(QTorrentHandle& h) const {
if(h.is_seed()) { if(h.is_seed()) {
finishedTorrentTab->pauseTorrent(h.hash()); finishedTorrentTab->pauseTorrent(h.hash());
@ -409,7 +410,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
downloadingTorrentTab->pauseTorrent(h.hash()); downloadingTorrentTab->pauseTorrent(h.hash());
} }
} }
void GUI::resumedTorrent(QTorrentHandle& h) const { void GUI::resumedTorrent(QTorrentHandle& h) const {
if(h.is_seed()) { if(h.is_seed()) {
finishedTorrentTab->updateTorrent(h); finishedTorrentTab->updateTorrent(h);
@ -417,7 +418,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
downloadingTorrentTab->updateTorrent(h); downloadingTorrentTab->updateTorrent(h);
} }
} }
void GUI::checkedTorrent(QTorrentHandle& h) const { void GUI::checkedTorrent(QTorrentHandle& h) const {
if(h.is_seed()) { if(h.is_seed()) {
// Move torrent to finished tab // Move torrent to finished tab
@ -432,7 +433,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
} }
} }
// Notification when disk is full // Notification when disk is full
void GUI::fullDiskError(QTorrentHandle& h, QString msg) const { void GUI::fullDiskError(QTorrentHandle& h, QString msg) const {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
@ -443,16 +444,22 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
// Download will be paused by libtorrent. Updating GUI information accordingly // Download will be paused by libtorrent. Updating GUI information accordingly
QString hash = h.hash(); QString hash = h.hash();
qDebug("Full disk error, pausing torrent %s", hash.toLocal8Bit().data()); qDebug("Full disk error, pausing torrent %s", hash.toLocal8Bit().data());
setPaused(h);
BTSession->addConsoleMessage(tr("An error occured (full disk?), '%1' paused.", "e.g: An error occured (full disk?), 'xxx.avi' paused.").arg(h.name()));
}
void GUI::setPaused(QTorrentHandle &h) const {
Q_ASSERT(h.is_paused());
qDebug("Marking torrent %s as paused", h.hash().toUtf8().data());
if(h.is_seed()) { if(h.is_seed()) {
// In finished list // In finished list
qDebug("Automatically paused torrent was in finished list"); qDebug("Automatically paused torrent was in finished list");
finishedTorrentTab->pauseTorrent(hash); finishedTorrentTab->pauseTorrent(h.hash());
}else{ }else{
downloadingTorrentTab->pauseTorrent(hash); downloadingTorrentTab->pauseTorrent(h.hash());
} }
BTSession->addConsoleMessage(tr("An error occured (full disk?), '%1' paused.", "e.g: An error occured (full disk?), 'xxx.avi' paused.").arg(h.name()));
} }
void GUI::createKeyboardShortcuts() { void GUI::createKeyboardShortcuts() {
actionCreate_torrent->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+N"))); actionCreate_torrent->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+N")));
actionOpen->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+O"))); actionOpen->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+O")));
@ -478,26 +485,26 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
actionDecreasePriority->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+-"))); actionDecreasePriority->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+-")));
actionIncreasePriority->setShortcut(QKeySequence(QString::fromUtf8("Ctrl++"))); actionIncreasePriority->setShortcut(QKeySequence(QString::fromUtf8("Ctrl++")));
} }
// Keyboard shortcuts slots // Keyboard shortcuts slots
void GUI::displayDownTab() const { void GUI::displayDownTab() const {
tabs->setCurrentIndex(0); tabs->setCurrentIndex(0);
} }
void GUI::displayUpTab() const { void GUI::displayUpTab() const {
tabs->setCurrentIndex(1); tabs->setCurrentIndex(1);
} }
void GUI::displaySearchTab() const { void GUI::displaySearchTab() const {
tabs->setCurrentIndex(2); tabs->setCurrentIndex(2);
} }
void GUI::displayRSSTab() const { void GUI::displayRSSTab() const {
tabs->setCurrentIndex(3); tabs->setCurrentIndex(3);
} }
// End of keyboard shortcuts slots // End of keyboard shortcuts slots
void GUI::readSettings() { void GUI::readSettings() {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
settings.beginGroup(QString::fromUtf8("MainWindow")); settings.beginGroup(QString::fromUtf8("MainWindow"));
@ -505,7 +512,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
move(settings.value(QString::fromUtf8("pos"), screenCenter()).toPoint()); move(settings.value(QString::fromUtf8("pos"), screenCenter()).toPoint());
settings.endGroup(); settings.endGroup();
} }
void GUI::balloonClicked() { void GUI::balloonClicked() {
if(isHidden()) { if(isHidden()) {
show(); show();
@ -516,13 +523,13 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
activateWindow(); activateWindow();
} }
} }
void GUI::acceptConnection() { void GUI::acceptConnection() {
clientConnection = localServer->nextPendingConnection(); clientConnection = localServer->nextPendingConnection();
connect(clientConnection, SIGNAL(disconnected()), this, SLOT(readParamsOnSocket())); connect(clientConnection, SIGNAL(disconnected()), this, SLOT(readParamsOnSocket()));
qDebug("accepted connection from another instance"); qDebug("accepted connection from another instance");
} }
void GUI::readParamsOnSocket() { void GUI::readParamsOnSocket() {
if(clientConnection) { if(clientConnection) {
QByteArray params = clientConnection->readAll(); QByteArray params = clientConnection->readAll();
@ -532,26 +539,26 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
} }
} }
void GUI::handleDownloadFromUrlFailure(QString url, QString reason) const{ void GUI::handleDownloadFromUrlFailure(QString url, QString reason) const{
// Display a message box // Display a message box
QMessageBox::critical(0, tr("Url download error"), tr("Couldn't download file at url: %1, reason: %2.").arg(url).arg(reason)); QMessageBox::critical(0, tr("Url download error"), tr("Couldn't download file at url: %1, reason: %2.").arg(url).arg(reason));
} }
void GUI::on_actionSet_global_upload_limit_triggered() { void GUI::on_actionSet_global_upload_limit_triggered() {
qDebug("actionSet_global_upload_limit_triggered"); qDebug("actionSet_global_upload_limit_triggered");
new BandwidthAllocationDialog(this, true, BTSession, QStringList()); new BandwidthAllocationDialog(this, true, BTSession, QStringList());
} }
void GUI::on_actionShow_console_triggered() { void GUI::on_actionShow_console_triggered() {
new consoleDlg(this, BTSession); new consoleDlg(this, BTSession);
} }
void GUI::on_actionSet_global_download_limit_triggered() { void GUI::on_actionSet_global_download_limit_triggered() {
qDebug("actionSet_global_download_limit_triggered"); qDebug("actionSet_global_download_limit_triggered");
new BandwidthAllocationDialog(this, false, BTSession, QStringList()); new BandwidthAllocationDialog(this, false, BTSession, QStringList());
} }
void GUI::on_actionPreview_file_triggered() { void GUI::on_actionPreview_file_triggered() {
QString hash; QString hash;
switch(tabs->currentIndex()){ switch(tabs->currentIndex()){
@ -567,7 +574,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
QTorrentHandle h = BTSession->getTorrentHandle(hash); QTorrentHandle h = BTSession->getTorrentHandle(hash);
new previewSelect(this, h); new previewSelect(this, h);
} }
void GUI::openDestinationFolder() const { void GUI::openDestinationFolder() const {
QStringList hashes; QStringList hashes;
switch(tabs->currentIndex()){ switch(tabs->currentIndex()){
@ -590,7 +597,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
} }
} }
void GUI::goBuyPage() const { void GUI::goBuyPage() const {
QStringList hashes; QStringList hashes;
switch(tabs->currentIndex()){ switch(tabs->currentIndex()){
@ -609,28 +616,28 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
QDesktopServices::openUrl("http://match.sharemonkey.com/?info_hash="+hash+"&n="+h.name()+"&cid=33"); QDesktopServices::openUrl("http://match.sharemonkey.com/?info_hash="+hash+"&n="+h.name()+"&cid=33");
} }
} }
// Necessary if we want to close the window // Necessary if we want to close the window
// in one time if "close to systray" is enabled // in one time if "close to systray" is enabled
void GUI::on_actionExit_triggered() { void GUI::on_actionExit_triggered() {
force_exit = true; force_exit = true;
close(); close();
} }
void GUI::previewFile(QString filePath) { void GUI::previewFile(QString filePath) {
QDesktopServices::openUrl(QString("file://")+filePath); QDesktopServices::openUrl(QString("file://")+filePath);
} }
int GUI::getCurrentTabIndex() const{ int GUI::getCurrentTabIndex() const{
if(isMinimized() || isHidden()) if(isMinimized() || isHidden())
return -1; return -1;
return tabs->currentIndex(); return tabs->currentIndex();
} }
void GUI::setTabText(int index, QString text) const { void GUI::setTabText(int index, QString text) const {
tabs->setTabText(index, text); tabs->setTabText(index, text);
} }
// Toggle Main window visibility // Toggle Main window visibility
void GUI::toggleVisibility(QSystemTrayIcon::ActivationReason e) { void GUI::toggleVisibility(QSystemTrayIcon::ActivationReason e) {
if(e == QSystemTrayIcon::Trigger || e == QSystemTrayIcon::DoubleClick) { if(e == QSystemTrayIcon::Trigger || e == QSystemTrayIcon::DoubleClick) {
@ -650,38 +657,38 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
} }
} }
// Center window // Center window
QPoint GUI::screenCenter() const{ QPoint GUI::screenCenter() const{
int scrn = 0; int scrn = 0;
QWidget *w = this->topLevelWidget(); QWidget *w = this->topLevelWidget();
if(w) if(w)
scrn = QApplication::desktop()->screenNumber(w); scrn = QApplication::desktop()->screenNumber(w);
else if(QApplication::desktop()->isVirtualDesktop()) else if(QApplication::desktop()->isVirtualDesktop())
scrn = QApplication::desktop()->screenNumber(QCursor::pos()); scrn = QApplication::desktop()->screenNumber(QCursor::pos());
else else
scrn = QApplication::desktop()->screenNumber(this); scrn = QApplication::desktop()->screenNumber(this);
QRect desk(QApplication::desktop()->availableGeometry(scrn)); QRect desk(QApplication::desktop()->availableGeometry(scrn));
return QPoint((desk.width() - this->frameGeometry().width()) / 2, (desk.height() - this->frameGeometry().height()) / 2); return QPoint((desk.width() - this->frameGeometry().width()) / 2, (desk.height() - this->frameGeometry().height()) / 2);
} }
// Display About Dialog // Display About Dialog
void GUI::on_actionAbout_triggered() { void GUI::on_actionAbout_triggered() {
//About dialog //About dialog
new about(this); new about(this);
} }
void GUI::showEvent(QShowEvent *e) { void GUI::showEvent(QShowEvent *e) {
qDebug("** Show Event **"); qDebug("** Show Event **");
updateLists(true); updateLists(true);
e->accept(); e->accept();
} }
// Called when we close the program // Called when we close the program
void GUI::closeEvent(QCloseEvent *e) { void GUI::closeEvent(QCloseEvent *e) {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
bool goToSystrayOnExit = settings.value(QString::fromUtf8("Preferences/General/CloseToTray"), false).toBool(); bool goToSystrayOnExit = settings.value(QString::fromUtf8("Preferences/General/CloseToTray"), false).toBool();
if(!force_exit && systrayIntegration && goToSystrayOnExit && !this->isHidden()) { if(!force_exit && systrayIntegration && goToSystrayOnExit && !this->isHidden()) {
@ -717,14 +724,14 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
e->accept(); e->accept();
qApp->exit(); qApp->exit();
} }
// Display window to create a torrent // Display window to create a torrent
void GUI::on_actionCreate_torrent_triggered() { void GUI::on_actionCreate_torrent_triggered() {
createtorrent *ct = new createtorrent(this); createtorrent *ct = new createtorrent(this);
connect(ct, SIGNAL(torrent_to_seed(QString)), this, SLOT(addTorrent(QString))); connect(ct, SIGNAL(torrent_to_seed(QString)), this, SLOT(addTorrent(QString)));
} }
bool GUI::event(QEvent * e) { bool GUI::event(QEvent * e) {
if(e->type() == QEvent::WindowStateChange) { if(e->type() == QEvent::WindowStateChange) {
//Now check to see if the window is minimised //Now check to see if the window is minimised
@ -738,7 +745,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
return QMainWindow::event(e); return QMainWindow::event(e);
} }
// Action executed when a file is dropped // Action executed when a file is dropped
void GUI::dropEvent(QDropEvent *event) { void GUI::dropEvent(QDropEvent *event) {
event->acceptProposedAction(); event->acceptProposedAction();
@ -776,7 +783,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
} }
} }
// Decode if we accept drag 'n drop or not // Decode if we accept drag 'n drop or not
void GUI::dragEnterEvent(QDragEnterEvent *event) { void GUI::dragEnterEvent(QDragEnterEvent *event) {
foreach(const QString &mime, event->mimeData()->formats()){ foreach(const QString &mime, event->mimeData()->formats()){
@ -786,13 +793,13 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
event->acceptProposedAction(); event->acceptProposedAction();
} }
} }
/***************************************************** /*****************************************************
* * * *
* Torrent * * Torrent *
* * * *
*****************************************************/ *****************************************************/
// Display a dialog to allow user to add // Display a dialog to allow user to add
// torrents to download list // torrents to download list
void GUI::on_actionOpen_triggered() { void GUI::on_actionOpen_triggered() {
@ -819,7 +826,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
settings.setValue(QString::fromUtf8("MainWindowLastDir"), top_dir.join(QDir::separator())); settings.setValue(QString::fromUtf8("MainWindowLastDir"), top_dir.join(QDir::separator()));
} }
} }
// delete from download list AND from hard drive // delete from download list AND from hard drive
void GUI::on_actionDelete_Permanently_triggered() { void GUI::on_actionDelete_Permanently_triggered() {
QStringList hashes; QStringList hashes;
@ -861,13 +868,13 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
BTSession->deleteTorrent(hash, true); BTSession->deleteTorrent(hash, true);
} }
} }
void GUI::deleteTorrent(QString hash) { void GUI::deleteTorrent(QString hash) {
// Delete item from list // Delete item from list
downloadingTorrentTab->deleteTorrent(hash); downloadingTorrentTab->deleteTorrent(hash);
finishedTorrentTab->deleteTorrent(hash); finishedTorrentTab->deleteTorrent(hash);
} }
// delete selected items in the list // delete selected items in the list
void GUI::on_actionDelete_triggered() { void GUI::on_actionDelete_triggered() {
QStringList hashes; QStringList hashes;
@ -913,7 +920,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
BTSession->deleteTorrent(hash, false); BTSession->deleteTorrent(hash, false);
} }
} }
// As program parameters, we can get paths or urls. // As program parameters, we can get paths or urls.
// This function parse the parameters and call // This function parse the parameters and call
// the right addTorrent function, considering // the right addTorrent function, considering
@ -940,11 +947,11 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
} }
} }
void GUI::addTorrent(QString path) { void GUI::addTorrent(QString path) {
BTSession->addTorrent(path); BTSession->addTorrent(path);
} }
void GUI::processDownloadedFiles(QString path, QString url) { void GUI::processDownloadedFiles(QString path, QString url) {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool(); bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool();
@ -955,7 +962,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
BTSession->addTorrent(path, false, url); BTSession->addTorrent(path, false, url);
} }
} }
// Set BT session configuration // Set BT session configuration
void GUI::configureSession(bool deleteOptions) { void GUI::configureSession(bool deleteOptions) {
qDebug("Configuring session"); qDebug("Configuring session");
@ -1160,7 +1167,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
proxySettings.port = options->getProxyPort(); proxySettings.port = options->getProxyPort();
qDebug("port is %d", proxySettings.port); qDebug("port is %d", proxySettings.port);
if(options->isProxyAuthEnabled()) { if(options->isProxyAuthEnabled()) {
proxySettings.username = options->getProxyUsername().toStdString(); proxySettings.username = options->getProxyUsername().toStdString();
proxySettings.password = options->getProxyPassword().toStdString(); proxySettings.password = options->getProxyPassword().toStdString();
qDebug("username is %s", proxySettings.username.c_str()); qDebug("username is %s", proxySettings.username.c_str());
@ -1226,29 +1233,29 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
qDebug("Session configured"); qDebug("Session configured");
} }
void GUI::updateUnfinishedTorrentNumber(unsigned int nb) { void GUI::updateUnfinishedTorrentNumber(unsigned int nb) {
unsigned int paused = BTSession->getUnfinishedPausedTorrentsNb(); unsigned int paused = BTSession->getUnfinishedPausedTorrentsNb();
tabs->setTabText(0, tr("Downloads") +QString::fromUtf8(" (")+misc::toQString(nb-paused)+"/"+misc::toQString(nb)+QString::fromUtf8(")")); tabs->setTabText(0, tr("Downloads") +QString::fromUtf8(" (")+misc::toQString(nb-paused)+"/"+misc::toQString(nb)+QString::fromUtf8(")"));
} }
void GUI::updateFinishedTorrentNumber(unsigned int nb) { void GUI::updateFinishedTorrentNumber(unsigned int nb) {
unsigned int paused = BTSession->getFinishedPausedTorrentsNb(); unsigned int paused = BTSession->getFinishedPausedTorrentsNb();
tabs->setTabText(1, tr("Finished") +QString::fromUtf8(" (")+misc::toQString(nb-paused)+"/"+misc::toQString(nb)+QString::fromUtf8(")")); tabs->setTabText(1, tr("Finished") +QString::fromUtf8(" (")+misc::toQString(nb-paused)+"/"+misc::toQString(nb)+QString::fromUtf8(")"));
} }
// Allow to change action on double-click // Allow to change action on double-click
void GUI::torrentDoubleClicked(QString hash, bool finished) { void GUI::torrentDoubleClicked(QString hash, bool finished) {
int action; int action;
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
QTorrentHandle h = BTSession->getTorrentHandle(hash); QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(finished) { if(finished) {
action = settings.value(QString::fromUtf8("Preferences/Downloads/DblClOnTorFN"), 0).toInt(); action = settings.value(QString::fromUtf8("Preferences/Downloads/DblClOnTorFN"), 0).toInt();
} else { } else {
action = settings.value(QString::fromUtf8("Preferences/Downloads/DblClOnTorDl"), 0).toInt(); action = settings.value(QString::fromUtf8("Preferences/Downloads/DblClOnTorDl"), 0).toInt();
} }
switch(action) { switch(action) {
case TOGGLE_PAUSE: case TOGGLE_PAUSE:
this->togglePausedState(hash); this->togglePausedState(hash);
@ -1268,7 +1275,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
break; break;
} }
} }
// Toggle paused state of selected torrent // Toggle paused state of selected torrent
void GUI::togglePausedState(QString hash) { void GUI::togglePausedState(QString hash) {
if(tabs->currentIndex() > 1) return; if(tabs->currentIndex() > 1) return;
@ -1294,7 +1301,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
} }
} }
// Pause All Downloads in DL list // Pause All Downloads in DL list
void GUI::on_actionPause_All_triggered() { void GUI::on_actionPause_All_triggered() {
bool change = false; bool change = false;
@ -1312,7 +1319,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList()); updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList());
} }
} }
void GUI::on_actionIncreasePriority_triggered() { void GUI::on_actionIncreasePriority_triggered() {
if(tabs->currentIndex() != 0) if(tabs->currentIndex() != 0)
return; return;
@ -1322,7 +1329,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
updateLists(); updateLists();
} }
void GUI::on_actionDecreasePriority_triggered() { void GUI::on_actionDecreasePriority_triggered() {
Q_ASSERT(tabs->currentIndex() == 0); Q_ASSERT(tabs->currentIndex() == 0);
QStringList hashes = downloadingTorrentTab->getSelectedTorrents(); QStringList hashes = downloadingTorrentTab->getSelectedTorrents();
@ -1331,7 +1338,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
updateLists(); updateLists();
} }
// pause selected items in the list // pause selected items in the list
void GUI::on_actionPause_triggered() { void GUI::on_actionPause_triggered() {
bool inDownloadList = true; bool inDownloadList = true;
@ -1357,7 +1364,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
} }
} }
// Resume All Downloads in DL list // Resume All Downloads in DL list
void GUI::on_actionStart_All_triggered() { void GUI::on_actionStart_All_triggered() {
bool change = false; bool change = false;
@ -1375,7 +1382,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList()); updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList());
} }
} }
// start selected items in the list // start selected items in the list
void GUI::on_actionStart_triggered() { void GUI::on_actionStart_triggered() {
bool inDownloadList = true; bool inDownloadList = true;
@ -1401,14 +1408,14 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
} }
} }
void GUI::addUnauthenticatedTracker(QPair<QTorrentHandle,QString> tracker) { void GUI::addUnauthenticatedTracker(QPair<QTorrentHandle,QString> tracker) {
// Trackers whose authentication was cancelled // Trackers whose authentication was cancelled
if(unauthenticated_trackers.indexOf(tracker) < 0) { if(unauthenticated_trackers.indexOf(tracker) < 0) {
unauthenticated_trackers << tracker; unauthenticated_trackers << tracker;
} }
} }
// display properties of selected items // display properties of selected items
void GUI::on_actionTorrent_Properties_triggered() { void GUI::on_actionTorrent_Properties_triggered() {
if(tabs->currentIndex() > 1) return; if(tabs->currentIndex() > 1) return;
@ -1420,7 +1427,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
downloadingTorrentTab->propertiesSelection(); downloadingTorrentTab->propertiesSelection();
} }
} }
void GUI::updateLists(bool force) { void GUI::updateLists(bool force) {
if(isVisible() || force) { if(isVisible() || force) {
// update global informations // update global informations
@ -1454,7 +1461,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
setWindowTitle(tr("qBittorrent %1 (DL: %2KiB/s, UP: %3KiB/s)", "%1 is qBittorrent version").arg(QString::fromUtf8(VERSION)).arg(dl_rate).arg(up_rate)); setWindowTitle(tr("qBittorrent %1 (DL: %2KiB/s, UP: %3KiB/s)", "%1 is qBittorrent version").arg(QString::fromUtf8(VERSION)).arg(dl_rate).arg(up_rate));
} }
} }
// Called when a tracker requires authentication // Called when a tracker requires authentication
void GUI::trackerAuthenticationRequired(QTorrentHandle& h) { void GUI::trackerAuthenticationRequired(QTorrentHandle& h) {
if(unauthenticated_trackers.indexOf(QPair<QTorrentHandle,QString>(h, h.current_tracker())) < 0) { if(unauthenticated_trackers.indexOf(QPair<QTorrentHandle,QString>(h, h.current_tracker())) < 0) {
@ -1462,7 +1469,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
new trackerLogin(this, h); new trackerLogin(this, h);
} }
} }
// Check connection status and display right icon // Check connection status and display right icon
void GUI::checkConnectionStatus() { void GUI::checkConnectionStatus() {
// qDebug("Checking connection status"); // qDebug("Checking connection status");
@ -1498,13 +1505,13 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
connecStatusLblIcon->setToolTip(QString::fromUtf8("<b>")+tr("Connection status:")+QString::fromUtf8("</b><br>")+QString::fromUtf8("<i>")+tr("No direct connections. This may indicate network configuration problems.")+QString::fromUtf8("</i>")); connecStatusLblIcon->setToolTip(QString::fromUtf8("<b>")+tr("Connection status:")+QString::fromUtf8("</b><br>")+QString::fromUtf8("<i>")+tr("No direct connections. This may indicate network configuration problems.")+QString::fromUtf8("</i>"));
} }
} }
/***************************************************** /*****************************************************
* * * *
* Utils * * Utils *
* * * *
*****************************************************/ *****************************************************/
void GUI::downloadFromURLList(const QStringList& url_list) { void GUI::downloadFromURLList(const QStringList& url_list) {
foreach(const QString url, url_list) { foreach(const QString url, url_list) {
if(url.startsWith("magnet:", Qt::CaseInsensitive)) { if(url.startsWith("magnet:", Qt::CaseInsensitive)) {
@ -1514,13 +1521,13 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
} }
} }
/***************************************************** /*****************************************************
* * * *
* Options * * Options *
* * * *
*****************************************************/ *****************************************************/
void GUI::createSystrayDelayed() { void GUI::createSystrayDelayed() {
static int timeout = 10; static int timeout = 10;
if(QSystemTrayIcon::isSystemTrayAvailable()) { if(QSystemTrayIcon::isSystemTrayAvailable()) {
@ -1541,7 +1548,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
} }
} }
} }
void GUI::createTrayIcon() { void GUI::createTrayIcon() {
// Tray icon // Tray icon
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
@ -1568,14 +1575,14 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
connect(myTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleVisibility(QSystemTrayIcon::ActivationReason))); connect(myTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleVisibility(QSystemTrayIcon::ActivationReason)));
myTrayIcon->show(); myTrayIcon->show();
} }
// Display Program Options // Display Program Options
void GUI::on_actionOptions_triggered() { void GUI::on_actionOptions_triggered() {
options = new options_imp(this); options = new options_imp(this);
connect(options, SIGNAL(status_changed(bool)), this, SLOT(OptionsSaved(bool))); connect(options, SIGNAL(status_changed(bool)), this, SLOT(OptionsSaved(bool)));
options->show(); options->show();
} }
// Is executed each time options are saved // Is executed each time options are saved
void GUI::OptionsSaved(bool deleteOptions) { void GUI::OptionsSaved(bool deleteOptions) {
BTSession->addConsoleMessage(tr("Options were saved successfully.")); BTSession->addConsoleMessage(tr("Options were saved successfully."));
@ -1603,7 +1610,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
// Update session // Update session
configureSession(deleteOptions); configureSession(deleteOptions);
} }
bool GUI::initWebUi(QString username, QString password, int port) { bool GUI::initWebUi(QString username, QString password, int port) {
if(httpServer) if(httpServer)
httpServer->close(); httpServer->close();
@ -1617,16 +1624,17 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
QMessageBox::critical(this, "Web User Interface Error", "Unable to initialize HTTP Server on port " + misc::toQString(port)); QMessageBox::critical(this, "Web User Interface Error", "Unable to initialize HTTP Server on port " + misc::toQString(port));
return success; return success;
} }
/***************************************************** /*****************************************************
* * * *
* HTTP Downloader * * HTTP Downloader *
* * * *
*****************************************************/ *****************************************************/
// Display an input dialog to prompt user for // Display an input dialog to prompt user for
// an url // an url
void GUI::on_actionDownload_from_URL_triggered() { void GUI::on_actionDownload_from_URL_triggered() {
downloadFromURL *downloadFromURLDialog = new downloadFromURL(this); downloadFromURL *downloadFromURLDialog = new downloadFromURL(this);
connect(downloadFromURLDialog, SIGNAL(urlsReadyToBeDownloaded(const QStringList&)), BTSession, SLOT(downloadFromURLList(const QStringList&))); connect(downloadFromURLDialog, SIGNAL(urlsReadyToBeDownloaded(const QStringList&)), BTSession, SLOT(downloadFromURLList(const QStringList&)));
} }

View File

@ -143,6 +143,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{
void fullDiskError(QTorrentHandle& h, QString msg) const; void fullDiskError(QTorrentHandle& h, QString msg) const;
void handleDownloadFromUrlFailure(QString, QString) const; void handleDownloadFromUrlFailure(QString, QString) const;
void createSystrayDelayed(); void createSystrayDelayed();
void setPaused(QTorrentHandle &h) const;
// Keyboard shortcuts // Keyboard shortcuts
void createKeyboardShortcuts(); void createKeyboardShortcuts();
void displayDownTab() const; void displayDownTab() const;

View File

@ -1255,7 +1255,15 @@ void bittorrent::readAlerts() {
} }
else if (metadata_received_alert* p = dynamic_cast<metadata_received_alert*>(a.get())) { else if (metadata_received_alert* p = dynamic_cast<metadata_received_alert*>(a.get())) {
QTorrentHandle h(p->handle); QTorrentHandle h(p->handle);
emit metadataReceived(h); if(h.is_valid()) {
qDebug("Received metadata for %s", h.hash().toUtf8().data());
emit metadataReceived(h);
if(h.is_paused()) {
// XXX: Unfortunately libtorrent-rasterbar does not send a torrent_paused_alert
// and the torrent can be paused when metadata is received
emit torrentPaused(h);
}
}
} }
else if (file_error_alert* p = dynamic_cast<file_error_alert*>(a.get())) { else if (file_error_alert* p = dynamic_cast<file_error_alert*>(a.get())) {
QTorrentHandle h(p->handle); QTorrentHandle h(p->handle);
@ -1269,6 +1277,13 @@ void bittorrent::readAlerts() {
addConsoleMessage(tr("Couldn't listen on any of the given ports."), QString::fromUtf8("red")); addConsoleMessage(tr("Couldn't listen on any of the given ports."), QString::fromUtf8("red"));
//emit portListeningFailure(); //emit portListeningFailure();
} }
else if (torrent_paused_alert* p = dynamic_cast<torrent_paused_alert*>(a.get())) {
QTorrentHandle h(p->handle);
qDebug("Received a torrent_paused_alert for %s", h.hash().toUtf8().data());
if(h.is_valid()) {
emit torrentPaused(h);
}
}
else if (tracker_error_alert* p = dynamic_cast<tracker_error_alert*>(a.get())) { else if (tracker_error_alert* p = dynamic_cast<tracker_error_alert*>(a.get())) {
// Level: fatal // Level: fatal
QTorrentHandle h(p->handle); QTorrentHandle h(p->handle);

View File

@ -186,6 +186,7 @@ class bittorrent : public QObject {
void downloadFromUrlFailure(QString url, QString reason); void downloadFromUrlFailure(QString url, QString reason);
void torrentFinishedChecking(QTorrentHandle& h); void torrentFinishedChecking(QTorrentHandle& h);
void metadataReceived(QTorrentHandle &h); void metadataReceived(QTorrentHandle &h);
void torrentPaused(QTorrentHandle &h);
}; };
#endif #endif