/* Copyright 2010-2011 Grégory Soutadé 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 . */ #include "PreferencesPanel.h" enum {ACCOUNT_NAME, ACCOUNT_NUMBER, ACCOUNT_DEFAULT, ACCOUNT_VIRTUAL, ACCOUNT_BLOCKED, ACCOUNT_DELETE, NUMBER_COLS_ACCOUNT}; enum {CATEGORY_NAME, CATEGORY_BACKGROUND_COLOR, CATEGORY_FOREGROUND_COLOR, CATEGORY_FONT, CATEGORY_DELETE, NUMBER_COLS_CATEGORY}; enum {CATEGORIES_GRID_ID=1, ACCOUNTS_GRID_ID, NAME_ID, CHANGE_NAME_ID, CHANGE_PASSWORD_ID, KILL_ME_ID, LANGUAGE_ID, OPERATION_ORDER_ID, SHARED_WITH_ID}; BEGIN_EVENT_TABLE(PreferencesPanel, wxPanel) EVT_BUTTON(CHANGE_NAME_ID, PreferencesPanel::OnChangeName) EVT_BUTTON(CHANGE_PASSWORD_ID, PreferencesPanel::OnChangePassword) EVT_BUTTON(KILL_ME_ID, PreferencesPanel::OnKillMe) EVT_GRID_CMD_CELL_CHANGE(CATEGORIES_GRID_ID, PreferencesPanel::OnCategoryModified) EVT_GRID_CMD_CELL_CHANGE(ACCOUNTS_GRID_ID, PreferencesPanel::OnAccountModified) EVT_GRID_CMD_SELECT_CELL(ACCOUNTS_GRID_ID, PreferencesPanel::OnAccountCellChanged) EVT_COMBOBOX(OPERATION_ORDER_ID, PreferencesPanel::OnOperationOrderChange) EVT_COMBOBOX(LANGUAGE_ID, PreferencesPanel::OnLanguageChange) EVT_CHECKLISTBOX(SHARED_WITH_ID, PreferencesPanel::OnSharedChange) EVT_SHOW(PreferencesPanel::OnShow) END_EVENT_TABLE() PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent), _sharedWith(0), _curAccountRow(-1) { wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); wxBoxSizer *hbox1 = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer *hbox2 = new wxBoxSizer(wxHORIZONTAL); //wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL); wxStaticBox* staticUser, *staticAccount, *staticCategories, *staticLanguage, *staticOperationOrder, *staticSharedWith; User* user = _kiss->GetUser(); wxGridBagSizer *gridBagSizer; wxStaticText* label; wxButton* buttonChangeName, *buttonChangePassword, *killMe; wxStaticBoxSizer * staticBoxSizer; std::list users; std::list::iterator it; wxRect rect = wxDisplay().GetGeometry(); SetSizer(vbox); staticUser = new wxStaticBox(this, wxID_ANY, _("User")); staticAccount = new wxStaticBox(this, wxID_ANY, _("Accounts")); staticCategories = new wxStaticBox(this, wxID_ANY, _("Categories")); staticLanguage = new wxStaticBox(this, wxID_ANY, _("Language")); staticOperationOrder = new wxStaticBox(this, wxID_ANY, _("Operation order")); staticSharedWith = new wxStaticBox(this, wxID_ANY, _("Shared with")); // User staticBoxSizer = new wxStaticBoxSizer (staticUser, wxVERTICAL); gridBagSizer = new wxGridBagSizer(2, 3); staticBoxSizer->Add(gridBagSizer, 0, wxGROW|wxALL, 2); label = new wxStaticText(this, wxID_ANY, _("Name")); gridBagSizer->Add(label, wxGBPosition(0, 0)); _name = new wxTextCtrl(this, NAME_ID, user->_name); gridBagSizer->Add(_name, wxGBPosition(0, 1)); buttonChangeName = new wxButton(this, CHANGE_NAME_ID, _("Change Name")); buttonChangePassword = new wxButton(this, CHANGE_PASSWORD_ID, _("Change Password")); killMe = new wxButton(this, KILL_ME_ID, _("Kill me")); gridBagSizer->Add(buttonChangeName, wxGBPosition(1, 0)); gridBagSizer->Add(buttonChangePassword, wxGBPosition(1, 1)); gridBagSizer->Add(killMe, wxGBPosition(1, 2)); vbox->Add(staticBoxSizer, 0, wxALL, 10); // Account staticBoxSizer = new wxStaticBoxSizer (staticAccount, wxVERTICAL); { int clicks[] = {ACCOUNT_DEFAULT, ACCOUNT_DELETE}; _accountsGrid = new wxMyGrid(this, ACCOUNTS_GRID_ID, clicks, 2); } InitAccounts(user); staticBoxSizer->Add(_accountsGrid, 0, wxGROW|wxALL, 2); hbox1->Add(staticBoxSizer, 0, wxALL); staticBoxSizer = new wxStaticBoxSizer (staticSharedWith, wxVERTICAL); _sharedWith = new wxCheckListBox(this, SHARED_WITH_ID); staticBoxSizer->Add(_sharedWith, 0, wxGROW); users = _kiss->GetUsers(); for(it=users.begin(); it!=users.end(); it++) if (*it != user->_name) _sharedWith->Append(*it); _sharedWith->Enable(false); hbox1->Add(staticBoxSizer, 0, wxLEFT, 5); vbox->Add(hbox1, 0, wxGROW|wxALL, 10); // Categories staticBoxSizer = new wxStaticBoxSizer (staticCategories, wxVERTICAL); { int clicks[] = {CATEGORY_BACKGROUND_COLOR, CATEGORY_FOREGROUND_COLOR, CATEGORY_FONT, CATEGORY_DELETE}; _categoriesGrid = new wxMyGrid(this, CATEGORIES_GRID_ID, clicks, 4); } staticBoxSizer->Add(_categoriesGrid, 0, wxGROW|wxALL, 2); InitCategories(user); vbox->Add(staticBoxSizer, 0, wxALL, 10); // Operation Order staticBoxSizer = new wxStaticBoxSizer (staticOperationOrder, wxVERTICAL); _operationOrder = new wxComboBox(this, OPERATION_ORDER_ID); _operationOrder->SetWindowStyle(wxCB_READONLY); staticBoxSizer->Add(_operationOrder, 0, wxGROW|wxALL, 2); hbox2->Add(staticBoxSizer, 0); InitOperationOrder(user); // Language staticBoxSizer = new wxStaticBoxSizer (staticLanguage, wxVERTICAL); _language = new wxBitmapComboBox(this, LANGUAGE_ID); _language->SetWindowStyle(wxCB_READONLY); staticBoxSizer->Add(_language, 0, wxGROW|wxALL, 2); hbox2->Add(staticBoxSizer, 0, wxLEFT, 10); InitLanguage(user); _language->Fit(); vbox->Add(hbox2, 0, wxALL, 10); Fit(); SetMinSize(wxSize(rect.width-rect.x-15, rect.height-rect.y-128-25)); SetMaxSize(wxSize(rect.width-rect.x-15, rect.height-rect.y-128-25)); SetScrollbars(10, 10, 100/10, 100/10); } KissPanel* PreferencesPanel::CreatePanel() { return new PreferencesPanel(_kiss, _wxUI); } wxBitmapButton* PreferencesPanel::GetButton(int id) { if (!_KissButton) _KissButton = new wxBitmapButton(_wxUI, id, wxBitmap(wxT(PREFS_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128)); return _KissButton; } wxString PreferencesPanel::GetToolTip() { return _("Preferences"); } void PreferencesPanel::InitAccounts(User* user) { std::vector::iterator it; int curLine = 0; Account account ; DEFAULT_FONT(font); _accountsGrid->CreateGrid(0, NUMBER_COLS_ACCOUNT); _accountsGrid->SetRowLabelSize(0); _accountsGrid->SetColLabelValue(ACCOUNT_NAME, _("Name")); _accountsGrid->SetColLabelValue(ACCOUNT_NUMBER, _("Number")); _accountsGrid->SetColLabelValue(ACCOUNT_DEFAULT, _("Default")); _accountsGrid->SetColLabelValue(ACCOUNT_VIRTUAL, _("Virtual")); _accountsGrid->SetColLabelValue(ACCOUNT_BLOCKED, _("Blocked")); _accountsGrid->SetColLabelValue(ACCOUNT_DELETE, _("Delete")); _accountsGrid->SetDefaultCellFont(font); for (it = user->_accounts.begin(); it != user->_accounts.end(); it++, curLine++) { _accountsGrid->AppendRows(); AddAccount(curLine, *it); } _accountsGrid->AppendRows(); account.id = wxT("0"); AddAccount(curLine, account); } void PreferencesPanel::AddAccount(int line, Account ac) { if (ac.id != wxT("0")) { _accountsGrid->SetCellValue(line, ACCOUNT_NAME, ac.name); if (ac.shared) _accountsGrid->SetCellValue(line, ACCOUNT_NUMBER, ac.number + wxT("*")); else _accountsGrid->SetCellValue(line, ACCOUNT_NUMBER, ac.number); _accountsGrid->SetCellEditor(line, ACCOUNT_NUMBER, new wxGridCellStarEditor ()); _accountsGrid->SetCellRenderer(line, ACCOUNT_DEFAULT, new wxGridCellBoolRenderer ()); _accountsGrid->SetCellEditor(line, ACCOUNT_DEFAULT, new wxGridCellFastBoolEditor ()); _accountsGrid->SetCellRenderer(line, ACCOUNT_VIRTUAL, new wxGridCellBoolRenderer ()); _accountsGrid->SetCellEditor(line, ACCOUNT_VIRTUAL, new wxGridCellFastBoolEditor ()); _accountsGrid->SetCellRenderer(line, ACCOUNT_BLOCKED, new wxGridCellBoolRenderer ()); _accountsGrid->SetCellEditor(line, ACCOUNT_BLOCKED, new wxGridCellFastBoolEditor ()); _accountsGrid->SetCellRenderer(line, ACCOUNT_DELETE, new wxGridCellBoolRenderer ()); _accountsGrid->SetCellEditor(line, ACCOUNT_DELETE, new wxGridCellBoolEditor ()); _accountsGrid->SetCellValue(line, ACCOUNT_DEFAULT, (ac._default)?wxT("1"):wxT("0")); _accountsGrid->SetCellValue(line, ACCOUNT_VIRTUAL, (ac._virtual)?wxT("1"):wxT("0")); _accountsGrid->SetCellValue(line, ACCOUNT_BLOCKED, (ac.blocked)?wxT("1"):wxT("0")); _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) { _accountsGrid->SetReadOnly(line, ACCOUNT_NAME, true); _accountsGrid->SetReadOnly(line, ACCOUNT_NUMBER, true); _accountsGrid->SetReadOnly(line, ACCOUNT_DEFAULT, true); _accountsGrid->SetReadOnly(line, ACCOUNT_VIRTUAL, true); _accountsGrid->SetReadOnly(line, ACCOUNT_BLOCKED, true); } else { _accountsGrid->SetReadOnly(line, ACCOUNT_DEFAULT, false); _accountsGrid->SetReadOnly(line, ACCOUNT_VIRTUAL, false); _accountsGrid->SetReadOnly(line, ACCOUNT_BLOCKED, false); _accountsGrid->SetReadOnly(line, ACCOUNT_DELETE, false); } } else { _accountsGrid->SetReadOnly(line, ACCOUNT_DEFAULT, true); _accountsGrid->SetReadOnly(line, ACCOUNT_VIRTUAL, true); _accountsGrid->SetReadOnly(line, ACCOUNT_BLOCKED, true); _accountsGrid->SetReadOnly(line, ACCOUNT_DELETE, true); _accountsGrid->AutoSizeColumns(true); } } #define SET_ROW_COLOR(row, backcolor, forecolor) for(int i=0; iSetCellBackgroundColour(row, i, backcolor); \ _categoriesGrid->SetCellTextColour(row, i, forecolor); \ } #define SET_ROW_FONT(row, font) for(int i=0; iSetCellFont(row, i, font); \ } void PreferencesPanel::InitCategories(User* user) { std::vector::iterator it; int curLine = 0; DEFAULT_FONT(font); Category cat; _categoriesGrid->CreateGrid(0, NUMBER_COLS_CATEGORY); _categoriesGrid->SetRowLabelSize(0); _categoriesGrid->SetDefaultCellFont(font); _categoriesGrid->SetColLabelValue(CATEGORY_NAME, _("Name")); _categoriesGrid->SetColLabelValue(CATEGORY_BACKGROUND_COLOR, _("Background color")); _categoriesGrid->SetColLabelValue(CATEGORY_FOREGROUND_COLOR, _("Foreground color")); _categoriesGrid->SetColLabelValue(CATEGORY_FONT, _("Font")); _categoriesGrid->SetColLabelValue(CATEGORY_DELETE, _("Delete")); for (it=user->_categories.begin(); it!=user->_categories.end(); it++, curLine++) { _categoriesGrid->AppendRows(); AddCategory(curLine, *it); } _categoriesGrid->SetReadOnly(0, CATEGORY_NAME, true); _categoriesGrid->SetReadOnly(0, CATEGORY_DELETE, true); cat.id = wxT("0"); _categoriesGrid->AppendRows(); AddCategory(curLine, cat); } void PreferencesPanel::AddCategory(int line, Category cat) { User* user = _kiss->GetUser(); if (cat.id != wxT("0")) { _categoriesGrid->SetCellValue(line, CATEGORY_NAME, wxGetTranslation(cat.name)); SET_ROW_COLOR(line, cat.backcolor, cat.forecolor); if (line) { _categoriesGrid->SetCellRenderer(line, CATEGORY_DELETE, new wxGridCellBoolRenderer ()); _categoriesGrid->SetCellEditor(line, CATEGORY_DELETE, new wxGridCellBoolEditor ()); } _categoriesGrid->SetCellRenderer(line, CATEGORY_BACKGROUND_COLOR, new wxGridCellButtonRenderer (wxT("..."))); _categoriesGrid->SetCellRenderer(line, CATEGORY_FOREGROUND_COLOR, new wxGridCellButtonRenderer (wxT("..."))); _categoriesGrid->SetCellRenderer(line, CATEGORY_FONT, new wxGridCellButtonRenderer (wxT("..."))); _categoriesGrid->SetCellEditor(line, CATEGORY_BACKGROUND_COLOR, new wxGridCellButtonEditor (wxT("..."))); _categoriesGrid->SetCellEditor(line, CATEGORY_FOREGROUND_COLOR, new wxGridCellButtonEditor (wxT("..."))); _categoriesGrid->SetCellEditor(line, CATEGORY_FONT, new wxGridCellButtonEditor (wxT("..."))); if (cat.font.Length()) { wxFont font = user->GetCategoryFont(cat.id); SET_ROW_FONT(line, font); } _categoriesGrid->SetCellAlignment(line, CATEGORY_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); } else { _categoriesGrid->SetReadOnly(line, CATEGORY_BACKGROUND_COLOR, true); _categoriesGrid->SetReadOnly(line, CATEGORY_FOREGROUND_COLOR, true); _categoriesGrid->SetReadOnly(line, CATEGORY_FONT, true); _categoriesGrid->SetReadOnly(line, CATEGORY_DELETE, true); SET_ROW_COLOR(line, view::OWN_GREEN, *wxBLACK); _categoriesGrid->AutoSizeColumns(true); } } void PreferencesPanel::InitLanguage(User* user) { int i, select=0; for (i=0; iAppend(SupportedLanguages::languages[i].name, wxBitmap(SupportedLanguages::languages[i].icon, wxBITMAP_TYPE_PNG)); if (SupportedLanguages::languages[i].language == _wxUI->_language) select = i; } _language->Select(select); } void PreferencesPanel::InitOperationOrder(User* user) { _operationOrder->Append(_("Ascending")); _operationOrder->Append(_("Descending")); if (user->_preferences[wxT("operation_order")] == wxT("ASC")) _operationOrder->Select(0); else _operationOrder->Select(1); } void PreferencesPanel::OnAccountModified(wxGridEvent& event) { int op_complete = 1; wxString value ; Account new_account, account; User* user = _kiss->GetUser(); int row = event.GetRow(); int col = event.GetCol(); static bool inModification = false ; int i, a; if (inModification) return; inModification = true; value = _accountsGrid->GetCellValue(row, ACCOUNT_NAME); if (value.Length()) { new_account.name = value; op_complete--; } value = _accountsGrid->GetCellValue(row, ACCOUNT_NUMBER); if (value.Length()) { new_account.number = value; op_complete--; } value = _accountsGrid->GetCellValue(row, ACCOUNT_DEFAULT); if (value.Length() && value != wxT("0")) new_account._default = true; else new_account._default = false; value = _accountsGrid->GetCellValue(row, ACCOUNT_VIRTUAL); if (value.Length() && value != wxT("0")) new_account._virtual = true; else new_account._virtual = false; value = _accountsGrid->GetCellValue(row, ACCOUNT_BLOCKED); if (value.Length() && value != wxT("0")) new_account.blocked = true; else new_account.blocked = false; // Account modification if (user->GetAccountsNumber() && row < user->GetAccountsNumber()) { new_account.id = user->_accounts[row].id; new_account.shared = user->_accounts[row].shared; new_account.is_owner = user->_accounts[row].is_owner; if (col == ACCOUNT_DELETE) { if (user->_accounts.size() == 1) { wxMessageBox(_("It must be at least one account !"), _("Error"), wxICON_ERROR | wxOK); _accountsGrid->SetCellValue(row, col, wxT("0")); return; } wxString *accounts = new wxString[user->GetAccountsNumber()]; accounts[0] = _("None"); a = 0; for(i=0; i < user->GetAccountsNumber(); i++) if (user->_accounts[i].id != new_account.id) accounts[++a] = user->_accounts[i].name; wxSingleChoiceDialog dialog(_wxUI, _("Wich account will replace this one ?"), wxT("KissCount"), user->GetAccountsNumber(), accounts); if (dialog.ShowModal() == wxID_CANCEL) { _accountsGrid->SetCellValue(row, col, wxT("0")); } else { _accountsGrid->DeleteRows(row, 1); i = dialog.GetSelection(); _kiss->DeleteAccount(new_account, (!i) ? wxT("0") : user->GetAccountId(accounts[i])); } if (user->_accounts.size() == 1) { user->_accounts[0]._default = true; _kiss->UpdateAccount(user->_accounts[0]); _accountsGrid->SetCellValue(0, ACCOUNT_DEFAULT, wxT("1")); } Fit(); inModification = false; _wxUI->NeedReload(); return; } if (col == ACCOUNT_DEFAULT) { for (i=0; iGetAccountsNumber(); i++) { if (i != row) { account = user->_accounts[i]; if (account._default) { account._default = false; _kiss->UpdateAccount(account); _accountsGrid->SetCellValue(i, ACCOUNT_DEFAULT, wxT("")); break; } } } } if (col == ACCOUNT_NAME) { value = user->GetAccountId(new_account.name); if (value != wxT("0") && value != new_account.id) { wxMessageBox(_("Account ")+new_account.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK ); _accountsGrid->SetCellValue(row, ACCOUNT_NAME, user->_accounts[row].name); inModification = false; return ; } } _kiss->UpdateAccount(new_account); } // New account else { if (op_complete) { inModification = false; return ; } if (user->GetAccountId(new_account.name) != wxT("0")) { wxMessageBox(_("Account ")+new_account.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK ); inModification = false; return ; } new_account.shared = false; new_account.blocked = false; new_account.is_owner = true; new_account._virtual = false; AddAccount(row, new_account); _kiss->AddAccount(new_account); _accountsGrid->AppendRows(); new_account.id = wxT("0"); AddAccount(row+1, new_account); } Fit(); _wxUI->NeedReload(); inModification = false; } void PreferencesPanel::OnAccountCellChanged(wxGridEvent& event) { User* user = _kiss->GetUser(); int row = event.GetRow(); std::map::iterator it; int i; bool own; wxString owner; if (!_sharedWith || _curAccountRow == row) { event.Skip(); return ; } _curAccountRow = row ; if (row >= (int) user->_accounts.size()) { for(i=0; i<(int)_sharedWith->GetCount(); i++) _sharedWith->Check(i, false); own = false; } else { _sharedOwners = _kiss->getSharedAccountOwners(user->_accounts[row].id); owner = _kiss->getSharedAccountOwner(user->_accounts[row].id); for(i=0; i<(int)_sharedWith->GetCount(); i++) { _sharedWith->Check(i, _sharedOwners[_sharedWith->GetString(i)].Length() > 0 || _sharedWith->GetString(i) == owner); } own = user->_accounts[row].is_owner; } _sharedWith->Enable(own); event.Skip(); } void PreferencesPanel::OnSharedChange(wxCommandEvent& event) { User* user = _kiss->GetUser(); // Event is fired before change if (_sharedWith->IsChecked(event.GetSelection())) { if (!user->_accounts[_curAccountRow].shared) _accountsGrid->SetCellValue(_curAccountRow, ACCOUNT_NUMBER, user->_accounts[_curAccountRow].number + wxT("*")); _kiss->AddSharedAccount(user->_accounts[_curAccountRow], _sharedWith->GetString(event.GetSelection())); } else { _kiss->RemoveSharedAccount(user->_accounts[_curAccountRow], _sharedOwners[_sharedWith->GetString( event.GetSelection())]); if (!user->_accounts[_curAccountRow].shared) _accountsGrid->SetCellValue(_curAccountRow, ACCOUNT_NUMBER, user->_accounts[_curAccountRow].number); } _wxUI->NeedReload(); event.Skip(); } void PreferencesPanel::OnCategoryModified(wxGridEvent& event) { int op_complete = 1; wxString value; User* user = _kiss->GetUser(); int row = event.GetRow(); int col = event.GetCol(); static bool inModification = false ; Category new_cat, cat_tmp; int i, a; if (inModification) return; inModification = true; if (event.GetCol() == CATEGORY_BACKGROUND_COLOR) { wxColourData color; color.SetColour(wxColor(user->_categories[row].backcolor)); wxColourDialog dial(this, &color); if (dial.ShowModal() == wxID_OK) { user->_categories[row].backcolor = dial.GetColourData().GetColour(); _kiss->UpdateCategory(user->_categories[row]); SET_ROW_COLOR(row, user->_categories[row].backcolor, user->_categories[row].forecolor); _wxUI->NeedReload(); } inModification = false ; return ; } if (event.GetCol() == CATEGORY_FOREGROUND_COLOR) { wxColourData color; color.SetColour(wxColor(user->_categories[row].forecolor)); wxColourDialog dial(this, &color); if (dial.ShowModal() == wxID_OK) { user->_categories[row].forecolor = dial.GetColourData().GetColour(); _kiss->UpdateCategory(user->_categories[row]); SET_ROW_COLOR(row, user->_categories[row].backcolor, user->_categories[row].forecolor); _wxUI->NeedReload(); } inModification = false ; return ; } if (event.GetCol() == CATEGORY_FONT) { wxFontData font; font.SetInitialFont(_kiss->ExtractFont(user->_categories[row].font)); wxFontDialog dial(this, font); if (dial.ShowModal() == wxID_OK) { font = dial.GetFontData(); user->_categories[row].font = _kiss->CompactFont(font.GetChosenFont()); _kiss->UpdateCategory(user->_categories[row]); SET_ROW_FONT(row, font.GetChosenFont()); _wxUI->NeedReload(); } inModification = false ; return ; } value = _categoriesGrid->GetCellValue(row, CATEGORY_NAME); if (value.Length()) { new_cat.name = value; op_complete--; } new_cat.backcolor = _categoriesGrid->GetCellBackgroundColour(row, col); new_cat.forecolor = _categoriesGrid->GetCellTextColour(row, col); new_cat.font = wxT(""); new_cat.parent = wxT("0"); // Categories modification if (user->GetCategoriesNumber() && row < user->GetCategoriesNumber()) { new_cat.id = user->_categories[row].id; new_cat.fix_cost = user->_categories[row].fix_cost; if (col == CATEGORY_DELETE) { wxString *categories = new wxString[user->GetCategoriesNumber()]; categories[0] = _("None"); a = 0; for(i=0; i < user->GetCategoriesNumber(); i++) if (user->_categories[i].id != new_cat.id) categories[++a] = wxGetTranslation(user->_categories[i].name); wxSingleChoiceDialog dialog(_wxUI, _("Wich category will replace this one ?"), wxT("KissCount"), user->GetCategoriesNumber(), categories); if (dialog.ShowModal() == wxID_CANCEL) { _categoriesGrid->SetCellValue(row, col, wxT("0")); } else { _categoriesGrid->DeleteRows(row, 1); i = dialog.GetSelection(); _kiss->DeleteCategory(user->_categories[row], (!i) ? wxT("0") : user->GetCategoryId(categories[i])); Fit(); _wxUI->NeedReload(); } inModification = false; return; } value = user->GetCategoryId(new_cat.name); if (value != wxT("0") && value != new_cat.id) { wxMessageBox(_("Category ")+new_cat.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK ); _categoriesGrid->SetCellValue(row, CATEGORY_NAME, user->_categories[row].name); inModification = false; return ; } _kiss->UpdateCategory(new_cat); } // New category else { if (op_complete) { inModification = false; return ; } if (user->GetCategoryId(new_cat.name) != wxT("0")) { wxMessageBox(_("Category ")+new_cat.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK ); inModification = false; return ; } new_cat.fix_cost = false; _kiss->AddCategory(new_cat); AddCategory(row, new_cat); _categoriesGrid->SetReadOnly(row, CATEGORY_BACKGROUND_COLOR, false); _categoriesGrid->SetReadOnly(row, CATEGORY_FOREGROUND_COLOR, false); _categoriesGrid->SetReadOnly(row, CATEGORY_FONT, false); _categoriesGrid->SetReadOnly(row, CATEGORY_DELETE, false); new_cat.id = wxT("0"); _categoriesGrid->AppendRows(); AddCategory(++row, new_cat); } Fit(); _wxUI->NeedReload(); inModification = false; return; } void PreferencesPanel::OnChangeName(wxCommandEvent& event) { User* user = _kiss->GetUser(); wxString name = _name->GetLineText(0); if (name == user->_name) return; if (!name.size()) { wxMessageBox(_("Invalid name"), _("Error"), wxICON_ERROR | wxOK); return; } if (_kiss->UserExists(name)) { wxMessageBox(_("User ") + name + _(" already exists"), _("Error"), wxICON_ERROR | wxOK); return; } _kiss->ChangeName(name); wxMessageBox(_("Name changed"), wxT("KissCount"), wxICON_INFORMATION | wxOK); _wxUI->NeedReload(); _wxUI->SetTitle(_kiss->GetUser()->_name + wxT(" - ") +_("Preferences")); } void PreferencesPanel::OnChangePassword(wxCommandEvent& event) { PasswordDialog p(_kiss, _wxUI); p.ShowModal(); } void PreferencesPanel::OnOperationOrderChange(wxCommandEvent& event) { if (_operationOrder->GetCurrentSelection() == 0) _kiss->SetOperationOrder(wxT("ASC")); else _kiss->SetOperationOrder(wxT("DESC")); _wxUI->NeedReload(); } void PreferencesPanel::OnLanguageChange(wxCommandEvent& event) { wxLanguage language = SupportedLanguages::languages[_language->GetSelection()].language; if (_wxUI->SetLanguage(language) || language == wxLANGUAGE_ENGLISH) { _wxUI->NeedReload(); _kiss->SetLanguage(language); wxMessageBox(_("Language successfully changed, please go to another panel"), _("KissCount"), wxICON_INFORMATION | wxOK); } else wxMessageBox(_("Language not changed"), _("KissCount"), wxICON_ERROR | wxOK); } void PreferencesPanel::OnShow(wxShowEvent& event) { _wxUI->SetTitle(_kiss->GetUser()->_name + _(" - ") + _("Preferences")); } void PreferencesPanel::OnKillMe(wxCommandEvent& event) { User* user = _kiss->GetUser(); wxMessageDialog dialog(_wxUI, _("Are you sure want to delete ")+user->_name+_(" profil ?"), wxT("KissCount"), wxYES_NO); if (dialog.ShowModal() == wxID_NO) { return; } _kiss->KillMe(); }