Skip to content

Commit

Permalink
Merge pull request #936 from Chilledheart/ui_add_enable_post_quatumn_…
Browse files Browse the repository at this point in the history
…kyber_button

ui: add enable_post_quatumn_kyber button
  • Loading branch information
Chilledheart authored May 5, 2024
2 parents 14825e2 + 007c01a commit c482ab1
Show file tree
Hide file tree
Showing 17 changed files with 362 additions and 157 deletions.
29 changes: 23 additions & 6 deletions src/gtk/option_dialog.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2021-2022 Chilledheart */
/* Copyright (c) 2021-2024 Chilledheart */

#include "gtk/option_dialog.hpp"

Expand Down Expand Up @@ -32,20 +32,25 @@ OptionDialog::OptionDialog(const std::string& title, GtkWindow* parent, bool mod
auto tcp_keep_alive_idle_timeout_label = gtk_label_new(_("TCP keep alive after idle"));
auto tcp_keep_alive_interval_label = gtk_label_new(_("TCP keep alive interval"));

auto enable_post_quantum_kyber_label = gtk_label_new(_("Kyber post-quantum key agreement for TLS"));

gtk_grid_attach(grid, GTK_WIDGET(tcp_keep_alive_label), 0, 0, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(tcp_keep_alive_cnt_label), 0, 1, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(tcp_keep_alive_idle_timeout_label), 0, 2, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(tcp_keep_alive_interval_label), 0, 3, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(enable_post_quantum_kyber_label), 0, 4, 1, 1);

tcp_keep_alive_ = GTK_CHECK_BUTTON(gtk_check_button_new());
tcp_keep_alive_cnt_ = GTK_ENTRY(gtk_entry_new());
tcp_keep_alive_idle_timeout_ = GTK_ENTRY(gtk_entry_new());
tcp_keep_alive_interval_ = GTK_ENTRY(gtk_entry_new());
enable_post_quantum_kyber_ = GTK_CHECK_BUTTON(gtk_check_button_new());

gtk_grid_attach(grid, GTK_WIDGET(tcp_keep_alive_), 1, 0, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(tcp_keep_alive_cnt_), 1, 1, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(tcp_keep_alive_idle_timeout_), 1, 2, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(tcp_keep_alive_interval_), 1, 3, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(enable_post_quantum_kyber_), 1, 4, 1, 1);

okay_button_ = GTK_BUTTON(gtk_button_new());
gtk_button_set_label(okay_button_, _("Okay"));
Expand All @@ -61,8 +66,8 @@ OptionDialog::OptionDialog(const std::string& title, GtkWindow* parent, bool mod

g_signal_connect(G_OBJECT(cancel_button_), "clicked", G_CALLBACK(cancel_callback), nullptr);

gtk_grid_attach(grid, GTK_WIDGET(okay_button_), 0, 4, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(cancel_button_), 1, 4, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(okay_button_), 0, 5, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(cancel_button_), 1, 5, 1, 1);

gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(impl_)), GTK_WIDGET(grid));

Expand All @@ -76,7 +81,10 @@ OptionDialog::~OptionDialog() {
}

void OptionDialog::OnOkayButtonClicked() {
OnSave();
if (!OnSave()) {
return;
}
config::SaveConfig();
gtk_dialog_response(impl_, GTK_RESPONSE_ACCEPT);
}

Expand All @@ -96,22 +104,31 @@ void OptionDialog::LoadChanges() {
gtk_entry_set_text(tcp_keep_alive_idle_timeout_, tcp_keep_alive_idle_timeout_str.c_str());
auto tcp_keep_alive_interval_str = std::to_string(absl::GetFlag(FLAGS_tcp_keep_alive_interval));
gtk_entry_set_text(tcp_keep_alive_interval_, tcp_keep_alive_interval_str.c_str());

gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_post_quantum_kyber_),
absl::GetFlag(FLAGS_enable_post_quantum_kyber));
}

void OptionDialog::OnSave() {
bool OptionDialog::OnSave() {
auto tcp_keep_alive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tcp_keep_alive_));
auto tcp_keep_alive_cnt = StringToIntegerU(gtk_entry_get_text(tcp_keep_alive_cnt_));
auto tcp_keep_alive_idle_timeout = StringToIntegerU(gtk_entry_get_text(tcp_keep_alive_idle_timeout_));
auto tcp_keep_alive_interval = StringToIntegerU(gtk_entry_get_text(tcp_keep_alive_interval_));

auto enable_post_quantum_kyber = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(enable_post_quantum_kyber_));

