Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmPreferences: Removed std::cout printing contact background colour
[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         sliPriority->Disable();
32         
33 }
35 void frmContactEditorOrganisations::UpdateSortAs( wxCommandEvent& event )
36 {
38         // Update the predefined SortAs listings.
39         
40         // Clear out the options for the combo box.
41         
42         cmbSortAs->Clear();
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.
47         
48         wxStringTokenizer tknOrg(txtOrganisation->GetValue(), wxT(" "));
49         wxString strArrange;
50         wxString strFirst;
51         wxString strArrFinal;
52         
53         if (tknOrg.CountTokens() > 1){
54         
55                 strFirst = tknOrg.GetNextToken();
56                 
57                 while (tknOrg.HasMoreTokens()){
58                 
59                         strArrange.Append(tknOrg.GetNextToken());
60                         
61                         if (tknOrg.CountTokens() != 0){
62                                 strArrange.Append(wxT(" "));
63                         }
64                 
65                 }
66         
67                 strArrFinal.Append(strArrange);
68                 strArrFinal.Append(wxT(", "));
69                 strArrFinal.Append(strFirst);
70                 cmbSortAs->Append(strArrFinal);
71         
72         }
74 }
76 void frmContactEditorOrganisations::EnablePriority( wxCommandEvent& event )
77 {
78         
79         // Enable/disable the priority setting.
80         
81         if (chkUsePref->IsChecked()){
82                 sliPriority->Enable();
83         } else {
84                 sliPriority->Disable();
85         }
86         
87 }
89 void frmContactEditorOrganisations::ProcessAction( wxCommandEvent& event )
90 {
92         // Process action.
93         
94         long ListCtrlIndex;
95         
96         if (EditorMode == FALSE){
98                 wxString strValue;
99         
100                 // Setup Organisation Name.
101                 
102                 OrganisationListPtr->insert(std::make_pair(OrganisationListIndex, txtOrganisation->GetValue()));
104                 // Setup Organisation Type.
106                 if (EditSectionType == CE_GENERAL){
107                 
108                         OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("")));
109                 
110                 } else if (EditSectionType == CE_HOME) {
111                 
112                         OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("home")));
113                 
114                 } else if (EditSectionType == CE_WORK) {
115                 
116                         OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("work")));
117                 
118                 }
119                 
120                 // Setup Organisation SortAs.
121                 
122                 strValue.Clear();
123                 OrganisationListSortAsPtr->insert(std::make_pair(OrganisationListIndex, cmbSortAs->GetValue()));
124                 
125                 // Setup Organisation Priority.
126                 
127                 if (chkUsePref->IsChecked()){
128                 
129                         OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, sliPriority->GetValue()));
130                 
131                 } else {
132                 
133                         OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, 0));
134                 
135                 }
136                 
137                 // Add to form.
138                 
139                 wxListItem coldata;
140                 
141                 coldata.SetId(OrganisationListIndex);
142                 coldata.SetData(OrganisationListIndex);
143                 coldata.SetText(txtOrganisation->GetValue());
144                 ListCtrlIndex = OrganisationListCtrlPtr->InsertItem(coldata);
145                 
146                 if (chkUsePref->IsChecked()){
147                 
148                         OrganisationListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
149                 
150                 }
151                 
152                 this->Close();
153                 
154         } else if (EditorMode == TRUE) {
155         
156                 long longSelected = -1;
157                 wxString strValue;      
158         
159                 // Update Organisation Name.
160                 
161                 OrganisationListPtr->erase(OrganisationListIndex);
162                 OrganisationListPtr->insert(std::make_pair(OrganisationListIndex, txtOrganisation->GetValue()));
163                 
164                 // Update Organisation SortAs.
165                 
166                 strValue.Clear();
167                 OrganisationListSortAsPtr->erase(OrganisationListIndex);
168                 OrganisationListSortAsPtr->insert(std::make_pair(OrganisationListIndex, cmbSortAs->GetValue()));
169                 
170                 // Update Organisation Priority.
171                 
172                 OrganisationListPrefPtr->erase(OrganisationListIndex);
173                 
174                 if (chkUsePref->IsChecked()){
175                 
176                         OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, sliPriority->GetValue()));
177                 
178                 } else {
179                 
180                         OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, 0));
181                 
182                 }
183                 
184                 // Update form.
185                 
186                 longSelected = OrganisationListCtrlPtr->GetNextItem(longSelected, 
187                         wxLIST_NEXT_ALL,
188                         wxLIST_STATE_SELECTED);
189                         
190                 if (longSelected == -1){
191                         return;
192                 }               
193                 
194                 OrganisationListCtrlPtr->SetItem(longSelected, 0, txtOrganisation->GetValue());
195                 
196                 if (chkUsePref->IsChecked()){
197                 
198                         OrganisationListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
199                 
200                 } else {
201                 
202                         OrganisationListCtrlPtr->SetItem(longSelected, 1, wxT(""));
203                 
204                 }
205                 
206                 this->Close();  
207         
208         }
212 void frmContactEditorOrganisations::SetEditorMode(bool EditMode, SectionType SectType)
214         
215         // Set the editor mode.
216         
217         // Set if the editor is adding or editing an address.
218         // FALSE = Add
219         // TRUE = Edit
220         
221         if (EditMode == FALSE){
222         
223                 EditorMode = FALSE;
224                 btnAction->SetLabel(_("Add"));
225                 this->SetTitle(_("Add Organisation"));
226         
227         } else if (EditMode == TRUE){
228         
229                 EditorMode = TRUE;
230                 btnAction->SetLabel(_("Modify"));
231                 this->SetTitle(_("Modify Organisation"));               
232                 
233                 // Load the data into the form.
234                 
235                 std::map<int,int>::iterator intiter;
236                 std::map<int,wxString>::iterator striter;               
237                 wxString strValue;              
238                         
239                 // Get the organisation name.
240                 
241                 striter = OrganisationListPtr->find(OrganisationListIndex);
242                  
243                 if (striter->first == OrganisationListIndex){
244                 
245                         strValue = striter->second;
246                 
247                 }
248                 
249                 txtOrganisation->SetValue(strValue);
250                 
251                 strValue.Clear();
252                 
253                 // Get the organisation sort as.
254                 
255                 striter = OrganisationListSortAsPtr->find(OrganisationListIndex);
256                  
257                 if (striter->first == OrganisationListIndex && 
258                   striter != OrganisationListSortAsPtr->end()){
259                 
260                         strValue = striter->second;
261                 
262                 }
263                 
264                 cmbSortAs->SetValue(strValue);          
265                 
266                 // Get the organisation priority.
267                 
268                 intiter = OrganisationListPrefPtr->find(OrganisationListIndex);         
269                 
270                 if (intiter->first == OrganisationListIndex && intiter->second > 0 &&
271                   intiter != OrganisationListPrefPtr->end()){
272                 
273                         sliPriority->SetValue(intiter->second);
274                         sliPriority->Enable();
275                         chkUsePref->SetValue(TRUE);
276                 
277                 }
278                 
279         }
280         
281         EditSectionType = SectType;
282         
285 void frmContactEditorOrganisations::CloseWindow( wxCommandEvent& event )
287         
288         // Close the window.
289         
290         this->Close();
291         
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.
307         
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;
318         
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