KissCount/src/view/wxUI.cpp

213 lines
4.1 KiB
C++
Raw Normal View History

#include "wxUI.h"
2010-07-04 19:39:39 +02:00
wxString months[12] ;
2010-05-16 10:35:34 +02:00
wxUI::wxUI(KissCount* kiss, const wxString& title, const wxPoint& pos, const wxSize& size)
2010-06-27 21:39:49 +02:00
: wxFrame(NULL, -1, title, pos, size), _kiss(kiss), _accountPanel(NULL), _preferencesPanel(NULL), _curPanel(NULL),
2010-07-04 19:39:39 +02:00
_locale(NULL), _needReload(false)
{
2010-07-04 16:33:25 +02:00
_hbox = new wxBoxSizer(wxVERTICAL);
ButtonPanel* buttons = new ButtonPanel(_kiss, this);
// wxMenu *menuFile = new wxMenu;
2010-07-04 16:33:25 +02:00
// menuFile->Append( ID_About, wxT("&About...") );
// menuFile->AppendSeparator();
// menuFile->Append( ID_Quit, wxT("E&xit") );
2010-07-04 16:33:25 +02:00
// wxMenuBar *menuBar = new wxMenuBar;
// menuBar->Append( menuFile, wxT("&File") );
2010-07-04 16:33:25 +02:00
// SetMenuBar( menuBar );
2010-07-04 16:33:25 +02:00
// CreateStatusBar();
// SetStatusText( wxT("Welcome to wxWidgets!") );
2010-07-04 16:33:25 +02:00
SetSizer(_hbox);
2010-07-04 16:33:25 +02:00
_hbox->Add(buttons);
}
wxUI::~wxUI()
{
if (_accountPanel) delete _accountPanel;
2010-05-17 18:03:21 +02:00
if (_preferencesPanel) delete _preferencesPanel;
2010-07-04 19:39:39 +02:00
if (_locale) delete _locale;
}
2010-07-06 20:59:02 +02:00
bool wxUI::SetLanguage(long language)
2010-07-04 19:39:39 +02:00
{
bool res = true;
2010-07-04 19:39:39 +02:00
if (_locale) delete _locale;
2010-07-06 20:59:02 +02:00
_locale = NULL;
2010-07-04 19:39:39 +02:00
// load language if possible, fall back to english otherwise
if(wxLocale::IsAvailable(language))
{
_locale = new wxLocale( language, wxLOCALE_CONV_ENCODING );
#ifdef __WXGTK__
_locale->AddCatalogLookupPathPrefix(wxT("./ressources/po"));
#endif
_locale->AddCatalog(wxT("french"));
_locale->AddCatalog(wxT("kisscount"));
_language = (wxLanguage) language;
2010-07-04 19:39:39 +02:00
}
if (_locale == NULL || !_locale->IsOk())
2010-07-04 19:39:39 +02:00
{
if (_locale) delete _locale;
_locale = new wxLocale();
#ifdef __WXGTK__
_locale->AddCatalogLookupPathPrefix(wxT("./ressources/po"));
#endif
_locale->AddCatalog(wxT("kisscount"));
_language = wxLANGUAGE_ENGLISH;
res = false;
2010-07-04 19:39:39 +02:00
}
months[0] = _("january");
months[1] = _("february");
months[2] = _("march");
months[3] = _("april");
months[4] = _("may");
months[5] = _("june");
months[6] = _("july");
months[7] = _("august");
months[8] = _("september");
months[9] = _("october");
months[10] = _("november");
months[11] = _("december") ;
return res;
}
2010-05-17 18:03:21 +02:00
void wxUI::ShowAccount()
{
ShowPanel(_accountPanel);
}
void wxUI::ShowPreferences()
{
ShowPanel(_preferencesPanel);
}
void wxUI::ChangeUser()
{
UsersDialog u(_kiss, this);
u.ShowModal();
}
void wxUI::LoadUser()
{
User* user = _kiss->GetUser();
2010-07-04 16:33:25 +02:00
if (_curPanel)
{
2010-07-04 16:33:25 +02:00
_hbox->Detach(_curPanel);
_curPanel = NULL;
}
2010-05-17 18:03:21 +02:00
if (_accountPanel)
2010-07-04 16:33:25 +02:00
delete _accountPanel;
2010-05-17 18:03:21 +02:00
if (_preferencesPanel)
2010-07-04 16:33:25 +02:00
delete _preferencesPanel;
2010-05-17 18:03:21 +02:00
if (user->_preferences[wxT("language")] != wxT(""))
SetLanguage(user->GetLanguage());
2010-05-17 18:03:21 +02:00
_preferencesPanel = new PreferencesPanel(_kiss, this);
2010-06-27 21:39:49 +02:00
_accountPanel = new AccountPanel(_kiss, this);
2010-05-17 18:03:21 +02:00
ShowPanel(_accountPanel);
}
void wxUI::ShowPanel(wxPanel* panel)
{
int month, year, account=0, preferences=0;
wxShowEvent event;
2010-06-27 21:39:49 +02:00
2010-07-04 16:33:25 +02:00
if (!panel) return;
2010-05-17 18:03:21 +02:00
2010-07-04 16:33:25 +02:00
if (_curPanel)
2010-05-17 18:03:21 +02:00
{
2010-07-04 16:33:25 +02:00
_hbox->Detach(_curPanel);
_curPanel->Hide();
2010-05-17 18:03:21 +02:00
}
if (_needReload)
2010-07-04 16:33:25 +02:00
{
if (panel == _accountPanel)
{
account = 1;
month = _accountPanel->_curMonth;
year = _accountPanel->_curYear;
}
if (panel == _preferencesPanel)
{
preferences = 1;
}
delete _accountPanel;
delete _preferencesPanel;
_accountPanel = new AccountPanel(_kiss, this);
if (year != -1)
_accountPanel->ShowMonth(month, year);
_preferencesPanel = new PreferencesPanel(_kiss, this);
if (account)
{
_accountPanel->OnShow(event);
panel = _accountPanel;
}
if (preferences)
{
_preferencesPanel->OnShow(event);
panel = _preferencesPanel;
}
2010-07-04 16:33:25 +02:00
_needReload = false;
}
2010-06-27 21:39:49 +02:00
2010-05-17 18:03:21 +02:00
_curPanel = panel;
_hbox->Add(panel);
_curPanel->Show();
Layout();
}
2010-06-23 19:32:42 +02:00
void wxUI::GenerateMonth(int month, int year)
{
_accountPanel->GenerateMonth(month, year);
}
2010-06-27 21:39:49 +02:00
void wxUI::KillMe()
{
2010-07-04 16:33:25 +02:00
if (_curPanel)
2010-06-27 21:39:49 +02:00
{
2010-07-04 16:33:25 +02:00
_hbox->Detach(_curPanel);
_curPanel = NULL;
2010-06-27 21:39:49 +02:00
}
if (_accountPanel)
2010-07-04 16:33:25 +02:00
delete _accountPanel;
2010-06-27 21:39:49 +02:00
if (_preferencesPanel)
2010-07-04 16:33:25 +02:00
delete _preferencesPanel;
2010-06-27 21:39:49 +02:00
_accountPanel = NULL;
_preferencesPanel = NULL;
}
void wxUI::NeedReload()
{
_needReload = true;
}