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