diff --git a/src/GUI.cpp b/src/GUI.cpp index 70a33acda..c6d194115 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -42,6 +42,7 @@ #include "searchEngine.h" #include "rss_imp.h" #include "FinishedTorrents.h" +#include "allocationDlg.h" /***************************************************** * * diff --git a/src/allocationDlg.h b/src/allocationDlg.h new file mode 100644 index 000000000..7376a6d5a --- /dev/null +++ b/src/allocationDlg.h @@ -0,0 +1,84 @@ +/* + * Bittorrent Client using Qt4 and libtorrent. + * Copyright (C) 2006 Christophe Dumez + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contact : chris@qbittorrent.org + */ + +#ifndef BANDWIDTH_ALLOCATION_H +#define BANDWIDTH_ALLOCATION_H + +#include +#include "ui_bandwidth_limit.h" +#include "misc.h" +#include "bittorrent.h" + +using namespace libtorrent; + +class BandwidthAllocationDialog : public QDialog, private Ui_bandwidth_dlg { + public: + BandwidthAllocationDialog(QWidget *parent, bool uploadMode, bittorrent *BTSession, QString hash): QDialog(parent), uploadMode(uploadMode){ + setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + this->BTSession = BTSession; + if(uploadMode) + lblTitle->setText(tr("Upload limit:")); + else + lblTitle->setText(tr("Download limit:")); + connect(bandwidthSlider, SIGNAL(valueChanged(int)), this, SLOT(updateBandwidthLabel(int))); + h = BTSession->getTorrentHandle(hash); + if(!h.is_valid()){ + qDebug("Error: Invalid Handle!"); + close(); + } + // TODO: Uncomment the following lines as soon as we upgrade + // to libtorrent svn to correctly initialize the bandwidth slider. +// if(uploadMode) { +// int val = h.upload_limit(); +// if(val > bandwidthSlider->maximum() || val < bandwidthSlider->minimum()) +// val = -1; +// bandwidthSlider->setValue(val); +// } else { +// int val = h.download_limit(); +// if(val > bandwidthSlider->maximum() || val < bandwidthSlider->minimum()) +// val = -1; +// bandwidthSlider->setValue(val); +// } + } + + ~BandwidthAllocationDialog(){ + qDebug("Deleting bandwidth allocation dialog"); + } + + protected slots: + void updateBandwidthLabel(int val){ + if(val == -1){ + limit_lbl->setText(tr("Unlimited", "Unlimited (bandwidth)")); + kb_lbl->setText(""); + }else{ + limit_lbl->setText(QString(misc::toString(val).c_str())); + kb_lbl->setText(tr("KiB/s")); + } + } + + private: + bool uploadMode; + bittorrent *BTSession; + torrent_handle h; +}; + +#endif diff --git a/src/bandwidth_limit.ui b/src/bandwidth_limit.ui new file mode 100644 index 000000000..165caff73 --- /dev/null +++ b/src/bandwidth_limit.ui @@ -0,0 +1,129 @@ + + bandwidth_dlg + + + + 0 + 0 + 222 + 99 + + + + Bandwidth allocation + + + + 9 + + + 6 + + + + + 0 + + + 6 + + + + + + + + + + + + + + + + + + + KiB/s + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + -1 + + + 1000 + + + -1 + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + bandwidth_dlg + accept() + + + 212 + 77 + + + 157 + 98 + + + + + buttonBox + rejected() + bandwidth_dlg + reject() + + + 212 + 83 + + + 221 + 98 + + + + + diff --git a/src/src.pro b/src/src.pro index a71474431..3ce1f9e98 100644 --- a/src/src.pro +++ b/src/src.pro @@ -117,11 +117,12 @@ HEADERS += GUI.h misc.h options_imp.h about_imp.h \ downloadThread.h downloadFromURLImp.h \ torrentAddition.h deleteThread.h \ bittorrent.h searchEngine.h \ - rss.h rss_imp.h FinishedTorrents.h + rss.h rss_imp.h FinishedTorrents.h \ + allocationDlg.h FORMS += MainWindow.ui options.ui about.ui \ properties.ui createtorrent.ui preview.ui \ login.ui downloadFromURL.ui addTorrentDialog.ui \ - search.ui rss.ui seeding.ui + search.ui rss.ui seeding.ui bandwidth_limit.ui SOURCES += GUI.cpp \ main.cpp \ options_imp.cpp \