2010-07-10 16:34:30 +02:00
|
|
|
/*
|
2010-08-26 21:28:15 +02:00
|
|
|
Copyright 2010 Grégory Soutadé
|
2010-07-10 16:34:30 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
This file is part of KissCount.
|
2010-07-10 16:34:30 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
KissCount is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2010-07-10 16:34:30 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
KissCount is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2010-07-10 16:34:30 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
|
2010-07-10 16:34:30 +02:00
|
|
|
*/
|
|
|
|
|
2010-05-14 15:04:01 +02:00
|
|
|
#include "wxUI.h"
|
|
|
|
|
2010-07-04 19:39:39 +02:00
|
|
|
wxString months[12] ;
|
2010-08-17 18:59:19 +02:00
|
|
|
wxColour categoryColors[12] = {wxColour(0x00, 0x45, 0x86),
|
|
|
|
wxColour(0xFF, 0x3E, 0x0E),
|
|
|
|
wxColour(0xFF, 0xD3, 0x20),
|
|
|
|
wxColour(0x58, 0x9D, 0x1B),
|
|
|
|
wxColour(0x7E, 0x00, 0x21),
|
|
|
|
wxColour(0x83, 0xCC, 0xFF),
|
|
|
|
wxColour(0x31, 0x40, 0x04),
|
|
|
|
wxColour(0xB0, 0xCF, 0x00),
|
|
|
|
wxColour(0x4B, 0x1F, 0x6F),
|
|
|
|
wxColour(0xFF, 0x93, 0x0E),
|
|
|
|
wxColour(0xC5, 0x00, 0x0D),
|
|
|
|
wxColour(0x00, 0x84, 0xD1)};
|
2010-05-16 10:35:34 +02:00
|
|
|
|
2010-05-14 15:04:01 +02:00
|
|
|
wxUI::wxUI(KissCount* kiss, const wxString& title, const wxPoint& pos, const wxSize& size)
|
2010-08-29 09:29:34 +02:00
|
|
|
: wxFrame(NULL, wxID_ANY, title, pos, size), _kiss(kiss), _buttonPanel(NULL), _accountPanel(NULL), _statsPanel(NULL),
|
2010-08-26 21:28:15 +02:00
|
|
|
_searchPanel(NULL), _preferencesPanel(NULL), _curPanel(NULL), _locale(NULL), _needReload(false)
|
2010-05-14 15:04:01 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_hbox = new wxBoxSizer(wxVERTICAL);
|
2010-08-29 09:29:34 +02:00
|
|
|
_buttonPanel = new ButtonPanel(_kiss, this);
|
2010-08-26 21:28:15 +02:00
|
|
|
// wxMenu *menuFile = new wxMenu;
|
2010-05-14 15:04:01 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
// menuFile->Append( ID_About, wxT("&About...") );
|
|
|
|
// menuFile->AppendSeparator();
|
|
|
|
// menuFile->Append( ID_Quit, wxT("E&xit") );
|
2010-05-14 15:04:01 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
// wxMenuBar *menuBar = new wxMenuBar;
|
|
|
|
// menuBar->Append( menuFile, wxT("&File") );
|
2010-05-14 15:04:01 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
// SetMenuBar( menuBar );
|
2010-05-14 15:04:01 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
// CreateStatusBar();
|
|
|
|
// SetStatusText( wxT("Welcome to wxWidgets!") );
|
2010-05-14 15:04:01 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
SetSizer(_hbox);
|
2010-05-14 15:04:01 +02:00
|
|
|
|
2010-08-29 09:29:34 +02:00
|
|
|
_hbox->Add(_buttonPanel);
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
wxUI::~wxUI()
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_accountPanel) delete _accountPanel;
|
|
|
|
if (_preferencesPanel) delete _preferencesPanel;
|
|
|
|
if (_searchPanel) delete _searchPanel;
|
|
|
|
if (_statsPanel) delete _statsPanel;
|
|
|
|
if (_locale) delete _locale;
|
2010-07-04 19:39:39 +02:00
|
|
|
}
|
|
|
|
|
2010-07-06 20:59:02 +02:00
|
|
|
bool wxUI::SetLanguage(long language)
|
2010-07-04 19:39:39 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
bool res = true;
|
2010-07-07 21:04:38 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_locale) delete _locale;
|
|
|
|
_locale = NULL;
|
2010-07-04 19:39:39 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
// load language if possible, fall back to english otherwise
|
|
|
|
if(wxLocale::IsAvailable(language))
|
2010-07-04 19:39:39 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_locale = new wxLocale( language, wxLOCALE_CONV_ENCODING );
|
2010-07-04 19:39:39 +02:00
|
|
|
|
|
|
|
#ifdef __WXGTK__
|
2010-08-26 21:28:15 +02:00
|
|
|
_locale->AddCatalogLookupPathPrefix(wxT("./ressources/po"));
|
2010-07-04 19:39:39 +02:00
|
|
|
#endif
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_locale->AddCatalog(wxT("french"));
|
|
|
|
_locale->AddCatalog(wxT("kisscount"));
|
2010-07-07 21:04:38 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_language = (wxLanguage) language;
|
2010-07-04 19:39:39 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_locale == NULL || !_locale->IsOk())
|
2010-07-04 19:39:39 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_locale) delete _locale;
|
|
|
|
_locale = new wxLocale();
|
2010-07-07 21:04:38 +02:00
|
|
|
|
|
|
|
#ifdef __WXGTK__
|
2010-08-26 21:28:15 +02:00
|
|
|
_locale->AddCatalogLookupPathPrefix(wxT("./ressources/po"));
|
2010-07-07 21:04:38 +02:00
|
|
|
#endif
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_locale->AddCatalog(wxT("kisscount"));
|
2010-07-07 21:04:38 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_language = wxLANGUAGE_ENGLISH;
|
|
|
|
res = false;
|
2010-07-04 19:39:39 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +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") ;
|
|
|
|
|
2010-08-29 09:29:34 +02:00
|
|
|
if (_buttonPanel)
|
|
|
|
_buttonPanel->SetToolTips();
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
return res;
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
|
|
|
|
2010-05-17 18:03:21 +02:00
|
|
|
void wxUI::ShowAccount()
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
ShowPanel(_accountPanel);
|
2010-05-17 18:03:21 +02:00
|
|
|
}
|
|
|
|
|
2010-07-14 11:15:48 +02:00
|
|
|
void wxUI::ShowSearch()
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
ShowPanel(_searchPanel);
|
2010-07-14 11:15:48 +02:00
|
|
|
}
|
|
|
|
|
2010-08-17 18:59:19 +02:00
|
|
|
void wxUI::ShowStats()
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
ShowPanel(_statsPanel);
|
2010-08-17 18:59:19 +02:00
|
|
|
}
|
|
|
|
|
2010-05-17 18:03:21 +02:00
|
|
|
void wxUI::ShowPreferences()
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
ShowPanel(_preferencesPanel);
|
2010-05-17 18:03:21 +02:00
|
|
|
}
|
|
|
|
|
2010-05-14 15:04:01 +02:00
|
|
|
void wxUI::ChangeUser()
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
UsersDialog u(_kiss, this);
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void wxUI::LoadUser()
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
User* user = _kiss->GetUser();
|
|
|
|
wxShowEvent event;
|
2010-07-07 21:04:38 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_curPanel)
|
2010-05-14 15:04:01 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_hbox->Detach(_curPanel);
|
|
|
|
_curPanel = NULL;
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
2010-05-17 18:03:21 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_accountPanel)
|
|
|
|
delete _accountPanel;
|
2010-05-17 18:03:21 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_preferencesPanel)
|
|
|
|
delete _preferencesPanel;
|
2010-05-17 18:03:21 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_searchPanel)
|
|
|
|
delete _searchPanel;
|
2010-07-14 11:15:48 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_statsPanel)
|
|
|
|
delete _statsPanel;
|
2010-08-17 18:59:19 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (user->_preferences[wxT("language")].Length())
|
|
|
|
SetLanguage(user->GetLanguage());
|
2010-07-07 21:04:38 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_accountPanel = new AccountPanel(_kiss, this);
|
|
|
|
_statsPanel = new StatsPanel(_kiss, this);
|
|
|
|
_searchPanel = new SearchPanel(_kiss, this);
|
|
|
|
_preferencesPanel = new PreferencesPanel(_kiss, this);
|
2010-05-17 18:03:21 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
ShowPanel(_accountPanel);
|
|
|
|
_accountPanel->OnShow(event);
|
2010-05-17 18:03:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void wxUI::ShowPanel(wxPanel* panel)
|
|
|
|
{
|
2010-09-04 11:54:49 +02:00
|
|
|
int month, year=-1, account=0, preferences=0, search=0, stats=0;
|
2010-08-26 21:28:15 +02:00
|
|
|
wxShowEvent event;
|
2010-06-27 21:39:49 +02:00
|
|
|
|
2010-09-22 21:02:29 +02:00
|
|
|
if (!panel || (panel == _curPanel && !_needReload)) return;
|
2010-05-17 18:03:21 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_curPanel)
|
2010-05-17 18:03:21 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_hbox->Detach(_curPanel);
|
|
|
|
_curPanel->Hide();
|
2010-05-17 18:03:21 +02:00
|
|
|
}
|
2010-07-07 21:04:38 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_needReload)
|
2010-07-04 16:33:25 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
if (panel == _accountPanel)
|
2010-07-07 21:04:38 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
account = 1;
|
|
|
|
month = _accountPanel->_curMonth;
|
|
|
|
year = _accountPanel->_curYear;
|
2010-07-07 21:04:38 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (panel == _preferencesPanel)
|
2010-07-07 21:04:38 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
preferences = 1;
|
2010-07-07 21:04:38 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (panel == _searchPanel)
|
2010-07-14 11:15:48 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
search = 1;
|
2010-07-14 11:15:48 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (panel == _statsPanel)
|
2010-08-17 18:59:19 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
stats = 1;
|
2010-08-17 18:59:19 +02:00
|
|
|
}
|
|
|
|
|
2010-07-07 21:04:38 +02:00
|
|
|
delete _accountPanel;
|
|
|
|
delete _preferencesPanel;
|
2010-07-14 11:15:48 +02:00
|
|
|
delete _searchPanel;
|
2010-08-17 18:59:19 +02:00
|
|
|
delete _statsPanel;
|
2010-07-07 21:04:38 +02:00
|
|
|
|
|
|
|
_accountPanel = new AccountPanel(_kiss, this);
|
|
|
|
if (year != -1)
|
2010-08-26 21:28:15 +02:00
|
|
|
{
|
2010-07-16 19:28:36 +02:00
|
|
|
_kiss->LoadYear(year, true);
|
|
|
|
_accountPanel->ShowMonth(month, year);
|
2010-08-26 21:28:15 +02:00
|
|
|
}
|
2010-07-07 21:04:38 +02:00
|
|
|
_preferencesPanel = new PreferencesPanel(_kiss, this);
|
2010-07-14 11:15:48 +02:00
|
|
|
_searchPanel = new SearchPanel(_kiss, this);
|
2010-08-17 18:59:19 +02:00
|
|
|
_statsPanel = new StatsPanel(_kiss, this);
|
2010-07-07 21:04:38 +02:00
|
|
|
|
|
|
|
if (account)
|
2010-08-26 21:28:15 +02:00
|
|
|
{
|
2010-07-07 21:04:38 +02:00
|
|
|
_accountPanel->OnShow(event);
|
|
|
|
panel = _accountPanel;
|
2010-08-26 21:28:15 +02:00
|
|
|
}
|
2010-08-17 18:59:19 +02:00
|
|
|
else if (preferences)
|
2010-08-26 21:28:15 +02:00
|
|
|
{
|
2010-07-07 21:04:38 +02:00
|
|
|
_preferencesPanel->OnShow(event);
|
|
|
|
panel = _preferencesPanel;
|
2010-08-26 21:28:15 +02:00
|
|
|
}
|
2010-08-17 18:59:19 +02:00
|
|
|
else if (search)
|
2010-08-26 21:28:15 +02:00
|
|
|
{
|
2010-07-14 11:15:48 +02:00
|
|
|
_searchPanel->OnShow(event);
|
|
|
|
panel = _searchPanel;
|
2010-08-26 21:28:15 +02:00
|
|
|
}
|
2010-08-17 18:59:19 +02:00
|
|
|
else if (stats)
|
2010-08-26 21:28:15 +02:00
|
|
|
{
|
2010-08-17 18:59:19 +02:00
|
|
|
_statsPanel->OnShow(event);
|
|
|
|
panel = _statsPanel;
|
2010-08-26 21:28:15 +02:00
|
|
|
}
|
2010-07-14 11:15:48 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_needReload = false;
|
2010-07-04 16:33:25 +02:00
|
|
|
}
|
2010-06-27 21:39:49 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_curPanel = panel;
|
|
|
|
_hbox->Add(panel);
|
|
|
|
_curPanel->Show();
|
|
|
|
Layout();
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
2010-06-23 19:32:42 +02:00
|
|
|
|
|
|
|
void wxUI::GenerateMonth(int month, int year)
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_accountPanel->GenerateMonth(month, year);
|
2010-06-23 19:32:42 +02:00
|
|
|
}
|
2010-06-27 21:39:49 +02:00
|
|
|
|
|
|
|
void wxUI::KillMe()
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_curPanel)
|
2010-06-27 21:39:49 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_hbox->Detach(_curPanel);
|
|
|
|
_curPanel = NULL;
|
2010-06-27 21:39:49 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_accountPanel)
|
|
|
|
delete _accountPanel;
|
2010-06-27 21:39:49 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_preferencesPanel)
|
|
|
|
delete _preferencesPanel;
|
2010-06-27 21:39:49 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_searchPanel)
|
|
|
|
delete _searchPanel;
|
2010-07-14 11:15:48 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_accountPanel = NULL;
|
|
|
|
_preferencesPanel = NULL;
|
|
|
|
_searchPanel = NULL;
|
2010-06-27 21:39:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void wxUI::NeedReload()
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_needReload = true;
|
2010-06-27 21:39:49 +02:00
|
|
|
}
|