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