#include #include #include "configdialog.h" #include "configdialog.moc" ConfigDialog::ConfigDialog(QWidget *parent) : QDialog(parent) { ui = new Ui::ConfigDialog(); ui->setupUi(this); connectSlots(); } void ConfigDialog::connectSlots() { QPushButton * ui_button = qFindChild(this, "rulesDirButton"); Q_ASSERT(ui_button != NULL); connect(ui_button, SIGNAL(clicked()), this, SLOT(browseRulesDir())); connect(this, SIGNAL(accepted()), this, SLOT(acceptValues())); connect(this, SIGNAL(rejected()), this, SLOT(discardValues())); } void ConfigDialog::browseRulesDir() { QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), "/home", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); if (dir.length() > 0) { QLineEdit * ui_ed = qFindChild(this, "rulesDirEdit"); Q_ASSERT(ui_ed != NULL); ui_ed->setText(dir); } } void ConfigDialog::acceptValues() { QLineEdit * ui_ed = qFindChild(this, "rulesDirEdit"); Q_ASSERT(ui_ed != NULL); _rulesDir = ui_ed->text(); } void ConfigDialog::discardValues() { QLineEdit * ui_ed = qFindChild(this, "rulesDirEdit"); Q_ASSERT(ui_ed != NULL); ui_ed->setText(_rulesDir); } static ConfigDialog * _config_dialog = NULL; /** \brief Return existing Config Dialog instance (creating it if needed) */ QDialog * getConfigDialog() { if (_config_dialog != NULL) return _config_dialog; _config_dialog = new ConfigDialog(); return _config_dialog; }