Commit 3c11cc7e authored by coppro's avatar coppro

Improved the update window further - now we just need a system to actual download and install them.

Added safeties to locale validation (ugly code though... I'd add another function, but I'm lazy and this is faster)
parent 5ef8ff29
mse version: 0.3.2 mse version: 0.3.2
full name: English full name: English
############################################################## Menu items ############################################################## Menu items
...@@ -686,7 +686,7 @@ type: ...@@ -686,7 +686,7 @@ type:
upgradeable: upgradeable upgradeable: upgradeable
install: install install: install
uninstall: uninstalled uninstall: uninstall
upgrade: upgrade upgrade: upgrade
do nothing: do nothing do nothing: do nothing
new mse: MSE outdated new mse: MSE outdated
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <data/symbol_font.hpp> #include <data/symbol_font.hpp>
#include <util/io/package_manager.hpp> #include <util/io/package_manager.hpp>
#include <script/to_value.hpp> #include <script/to_value.hpp>
#include <wx/wfstream.h>
#include <wx/stdpaths.h> #include <wx/stdpaths.h>
#if defined(__WXMSW__) #if defined(__WXMSW__)
...@@ -209,16 +210,26 @@ void Locale::validate(Version ver) { ...@@ -209,16 +210,26 @@ void Locale::validate(Version ver) {
r.handle_greedy(v); r.handle_greedy(v);
// validate // validate
String errors; String errors;
errors += translations[LOCALE_CAT_MENU ].validate(_("menu"), *v.sublocales[_("menu") ]); // For efficiency, this needs to be parallel to LocaleCategory's values.
errors += translations[LOCALE_CAT_HELP ].validate(_("help"), *v.sublocales[_("help") ]); String sublocales[10] = {
errors += translations[LOCALE_CAT_TOOL ].validate(_("tool"), *v.sublocales[_("tool") ]); _("menu"),
errors += translations[LOCALE_CAT_TOOLTIP].validate(_("tooltip"), *v.sublocales[_("tooltip")]); _("help"),
errors += translations[LOCALE_CAT_LABEL ].validate(_("label"), *v.sublocales[_("label") ]); _("tool"),
errors += translations[LOCALE_CAT_BUTTON ].validate(_("button"), *v.sublocales[_("button") ]); _("tooltip"),
errors += translations[LOCALE_CAT_TITLE ].validate(_("title"), *v.sublocales[_("title") ]); _("label"),
errors += translations[LOCALE_CAT_ACTION ].validate(_("action"), *v.sublocales[_("action") ]); _("button"),
errors += translations[LOCALE_CAT_ERROR ].validate(_("error"), *v.sublocales[_("error") ]); _("title"),
errors += translations[LOCALE_CAT_TYPE ].validate(_("type"), *v.sublocales[_("type") ]); _("type"),
_("action"),
_("error")
};
for (String * current = sublocales; current < sublocales + 10; ++current) {
if (v.sublocales[*current])
errors += translations[current - sublocales].validate(*current, *v.sublocales[*current]);
else
errors += _("\nError validating local file: expected keys file missing \"") + *current + _("\" section.");
}
// errors? // errors?
if (!errors.empty()) { if (!errors.empty()) {
if (ver != app_version) { if (ver != app_version) {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <data/settings.hpp> #include <data/settings.hpp>
#include <util/io/package_manager.hpp> #include <util/io/package_manager.hpp>
#include <util/version.hpp> #include <util/version.hpp>
#include <util/window_id.hpp>
#include <script/value.hpp> // for some strange reason the profile build needs this :( #include <script/value.hpp> // for some strange reason the profile build needs this :(
#include <script/to_value.hpp> #include <script/to_value.hpp>
#include <wx/dialup.h> #include <wx/dialup.h>
...@@ -184,7 +185,7 @@ void show_update_dialog(Window* parent) { ...@@ -184,7 +185,7 @@ void show_update_dialog(Window* parent) {
class PackageUpdateList : public wxVListBox { class PackageUpdateList : public wxVListBox {
public: public:
PackageUpdateList(UpdatesWindow* parent) PackageUpdateList(UpdatesWindow* parent)
: wxVListBox (parent, wxID_ANY, wxDefaultPosition, wxSize(480,210), wxNO_BORDER | wxVSCROLL) : wxVListBox (parent, ID_PACKAGE_LIST, wxDefaultPosition, wxSize(480,210), wxNO_BORDER | wxVSCROLL)
, parent(parent) , parent(parent)
{ {
if (!checking_updates && !update_version_data) { if (!checking_updates && !update_version_data) {
...@@ -258,14 +259,11 @@ class PackageUpdateList : public wxVListBox { ...@@ -258,14 +259,11 @@ class PackageUpdateList : public wxVListBox {
,_TYPE_("new mse") ,_TYPE_("new mse")
}; };
// this doesn't work for me, is it really necessary?
//static Color textBack(0,0,0,wxALPHA_TRANSPARENT);
static Color packageFront(64,64,64); static Color packageFront(64,64,64);
#define SELECT_WHITE(color) (IsSelected(n) ? *wxWHITE : color) #define SELECT_WHITE(color) (IsSelected(n) ? *wxWHITE : color)
dc.SetTextForeground(SELECT_WHITE(packageFront)); dc.SetTextForeground(SELECT_WHITE(packageFront));
//dc.SetTextBackground(textBack);
dc.DrawText(pack->name, rect.GetLeft() + 1, rect.GetTop()); dc.DrawText(pack->name, rect.GetLeft() + 1, rect.GetTop());
dc.SetTextForeground(SELECT_WHITE(status_colors[status])); dc.SetTextForeground(SELECT_WHITE(status_colors[status]));
...@@ -274,7 +272,7 @@ class PackageUpdateList : public wxVListBox { ...@@ -274,7 +272,7 @@ class PackageUpdateList : public wxVListBox {
dc.SetTextForeground(SELECT_WHITE(action_colors[action])); dc.SetTextForeground(SELECT_WHITE(action_colors[action]));
dc.DrawText(action_texts[action], rect.GetLeft() + 360, rect.GetTop()); dc.DrawText(action_texts[action], rect.GetLeft() + 360, rect.GetTop());
#undef SELECT_INVERT #undef SELECT_WHITE
} }
} }
...@@ -304,27 +302,48 @@ END_EVENT_TABLE() ...@@ -304,27 +302,48 @@ END_EVENT_TABLE()
// ----------------------------------------------------------------------------- : UpdateWindow // ----------------------------------------------------------------------------- : UpdateWindow
UpdatesWindow::UpdatesWindow() UpdatesWindow::UpdatesWindow()
: Frame(nullptr, wxID_ANY, _TITLE_("package list"), wxDefaultPosition, wxSize(480,375), wxDEFAULT_DIALOG_STYLE | wxCLIP_CHILDREN) : Frame(nullptr, wxID_ANY, _TITLE_("package list"), wxDefaultPosition, wxSize(480,400), wxDEFAULT_DIALOG_STYLE | wxCLIP_CHILDREN)
{ {
SetIcon(wxIcon()); SetIcon(wxIcon());
wxBoxSizer *v = new wxBoxSizer(wxVERTICAL); wxBoxSizer *v = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *h1 = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *h2 = new wxBoxSizer(wxHORIZONTAL);
package_list = new PackageUpdateList(this); package_list = new PackageUpdateList(this);
description_window = new HtmlWindowToBrowser(this, wxID_ANY, wxDefaultPosition, wxSize(480,100), wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER); description_window = new HtmlWindowToBrowser(this, wxID_ANY, wxDefaultPosition, wxSize(480,100), wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER);
setDefaultPackageStatus(); setDefaultPackageStatus();
// TODO: No absolute positioning please!
package_title = new wxStaticText(this, wxID_ANY, _TITLE_("package name"), wxDefaultPosition, wxSize(120,15), wxALIGN_LEFT | wxST_NO_AUTORESIZE); package_title = new wxStaticText(this, wxID_ANY, _TITLE_("package name"), wxDefaultPosition, wxSize(120,15), wxALIGN_LEFT | wxST_NO_AUTORESIZE);
status_title = new wxStaticText(this, wxID_ANY, _TITLE_("package status"), wxDefaultPosition, wxSize(120,15), wxALIGN_LEFT | wxST_NO_AUTORESIZE); status_title = new wxStaticText(this, wxID_ANY, _TITLE_("package status"), wxDefaultPosition, wxSize(120,15), wxALIGN_LEFT | wxST_NO_AUTORESIZE);
new_title = new wxStaticText(this, wxID_ANY, _TITLE_("new status"), wxDefaultPosition, wxSize(120,15), wxALIGN_LEFT | wxST_NO_AUTORESIZE); new_title = new wxStaticText(this, wxID_ANY, _TITLE_("new status"), wxDefaultPosition, wxSize(120,15), wxALIGN_LEFT | wxST_NO_AUTORESIZE);
package_title->Move(1,0);
status_title->Move(240,0);
new_title->Move(360,0);
v->AddSpacer(15); h1->Add(package_title);
h1->Add(status_title);
h1->Add(new_title, 2);
(install_button = new wxButton(this, ID_INSTALL, _("Install")))->Disable();
(upgrade_button = new wxButton(this, ID_UPGRADE, _("Update")))->Disable();
(remove_button = new wxButton(this, ID_REMOVE, _("Remove")))->Disable();
(cancel_button = new wxButton(this, ID_CANCEL, _("Cancel")))->Disable();
h2->AddStretchSpacer(1);
h2->Add(install_button);
h2->AddStretchSpacer(2);
h2->Add(upgrade_button);
h2->AddStretchSpacer(2);
h2->Add(remove_button);
h2->AddStretchSpacer(2);
h2->Add(cancel_button);
h2->AddStretchSpacer(1);
v->Add(h1);
v->Add(package_list); v->Add(package_list);
v->AddStretchSpacer(1);
v->Add(description_window); v->Add(description_window);
v->AddStretchSpacer(1);
v->Add(h2);
v->AddStretchSpacer(1);
SetSizer(v); SetSizer(v);
} }
...@@ -333,6 +352,54 @@ void UpdatesWindow::onUpdateCheckFinished(wxCommandEvent&) { ...@@ -333,6 +352,54 @@ void UpdatesWindow::onUpdateCheckFinished(wxCommandEvent&) {
setDefaultPackageStatus(); setDefaultPackageStatus();
} }
void UpdatesWindow::onPackageSelect(wxCommandEvent& ev) {
updateButtons(ev.GetInt());
}
void UpdatesWindow::onButton(wxCommandEvent& ev) {
PackageVersionDataP pack = update_version_data->packages[package_list->GetSelection()];
PackageAction& action = package_data[pack].second;
switch (ev.GetId()) {
case ID_INSTALL: action = ACTION_INSTALL; break;
case ID_REMOVE: action = ACTION_UNINSTALL; break;
case ID_UPGRADE: action = ACTION_UPGRADE; break;
case ID_CANCEL: action = (pack->app_version > file_version) ? ACTION_NEW_MSE : ACTION_NOTHING; break;
}
updateButtons(package_list->GetSelection());
package_list->Refresh();
}
void UpdatesWindow::updateButtons(int id) {
PackageVersionDataP pack = update_version_data->packages[id];
description_window->SetPage(pack->description);
PackageStatus status = package_data[pack].first;
PackageAction action = package_data[pack].second;
if (action == ACTION_NEW_MSE) {
install_button->Disable();
remove_button->Enable(status != STATUS_NOT_INSTALLED);
upgrade_button->Disable();
cancel_button->Disable();
} else if (status == STATUS_INSTALLED) {
install_button->Disable();
remove_button->Enable(action != ACTION_UNINSTALL);
upgrade_button->Disable();
cancel_button->Enable(action == ACTION_UNINSTALL);
} else if (status == STATUS_NOT_INSTALLED) {
install_button->Enable(action != ACTION_INSTALL);
remove_button->Disable();
upgrade_button->Disable();
cancel_button->Enable(action == ACTION_INSTALL);
} else /* status == STATUS_UPGRADEABLE */ {
install_button->Disable();
remove_button->Enable(action != ACTION_UNINSTALL);
upgrade_button->Enable(action != ACTION_UPGRADE);
cancel_button->Enable(action != ACTION_NOTHING);
}
}
void UpdatesWindow::setDefaultPackageStatus() { void UpdatesWindow::setDefaultPackageStatus() {
if (!update_version_data) return; if (!update_version_data) return;
FOR_EACH(p, update_version_data->packages) { FOR_EACH(p, update_version_data->packages) {
...@@ -362,4 +429,9 @@ void UpdatesWindow::setDefaultPackageStatus() { ...@@ -362,4 +429,9 @@ void UpdatesWindow::setDefaultPackageStatus() {
BEGIN_EVENT_TABLE(UpdatesWindow, Frame) BEGIN_EVENT_TABLE(UpdatesWindow, Frame)
EVT_COMMAND(wxID_ANY, UPDATE_CHECK_FINISHED_EVT, UpdatesWindow::onUpdateCheckFinished) EVT_COMMAND(wxID_ANY, UPDATE_CHECK_FINISHED_EVT, UpdatesWindow::onUpdateCheckFinished)
EVT_LISTBOX(ID_PACKAGE_LIST, UpdatesWindow::onPackageSelect)
EVT_BUTTON(ID_INSTALL, UpdatesWindow::onButton)
EVT_BUTTON(ID_REMOVE, UpdatesWindow::onButton)
EVT_BUTTON(ID_UPGRADE, UpdatesWindow::onButton)
EVT_BUTTON(ID_CANCEL, UpdatesWindow::onButton)
END_EVENT_TABLE() END_EVENT_TABLE()
...@@ -65,8 +65,14 @@ class UpdatesWindow : public Frame { ...@@ -65,8 +65,14 @@ class UpdatesWindow : public Frame {
wxHtmlWindow* description_window; wxHtmlWindow* description_window;
wxStaticText *package_title, *status_title, *new_title; wxStaticText *package_title, *status_title, *new_title;
wxButton *install_button, *upgrade_button, *remove_button, *cancel_button;
void onUpdateCheckFinished(wxCommandEvent&); void onUpdateCheckFinished(wxCommandEvent&);
void onPackageSelect(wxCommandEvent&);
void onButton(wxCommandEvent&);
/// Update the buttons to indicate that this is selected.
void updateButtons(int index);
void setDefaultPackageStatus(); void setDefaultPackageStatus();
}; };
......
...@@ -237,6 +237,12 @@ enum ControlID { ...@@ -237,6 +237,12 @@ enum ControlID {
, ID_ZOOM_Y , ID_ZOOM_Y
, ID_SHARPEN , ID_SHARPEN
, ID_SHARPEN_AMOUNT , ID_SHARPEN_AMOUNT
// Updates window
, ID_PACKAGE_LIST
, ID_INSTALL
, ID_UPGRADE
, ID_REMOVE
, ID_CANCEL
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment