diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/gui_form.hh | 4 | ||||
| -rw-r--r-- | src/gui_gtk.cc | 20 | ||||
| -rw-r--r-- | src/gui_qt.cc | 16 | ||||
| -rw-r--r-- | src/monitor-gui.cc | 2 |
4 files changed, 26 insertions, 16 deletions
diff --git a/src/gui_form.hh b/src/gui_form.hh index d154518..972c781 100644 --- a/src/gui_form.hh +++ b/src/gui_form.hh @@ -32,9 +32,11 @@ public: std::string name; std::vector<std::string> masks; }; + static const uint8_t FILE_OPEN; + static const uint8_t FILE_SAVE; virtual void add_file(std::string const& id, std::string const& label, std::string const& value, - std::string const& description, bool must_exist, + std::string const& description, uint8_t flags, std::vector<Filter> const& filter) = 0; virtual void add_listener(Listener* listener) = 0; diff --git a/src/gui_gtk.cc b/src/gui_gtk.cc index a326cea..7510f09 100644 --- a/src/gui_gtk.cc +++ b/src/gui_gtk.cc @@ -925,10 +925,10 @@ public: void add_file(std::string const& id, std::string const& label, std::string const& value, std::string const& description, - bool must_exist, + uint8_t flags, std::vector<Filter> const& filter) override { values_.emplace_back(new FileValue(id, label, description, value, - must_exist, filter)); + flags, filter)); } std::string get_string(std::string const& id) const override { @@ -964,7 +964,7 @@ public: for (auto const& value : values_) { if (value->id_ == id && value->type_ == FILE) { auto v = static_cast<FileValue*>(value.get()); - if (v->must_exist_ && v->chooser_) { + if ((v->flags_ & FILE_SAVE) == 0 && v->chooser_) { std::string ret; auto file = gtk_file_chooser_get_filename(v->chooser_); if (file) { @@ -1039,7 +1039,7 @@ public: } case FILE: { auto v = static_cast<FileValue*>(value.get()); - if (v->must_exist_) { + if ((v->flags_ & FILE_SAVE) == 0) { gtk_widget_destroy(value->entry_); auto button = gtk_file_chooser_button_new( v->label_.c_str(), GTK_FILE_CHOOSER_ACTION_OPEN); @@ -1116,7 +1116,7 @@ public: break; case FILE: { auto v = static_cast<FileValue*>(value.get()); - if (v->must_exist_) { + if ((v->flags_ & FILE_SAVE) == 0) { auto file = gtk_file_chooser_get_filename(v->chooser_); if (file) { v->value_ = file; @@ -1181,15 +1181,15 @@ protected: struct FileValue : public Value { std::string value_; - bool must_exist_; + uint8_t flags_; std::vector<Filter> filter_; GtkFileChooser* chooser_; FileValue(std::string const& id, std::string const& label, std::string const& description, std::string const& value, - bool must_exist, std::vector<Filter> const& filter) + uint8_t flags, std::vector<Filter> const& filter) : Value(FILE, id, label, description), value_(value), - must_exist_(must_exist), filter_(filter) { + flags_(flags), filter_(filter) { } }; @@ -1955,6 +1955,10 @@ GuiForm* GuiForm::create(std::string const& title, } // static +uint8_t const GuiForm::FILE_OPEN = 0; +uint8_t const GuiForm::FILE_SAVE = 1; + +// static GuiFormApply* GuiFormApply::create(std::string const& title, std::string const& text, std::string const& apply_button, diff --git a/src/gui_qt.cc b/src/gui_qt.cc index ec67527..3e7c696 100644 --- a/src/gui_qt.cc +++ b/src/gui_qt.cc @@ -857,10 +857,10 @@ public: void add_file(std::string const& id, std::string const& label, std::string const& value, std::string const& description, - bool must_exist, + uint8_t flags, std::vector<Filter> const& filter) override { values_.emplace_back(new FileValue(id, label, description, value, - must_exist, filter)); + flags, filter)); } std::string get_string(std::string const& id) const override { @@ -965,15 +965,15 @@ protected: struct FileValue : public Value { std::string value_; - bool must_exist_; + uint8_t flags_; std::vector<Filter> filter_; FileValue(std::string const& id, std::string const& label, std::string const& description, std::string const& value, - bool must_exist, std::vector<Filter> const& filter) + uint8_t flags, std::vector<Filter> const& filter) : Value(FILE, id, label, description), value_(value), - must_exist_(must_exist), filter_(filter) { + flags_(flags), filter_(filter) { } }; @@ -1112,7 +1112,7 @@ protected: } filter.append(')'); } - if (value->must_exist_) { + if (!(value->flags_ & FILE_SAVE)) { auto file = QFileDialog::getOpenFileName( dialog_, QString::fromStdString(value->label_), value->edit_->text(), filter); @@ -1591,6 +1591,10 @@ GuiForm* GuiForm::create(std::string const& title, } // static +uint8_t const GuiForm::FILE_OPEN = 0; +uint8_t const GuiForm::FILE_SAVE = 1; + +// static GuiFormApply* GuiFormApply::create(std::string const& title, std::string const& text, std::string const& apply_button, diff --git a/src/monitor-gui.cc b/src/monitor-gui.cc index 4f4f2fb..7b4f5f2 100644 --- a/src/monitor-gui.cc +++ b/src/monitor-gui.cc @@ -702,7 +702,7 @@ public: filter.back().masks.emplace_back("*.pem"); dlg->add_file("output", "File", "", "File to save certificate and key pair to.", - false, filter); + GuiForm::FILE_SAVE, filter); dlg->add_listener(lst.get()); dlg->show(main_.get()); } else { |