if (!tcp_keep_alive_cnt.has_value() || !tcp_keep_alive_idle_timeout.has_value() ||
!tcp_keep_alive_interval.has_value()) {
LOG(WARNING) << "invalid options";
return;
return false;
}

absl::SetFlag(&FLAGS_tcp_keep_alive, tcp_keep_alive);
absl::SetFlag(&FLAGS_tcp_keep_alive_cnt, tcp_keep_alive_cnt.value());
absl::SetFlag(&FLAGS_tcp_keep_alive_idle_timeout, tcp_keep_alive_idle_timeout.value());
absl::SetFlag(&FLAGS_tcp_keep_alive_interval, tcp_keep_alive_interval.value());

absl::SetFlag(&FLAGS_enable_post_quantum_kyber, enable_post_quantum_kyber);

return true;
}
5 changes: 3 additions & 2 deletions src/gtk/option_dialog.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2021-2022 Chilledheart */
/* Copyright (c) 2021-2024 Chilledheart */
#ifndef OPTION_DIALOG
#define OPTION_DIALOG

Expand All @@ -19,12 +19,13 @@ class OptionDialog {

private:
void LoadChanges();
void OnSave();
bool OnSave();

GtkCheckButton* tcp_keep_alive_;
GtkEntry* tcp_keep_alive_cnt_;
GtkEntry* tcp_keep_alive_idle_timeout_;
GtkEntry* tcp_keep_alive_interval_;
GtkCheckButton* enable_post_quantum_kyber_;

GtkButton* okay_button_;
GtkButton* cancel_button_;
Expand Down
4 changes: 4 additions & 0 deletions src/gtk/yass_en.po
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ msgstr "TCP keep alive after idle"
msgid "TCP keep alive interval"
msgstr "TCP keep alive interval"

#: option_dialog.ui:50
msgid "Kyber post-quantum key agreement for TLS"
msgstr "Kyber post-quantum key agreement for TLS"

#: option_dialog.cpp:54
msgid "Okay"
msgstr "Okay"
Expand Down
4 changes: 4 additions & 0 deletions src/gtk/yass_zh_CN.po
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ msgstr "TCP 在闲置以后的保活次数"
msgid "TCP keep alive interval"
msgstr "TCP 保活间隔"

#: option_dialog.ui:50
msgid "Kyber post-quantum key agreement for TLS"
msgstr "TLS的Kyber后量子密钥协商"

#: option_dialog.cpp:54
msgid "Okay"
msgstr "确认"
Expand Down
21 changes: 17 additions & 4 deletions src/gtk4/option_dialog.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2021-2023 Chilledheart */
/* Copyright (c) 2021-2024 Chilledheart */

#include "gtk4/option_dialog.hpp"

Expand All @@ -19,6 +19,7 @@ struct _OptionGtkDialog {
GtkWidget* tcp_keep_alive_cnt;
GtkWidget* tcp_keep_alive_idle_timeout;
GtkWidget* tcp_keep_alive_interval;
GtkWidget* enable_post_quantum_kyber;

GtkWidget* okay_button;
GtkWidget* cancel_button;
Expand All @@ -40,6 +41,7 @@ static void option_dialog_class_init(OptionGtkDialogClass* cls) {
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(cls), OptionGtkDialog, tcp_keep_alive_cnt);
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(cls), OptionGtkDialog, tcp_keep_alive_idle_timeout);
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(cls), OptionGtkDialog, tcp_keep_alive_interval);
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(cls), OptionGtkDialog, enable_post_quantum_kyber);

gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(cls), OptionGtkDialog, okay_button);
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(cls), OptionGtkDialog, cancel_button);
Expand Down Expand Up @@ -96,7 +98,10 @@ OptionDialog::~OptionDialog() {
}

void OptionDialog::OnOkayButtonClicked() {
OnSave();
if (!OnSave()) {
return;
}
config::SaveConfig();
gtk_dialog_response(GTK_DIALOG(impl_), GTK_RESPONSE_ACCEPT);
}

Expand All @@ -116,23 +121,31 @@ void OptionDialog::LoadChanges() {
gtk_editable_set_text(GTK_EDITABLE(impl_->tcp_keep_alive_cnt), tcp_keep_alive_cnt_str.c_str());
gtk_editable_set_text(GTK_EDITABLE(impl_->tcp_keep_alive_idle_timeout), tcp_keep_alive_idle_timeout_str.c_str());
gtk_editable_set_text(GTK_EDITABLE(impl_->tcp_keep_alive_interval), tcp_keep_alive_interval_str.c_str());

gtk_check_button_set_active(GTK_CHECK_BUTTON(impl_->enable_post_quantum_kyber),
absl::GetFlag(FLAGS_enable_post_quantum_kyber));
}

