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