summaryrefslogtreecommitdiff
path: root/src/gui_qt.cc
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@yahoo.com>2017-07-26 23:06:58 +0200
committerJoel Klinghed <the_jk@yahoo.com>2017-07-26 23:06:58 +0200
commit51587ef41ab94dca2900267a5edcab4345b8f663 (patch)
tree62d3879037fd311184d67d87a2f697a7a9bcd543 /src/gui_qt.cc
parentba31faa55abedea506443df821e32aff93378c15 (diff)
Add SSL interception to Setup in GUI
Diffstat (limited to 'src/gui_qt.cc')
-rw-r--r--src/gui_qt.cc124
1 files changed, 109 insertions, 15 deletions
diff --git a/src/gui_qt.cc b/src/gui_qt.cc
index cad859e..77e292e 100644
--- a/src/gui_qt.cc
+++ b/src/gui_qt.cc
@@ -4,6 +4,7 @@
#include <QAction>
#include <QApplication>
+#include <QCheckBox>
#include <QClipboard>
#include <QCloseEvent>
#include <QDialogButtonBox>
@@ -863,6 +864,37 @@ public:
flags, filter));
}
+ void add_bool(std::string const& id, std::string const& label,
+ bool value, std::string const& description) override {
+ values_.emplace_back(new BoolValue(id, label, description, value));
+ }
+
+ void enable(std::string const& id, bool enable) override {
+ for (auto const& value : values_) {
+ if (value->id_ == id) {
+ value->enable_ = enable;
+ if (value->edit_) {
+ value->edit_->setEnabled(enable);
+ }
+ switch (value->type_) {
+ case STRING:
+ case NUMBER:
+ break;
+ case FILE: {
+ auto v = static_cast<FileValue*>(value.get());
+ if (v->button_) v->button_->setEnabled(enable);
+ break;
+ }
+ case BOOLEAN: {
+ auto v = static_cast<BoolValue*>(value.get());
+ if (v->check_) v->check_->setEnabled(enable);
+ break;
+ }
+ }
+ }
+ }
+ }
+
std::string get_string(std::string const& id) const override {
for (auto const& value : values_) {
if (value->id_ == id && value->type_ == STRING) {
@@ -905,6 +937,20 @@ public:
return "";
}
+ bool get_bool(std::string const& id) const override {
+ for (auto const& value : values_) {
+ if (value->id_ == id && value->type_ == BOOLEAN) {
+ auto v = static_cast<BoolValue*>(value.get());
+ if (v->check_) {
+ return v->check_->isChecked();
+ }
+ return v->value_;
+ }
+ }
+ assert(false);
+ return "";
+ }
+
void set_error(std::string const& error) override {
if (!error_) {
assert(false);
@@ -927,6 +973,7 @@ protected:
STRING,
NUMBER,
FILE,
+ BOOLEAN,
};
struct Value {
@@ -934,12 +981,13 @@ protected:
std::string const id_;
std::string const label_;
std::string const description_;
+ bool enable_;
QLineEdit* edit_;
Value(Type type, std::string const& id, std::string const& label,
std::string const& description)
: type_(type), id_(id), label_(label), description_(description),
- edit_(nullptr) {
+ enable_(true), edit_(nullptr) {
}
};
@@ -967,13 +1015,25 @@ protected:
std::string value_;
uint8_t flags_;
std::vector<Filter> filter_;
+ QPushButton* button_;
FileValue(std::string const& id, std::string const& label,
std::string const& description,
std::string const& value,
uint8_t flags, std::vector<Filter> const& filter)
: Value(FILE, id, label, description), value_(value),
- flags_(flags), filter_(filter) {
+ flags_(flags), filter_(filter), button_(nullptr) {
+ }
+ };
+
+ struct BoolValue : public Value {
+ bool value_;
+ QCheckBox* check_;
+
+ BoolValue(std::string const& id, std::string const& label,
+ std::string const& description, bool value)
+ : Value(BOOLEAN, id, label, description), value_(value),
+ check_(nullptr) {
}
};
@@ -1000,9 +1060,16 @@ protected:
layout->addWidget(text, row++, 0, 1, 3);
}
for (auto& value : values_) {
- auto label = new QLabel(QString::fromStdString(value->label_));
- auto edit = new QLineEdit();
- value->edit_ = edit;
+ QWidget* label;
+ QLineEdit* edit;
+ if (value->type_ != BOOLEAN) {
+ label = new QLabel(QString::fromStdString(value->label_));
+ edit = new QLineEdit();
+ value->edit_ = edit;
+ } else {
+ label = nullptr;
+ edit = nullptr;
+ }
switch (value->type_) {
case STRING:
edit->setText(QString::fromStdString(
@@ -1020,24 +1087,45 @@ protected:
edit->setText(QString::fromStdString(
static_cast<FileValue*>(value.get())->value_));
break;
+ case BOOLEAN: {
+ auto v = static_cast<BoolValue*>(value.get());
+ assert(!label);
+ v->check_ = new QCheckBox(QString::fromStdString(v->label_));
+ label = v->check_;
+ v->check_->setChecked(v->value_);
+ v->check_->setEnabled(v->enable_);
+ v->check_->connect(v->check_, &QCheckBox::stateChanged,
+ [=](int UNUSED(state)) {
+ notify_changed(v->id_);
+ });
+ break;
+ }
}
auto vp = value.get();
- edit->connect(edit, &QLineEdit::textChanged,
- [=](QString const& UNUSED(text)) {
- notify_changed(vp->id_);
- });
- layout->addWidget(label, row, 0);
+ if (edit) {
+ edit->connect(edit, &QLineEdit::textChanged,
+ [=](QString const& UNUSED(text)) {
+ notify_changed(vp->id_);
+ });
+ edit->setEnabled(value->enable_);
+ }
if (value->type_ == FILE) {
- auto button = new QPushButton("...");
+ auto v = static_cast<FileValue*>(vp);
+ v->button_ = new QPushButton("...");
+ v->button_->setEnabled(v->enable_);
edit->setReadOnly(true);
- dialog_->connect(button, &QPushButton::clicked,
+ dialog_->connect(v->button_, &QPushButton::clicked,
[=](bool UNUSED(checked)) {
- showFileDialog(static_cast<FileValue*>(vp));
+ showFileDialog(v);
});
+ layout->addWidget(label, row, 0);
layout->addWidget(edit, row, 1);
- layout->addWidget(button, row, 2);
- } else {
+ layout->addWidget(v->button_, row, 2);
+ } else if (edit) {
+ layout->addWidget(label, row, 0);
layout->addWidget(edit, row, 1, 1, 2);
+ } else {
+ layout->addWidget(label, row, 0, 1, 3);
}
++row;
if (!value->description_.empty()) {
@@ -1074,6 +1162,12 @@ protected:
static_cast<FileValue*>(value.get())->value_ =
value->edit_->text().toStdString();
break;
+ case BOOLEAN: {
+ auto v = static_cast<BoolValue*>(value.get());
+ v->value_ = v->check_->isChecked();
+ v->check_ = nullptr;
+ break;
+ }
}
value->edit_ = nullptr;
}