Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Fixed potential crash with frmContactEditorRelated in Edit mode.
[xestiaab/.git] / source / contacteditor / frmContactEditorRelated.cpp
1 // frmContactEditorRelated.cpp - frmContactEditorRelated 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 "frmContactEditorRelated.h"
20 #include <map>
21 #include "../common/textprocessing.h"
22 #include "../enums.h"
24 frmContactEditorRelated::frmContactEditorRelated( wxWindow* parent )
25 :
26 frmContactEditorRelatedADT( parent )
27 {
28         
29         EditorMode = FALSE;
30         sliPriority->Disable();
31         
32         // Setup the list of types for the related drop down box.
33         
34         cmbType->Append(_("Contact"));
35         cmbType->Append(_("Acquaintance"));     
36         cmbType->Append(_("Friend"));   
37         cmbType->Append(_("Met"));
38         cmbType->Append(_("Co-worker"));
39         cmbType->Append(_("Colleague"));
40         cmbType->Append(_("Co-resident"));
41         cmbType->Append(_("Neighbour"));
42         cmbType->Append(_("Child"));
43         cmbType->Append(_("Parent"));
44         cmbType->Append(_("Sibling"));  
45         cmbType->Append(_("Spouse"));
46         cmbType->Append(_("Kin"));
47         cmbType->Append(_("Muse"));
48         cmbType->Append(_("Crush"));
49         cmbType->Append(_("Date"));
50         cmbType->Append(_("Sweetheart"));
51         cmbType->Append(_("Me"));
52         cmbType->Append(_("Agent"));
53         cmbType->Append(_("Emergency"));        
54         
55 }
57 void frmContactEditorRelated::EnablePriority( wxCommandEvent& event )
58 {
59         if (chkUsePref->IsChecked()){
60                 sliPriority->Enable();
61         } else {
62                 sliPriority->Disable();
63         }
64 }
66 void frmContactEditorRelated::SetEditorMode(bool EditMode, SectionType SectType)
67 {
68         if (EditMode == FALSE){
69         
70                 EditorMode = FALSE;
71                 btnAction->SetLabel(_("Add"));
72                 this->SetTitle(_("Add Related"));
73         
74         } else if (EditMode == TRUE){
75         
76                 EditorMode = TRUE;
77                 btnAction->SetLabel(_("Modify"));
78                 this->SetTitle(_("Modify Related"));
79                 
80                 std::map<int,int>::iterator intiter;
81                 std::map<int,wxString>::iterator striter;               
82                 wxString strValue;
83                 
84                 // Get the related data.
85                 
86                 striter = RelatedListPtr->find(RelatedListIndex);
87                  
88                 if (striter->first == RelatedListIndex){
89                 
90                         strValue = striter->second;
91                 
92                 }
93                 
94                 txtRelated->SetValue(strValue);
95                 
96                 strValue.Clear();
97                 
98                 // Get the related type.
99                 
100                 striter = RelatedListRelTypePtr->find(RelatedListIndex);
101                  
102                 if (striter->first == RelatedListIndex &&
103                         striter != RelatedListRelTypePtr->end()){
104                 
105                         strValue = striter->second;
106                 
107                 }
108                 
109                 if (strValue == wxT("contact")){
110                 
111                         cmbType->SetValue(_("Contact"));
112                 
113                 } else if (strValue == wxT("acquaintance")){
114                 
115                         cmbType->SetValue(_("Acquaintance"));
116                 
117                 } else if (strValue == wxT("friend")){
118                 
119                         cmbType->SetValue(_("Friend"));
120                 
121                 } else if (strValue == wxT("met")){
122                 
123                         cmbType->SetValue(_("Met"));
124                 
125                 } else if (strValue == wxT("co-worker")){
126                 
127                         cmbType->SetValue(_("Co-worker"));
128                 
129                 } else if (strValue == wxT("colleague")){
130                 
131                         cmbType->SetValue(_("Colleague"));
132                 
133                 } else if (strValue == wxT("co-resident")){
134                 
135                         cmbType->SetValue(_("Co-resident"));
136                 
137                 } else if (strValue == wxT("neighbor")){
138                 
139                         cmbType->SetValue(_("Neighbour"));
140                 
141                 } else if (strValue == wxT("child")){
142                 
143                         cmbType->SetValue(_("Child"));
144                 
145                 } else if (strValue == wxT("parent")){
146                 
147                         cmbType->SetValue(_("Parent"));
148                 
149                 } else if (strValue == wxT("sibling")){
150                 
151                         cmbType->SetValue(_("Sibling"));
152                 
153                 } else if (strValue == wxT("spouse")){
154                 
155                         cmbType->SetValue(_("Spouse"));
156                 
157                 } else if (strValue == wxT("kin")){
158                 
159                         cmbType->SetValue(_("Kin"));
160                 
161                 } else if (strValue == wxT("muse")){
162                 
163                         cmbType->SetValue(_("Muse"));
164                 
165                 } else if (strValue == wxT("crush")){
166                 
167                         cmbType->SetValue(_("Crush"));
168                 
169                 } else if (strValue == wxT("date")){
170                 
171                         cmbType->SetValue(_("Date"));
172                 
173                 } else if (strValue == wxT("sweetheart")){
174                 
175                         cmbType->SetValue(_("Sweetheart"));
176                 
177                 } else if (strValue == wxT("me")){
178                 
179                         cmbType->SetValue(_("Me"));
180                 
181                 } else if (strValue == wxT("agent")){
182                 
183                         cmbType->SetValue(_("Agent"));
184                 
185                 } else if (strValue == wxT("emergency")){
186                 
187                         cmbType->SetValue(_("Emergency"));
188                 
189                 } else {
190                 
191                         cmbType->SetValue(strValue);
192                 
193                 }
194                 
195                 // Setup the Slider.
196                 
197                 intiter = RelatedListPrefPtr->find(RelatedListIndex);
198                 
199                 if (intiter->first == RelatedListIndex && intiter->second > 0 &&
200                         intiter != RelatedListPrefPtr->end()){
201                 
202                         sliPriority->SetValue(intiter->second);
203                         sliPriority->Enable();
204                         chkUsePref->SetValue(TRUE);
205                 
206                 }
207                 
208         }
209         
210         EditSectionType = SectType;     
211         
214 void frmContactEditorRelated::ProcessData( wxCommandEvent& event )
216         long ListCtrlIndex;
217         
218         if (EditorMode == FALSE){
220                 wxString strValue;
222                 RelatedListPtr->insert(std::make_pair(RelatedListIndex, txtRelated->GetValue()));
223                 
224                 // Work out the type of contact.
225                 
226                 strValue = cmbType->GetValue();         
227                 
228                 if (strValue == _("Contact")){
229                 
230                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("contact")));
231                 
232                 } else if (strValue == _("Acquaintance")){
233                 
234                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("acquaintance")));
235                 
236                 } else if (strValue == _("Friend")){
237                 
238                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("friend")));
239                 
240                 } else if (strValue == _("Met")){
241                 
242                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("met")));
243                 
244                 } else if (strValue == _("Co-worker")){
245                 
246                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-worker")));
247                 
248                 } else if (strValue == _("Colleague")){
249                 
250                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("colleague")));
251                 
252                 } else if (strValue == _("Co-resident")){
253                 
254                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-resident")));
255                 
256                 } else if (strValue == _("Neighbour")){
257                 
258                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("neighbor")));
259                 
260                 } else if (strValue == _("Child")){
261                 
262                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("child")));
263                 
264                 } else if (strValue == _("Parent")){
265                 
266                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("parent")));
267                 
268                 } else if (strValue == _("Sibling")){
269                 
270                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sibling")));
271                 
272                 } else if (strValue == _("Spouse")){
273                 
274                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("spouse")));
275                 
276                 } else if (strValue == _("Kin")){
277                 
278                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("kin")));
279                 
280                 } else if (strValue == _("Muse")){
281                 
282                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("muse")));
283                 
284                 } else if (strValue == _("Crush")){
285                 
286                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("crush")));
287                 
288                 } else if (strValue == _("Date")){
289                 
290                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("date")));
291                 
292                 } else if (strValue == _("Sweetheart")){
293                 
294                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sweetheart")));
295                 
296                 } else if (strValue == _("Me")){
297                 
298                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("me")));
299                 
300                 } else if (strValue == _("Agent")){
301                 
302                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("agent")));
303                 
304                 } else if (strValue == _("Emergency")){
305                 
306                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("emergency")));
307                 
308                 } else {
309                 
310                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, strValue));
311                 
312                 }
313                 
314                 // Add Related type.
315                 
316                 if (EditSectionType == CE_GENERAL){
317                 
318                         RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("")));
319                 
320                 } else if (EditSectionType == CE_HOME) {
321                 
322                         RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("home")));
323                 
324                 } else if (EditSectionType == CE_WORK) {
325                 
326                         RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("work")));
327                 
328                 }       
329                 
330                 // Add Related Priority.
331                 
332                 if (chkUsePref->IsChecked()){
333                 
334                         RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, sliPriority->GetValue()));
335                 
336                 } else {
337                 
338                         RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, 0));                
339                 
340                 }
341                 
342                 // Add to the form.
343                 
344                 wxListItem coldata;
345                 
346                 coldata.SetId(RelatedListIndex);
347                 coldata.SetData(RelatedListIndex);              
348                 coldata.SetText(cmbType->GetValue());
349                 ListCtrlIndex = RelatedListCtrlPtr->InsertItem(coldata);
350                 
351                 RelatedListCtrlPtr->SetItem(ListCtrlIndex, 1, txtRelated->GetValue());
352                 
353                 if (chkUsePref->IsChecked()){
354                 
355                         RelatedListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
356                 
357                 }               
358         
359                 this->Close();
360         
361         } else if (EditorMode == TRUE) {
362         
363                 wxString strValue;
364                 long longSelected = -1;
365         
366                 // Work out the type of contact.
367                 
368                 strValue = cmbType->GetValue();         
369                 
370                 RelatedListRelTypePtr->erase(RelatedListIndex);
371                 
372                 if (strValue == _("Contact")){
373                 
374                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("contact")));
375                 
376                 } else if (strValue == _("Acquaintance")){
377                 
378                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("acquaintance")));
379                 
380                 } else if (strValue == _("Friend")){
381                 
382                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("friend")));
383                 
384                 } else if (strValue == _("Met")){
385                 
386                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("met")));
387                 
388                 } else if (strValue == _("Co-worker")){
389                 
390                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-worker")));
391                 
392                 } else if (strValue == _("Colleague")){
393                 
394                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("colleague")));
395                 
396                 } else if (strValue == _("Co-resident")){
397                 
398                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-resident")));
399                 
400                 } else if (strValue == _("Neighbour")){
401                 
402                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("neighbor")));
403                 
404                 } else if (strValue == _("Child")){
405                 
406                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("child")));
407                 
408                 } else if (strValue == _("Parent")){
409                 
410                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("parent")));
411                 
412                 } else if (strValue == _("Sibling")){
413                 
414                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sibling")));
415                 
416                 } else if (strValue == _("Spouse")){
417                 
418                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("spouse")));
419                 
420                 } else if (strValue == _("Kin")){
421                 
422                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("kin")));
423                 
424                 } else if (strValue == _("Muse")){
425                 
426                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("muse")));
427                 
428                 } else if (strValue == _("Crush")){
429                 
430                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("crush")));
431                 
432                 } else if (strValue == _("Date")){
433                 
434                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("date")));
435                 
436                 } else if (strValue == _("Sweetheart")){
437                 
438                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sweetheart")));
439                 
440                 } else if (strValue == _("Me")){
441                 
442                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("me")));
443                 
444                 } else if (strValue == _("Agent")){
445                 
446                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("agent")));
447                 
448                 } else if (strValue == _("Emergency")){
449                 
450                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("emergency")));
451                 
452                 } else {
453                 
454                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, strValue));
455                 
456                 }       
457                 
458                 RelatedListPrefPtr->erase(RelatedListIndex);
459                 
460                 if (chkUsePref->IsChecked()){
461                 
462                         RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, sliPriority->GetValue()));
463                 
464                 } else {
465                 
466                         RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, 0));
467                 
468                 }
469                 
470                 // Get the related person/details.
471                 
472                 RelatedListPtr->erase(RelatedListIndex);
473                 RelatedListPtr->insert(std::make_pair(RelatedListIndex, txtRelated->GetValue()));               
474                 
475                 // Update the form.
476                 
477                 longSelected = RelatedListCtrlPtr->GetNextItem(longSelected, 
478                         wxLIST_NEXT_ALL,
479                         wxLIST_STATE_SELECTED);
480                         
481                 if (longSelected == -1){
482                         return;
483                 }               
484                 
485                 RelatedListCtrlPtr->SetItem(longSelected, 0, cmbType->GetValue());
486                 RelatedListCtrlPtr->SetItem(longSelected, 1, txtRelated->GetValue());
487                 
488                 if (chkUsePref->IsChecked()){
489                 
490                         RelatedListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
491                 
492                 } else {
493                 
494                         RelatedListCtrlPtr->SetItem(longSelected, 2, wxT(""));
495                 
496                 }       
497         
498                 this->Close();
499         
500         }       
503 void frmContactEditorRelated::CloseWindow( wxCommandEvent& event )
505         this->Close();
508 void frmContactEditorRelated::SetupPointers(std::map<int, wxString> *RelatedList,
509         std::map<int, wxString> *RelatedListRelType,
510         std::map<int, wxString> *RelatedListAltID,
511         std::map<int, wxString> *RelatedListPID,
512         std::map<int, wxString> *RelatedListType,
513         std::map<int, wxString> *RelatedListTokens,                     
514         std::map<int, int> *RelatedListPref,
515         wxListCtrl *RelatedListCtrl,
516         int RelatedIndex )
519         RelatedListPtr = RelatedList;
520         RelatedListRelTypePtr = RelatedListRelType;     
521         RelatedListAltIDPtr = RelatedListAltID;
522         RelatedListPIDPtr = RelatedListPID;
523         RelatedListTypePtr = RelatedListType;
524         RelatedListTokensPtr = RelatedListTokens;
525         RelatedListPrefPtr = RelatedListPref;
526         RelatedListCtrlPtr = RelatedListCtrl;
527         RelatedListIndex = RelatedIndex;
528         
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