diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-03-07 10:31:22 -0500 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2024-03-07 10:31:22 -0500 |
commit | d0029a806b8b6d244a6a3ec5b243303a8203cdd5 (patch) | |
tree | 978cfb8fc9ec880a99b0a4c0c1d8ffa2503db622 | |
parent | 10d6eff4dc1ab7a79920721c0fe2ed371d7dfaf3 (diff) | |
download | lingo-ap-tracker-d0029a806b8b6d244a6a3ec5b243303a8203cdd5.tar.gz lingo-ap-tracker-d0029a806b8b6d244a6a3ec5b243303a8203cdd5.tar.bz2 lingo-ap-tracker-d0029a806b8b6d244a6a3ec5b243303a8203cdd5.zip |
Added connection history
-rw-r--r-- | src/connection_dialog.cpp | 46 | ||||
-rw-r--r-- | src/connection_dialog.h | 4 | ||||
-rw-r--r-- | src/tracker_config.cpp | 32 | ||||
-rw-r--r-- | src/tracker_config.h | 17 | ||||
-rw-r--r-- | src/tracker_frame.cpp | 21 |
5 files changed, 100 insertions, 20 deletions
diff --git a/src/connection_dialog.cpp b/src/connection_dialog.cpp index 9dd9984..64fee98 100644 --- a/src/connection_dialog.cpp +++ b/src/connection_dialog.cpp | |||
@@ -4,12 +4,15 @@ | |||
4 | 4 | ||
5 | ConnectionDialog::ConnectionDialog() | 5 | ConnectionDialog::ConnectionDialog() |
6 | : wxDialog(nullptr, wxID_ANY, "Connect to Archipelago") { | 6 | : wxDialog(nullptr, wxID_ANY, "Connect to Archipelago") { |
7 | server_box_ = new wxTextCtrl(this, -1, GetTrackerConfig().ap_server, wxDefaultPosition, | 7 | server_box_ = |
8 | {300, -1}); | 8 | new wxTextCtrl(this, -1, GetTrackerConfig().connection_details.ap_server, |
9 | player_box_ = new wxTextCtrl(this, -1, GetTrackerConfig().ap_player, wxDefaultPosition, | 9 | wxDefaultPosition, {300, -1}); |
10 | {300, -1}); | 10 | player_box_ = |
11 | password_box_ = new wxTextCtrl(this, -1, GetTrackerConfig().ap_password, | 11 | new wxTextCtrl(this, -1, GetTrackerConfig().connection_details.ap_player, |
12 | wxDefaultPosition, {300, -1}); | 12 | wxDefaultPosition, {300, -1}); |
13 | password_box_ = new wxTextCtrl( | ||
14 | this, -1, GetTrackerConfig().connection_details.ap_password, | ||
15 | wxDefaultPosition, {300, -1}); | ||
13 | 16 | ||
14 | wxFlexGridSizer* form_sizer = new wxFlexGridSizer(2, 10, 10); | 17 | wxFlexGridSizer* form_sizer = new wxFlexGridSizer(2, 10, 10); |
15 | 18 | ||
@@ -26,15 +29,42 @@ ConnectionDialog::ConnectionDialog() | |||
26 | wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT)); | 29 | wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT)); |
27 | form_sizer->Add(password_box_, wxSizerFlags().Expand()); | 30 | form_sizer->Add(password_box_, wxSizerFlags().Expand()); |
28 | 31 | ||
32 | history_list_ = new wxListBox(this, -1); | ||
33 | for (const ConnectionDetails& details : GetTrackerConfig().connection_history) { | ||
34 | wxString display_text; | ||
35 | display_text << details.ap_player; | ||
36 | display_text << " ("; | ||
37 | display_text << details.ap_server; | ||
38 | display_text << ")"; | ||
39 | |||
40 | history_list_->Append(display_text); | ||
41 | } | ||
42 | |||
43 | history_list_->Bind(wxEVT_LISTBOX, &ConnectionDialog::OnOldConnectionChosen, this); | ||
44 | |||
45 | wxBoxSizer* mid_sizer = new wxBoxSizer(wxHORIZONTAL); | ||
46 | mid_sizer->Add(form_sizer, wxSizerFlags().Proportion(3).Expand()); | ||
47 | mid_sizer->AddSpacer(10); | ||
48 | mid_sizer->Add(history_list_, wxSizerFlags().Proportion(2).Expand()); | ||
49 | |||
29 | wxBoxSizer* top_sizer = new wxBoxSizer(wxVERTICAL); | 50 | wxBoxSizer* top_sizer = new wxBoxSizer(wxVERTICAL); |
30 | top_sizer->Add(new wxStaticText( | 51 | top_sizer->Add(new wxStaticText( |
31 | this, -1, "Enter the details to connect to Archipelago."), | 52 | this, -1, "Enter the details to connect to Archipelago."), |
32 | wxSizerFlags().Align(wxALIGN_LEFT).DoubleBorder()); | 53 | wxSizerFlags().Align(wxALIGN_LEFT).DoubleBorder()); |
33 | top_sizer->Add(form_sizer, wxSizerFlags().DoubleBorder().Expand()); | 54 | top_sizer->Add(mid_sizer, wxSizerFlags().DoubleBorder().Expand()); |
34 | top_sizer->Add(CreateButtonSizer(wxOK | wxCANCEL), wxSizerFlags().Center()); | 55 | top_sizer->Add(CreateButtonSizer(wxOK | wxCANCEL), wxSizerFlags().Border().Center()); |
35 | 56 | ||
36 | SetSizerAndFit(top_sizer); | 57 | SetSizerAndFit(top_sizer); |
37 | 58 | ||
38 | Center(); | 59 | Center(); |
39 | server_box_->SetFocus(); | 60 | server_box_->SetFocus(); |
40 | } | 61 | } |
62 | |||
63 | void ConnectionDialog::OnOldConnectionChosen(wxCommandEvent& e) { | ||
64 | if (e.IsSelection()) { | ||
65 | const ConnectionDetails& details = GetTrackerConfig().connection_history.at(e.GetSelection()); | ||
66 | server_box_->SetValue(details.ap_server); | ||
67 | player_box_->SetValue(details.ap_player); | ||
68 | password_box_->SetValue(details.ap_password); | ||
69 | } | ||
70 | } | ||
diff --git a/src/connection_dialog.h b/src/connection_dialog.h index 5d2703d..9fe62fd 100644 --- a/src/connection_dialog.h +++ b/src/connection_dialog.h | |||
@@ -8,6 +8,7 @@ | |||
8 | #endif | 8 | #endif |
9 | 9 | ||
10 | #include <string> | 10 | #include <string> |
11 | #include <wx/listbox.h> | ||
11 | 12 | ||
12 | class ConnectionDialog : public wxDialog { | 13 | class ConnectionDialog : public wxDialog { |
13 | public: | 14 | public: |
@@ -22,9 +23,12 @@ class ConnectionDialog : public wxDialog { | |||
22 | } | 23 | } |
23 | 24 | ||
24 | private: | 25 | private: |
26 | void OnOldConnectionChosen(wxCommandEvent& e); | ||
27 | |||
25 | wxTextCtrl* server_box_; | 28 | wxTextCtrl* server_box_; |
26 | wxTextCtrl* player_box_; | 29 | wxTextCtrl* player_box_; |
27 | wxTextCtrl* password_box_; | 30 | wxTextCtrl* password_box_; |
31 | wxListBox* history_list_; | ||
28 | }; | 32 | }; |
29 | 33 | ||
30 | #endif /* end of include guard: CONNECTION_DIALOG_H_E526D0E7 */ | 34 | #endif /* end of include guard: CONNECTION_DIALOG_H_E526D0E7 */ |
diff --git a/src/tracker_config.cpp b/src/tracker_config.cpp index b0f4ac4..85164d5 100644 --- a/src/tracker_config.cpp +++ b/src/tracker_config.cpp | |||
@@ -10,13 +10,23 @@ void TrackerConfig::Load() { | |||
10 | try { | 10 | try { |
11 | YAML::Node file = YAML::LoadFile(filename_); | 11 | YAML::Node file = YAML::LoadFile(filename_); |
12 | 12 | ||
13 | ap_server = file["ap_server"].as<std::string>(); | 13 | connection_details.ap_server = file["ap_server"].as<std::string>(); |
14 | ap_player = file["ap_player"].as<std::string>(); | 14 | connection_details.ap_player = file["ap_player"].as<std::string>(); |
15 | ap_password = file["ap_password"].as<std::string>(); | 15 | connection_details.ap_password = file["ap_password"].as<std::string>(); |
16 | asked_to_check_for_updates = file["asked_to_check_for_updates"].as<bool>(); | 16 | asked_to_check_for_updates = file["asked_to_check_for_updates"].as<bool>(); |
17 | should_check_for_updates = file["should_check_for_updates"].as<bool>(); | 17 | should_check_for_updates = file["should_check_for_updates"].as<bool>(); |
18 | hybrid_areas = file["hybrid_areas"].as<bool>(); | 18 | hybrid_areas = file["hybrid_areas"].as<bool>(); |
19 | show_hunt_panels = file["show_hunt_panels"].as<bool>(); | 19 | show_hunt_panels = file["show_hunt_panels"].as<bool>(); |
20 | |||
21 | if (file["connection_history"]) { | ||
22 | for (const auto& connection : file["connection_history"]) { | ||
23 | connection_history.push_back(ConnectionDetails{ | ||
24 | .ap_server = connection["ap_server"].as<std::string>(), | ||
25 | .ap_player = connection["ap_player"].as<std::string>(), | ||
26 | .ap_password = connection["ap_password"].as<std::string>() | ||
27 | }); | ||
28 | } | ||
29 | } | ||
20 | } catch (const std::exception&) { | 30 | } catch (const std::exception&) { |
21 | // It's fine if the file can't be loaded. | 31 | // It's fine if the file can't be loaded. |
22 | } | 32 | } |
@@ -24,13 +34,23 @@ void TrackerConfig::Load() { | |||
24 | 34 | ||
25 | void TrackerConfig::Save() { | 35 | void TrackerConfig::Save() { |
26 | YAML::Node output; | 36 | YAML::Node output; |
27 | output["ap_server"] = ap_server; | 37 | output["ap_server"] = connection_details.ap_server; |
28 | output["ap_player"] = ap_player; | 38 | output["ap_player"] = connection_details.ap_player; |
29 | output["ap_password"] = ap_password; | 39 | output["ap_password"] = connection_details.ap_password; |
30 | output["asked_to_check_for_updates"] = asked_to_check_for_updates; | 40 | output["asked_to_check_for_updates"] = asked_to_check_for_updates; |
31 | output["should_check_for_updates"] = should_check_for_updates; | 41 | output["should_check_for_updates"] = should_check_for_updates; |
32 | output["hybrid_areas"] = hybrid_areas; | 42 | output["hybrid_areas"] = hybrid_areas; |
33 | output["show_hunt_panels"] = show_hunt_panels; | 43 | output["show_hunt_panels"] = show_hunt_panels; |
44 | |||
45 | output.remove("connection_history"); | ||
46 | for (const ConnectionDetails& details : connection_history) { | ||
47 | YAML::Node connection; | ||
48 | connection["ap_server"] = details.ap_server; | ||
49 | connection["ap_player"] = details.ap_player; | ||
50 | connection["ap_password"] = details.ap_password; | ||
51 | |||
52 | output["connection_history"].push_back(connection); | ||
53 | } | ||
34 | 54 | ||
35 | std::ofstream filewriter(filename_); | 55 | std::ofstream filewriter(filename_); |
36 | filewriter << output; | 56 | filewriter << output; |
diff --git a/src/tracker_config.h b/src/tracker_config.h index b95194e..a1a6c1d 100644 --- a/src/tracker_config.h +++ b/src/tracker_config.h | |||
@@ -1,7 +1,19 @@ | |||
1 | #ifndef TRACKER_CONFIG_H_36CDD648 | 1 | #ifndef TRACKER_CONFIG_H_36CDD648 |
2 | #define TRACKER_CONFIG_H_36CDD648 | 2 | #define TRACKER_CONFIG_H_36CDD648 |
3 | 3 | ||
4 | #include <deque> | ||
4 | #include <string> | 5 | #include <string> |
6 | #include <utility> | ||
7 | |||
8 | struct ConnectionDetails { | ||
9 | std::string ap_server; | ||
10 | std::string ap_player; | ||
11 | std::string ap_password; | ||
12 | |||
13 | bool operator!=(const ConnectionDetails& rhs) const { | ||
14 | return std::tie(ap_server, ap_player, ap_password) != std::tie(rhs.ap_server, rhs.ap_player, rhs.ap_password); | ||
15 | } | ||
16 | }; | ||
5 | 17 | ||
6 | class TrackerConfig { | 18 | class TrackerConfig { |
7 | public: | 19 | public: |
@@ -11,13 +23,12 @@ class TrackerConfig { | |||
11 | 23 | ||
12 | void Save(); | 24 | void Save(); |
13 | 25 | ||
14 | std::string ap_server; | 26 | ConnectionDetails connection_details; |
15 | std::string ap_player; | ||
16 | std::string ap_password; | ||
17 | bool asked_to_check_for_updates = false; | 27 | bool asked_to_check_for_updates = false; |
18 | bool should_check_for_updates = false; | 28 | bool should_check_for_updates = false; |
19 | bool hybrid_areas = false; | 29 | bool hybrid_areas = false; |
20 | bool show_hunt_panels = false; | 30 | bool show_hunt_panels = false; |
31 | std::deque<ConnectionDetails> connection_history; | ||
21 | 32 | ||
22 | private: | 33 | private: |
23 | std::string filename_; | 34 | std::string filename_; |
diff --git a/src/tracker_frame.cpp b/src/tracker_frame.cpp index a8c1063..d64e0d3 100644 --- a/src/tracker_frame.cpp +++ b/src/tracker_frame.cpp | |||
@@ -115,9 +115,24 @@ void TrackerFrame::OnConnect(wxCommandEvent &event) { | |||
115 | ConnectionDialog dlg; | 115 | ConnectionDialog dlg; |
116 | 116 | ||
117 | if (dlg.ShowModal() == wxID_OK) { | 117 | if (dlg.ShowModal() == wxID_OK) { |
118 | GetTrackerConfig().ap_server = dlg.GetServerValue(); | 118 | GetTrackerConfig().connection_details.ap_server = dlg.GetServerValue(); |
119 | GetTrackerConfig().ap_player = dlg.GetPlayerValue(); | 119 | GetTrackerConfig().connection_details.ap_player = dlg.GetPlayerValue(); |
120 | GetTrackerConfig().ap_password = dlg.GetPasswordValue(); | 120 | GetTrackerConfig().connection_details.ap_password = dlg.GetPasswordValue(); |
121 | |||
122 | std::deque<ConnectionDetails> new_history; | ||
123 | new_history.push_back(GetTrackerConfig().connection_details); | ||
124 | |||
125 | for (const ConnectionDetails& details : GetTrackerConfig().connection_history) { | ||
126 | if (details != GetTrackerConfig().connection_details) { | ||
127 | new_history.push_back(details); | ||
128 | } | ||
129 | } | ||
130 | |||
131 | while (new_history.size() > 5) { | ||
132 | new_history.pop_back(); | ||
133 | } | ||
134 | |||
135 | GetTrackerConfig().connection_history = std::move(new_history); | ||
121 | GetTrackerConfig().Save(); | 136 | GetTrackerConfig().Save(); |
122 | 137 | ||
123 | AP_Connect(dlg.GetServerValue(), dlg.GetPlayerValue(), | 138 | AP_Connect(dlg.GetServerValue(), dlg.GetPlayerValue(), |