Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditorAddress: Implemented priority control
[xestiaab/.git] / source / contacteditor / frmContactEditorAddress.cpp
1 // frmContactEditorAddress.cpp - frmContactEditorAddress 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 "frmContactEditorAddress.h"
20 #include <map>
21 #include <wx/tokenzr.h>
23 #include "../common/textprocessing.h"
25 frmContactEditorAddress::frmContactEditorAddress( wxWindow* parent )
26 :
27 frmContactEditorAddressADT( parent )
28 {
29         
30         // Setup the window.
31         
32         EditorMode = FALSE;
33         priorityCtrl = new XABPriorityCtrl(tabGeneral);
34         szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
35         szrGeneral->Layout();
36         
37 }
39 void frmContactEditorAddress::InitAddressEditor( wxInitDialogEvent& event )
40 {
41         // Do nothing with this subroutine at this time.
42 }
44 void frmContactEditorAddress::ProcessData( wxCommandEvent& event )
45 {
47         // Process data.
48         
49         // Check what edit mode we are in and go from there.
50         
51         long ListCtrlIndex;
52         
53         if (EditorMode == FALSE){
54         
55                 // Add the address to the list (maps).
56                 
57                 AddressListPtr->erase(AddressListIndex);                
58                 AddressListPtr->insert(std::make_pair(AddressListIndex, txtAddress->GetValue()));
60                 AddressListTownPtr->erase(AddressListIndex);
61                 AddressListTownPtr->insert(std::make_pair(AddressListIndex, txtTownCity->GetValue()));
63                 AddressListCountyPtr->erase(AddressListIndex);
64                 AddressListCountyPtr->insert(std::make_pair(AddressListIndex, txtCounty->GetValue()));
66                 AddressListPostCodePtr->erase(AddressListIndex);
67                 AddressListPostCodePtr->insert(std::make_pair(AddressListIndex, txtPostCode->GetValue()));
69                 AddressListCountryPtr->erase(AddressListIndex);
70                 AddressListCountryPtr->insert(std::make_pair(AddressListIndex, txtCountry->GetValue()));
71                 
72                 // Add the label to the list (maps).
73                 
74                 wxString LabelData = txtLabel->GetValue();
75                 LabelData.Prepend("\"");
76                 LabelData.Append("\"");
77                 AddressListLabelPtr->insert(std::make_pair(AddressListIndex, LabelData));
78                 
79                 // Add the language to the list (maps).
80                 
81                 AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue()));
82                 
83                 // No AltIDs at present.
84                 
85                 // No PIDs at present.
86                 
87                 // There are no tokens for a new address to add so this can be
88                 // ignored for the time being.
89                 
90                 // Add the Geopositioning to the list (maps).
91                 
92                 AddressListGeoPtr->insert(std::make_pair(AddressListIndex, txtGeo->GetValue()));
93                 
94                 // Add the Timezone to the list (maps).
96                 AddressListTimezonePtr->insert(std::make_pair(AddressListIndex, txtTimezone->GetValue()));
97                 
98                 if (EditSectionType == CE_GENERAL){
99                 
100                         AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("")));
101                 
102                 } else if (EditSectionType == CE_HOME) {
103                 
104                         AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("home")));
105                 
106                 } else if (EditSectionType == CE_WORK) {
107                 
108                         AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("work")));
109                 
110                 }
112                 // Add the mediatype to the list (maps).
113                 
114                 AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain")));
115                 
116                 if (priorityCtrl->IsPriorityChecked()){
117                 
118                         AddressListPrefPtr->insert(std::make_pair(AddressListIndex, priorityCtrl->GetValue()));
119                 
120                 } else {
121                 
122                         AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0));                
123                 
124                 }
125                 
126                 // Add to the form.
127                 
128                 wxListItem coldata;
129                 
130                 coldata.SetId(AddressListIndex);
131                 coldata.SetData(AddressListIndex);              
132                 coldata.SetText(txtAddress->GetValue());
133                 ListCtrlIndex = AddressListCtrlPtr->InsertItem(coldata);
134                 
135                 AddressListCtrlPtr->SetItem(ListCtrlIndex, 1, txtTownCity->GetValue());
136                 AddressListCtrlPtr->SetItem(ListCtrlIndex, 2, txtCounty->GetValue());
137                 AddressListCtrlPtr->SetItem(ListCtrlIndex, 3, txtPostCode->GetValue());
138                 
139                 if (priorityCtrl->IsPriorityChecked()){
140                 
141                         AddressListCtrlPtr->SetItem(ListCtrlIndex, 4, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
142                 
143                 }
144                 
145                 this->Close();
146         
147         } else if (EditorMode == TRUE){
148         
149                 // Edit the address in the list.
150                 
151                 wxString strAddress;
152                 wxString strValue;
153                 long longSelected = -1;
154                 
155                 AddressListPtr->erase(AddressListIndex);                
156                 AddressListPtr->insert(std::make_pair(AddressListIndex, txtAddress->GetValue()));
158                 AddressListTownPtr->erase(AddressListIndex);
159                 AddressListTownPtr->insert(std::make_pair(AddressListIndex, txtTownCity->GetValue()));
161                 AddressListCountyPtr->erase(AddressListIndex);
162                 AddressListCountyPtr->insert(std::make_pair(AddressListIndex, txtCounty->GetValue()));
164                 AddressListPostCodePtr->erase(AddressListIndex);
165                 AddressListPostCodePtr->insert(std::make_pair(AddressListIndex, txtPostCode->GetValue()));
167                 AddressListCountryPtr->erase(AddressListIndex);
168                 AddressListCountryPtr->insert(std::make_pair(AddressListIndex, txtCountry->GetValue()));
169                 
170                 // Add the label to the list (maps).
171                 
172                 AddressListLabelPtr->erase(AddressListIndex);
173                 
174                 wxString LabelData = txtLabel->GetValue();
175                 LabelData.Prepend("\"");
176                 LabelData.Append("\"");
177                 AddressListLabelPtr->insert(std::make_pair(AddressListIndex, LabelData));
178                 
179                 // Add the language to the list (maps).
180                 
181                 AddressListLangPtr->erase(AddressListIndex);
182                 AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue()));
183                 
184                 //AddressListAltIDPtr = &AddressListAltID;
185                 
186                 // No AltIDs at present.
187                 
188                 // No PIDs at present.
189                 
190                 // There are no tokens for a new address to add so this can be
191                 // ignored for the time being.
192                 
193                 // Add the Geopositioning to the list (maps).
194                 
195                 AddressListGeoPtr->erase(AddressListIndex);
196                 AddressListGeoPtr->insert(std::make_pair(AddressListIndex, txtGeo->GetValue()));
197                 
198                 // Add the Timezone to the list (maps).
199                 
200                 AddressListTimezonePtr->erase(AddressListIndex);
201                 AddressListTimezonePtr->insert(std::make_pair(AddressListIndex, txtTimezone->GetValue()));
202                 
203                 // Add the mediatype to the list (maps).
204                 
205                 AddressListMediatypePtr->erase(AddressListIndex);
206                 AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain")));
207                 
208                 AddressListPrefPtr->erase(AddressListIndex);
209                 
210                 if (priorityCtrl->IsPriorityChecked()){
211                 
212                         AddressListPrefPtr->insert(std::make_pair(AddressListIndex, priorityCtrl->GetValue()));
213                 
214                 } else {
215                 
216                         AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0));                
217                 
218                 }
219                 
220                 // Update the form with the new details.
221                 
222                 longSelected = AddressListCtrlPtr->GetNextItem(longSelected, 
223                         wxLIST_NEXT_ALL,
224                         wxLIST_STATE_SELECTED);
225     
226                 if (longSelected == -1){
227                         return;
228                 }
230                 AddressListCtrlPtr->SetItem(longSelected, 0, txtAddress->GetValue());           
231                 AddressListCtrlPtr->SetItem(longSelected, 1, txtTownCity->GetValue());
232                 AddressListCtrlPtr->SetItem(longSelected, 2, txtCounty->GetValue());
233                 AddressListCtrlPtr->SetItem(longSelected, 3, txtPostCode->GetValue());
234                 
235                 if (priorityCtrl->IsPriorityChecked()){
236                 
237                         AddressListCtrlPtr->SetItem(longSelected, 4, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
238                 
239                 } else {
240                 
241                         AddressListCtrlPtr->SetItem(longSelected, 4, wxT(""));
242                 
243                 }
244                 
245                 this->Close();
246         
247         }
251 void frmContactEditorAddress::CloseWindow( wxCommandEvent& event )
253         
254         // Close the window.
255         
256         this->Close();
257         
260 void frmContactEditorAddress::CopyAddress( wxCommandEvent& event )
263         // Copy the address.
264         
265         wxString MailingLabel;
266         bool AddComma = FALSE;
267         
268         if (!txtAddress->IsEmpty()){
269         
270                 MailingLabel.Append(txtAddress->GetValue());
271                 AddComma = TRUE;
272         
273         }
274         
275         if (!txtTownCity->IsEmpty()){
276         
277                 if(AddComma == TRUE){
278                 
279                         MailingLabel.Append(wxT(",\n"));
280                         AddComma = FALSE;
281                 
282                 }
283                 
284                 MailingLabel.Append(txtTownCity->GetValue());
285                 AddComma = TRUE;
286         
287         }
288         
289         if (!txtCounty->IsEmpty()){
290         
291                 if(AddComma == TRUE){
292                 
293                         MailingLabel.Append(wxT(",\n"));
294                         AddComma = FALSE;
295                 
296                 }
297                 
298                 MailingLabel.Append(txtCounty->GetValue());
299                 AddComma = TRUE;
300         
301         }
302         
303         if (!txtPostCode->IsEmpty()){
304         
305                 if(AddComma == TRUE){
306                 
307                         MailingLabel.Append(wxT(",\n"));
308                         AddComma = FALSE;
309                 
310                 }
311                 
312                 MailingLabel.Append(txtPostCode->GetValue());
313                 AddComma = TRUE;
314         
315         }
316         
317         if (!txtCountry->IsEmpty()){
318         
319                 if(AddComma == TRUE){
320                 
321                         MailingLabel.Append(wxT(",\n"));
322                         AddComma = FALSE;
323                 
324                 }
325                 
326                 MailingLabel.Append(txtCountry->GetValue());
327                 AddComma = TRUE;
328         
329         }       
330         
331         txtLabel->SetValue(MailingLabel);
335 void frmContactEditorAddress::SetEditorMode( bool EditMode, SectionType SectType )
337         
338         // Set the editor mode.
339         
340         // Set if the editor is adding or editing an address.
341         // FALSE = Add
342         // TRUE = Edit
343         
344         if (EditMode == FALSE){
345         
346                 EditorMode = FALSE;
347                 btnAction->SetLabel(_("Add"));
348                 this->SetTitle(_("Add Address"));
349         
350         } else if (EditMode == TRUE){
351         
352                 EditorMode = TRUE;
353                 btnAction->SetLabel(_("Modify"));
354                 this->SetTitle(_("Modify Address"));
355                 
356                 wxString strValue;
357                 
358                 std::map<int,int>::iterator intiter;
359                 std::map<int,wxString>::iterator striter;               
360                 
361                 // Load the data into the form.
362                 
363                 striter = AddressListPtr->find(AddressListIndex);
364                  
365                 if (striter->first == AddressListIndex &&
366                   striter != AddressListPtr->end()){
367                 
368                         txtAddress->SetValue(striter->second);
369                 
370                 }
371                 
372                 striter = AddressListTownPtr->find(AddressListIndex);
374                 if (striter->first == AddressListIndex &&
375                   striter != AddressListTownPtr->end()){
376                 
377                         txtTownCity->SetValue(striter->second);
378                 
379                 }
380                 
381                 striter = AddressListCountyPtr->find(AddressListIndex);
383                 if (striter->first == AddressListIndex &&
384                   striter != AddressListCountyPtr->end()){
385                 
386                         txtCounty->SetValue(striter->second);
387                 
388                 }
390                 striter = AddressListPostCodePtr->find(AddressListIndex);
392                 if (striter->first == AddressListIndex &&
393                   striter != AddressListPostCodePtr->end()){
394                 
395                         txtPostCode->SetValue(striter->second);
396                 
397                 }
399                 striter = AddressListCountryPtr->find(AddressListIndex);
401                 if (striter->first == AddressListIndex &&
402                   striter != AddressListCountryPtr->end()){
403                 
404                         txtCountry->SetValue(striter->second);
405                 
406                 }
407                 
408                 // Setup the Slider.
409                 
410                 intiter = AddressListPrefPtr->find(AddressListIndex);
411                 
412                 if (intiter->first == AddressListIndex && intiter->second > 0 && intiter != AddressListPrefPtr->end() &&
413                   intiter != AddressListPrefPtr->end()){
414                 
415                         priorityCtrl->SetValue(intiter->second);
416                         priorityCtrl->EnablePriority(true);
417                 
418                 }
419                 
420                 // Setup the Label.
421                 
422                 striter = AddressListLabelPtr->find(AddressListIndex);
423                  
424                 if (striter->first == AddressListIndex && striter != AddressListLabelPtr->end() &&
425                   striter != AddressListLabelPtr->end()){
426                 
427                         strValue = striter->second;
428                         if (strValue.Left(1) == "\"" && strValue.Right(1) == "\""){
429                                 strValue.erase(0, 1);
430                                 strValue.RemoveLast();
431                         }
432                 
433                 }
435                 txtLabel->SetValue(strValue);
436                 
437                 // Setup the Language, Geographic position and timezone.
438                 
439                 striter = AddressListLangPtr->find(AddressListIndex);
440                  
441                 if (striter->first == AddressListIndex && striter != AddressListLangPtr->end()){
442                 
443                         strValue = striter->second;
445                 }       
446                 
447                 cmbLanguage->SetValue(strValue);
448                 
449                 striter = AddressListGeoPtr->find(AddressListIndex);
450                  
451                 if (striter->first == AddressListIndex && striter != AddressListGeoPtr->end()){
452                 
453                         strValue = striter->second;
454                 
455                 }
456                 
457                 txtGeo->SetValue(strValue);
458                 
459                 striter = AddressListTimezonePtr->find(AddressListIndex);
460                  
461                 if (striter->first == AddressListIndex && striter != AddressListTimezonePtr->end()){
462                 
463                         strValue = striter->second;
464                 
465                 }
466                 
467                 txtTimezone->SetValue(strValue);        
468         
469         }
470         
471         EditSectionType = SectType;
474 void frmContactEditorAddress::SetupPointers( std::map<int, wxString> *AddressList,
475         std::map<int, wxString> *AddressListTown,
476         std::map<int, wxString> *AddressListCounty,
477         std::map<int, wxString> *AddressListPostCode,
478         std::map<int, wxString> *AddressListCountry,
479         std::map<int, wxString> *AddressListLabel,
480         std::map<int, wxString> *AddressListLang,               
481         std::map<int, wxString> *AddressListAltID,
482         std::map<int, wxString> *AddressListPID,
483         std::map<int, wxString> *AddressListTokens,
484         std::map<int, wxString> *AddressListGeo,
485         std::map<int, wxString> *AddressListTimezone,
486         std::map<int, wxString> *AddressListType,
487         std::map<int, wxString> *AddressListMediatype,
488         std::map<int, int> *AddressListPref,
489         wxListCtrl *AddressListCtrl, 
490         int AddressIndex )
493         // Setup the pointers.
494         
495         AddressListPtr = AddressList;
496         AddressListTownPtr = AddressListTown;
497         AddressListCountyPtr = AddressListCounty;
498         AddressListPostCodePtr = AddressListPostCode;
499         AddressListCountryPtr = AddressListCountry;
500         AddressListLabelPtr = AddressListLabel;
501         AddressListLangPtr = AddressListLang;
502         AddressListAltIDPtr = AddressListAltID;
503         AddressListPIDPtr = AddressListPID;
504         AddressListTokensPtr = AddressListTokens;
505         AddressListGeoPtr = AddressListGeo;
506         AddressListTimezonePtr = AddressListTimezone;
507         AddressListTypePtr = AddressListType;
508         AddressListMediatypePtr = AddressListMediatype;
509         AddressListPrefPtr = AddressListPref;
510         AddressListCtrlPtr = AddressListCtrl;
511         AddressListIndex = AddressIndex;
512         
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