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 )
31 priorityCtrl = new XABPriorityCtrl(tabGeneral);
32 szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
36 void frmContactEditorOrganisations::UpdateSortAs( wxCommandEvent& event )
39 // Update the predefined SortAs listings.
41 // Clear out the options for the combo box.
44 cmbSortAs->Append(txtOrganisation->GetValue());
46 // See if there are more than one word, if not leave drop down
47 // with the default organisation name.
49 wxStringTokenizer tknOrg(txtOrganisation->GetValue(), wxT(" "));
54 if (tknOrg.CountTokens() > 1){
56 strFirst = tknOrg.GetNextToken();
58 while (tknOrg.HasMoreTokens()){
60 strArrange.Append(tknOrg.GetNextToken());
62 if (tknOrg.CountTokens() != 0){
63 strArrange.Append(wxT(" "));
68 strArrFinal.Append(strArrange);
69 strArrFinal.Append(wxT(", "));
70 strArrFinal.Append(strFirst);
71 cmbSortAs->Append(strArrFinal);
77 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 (priorityCtrl->IsPriorityChecked()){
117 OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, priorityCtrl->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 (priorityCtrl->IsPriorityChecked()){
136 OrganisationListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->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 (priorityCtrl->IsPriorityChecked()){
164 OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, priorityCtrl->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 (priorityCtrl->IsPriorityChecked()){
186 OrganisationListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
190 OrganisationListCtrlPtr->SetItem(longSelected, 1, wxT(""));
200 void frmContactEditorOrganisations::SetEditorMode(bool EditMode, SectionType SectType)
203 // Set the editor mode.
205 // Set if the editor is adding or editing an address.
209 if (EditMode == FALSE){
212 btnAction->SetLabel(_("Add"));
213 this->SetTitle(_("Add Organisation"));
215 } else if (EditMode == TRUE){
218 btnAction->SetLabel(_("Modify"));
219 this->SetTitle(_("Modify Organisation"));
221 // Load the data into the form.
223 std::map<int,int>::iterator intiter;
224 std::map<int,wxString>::iterator striter;
227 // Get the organisation name.
229 striter = OrganisationListPtr->find(OrganisationListIndex);
231 if (striter->first == OrganisationListIndex){
233 strValue = striter->second;
237 txtOrganisation->SetValue(strValue);
241 // Get the organisation sort as.
243 striter = OrganisationListSortAsPtr->find(OrganisationListIndex);
245 if (striter->first == OrganisationListIndex &&
246 striter != OrganisationListSortAsPtr->end()){
248 strValue = striter->second;
252 cmbSortAs->SetValue(strValue);
254 // Get the organisation priority.
256 intiter = OrganisationListPrefPtr->find(OrganisationListIndex);
258 if (intiter->first == OrganisationListIndex && intiter->second > 0 &&
259 intiter != OrganisationListPrefPtr->end()){
261 priorityCtrl->SetValue(intiter->second);
262 priorityCtrl->EnablePriority(true);
268 EditSectionType = SectType;
272 void frmContactEditorOrganisations::CloseWindow( wxCommandEvent& event )
281 void frmContactEditorOrganisations::SetupPointers(std::map<int, wxString> *OrganisationList,
282 std::map<int, wxString> *OrganisationListLanguage,
283 std::map<int, wxString> *OrganisationListSortAs,
284 std::map<int, wxString> *OrganisationListAltID,
285 std::map<int, wxString> *OrganisationListPID,
286 std::map<int, wxString> *OrganisationListType,
287 std::map<int, wxString> *OrganisationListTokens,
288 std::map<int, int> *OrganisationListPref,
289 wxListCtrl *OrganisationListCtrl,
290 int OrganisationIndex )
293 // Setup the pointers.
295 OrganisationListPtr = OrganisationList;
296 OrganisationListLanguagePtr = OrganisationListLanguage;
297 OrganisationListSortAsPtr = OrganisationListSortAs;
298 OrganisationListAltIDPtr = OrganisationListAltID;
299 OrganisationListPIDPtr = OrganisationListPID;
300 OrganisationListTypePtr = OrganisationListType;
301 OrganisationListTokensPtr = OrganisationListTokens;
302 OrganisationListPrefPtr = OrganisationListPref;
303 OrganisationListCtrlPtr = OrganisationListCtrl;
304 OrganisationListIndex = OrganisationIndex;