33#include <wx/stattext.h>
34#include <wx/textctrl.h>
36#include "cat_settings.h"
37#include "observable_globvar.h"
38#include "ocpn_utils.h"
39#include "plugin_cache.h"
40#include "plugin_handler.h"
42extern wxString g_catalog_channel;
43extern wxString g_catalog_custom_url;
44extern wxString g_compatOS;
45extern wxString g_compatOsVersion;
51 SetValue(g_catalog_custom_url);
53 [&](wxCommandEvent&) { g_catalog_custom_url = GetValue(); });
61 : wxChoice(), m_selected(selected) {
62 Bind(wxEVT_CHOICE, &PlatformChoice::OnChoice,
this);
63 Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, getLabels());
69 wxStaticText* m_selected;
71 void OnChoice(wxCommandEvent&) {
73 if (GetSelection() == 0) {
77 if (GetSelection() == 1) {
79 g_compatOsVersion =
"";
81 auto newOS = CompatOs::getInstance();
82 m_selected->SetLabel(newOS->name() +
":" + newOS->version());
84 auto current = GetString(GetSelection());
85 auto os = ocpn::split(current,
" ")[0];
86 m_selected->SetLabel(os);
87 compat_os.
Set(ocpn::split(os.c_str(),
":")[0]);
88 g_compatOsVersion = ocpn::split(os.c_str(),
":")[1];
92 wxArrayString getLabels() {
93 auto plug_handler = PluginHandler::getInstance();
95 labels.Add(_(
"Select new flavour"));
96 labels.Add(_(
"Default setting"));
97 for (
const auto& c : plug_handler->getCountByTarget()) {
99 ss << c.first <<
" (" << c.second <<
")";
100 labels.Add(ss.str());
110 : wxChoice(), m_custom_ctrl(custom_ctrl) {
111 static const std::vector<std::string> labels(
112 {
"master",
"Beta",
"Alpha",
"custom"});
113 wxArrayString wxLabels;
114 for (
const auto& l : labels) wxLabels.Add(l);
115 Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLabels);
117 m_custom_ctrl->Enable(
false);
118 for (
auto l = labels.begin(); l != labels.end(); l++) {
119 if (g_catalog_channel == *l) {
120 SetSelection(l - labels.begin());
126 Bind(wxEVT_CHOICE, &CatalogChoice::OnChoice,
this);
130 wxTextCtrl* m_custom_ctrl;
132 void OnChoice(wxCommandEvent&) {
133 auto selected = GetString(GetSelection());
134 m_custom_ctrl->Enable(selected ==
"custom");
135 if (selected ==
"custom") {
136 m_custom_ctrl->Show();
137 GetParent()->Layout();
138 m_custom_ctrl->SetFocus();
139 g_catalog_custom_url = m_custom_ctrl->GetValue();
141 m_custom_ctrl->Hide();
144 catalog.
Set(selected);
152 CompatText(wxWindow* parent) : wxStaticText(parent, wxID_ANY,
"") {
153 auto compatOs = CompatOs::getInstance();
154 SetLabel(compatOs->name() +
":" + compatOs->version());
162 : wxStaticBoxSizer(wxHORIZONTAL, parent, _(
"Active catalog")) {
163 auto flags = wxSizerFlags().Border();
164 Add(
new wxStaticText(parent, wxID_ANY, _(
"Select plugin catalog")), flags);
167 Add(custom_ctrl, flags.Expand().Proportion(1));
176 : wxStaticBoxSizer(wxHORIZONTAL, parent, _(
"Compatibility")) {
177 auto flags = wxSizerFlags().Border();
178 Add(
new wxStaticText(parent, wxID_ANY, _(
"Active setting:")),
181 Add(status_text, flags.Center().Proportion(1));
190 : wxStaticBoxSizer(wxHORIZONTAL, parent, _(
"Cache")) {
191 using CmdEvt = wxCommandEvent;
193 auto flags = wxSizerFlags().Border();
194 m_label =
new wxStaticText(parent, wxID_ANY,
"");
196 Add(m_label, flags.Center().Proportion(1));
198 Add(1, 1, 1, wxEXPAND);
199 m_clear_button =
new wxButton(parent, wxID_ANY, _(
"Clear cache"));
200 Add(m_clear_button, flags);
201 m_clear_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED,
202 [=](CmdEvt& e) { on_clear_btn_clicked(); });
206 wxButton* m_clear_button;
207 wxStaticText* m_label;
209 void on_clear_btn_clicked() {
214 void update_label() {
216 snprintf(buf,
sizeof(buf), _(
"Size: %d MB in %d files"),
ocpn::cache_size(),
218 m_label->SetLabel(buf);
225 ButtonsSizer(wxWindow* parent) : wxStdDialogButtonSizer() {
226 auto button =
new wxButton(parent, wxID_OK,
"LongLabel", wxDefaultPosition,
227 wxSize(10 * parent->GetCharWidth(), -1));
228 button->SetLabel(_(
"Done"));
229 SetAffirmativeButton(button);
236 : wxDialog(parent, wxID_ANY, _(
"Plugin Catalog Settings"),
237 wxDefaultPosition, wxDefaultSize,
238 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {
239#ifdef __OCPN__ANDROID__
240 SetBackgroundColour(wxColour(0x7c, 0xb0, 0xe9));
242 auto vbox =
new wxBoxSizer(wxVERTICAL);
244 vbox->Add(
new CatalogSizer(
this), wxSizerFlags().Expand().DoubleBorder());
245#ifndef __OCPN__ANDROID__
246 vbox->Add(
new CompatSizer(
this), wxSizerFlags().Expand().DoubleBorder());
248 vbox->Add(
new CacheSizer(
this), wxSizerFlags().Expand().DoubleBorder());
249 vbox->Add(
new ButtonsSizer(
this), wxSizerFlags().Expand().DoubleBorder());
254 SetMinSize(GetSize());
Select master, beta, alpha, custom drop-down.
CatalogSettingsDialog(wxWindow *parent)
Top-level plugin settings dialog.
Catalog channel selection panel.
Plugin compatibility panel.
Current selected compatibility.
The custom URL text entry.
Wrapper for global variable, supports notification events when value changes.
void Set(const T &arg)
Set variable value and notify all listeners.
void cache_clear()
Remove all files in cache:
unsigned cache_file_count()
Return number of files in cache.
unsigned long cache_size()
Return total size of files in cache in kbytes.