Commit 7201fac0 authored by twanvl's avatar twanvl

Modified update checker to get it to compile

parent 2cac5492
......@@ -11,6 +11,7 @@
#include <gui/control/card_editor.hpp>
#include <gui/control/text_ctrl.hpp>
#include <gui/about_window.hpp>
#include <gui/update_checker.hpp>
#include <gui/icon_menu.hpp>
#include <gui/util.hpp>
#include <data/set.hpp>
......@@ -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"));
// NOTE: space after "Del" prevents wx from making del an accellerator
// 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();
IconMenu* menuRotate = new IconMenu();
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&) {
}
void SetWindow::onFileCheckUpdates(wxCommandEvent&) {
(new UpdateWindow)->Show();
(new UpdatesWindow)->Show();
}
void SetWindow::onFilePrint(wxCommandEvent&) {
......
......@@ -179,11 +179,11 @@ void show_update_dialog(Window* parent) {
shown_dialog = true;
}
// ----------------------------------------------------------------------------- : UpdateWindow
// ----------------------------------------------------------------------------- : PackageUpdateList
class PackageUpdateList: public wxVListBox {
class PackageUpdateList : public wxVListBox {
public:
PackageUpdateList(UpdateWindow * parent)
PackageUpdateList(UpdatesWindow* parent)
: wxVListBox (parent, wxID_ANY, wxDefaultPosition, wxSize(480,210), wxNO_BORDER | wxVSCROLL)
, parent(parent)
{
......@@ -192,47 +192,49 @@ class PackageUpdateList: public wxVListBox {
}
SetItemCount(update_version_data ? update_version_data->packages.size() : 1);
}
virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const {
static wxBrush greyBrush(Color(224,224,224));
if (checking_updates) {
String text = _ERROR_("checking updates");
wxSize text_size = dc.GetTextExtent(text);
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(greyBrush);
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()) {
String text = _ERROR_("no packages");
wxSize text_size = dc.GetTextExtent(text);
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(greyBrush);
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 {
static wxBrush darkBrush(Color(192,224,255));
static wxBrush selectBrush(Color(96,96,192));
PackageVersionDataP pack = update_version_data->packages[n];
UpdateWindow::PackageStatus status = parent->package_data[pack].first;
UpdateWindow::PackageAction action = parent->package_data[pack].second;
UpdatesWindow::PackageStatus status = parent->package_data[pack].first;
UpdatesWindow::PackageAction action = parent->package_data[pack].second;
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(IsSelected(n) ? selectBrush : (n % 2 ? *wxWHITE_BRUSH : darkBrush));
dc.DrawRectangle(rect);
// These two arrays correspond to PackageStatus and PackageAction, respectively
static Color status_colors [] = {
Color(32,160,32)
,Color(32,32,255)
,Color(192,32,32)
};
static Color action_colors [] = {
Color(32,160,32)
,Color(192,32,32)
......@@ -240,14 +242,14 @@ class PackageUpdateList: public wxVListBox {
,Color(32,32,255)
,Color(32,32,32)
};
// Ditto here (these are the locale names)
static String status_texts [] = {
_TYPE_("installed")
,_TYPE_("uninstalled")
,_TYPE_("upgradeable")
};
static String action_texts [] = {
_TYPE_("install")
,_TYPE_("uninstall")
......@@ -255,98 +257,109 @@ class PackageUpdateList: public wxVListBox {
,_TYPE_("do nothing")
,_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);
#define SELECT_WHITE(color) (IsSelected(n) ? *wxWHITE : color)
dc.SetTextForeground(SELECT_WHITE(packageFront));
dc.SetTextBackground(textBack);
//dc.SetTextBackground(textBack);
dc.DrawText(pack->name, rect.GetLeft() + 1, rect.GetTop());
dc.SetTextForeground(SELECT_WHITE(status_colors[status]));
dc.DrawText(status_texts[status], rect.GetLeft() + 240, rect.GetTop());
dc.SetTextForeground(SELECT_WHITE(action_colors[action]));
dc.DrawText(action_texts[action], rect.GetLeft() + 360, rect.GetTop());
#undef SELECT_INVERT
}
}
virtual wxCoord OnMeasureItem(size_t) const {
return (update_version_data && !update_version_data->packages.empty()) ? 15 : 210;
}
void onUpdateCheckingFinished(wxEvent& event) {
SetItemCount(update_version_data ? update_version_data->packages.size() : 1);
}
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:
DECLARE_EVENT_TABLE()
UpdateWindow * parent;
UpdatesWindow* parent;
};
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()
UpdateWindow::UpdateWindow()
// ----------------------------------------------------------------------------- : UpdateWindow
UpdatesWindow::UpdatesWindow()
: Frame(nullptr, wxID_ANY, _TITLE_("package list"), wxDefaultPosition, wxSize(480,375), wxDEFAULT_DIALOG_STYLE | wxCLIP_CHILDREN)
{
SetIcon(wxIcon());
wxBoxSizer *v = new wxBoxSizer(wxVERTICAL);
package_list = new PackageUpdateList(this);
description_window = new HtmlWindowToBrowser(this, wxID_ANY, wxDefaultPosition, wxSize(480,100), wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER);
wxCommandEvent ev;
SetDefaultPackageStatus(ev);
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);
new_title = new wxStaticText(this, wxID_ANY, _TITLE_("new status"), wxDefaultPosition, wxSize(120,15), wxALIGN_LEFT | wxST_NO_AUTORESIZE);
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);
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);
package_title->Move(1,0);
status_title->Move(240,0);
new_title->Move(360,0);
v->AddSpacer(15);
v->Add(package_list);
v->Add(description_window);
SetSizer(v);
}
void UpdateWindow::SetDefaultPackageStatus(wxCommandEvent&)
{
if (!update_version_data)
return;
void UpdatesWindow::onUpdateCheckFinished(wxCommandEvent&) {
setDefaultPackageStatus();
}
void UpdatesWindow::setDefaultPackageStatus() {
if (!update_version_data) return;
FOR_EACH(p, update_version_data->packages) {
PackagedP pack;
try { pack = packages.openAny(p->name); }
catch (Error& e) { } // We couldn't open a package... wonder why?
try { pack = packages.openAny(p->name, true); }
catch (const Error&) { } // We couldn't open a package... wonder why?
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);
else
} else {
package_data[p] = PackageData(STATUS_NOT_INSTALLED, ACTION_NOTHING);
}
} 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);
else
} else {
package_data[p] = PackageData(STATUS_UPGRADEABLE, ACTION_UPGRADE);
} else
}
} else {
package_data[p] = PackageData(STATUS_INSTALLED, ACTION_NOTHING);
}
}
}
BEGIN_EVENT_TABLE(UpdateWindow, Frame)
EVT_COMMAND(-1, UPDATE_CHECK_FINISHED_EVT, UpdateWindow::SetDefaultPackageStatus)
BEGIN_EVENT_TABLE(UpdatesWindow, Frame)
EVT_COMMAND(wxID_ANY, UPDATE_CHECK_FINISHED_EVT, UpdatesWindow::onUpdateCheckFinished)
END_EVENT_TABLE()
......@@ -10,7 +10,6 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <wx/html/htmlwin.h>
// ----------------------------------------------------------------------------- : Update checking
......@@ -27,14 +26,20 @@ void check_updates_now(bool async = true);
* Call this function from an onIdle loop */
void show_update_dialog(Window* parent);
// ----------------------------------------------------------------------------- : Update window
class PackageUpdateList;
class wxHtmlWindow;
DECLARE_POINTER_TYPE(PackageVersionData);
/// 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:
UpdateWindow();
UpdatesWindow();
void DrawTitles(wxPaintEvent&);
enum PackageStatus {
......@@ -54,13 +59,16 @@ class UpdateWindow : public Frame {
map<PackageVersionDataP, PackageData> package_data;
void SetDefaultPackageStatus(wxCommandEvent&);
private:
DECLARE_EVENT_TABLE();
PackageUpdateList* package_list;
PackageUpdateList* package_list; ///< List of available packages
wxHtmlWindow* description_window;
wxStaticText *package_title, *status_title, *new_title;
void onUpdateCheckFinished(wxCommandEvent&);
void setDefaultPackageStatus();
};
/// 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