Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Removed commented out form code from ADR in ContactDataObject.
[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         EditorMode = FALSE;
28         sliPriority->Disable();
29 }
31 void frmContactEditorOrganisations::UpdateSortAs( wxCommandEvent& event )
32 {
34         // Clear out the options for the combo box.
35         
36         cmbSortAs->Clear();
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.
41         
42         wxStringTokenizer tknOrg(txtOrganisation->GetValue(), wxT(" "));
43         wxString strArrange;
44         wxString strFirst;
45         wxString strArrFinal;
46         
47         if (tknOrg.CountTokens() > 1){
48         
49                 strFirst = tknOrg.GetNextToken();
50                 
51                 while (tknOrg.HasMoreTokens()){
52                 
53                         strArrange.Append(tknOrg.GetNextToken());
54                         
55                         if (tknOrg.CountTokens() != 0){
56                                 strArrange.Append(wxT(" "));
57                         }
58                 
59                 }
60         
61                 strArrFinal.Append(strArrange);
62                 strArrFinal.Append(wxT(", "));
63                 strArrFinal.Append(strFirst);
64                 cmbSortAs->Append(strArrFinal);
65         
66         }
68 }
70 void frmContactEditorOrganisations::EnablePriority( wxCommandEvent& event )
71 {
72         if (chkUsePref->IsChecked()){
73                 sliPriority->Enable();
74         } else {
75                 sliPriority->Disable();
76         }
77 }
79 void frmContactEditorOrganisations::ProcessAction( wxCommandEvent& event )
80 {
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 (chkUsePref->IsChecked()){
116                 
117                         OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, sliPriority->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 (chkUsePref->IsChecked()){
135                 
136                         OrganisationListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->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 (chkUsePref->IsChecked()){
163                 
164                         OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, sliPriority->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 (chkUsePref->IsChecked()){
185                 
186                         OrganisationListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->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         // Set if the editor is adding or editing an address.
203         // FALSE = Add
204         // TRUE = Edit
205         
206         if (EditMode == FALSE){
207         
208                 EditorMode = FALSE;
209                 btnAction->SetLabel(_("Add"));
210                 this->SetTitle(_("Add Organisation"));
211         
212         } else if (EditMode == TRUE){
213         
214                 EditorMode = TRUE;
215                 btnAction->SetLabel(_("Modify"));
216                 this->SetTitle(_("Modify Organisation"));               
217                 
218                 // Load the data into the form.
219                 
220                 std::map<int,int>::iterator intiter;
221                 std::map<int,wxString>::iterator striter;               
222                 wxString strValue;              
223                         
224                 // Get the organisation name.
225                 
226                 striter = OrganisationListPtr->find(OrganisationListIndex);
227                  
228                 if (striter->first == OrganisationListIndex){
229                 
230                         strValue = striter->second;
231                 
232                 }
233                 
234                 txtOrganisation->SetValue(strValue);
235                 
236                 strValue.Clear();
237                 
238                 // Get the organisation sort as.
239                 
240                 striter = OrganisationListSortAsPtr->find(OrganisationListIndex);
241                  
242                 if (striter->first == OrganisationListIndex){
243                 
244                         strValue = striter->second;
245                 
246                 }
247                 
248                 cmbSortAs->SetValue(strValue);          
249                 
250                 // Get the organisation priority.
251                 
252                 intiter = OrganisationListPrefPtr->find(OrganisationListIndex);         
253                 
254                 if (intiter->first == OrganisationListIndex && intiter->second > 0){
255                 
256                         sliPriority->SetValue(intiter->second);
257                         sliPriority->Enable();
258                         chkUsePref->SetValue(TRUE);
259                 
260                 }
261                 
262         }
263         
264         EditSectionType = SectType;
265         
268 void frmContactEditorOrganisations::CloseWindow( wxCommandEvent& event )
270         this->Close();
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;
295         
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