Commit 7201fac0 authored by twanvl's avatar twanvl

Modified update checker to get it to compile

parent 2cac5492
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <gui/control/card_editor.hpp> #include <gui/control/card_editor.hpp>
#include <gui/control/text_ctrl.hpp> #include <gui/control/text_ctrl.hpp>
#include <gui/about_window.hpp> #include <gui/about_window.hpp>
#include <gui/update_checker.hpp>
#include <gui/icon_menu.hpp> #include <gui/icon_menu.hpp>
#include <gui/util.hpp> #include <gui/util.hpp>
#include <data/set.hpp> #include <data/set.hpp>
...@@ -64,7 +65,8 @@ CardsPanel::CardsPanel(Window* parent, int id) ...@@ -64,7 +65,8 @@ CardsPanel::CardsPanel(Window* parent, int id)
menuCard->Append(ID_CARD_ADD_MULT, _("card_add_multiple"), _MENU_("add cards"), _HELP_("add cards")); menuCard->Append(ID_CARD_ADD_MULT, _("card_add_multiple"), _MENU_("add cards"), _HELP_("add cards"));
// NOTE: space after "Del" prevents wx from making del an accellerator // NOTE: space after "Del" prevents wx from making del an accellerator
// otherwise we delete a card when delete is pressed inside the editor // otherwise we delete a card when delete is pressed inside the editor
menuCard->Append(ID_CARD_REMOVE, _("card_del"), _MENU_("remove card"),_HELP_("remove card")); // Adding a space never hurts, please keep it just to be safe.
menuCard->Append(ID_CARD_REMOVE, _("card_del"), _MENU_("remove card")+_(" "),_HELP_("remove card"));
menuCard->AppendSeparator(); menuCard->AppendSeparator();
IconMenu* menuRotate = new IconMenu(); IconMenu* menuRotate = new IconMenu();
menuRotate->Append(ID_CARD_ROTATE_0, _("card_rotate_0"), _MENU_("rotate 0"), _HELP_("rotate 0"), wxITEM_CHECK); menuRotate->Append(ID_CARD_ROTATE_0, _("card_rotate_0"), _MENU_("rotate 0"), _HELP_("rotate 0"), wxITEM_CHECK);
......
...@@ -529,7 +529,7 @@ void SetWindow::onFileExportMWS(wxCommandEvent&) { ...@@ -529,7 +529,7 @@ void SetWindow::onFileExportMWS(wxCommandEvent&) {
} }
void SetWindow::onFileCheckUpdates(wxCommandEvent&) { void SetWindow::onFileCheckUpdates(wxCommandEvent&) {
(new UpdateWindow)->Show(); (new UpdatesWindow)->Show();
} }
void SetWindow::onFilePrint(wxCommandEvent&) { void SetWindow::onFilePrint(wxCommandEvent&) {
......
...@@ -179,11 +179,11 @@ void show_update_dialog(Window* parent) { ...@@ -179,11 +179,11 @@ void show_update_dialog(Window* parent) {
shown_dialog = true; shown_dialog = true;
} }
// ----------------------------------------------------------------------------- : UpdateWindow // ----------------------------------------------------------------------------- : PackageUpdateList
class PackageUpdateList: public wxVListBox { class PackageUpdateList : public wxVListBox {
public: public:
PackageUpdateList(UpdateWindow * parent) PackageUpdateList(UpdatesWindow* parent)
: wxVListBox (parent, wxID_ANY, wxDefaultPosition, wxSize(480,210), wxNO_BORDER | wxVSCROLL) : wxVListBox (parent, wxID_ANY, wxDefaultPosition, wxSize(480,210), wxNO_BORDER | wxVSCROLL)
, parent(parent) , parent(parent)
{ {
...@@ -192,47 +192,49 @@ class PackageUpdateList: public wxVListBox { ...@@ -192,47 +192,49 @@ class PackageUpdateList: public wxVListBox {
} }
SetItemCount(update_version_data ? update_version_data->packages.size() : 1); SetItemCount(update_version_data ? update_version_data->packages.size() : 1);
} }
virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const { virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const {
static wxBrush greyBrush(Color(224,224,224)); static wxBrush greyBrush(Color(224,224,224));
if (checking_updates) { if (checking_updates) {
String text = _ERROR_("checking updates"); String text = _ERROR_("checking updates");
wxSize text_size = dc.GetTextExtent(text);
dc.SetPen(*wxTRANSPARENT_PEN); dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(greyBrush); dc.SetBrush(greyBrush);
dc.DrawRectangle(rect); dc.DrawRectangle(rect);
dc.DrawText(text, rect.GetLeft() + (rect.GetWidth() - text_size.GetWidth()) / 2, rect.GetTop() + (rect.GetHeight() - text_size.GetHeight()) / 2); int w, h;
dc.GetTextExtent(text, &w, &h);
dc.DrawText(text, rect.GetLeft() + (rect.GetWidth() - w) / 2, rect.GetTop() + (rect.GetHeight() - h) / 2);
} else if (!update_version_data || update_version_data->packages.empty()) { } else if (!update_version_data || update_version_data->packages.empty()) {
String text = _ERROR_("no packages"); String text = _ERROR_("no packages");
wxSize text_size = dc.GetTextExtent(text);
dc.SetPen(*wxTRANSPARENT_PEN); dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(greyBrush); dc.SetBrush(greyBrush);
dc.DrawRectangle(rect); dc.DrawRectangle(rect);
dc.DrawText(text, rect.GetLeft() + (rect.GetWidth() - text_size.GetWidth()) / 2, rect.GetTop() + (rect.GetHeight() - text_size.GetHeight()) / 2); int w, h;
dc.GetTextExtent(text, &w, &h);
dc.DrawText(text, rect.GetLeft() + (rect.GetWidth() - w) / 2, rect.GetTop() + (rect.GetHeight() - h) / 2);
} else { } else {
static wxBrush darkBrush(Color(192,224,255)); static wxBrush darkBrush(Color(192,224,255));
static wxBrush selectBrush(Color(96,96,192)); static wxBrush selectBrush(Color(96,96,192));
PackageVersionDataP pack = update_version_data->packages[n]; PackageVersionDataP pack = update_version_data->packages[n];
UpdateWindow::PackageStatus status = parent->package_data[pack].first; UpdatesWindow::PackageStatus status = parent->package_data[pack].first;
UpdateWindow::PackageAction action = parent->package_data[pack].second; UpdatesWindow::PackageAction action = parent->package_data[pack].second;
dc.SetPen(*wxTRANSPARENT_PEN); dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(IsSelected(n) ? selectBrush : (n % 2 ? *wxWHITE_BRUSH : darkBrush)); dc.SetBrush(IsSelected(n) ? selectBrush : (n % 2 ? *wxWHITE_BRUSH : darkBrush));
dc.DrawRectangle(rect); dc.DrawRectangle(rect);
// These two arrays correspond to PackageStatus and PackageAction, respectively // These two arrays correspond to PackageStatus and PackageAction, respectively
static Color status_colors [] = { static Color status_colors [] = {
Color(32,160,32) Color(32,160,32)
,Color(32,32,255) ,Color(32,32,255)
,Color(192,32,32) ,Color(192,32,32)
}; };
static Color action_colors [] = { static Color action_colors [] = {
Color(32,160,32) Color(32,160,32)
,Color(192,32,32) ,Color(192,32,32)
...@@ -240,14 +242,14 @@ class PackageUpdateList: public wxVListBox { ...@@ -240,14 +242,14 @@ class PackageUpdateList: public wxVListBox {
,Color(32,32,255) ,Color(32,32,255)
,Color(32,32,32) ,Color(32,32,32)
}; };
// Ditto here (these are the locale names) // Ditto here (these are the locale names)
static String status_texts [] = { static String status_texts [] = {
_TYPE_("installed") _TYPE_("installed")
,_TYPE_("uninstalled") ,_TYPE_("uninstalled")
,_TYPE_("upgradeable") ,_TYPE_("upgradeable")
}; };
static String action_texts [] = { static String action_texts [] = {
_TYPE_("install") _TYPE_("install")
,_TYPE_("uninstall") ,_TYPE_("uninstall")
...@@ -255,98 +257,109 @@ class PackageUpdateList: public wxVListBox { ...@@ -255,98 +257,109 @@ class PackageUpdateList: public wxVListBox {
,_TYPE_("do nothing") ,_TYPE_("do nothing")
,_TYPE_("new mse") ,_TYPE_("new mse")
}; };
static Color textBack(0,0,0,wxALPHA_TRANSPARENT); // 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.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]));
dc.DrawText(status_texts[status], rect.GetLeft() + 240, rect.GetTop()); dc.DrawText(status_texts[status], rect.GetLeft() + 240, rect.GetTop());
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_INVERT
} }
} }
virtual wxCoord OnMeasureItem(size_t) const { virtual wxCoord OnMeasureItem(size_t) const {
return (update_version_data && !update_version_data->packages.empty()) ? 15 : 210; return (update_version_data && !update_version_data->packages.empty()) ? 15 : 210;
} }
void onUpdateCheckingFinished(wxEvent& event) { void onUpdateCheckingFinished(wxEvent& event) {
SetItemCount(update_version_data ? update_version_data->packages.size() : 1); SetItemCount(update_version_data ? update_version_data->packages.size() : 1);
} }
virtual wxCoord EstimateTotalHeight() const { virtual wxCoord EstimateTotalHeight() const {
return (update_version_data && !update_version_data->packages.empty()) ? 15 * update_version_data->packages.size() : 210; return (update_version_data && !update_version_data->packages.empty())
? 15 * (int)update_version_data->packages.size()
: 210;
} }
private: private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
UpdateWindow * parent; UpdatesWindow* parent;
}; };
BEGIN_EVENT_TABLE(PackageUpdateList, wxVListBox) BEGIN_EVENT_TABLE(PackageUpdateList, wxVListBox)
EVT_CUSTOM(UPDATE_CHECK_FINISHED_EVT, -1, PackageUpdateList::onUpdateCheckingFinished) EVT_CUSTOM(UPDATE_CHECK_FINISHED_EVT, wxID_ANY, PackageUpdateList::onUpdateCheckingFinished)
END_EVENT_TABLE() END_EVENT_TABLE()
UpdateWindow::UpdateWindow() // ----------------------------------------------------------------------------- : UpdateWindow
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,375), wxDEFAULT_DIALOG_STYLE | wxCLIP_CHILDREN)
{ {
SetIcon(wxIcon()); SetIcon(wxIcon());
wxBoxSizer *v = new wxBoxSizer(wxVERTICAL); wxBoxSizer *v = new wxBoxSizer(wxVERTICAL);
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);
wxCommandEvent ev; setDefaultPackageStatus();
SetDefaultPackageStatus(ev);
// 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); package_title->Move(1,0);
status_title->Move(240,0); status_title->Move(240,0);
new_title->Move(360,0); new_title->Move(360,0);
v->AddSpacer(15); v->AddSpacer(15);
v->Add(package_list); v->Add(package_list);
v->Add(description_window); v->Add(description_window);
SetSizer(v); SetSizer(v);
} }
void UpdateWindow::SetDefaultPackageStatus(wxCommandEvent&) void UpdatesWindow::onUpdateCheckFinished(wxCommandEvent&) {
{ setDefaultPackageStatus();
if (!update_version_data) }
return;
void UpdatesWindow::setDefaultPackageStatus() {
if (!update_version_data) return;
FOR_EACH(p, update_version_data->packages) { FOR_EACH(p, update_version_data->packages) {
PackagedP pack; PackagedP pack;
try { pack = packages.openAny(p->name); } try { pack = packages.openAny(p->name, true); }
catch (Error& e) { } // We couldn't open a package... wonder why? catch (const Error&) { } // We couldn't open a package... wonder why?
if (!pack) { if (!pack) {
if (p->app_version > file_version) // not installed
if (p->app_version > file_version) {
package_data[p] = PackageData(STATUS_NOT_INSTALLED, ACTION_NEW_MSE); package_data[p] = PackageData(STATUS_NOT_INSTALLED, ACTION_NEW_MSE);
else } else {
package_data[p] = PackageData(STATUS_NOT_INSTALLED, ACTION_NOTHING); package_data[p] = PackageData(STATUS_NOT_INSTALLED, ACTION_NOTHING);
}
} else if (pack->version < p->version) { } else if (pack->version < p->version) {
if (p->app_version > file_version) // newer version
if (p->app_version > file_version) {
package_data[p] = PackageData(STATUS_UPGRADEABLE, ACTION_NEW_MSE); package_data[p] = PackageData(STATUS_UPGRADEABLE, ACTION_NEW_MSE);
else } else {
package_data[p] = PackageData(STATUS_UPGRADEABLE, ACTION_UPGRADE); package_data[p] = PackageData(STATUS_UPGRADEABLE, ACTION_UPGRADE);
} else }
} else {
package_data[p] = PackageData(STATUS_INSTALLED, ACTION_NOTHING); package_data[p] = PackageData(STATUS_INSTALLED, ACTION_NOTHING);
}
} }
} }
BEGIN_EVENT_TABLE(UpdateWindow, Frame) BEGIN_EVENT_TABLE(UpdatesWindow, Frame)
EVT_COMMAND(-1, UPDATE_CHECK_FINISHED_EVT, UpdateWindow::SetDefaultPackageStatus) EVT_COMMAND(wxID_ANY, UPDATE_CHECK_FINISHED_EVT, UpdatesWindow::onUpdateCheckFinished)
END_EVENT_TABLE() END_EVENT_TABLE()
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
// ----------------------------------------------------------------------------- : Includes // ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp> #include <util/prec.hpp>
#include <wx/html/htmlwin.h>
// ----------------------------------------------------------------------------- : Update checking // ----------------------------------------------------------------------------- : Update checking
...@@ -27,14 +26,20 @@ void check_updates_now(bool async = true); ...@@ -27,14 +26,20 @@ void check_updates_now(bool async = true);
* Call this function from an onIdle loop */ * Call this function from an onIdle loop */
void show_update_dialog(Window* parent); void show_update_dialog(Window* parent);
// ----------------------------------------------------------------------------- : Update window
class PackageUpdateList; class PackageUpdateList;
class wxHtmlWindow;
DECLARE_POINTER_TYPE(PackageVersionData); DECLARE_POINTER_TYPE(PackageVersionData);
/// A window that displays the updates and allows the user to select some. /// A window that displays the updates and allows the user to select some.
class UpdateWindow : public Frame { /** NOTE: cannot be called 'UpdateWindow' because there is a Win32 function with that name
*/
class UpdatesWindow : public Frame {
public: public:
UpdateWindow(); UpdatesWindow();
void DrawTitles(wxPaintEvent&); void DrawTitles(wxPaintEvent&);
enum PackageStatus { enum PackageStatus {
...@@ -54,13 +59,16 @@ class UpdateWindow : public Frame { ...@@ -54,13 +59,16 @@ class UpdateWindow : public Frame {
map<PackageVersionDataP, PackageData> package_data; map<PackageVersionDataP, PackageData> package_data;
void SetDefaultPackageStatus(wxCommandEvent&);
private: private:
DECLARE_EVENT_TABLE(); DECLARE_EVENT_TABLE();
PackageUpdateList* package_list; PackageUpdateList* package_list; ///< List of available packages
wxHtmlWindow* description_window; wxHtmlWindow* description_window;
wxStaticText *package_title, *status_title, *new_title; wxStaticText *package_title, *status_title, *new_title;
void onUpdateCheckFinished(wxCommandEvent&);
void setDefaultPackageStatus();
}; };
/// Was update data found? /// Was update data found?
......
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