1 // frmContactEditorOrganisation.cpp - frmContactEditorOrganisation form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "frmContactEditorOrganisations.h"
20 #include <wx/tokenzr.h>
21 #include "../common/textprocessing.h"
23 frmContactEditorOrganisations::frmContactEditorOrganisations( wxWindow* parent )
25 frmContactEditorOrganisationsADT( parent )
28 sliPriority->Disable();
31 void frmContactEditorOrganisations::UpdateSortAs( wxCommandEvent& event )
34 // Clear out the options for the combo box.
37 cmbSortAs->Append(txtOrganisation->GetValue());
39 // See if there are more than one word, if not leave drop down
40 // with the default organisation name.
42 wxStringTokenizer tknOrg(txtOrganisation->GetValue(), wxT(" "));
47 if (tknOrg.CountTokens() > 1){
49 strFirst = tknOrg.GetNextToken();
51 while (tknOrg.HasMoreTokens()){
53 strArrange.Append(tknOrg.GetNextToken());
55 if (tknOrg.CountTokens() != 0){
56 strArrange.Append(wxT(" "));
61 strArrFinal.Append(strArrange);
62 strArrFinal.Append(wxT(", "));
63 strArrFinal.Append(strFirst);
64 cmbSortAs->Append(strArrFinal);
70 void frmContactEditorOrganisations::EnablePriority( wxCommandEvent& event )
72 if (chkUsePref->IsChecked()){
73 sliPriority->Enable();
75 sliPriority->Disable();
79 void frmContactEditorOrganisations::ProcessAction( wxCommandEvent& event )
84 if (EditorMode == FALSE){
88 // Setup Organisation Name.
90 OrganisationListPtr->insert(std::make_pair(OrganisationListIndex, txtOrganisation->GetValue()));
92 // Setup Organisation Type.
94 if (EditSectionType == CE_GENERAL){
96 OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("")));
98 } else if (EditSectionType == CE_HOME) {
100 OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("home")));
102 } else if (EditSectionType == CE_WORK) {
104 OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("work")));
108 // Setup Organisation SortAs.
111 OrganisationListSortAsPtr->insert(std::make_pair(OrganisationListIndex, cmbSortAs->GetValue()));
113 // Setup Organisation Priority.
115 if (chkUsePref->IsChecked()){
117 OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, sliPriority->GetValue()));
121 OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, 0));
129 coldata.SetId(OrganisationListIndex);
130 coldata.SetData(OrganisationListIndex);
131 coldata.SetText(txtOrganisation->GetValue());
132 ListCtrlIndex = OrganisationListCtrlPtr->InsertItem(coldata);
134 if (chkUsePref->IsChecked()){
136 OrganisationListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
142 } else if (EditorMode == TRUE) {
144 long longSelected = -1;
147 // Update Organisation Name.
149 OrganisationListPtr->erase(OrganisationListIndex);
150 OrganisationListPtr->insert(std::make_pair(OrganisationListIndex, txtOrganisation->GetValue()));
152 // Update Organisation SortAs.
155 OrganisationListSortAsPtr->erase(OrganisationListIndex);
156 OrganisationListSortAsPtr->insert(std::make_pair(OrganisationListIndex, cmbSortAs->GetValue()));
158 // Update Organisation Priority.
160 OrganisationListPrefPtr->erase(OrganisationListIndex);
162 if (chkUsePref->IsChecked()){
164 OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, sliPriority->GetValue()));
168 OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, 0));
174 longSelected = OrganisationListCtrlPtr->GetNextItem(longSelected,
176 wxLIST_STATE_SELECTED);
178 if (longSelected == -1){
182 OrganisationListCtrlPtr->SetItem(longSelected, 0, txtOrganisation->GetValue());
184 if (chkUsePref->IsChecked()){
186 OrganisationListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
190 OrganisationListCtrlPtr->SetItem(longSelected, 1, wxT(""));
200 void frmContactEditorOrganisations::SetEditorMode(bool EditMode, SectionType SectType)
202 // Set if the editor is adding or editing an address.
206 if (EditMode == FALSE){
209 btnAction->SetLabel(_("Add"));
210 this->SetTitle(_("Add Organisation"));
212 } else if (EditMode == TRUE){
215 btnAction->SetLabel(_("Modify"));
216 this->SetTitle(_("Modify Organisation"));
218 // Load the data into the form.
220 std::map<int,int>::iterator intiter;
221 std::map<int,wxString>::iterator striter;
224 // Get the organisation name.
226 striter = OrganisationListPtr->find(OrganisationListIndex);
228 if (striter->first == OrganisationListIndex){
230 strValue = striter->second;
234 txtOrganisation->SetValue(strValue);
238 // Get the organisation sort as.
240 striter = OrganisationListSortAsPtr->find(OrganisationListIndex);
242 if (striter->first == OrganisationListIndex){
244 strValue = striter->second;
248 cmbSortAs->SetValue(strValue);
250 // Get the organisation priority.
252 intiter = OrganisationListPrefPtr->find(OrganisationListIndex);
254 if (intiter->first == OrganisationListIndex && intiter->second > 0){
256 sliPriority->SetValue(intiter->second);
257 sliPriority->Enable();
258 chkUsePref->SetValue(TRUE);
264 EditSectionType = SectType;
268 void frmContactEditorOrganisations::CloseWindow( wxCommandEvent& event )
273 void frmContactEditorOrganisations::SetupPointers(std::map<int, wxString> *OrganisationList,
274 std::map<int, wxString> *OrganisationListLanguage,
275 std::map<int, wxString> *OrganisationListSortAs,
276 std::map<int, wxString> *OrganisationListAltID,
277 std::map<int, wxString> *OrganisationListPID,
278 std::map<int, wxString> *OrganisationListType,
279 std::map<int, wxString> *OrganisationListTokens,
280 std::map<int, int> *OrganisationListPref,
281 wxListCtrl *OrganisationListCtrl,
282 int OrganisationIndex )
285 OrganisationListPtr = OrganisationList;
286 OrganisationListLanguagePtr = OrganisationListLanguage;
287 OrganisationListSortAsPtr = OrganisationListSortAs;
288 OrganisationListAltIDPtr = OrganisationListAltID;
289 OrganisationListPIDPtr = OrganisationListPID;
290 OrganisationListTypePtr = OrganisationListType;
291 OrganisationListTokensPtr = OrganisationListTokens;
292 OrganisationListPrefPtr = OrganisationListPref;
293 OrganisationListCtrlPtr = OrganisationListCtrl;
294 OrganisationListIndex = OrganisationIndex;