Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditor: Stop XAB crashing when pressing Modify/Delete
[xestiaab/.git] / source / contacteditor / frmContactEditorOrganisations.cpp
1 // frmContactEditorOrganisation.cpp - frmContactEditorOrganisation form.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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 )
24 :
25 frmContactEditorOrganisationsADT( parent )
26 {
27         
28         // Setup the window.
29         
30         EditorMode = FALSE;
31         priorityCtrl = new XABPriorityCtrl(tabGeneral);
32         szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
33         
34 }
36 void frmContactEditorOrganisations::UpdateSortAs( wxCommandEvent& event )
37 {
39         // Update the predefined SortAs listings.
40         
41         // Clear out the options for the combo box.
42         
43         cmbSortAs->Clear();
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.
48         
49         wxStringTokenizer tknOrg(txtOrganisation->GetValue(), wxT(" "));
50         wxString strArrange;
51         wxString strFirst;
52         wxString strArrFinal;
53         
54         if (tknOrg.CountTokens() > 1){
55         
56                 strFirst = tknOrg.GetNextToken();
57                 
58                 while (tknOrg.HasMoreTokens()){
59                 
60                         strArrange.Append(tknOrg.GetNextToken());
61                         
62                         if (tknOrg.CountTokens() != 0){
63                                 strArrange.Append(wxT(" "));
64                         }
65                 
66                 }
67         
68                 strArrFinal.Append(strArrange);
69                 strArrFinal.Append(wxT(", "));
70                 strArrFinal.Append(strFirst);
71                 cmbSortAs->Append(strArrFinal);
72         
73         }
75 }
77 void frmContactEditorOrganisations::ProcessAction( wxCommandEvent& event )
78 {
80         // Process action.
81         
82         long ListCtrlIndex;
83         
84         if (EditorMode == FALSE){
86                 wxString strValue;
87         
88                 // Setup Organisation Name.
89                 
90                 OrganisationListPtr->insert(std::make_pair(OrganisationListIndex, txtOrganisation->GetValue()));
92                 // Setup Organisation Type.
94                 if (EditSectionType == CE_GENERAL){
95                 
96                         OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("")));
97                 
98                 } else if (EditSectionType == CE_HOME) {
99                 
100                         OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("home")));
101                 
102                 } else if (EditSectionType == CE_WORK) {
103                 
104                         OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("work")));
105                 
106                 }
107                 
108                 // Setup Organisation SortAs.
109                 
110                 strValue.Clear();
111                 OrganisationListSortAsPtr->insert(std::make_pair(OrganisationListIndex, cmbSortAs->GetValue()));
112                 
113                 // Setup Organisation Priority.
114                 
115                 if (priorityCtrl->IsPriorityChecked()){
116                 
117                         OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, priorityCtrl->GetValue()));
118                 
119                 } else {
120                 
121                         OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, 0));
122                 
123                 }
124                 
125                 // Add to form.
126                 
127                 wxListItem coldata;
128                 
129                 coldata.SetId(OrganisationListIndex);
130                 coldata.SetData(OrganisationListIndex);
131                 coldata.SetText(txtOrganisation->GetValue());
132                 ListCtrlIndex = OrganisationListCtrlPtr->InsertItem(coldata);
133                 
134                 if (priorityCtrl->IsPriorityChecked()){
135                 
136                         OrganisationListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
137                 
138                 }
139                 
140                 this->Close();
141                 
142         } else if (EditorMode == TRUE) {
143         
144                 long longSelected = -1;
145                 wxString strValue;      
146         
147                 // Update Organisation Name.
148                 
149                 OrganisationListPtr->erase(OrganisationListIndex);
150                 OrganisationListPtr->insert(std::make_pair(OrganisationListIndex, txtOrganisation->GetValue()));
151                 
152                 // Update Organisation SortAs.
153                 
154                 strValue.Clear();
155                 OrganisationListSortAsPtr->erase(OrganisationListIndex);
156                 OrganisationListSortAsPtr->insert(std::make_pair(OrganisationListIndex, cmbSortAs->GetValue()));
157                 
158                 // Update Organisation Priority.
159                 
160                 OrganisationListPrefPtr->erase(OrganisationListIndex);
161                 
162                 if (priorityCtrl->IsPriorityChecked()){
163                 
164                         OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, priorityCtrl->GetValue()));
165                 
166                 } else {
167                 
168                         OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, 0));
169                 
170                 }
171                 
172                 // Update form.
173                 
174                 longSelected = OrganisationListCtrlPtr->GetNextItem(longSelected, 
175                         wxLIST_NEXT_ALL,
176                         wxLIST_STATE_SELECTED);
177                         
178                 if (longSelected == -1){
179                         return;
180                 }               
181                 
182                 OrganisationListCtrlPtr->SetItem(longSelected, 0, txtOrganisation->GetValue());
183                 
184                 if (priorityCtrl->IsPriorityChecked()){
185                 
186                         OrganisationListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
187                 
188                 } else {
189                 
190                         OrganisationListCtrlPtr->SetItem(longSelected, 1, wxT(""));
191                 
192                 }
193                 
194                 this->Close();  
195         
196         }
200 void frmContactEditorOrganisations::SetEditorMode(bool EditMode, SectionType SectType)
202         
203         // Set the editor mode.
204         
205         // Set if the editor is adding or editing an address.
206         // FALSE = Add
207         // TRUE = Edit
208         
209         if (EditMode == FALSE){
210         
211                 EditorMode = FALSE;
212                 btnAction->SetLabel(_("Add"));
213                 this->SetTitle(_("Add Organisation"));
214         
215         } else if (EditMode == TRUE){
216         
217                 EditorMode = TRUE;
218                 btnAction->SetLabel(_("Modify"));
219                 this->SetTitle(_("Modify Organisation"));               
220                 
221                 // Load the data into the form.
222                 
223                 std::map<int,int>::iterator intiter;
224                 std::map<int,wxString>::iterator striter;               
225                 wxString strValue;              
226                         
227                 // Get the organisation name.
228                 
229                 striter = OrganisationListPtr->find(OrganisationListIndex);
230                  
231                 if (striter->first == OrganisationListIndex){
232                 
233                         strValue = striter->second;
234                 
235                 }
236                 
237                 txtOrganisation->SetValue(strValue);
238                 
239                 strValue.Clear();
240                 
241                 // Get the organisation sort as.
242                 
243                 striter = OrganisationListSortAsPtr->find(OrganisationListIndex);
244                  
245                 if (striter->first == OrganisationListIndex && 
246                   striter != OrganisationListSortAsPtr->end()){
247                 
248                         strValue = striter->second;
249                 
250                 }
251                 
252                 cmbSortAs->SetValue(strValue);          
253                 
254                 // Get the organisation priority.
255                 
256                 intiter = OrganisationListPrefPtr->find(OrganisationListIndex);         
257                 
258                 if (intiter->first == OrganisationListIndex && intiter->second > 0 &&
259                   intiter != OrganisationListPrefPtr->end()){
260                 
261                         priorityCtrl->SetValue(intiter->second);
262                         priorityCtrl->EnablePriority(true);
263                 
264                 }
265                 
266         }
267         
268         EditSectionType = SectType;
269         
272 void frmContactEditorOrganisations::CloseWindow( wxCommandEvent& event )
274         
275         // Close the window.
276         
277         this->Close();
278         
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.
294         
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;
305         
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy