2011-12-18 13:51:04 +01:00
/*
2012-02-01 11:02:54 +01:00
Copyright 2010 - 2012 Grégory Soutadé
2011-12-18 13:51:04 +01:00
This file is part of KissCount .
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 .
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 .
You should have received a copy of the GNU General Public License
along with KissCount . If not , see < http : //www.gnu.org/licenses/>.
*/
2012-01-07 09:21:22 +01:00
# include "PasswordDialog.hpp"
2011-12-18 13:51:04 +01:00
# include "PreferencesPanel.hpp"
# include "grid/StarDelegate.hpp"
2012-02-01 12:43:43 +01:00
enum { ACCOUNT_NAME , ACCOUNT_NUMBER , ACCOUNT_DEFAULT , ACCOUNT_VIRTUAL , ACCOUNT_BLOCKED , ACCOUNT_DELETE , ACCOUNT_HIDDEN , NUMBER_COLS_ACCOUNT } ;
2011-12-18 13:51:04 +01:00
enum { CATEGORY_NAME , CATEGORY_BACKGROUND_COLOR , CATEGORY_FOREGROUND_COLOR , CATEGORY_FONT , CATEGORY_DELETE , NUMBER_COLS_CATEGORY } ;
PreferencesPanel : : PreferencesPanel ( KissCount * kiss , wxUI * parent ) : KissPanel ( kiss , parent ) , _sharedWith ( 0 ) , _curAccountRow ( - 1 ) , _defaultSignalMapper ( this ) , _virtualSignalMapper ( this ) , _blockedSignalMapper ( this ) , _deleteAccountSignalMapper ( this ) , _deleteCategorySignalMapper ( this ) , _backgroundColorSignalMapper ( this ) , _foregroundColorSignalMapper ( this ) , _fontSignalMapper ( this ) , _inModification ( false )
{
QVBoxLayout * vbox = new QVBoxLayout ;
QHBoxLayout * hbox1 = new QHBoxLayout ;
QHBoxLayout * hbox2 = new QHBoxLayout ;
//QHBoxLayout *hbox = new QHBoxLayout;
QGroupBox * staticUser , * staticAccount , * staticCategories , * staticLanguage , * staticOperationOrder , * staticSharedWith ;
User * user = _kiss - > GetUser ( ) ;
QGridLayout * gridBagSizer ;
QLabel * label ;
QPushButton * buttonChangeName , * buttonChangePassword , * killMe ;
QVBoxLayout * staticBoxSizer ;
std : : list < QString > users ;
std : : list < QString > : : iterator it ;
setLayout ( vbox ) ;
staticUser = new QGroupBox ( _ ( " User " ) ) ;
staticAccount = new QGroupBox ( _ ( " Accounts " ) ) ;
staticCategories = new QGroupBox ( _ ( " Categories " ) ) ;
staticLanguage = new QGroupBox ( _ ( " Language " ) ) ;
staticOperationOrder = new QGroupBox ( _ ( " Operation order " ) ) ;
staticSharedWith = new QGroupBox ( _ ( " Shared with " ) ) ;
// User
staticBoxSizer = new QVBoxLayout ( ) ;
staticUser - > setLayout ( staticBoxSizer ) ;
gridBagSizer = new QGridLayout ( ) ;
label = new QLabel ( _ ( " Name " ) ) ;
gridBagSizer - > addWidget ( label , 0 , 0 ) ;
_name = new QLineEdit ( user - > _name ) ;
gridBagSizer - > addWidget ( _name , 0 , 1 ) ;
buttonChangeName = new QPushButton ( _ ( " Change Name " ) ) ;
buttonChangePassword = new QPushButton ( _ ( " Change Password " ) ) ;
killMe = new QPushButton ( _ ( " Kill me " ) ) ;
gridBagSizer - > addWidget ( buttonChangeName , 1 , 0 ) ;
gridBagSizer - > addWidget ( buttonChangePassword , 1 , 1 ) ;
gridBagSizer - > addWidget ( killMe , 1 , 2 ) ;
staticBoxSizer - > addLayout ( gridBagSizer ) ;
vbox - > addWidget ( staticUser ) ;
connect ( buttonChangeName , SIGNAL ( clicked ( ) ) , this , SLOT ( OnChangeName ( ) ) ) ;
connect ( buttonChangePassword , SIGNAL ( clicked ( ) ) , this , SLOT ( OnChangePassword ( ) ) ) ;
connect ( killMe , SIGNAL ( clicked ( ) ) , this , SLOT ( OnKillMe ( ) ) ) ;
// Account
staticBoxSizer = new QVBoxLayout ( ) ;
staticAccount - > setLayout ( staticBoxSizer ) ;
_accountsGrid = new QTableWidget ( ) ;
StarDelegate * starDelegate = new StarDelegate ( this , & user - > _accounts ) ;
_accountsGrid - > setItemDelegateForColumn ( ACCOUNT_NUMBER , starDelegate ) ;
InitAccounts ( user ) ;
connect ( _accountsGrid , SIGNAL ( cellChanged ( int , int ) ) , this , SLOT ( OnAccountModified ( int , int ) ) ) ;
connect ( _accountsGrid , SIGNAL ( currentCellChanged ( int , int , int , int ) ) , this , SLOT ( OnAccountCellChanged ( int , int , int , int ) ) ) ;
staticBoxSizer - > addWidget ( _accountsGrid ) ;
hbox1 - > addWidget ( staticAccount ) ;
staticBoxSizer = new QVBoxLayout ( ) ;
staticSharedWith - > setLayout ( staticBoxSizer ) ;
_sharedWith = new QListWidget ( ) ;
users = _kiss - > GetUsers ( ) ;
QListWidgetItem * item ;
for ( it = users . begin ( ) ; it ! = users . end ( ) ; it + + )
{
if ( * it ! = user - > _name )
{
item = new QListWidgetItem ( * it ) ;
item - > setCheckState ( Qt : : Unchecked ) ;
_sharedWith - > addItem ( item ) ;
}
}
_sharedWith - > setEnabled ( false ) ;
connect ( _sharedWith , SIGNAL ( itemChanged ( QListWidgetItem * ) ) , this , SLOT ( OnSharedChange ( QListWidgetItem * ) ) ) ;
staticBoxSizer - > addWidget ( _sharedWith ) ;
hbox1 - > addWidget ( staticSharedWith ) ;
vbox - > addLayout ( hbox1 ) ;
// Categories
staticBoxSizer = new QVBoxLayout ( ) ;
staticCategories - > setLayout ( staticBoxSizer ) ;
_categoriesGrid = new QTableWidget ( ) ;
staticBoxSizer - > addWidget ( _categoriesGrid ) ;
InitCategories ( user ) ;
2012-01-07 09:21:22 +01:00
connect ( _categoriesGrid , SIGNAL ( cellChanged ( int , int ) ) , this , SLOT ( OnCategoryModified ( int , int ) ) ) ;
2011-12-18 13:51:04 +01:00
vbox - > addWidget ( staticCategories ) ;
// Operation Order
staticBoxSizer = new QVBoxLayout ( ) ;
staticOperationOrder - > setLayout ( staticBoxSizer ) ;
_operationOrder = new QComboBox ( ) ;
//_operationOrder->SetWindowStyle(wxCB_READONLY);
InitOperationOrder ( user ) ;
staticBoxSizer - > addWidget ( _operationOrder ) ;
hbox2 - > addWidget ( staticOperationOrder ) ;
connect ( _operationOrder , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( OnOperationOrderChange ( int ) ) ) ;
// Language
staticBoxSizer = new QVBoxLayout ( ) ;
staticLanguage - > setLayout ( staticBoxSizer ) ;
_language = new QListWidget ( ) ;
//_language->SetWindowStyle(wxCB_READONLY);
2012-02-11 12:48:19 +01:00
connect ( _language , SIGNAL ( currentRowChanged ( int ) ) , this , SLOT ( OnLanguageChange ( int ) ) ) ;
2011-12-18 13:51:04 +01:00
staticBoxSizer - > addWidget ( _language ) ;
hbox2 - > addWidget ( staticLanguage ) ;
vbox - > addLayout ( hbox2 ) ;
connect ( & _defaultSignalMapper , SIGNAL ( mapped ( int ) ) , this , SLOT ( OnAccountDefaultClicked ( int ) ) ) ;
connect ( & _virtualSignalMapper , SIGNAL ( mapped ( int ) ) , this , SLOT ( OnAccountVirtualClicked ( int ) ) ) ;
connect ( & _blockedSignalMapper , SIGNAL ( mapped ( int ) ) , this , SLOT ( OnAccountBlockedClicked ( int ) ) ) ;
connect ( & _deleteAccountSignalMapper , SIGNAL ( mapped ( int ) ) , this , SLOT ( OnAccountDeleteClicked ( int ) ) ) ;
2012-02-01 12:43:43 +01:00
connect ( & _hiddenAccountSignalMapper , SIGNAL ( mapped ( int ) ) , this , SLOT ( OnAccountHiddenClicked ( int ) ) ) ;
2011-12-18 13:51:04 +01:00
connect ( & _deleteCategorySignalMapper , SIGNAL ( mapped ( int ) ) , this , SLOT ( OnCategoryDeleteClicked ( int ) ) ) ;
connect ( & _backgroundColorSignalMapper , SIGNAL ( mapped ( int ) ) , this , SLOT ( OnBackgroundColorClicked ( int ) ) ) ;
connect ( & _foregroundColorSignalMapper , SIGNAL ( mapped ( int ) ) , this , SLOT ( OnForegroundClicked ( int ) ) ) ;
connect ( & _fontSignalMapper , SIGNAL ( mapped ( int ) ) , this , SLOT ( OnFontClicked ( int ) ) ) ;
layout ( ) ;
}
KissPanel * PreferencesPanel : : CreatePanel ( )
{
return new PreferencesPanel ( _kiss , _wxUI ) ;
}
QPushButton * PreferencesPanel : : GetButton ( )
{
if ( ! _KissButton )
{
_KissButton = new QPushButton ( QIcon ( PREFS_ICON ) , " " , this ) ;
_KissButton - > setFixedSize ( 128 , 128 ) ;
_KissButton - > setIconSize ( QSize ( 128 , 128 ) ) ;
}
return _KissButton ;
}
QString PreferencesPanel : : GetToolTip ( )
{
return _ ( " Preferences " ) ;
}
void PreferencesPanel : : InitAccounts ( User * user )
{
std : : vector < Account > : : iterator it ;
int curLine = 0 ;
Account account ;
DEFAULT_FONT ( font ) ;
_accountsGrid - > setColumnCount ( NUMBER_COLS_ACCOUNT ) ;
_accountsGrid - > verticalHeader ( ) - > setHidden ( true ) ;
_accountsGrid - > setFont ( font ) ;
_accountsGrid - > setHorizontalHeaderItem ( ACCOUNT_NAME , new QTableWidgetItem ( _ ( " Name " ) ) ) ;
_accountsGrid - > setHorizontalHeaderItem ( ACCOUNT_NUMBER , new QTableWidgetItem ( _ ( " Number " ) ) ) ;
_accountsGrid - > setHorizontalHeaderItem ( ACCOUNT_DEFAULT , new QTableWidgetItem ( _ ( " Default " ) ) ) ;
_accountsGrid - > setHorizontalHeaderItem ( ACCOUNT_VIRTUAL , new QTableWidgetItem ( _ ( " Virtual " ) ) ) ;
_accountsGrid - > setHorizontalHeaderItem ( ACCOUNT_BLOCKED , new QTableWidgetItem ( _ ( " Blocked " ) ) ) ;
_accountsGrid - > setHorizontalHeaderItem ( ACCOUNT_DELETE , new QTableWidgetItem ( _ ( " Delete " ) ) ) ;
2012-02-01 12:43:43 +01:00
_accountsGrid - > setHorizontalHeaderItem ( ACCOUNT_HIDDEN , new QTableWidgetItem ( _ ( " Hidden " ) ) ) ;
2011-12-18 13:51:04 +01:00
font . setBold ( true ) ;
for ( int i = 0 ; i < NUMBER_COLS_ACCOUNT ; i + + )
{
_accountsGrid - > horizontalHeaderItem ( i ) - > setFont ( font ) ;
}
_accountsGrid - > setRowCount ( user - > GetAccountsNumber ( ) + 1 ) ;
for ( it = user - > _accounts . begin ( ) ; it ! = user - > _accounts . end ( ) ; it + + , curLine + + )
{
AddAccount ( curLine , * it ) ;
}
account . id = 0 ;
AddAccount ( curLine , account ) ;
}
# define SET_READ_ONLY(row, line) _accountsGrid->item(row, line)->setFlags(_accountsGrid->item(row, line)->flags() & ~Qt::ItemIsEditable);
void PreferencesPanel : : AddAccount ( int line , Account ac )
{
QCheckBox * checkBox ;
if ( ac . id ! = 0 )
{
_accountsGrid - > setItem ( line , ACCOUNT_NAME , new QTableWidgetItem ( ac . name ) ) ;
if ( ac . shared )
_accountsGrid - > setItem ( line , ACCOUNT_NUMBER , new QTableWidgetItem ( ac . number + " * " ) ) ;
else
_accountsGrid - > setItem ( line , ACCOUNT_NUMBER , new QTableWidgetItem ( ac . number ) ) ;
checkBox = new QCheckBox ( ) ;
checkBox - > setCheckState ( ( ac . _default ) ? Qt : : Checked : Qt : : Unchecked ) ;
_accountsGrid - > setCellWidget ( line , ACCOUNT_DEFAULT , checkBox ) ;
_defaultSignalMapper . setMapping ( checkBox , ac . id ) ;
connect ( checkBox , SIGNAL ( stateChanged ( int ) ) , & _defaultSignalMapper , SLOT ( map ( ) ) ) ;
checkBox = new QCheckBox ( ) ;
checkBox - > setCheckState ( ( ac . _virtual ) ? Qt : : Checked : Qt : : Unchecked ) ;
_accountsGrid - > setCellWidget ( line , ACCOUNT_VIRTUAL , checkBox ) ;
_virtualSignalMapper . setMapping ( checkBox , ac . id ) ;
connect ( checkBox , SIGNAL ( stateChanged ( int ) ) , & _virtualSignalMapper , SLOT ( map ( ) ) ) ;
checkBox = new QCheckBox ( ) ;
checkBox - > setCheckState ( ( ac . blocked ) ? Qt : : Checked : Qt : : Unchecked ) ;
_accountsGrid - > setCellWidget ( line , ACCOUNT_BLOCKED , checkBox ) ;
_blockedSignalMapper . setMapping ( checkBox , ac . id ) ;
connect ( checkBox , SIGNAL ( stateChanged ( int ) ) , & _blockedSignalMapper , SLOT ( map ( ) ) ) ;
checkBox = new QCheckBox ( ) ;
checkBox - > setCheckState ( Qt : : Unchecked ) ;
_accountsGrid - > setCellWidget ( line , ACCOUNT_DELETE , checkBox ) ;
_deleteAccountSignalMapper . setMapping ( checkBox , ac . id ) ;
connect ( checkBox , SIGNAL ( stateChanged ( int ) ) , & _deleteAccountSignalMapper , SLOT ( map ( ) ) ) ;
2012-02-01 12:43:43 +01:00
checkBox = new QCheckBox ( ) ;
checkBox - > setCheckState ( ( ac . hidden ) ? Qt : : Checked : Qt : : Unchecked ) ;
_accountsGrid - > setCellWidget ( line , ACCOUNT_HIDDEN , checkBox ) ;
_hiddenAccountSignalMapper . setMapping ( checkBox , ac . id ) ;
connect ( checkBox , SIGNAL ( stateChanged ( int ) ) , & _hiddenAccountSignalMapper , SLOT ( map ( ) ) ) ;
2011-12-18 13:51:04 +01:00
for ( int i = 0 ; i < NUMBER_COLS_ACCOUNT ; i + + )
if ( ! _accountsGrid - > item ( line , i ) )
_accountsGrid - > setItem ( line , i , new QTableWidgetItem ( " " ) ) ;
// _accountsGrid->SetCellAlignment(line, ACCOUNT_DEFAULT, wxALIGN_CENTRE, wxALIGN_CENTRE);
// _accountsGrid->SetCellAlignment(line, ACCOUNT_VIRTUAL, wxALIGN_CENTRE, wxALIGN_CENTRE);
// _accountsGrid->SetCellAlignment(line, ACCOUNT_BLOCKED, wxALIGN_CENTRE, wxALIGN_CENTRE);
// _accountsGrid->SetCellAlignment(line, ACCOUNT_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE);
if ( ! ac . is_owner )
{
SET_READ_ONLY ( line , ACCOUNT_NAME ) ;
SET_READ_ONLY ( line , ACCOUNT_NUMBER ) ;
SET_READ_ONLY ( line , ACCOUNT_DEFAULT ) ;
SET_READ_ONLY ( line , ACCOUNT_VIRTUAL ) ;
SET_READ_ONLY ( line , ACCOUNT_BLOCKED ) ;
2012-02-01 12:43:43 +01:00
SET_READ_ONLY ( line , ACCOUNT_HIDDEN ) ;
2011-12-18 13:51:04 +01:00
}
else
{
SET_READ_ONLY ( line , ACCOUNT_DEFAULT ) ;
SET_READ_ONLY ( line , ACCOUNT_VIRTUAL ) ;
SET_READ_ONLY ( line , ACCOUNT_BLOCKED ) ;
SET_READ_ONLY ( line , ACCOUNT_DELETE ) ;
}
}
else
{
for ( int i = 0 ; i < NUMBER_COLS_ACCOUNT ; i + + )
if ( ! _accountsGrid - > item ( line , i ) )
_accountsGrid - > setItem ( line , i , new QTableWidgetItem ( " " ) ) ;
SET_READ_ONLY ( line , ACCOUNT_DEFAULT ) ;
SET_READ_ONLY ( line , ACCOUNT_VIRTUAL ) ;
SET_READ_ONLY ( line , ACCOUNT_BLOCKED ) ;
SET_READ_ONLY ( line , ACCOUNT_DELETE ) ;
2012-02-01 12:43:43 +01:00
SET_READ_ONLY ( line , ACCOUNT_HIDDEN ) ;
2011-12-18 13:51:04 +01:00
}
_accountsGrid - > resizeColumnsToContents ( ) ;
}
# undef SET_READ_ONLY
# define SET_READ_ONLY(row, line) _categoriesGrid->item(row, line)->setFlags(_categoriesGrid->item(row, line)->flags() & ~Qt::ItemIsEditable);
# define SET_ROW_COLOR(row, backcolor, forecolor) \
for ( int i = 0 ; i < NUMBER_COLS_CATEGORY ; i + + ) \
{ \
_categoriesGrid - > item ( row , i ) - > setBackground ( QBrush ( backcolor ) ) ; \
_categoriesGrid - > item ( row , i ) - > setForeground ( QBrush ( forecolor ) ) ; \
}
# define SET_ROW_FONT(row, font) \
for ( int i = 0 ; i < NUMBER_COLS_CATEGORY ; i + + ) \
{ \
_categoriesGrid - > item ( row , i ) - > setFont ( font ) ; \
}
void PreferencesPanel : : InitCategories ( User * user )
{
std : : vector < Category > : : iterator it ;
int curLine = 0 ;
DEFAULT_FONT ( font ) ;
Category cat ;
_categoriesGrid - > setColumnCount ( NUMBER_COLS_CATEGORY ) ;
_categoriesGrid - > verticalHeader ( ) - > setHidden ( true ) ;
_categoriesGrid - > setFont ( font ) ;
_categoriesGrid - > setHorizontalHeaderItem ( CATEGORY_NAME , new QTableWidgetItem ( _ ( " Name " ) ) ) ;
_categoriesGrid - > setHorizontalHeaderItem ( CATEGORY_BACKGROUND_COLOR , new QTableWidgetItem ( _ ( " Background color " ) ) ) ;
_categoriesGrid - > setHorizontalHeaderItem ( CATEGORY_FOREGROUND_COLOR , new QTableWidgetItem ( _ ( " Foreground color " ) ) ) ;
_categoriesGrid - > setHorizontalHeaderItem ( CATEGORY_FONT , new QTableWidgetItem ( _ ( " Font " ) ) ) ;
_categoriesGrid - > setHorizontalHeaderItem ( CATEGORY_DELETE , new QTableWidgetItem ( _ ( " Delete " ) ) ) ;
_categoriesGrid - > setRowCount ( user - > GetCategoriesNumber ( ) + 1 ) ;
font . setBold ( true ) ;
for ( int i = 0 ; i < NUMBER_COLS_CATEGORY ; i + + )
{
_categoriesGrid - > horizontalHeaderItem ( i ) - > setFont ( font ) ;
}
for ( it = user - > _categories . begin ( ) ; it ! = user - > _categories . end ( ) ; it + + , curLine + + )
{
AddCategory ( curLine , * it ) ;
}
for ( int i = 0 ; i < NUMBER_COLS_CATEGORY ; i + + )
if ( ! _categoriesGrid - > item ( curLine , i ) )
_categoriesGrid - > setItem ( curLine , i , new QTableWidgetItem ( " " ) ) ;
2012-01-07 09:21:22 +01:00
SET_READ_ONLY ( curLine , CATEGORY_BACKGROUND_COLOR ) ;
SET_READ_ONLY ( curLine , CATEGORY_FOREGROUND_COLOR ) ;
SET_READ_ONLY ( curLine , CATEGORY_FONT ) ;
2011-12-18 13:51:04 +01:00
SET_READ_ONLY ( curLine , CATEGORY_DELETE ) ;
cat . id = 0 ;
AddCategory ( curLine , cat ) ;
}
void PreferencesPanel : : AddCategory ( int line , Category cat )
{
User * user = _kiss - > GetUser ( ) ;
QCheckBox * checkBox ;
QPushButton * button ;
if ( cat . id ! = 0 )
{
_categoriesGrid - > setItem ( line , CATEGORY_NAME , new QTableWidgetItem ( _ ( cat . name . toStdString ( ) . c_str ( ) ) ) ) ;
if ( line )
{
checkBox = new QCheckBox ( ) ;
checkBox - > setCheckState ( Qt : : Unchecked ) ;
_categoriesGrid - > setCellWidget ( line , CATEGORY_DELETE , checkBox ) ;
_deleteCategorySignalMapper . setMapping ( checkBox , cat . id ) ;
connect ( checkBox , SIGNAL ( stateChanged ( int ) ) , & _deleteCategorySignalMapper , SLOT ( map ( ) ) ) ;
}
button = new QPushButton ( " ... " ) ;
_categoriesGrid - > setCellWidget ( line , CATEGORY_BACKGROUND_COLOR , button ) ;
_backgroundColorSignalMapper . setMapping ( button , cat . id ) ;
connect ( button , SIGNAL ( clicked ( ) ) , & _backgroundColorSignalMapper , SLOT ( map ( ) ) ) ;
button = new QPushButton ( " ... " ) ;
_categoriesGrid - > setCellWidget ( line , CATEGORY_FOREGROUND_COLOR , button ) ;
_foregroundColorSignalMapper . setMapping ( button , cat . id ) ;
connect ( button , SIGNAL ( clicked ( ) ) , & _foregroundColorSignalMapper , SLOT ( map ( ) ) ) ;
button = new QPushButton ( " ... " ) ;
_categoriesGrid - > setCellWidget ( line , CATEGORY_FONT , button ) ;
_fontSignalMapper . setMapping ( button , cat . id ) ;
connect ( button , SIGNAL ( clicked ( ) ) , & _fontSignalMapper , SLOT ( map ( ) ) ) ;
for ( int i = 0 ; i < NUMBER_COLS_CATEGORY ; i + + )
2012-04-30 21:22:52 +02:00
if ( _categoriesGrid - > item ( line , i ) = = 0 )
2011-12-18 13:51:04 +01:00
_categoriesGrid - > setItem ( line , i , new QTableWidgetItem ( " " ) ) ;
SET_ROW_COLOR ( line , cat . backcolor , cat . forecolor ) ;
if ( cat . font . size ( ) )
{
QFont font = user - > GetCategoryFont ( cat . id ) ;
SET_ROW_FONT ( line , font ) ;
}
// _categoriesGrid->SetCellAlignment(line, CATEGORY_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE);
}
else
{
for ( int i = 0 ; i < NUMBER_COLS_CATEGORY ; i + + )
if ( ! _categoriesGrid - > item ( line , i ) )
_categoriesGrid - > setItem ( line , i , new QTableWidgetItem ( " " ) ) ;
SET_READ_ONLY ( line , CATEGORY_BACKGROUND_COLOR ) ;
SET_READ_ONLY ( line , CATEGORY_FOREGROUND_COLOR ) ;
SET_READ_ONLY ( line , CATEGORY_FONT ) ;
SET_READ_ONLY ( line , CATEGORY_DELETE ) ;
SET_ROW_COLOR ( line , view : : OWN_GREEN , Qt : : black ) ;
_categoriesGrid - > resizeColumnsToContents ( ) ;
}
}
void PreferencesPanel : : InitLanguage ( User * user )
{
int i , select = 0 ;
2012-01-07 09:21:22 +01:00
QListWidgetItem * item ;
2011-12-18 13:51:04 +01:00
2012-04-27 20:24:22 +02:00
if ( _inModification ) return ;
2012-04-01 10:49:39 +02:00
_inModification = true ;
_language - > clear ( ) ;
2011-12-18 13:51:04 +01:00
for ( i = 0 ; i < SupportedLanguages : : NB_SUPPORTED_LANGUAGES ; i + + )
{
2012-04-01 10:49:39 +02:00
item = new QListWidgetItem ( SupportedLanguages : : languages [ i ] . name . toLatin1 ( ) ) ;
2012-01-07 09:21:22 +01:00
item - > setIcon ( QIcon ( SupportedLanguages : : languages [ i ] . icon ) ) ,
_language - > addItem ( item ) ;
2011-12-18 13:51:04 +01:00
2012-04-01 10:49:39 +02:00
if ( SupportedLanguages : : languages [ i ] . name = = _wxUI - > _curLanguage . name )
2011-12-18 13:51:04 +01:00
select = i ;
}
2012-04-01 10:49:39 +02:00
_language - > setCurrentRow ( select ) ;
_inModification = false ;
2011-12-18 13:51:04 +01:00
}
void PreferencesPanel : : InitOperationOrder ( User * user )
{
_operationOrder - > addItem ( _ ( " Ascending " ) ) ;
_operationOrder - > addItem ( _ ( " Descending " ) ) ;
if ( user - > _preferences [ " operation_order " ] = = " ASC " )
_operationOrder - > setCurrentIndex ( 0 ) ;
else
_operationOrder - > setCurrentIndex ( 1 ) ;
}
void PreferencesPanel : : OnAccountDefaultClicked ( int id )
{
User * user = _kiss - > GetUser ( ) ;
QCheckBox * checkBox = qobject_cast < QCheckBox * > ( _defaultSignalMapper . mapping ( id ) ) ;
std : : vector < Account > : : iterator it ;
int i , row ;
Account account ;
if ( _inModification ) return ;
it = std : : find ( user - > _accounts . begin ( ) , user - > _accounts . end ( ) , id ) ;
if ( it = = user - > _accounts . end ( ) ) return ;
row = it - user - > _accounts . begin ( ) ;
account = user - > _accounts [ row ] ;
_inModification = true ;
if ( account . _default )
{
checkBox - > setCheckState ( Qt : : Checked ) ;
_inModification = false ;
return ;
}
account . _default = true ;
_kiss - > UpdateAccount ( account ) ;
for ( i = 0 ; i < user - > GetAccountsNumber ( ) ; i + + )
{
if ( i ! = row )
{
account = user - > _accounts [ i ] ;
if ( account . _default )
{
account . _default = false ;
_kiss - > UpdateAccount ( account ) ;
checkBox = qobject_cast < QCheckBox * > ( _accountsGrid - > cellWidget ( i , ACCOUNT_DEFAULT ) ) ;
checkBox - > setCheckState ( Qt : : Unchecked ) ;
break ;
}
}
}
account = user - > _accounts [ row ] ;
_inModification = false ;
2012-02-01 12:43:43 +01:00
_wxUI - > NeedReload ( ) ;
2011-12-18 13:51:04 +01:00
}
void PreferencesPanel : : OnAccountVirtualClicked ( int id )
{
User * user = _kiss - > GetUser ( ) ;
QCheckBox * checkBox = qobject_cast < QCheckBox * > ( _virtualSignalMapper . mapping ( id ) ) ;
std : : vector < Account > : : iterator it ;
Account account ;
int row ;
2012-04-27 21:59:25 +02:00
if ( _inModification ) return ;
2011-12-18 13:51:04 +01:00
it = std : : find ( user - > _accounts . begin ( ) , user - > _accounts . end ( ) , id ) ;
if ( it = = user - > _accounts . end ( ) ) return ;
2012-04-27 21:59:25 +02:00
_inModification = true ;
2011-12-18 13:51:04 +01:00
row = it - user - > _accounts . begin ( ) ;
account = user - > _accounts [ row ] ;
account . _virtual = ( checkBox - > checkState ( ) = = Qt : : Checked ) ;
_kiss - > UpdateAccount ( account ) ;
2012-02-01 12:43:43 +01:00
2012-04-27 21:59:25 +02:00
_inModification = false ;
2012-02-01 12:43:43 +01:00
_wxUI - > NeedReload ( ) ;
2011-12-18 13:51:04 +01:00
}
void PreferencesPanel : : OnAccountBlockedClicked ( int id )
{
User * user = _kiss - > GetUser ( ) ;
QCheckBox * checkBox = qobject_cast < QCheckBox * > ( _blockedSignalMapper . mapping ( id ) ) ;
std : : vector < Account > : : iterator it ;
Account account ;
int row ;
2012-04-27 21:59:25 +02:00
if ( _inModification ) return ;
2011-12-18 13:51:04 +01:00
it = std : : find ( user - > _accounts . begin ( ) , user - > _accounts . end ( ) , id ) ;
if ( it = = user - > _accounts . end ( ) ) return ;
2012-04-27 21:59:25 +02:00
_inModification = true ;
2011-12-18 13:51:04 +01:00
row = it - user - > _accounts . begin ( ) ;
account = user - > _accounts [ row ] ;
account . blocked = ( checkBox - > checkState ( ) = = Qt : : Checked ) ;
_kiss - > UpdateAccount ( account ) ;
2012-02-01 12:43:43 +01:00
2012-04-27 21:59:25 +02:00
_inModification = false ;
2012-02-01 12:43:43 +01:00
_wxUI - > NeedReload ( ) ;
2011-12-18 13:51:04 +01:00
}
void PreferencesPanel : : OnAccountDeleteClicked ( int id )
{
User * user = _kiss - > GetUser ( ) ;
std : : vector < Account > : : iterator it ;
int i , row ;
QStringList accounts ;
QString res ;
QCheckBox * checkBox = qobject_cast < QCheckBox * > ( _deleteAccountSignalMapper . mapping ( id ) ) ;
Account account ;
2012-04-27 21:38:30 +02:00
bool ok , default_account ;
2011-12-18 13:51:04 +01:00
if ( user - > GetAccountsNumber ( ) = = 1 )
{
QMessageBox : : critical ( 0 , _ ( " Error " ) , _ ( " It must be at least one account ! " ) ) ;
checkBox - > setCheckState ( Qt : : Unchecked ) ;
return ;
}
it = std : : find ( user - > _accounts . begin ( ) , user - > _accounts . end ( ) , id ) ;
if ( it = = user - > _accounts . end ( ) ) return ;
if ( _inModification ) return ;
_inModification = true ;
row = it - user - > _accounts . begin ( ) ;
account = user - > _accounts [ row ] ;
accounts < < _ ( " None " ) ;
for ( i = 0 ; i < user - > GetAccountsNumber ( ) ; i + + )
if ( user - > _accounts [ i ] . id ! = id )
accounts < < user - > _accounts [ i ] . name ;
2012-04-30 21:22:52 +02:00
res = QInputDialog : : getItem ( 0 , " KissCount " , _ ( " Wich account will replace this one ? " ) , accounts , 0 , false , & ok ) ;
2011-12-18 13:51:04 +01:00
if ( ! ok )
{
checkBox - > setCheckState ( Qt : : Unchecked ) ;
_inModification = false ;
return ;
}
else
{
i = accounts . indexOf ( res ) ;
2012-04-27 21:38:30 +02:00
default_account = user - > _accounts [ i ] . _default ;
2011-12-18 13:51:04 +01:00
_kiss - > DeleteAccount ( account , ( ! i ) ? 0 : user - > GetAccountId ( accounts [ i ] ) ) ;
_accountsGrid - > removeRow ( row ) ;
}
2012-04-27 21:38:30 +02:00
if ( default_account )
2011-12-18 13:51:04 +01:00
{
user - > _accounts [ 0 ] . _default = true ;
2012-04-28 09:23:38 +02:00
user - > _accounts [ 0 ] . hidden = false ;
2011-12-18 13:51:04 +01:00
_kiss - > UpdateAccount ( user - > _accounts [ 0 ] ) ;
2012-04-27 21:38:30 +02:00
checkBox = qobject_cast < QCheckBox * > ( _accountsGrid - > cellWidget ( 0 , ACCOUNT_DEFAULT ) ) ;
2011-12-18 13:51:04 +01:00
checkBox - > setCheckState ( Qt : : Checked ) ;
2012-04-28 09:23:38 +02:00
checkBox = qobject_cast < QCheckBox * > ( _accountsGrid - > cellWidget ( 0 , ACCOUNT_HIDDEN ) ) ;
checkBox - > setCheckState ( Qt : : Unchecked ) ;
2011-12-18 13:51:04 +01:00
}
_inModification = false ;
_wxUI - > NeedReload ( ) ;
}
2012-02-01 12:43:43 +01:00
void PreferencesPanel : : OnAccountHiddenClicked ( int id )
{
User * user = _kiss - > GetUser ( ) ;
QCheckBox * checkBox = qobject_cast < QCheckBox * > ( _hiddenAccountSignalMapper . mapping ( id ) ) ;
std : : vector < Account > : : iterator it ;
Account account ;
int row ;
2012-04-27 21:59:25 +02:00
if ( _inModification ) return ;
_inModification = true ;
2012-02-01 12:43:43 +01:00
it = std : : find ( user - > _accounts . begin ( ) , user - > _accounts . end ( ) , id ) ;
if ( it = = user - > _accounts . end ( ) ) return ;
row = it - user - > _accounts . begin ( ) ;
account = user - > _accounts [ row ] ;
2012-04-28 09:23:38 +02:00
if ( account . _default )
{
QMessageBox : : critical ( 0 , _ ( " Error " ) , _ ( " Default account cannot be hidden " ) ) ;
checkBox - > setCheckState ( Qt : : Unchecked ) ;
_inModification = false ;
return ;
}
2012-02-01 12:43:43 +01:00
account . hidden = ( checkBox - > checkState ( ) = = Qt : : Checked ) ;
_kiss - > UpdateAccount ( account ) ;
2012-04-27 21:59:25 +02:00
_inModification = false ;
2012-02-01 12:43:43 +01:00
_wxUI - > NeedReload ( ) ;
}
2011-12-18 13:51:04 +01:00
void PreferencesPanel : : OnCategoryDeleteClicked ( int id )
2012-01-07 09:21:22 +01:00
{
QStringList categories ;
int i , row ;
QString res ;
User * user = _kiss - > GetUser ( ) ;
bool ok ;
QCheckBox * checkBox = qobject_cast < QCheckBox * > ( _deleteCategorySignalMapper . mapping ( id ) ) ;
Category category ;
std : : vector < Category > : : iterator it ;
if ( _inModification ) return ;
it = std : : find ( user - > _categories . begin ( ) , user - > _categories . end ( ) , id ) ;
if ( it = = user - > _categories . end ( ) ) return ;
_inModification = true ;
row = it - user - > _categories . begin ( ) ;
category = user - > _categories [ row ] ;
categories < < _ ( " None " ) ;
for ( i = 0 ; i < user - > GetCategoriesNumber ( ) ; i + + )
if ( user - > _categories [ i ] . id ! = id )
categories < < _ ( user - > _categories [ i ] . name . toStdString ( ) . c_str ( ) ) ;
2012-04-30 21:22:52 +02:00
res = QInputDialog : : getItem ( 0 , " KissCount " , _ ( " Wich category will replace this one ? " ) , categories , 0 , false , & ok ) ;
2012-01-07 09:21:22 +01:00
if ( ! ok )
{
checkBox - > setCheckState ( Qt : : Unchecked ) ;
_inModification = false ;
return ;
}
else
{
i = categories . indexOf ( res ) ;
_kiss - > DeleteCategory ( category , ( ! i ) ? 0 : user - > GetCategoryId ( categories [ i ] ) ) ;
_categoriesGrid - > removeRow ( row ) ;
_wxUI - > NeedReload ( ) ;
}
_inModification = false ;
}
2011-12-18 13:51:04 +01:00
void PreferencesPanel : : OnBackgroundColorClicked ( int id )
2012-01-07 09:21:22 +01:00
{
User * user = _kiss - > GetUser ( ) ;
QColor color ;
std : : vector < Category > : : iterator it ;
int row ;
2012-04-27 21:59:25 +02:00
if ( _inModification ) return ;
2012-01-07 09:21:22 +01:00
it = std : : find ( user - > _categories . begin ( ) , user - > _categories . end ( ) , id ) ;
if ( it = = user - > _categories . end ( ) ) return ;
row = it - user - > _categories . begin ( ) ;
_inModification = true ;
color = QColorDialog : : getColor ( user - > _categories [ row ] . backcolor ) ;
if ( color . isValid ( ) )
{
user - > _categories [ row ] . backcolor = color ;
_kiss - > UpdateCategory ( user - > _categories [ row ] ) ;
SET_ROW_COLOR ( row , user - > _categories [ row ] . backcolor , user - > _categories [ row ] . forecolor ) ;
_wxUI - > NeedReload ( ) ;
}
_inModification = false ;
}
2011-12-18 13:51:04 +01:00
void PreferencesPanel : : OnForegroundClicked ( int id )
2012-01-07 09:21:22 +01:00
{
User * user = _kiss - > GetUser ( ) ;
QColor color ;
std : : vector < Category > : : iterator it ;
int row ;
2012-04-27 21:59:25 +02:00
if ( _inModification ) return ;
2012-01-07 09:21:22 +01:00
it = std : : find ( user - > _categories . begin ( ) , user - > _categories . end ( ) , id ) ;
if ( it = = user - > _categories . end ( ) ) return ;
row = it - user - > _categories . begin ( ) ;
_inModification = true ;
color = QColorDialog : : getColor ( user - > _categories [ row ] . forecolor ) ;
if ( color . isValid ( ) )
{
user - > _categories [ row ] . forecolor = color ;
_kiss - > UpdateCategory ( user - > _categories [ row ] ) ;
SET_ROW_COLOR ( row , user - > _categories [ row ] . backcolor , user - > _categories [ row ] . forecolor ) ;
_wxUI - > NeedReload ( ) ;
}
_inModification = false ;
}
2011-12-18 13:51:04 +01:00
void PreferencesPanel : : OnFontClicked ( int id )
2012-01-07 09:21:22 +01:00
{
User * user = _kiss - > GetUser ( ) ;
bool ok ;
QFont font ;
std : : vector < Category > : : iterator it ;
int row ;
2012-04-27 21:59:25 +02:00
if ( _inModification ) return ;
2012-01-07 09:21:22 +01:00
it = std : : find ( user - > _categories . begin ( ) , user - > _categories . end ( ) , id ) ;
if ( it = = user - > _categories . end ( ) ) return ;
row = it - user - > _categories . begin ( ) ;
_inModification = true ;
font = QFontDialog : : getFont ( & ok , user - > _categories [ row ] . font ) ;
if ( ok )
{
user - > _categories [ row ] . font = KissCount : : CompactFont ( font ) ;
_kiss - > UpdateCategory ( user - > _categories [ row ] ) ;
SET_ROW_FONT ( row , font ) ;
_wxUI - > NeedReload ( ) ;
}
_inModification = false ;
}
2011-12-18 13:51:04 +01:00
void PreferencesPanel : : OnAccountModified ( int row , int col )
{
int op_complete = 1 , new_id ;
QString value ;
Account new_account , account ;
User * user = _kiss - > GetUser ( ) ;
if ( _inModification ) return ;
_inModification = true ;
value = _accountsGrid - > item ( row , ACCOUNT_NAME ) - > text ( ) ;
if ( value . size ( ) )
{
new_account . name = value ;
op_complete - - ;
}
value = _accountsGrid - > item ( row , ACCOUNT_NUMBER ) - > text ( ) ;
if ( value . size ( ) )
{
new_account . number = value ;
2012-05-12 09:56:33 +02:00
//op_complete--;
2011-12-18 13:51:04 +01:00
}
// Account modification
if ( user - > GetAccountsNumber ( ) & & row < user - > GetAccountsNumber ( ) )
{
2012-04-28 09:23:38 +02:00
new_account . _default = user - > _accounts [ row ] . _default ;
2011-12-18 13:51:04 +01:00
new_account . id = user - > _accounts [ row ] . id ;
new_account . shared = user - > _accounts [ row ] . shared ;
new_account . is_owner = user - > _accounts [ row ] . is_owner ;
2012-04-28 09:23:38 +02:00
new_account . blocked = user - > _accounts [ row ] . blocked ;
new_account . _virtual = user - > _accounts [ row ] . _virtual ;
new_account . hidden = user - > _accounts [ row ] . hidden ;
2011-12-18 13:51:04 +01:00
if ( col = = ACCOUNT_NAME )
{
2012-05-12 09:56:33 +02:00
if ( new_account . name . length ( ) = = 0 )
{
QMessageBox : : critical ( 0 , _ ( " Error " ) , _ ( " Account must have a name " ) + new_account . name + _ ( " already exists " ) ) ;
_accountsGrid - > setItem ( row , ACCOUNT_NAME , new QTableWidgetItem ( user - > _accounts [ row ] . name ) ) ;
_inModification = false ;
return ;
}
2012-04-27 20:24:22 +02:00
try {
new_id = user - > GetAccountId ( new_account . name ) ;
if ( new_id ! = new_account . id )
{
QMessageBox : : critical ( 0 , _ ( " Error " ) , _ ( " Account " ) + new_account . name + _ ( " already exists " ) ) ;
_accountsGrid - > setItem ( row , ACCOUNT_NAME , new QTableWidgetItem ( user - > _accounts [ row ] . name ) ) ;
_inModification = false ;
return ;
}
}
catch ( User : : AccountNotFound e )
{ }
2011-12-18 13:51:04 +01:00
}
_kiss - > UpdateAccount ( new_account ) ;
}
// New account
else
{
2012-05-12 09:56:33 +02:00
if ( op_complete | | new_account . name . length ( ) = = 0 )
2011-12-18 13:51:04 +01:00
{
_inModification = false ;
return ;
}
2012-04-27 20:24:22 +02:00
try {
user - > GetAccountId ( new_account . name ) ;
2011-12-18 13:51:04 +01:00
QMessageBox : : critical ( 0 , _ ( " Error " ) , _ ( " Account " ) + new_account . name + _ ( " already exists " ) ) ;
_inModification = false ;
return ;
}
2012-04-27 20:24:22 +02:00
catch ( User : : AccountNotFound e )
{ }
2011-12-18 13:51:04 +01:00
new_account . _default = false ;
new_account . shared = false ;
new_account . blocked = false ;
new_account . is_owner = true ;
new_account . _virtual = false ;
2012-02-01 12:43:43 +01:00
new_account . hidden = false ;
2011-12-18 13:51:04 +01:00
_kiss - > AddAccount ( new_account ) ;
2012-04-27 21:38:30 +02:00
AddAccount ( row , new_account ) ;
2011-12-18 13:51:04 +01:00
new_account . id = 0 ;
_accountsGrid - > setRowCount ( row + 2 ) ;
AddAccount ( row + 1 , new_account ) ;
}
_accountsGrid - > resizeColumnsToContents ( ) ;
_wxUI - > NeedReload ( ) ;
_inModification = false ;
}
void PreferencesPanel : : OnAccountCellChanged ( int row , int col , int previousRow , int previousCol )
{
User * user = _kiss - > GetUser ( ) ;
std : : map < QString , QString > : : iterator it ;
int i ;
bool own ;
QString owner ;
QListWidgetItem * item ;
if ( ! _sharedWith | | _curAccountRow = = row )
return ;
_curAccountRow = row ;
if ( row > = ( int ) user - > _accounts . size ( ) )
{
for ( i = 0 ; i < ( int ) _sharedWith - > count ( ) ; i + + )
_sharedWith - > item ( i ) - > setCheckState ( Qt : : Unchecked ) ;
own = false ;
}
else
{
_sharedOwners = _kiss - > getSharedAccountOwners ( user - > _accounts [ row ] . id ) ;
owner = _kiss - > getSharedAccountOwner ( user - > _accounts [ row ] . id ) ;
for ( i = 0 ; i < ( int ) _sharedWith - > count ( ) ; i + + )
{
item = _sharedWith - > item ( i ) ;
item - > setCheckState ( ( _sharedOwners [ item - > text ( ) ] . size ( ) > 0 | |
item - > text ( ) = = owner ) ? Qt : : Checked : Qt : : Unchecked ) ;
}
own = user - > _accounts [ row ] . is_owner ;
}
_sharedWith - > setEnabled ( own ) ;
}
void PreferencesPanel : : OnSharedChange ( QListWidgetItem * item )
{
User * user = _kiss - > GetUser ( ) ;
if ( _inModification ) return ;
_inModification = true ;
if ( item - > checkState ( ) = = Qt : : Checked )
{
if ( ! user - > _accounts [ _curAccountRow ] . shared )
_accountsGrid - > setItem ( _curAccountRow , ACCOUNT_NUMBER ,
new QTableWidgetItem ( user - > _accounts [ _curAccountRow ] . number + " * " ) ) ;
_kiss - > AddSharedAccount ( user - > _accounts [ _curAccountRow ] , item - > text ( ) ) ;
}
else
{
_kiss - > RemoveSharedAccount ( user - > _accounts [ _curAccountRow ] , _sharedOwners [ item - > text ( ) ] . toInt ( ) ) ;
if ( ! user - > _accounts [ _curAccountRow ] . shared )
_accountsGrid - > setItem ( _curAccountRow , ACCOUNT_NUMBER , new QTableWidgetItem ( user - > _accounts [ _curAccountRow ] . number ) ) ;
}
_inModification = false ;
_wxUI - > NeedReload ( ) ;
}
2012-01-07 09:21:22 +01:00
void PreferencesPanel : : OnCategoryModified ( int row , int col )
2011-12-18 13:51:04 +01:00
{
2012-01-07 09:21:22 +01:00
int op_complete = 1 ;
QString value ;
User * user = _kiss - > GetUser ( ) ;
Category new_cat , old_cat ;
int new_id ;
QTableWidgetItem * item = _categoriesGrid - > item ( row , col ) ;
if ( _inModification ) return ;
_inModification = true ;
value = item - > text ( ) ;
if ( value . size ( ) )
{
new_cat . name = value ;
op_complete - - ;
}
new_cat . backcolor = item - > background ( ) . color ( ) ;
new_cat . forecolor = item - > foreground ( ) . color ( ) ;
new_cat . font = " " ;
new_cat . parent = 0 ;
// Categories modification
if ( user - > GetCategoriesNumber ( ) & & row < user - > GetCategoriesNumber ( ) )
{
old_cat = user - > _categories [ row ] ;
new_cat . id = user - > _categories [ row ] . id ;
new_cat . fix_cost = user - > _categories [ row ] . fix_cost ;
new_cat . backcolor = old_cat . backcolor ;
new_cat . forecolor = old_cat . forecolor ;
new_cat . font = old_cat . font ;
new_cat . parent = old_cat . parent ;
2012-05-12 09:56:33 +02:00
if ( new_cat . name . length ( ) = = 0 )
{
QMessageBox : : critical ( 0 , _ ( " Error " ) , _ ( " Category must have a name " ) ) ;
_categoriesGrid - > setItem ( row , CATEGORY_NAME , new QTableWidgetItem ( _ ( user - > _categories [ row ] . name . toStdString ( ) . c_str ( ) ) ) ) ;
_inModification = false ;
return ;
}
2012-04-27 20:24:22 +02:00
try {
new_id = user - > GetCategoryId ( new_cat . name ) ;
if ( new_id ! = new_cat . id )
{
QMessageBox : : critical ( 0 , _ ( " Error " ) , _ ( " Category " ) + new_cat . name + _ ( " already exists " ) ) ;
_categoriesGrid - > setItem ( row , CATEGORY_NAME , new QTableWidgetItem ( _ ( user - > _categories [ row ] . name . toStdString ( ) . c_str ( ) ) ) ) ;
_inModification = false ;
return ;
}
}
catch ( User : : CategoryNotFound e )
{ }
2012-01-07 09:21:22 +01:00
_kiss - > UpdateCategory ( new_cat ) ;
}
// New category
else
{
if ( op_complete )
{
_inModification = false ;
return ;
}
2011-12-18 13:51:04 +01:00
2012-04-27 20:24:22 +02:00
try {
user - > GetCategoryId ( new_cat . name ) ;
2012-01-07 09:21:22 +01:00
QMessageBox : : critical ( 0 , _ ( " Error " ) , _ ( " Category " ) + new_cat . name + _ ( " already exists " ) ) ;
_inModification = false ;
return ;
}
2012-04-27 20:24:22 +02:00
catch ( User : : CategoryNotFound e )
{ }
2011-12-18 13:51:04 +01:00
2012-01-07 09:21:22 +01:00
new_cat . fix_cost = false ;
2011-12-18 13:51:04 +01:00
2012-01-07 09:21:22 +01:00
_kiss - > AddCategory ( new_cat ) ;
AddCategory ( row , new_cat ) ;
2011-12-18 13:51:04 +01:00
2012-01-07 09:21:22 +01:00
SET_READ_ONLY ( row , CATEGORY_BACKGROUND_COLOR ) ;
SET_READ_ONLY ( row , CATEGORY_FOREGROUND_COLOR ) ;
SET_READ_ONLY ( row , CATEGORY_FONT ) ;
SET_READ_ONLY ( row , CATEGORY_DELETE ) ;
2011-12-18 13:51:04 +01:00
2012-01-07 09:21:22 +01:00
new_cat . id = 0 ;
_categoriesGrid - > setRowCount ( row + 2 ) ;
AddCategory ( + + row , new_cat ) ;
}
2011-12-18 13:51:04 +01:00
2012-01-07 09:21:22 +01:00
_wxUI - > NeedReload ( ) ;
2011-12-18 13:51:04 +01:00
2012-01-07 09:21:22 +01:00
_inModification = false ;
2011-12-18 13:51:04 +01:00
}
void PreferencesPanel : : OnChangeName ( )
{
User * user = _kiss - > GetUser ( ) ;
QString name = _name - > text ( ) ;
if ( name = = user - > _name )
return ;
if ( ! name . size ( ) )
{
QMessageBox : : critical ( 0 , _ ( " Error " ) , _ ( " Invalid name ! " ) ) ;
return ;
}
if ( _kiss - > UserExists ( name ) )
{
QMessageBox : : critical ( 0 , _ ( " Error " ) , _ ( " User " ) + name + _ ( " already exists " ) ) ;
return ;
}
_kiss - > ChangeName ( name ) ;
QMessageBox : : information ( 0 , " KissCount " , _ ( " Name changed " ) ) ;
_wxUI - > NeedReload ( ) ;
OnShow ( ) ;
}
void PreferencesPanel : : OnChangePassword ( )
{
2012-01-07 09:21:22 +01:00
PasswordDialog g ( _kiss , _wxUI ) ;
g . setModal ( true ) ;
g . exec ( ) ;
2011-12-18 13:51:04 +01:00
}
void PreferencesPanel : : OnOperationOrderChange ( int index )
{
if ( index = = 0 )
_kiss - > SetOperationOrder ( " ASC " ) ;
else
_kiss - > SetOperationOrder ( " DESC " ) ;
_wxUI - > NeedReload ( ) ;
}
2012-02-11 12:48:19 +01:00
void PreferencesPanel : : OnLanguageChange ( int index )
2011-12-18 13:51:04 +01:00
{
2012-04-27 20:24:22 +02:00
if ( _inModification ) return ;
2012-02-26 14:24:04 +01:00
int language = SupportedLanguages : : languages [ index ] . language ;
2012-02-11 12:48:19 +01:00
QString name_lang = SupportedLanguages : : languages [ index ] . name ;
2011-12-18 13:51:04 +01:00
2012-02-26 14:24:04 +01:00
if ( _wxUI - > SetLanguage ( name_lang ) | | language = = SupportedLanguages : : English )
2011-12-18 13:51:04 +01:00
{
_wxUI - > NeedReload ( ) ;
_kiss - > SetLanguage ( name_lang ) ;
QMessageBox : : information ( 0 , " KissCount " , _ ( " Language successfully changed, please go to another panel " ) ) ;
}
else
QMessageBox : : critical ( 0 , _ ( " Error " ) , _ ( " Language not changed " ) ) ;
}
void PreferencesPanel : : OnShow ( )
{
_wxUI - > setWindowTitle ( _kiss - > GetUser ( ) - > _name + " - " + _ ( " Preferences " ) ) ;
2012-04-01 10:49:39 +02:00
InitLanguage ( _kiss - > GetUser ( ) ) ;
2011-12-18 13:51:04 +01:00
}
void PreferencesPanel : : OnKillMe ( )
{
User * user = _kiss - > GetUser ( ) ;
2012-05-22 21:29:56 +02:00
if ( QMessageBox : : question ( 0 , " KissCount " , _ ( " Are you sure want to delete profil of " ) + user - > _name + _ ( " ? " ) , QMessageBox : : Yes | QMessageBox : : No ) = = QMessageBox : : No )
2011-12-18 13:51:04 +01:00
{
return ;
}
_kiss - > KillMe ( ) ;
}