#include "PreferencesDialog.h"
PreferencesDialog::PreferencesDialog(QWidget* parent, Qt::WindowFlags f) :
- QDialog(parent, f), // Superclass
- dirLineEdit_(NULL),
- dialogButtons_(NULL),
- settings_()
+ QDialog(parent, f), // Superclass
+ dirLineEdit_(NULL),
+ dialogButtons_(NULL),
+ settings_()
{
- setWindowTitle("Preferences");
+ setWindowTitle("Preferences");
- QBoxLayout *verticalBox = new QBoxLayout(QBoxLayout::TopToBottom);
- QBoxLayout *horizontalBox1 = new QBoxLayout(QBoxLayout::LeftToRight);
- setLayout(verticalBox);
- verticalBox->addLayout(horizontalBox1);
+ QBoxLayout *verticalBox = new QBoxLayout(QBoxLayout::TopToBottom);
+ QBoxLayout *horizontalBox1 = new QBoxLayout(QBoxLayout::LeftToRight);
+ setLayout(verticalBox);
+ verticalBox->addLayout(horizontalBox1);
- QLabel *dirLabel = new QLabel(tr("Download directory: "));
- dirLineEdit_ = new QLineEdit(this);
- QPushButton *browseDirButton = new QPushButton(tr("Browse.."));
+ 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);
+ horizontalBox1->addWidget(dirLabel);
+ horizontalBox1->addWidget(dirLineEdit_);
+ horizontalBox1->addWidget(browseDirButton);
- connect(browseDirButton, SIGNAL(clicked()),
- this, SLOT(on_browseDirButtonClicked()));
+ connect(browseDirButton, SIGNAL(clicked()),
+ this, SLOT(on_browseDirButtonClicked()));
- dialogButtons_ = new QDialogButtonBox(this);
- dialogButtons_->setStandardButtons(QDialogButtonBox::Ok
- | QDialogButtonBox::Apply
- | QDialogButtonBox::Cancel);
+ dialogButtons_ = new QDialogButtonBox(this);
+ dialogButtons_->setStandardButtons(QDialogButtonBox::Ok
+ | QDialogButtonBox::Apply
+ | QDialogButtonBox::Cancel);
- verticalBox->addWidget(dialogButtons_);
+ verticalBox->addWidget(dialogButtons_);
- connect(dialogButtons_, SIGNAL(clicked(QAbstractButton*)),
- this, SLOT(on_buttonClicked(QAbstractButton*)));
+ connect(dialogButtons_, SIGNAL(clicked(QAbstractButton*)),
+ this, SLOT(on_buttonClicked(QAbstractButton*)));
- // Set saved preference values to fields.
- ReadSettings();
+ // Set saved preference values to fields.
+ ReadSettings();
}
// ======================== SLOTS ========================
void PreferencesDialog::on_browseDirButtonClicked()
{
- QFileDialog *dialog
- = new QFileDialog(this, "Download directory",
- QString(), tr("Torrent files (*.torrent)"));
+ QFileDialog *dialog
+ = new QFileDialog(this, "Download directory",
+ QString(), tr("Torrent files (*.torrent)"));
- dialog->setFileMode(QFileDialog::Directory);
- dialog->setOption(QFileDialog::ShowDirsOnly, true);
+ dialog->setFileMode(QFileDialog::Directory);
+ dialog->setOption(QFileDialog::ShowDirsOnly, true);
- connect(dialog, SIGNAL(fileSelected(const QString&)),
- this, SLOT(on_downloadDirectorySelected(const QString&)));
+ connect(dialog, SIGNAL(fileSelected(const QString&)),
+ this, SLOT(on_downloadDirectorySelected(const QString&)));
- dialog->show();
+ dialog->show();
}
void PreferencesDialog::on_buttonClicked(QAbstractButton* button)
{
- switch (dialogButtons_->buttonRole ( button ) )
- {
- case QDialogButtonBox::AcceptRole :
- qDebug() << "PreferencesDialog: OK";
- WriteSettings();
- close();
- break;
- case QDialogButtonBox::ApplyRole :
- qDebug() << "PreferencesDialog: APPLY";
- WriteSettings();
- break;
- case QDialogButtonBox::RejectRole :
- qDebug() << "PreferencesDialog: CANCEL";
- close();
- break;
- default:
- return;
- }
+ switch (dialogButtons_->buttonRole ( button ) ) {
+ case QDialogButtonBox::AcceptRole :
+ qDebug() << "PreferencesDialog: OK";
+ WriteSettings();
+ close();
+ break;
+ case QDialogButtonBox::ApplyRole :
+ qDebug() << "PreferencesDialog: APPLY";
+ WriteSettings();
+ break;
+ case QDialogButtonBox::RejectRole :
+ qDebug() << "PreferencesDialog: CANCEL";
+ close();
+ break;
+ default:
+ return;
+ }
}
void PreferencesDialog::on_downloadDirectorySelected(const QString& directory)
{
- qDebug() << "PreferencesDialog::on_downloadDirectorySelected(): " << directory;
- // Torrent filename empty, do nothing.
- if (directory == "")
- return;
+ qDebug() << "PreferencesDialog::on_downloadDirectorySelected(): " << directory;
+ // Torrent filename empty, do nothing.
+ if (directory == "")
+ return;
- dirLineEdit_->insert(directory);
+ dirLineEdit_->insert(directory);
- /// @todo check that user has privileges to write to this directory.
+ /// @todo check that user has privileges to write to this directory.
}
// ========================= Private functions ==========================
void PreferencesDialog::WriteSettings()
{
- settings_.setValue("download/directory", dirLineEdit_->text());
+ settings_.setValue("download/directory", dirLineEdit_->text());
- // 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.
+ // 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.
}
void PreferencesDialog::ReadSettings()
{
- dirLineEdit_->insert(settings_.value("download/directory").toString());
+ dirLineEdit_->insert(settings_.value("download/directory").toString());
- // 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.
+ // 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.
}