diff --git a/src/data/settings.hpp b/src/data/settings.hpp index a35b14ed..49445781 100644 --- a/src/data/settings.hpp +++ b/src/data/settings.hpp @@ -111,8 +111,8 @@ class Settings { private: map game_settings; map stylesheet_settings; - StyleSheetSettings default_stylesheet_settings; public: + StyleSheetSettings default_stylesheet_settings; ///< The default settings for stylesheets // --------------------------------------------------- : Special game stuff String apprentice_location; diff --git a/src/gui/preferences_window.cpp b/src/gui/preferences_window.cpp new file mode 100644 index 00000000..5dffa3c8 --- /dev/null +++ b/src/gui/preferences_window.cpp @@ -0,0 +1,252 @@ +//+----------------------------------------------------------------------------+ +//| Description: Magic Set Editor - Program to make Magic (tm) cards | +//| Copyright: (C) 2001 - 2006 Twan van Laarhoven | +//| License: GNU General Public License 2 or later (see file COPYING) | +//+----------------------------------------------------------------------------+ + +// ----------------------------------------------------------------------------- : Includes + +#include +#include +#include +#include +#include +#include + +// ----------------------------------------------------------------------------- : Preferences pages + +// A page from the preferences dialog +class PreferencesPage : public wxPanel { + public: + PreferencesPage(Window* parent) + : wxPanel(parent, wxID_ANY) + {} + + /// Stores the settings from the panel in the global settings object + virtual void store() = 0; +}; + +// Preferences page for card viewing related settings +class DisplayPreferencesPage : public PreferencesPage { + public: + DisplayPreferencesPage(Window* parent); + void store(); + + private: + DECLARE_EVENT_TABLE(); + + wxCheckBox* high_quality, *borders; + wxSpinCtrl* zoom; + wxCheckBox* non_normal_export; + + void onSelectColumns(wxCommandEvent&); +}; + +// Preferences page for directories of programs +// i.e. Apprentice, Magic Workstation +// perhaps in the future also directories for packages? +class DirsPreferencesPage : public PreferencesPage { + public: + DirsPreferencesPage(Window* parent); + void store(); + + private: + DECLARE_EVENT_TABLE(); + + wxTextCtrl* apprentice; + + void onApprenticeBrowse(wxCommandEvent&); +}; + +// Preferences page for automatic updates +class UpdatePreferencesPage : public PreferencesPage { + public: + UpdatePreferencesPage(Window* parent); + void store(); + + private: + DECLARE_EVENT_TABLE(); + + wxChoice* check_at_startup; + + // check for updates + void onCheckUpdatesNow(wxCommandEvent&); +}; + + +// ----------------------------------------------------------------------------- : PreferencesWindow + +PreferencesWindow::PreferencesWindow(Window* parent) + : wxDialog(parent, wxID_ANY, _("Preferences"), wxDefaultPosition) +{ + // init notebook + wxNotebook* nb = new wxNotebook(this, ID_NOTEBOOK); + nb->AddPage(new DisplayPreferencesPage(nb), _("Display")); + nb->AddPage(new DirsPreferencesPage (nb), _("Directories")); + nb->AddPage(new UpdatePreferencesPage (nb), _("Updates")); + + // init sizer + wxSizer* s = new wxBoxSizer(wxVERTICAL); + s->Add(nb, 1, wxEXPAND | wxALL & ~wxBOTTOM, 8); + s->AddSpacer(4); + s->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, wxEXPAND | wxALL & ~wxTOP, 8); + s->SetSizeHints(this); + SetSizer(s); +} + +void PreferencesWindow::onOk(wxCommandEvent&) { + // store each page + wxNotebook* nb = static_cast(FindWindow(ID_NOTEBOOK)); + size_t count = nb->GetPageCount(); + for (size_t i = 0 ; i < count ; ++i) { + static_cast(nb->GetPage(i))->store(); + } + // close + EndModal(wxID_OK); +} + +BEGIN_EVENT_TABLE(PreferencesWindow, wxDialog) + EVT_BUTTON (wxID_OK, PreferencesWindow::onOk) +END_EVENT_TABLE () + + +// ----------------------------------------------------------------------------- : Preferences page : display + +DisplayPreferencesPage::DisplayPreferencesPage(Window* parent) + : PreferencesPage(parent) +{ + // init controls + high_quality = new wxCheckBox(this, wxID_ANY, _("&High quality rendering")); + borders = new wxCheckBox(this, wxID_ANY, _("Show &lines around fields")); + zoom = new wxSpinCtrl(this, wxID_ANY); + non_normal_export = new wxCheckBox(this, wxID_ANY, _("Use zoom and rotation settings when e&xporting")); + wxButton* columns = new wxButton(this, ID_SELECT_COLUMNS, _("Select...")); + // set values + high_quality-> SetValue( settings.default_stylesheet_settings.card_anti_alias()); + borders-> SetValue( settings.default_stylesheet_settings.card_borders()); + non_normal_export->SetValue(!settings.default_stylesheet_settings.card_normal_export()); + zoom->SetRange(1, 1000); + zoom-> SetValue( settings.default_stylesheet_settings.card_zoom() * 100); + // init sizer + wxSizer* s = new wxBoxSizer(wxVERTICAL); + wxSizer* s2 = new wxStaticBoxSizer(wxVERTICAL, this, _("Card Display")); + s2->Add(high_quality, 0, wxEXPAND | wxALL, 4); + s2->Add(borders, 0, wxEXPAND | wxALL, 4); + wxSizer* s3 = new wxBoxSizer(wxHORIZONTAL); + s3->Add(new wxStaticText(this, wxID_ANY, _("&Zoom:")), 0, wxALL & ~wxLEFT, 4); + s3->Add(zoom); + s3->Add(new wxStaticText(this, wxID_ANY, _("% of normal size")),1, wxALL & ~wxRIGHT, 4); + s2->Add(s3, 0, wxEXPAND | wxALL, 4); + s2->Add(non_normal_export,0, wxEXPAND | wxALL, 4); + s2->Add(new wxStaticText(this, wxID_ANY, _("(When off the cards are exported\n and copied at 100% size and normal rotation)")), 0, wxALL & ~wxTOP, 4); + s->Add(s2, 0, wxEXPAND | wxALL, 8); + wxSizer* s4 = new wxStaticBoxSizer(wxVERTICAL, this, _("Card List")); + wxSizer* s5 = new wxBoxSizer(wxHORIZONTAL); + s5->Add(new wxStaticText(this, wxID_ANY, _("Columns: ")), 0, wxALL & ~wxLEFT | wxEXPAND, 4); + s5->Add(columns); + s4->Add(s5, 0, wxEXPAND | wxALL, 4); + s->Add(s, 0, wxEXPAND | wxALL & ~wxTOP, 8); + s->SetSizeHints(this); + SetSizer(s); +} + +void DisplayPreferencesPage::store() { + settings.default_stylesheet_settings.card_anti_alias = high_quality->GetValue(); + settings.default_stylesheet_settings.card_borders = borders->GetValue(); + settings.default_stylesheet_settings.card_zoom = zoom->GetValue() / 100.0; + settings.default_stylesheet_settings.card_normal_export = !non_normal_export->GetValue(); +} + +void DisplayPreferencesPage::onSelectColumns(wxCommandEvent&) { + // TODO +} + +BEGIN_EVENT_TABLE(DisplayPreferencesPage, wxPanel) + EVT_BUTTON (ID_SELECT_COLUMNS, DisplayPreferencesPage::onSelectColumns) +END_EVENT_TABLE () + + +// ----------------------------------------------------------------------------- : Preferences page : directories + +DirsPreferencesPage::DirsPreferencesPage(Window* parent) + : PreferencesPage(parent) +{ + // init controls + apprentice = new wxTextCtrl(this, wxID_ANY); + wxButton* ab = new wxButton(this, ID_APPRENTICE_BROWSE, _("&Browse...")); + // set values + apprentice->SetValue(settings.apprentice_location); + // init sizer + wxSizer* s = new wxBoxSizer(wxVERTICAL); + wxSizer* s2 = new wxStaticBoxSizer(wxVERTICAL, this, _("External programs")); + s2->Add(new wxStaticText(this, wxID_ANY, _("&Apprentice:")), 0, wxALL, 4); + wxSizer* s3 = new wxBoxSizer(wxHORIZONTAL); + s3->Add(apprentice, 1, wxEXPAND | wxRIGHT, 4); + s3->Add(ab, 0, wxEXPAND); + s2->Add(s3, 0, wxEXPAND | wxALL & ~wxTOP, 4); + s->Add(s2, 0, wxEXPAND | wxALL, 8); + s->SetSizeHints(this); + SetSizer(s); +} + +void DirsPreferencesPage::store() { + settings.apprentice_location = apprentice->GetValue(); +} + +void DirsPreferencesPage::onApprenticeBrowse(wxCommandEvent&) { + // browse for appr.exe + wxFileDialog dlg(this, _("Locate apprentice"), apprentice->GetValue(), _(""), _("Apprentice Executable|appr.exe"), wxOPEN); + if (dlg.ShowModal() == wxID_OK) { + wxFileName fn(dlg.GetPath()); + apprentice->SetValue(fn.GetPath()); + } +} + +BEGIN_EVENT_TABLE(DirsPreferencesPage, wxPanel) + EVT_BUTTON (ID_APPRENTICE_BROWSE, DirsPreferencesPage::onApprenticeBrowse) +END_EVENT_TABLE (); + + +// ----------------------------------------------------------------------------- : Preferences page : updates + +UpdatePreferencesPage::UpdatePreferencesPage(Window* parent) + : PreferencesPage(parent) +{ + // init controls + check_at_startup = new wxChoice(this, wxID_ANY); + wxButton* check_now = new wxButton(this, ID_CHECK_UPDATES_NOW, _("Check &Now")); + // set values + check_at_startup->Append(_("Always")); // 0 + check_at_startup->Append(_("If internet connection exists")); // 1 + check_at_startup->Append(_("Never")); // 2 + check_at_startup->SetSelection(settings.check_updates); + // init sizer + wxSizer* s = new wxBoxSizer(wxVERTICAL); + s->Add(new wxStaticText(this, wxID_ANY, _("&Check for new versions at startup:")), 0, wxALL, 8); + s->Add(check_at_startup, 0, wxALL & ~wxTOP, 8); + s->Add(check_now, 0, wxALL & ~wxTOP, 8); + s->Add(new wxStaticText(this, wxID_ANY, _("Checking for updates requires an internet connection.\nWhen no internet connection is found upates are not checked.\n\nNo information is collected when checking for updates.")), 0, wxALL & ~wxTOP, 8); + SetSizer(s); +} + +void UpdatePreferencesPage::store() { + int sel = check_at_startup->GetSelection(); + if (sel == 0) settings.check_updates = CHECK_ALWAYS; + else if (sel == 1) settings.check_updates = CHECK_IF_CONNECTED; + else settings.check_updates = CHECK_NEVER; +} + +void UpdatePreferencesPage::onCheckUpdatesNow(wxCommandEvent&) { + check_updates_now(false); + if (!update_data_found()) { + wxMessageBox(_("Checking updates failed"), _("Update Check"), wxICON_ERROR | wxOK); + } else if (!update_available()) { + wxMessageBox(_("There are no available updates."), _("Update Check"), wxICON_INFORMATION | wxOK); + } else { + show_update_dialog(GetParent()); + } +} + +BEGIN_EVENT_TABLE(UpdatePreferencesPage, wxPanel) + EVT_BUTTON (ID_CHECK_UPDATES_NOW, UpdatePreferencesPage::onCheckUpdatesNow) +END_EVENT_TABLE () diff --git a/src/gui/preferences_window.hpp b/src/gui/preferences_window.hpp new file mode 100644 index 00000000..f7677089 --- /dev/null +++ b/src/gui/preferences_window.hpp @@ -0,0 +1,29 @@ +//+----------------------------------------------------------------------------+ +//| Description: Magic Set Editor - Program to make Magic (tm) cards | +//| Copyright: (C) 2001 - 2006 Twan van Laarhoven | +//| License: GNU General Public License 2 or later (see file COPYING) | +//+----------------------------------------------------------------------------+ + +#ifndef HEADER_GUI_PREFERENCES_WINDOW +#define HEADER_GUI_PREFERENCES_WINDOW + +// ----------------------------------------------------------------------------- : Includes + +#include + +// ----------------------------------------------------------------------------- : Preferences window + +/// Dialog for the program settings, rendered as a set of pages +class PreferencesWindow : public wxDialog { + public: + PreferencesWindow(Window* parent); + + private: + DECLARE_EVENT_TABLE(); + + /// Close the dialog, and store all settings + void onOk(wxCommandEvent&); +}; + +// ----------------------------------------------------------------------------- : EOF +#endif diff --git a/src/gui/update_checker.cpp b/src/gui/update_checker.cpp index 72eea045..8b5586f9 100644 --- a/src/gui/update_checker.cpp +++ b/src/gui/update_checker.cpp @@ -38,6 +38,9 @@ VersionDataP update_version_data; // Is update checking in progress? volatile bool checking_updates = false; +bool update_data_found() { return !!update_version_data; } +bool update_available() { return update_version_data && update_version_data->version > app_version; } + // ----------------------------------------------------------------------------- : Update checking // Thread to retrieve update information @@ -114,8 +117,7 @@ struct HtmlWindowToBrowser : public wxHtmlWindow { }; void show_update_dialog(Window* parent) { - if (!update_version_data) return; - if (update_version_data->version <= app_version) return; // we already have the latest version + if (!update_available()) return; // we already have the latest version // Show update dialog wxDialog* dlg = new wxDialog(parent, wxID_ANY, _("Updates availible"), wxDefaultPosition); // controls diff --git a/src/gui/update_checker.hpp b/src/gui/update_checker.hpp index 18c7831f..cc4e7eec 100644 --- a/src/gui/update_checker.hpp +++ b/src/gui/update_checker.hpp @@ -26,5 +26,10 @@ void check_updates_now(bool async = true); * Call this function from an onIdle loop */ void show_update_dialog(Window* parent); +/// Was update data found? +bool update_data_found(); +/// Is there an update? +bool update_available(); + // ----------------------------------------------------------------------------- : EOF #endif diff --git a/src/mse.vcproj b/src/mse.vcproj index dcac9726..afb4246d 100644 --- a/src/mse.vcproj +++ b/src/mse.vcproj @@ -580,6 +580,12 @@ + + + + diff --git a/src/util/window_id.hpp b/src/util/window_id.hpp index 82a3dcfc..ba12f0fd 100644 --- a/src/util/window_id.hpp +++ b/src/util/window_id.hpp @@ -167,13 +167,17 @@ enum ControlID { , ID_NOTES , ID_KEYWORD , ID_PARAMETER -, ID_SEPARATOR , ID_REMINDER , ID_RULES + // Card list column select , ID_MOVE_UP , ID_MOVE_DOWN , ID_SHOW , ID_HIDE + // Settings +, ID_NOTEBOOK +, ID_APPRENTICE_BROWSE +, ID_CHECK_UPDATES_NOW }; // ----------------------------------------------------------------------------- : EOF