X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fclient%2FPreferencesDialog.cpp;h=f4043361a8718b8331e34451b7b6d1abb4f48248;hb=6ae61ea5faec84289c549193b680c32c9d0bf395;hp=e541e909ede6a006d40242b4739806b5278eb172;hpb=55732cd61b5d6c85a5e90aee584f12cbca70e116;p=qtrapids diff --git a/src/client/PreferencesDialog.cpp b/src/client/PreferencesDialog.cpp index e541e90..f404336 100644 --- a/src/client/PreferencesDialog.cpp +++ b/src/client/PreferencesDialog.cpp @@ -22,32 +22,60 @@ #include #include #include +#include #include #include #include +#include "qtrapids/dbus.hpp" +#include "proxy.h" #include "PreferencesDialog.h" -PreferencesDialog::PreferencesDialog(QWidget* parent, Qt::WindowFlags f) : + + +PreferencesDialog::PreferencesDialog(QWidget* parent, Qt::WindowFlags f, QtRapidsServer *server) : QDialog(parent, f), // Superclass dirLineEdit_(NULL), dialogButtons_(NULL), + uploadRateSpinBox_(NULL), + downloadRateSpinBox_(NULL), + server_(server), settings_() { setWindowTitle("Preferences"); QBoxLayout *verticalBox = new QBoxLayout(QBoxLayout::TopToBottom); - QBoxLayout *horizontalBox1 = new QBoxLayout(QBoxLayout::LeftToRight); + //QBoxLayout *horizontalBox1 = new QBoxLayout(QBoxLayout::LeftToRight); + QGridLayout *grid = new QGridLayout; setLayout(verticalBox); - verticalBox->addLayout(horizontalBox1); + verticalBox->addLayout(grid); QLabel *dirLabel = new QLabel(tr("Download directory: ")); dirLineEdit_ = new QLineEdit(this); QPushButton *browseDirButton = new QPushButton(tr("Browse..")); - - horizontalBox1->addWidget(dirLabel); - horizontalBox1->addWidget(dirLineEdit_); - horizontalBox1->addWidget(browseDirButton); + + QLabel *uploadLabel = new QLabel(tr("Max. upload rate: ")); + QLabel *downloadLabel = new QLabel(tr("Max. download rate: ")); + uploadRateSpinBox_ = new QSpinBox(this); + downloadRateSpinBox_ = new QSpinBox(this); + + grid->addWidget(dirLabel, 0, 0); + grid->addWidget(dirLineEdit_, 0, 1); + grid->addWidget(browseDirButton, 0, 2); + + grid->addWidget(uploadLabel, 1, 0); + grid->addWidget(uploadRateSpinBox_, 1, 1); + grid->addWidget(downloadLabel, 2, 0); + grid->addWidget(downloadRateSpinBox_, 2, 1); + + uploadRateSpinBox_->setRange(0, 1000); + uploadRateSpinBox_->setSuffix(" kB/s"); + downloadRateSpinBox_->setRange(0, 1000); + downloadRateSpinBox_->setSuffix(" kB/s"); + +// horizontalBox1->addWidget(dirLabel); +// horizontalBox1->addWidget(dirLineEdit_); +// horizontalBox1->addWidget(browseDirButton); connect(browseDirButton, SIGNAL(clicked()), this, SLOT(on_browseDirButtonClicked())); @@ -95,7 +123,7 @@ void PreferencesDialog::on_buttonClicked(QAbstractButton* button) case QDialogButtonBox::AcceptRole : qDebug() << "PreferencesDialog: OK"; WriteSettings(); - close(); + done(QDialog::Accepted); break; case QDialogButtonBox::ApplyRole : qDebug() << "PreferencesDialog: APPLY"; @@ -103,7 +131,7 @@ void PreferencesDialog::on_buttonClicked(QAbstractButton* button) break; case QDialogButtonBox::RejectRole : qDebug() << "PreferencesDialog: CANCEL"; - close(); + done(QDialog::Rejected); break; default: return; @@ -117,6 +145,7 @@ void PreferencesDialog::on_downloadDirectorySelected(const QString& directory) if (directory == "") return; + dirLineEdit_->clear(); dirLineEdit_->insert(directory); /// @todo check that user has privileges to write to this directory. @@ -126,16 +155,37 @@ void PreferencesDialog::on_downloadDirectorySelected(const QString& directory) // ========================= Private functions ========================== void PreferencesDialog::WriteSettings() { + int ulRate = 1000*uploadRateSpinBox_->value(); + int dlRate = 1000*downloadRateSpinBox_->value(); + settings_.setValue("download/directory", dirLineEdit_->text()); - + //settings_.setValue("net/uploadRate", ulRate); + //settings_.setValue("net/downloadRate", dlRate); + // NOTE: We might need to call QSettigns::sync() here to instantly write settings. // settings are written also by QSettings() destructor and by event loop at regular interval. + + // If server pointer was given, apply settings immediately. + if (server_) { + /// @todo Use DBus interface + /// @todo Set parameters for server + /// @todo Add speedlimit functionality to Server. + qtrapids::ParamsMap_t options; + options["net/downloadRate"] = QString::number(dlRate); + options["net/uploadRate"] = QString::number(ulRate); + server_->setOptions(options); +// btSession_->setUploadRateLimit(ulRate); +// btSession_->setDownloadRateLimit(dlRate); + } + } void PreferencesDialog::ReadSettings() { dirLineEdit_->insert(settings_.value("download/directory").toString()); - + uploadRateSpinBox_->setValue(settings_.value("net/uploadRate").toInt()/1000); + downloadRateSpinBox_->setValue(settings_.value("net/downloadRate").toInt()/1000); + // NOTE: We might need to call QSettigns::sync() here to instantly write settings. // settings are written also by QSettings() destructor and by event loop at regular interval. }