void OptionDialog::OnSave() {
bool OptionDialog::OnSave() {
auto tcp_keep_alive = gtk_check_button_get_active(GTK_CHECK_BUTTON(impl_->tcp_keep_alive_check));
auto tcp_keep_alive_cnt = StringToIntegerU(gtk_editable_get_text(GTK_EDITABLE(impl_->tcp_keep_alive_cnt)));
auto tcp_keep_alive_idle_timeout =
StringToIntegerU(gtk_editable_get_text(GTK_EDITABLE(impl_->tcp_keep_alive_idle_timeout)));
auto tcp_keep_alive_interval = StringToIntegerU(gtk_editable_get_text(GTK_EDITABLE(impl_->tcp_keep_alive_interval)));

auto enable_post_quantum_kyber = gtk_check_button_get_active(GTK_CHECK_BUTTON(impl_->enable_post_quantum_kyber));

if (!tcp_keep_alive_cnt.has_value() || !tcp_keep_alive_idle_timeout.has_value() ||
!tcp_keep_alive_interval.has_value()) {
LOG(WARNING) << "invalid options";
return;
return false;
}

absl::SetFlag(&FLAGS_tcp_keep_alive, tcp_keep_alive);
absl::SetFlag(&FLAGS_tcp_keep_alive_cnt, tcp_keep_alive_cnt.value());
absl::SetFlag(&FLAGS_tcp_keep_alive_idle_timeout, tcp_keep_alive_idle_timeout.value());
absl::SetFlag(&FLAGS_tcp_keep_alive_interval, tcp_keep_alive_interval.value());

absl::SetFlag(&FLAGS_enable_post_quantum_kyber, enable_post_quantum_kyber);
return true;
}
4 changes: 2 additions & 2 deletions src/gtk4/option_dialog.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2021-2023 Chilledheart */
/* Copyright (c) 2021-2024 Chilledheart */
#ifndef OPTION_DIALOG
#define OPTION_DIALOG

Expand All @@ -26,7 +26,7 @@ class OptionDialog {

private:
void LoadChanges();
void OnSave();
bool OnSave();

private:
OptionGtkDialog* impl_;
Expand Down
22 changes: 20 additions & 2 deletions src/gtk4/option_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Kyber post-quantum key agreement for TLS:</property>
<property name="xalign">1</property>
<layout>
<property name="column">0</property>
<property name="row">4</property>
</layout>
</object>
</child>
<child>
<object class="GtkCheckButton" id="tcp_keep_alive_check">
<layout>
Expand Down Expand Up @@ -87,12 +97,20 @@
</layout>
</object>
</child>
<child>
<object class="GtkCheckButton" id="enable_post_quantum_kyber">
<layout>
<property name="column">1</property>
<property name="row">4</property>
</layout>
</object>
</child>
<child>
<object class="GtkButton" id="okay_button">
<property name="label" translatable="yes">Okay</property>
<layout>
<property name="column">0</property>
<property name="row">4</property>
<property name="row">5</property>
</layout>
</object>
</child>
Expand All @@ -101,7 +119,7 @@
<property name="label" translatable="yes">Cancel</property>
<layout>
<property name="column">1</property>
<property name="row">4</property>
<property name="row">5</property>
</layout>
</object>
</child>
Expand Down
4 changes: 4 additions & 0 deletions src/gtk4/yass_en.po
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ msgstr "TCP keep alive after idle:"
msgid "TCP keep alive interval:"
msgstr "TCP keep alive interval:"

#: option_dialog.ui:50
msgid "Kyber post-quantum key agreement for TLS:"
msgstr "Kyber post-quantum key agreement for TLS:"

#: option_dialog.ui:92
msgid "Okay"
msgstr "Okay"
Expand Down
4 changes: 4 additions & 0 deletions src/gtk4/yass_zh_CN.po
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ msgstr "TCP 在闲置以后的保活次数:"
msgid "TCP keep alive interval:"
msgstr "TCP 保活间隔:"

#: option_dialog.ui:50
msgid "Kyber post-quantum key agreement for TLS:"
msgstr "TLS的Kyber后量子密钥协商:"

#: option_dialog.ui:92
msgid "Okay"
msgstr "确认"
Expand Down
Loading

0 comments on commit c482ab1

Please sign in to comment.