32#include <wx/stattext.h>
33#include <wx/textctrl.h>
39#include "model/plugin_cache.h"
46 SetValue(g_catalog_custom_url);
48 [&](wxCommandEvent&) { g_catalog_custom_url = GetValue(); });
56 : wxChoice(), m_selected(selected) {
57 Bind(wxEVT_CHOICE, &PlatformChoice::OnChoice,
this);
58 Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, getLabels());
64 wxStaticText* m_selected;
66 void OnChoice(wxCommandEvent&) {
68 if (GetSelection() == 0) {
72 if (GetSelection() == 1) {
74 g_compatOsVersion =
"";
76 auto newOS = CompatOs::GetInstance();
77 m_selected->SetLabel(newOS->name() +
":" + newOS->version());
79 auto current = GetString(GetSelection());
81 m_selected->SetLabel(os);
83 g_compatOsVersion =
ocpn::split(os.c_str(),
":")[1];
87 wxArrayString getLabels() {
90 labels.Add(_(
"Select new flavour"));
91 labels.Add(_(
"Default setting"));
92 for (
const auto& c : plug_handler->GetCountByTarget()) {
94 ss << c.first <<
" (" << c.second <<
")";
105 : wxChoice(), m_custom_ctrl(custom_ctrl) {
106 static const std::vector<std::string> labels(
107 {
"master",
"Beta",
"Alpha",
"custom"});
108 wxArrayString wxLabels;
109 for (
const auto& l : labels) wxLabels.Add(l);
110 Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLabels);
113 SetMinSize(wxSize(12 * GetCharWidth(), -1));
116 m_custom_ctrl->Enable(
false);
117 for (
auto l = labels.begin(); l != labels.end(); l++) {
118 if (g_catalog_channel == *l) {
119 SetSelection(l - labels.begin());
125 Bind(wxEVT_CHOICE, &CatalogChoice::OnChoice,
this);
129 wxTextCtrl* m_custom_ctrl;
131 void OnChoice(wxCommandEvent&) {
132 auto selected = GetString(GetSelection());
133 m_custom_ctrl->Enable(selected ==
"custom");
134 if (selected ==
"custom") {
135 m_custom_ctrl->Show();
136 GetParent()->Layout();
137 m_custom_ctrl->SetFocus();
138 g_catalog_custom_url = m_custom_ctrl->GetValue();
140 m_custom_ctrl->Hide();
143 catalog.Set(selected);
151 CompatText(wxWindow* parent) : wxStaticText(parent, wxID_ANY,
"") {
152 auto compatOs = CompatOs::GetInstance();
153 SetLabel(compatOs->name() +
":" + compatOs->version());
161 : wxStaticBoxSizer(wxHORIZONTAL, parent, _(
"Active catalog")) {
162 auto flags = wxSizerFlags().Border(wxALL, parent->GetCharWidth());
163 Add(
new wxStaticText(parent, wxID_ANY, _(
"Select plugin catalog")), flags);
166 Add(custom_ctrl, flags.Expand().Proportion(1));
175 : wxStaticBoxSizer(wxHORIZONTAL, parent, _(
"Compatibility")) {
176 auto flags = wxSizerFlags().Border();
177 Add(
new wxStaticText(parent, wxID_ANY, _(
"Active setting:")),
180 Add(status_text, flags.Center().Proportion(1));
189 : wxStaticBoxSizer(wxHORIZONTAL, parent, _(
"Cache")) {
190 using CmdEvt = wxCommandEvent;
192 auto flags = wxSizerFlags().Border();
193 m_label =
new wxStaticText(parent, wxID_ANY,
"");
195 Add(m_label, flags.Center().Proportion(1));
197 Add(1, 1, 1, wxEXPAND);
198 m_clear_button =
new wxButton(parent, wxID_ANY, _(
"Clear cache"));
199 Add(m_clear_button, flags);
200 m_clear_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED,
201 [=](CmdEvt& e) { on_clear_btn_clicked(); });
205 wxButton* m_clear_button;
206 wxStaticText* m_label;
208 void on_clear_btn_clicked() {
213 void update_label() {
215 snprintf(buf,
sizeof(buf), _(
"Size: %d MB in %d files"),
ocpn::cache_size(),
217 m_label->SetLabel(buf);
224 ButtonsSizer(wxWindow* parent) : wxStdDialogButtonSizer() {
225 auto button =
new wxButton(parent, wxID_OK,
"LongLabel", wxDefaultPosition,
226 wxSize(10 * parent->GetCharWidth(), -1));
227 button->SetLabel(_(
"Done"));
228 SetAffirmativeButton(button);
235 : wxDialog(parent, wxID_ANY, _(
"Plugin Catalog Settings"),
236 wxDefaultPosition, wxDefaultSize,
237 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {
239 SetBackgroundColour(wxColour(0x7c, 0xb0, 0xe9));
241 auto vbox =
new wxBoxSizer(wxVERTICAL);
243 vbox->Add(
new CatalogSizer(
this), wxSizerFlags().Expand().DoubleBorder());
245 vbox->Add(
new CompatSizer(
this), wxSizerFlags().Expand().DoubleBorder());
247 vbox->Add(
new CacheSizer(
this), wxSizerFlags().Expand().DoubleBorder());
248 vbox->Add(
new ButtonsSizer(
this), wxSizerFlags().Expand().DoubleBorder());
253 SetMinSize(GetSize());
Plugin catalog settings dialog.
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.
static PluginHandler * GetInstance()
Singleton factory.
Global variables stored in configuration file.
std::vector< std::string > split(const char *token_string, const std::string &delimiter)
Return vector of items in s separated by delimiter.
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.
Global variables Listen()/Notify() wrapper.
Miscellaneous utilities, many of which string related.
PLugin remote repositories installation and Uninstall/list operations.