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 sliPriority->Disable();
35 void frmContactEditorOrganisations::UpdateSortAs( wxCommandEvent& event )
38 // Update the predefined SortAs listings.
40 // Clear out the options for the combo box.
43 cmbSortAs->Append(txtOrganisation->GetValue());
45 // See if there are more than one word, if not leave drop down
46 // with the default organisation name.
48 wxStringTokenizer tknOrg(txtOrganisation->GetValue(), wxT(" "));
53 if (tknOrg.CountTokens() > 1){
55 strFirst = tknOrg.GetNextToken();
57 while (tknOrg.HasMoreTokens()){
59 strArrange.Append(tknOrg.GetNextToken());
61 if (tknOrg.CountTokens() != 0){
62 strArrange.Append(wxT(" "));
67 strArrFinal.Append(strArrange);
68 strArrFinal.Append(wxT(", "));
69 strArrFinal.Append(strFirst);
70 cmbSortAs->Append(strArrFinal);
76 void frmContactEditorOrganisations::EnablePriority( wxCommandEvent& event )
79 // Enable/disable the priority setting.
81 if (chkUsePref->IsChecked()){
82 sliPriority->Enable();
84 sliPriority->Disable();
89 void frmContactEditorOrganisations::ProcessAction( wxCommandEvent& event )
96 if (EditorMode == FALSE){
100 // Setup Organisation Name.
102 OrganisationListPtr->insert(std::make_pair(OrganisationListIndex, txtOrganisation->GetValue()));
104 // Setup Organisation Type.
106 if (EditSectionType == CE_GENERAL){
108 OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("")));
110 } else if (EditSectionType == CE_HOME) {
112 OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("home")));
114 } else if (EditSectionType == CE_WORK) {
116 OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("work")));
120 // Setup Organisation SortAs.
123 OrganisationListSortAsPtr->insert(std::make_pair(OrganisationListIndex, cmbSortAs->GetValue()));
125 // Setup Organisation Priority.
127 if (chkUsePref->IsChecked()){
129 OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, sliPriority->GetValue()));
133 OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, 0));
141 coldata.SetId(OrganisationListIndex);
142 coldata.SetData(OrganisationListIndex);
143 coldata.SetText(txtOrganisation->GetValue());
144 ListCtrlIndex = OrganisationListCtrlPtr->InsertItem(coldata);
146 if (chkUsePref->IsChecked()){
148 OrganisationListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
154 } else if (EditorMode == TRUE) {
156 long longSelected = -1;
159 // Update Organisation Name.
161 OrganisationListPtr->erase(OrganisationListIndex);
162 OrganisationListPtr->insert(std::make_pair(OrganisationListIndex, txtOrganisation->GetValue()));
164 // Update Organisation SortAs.
167 OrganisationListSortAsPtr->erase(OrganisationListIndex);
168 OrganisationListSortAsPtr->insert(std::make_pair(OrganisationListIndex, cmbSortAs->GetValue()));
170 // Update Organisation Priority.
172 OrganisationListPrefPtr->erase(OrganisationListIndex);
174 if (chkUsePref->IsChecked()){
176 OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, sliPriority->GetValue()));
180 OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, 0));
186 longSelected = OrganisationListCtrlPtr->GetNextItem(longSelected,
188 wxLIST_STATE_SELECTED);
190 if (longSelected == -1){
194 OrganisationListCtrlPtr->SetItem(longSelected, 0, txtOrganisation->GetValue());
196 if (chkUsePref->IsChecked()){
198 OrganisationListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
202 OrganisationListCtrlPtr->SetItem(longSelected, 1, wxT(""));
212 void frmContactEditorOrganisations::SetEditorMode(bool EditMode, SectionType SectType)
215 // Set the editor mode.
217 // Set if the editor is adding or editing an address.
221 if (EditMode == FALSE){
224 btnAction->SetLabel(_("Add"));
225 this->SetTitle(_("Add Organisation"));
227 } else if (EditMode == TRUE){
230 btnAction->SetLabel(_("Modify"));
231 this->SetTitle(_("Modify Organisation"));
233 // Load the data into the form.
235 std::map<int,int>::iterator intiter;
236 std::map<int,wxString>::iterator striter;
239 // Get the organisation name.
241 striter = OrganisationListPtr->find(OrganisationListIndex);
243 if (striter->first == OrganisationListIndex){
245 strValue = striter->second;
249 txtOrganisation->SetValue(strValue);
253 // Get the organisation sort as.
255 striter = OrganisationListSortAsPtr->find(OrganisationListIndex);
257 if (striter->first == OrganisationListIndex &&
258 striter != OrganisationListSortAsPtr->end()){
260 strValue = striter->second;
264 cmbSortAs->SetValue(strValue);
266 // Get the organisation priority.
268 intiter = OrganisationListPrefPtr->find(OrganisationListIndex);
270 if (intiter->first == OrganisationListIndex && intiter->second > 0 &&
271 intiter != OrganisationListPrefPtr->end()){
273 sliPriority->SetValue(intiter->second);
274 sliPriority->Enable();
275 chkUsePref->SetValue(TRUE);
281 EditSectionType = SectType;
285 void frmContactEditorOrganisations::CloseWindow( wxCommandEvent& event )
294 void frmContactEditorOrganisations::SetupPointers(std::map<int, wxString> *OrganisationList,
295 std::map<int, wxString> *OrganisationListLanguage,
296 std::map<int, wxString> *OrganisationListSortAs,
297 std::map<int, wxString> *OrganisationListAltID,
298 std::map<int, wxString> *OrganisationListPID,
299 std::map<int, wxString> *OrganisationListType,
300 std::map<int, wxString> *OrganisationListTokens,
301 std::map<int, int> *OrganisationListPref,
302 wxListCtrl *OrganisationListCtrl,
303 int OrganisationIndex )
306 // Setup the pointers.
308 OrganisationListPtr = OrganisationList;
309 OrganisationListLanguagePtr = OrganisationListLanguage;
310 OrganisationListSortAsPtr = OrganisationListSortAs;
311 OrganisationListAltIDPtr = OrganisationListAltID;
312 OrganisationListPIDPtr = OrganisationListPID;
313 OrganisationListTypePtr = OrganisationListType;
314 OrganisationListTokensPtr = OrganisationListTokens;
315 OrganisationListPrefPtr = OrganisationListPref;
316 OrganisationListCtrlPtr = OrganisationListCtrl;
317 OrganisationListIndex = OrganisationIndex;