Browse Source

- Removed logging panel for now. It will be replaced by a seperate dialog in order to simplify the default UI.

adaptive-webui-19844
Christophe Dumez 16 years ago
parent
commit
f0049f1dae
  1. 4
      src/FinishedTorrents.cpp
  2. 2
      src/FinishedTorrents.h
  3. 79
      src/GUI.cpp
  4. 3
      src/GUI.h
  5. 110
      src/bittorrent.cpp
  6. 32
      src/bittorrent.h
  7. 94
      src/download.ui
  8. 98
      src/downloadingTorrents.cpp
  9. 15
      src/downloadingTorrents.h
  10. 2
      src/eventmanager.cpp
  11. 2
      src/eventmanager.h
  12. 4
      src/httpserver.cpp
  13. 4
      src/options_imp.cpp
  14. 2
      src/options_imp.h
  15. 29
      src/torrentAddition.h

4
src/FinishedTorrents.cpp

@ -37,7 +37,7 @@ FinishedTorrents::FinishedTorrents(QObject *parent, bittorrent *BTSession) : par @@ -37,7 +37,7 @@ FinishedTorrents::FinishedTorrents(QObject *parent, bittorrent *BTSession) : par
setupUi(this);
actionStart->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/play.png")));
actionPause->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/pause.png")));
connect(BTSession, SIGNAL(addedTorrent(QString, QTorrentHandle&, bool)), this, SLOT(torrentAdded(QString, QTorrentHandle&, bool)));
connect(BTSession, SIGNAL(addedTorrent(QTorrentHandle&)), this, SLOT(torrentAdded(QTorrentHandle&)));
finishedListModel = new QStandardItemModel(0,7);
finishedListModel->setHeaderData(F_NAME, Qt::Horizontal, tr("Name", "i.e: file name"));
finishedListModel->setHeaderData(F_SIZE, Qt::Horizontal, tr("Size", "i.e: file size"));
@ -141,7 +141,7 @@ void FinishedTorrents::addTorrent(QString hash){ @@ -141,7 +141,7 @@ void FinishedTorrents::addTorrent(QString hash){
emit finishedTorrentsNumberChanged(nbFinished);
}
void FinishedTorrents::torrentAdded(QString, QTorrentHandle& h, bool) {
void FinishedTorrents::torrentAdded(QTorrentHandle& h) {
QString hash = h.hash();
if(BTSession->isFinished(hash)) {
addTorrent(hash);

2
src/FinishedTorrents.h

@ -64,7 +64,7 @@ class FinishedTorrents : public QWidget, public Ui::seeding { @@ -64,7 +64,7 @@ class FinishedTorrents : public QWidget, public Ui::seeding {
void sortFinishedListFloat(int index, Qt::SortOrder sortOrder);
void sortFinishedListString(int index, Qt::SortOrder sortOrder);
void updateFileSize(QString hash);
void torrentAdded(QString path, QTorrentHandle& h, bool fastResume);
void torrentAdded(QTorrentHandle& h);
void on_actionSet_upload_limit_triggered();
void notifyTorrentDoubleClicked(const QModelIndex& index);
void hideOrShowColumnName();

79
src/GUI.cpp

@ -120,7 +120,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis @@ -120,7 +120,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
toolBar->layout()->setSpacing(7);
// creating options
options = new options_imp(this);
connect(options, SIGNAL(status_changed(QString, bool)), this, SLOT(OptionsSaved(QString, bool)));
connect(options, SIGNAL(status_changed(bool)), this, SLOT(OptionsSaved(bool)));
BTSession = new bittorrent();
connect(BTSession, SIGNAL(fullDiskError(QTorrentHandle&)), this, SLOT(fullDiskError(QTorrentHandle&)));
connect(BTSession, SIGNAL(finishedTorrent(QTorrentHandle&)), this, SLOT(finishedTorrent(QTorrentHandle&)));
@ -130,7 +130,6 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis @@ -130,7 +130,6 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
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(deletedTorrent(QString)), this, SLOT(deleteTorrent(QString)));
connect(BTSession, SIGNAL(torrent_ratio_deleted(QString)), this, SLOT(deleteRatioTorrent(QString)));
connect(BTSession, SIGNAL(pausedTorrent(QString)), this, SLOT(pauseTorrent(QString)));
connect(BTSession, SIGNAL(updateUnfinishedTorrentNumber()), this, SLOT(updateUnfinishedTorrentNumberCalc()));
connect(BTSession, SIGNAL(updateFinishedTorrentNumber()), this, SLOT(updateFinishedTorrentNumberCalc()));
@ -373,7 +372,7 @@ void GUI::finishedTorrent(QTorrentHandle& h) const { @@ -373,7 +372,7 @@ void GUI::finishedTorrent(QTorrentHandle& h) const {
qDebug("We received a finished signal for torrent %s, but it already has a .finished file", hash.toUtf8().data());
}
if(show_msg)
downloadingTorrentTab->setInfoBar(tr("%1 has finished downloading.", "e.g: xxx.avi has finished downloading.").arg(fileName));
BTSession->addConsoleMessage(tr("%1 has finished downloading.", "e.g: xxx.avi has finished downloading.").arg(fileName));
downloadingTorrentTab->deleteTorrent(hash);
finishedTorrentTab->addTorrent(hash);
if(show_msg && systrayIntegration && useNotificationBalloons) {
@ -398,7 +397,7 @@ void GUI::fullDiskError(QTorrentHandle& h) const { @@ -398,7 +397,7 @@ void GUI::fullDiskError(QTorrentHandle& h) const {
}else{
downloadingTorrentTab->pauseTorrent(hash);
}
downloadingTorrentTab->setInfoBar(tr("An error occured (full disk?), '%1' paused.", "e.g: An error occured (full disk?), 'xxx.avi' paused.").arg(h.name()));
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() {
@ -709,9 +708,7 @@ void GUI::dropEvent(QDropEvent *event) { @@ -709,9 +708,7 @@ void GUI::dropEvent(QDropEvent *event) {
continue;
}
if(useTorrentAdditionDialog) {
torrentAdditionDialog *dialog = new torrentAdditionDialog(this);
connect(dialog, SIGNAL(torrentAddition(QString, bool, QString)), BTSession, SLOT(addTorrent(QString, bool, QString)));
connect(dialog, SIGNAL(setInfoBarGUI(QString, QColor)), downloadingTorrentTab, SLOT(setInfoBar(QString, QColor)));
torrentAdditionDialog *dialog = new torrentAdditionDialog(this, BTSession);
dialog->showLoad(file);
}else{
BTSession->addTorrent(file);
@ -750,9 +747,7 @@ void GUI::on_actionOpen_triggered() { @@ -750,9 +747,7 @@ void GUI::on_actionOpen_triggered() {
unsigned int listSize = pathsList.size();
for(unsigned int i=0; i<listSize; ++i) {
if(useTorrentAdditionDialog) {
torrentAdditionDialog *dialog = new torrentAdditionDialog(this);
connect(dialog, SIGNAL(torrentAddition(QString, bool, QString)), BTSession, SLOT(addTorrent(QString, bool, QString)));
connect(dialog, SIGNAL(setInfoBarGUI(QString, QColor)), downloadingTorrentTab, SLOT(setInfoBar(QString, QColor)));
torrentAdditionDialog *dialog = new torrentAdditionDialog(this, BTSession);
dialog->showLoad(pathsList.at(i));
}else{
BTSession->addTorrent(pathsList.at(i));
@ -805,16 +800,9 @@ void GUI::on_actionDelete_Permanently_triggered() { @@ -805,16 +800,9 @@ void GUI::on_actionDelete_Permanently_triggered() {
QString fileName = h.name();
// Remove the torrent
BTSession->deleteTorrent(hash, true);
// Update info bar
downloadingTorrentTab->setInfoBar(tr("'%1' was removed permanently.", "'xxx.avi' was removed permanently.").arg(fileName));
}
}
void GUI::deleteRatioTorrent(QString fileName) {
// Update info bar
downloadingTorrentTab->setInfoBar(tr("'%1' was removed because its ratio reached the maximum value you set.", "%1 is a file name").arg(fileName));
}
void GUI::deleteTorrent(QString hash) {
// Delete item from list
downloadingTorrentTab->deleteTorrent(hash);
@ -865,8 +853,6 @@ void GUI::on_actionDelete_triggered() { @@ -865,8 +853,6 @@ void GUI::on_actionDelete_triggered() {
QString fileName = h.name();
// Remove the torrent
BTSession->deleteTorrent(hash, false);
// Update info bar
downloadingTorrentTab->setInfoBar(tr("'%1' was removed.", "'xxx.avi' was removed.").arg(fileName));
}
}
@ -884,9 +870,7 @@ void GUI::processParams(const QStringList& params) { @@ -884,9 +870,7 @@ void GUI::processParams(const QStringList& params) {
BTSession->downloadFromUrl(param);
}else{
if(useTorrentAdditionDialog) {
torrentAdditionDialog *dialog = new torrentAdditionDialog(this);
connect(dialog, SIGNAL(torrentAddition(QString, bool, QString)), BTSession, SLOT(addTorrent(QString, bool, QString)));
connect(dialog, SIGNAL(setInfoBarGUI(QString, QColor)), downloadingTorrentTab, SLOT(setInfoBar(QString, QColor)));
torrentAdditionDialog *dialog = new torrentAdditionDialog(this, BTSession);
dialog->showLoad(param);
}else{
BTSession->addTorrent(param);
@ -905,9 +889,7 @@ void GUI::processScannedFiles(const QStringList& params) { @@ -905,9 +889,7 @@ void GUI::processScannedFiles(const QStringList& params) {
bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool();
foreach(param, params) {
if(useTorrentAdditionDialog) {
torrentAdditionDialog *dialog = new torrentAdditionDialog(this);
connect(dialog, SIGNAL(torrentAddition(QString, bool, QString)), BTSession, SLOT(addTorrent(QString, bool, QString)));
connect(dialog, SIGNAL(setInfoBarGUI(QString, QColor)), downloadingTorrentTab, SLOT(setInfoBar(QString, QColor)));
torrentAdditionDialog *dialog = new torrentAdditionDialog(this, BTSession);
dialog->showLoad(param, true);
}else{
BTSession->addTorrent(param, true);
@ -919,9 +901,7 @@ void GUI::processDownloadedFiles(QString path, QString url) { @@ -919,9 +901,7 @@ void GUI::processDownloadedFiles(QString path, QString url) {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool();
if(useTorrentAdditionDialog) {
torrentAdditionDialog *dialog = new torrentAdditionDialog(this);
connect(dialog, SIGNAL(torrentAddition(QString, bool, QString)), BTSession, SLOT(addTorrent(QString, bool, QString)));
connect(dialog, SIGNAL(setInfoBarGUI(QString, QColor)), downloadingTorrentTab, SLOT(setInfoBar(QString, QColor)));
torrentAdditionDialog *dialog = new torrentAdditionDialog(this, BTSession);
dialog->showLoad(path, false, url);
}else{
BTSession->addTorrent(path, false, url);
@ -967,7 +947,7 @@ void GUI::configureSession(bool deleteOptions) { @@ -967,7 +947,7 @@ void GUI::configureSession(bool deleteOptions) {
BTSession->setListeningPortsRange(options->getPorts());
unsigned short new_listenPort = BTSession->getListenPort();
if(new_listenPort != old_listenPort) {
downloadingTorrentTab->setInfoBar(tr("qBittorrent is bind to port: %1", "e.g: qBittorrent is bind to port: 1666").arg( misc::toQString(new_listenPort)));
BTSession->addConsoleMessage(tr("qBittorrent is bind to port: %1", "e.g: qBittorrent is bind to port: 1666").arg( misc::toQString(new_listenPort)));
}
// * Global download limit
QPair<int, int> limits = options->getGlobalBandwidthLimits();
@ -989,18 +969,18 @@ void GUI::configureSession(bool deleteOptions) { @@ -989,18 +969,18 @@ void GUI::configureSession(bool deleteOptions) {
// * UPnP
if(options->isUPnPEnabled()) {
BTSession->enableUPnP(true);
downloadingTorrentTab->setInfoBar(tr("UPnP support [ON]"), QString::fromUtf8("blue"));
BTSession->addConsoleMessage(tr("UPnP support [ON]"), QString::fromUtf8("blue"));
} else {
BTSession->enableUPnP(false);
downloadingTorrentTab->setInfoBar(tr("UPnP support [OFF]"), QString::fromUtf8("blue"));
BTSession->addConsoleMessage(tr("UPnP support [OFF]"), QString::fromUtf8("blue"));
}
// * NAT-PMP
if(options->isNATPMPEnabled()) {
BTSession->enableNATPMP(true);
downloadingTorrentTab->setInfoBar(tr("NAT-PMP support [ON]"), QString::fromUtf8("blue"));
BTSession->addConsoleMessage(tr("NAT-PMP support [ON]"), QString::fromUtf8("blue"));
} else {
BTSession->enableNATPMP(false);
downloadingTorrentTab->setInfoBar(tr("NAT-PMP support [OFF]"), QString::fromUtf8("blue"));
BTSession->addConsoleMessage(tr("NAT-PMP support [OFF]"), QString::fromUtf8("blue"));
}
// * Proxy settings
proxy_settings proxySettings;
@ -1068,29 +1048,29 @@ void GUI::configureSession(bool deleteOptions) { @@ -1068,29 +1048,29 @@ void GUI::configureSession(bool deleteOptions) {
// Set DHT Port
BTSession->setDHTPort(new_listenPort);
if(BTSession->enableDHT(true)) {
downloadingTorrentTab->setInfoBar(tr("DHT support [ON], port: %1").arg(new_listenPort), QString::fromUtf8("blue"));
BTSession->addConsoleMessage(tr("DHT support [ON], port: %1").arg(new_listenPort), QString::fromUtf8("blue"));
} else {
downloadingTorrentTab->setInfoBar(tr("DHT support [OFF]"), QString::fromUtf8("red"));
BTSession->addConsoleMessage(tr("DHT support [OFF]"), QString::fromUtf8("red"));
}
} else {
BTSession->enableDHT(false);
downloadingTorrentTab->setInfoBar(tr("DHT support [OFF]"), QString::fromUtf8("blue"));
BTSession->addConsoleMessage(tr("DHT support [OFF]"), QString::fromUtf8("blue"));
}
// * PeX
if(options->isPeXEnabled()) {
downloadingTorrentTab->setInfoBar(tr("PeX support [ON]"), QString::fromUtf8("blue"));
BTSession->addConsoleMessage(tr("PeX support [ON]"), QString::fromUtf8("blue"));
BTSession->enablePeerExchange();
}else{
// TODO: How can we remove the extension?
downloadingTorrentTab->setInfoBar(tr("PeX support [OFF]"), QString::fromUtf8("blue"));
BTSession->addConsoleMessage(tr("PeX support [OFF]"), QString::fromUtf8("blue"));
}
// * LSD
if(options->isLSDEnabled()) {
BTSession->enableLSD(true);
downloadingTorrentTab->setInfoBar(tr("Local Peer Discovery [ON]"), QString::fromUtf8("blue"));
BTSession->addConsoleMessage(tr("Local Peer Discovery [ON]"), QString::fromUtf8("blue"));
} else {
BTSession->enableLSD(false);
downloadingTorrentTab->setInfoBar(tr("Local Peer Discovery support [OFF]"), QString::fromUtf8("blue"));
BTSession->addConsoleMessage(tr("Local Peer Discovery support [OFF]"), QString::fromUtf8("blue"));
}
// * Encryption
int encryptionState = options->getEncryptionSetting();
@ -1102,17 +1082,17 @@ void GUI::configureSession(bool deleteOptions) { @@ -1102,17 +1082,17 @@ void GUI::configureSession(bool deleteOptions) {
case 0: //Enabled
encryptionSettings.out_enc_policy = pe_settings::enabled;
encryptionSettings.in_enc_policy = pe_settings::enabled;
downloadingTorrentTab->setInfoBar(tr("Encryption support [ON]"), QString::fromUtf8("blue"));
BTSession->addConsoleMessage(tr("Encryption support [ON]"), QString::fromUtf8("blue"));
break;
case 1: // Forced
encryptionSettings.out_enc_policy = pe_settings::forced;
encryptionSettings.in_enc_policy = pe_settings::forced;
downloadingTorrentTab->setInfoBar(tr("Encryption support [FORCED]"), QString::fromUtf8("blue"));
BTSession->addConsoleMessage(tr("Encryption support [FORCED]"), QString::fromUtf8("blue"));
break;
default: // Disabled
encryptionSettings.out_enc_policy = pe_settings::disabled;
encryptionSettings.in_enc_policy = pe_settings::disabled;
downloadingTorrentTab->setInfoBar(tr("Encryption support [OFF]"), QString::fromUtf8("blue"));
BTSession->addConsoleMessage(tr("Encryption support [OFF]"), QString::fromUtf8("blue"));
}
BTSession->applyEncryptionSettings(encryptionSettings);
// * Desired ratio
@ -1122,10 +1102,8 @@ void GUI::configureSession(bool deleteOptions) { @@ -1122,10 +1102,8 @@ void GUI::configureSession(bool deleteOptions) {
// Ip Filter
if(options->isFilteringEnabled()) {
BTSession->enableIPFilter(options->getFilter());
downloadingTorrentTab->setBottomTabEnabled(1, true);
}else{
BTSession->disableIPFilter();
downloadingTorrentTab->setBottomTabEnabled(1, false);
}
// RSS
if(options->isRSSEnabled()) {
@ -1233,7 +1211,6 @@ void GUI::togglePausedState(QString hash) { @@ -1233,7 +1211,6 @@ void GUI::togglePausedState(QString hash) {
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(BTSession->isPaused(hash) && !(BTSession->isQueueingEnabled() && (BTSession->isDownloadQueued(hash) || BTSession->isUploadQueued(hash)))) {
BTSession->resumeTorrent(hash);
downloadingTorrentTab->setInfoBar(tr("'%1' resumed.", "e.g: xxx.avi resumed.").arg(h.name()));
if(inDownloadList) {
downloadingTorrentTab->resumeTorrent(hash);
updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList());
@ -1250,7 +1227,6 @@ void GUI::togglePausedState(QString hash) { @@ -1250,7 +1227,6 @@ void GUI::togglePausedState(QString hash) {
finishedTorrentTab->pauseTorrent(hash);
updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList());
}
downloadingTorrentTab->setInfoBar(tr("'%1' paused.", "xxx.avi paused.").arg(h.name()));
}
}
@ -1275,7 +1251,6 @@ void GUI::on_actionPause_All_triggered() { @@ -1275,7 +1251,6 @@ void GUI::on_actionPause_All_triggered() {
if(change) {
updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList());
updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList());
downloadingTorrentTab->setInfoBar(tr("All downloads were paused."));
}
}
@ -1346,7 +1321,6 @@ void GUI::on_actionPause_triggered() { @@ -1346,7 +1321,6 @@ void GUI::on_actionPause_triggered() {
finishedTorrentTab->pauseTorrent(hash);
updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList());
}
downloadingTorrentTab->setInfoBar(tr("'%1' paused.", "xxx.avi paused.").arg(BTSession->getTorrentHandle(hash).name()));
}
}
}
@ -1379,7 +1353,6 @@ void GUI::on_actionStart_All_triggered() { @@ -1379,7 +1353,6 @@ void GUI::on_actionStart_All_triggered() {
if(change) {
updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList());
updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList());
downloadingTorrentTab->setInfoBar(tr("All downloads were resumed."));
}
}
@ -1405,7 +1378,6 @@ void GUI::on_actionStart_triggered() { @@ -1405,7 +1378,6 @@ void GUI::on_actionStart_triggered() {
finishedTorrentTab->resumeTorrent(hash);
updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList());
}
downloadingTorrentTab->setInfoBar(tr("'%1' resumed.", "e.g: xxx.avi resumed.").arg(BTSession->getTorrentHandle(hash).name()));
}
}
}
@ -1561,7 +1533,8 @@ void GUI::on_actionOptions_triggered() { @@ -1561,7 +1533,8 @@ void GUI::on_actionOptions_triggered() {
}
// Is executed each time options are saved
void GUI::OptionsSaved(QString info, bool deleteOptions) {
void GUI::OptionsSaved(bool deleteOptions) {
BTSession->addConsoleMessage(tr("Options were saved successfully."));
bool newSystrayIntegration = options->systrayIntegration();
if(newSystrayIntegration && !systrayIntegration) {
// create the trayicon
@ -1573,8 +1546,6 @@ void GUI::OptionsSaved(QString info, bool deleteOptions) { @@ -1573,8 +1546,6 @@ void GUI::OptionsSaved(QString info, bool deleteOptions) {
delete myTrayIconMenu;
}
systrayIntegration = newSystrayIntegration;
// Update info bar
downloadingTorrentTab->setInfoBar(info);
// Update Web UI
if (options->isWebUiEnabled())
{

3
src/GUI.h

@ -161,7 +161,6 @@ class GUI : public QMainWindow, private Ui::MainWindow{ @@ -161,7 +161,6 @@ class GUI : public QMainWindow, private Ui::MainWindow{
void processDownloadedFiles(QString path, QString url);
void downloadFromURLList(const QStringList& urls);
void deleteTorrent(QString hash);
void deleteRatioTorrent(QString fileName);
void finishedTorrent(QTorrentHandle& h) const;
void torrentChecked(QString hash) const;
void updateLists();
@ -171,7 +170,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{ @@ -171,7 +170,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{
void on_actionDecreasePriority_triggered();
// Options slots
void on_actionOptions_triggered();
void OptionsSaved(QString info, bool deleteOptions);
void OptionsSaved(bool deleteOptions);
// HTTP slots
void on_actionDownload_from_URL_triggered();

110
src/bittorrent.cpp

@ -148,8 +148,9 @@ void bittorrent::deleteBigRatios() { @@ -148,8 +148,9 @@ void bittorrent::deleteBigRatios() {
QString hash = h.hash();
if(getRealRatio(hash) > max_ratio) {
QString fileName = h.name();
addConsoleMessage(tr("%1 reached the maximum ratio you set.").arg(fileName));
deleteTorrent(hash);
emit torrent_ratio_deleted(fileName);
//emit torrent_ratio_deleted(fileName);
}
}
}
@ -667,6 +668,10 @@ void bittorrent::deleteTorrent(QString hash, bool permanent) { @@ -667,6 +668,10 @@ void bittorrent::deleteTorrent(QString hash, bool permanent) {
// Deleting in a thread to avoid GUI freeze
deleter->deleteTorrent(savePath, files_arb);
}
if(permanent)
addConsoleMessage(tr("'%1' was removed permanently.", "'xxx.avi' was removed permanently.").arg(fileName));
else
addConsoleMessage(tr("'%1' was removed.", "'xxx.avi' was removed.").arg(fileName));
emit deletedTorrent(hash);
}
@ -803,12 +808,15 @@ bool bittorrent::pauseTorrent(QString hash) { @@ -803,12 +808,15 @@ bool bittorrent::pauseTorrent(QString hash) {
TorrentsStartTime.remove(hash);
TorrentsStartData.remove(hash);
}
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 success = false;
bool change = false;
QTorrentHandle h = getTorrentHandle(hash);
if(h.is_valid() && h.is_paused()) {
if(!(queueingEnabled && (isDownloadQueued(hash)||isUploadQueued(hash)))) {
@ -818,7 +826,7 @@ bool bittorrent::resumeTorrent(QString hash) { @@ -818,7 +826,7 @@ bool bittorrent::resumeTorrent(QString hash) {
TorrentsStartTime[hash] = QDateTime::currentDateTime();
}
h.resume();
success = true;
change = true;
emit resumedTorrent(hash);
}
}
@ -828,13 +836,16 @@ bool bittorrent::resumeTorrent(QString hash) { @@ -828,13 +836,16 @@ bool bittorrent::resumeTorrent(QString hash) {
int index = torrentsToPauseAfterChecking.indexOf(hash);
if(index != -1) {
torrentsToPauseAfterChecking.removeAt(index);
success = true;
change = true;
}
if(queueingEnabled) {
updateDownloadQueue();
updateUploadQueue();
}
return success;
if(change) {
addConsoleMessage(tr("'%1' resumed.", "e.g: xxx.avi resumed.").arg(h.name()));
}
return change;
}
void bittorrent::pauseAllTorrents() {
@ -926,10 +937,12 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bo @@ -926,10 +937,12 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bo
if(!fromScanDir) {
if(!from_url.isNull()) {
// If download from url, remove temp file
QFile::remove(file);
emit duplicateTorrent(from_url);
QFile::remove(file);
addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(from_url));
//emit duplicateTorrent(from_url);
}else{
emit duplicateTorrent(file);
addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(file));
//emit duplicateTorrent(file);
}
}else{
// Delete torrent from scan dir
@ -1028,19 +1041,30 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bo @@ -1028,19 +1041,30 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bo
}
// Send torrent addition signal
if(!from_url.isNull()) {
emit addedTorrent(from_url, h, fastResume);
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(file, h, fastResume);
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));
}
}catch (invalid_encoding& e) { // Raised by bdecode()
std::cerr << "Could not decode file, reason: " << e.what() << '\n';
// Display warning to tell user we can't decode the torrent file
if(!from_url.isNull()) {
emit invalidTorrent(from_url);
addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(from_url), QString::fromUtf8("red"));
//emit invalidTorrent(from_url);
QFile::remove(file);
}else{
emit invalidTorrent(file);
addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(file), QString::fromUtf8("red"));
//emit invalidTorrent(file);
}
addConsoleMessage(tr("This file is either corrupted or this isn't a torrent."),QString::fromUtf8("red"));
if(fromScanDir) {
// Remove .corrupt file in case it already exists
QFile::remove(file+".corrupt");
@ -1051,11 +1075,13 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bo @@ -1051,11 +1075,13 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bo
catch (invalid_torrent_file&) { // Raised by torrent_info constructor
// Display warning to tell user we can't decode the torrent file
if(!from_url.isNull()) {
emit invalidTorrent(from_url);
addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(from_url), QString::fromUtf8("red"));
//emit invalidTorrent(from_url);
qDebug("File path is: %s", file.toUtf8().data());
QFile::remove(file);
}else{
emit invalidTorrent(file);
addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(file), QString::fromUtf8("red"));
//emit invalidTorrent(file);
}
if(fromScanDir) {
// Remove .corrupt file in case it already exists
@ -1068,10 +1094,12 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bo @@ -1068,10 +1094,12 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bo
std::cerr << "Could not decode file, reason: " << e.what() << '\n';
// Display warning to tell user we can't decode the torrent file
if(!from_url.isNull()) {
emit invalidTorrent(from_url);
addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(from_url), QString::fromUtf8("red"));
//emit invalidTorrent(from_url);
QFile::remove(file);
}else{
emit invalidTorrent(file);
addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(file), QString::fromUtf8("red"));
//emit invalidTorrent(file);
}
if(fromScanDir) {
// Remove .corrupt file in case it already exists
@ -1408,6 +1436,31 @@ void bittorrent::saveFastResumeAndRatioData() { @@ -1408,6 +1436,31 @@ void bittorrent::saveFastResumeAndRatioData() {
}
}
QStringList bittorrent::getConsoleMessages() const {
return consoleMessages;
}
QStringList bittorrent::getPeerBanMessages() const {
return peerBanMessages;
}
void bittorrent::addConsoleMessage(QString msg, QColor color) {
if(consoleMessages.size() > 100) {
consoleMessages.removeFirst();
}
consoleMessages.append(QString::fromUtf8("<font color='grey'>")+ QTime::currentTime().toString(QString::fromUtf8("hh:mm:ss")) + QString::fromUtf8("</font> - <font color='") + color.name() +QString::fromUtf8("'><i>") + msg + QString::fromUtf8("</i></font>"));
}
void bittorrent::addPeerBanMessage(QString ip, bool from_ipfilter) {
if(peerBanMessages.size() > 100) {
peerBanMessages.removeFirst();
}
if(from_ipfilter)
peerBanMessages.append(QString::fromUtf8("<font color='grey'>")+ QTime::currentTime().toString(QString::fromUtf8("hh:mm:ss")) + QString::fromUtf8("</font> - ")+tr("<font color='red'>%1</font> <i>was blocked due to your IP filter</i>", "x.y.z.w was blocked").arg(ip));
else
peerBanMessages.append(QString::fromUtf8("<font color='grey'>")+ QTime::currentTime().toString(QString::fromUtf8("hh:mm:ss")) + QString::fromUtf8("</font> - ")+tr("<font color='red'>%1</font> <i>was banned due to corrupt pieces</i>", "x.y.z.w was banned").arg(ip));
}
void bittorrent::saveFastResumeAndRatioData(QString hash) {
QString file;
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
@ -1696,7 +1749,8 @@ void bittorrent::readAlerts() { @@ -1696,7 +1749,8 @@ void bittorrent::readAlerts() {
}
else if (dynamic_cast<listen_failed_alert*>(a.get())) {
// Level: fatal
emit portListeningFailure();
addConsoleMessage(tr("Couldn't listen on any of the given ports."), QString::fromUtf8("red"));
//emit portListeningFailure();
}
else if (tracker_alert* p = dynamic_cast<tracker_alert*>(a.get())) {
// Level: fatal
@ -1727,24 +1781,33 @@ void bittorrent::readAlerts() { @@ -1727,24 +1781,33 @@ void bittorrent::readAlerts() {
}
}
else if (portmap_error_alert* p = dynamic_cast<portmap_error_alert*>(a.get())) {
emit UPnPError(QString(p->msg().c_str()));
addConsoleMessage(tr("UPnP/NAT-PMP: Port mapping failure, message: %1").arg(QString(p->msg().c_str())), QColor("red"));
//emit UPnPError(QString(p->msg().c_str()));
}
else if (portmap_alert* p = dynamic_cast<portmap_alert*>(a.get())) {
qDebug("UPnP Success, msg: %s", p->msg().c_str());
emit UPnPSuccess(QString(p->msg().c_str()));
addConsoleMessage(tr("UPnP/NAT-PMP: Port mapping successful, message: %1").arg(QString(p->msg().c_str())), QColor("blue"));
//emit UPnPSuccess(QString(p->msg().c_str()));
}
else if (peer_blocked_alert* p = dynamic_cast<peer_blocked_alert*>(a.get())) {
emit peerBlocked(QString::fromUtf8(p->ip.to_string().c_str()));
addPeerBanMessage(QString(p->ip.to_string().c_str()), true);
//emit peerBlocked(QString::fromUtf8(p->ip.to_string().c_str()));
}
else if (peer_ban_alert* p = dynamic_cast<peer_ban_alert*>(a.get())) {
addPeerBanMessage(QString(p->ip.address().to_string().c_str()), false);
//emit peerBlocked(QString::fromUtf8(p->ip.to_string().c_str()));
}
else if (fastresume_rejected_alert* p = dynamic_cast<fastresume_rejected_alert*>(a.get())) {
QTorrentHandle h(p->handle);
if(h.is_valid()){
qDebug("/!\\ Fast resume failed for %s, reason: %s", h.name().toUtf8().data(), p->msg().c_str());
emit fastResumeDataRejected(h.name());
addConsoleMessage(tr("Fast resume data was rejected for torrent %1, checking again...").arg(h.name()), QString::fromUtf8("red"));
//emit fastResumeDataRejected(h.name());
}
}
else if (url_seed_alert* p = dynamic_cast<url_seed_alert*>(a.get())) {
emit urlSeedProblem(QString::fromUtf8(p->url.c_str()), QString::fromUtf8(p->msg().c_str()));
addConsoleMessage(tr("Url seed lookup failed for url: %1, message: %2").arg(QString::fromUtf8(p->url.c_str())).arg(QString::fromUtf8(p->msg().c_str())), QString::fromUtf8("red"));
//emit urlSeedProblem(QString::fromUtf8(p->url.c_str()), QString::fromUtf8(p->msg().c_str()));
}
else if (torrent_checked_alert* p = dynamic_cast<torrent_checked_alert*>(a.get())) {
QTorrentHandle h(p->handle);
@ -1884,7 +1947,8 @@ QString bittorrent::getSavePath(QString hash) { @@ -1884,7 +1947,8 @@ QString bittorrent::getSavePath(QString hash) {
// download the torrent file to a tmp location, then
// add it to download list
void bittorrent::downloadFromUrl(QString url) {
emit aboutToDownloadFromUrl(url);
addConsoleMessage(tr("Downloading '%1', please wait...", "e.g: Downloading 'xxx.torrent', please wait...").arg(url), QPalette::WindowText);
//emit aboutToDownloadFromUrl(url);
// Launch downloader thread
downloader->downloadUrl(url);
}

32
src/bittorrent.h

@ -26,6 +26,8 @@ @@ -26,6 +26,8 @@
#include <QPair>
#include <QStringList>
#include <QDateTime>
#include <QApplication>
#include <QPalette>
#include <libtorrent/session.hpp>
#include <libtorrent/ip_filter.hpp>
@ -38,7 +40,7 @@ class deleteThread; @@ -38,7 +40,7 @@ class deleteThread;
class QTimer;
class FilterParserThread;
class bittorrent : public QObject{
class bittorrent : public QObject {
Q_OBJECT
private:
@ -56,6 +58,8 @@ class bittorrent : public QObject{ @@ -56,6 +58,8 @@ class bittorrent : public QObject{
QHash<QString, size_type> TorrentsStartData;
QHash<QString, QPair<size_type,size_type> > ratioData;
QHash<QString, QHash<QString, QString> > trackersErrors;
QStringList consoleMessages;
QStringList peerBanMessages;
deleteThread *deleter;
QStringList finishedTorrents;
QStringList unfinishedTorrents;
@ -114,6 +118,8 @@ class bittorrent : public QObject{ @@ -114,6 +118,8 @@ class bittorrent : public QObject{
bool isDownloadQueued(QString hash) const;
bool isUploadQueued(QString hash) const;
int loadTorrentPriority(QString hash);
QStringList getConsoleMessages() const;
QStringList getPeerBanMessages() const;
public slots:
void addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false);
@ -177,6 +183,8 @@ class bittorrent : public QObject{ @@ -177,6 +183,8 @@ class bittorrent : public QObject{
void setMaxActiveDownloads(int val);
void setMaxActiveTorrents(int val);
void setETACalculation(bool enable);
void addConsoleMessage(QString msg, QColor color=QApplication::palette().color(QPalette::WindowText));
void addPeerBanMessage(QString msg, bool from_ipfilter);
protected slots:
void scanDirectory();
@ -187,29 +195,29 @@ class bittorrent : public QObject{ @@ -187,29 +195,29 @@ class bittorrent : public QObject{
void deleteBigRatios();
signals:
void invalidTorrent(QString path);
void duplicateTorrent(QString path);
void addedTorrent(QString path, QTorrentHandle& h, bool fastResume);
//void invalidTorrent(QString path);
//void duplicateTorrent(QString path);
void addedTorrent(QTorrentHandle& h);
void deletedTorrent(QString hash);
void pausedTorrent(QString hash);
void resumedTorrent(QString hash);
void finishedTorrent(QTorrentHandle& h);
void fullDiskError(QTorrentHandle& h);
void trackerError(QString hash, QString time, QString msg);
void portListeningFailure();
//void portListeningFailure();
void trackerAuthenticationRequired(QTorrentHandle& h);
void scanDirFoundTorrents(const QStringList& pathList);
void newDownloadedTorrent(QString path, QString url);
void aboutToDownloadFromUrl(QString url);
//void aboutToDownloadFromUrl(QString url);
void updateFileSize(QString hash);
void peerBlocked(QString);
//void peerBlocked(QString);
void downloadFromUrlFailure(QString url, QString reason);
void fastResumeDataRejected(QString name);
void urlSeedProblem(QString url, QString msg);
//void fastResumeDataRejected(QString name);
//void urlSeedProblem(QString url, QString msg);
void torrentFinishedChecking(QString hash);
void torrent_ratio_deleted(QString fileName);
void UPnPError(QString msg);
void UPnPSuccess(QString msg);
//void torrent_ratio_deleted(QString fileName);
//void UPnPError(QString msg);
//void UPnPSuccess(QString msg);
void updateFinishedTorrentNumber();
void updateUnfinishedTorrentNumber();
void forceUnfinishedListUpdate();

94
src/download.ui

@ -57,95 +57,6 @@ @@ -57,95 +57,6 @@
</item>
</layout>
</item>
<item>
<widget class="QTabWidget" name="tabBottom" >
<property name="maximumSize" >
<size>
<width>16777215</width>
<height>142</height>
</size>
</property>
<property name="tabPosition" >
<enum>QTabWidget::West</enum>
</property>
<property name="currentIndex" >
<number>0</number>
</property>
<widget class="QWidget" name="log_tab" >
<attribute name="title" >
<string>Log</string>
</attribute>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>9</number>
</property>
<property name="topMargin" >
<number>9</number>
</property>
<property name="rightMargin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<number>9</number>
</property>
<item>
<widget class="QTextBrowser" name="infoBar" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize" >
<size>
<width>16777215</width>
<height>120</height>
</size>
</property>
<property name="contextMenuPolicy" >
<enum>Qt::CustomContextMenu</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="filter_tab" >
<attribute name="title" >
<string>IP filter</string>
</attribute>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>9</number>
</property>
<property name="topMargin" >
<number>9</number>
</property>
<property name="rightMargin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<number>9</number>
</property>
<item>
<widget class="QTextBrowser" name="textBlockedUsers" >
<property name="maximumSize" >
<size>
<width>16777215</width>
<height>123</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
<action name="actionStart" >
<property name="text" >
@ -162,11 +73,6 @@ @@ -162,11 +73,6 @@
<string>Delete</string>
</property>
</action>
<action name="actionClearLog" >
<property name="text" >
<string>Clear</string>
</property>
</action>
<action name="actionPreview_file" >
<property name="text" >
<string>Preview file</string>

98
src/downloadingTorrents.cpp

@ -39,7 +39,6 @@ DownloadingTorrents::DownloadingTorrents(QObject *parent, bittorrent *BTSession) @@ -39,7 +39,6 @@ DownloadingTorrents::DownloadingTorrents(QObject *parent, bittorrent *BTSession)
actionStart->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/play.png")));
actionPause->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/pause.png")));
actionDelete->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/delete.png")));
actionClearLog->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/delete.png")));
actionPreview_file->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/preview.png")));
actionSet_upload_limit->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/seeding.png")));
actionSet_download_limit->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/downloading.png")));
@ -68,16 +67,7 @@ DownloadingTorrents::DownloadingTorrents(QObject *parent, bittorrent *BTSession) @@ -68,16 +67,7 @@ DownloadingTorrents::DownloadingTorrents(QObject *parent, bittorrent *BTSession)
downloadList->hideColumn(HASH);
loadHiddenColumns();
connect(BTSession, SIGNAL(addedTorrent(QString, QTorrentHandle&, bool)), this, SLOT(torrentAdded(QString, QTorrentHandle&, bool)));
connect(BTSession, SIGNAL(duplicateTorrent(QString)), this, SLOT(torrentDuplicate(QString)));
connect(BTSession, SIGNAL(invalidTorrent(QString)), this, SLOT(torrentCorrupted(QString)));
connect(BTSession, SIGNAL(portListeningFailure()), this, SLOT(portListeningFailure()));
connect(BTSession, SIGNAL(peerBlocked(QString)), this, SLOT(addLogPeerBlocked(const QString)));
connect(BTSession, SIGNAL(fastResumeDataRejected(QString)), this, SLOT(addFastResumeRejectedAlert(QString)));
connect(BTSession, SIGNAL(aboutToDownloadFromUrl(QString)), this, SLOT(displayDownloadingUrlInfos(QString)));
connect(BTSession, SIGNAL(urlSeedProblem(QString, QString)), this, SLOT(addUrlSeedError(QString, QString)));
connect(BTSession, SIGNAL(UPnPError(QString)), this, SLOT(displayUPnPError(QString)));
connect(BTSession, SIGNAL(UPnPSuccess(QString)), this, SLOT(displayUPnPSuccess(QString)));
connect(BTSession, SIGNAL(addedTorrent(QTorrentHandle&)), this, SLOT(torrentAdded(QTorrentHandle&)));
connect(BTSession, SIGNAL(forceUnfinishedListUpdate()), this, SLOT(updateDlList()));
// Load last columns width for download list
@ -93,7 +83,6 @@ DownloadingTorrents::DownloadingTorrents(QObject *parent, bittorrent *BTSession) @@ -93,7 +83,6 @@ DownloadingTorrents::DownloadingTorrents(QObject *parent, bittorrent *BTSession)
connect(downloadList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayDLListMenu(const QPoint&)));
downloadList->header()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(downloadList->header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayDLHoSMenu(const QPoint&)));
connect(infoBar, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayInfoBarMenu(const QPoint&)));
// Actions
connect(actionPause, SIGNAL(triggered()), (GUI*)parent, SLOT(on_actionPause_triggered()));
connect(actionStart, SIGNAL(triggered()), (GUI*)parent, SLOT(on_actionStart_triggered()));
@ -117,7 +106,7 @@ DownloadingTorrents::DownloadingTorrents(QObject *parent, bittorrent *BTSession) @@ -117,7 +106,7 @@ DownloadingTorrents::DownloadingTorrents(QObject *parent, bittorrent *BTSession)
connect(actionHOSColPriority, SIGNAL(triggered()), this, SLOT(hideOrShowColumnPriority()));
// Set info Bar infos
setInfoBar(tr("qBittorrent %1 started.", "e.g: qBittorrent v0.x started.").arg(QString::fromUtf8(""VERSION)));
BTSession->addConsoleMessage(tr("qBittorrent %1 started.", "e.g: qBittorrent v0.x started.").arg(QString::fromUtf8(""VERSION)));
qDebug("Download tab built");
}
@ -142,16 +131,6 @@ void DownloadingTorrents::notifyTorrentDoubleClicked(const QModelIndex& index) { @@ -142,16 +131,6 @@ void DownloadingTorrents::notifyTorrentDoubleClicked(const QModelIndex& index) {
emit torrentDoubleClicked(hash, false);
}
void DownloadingTorrents::addLogPeerBlocked(QString ip) {
static unsigned int nbLines = 0;
++nbLines;
if(nbLines > 200) {
textBlockedUsers->clear();
nbLines = 1;
}
textBlockedUsers->append(QString::fromUtf8("<font color='grey'>")+ QTime::currentTime().toString(QString::fromUtf8("hh:mm:ss")) + QString::fromUtf8("</font> - ")+tr("<font color='red'>%1</font> <i>was blocked</i>", "x.y.z.w was blocked").arg(ip));
}
unsigned int DownloadingTorrents::getNbTorrentsInList() const {
return nbTorrents;
}
@ -176,12 +155,6 @@ QString DownloadingTorrents::getHashFromRow(unsigned int row) const { @@ -176,12 +155,6 @@ QString DownloadingTorrents::getHashFromRow(unsigned int row) const {
return DLListModel->data(DLListModel->index(row, HASH)).toString();
}
void DownloadingTorrents::setBottomTabEnabled(unsigned int index, bool b){
if(index and !b)
tabBottom->setCurrentIndex(0);
tabBottom->setTabEnabled(index, b);
}
// Show torrent properties dialog
void DownloadingTorrents::showProperties(const QModelIndex &index) {
showPropertiesFromHash(DLListModel->data(DLListModel->index(index.row(), HASH)).toString());
@ -214,34 +187,6 @@ void DownloadingTorrents::deleteTorrent(QString hash) { @@ -214,34 +187,6 @@ void DownloadingTorrents::deleteTorrent(QString hash) {
emit unfinishedTorrentsNumberChanged(nbTorrents);
}
void DownloadingTorrents::displayUPnPError(QString msg) {
setInfoBar(tr("UPnP/NAT-PMP: Port mapping failure, message: %1").arg(msg), QColor("red"));
}
void DownloadingTorrents::displayUPnPSuccess(QString msg) {
DownloadingTorrents::setInfoBar(tr("UPnP/NAT-PMP: Port mapping successful, message: %1").arg(msg), QColor("blue"));
}
// Update Info Bar information
void DownloadingTorrents::setInfoBar(QString info, QColor color) {
static unsigned int nbLines = 0;
++nbLines;
// Check log size, clear it if too big
if(nbLines > 200) {
infoBar->clear();
nbLines = 1;
}
infoBar->append(QString::fromUtf8("<font color='grey'>")+ QTime::currentTime().toString(QString::fromUtf8("hh:mm:ss")) + QString::fromUtf8("</font> - <font color='") + color.name() +QString::fromUtf8("'><i>") + info + QString::fromUtf8("</i></font>"));
}
void DownloadingTorrents::addFastResumeRejectedAlert(QString name) {
setInfoBar(tr("Fast resume data was rejected for torrent %1, checking again...").arg(name), QString::fromUtf8("red"));
}
void DownloadingTorrents::addUrlSeedError(QString url, QString msg) {
setInfoBar(tr("Url seed lookup failed for url: %1, message: %2").arg(url).arg(msg), QString::fromUtf8("red"));
}
void DownloadingTorrents::on_actionSet_download_limit_triggered() {
QModelIndexList selectedIndexes = downloadList->selectionModel()->selectedIndexes();
QModelIndex index;
@ -481,10 +426,6 @@ void DownloadingTorrents::hideOrShowColumnPriority() { @@ -481,10 +426,6 @@ void DownloadingTorrents::hideOrShowColumnPriority() {
hideOrShowColumn(PRIORITY);
}
void DownloadingTorrents::on_actionClearLog_triggered() {
infoBar->clear();
}
// getter, return the action hide or show whose id is index
QAction* DownloadingTorrents::getActionHoSCol(int index) {
switch(index) {
@ -535,14 +476,6 @@ QStringList DownloadingTorrents::getSelectedTorrents(bool only_one) const{ @@ -535,14 +476,6 @@ QStringList DownloadingTorrents::getSelectedTorrents(bool only_one) const{
return res;
}
void DownloadingTorrents::displayInfoBarMenu(const QPoint& pos) {
// Log Menu
QMenu myLogMenu(this);
myLogMenu.addAction(actionClearLog);
// XXX: Why mapToGlobal() is not enough?
myLogMenu.exec(mapToGlobal(pos)+QPoint(44,305));
}
void DownloadingTorrents::sortProgressColumnDelayed() {
if(delayedSorting) {
sortDownloadListFloat(PROGRESS, delayedSortingOrder);
@ -865,7 +798,7 @@ bool DownloadingTorrents::loadColWidthDLList() { @@ -865,7 +798,7 @@ bool DownloadingTorrents::loadColWidthDLList() {
}
// Called when a torrent is added
void DownloadingTorrents::torrentAdded(QString path, QTorrentHandle& h, bool fastResume) {
void DownloadingTorrents::torrentAdded(QTorrentHandle& h) {
QString hash = h.hash();
if(BTSession->isFinished(hash)) {
return;
@ -891,25 +824,10 @@ void DownloadingTorrents::torrentAdded(QString path, QTorrentHandle& h, bool fas @@ -891,25 +824,10 @@ void DownloadingTorrents::torrentAdded(QString path, QTorrentHandle& h, bool fas
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/connecting.png"))), Qt::DecorationRole);
setRowColor(row, QString::fromUtf8("grey"));
}
if(!fastResume) {
setInfoBar(tr("'%1' added to download list.", "'/home/y/xxx.torrent' was added to download list.").arg(path));
}else{
setInfoBar(tr("'%1' resumed. (fast resume)", "'/home/y/xxx.torrent' was resumed. (fast resume)").arg(path));
}
++nbTorrents;
emit unfinishedTorrentsNumberChanged(nbTorrents);
}
// Called when trying to add a duplicate torrent
void DownloadingTorrents::torrentDuplicate(QString path) {
setInfoBar(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(path));
}
void DownloadingTorrents::torrentCorrupted(QString path) {
setInfoBar(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(path), QString::fromUtf8("red"));
setInfoBar(tr("This file is either corrupted or this isn't a torrent."),QString::fromUtf8("red"));
}
void DownloadingTorrents::updateFileSizeAndProgress(QString hash) {
int row = getRowFromHash(hash);
Q_ASSERT(row != -1);
@ -918,12 +836,6 @@ void DownloadingTorrents::updateFileSizeAndProgress(QString hash) { @@ -918,12 +836,6 @@ void DownloadingTorrents::updateFileSizeAndProgress(QString hash) {
DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)h.progress()));
}
// Called when we couldn't listen on any port
// in the given range.
void DownloadingTorrents::portListeningFailure() {
setInfoBar(tr("Couldn't listen on any of the given ports."), QString::fromUtf8("red"));
}
// Set the color of a row in data model
void DownloadingTorrents::setRowColor(int row, QColor color) {
unsigned int nbColumns = DLListModel->columnCount()-1;
@ -943,7 +855,3 @@ int DownloadingTorrents::getRowFromHash(QString hash) const{ @@ -943,7 +855,3 @@ int DownloadingTorrents::getRowFromHash(QString hash) const{
}
return -1;
}
void DownloadingTorrents::displayDownloadingUrlInfos(QString url) {
setInfoBar(tr("Downloading '%1', please wait...", "e.g: Downloading 'xxx.torrent', please wait...").arg(url), QPalette::WindowText);
}

15
src/downloadingTorrents.h

@ -63,27 +63,18 @@ class DownloadingTorrents : public QWidget, public Ui::downloading{ @@ -63,27 +63,18 @@ class DownloadingTorrents : public QWidget, public Ui::downloading{
void torrentFinished(QString hash);
protected slots:
void addLogPeerBlocked(QString);
void addFastResumeRejectedAlert(QString);
void addUrlSeedError(QString url, QString msg);
void on_actionSet_download_limit_triggered();
void notifyTorrentDoubleClicked(const QModelIndex& index);
void on_actionSet_upload_limit_triggered();
void displayDLListMenu(const QPoint& pos);
void displayDLHoSMenu(const QPoint&);
void on_actionClearLog_triggered();
void displayInfoBarMenu(const QPoint& pos);
void addTorrent(QString hash);
void sortDownloadList(int index, Qt::SortOrder startSortOrder=Qt::AscendingOrder, bool fromLoadColWidth=false);
void sortDownloadListFloat(int index, Qt::SortOrder sortOrder);
void sortDownloadListString(int index, Qt::SortOrder sortOrder);
void saveColWidthDLList() const;
void torrentAdded(QString path, QTorrentHandle& h, bool fastResume);
void torrentDuplicate(QString path);
void torrentCorrupted(QString path);
void portListeningFailure();
void torrentAdded(QTorrentHandle& h);
void setRowColor(int row, QColor color);
void displayDownloadingUrlInfos(QString url);
void showProperties(const QModelIndex &index);
void hideOrShowColumnName();
void hideOrShowColumnSize();
@ -94,16 +85,12 @@ class DownloadingTorrents : public QWidget, public Ui::downloading{ @@ -94,16 +85,12 @@ class DownloadingTorrents : public QWidget, public Ui::downloading{
void hideOrShowColumnRatio();
void hideOrShowColumnEta();
void hideOrShowColumnPriority();
void displayUPnPError(QString msg);
void displayUPnPSuccess(QString msg);
public slots:
void updateDlList();
void setInfoBar(QString info, QColor color=QApplication::palette().color(QPalette::WindowText));
void pauseTorrent(QString hash);
void resumeTorrent(QString hash);
void deleteTorrent(QString hash);
void setBottomTabEnabled(unsigned int index, bool b);
void propertiesSelection();
void sortProgressColumnDelayed();
void updateFileSizeAndProgress(QString hash);

2
src/eventmanager.cpp

@ -65,7 +65,7 @@ bool EventManager::isUpdated(ulong r) const @@ -65,7 +65,7 @@ bool EventManager::isUpdated(ulong r) const
return (r < revision);
}
void EventManager::addedTorrent(QString, QTorrentHandle& h)
void EventManager::addedTorrent(QTorrentHandle& h)
{
QVariantMap event;
event["type"] = QVariant("add");

2
src/eventmanager.h

@ -50,7 +50,7 @@ class EventManager : public QObject @@ -50,7 +50,7 @@ class EventManager : public QObject
void updated();
public slots:
void addedTorrent(QString path, QTorrentHandle& h);
void addedTorrent(QTorrentHandle& h);
void deletedTorrent(QString hash);
void modifiedTorrent(QTorrentHandle h);
};

4
src/httpserver.cpp

@ -38,10 +38,10 @@ HttpServer::HttpServer(bittorrent *BTSession, int msec, QObject* parent) : QTcpS @@ -38,10 +38,10 @@ HttpServer::HttpServer(bittorrent *BTSession, int msec, QObject* parent) : QTcpS
{
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(h.is_valid())
manager->addedTorrent(QString(), h);
manager->addedTorrent(h);
}
//connect BTSession to manager
connect(BTSession, SIGNAL(addedTorrent(QString, QTorrentHandle&, bool)), manager, SLOT(addedTorrent(QString, QTorrentHandle&)));
connect(BTSession, SIGNAL(addedTorrent(QTorrentHandle&)), manager, SLOT(addedTorrent(QTorrentHandle&)));
connect(BTSession, SIGNAL(deletedTorrent(QString)), manager, SLOT(deletedTorrent(QString)));
//set timer
QTimer *timer = new QTimer(this);

4
src/options_imp.cpp

@ -816,7 +816,7 @@ void options_imp::on_buttonBox_accepted(){ @@ -816,7 +816,7 @@ void options_imp::on_buttonBox_accepted(){
applyButton->setEnabled(false);
// set infobar text
this->hide();
emit status_changed(tr("Options were saved successfully."), true);
emit status_changed(true);
}else{
setAttribute(Qt::WA_DeleteOnClose);
accept();
@ -826,7 +826,7 @@ void options_imp::on_buttonBox_accepted(){ @@ -826,7 +826,7 @@ void options_imp::on_buttonBox_accepted(){
void options_imp::applySettings(QAbstractButton* button) {
if(button == applyButton){
saveOptions();
emit status_changed(tr("Options were saved successfully."), false);
emit status_changed(false);
}
}

2
src/options_imp.h

@ -151,7 +151,7 @@ class options_imp : public QDialog, private Ui::Dialog { @@ -151,7 +151,7 @@ class options_imp : public QDialog, private Ui::Dialog {
void useStyle();
signals:
void status_changed(QString, bool) const;
void status_changed(bool) const;
void exitWithCancel();
};

29
src/torrentAddition.h

@ -34,6 +34,7 @@ @@ -34,6 +34,7 @@
#include <libtorrent/session.hpp>
#include <libtorrent/bencode.hpp>
#include "bittorrent.h"
#include "misc.h"
#include "PropListDelegate.h"
#include "ui_addTorrentDialog.h"
@ -44,11 +45,8 @@ using namespace libtorrent; @@ -44,11 +45,8 @@ using namespace libtorrent;
class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
Q_OBJECT
signals:
void setInfoBarGUI(QString info, QColor color);
void torrentAddition(QString filePath, bool fromScanDir, QString from_url);
private:
bittorrent *BTSession;
QString fileName;
QString hash;
QString filePath;
@ -59,9 +57,10 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ @@ -59,9 +57,10 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
unsigned int nbFiles;
public:
torrentAdditionDialog(QWidget *parent) : QDialog(parent) {
torrentAdditionDialog(QWidget *parent, bittorrent* _BTSession) : QDialog(parent) {
setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
BTSession = _BTSession;
// Set Properties list model
PropListModel = new QStandardItemModel(0,5);
PropListModel->setHeaderData(NAME, Qt::Horizontal, tr("File name"));
@ -126,12 +125,12 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ @@ -126,12 +125,12 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
catch (invalid_torrent_file&){ // Raised by torrent_info constructor
// Display warning to tell user we can't decode the torrent file
if(!from_url.isNull()){
emit setInfoBarGUI(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+from_url+QString::fromUtf8("'"), QString::fromUtf8("red"));
BTSession->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+from_url+QString::fromUtf8("'"), QString::fromUtf8("red"));
QFile::remove(filePath);
}else{
emit setInfoBarGUI(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+filePath+QString::fromUtf8("'"), QString::fromUtf8("red"));
BTSession->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+filePath+QString::fromUtf8("'"), QString::fromUtf8("red"));
}
emit setInfoBarGUI(tr("This file is either corrupted or this isn't a torrent."), QString::fromUtf8("red"));
BTSession->addConsoleMessage(tr("This file is either corrupted or this isn't a torrent."), QString::fromUtf8("red"));
if(fromScanDir){
// Remove .corrupt file in case it already exists
QFile::remove(filePath+QString::fromUtf8(".corrupt"));
@ -144,13 +143,13 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ @@ -144,13 +143,13 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
std::cerr << "Could not decode file, reason: " << e.what() << '\n';
// Display warning to tell user we can't decode the torrent file
if(!from_url.isNull()){
emit setInfoBarGUI(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+from_url+QString::fromUtf8("'"), QString::fromUtf8("red"));
BTSession->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+from_url+QString::fromUtf8("'"), QString::fromUtf8("red"));
QFile::remove(filePath);
}else{
emit setInfoBarGUI(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+filePath+QString::fromUtf8("'"), QString::fromUtf8("red"));
BTSession->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+filePath+QString::fromUtf8("'"), QString::fromUtf8("red"));
}
qDebug("path is %s", filePath.toUtf8().data());
emit setInfoBarGUI(tr("This file is either corrupted or this isn't a torrent."), QString::fromUtf8("red"));
BTSession->addConsoleMessage(tr("This file is either corrupted or this isn't a torrent."), QString::fromUtf8("red"));
if(fromScanDir){
// Remove .corrupt file in case it already exists
QFile::remove(filePath+QString::fromUtf8(".corrupt"));
@ -162,13 +161,13 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ @@ -162,13 +161,13 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
catch(std::exception& e){
std::cerr << "Could not decode file, reason: " << e.what() << '\n';
if(!from_url.isNull()){
emit setInfoBarGUI(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+from_url+QString::fromUtf8("'"), QString::fromUtf8("red"));
BTSession->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+from_url+QString::fromUtf8("'"), QString::fromUtf8("red"));
QFile::remove(filePath);
}else{
emit setInfoBarGUI(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+filePath+QString::fromUtf8("'"), QString::fromUtf8("red"));
BTSession->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+filePath+QString::fromUtf8("'"), QString::fromUtf8("red"));
}
qDebug("path is %s", filePath.toUtf8().data());
emit setInfoBarGUI(tr("This file is either corrupted or this isn't a torrent."), QString::fromUtf8("red"));
BTSession->addConsoleMessage(tr("This file is either corrupted or this isn't a torrent."), QString::fromUtf8("red"));
if(fromScanDir){
// Remove .corrupt file in case it already exists
QFile::remove(filePath+QString::fromUtf8(".corrupt"));
@ -469,7 +468,7 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ @@ -469,7 +468,7 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
// save filtered files
savePiecesPriorities();
// Add to download list
emit torrentAddition(filePath, fromScanDir, from_url);
BTSession->addTorrent(filePath, fromScanDir, from_url);
close();
}
};

Loading…
Cancel
Save