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);
37 void frmContactEditorOrganisations::UpdateSortAs( wxCommandEvent& event )
40 // Update the predefined SortAs listings.
42 // Clear out the options for the combo box.
45 cmbSortAs->Append(txtOrganisation->GetValue());
47 // See if there are more than one word, if not leave drop down
48 // with the default organisation name.
50 wxStringTokenizer tknOrg(txtOrganisation->GetValue(), wxT(" "));
55 if (tknOrg.CountTokens() > 1){
57 strFirst = tknOrg.GetNextToken();
59 while (tknOrg.HasMoreTokens()){
61 strArrange.Append(tknOrg.GetNextToken());
63 if (tknOrg.CountTokens() != 0){
64 strArrange.Append(wxT(" "));
69 strArrFinal.Append(strArrange);
70 strArrFinal.Append(wxT(", "));
71 strArrFinal.Append(strFirst);
72 cmbSortAs->Append(strArrFinal);
78 void frmContactEditorOrganisations::ProcessAction( wxCommandEvent& event )
85 if (EditorMode == FALSE){
89 // Setup Organisation Name.
91 OrganisationListPtr->insert(std::make_pair(OrganisationListIndex, txtOrganisation->GetValue()));
93 // Setup Organisation Type.
95 if (EditSectionType == CE_GENERAL){
97 OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("")));
99 } else if (EditSectionType == CE_HOME) {
101 OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("home")));
103 } else if (EditSectionType == CE_WORK) {
105 OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("work")));
109 // Setup Organisation SortAs.
112 OrganisationListSortAsPtr->insert(std::make_pair(OrganisationListIndex, cmbSortAs->GetValue()));
114 // Setup Organisation Priority.
116 if (priorityCtrl->IsPriorityChecked()){
118 OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, priorityCtrl->GetValue()));
122 OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, 0));
130 coldata.SetId(OrganisationListIndex);
131 coldata.SetData(OrganisationListIndex);
132 coldata.SetText(txtOrganisation->GetValue());
133 ListCtrlIndex = OrganisationListCtrlPtr->InsertItem(coldata);
135 if (priorityCtrl->IsPriorityChecked()){
137 OrganisationListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
143 } else if (EditorMode == TRUE) {
145 long longSelected = -1;
148 // Update Organisation Name.
150 OrganisationListPtr->erase(OrganisationListIndex);
151 OrganisationListPtr->insert(std::make_pair(OrganisationListIndex, txtOrganisation->GetValue()));
153 // Update Organisation SortAs.
156 OrganisationListSortAsPtr->erase(OrganisationListIndex);
157 OrganisationListSortAsPtr->insert(std::make_pair(OrganisationListIndex, cmbSortAs->GetValue()));
159 // Update Organisation Priority.
161 OrganisationListPrefPtr->erase(OrganisationListIndex);
163 if (priorityCtrl->IsPriorityChecked()){
165 OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, priorityCtrl->GetValue()));
169 OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, 0));
175 longSelected = OrganisationListCtrlPtr->GetNextItem(longSelected,
177 wxLIST_STATE_SELECTED);
179 if (longSelected == -1){
183 OrganisationListCtrlPtr->SetItem(longSelected, 0, txtOrganisation->GetValue());
185 if (priorityCtrl->IsPriorityChecked()){
187 OrganisationListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
191 OrganisationListCtrlPtr->SetItem(longSelected, 1, wxT(""));
201 void frmContactEditorOrganisations::SetEditorMode(bool EditMode, SectionType SectType)
204 // Set the editor mode.
206 // Set if the editor is adding or editing an address.
210 if (EditMode == FALSE){
213 btnAction->SetLabel(_("Add"));
214 this->SetTitle(_("Add Organisation"));
216 } else if (EditMode == TRUE){
219 btnAction->SetLabel(_("Modify"));
220 this->SetTitle(_("Modify Organisation"));
222 // Load the data into the form.
224 std::map<int,int>::iterator intiter;
225 std::map<int,wxString>::iterator striter;
228 // Get the organisation name.
230 striter = OrganisationListPtr->find(OrganisationListIndex);
232 if (striter->first == OrganisationListIndex){
234 strValue = striter->second;
238 txtOrganisation->SetValue(strValue);
242 // Get the organisation sort as.
244 striter = OrganisationListSortAsPtr->find(OrganisationListIndex);
246 if (striter->first == OrganisationListIndex &&
247 striter != OrganisationListSortAsPtr->end()){
249 strValue = striter->second;
253 cmbSortAs->SetValue(strValue);
255 // Get the organisation priority.
257 intiter = OrganisationListPrefPtr->find(OrganisationListIndex);
259 if (intiter->first == OrganisationListIndex && intiter->second > 0 &&
260 intiter != OrganisationListPrefPtr->end()){
262 priorityCtrl->SetValue(intiter->second);
263 priorityCtrl->EnablePriority(true);
269 EditSectionType = SectType;
273 void frmContactEditorOrganisations::CloseWindow( wxCommandEvent& event )
282 void frmContactEditorOrganisations::SetupPointers(std::map<int, wxString> *OrganisationList,
283 std::map<int, wxString> *OrganisationListLanguage,
284 std::map<int, wxString> *OrganisationListSortAs,
285 std::map<int, wxString> *OrganisationListAltID,
286 std::map<int, wxString> *OrganisationListPID,
287 std::map<int, wxString> *OrganisationListType,
288 std::map<int, wxString> *OrganisationListTokens,
289 std::map<int, int> *OrganisationListPref,
290 wxListCtrl *OrganisationListCtrl,
291 int OrganisationIndex )
294 // Setup the pointers.
296 OrganisationListPtr = OrganisationList;
297 OrganisationListLanguagePtr = OrganisationListLanguage;
298 OrganisationListSortAsPtr = OrganisationListSortAs;
299 OrganisationListAltIDPtr = OrganisationListAltID;
300 OrganisationListPIDPtr = OrganisationListPID;
301 OrganisationListTypePtr = OrganisationListType;
302 OrganisationListTokensPtr = OrganisationListTokens;
303 OrganisationListPrefPtr = OrganisationListPref;
304 OrganisationListCtrlPtr = OrganisationListCtrl;
305 OrganisationListIndex = OrganisationIndex;