1 // frmContactEditorRelated.cpp - frmContactEditorRelated form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
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.
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.
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"
21 #include "../common/textprocessing.h"
24 frmContactEditorRelated::frmContactEditorRelated( wxWindow* parent )
26 frmContactEditorRelatedADT( parent )
32 priorityCtrl = new XABPriorityCtrl(tabGeneral);
33 szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
36 // Setup the list of types for the related drop down box.
38 cmbType->Append(_("Contact"));
39 cmbType->Append(_("Acquaintance"));
40 cmbType->Append(_("Friend"));
41 cmbType->Append(_("Met"));
42 cmbType->Append(_("Co-worker"));
43 cmbType->Append(_("Colleague"));
44 cmbType->Append(_("Co-resident"));
45 cmbType->Append(_("Neighbour"));
46 cmbType->Append(_("Child"));
47 cmbType->Append(_("Parent"));
48 cmbType->Append(_("Sibling"));
49 cmbType->Append(_("Spouse"));
50 cmbType->Append(_("Kin"));
51 cmbType->Append(_("Muse"));
52 cmbType->Append(_("Crush"));
53 cmbType->Append(_("Date"));
54 cmbType->Append(_("Sweetheart"));
55 cmbType->Append(_("Me"));
56 cmbType->Append(_("Agent"));
57 cmbType->Append(_("Emergency"));
61 void frmContactEditorRelated::SetEditorMode(bool EditMode, SectionType SectType)
64 // Set the editor mode.
66 if (EditMode == FALSE){
69 btnAction->SetLabel(_("Add"));
70 this->SetTitle(_("Add Related"));
72 } else if (EditMode == TRUE){
75 btnAction->SetLabel(_("Modify"));
76 this->SetTitle(_("Modify Related"));
78 std::map<int,int>::iterator intiter;
79 std::map<int,wxString>::iterator striter;
82 // Get the related data.
84 striter = RelatedListPtr->find(RelatedListIndex);
86 if (striter->first == RelatedListIndex){
88 strValue = striter->second;
92 txtRelated->SetValue(strValue);
96 // Get the related type.
98 striter = RelatedListRelTypePtr->find(RelatedListIndex);
100 if (striter->first == RelatedListIndex &&
101 striter != RelatedListRelTypePtr->end()){
103 strValue = striter->second;
107 if (strValue == wxT("contact")){
109 cmbType->SetValue(_("Contact"));
111 } else if (strValue == wxT("acquaintance")){
113 cmbType->SetValue(_("Acquaintance"));
115 } else if (strValue == wxT("friend")){
117 cmbType->SetValue(_("Friend"));
119 } else if (strValue == wxT("met")){
121 cmbType->SetValue(_("Met"));
123 } else if (strValue == wxT("co-worker")){
125 cmbType->SetValue(_("Co-worker"));
127 } else if (strValue == wxT("colleague")){
129 cmbType->SetValue(_("Colleague"));
131 } else if (strValue == wxT("co-resident")){
133 cmbType->SetValue(_("Co-resident"));
135 } else if (strValue == wxT("neighbor")){
137 cmbType->SetValue(_("Neighbour"));
139 } else if (strValue == wxT("child")){
141 cmbType->SetValue(_("Child"));
143 } else if (strValue == wxT("parent")){
145 cmbType->SetValue(_("Parent"));
147 } else if (strValue == wxT("sibling")){
149 cmbType->SetValue(_("Sibling"));
151 } else if (strValue == wxT("spouse")){
153 cmbType->SetValue(_("Spouse"));
155 } else if (strValue == wxT("kin")){
157 cmbType->SetValue(_("Kin"));
159 } else if (strValue == wxT("muse")){
161 cmbType->SetValue(_("Muse"));
163 } else if (strValue == wxT("crush")){
165 cmbType->SetValue(_("Crush"));
167 } else if (strValue == wxT("date")){
169 cmbType->SetValue(_("Date"));
171 } else if (strValue == wxT("sweetheart")){
173 cmbType->SetValue(_("Sweetheart"));
175 } else if (strValue == wxT("me")){
177 cmbType->SetValue(_("Me"));
179 } else if (strValue == wxT("agent")){
181 cmbType->SetValue(_("Agent"));
183 } else if (strValue == wxT("emergency")){
185 cmbType->SetValue(_("Emergency"));
189 cmbType->SetValue(strValue);
195 intiter = RelatedListPrefPtr->find(RelatedListIndex);
197 if (intiter->first == RelatedListIndex && intiter->second > 0 &&
198 intiter != RelatedListPrefPtr->end()){
200 priorityCtrl->SetValue(intiter->second);
201 priorityCtrl->EnablePriority(true);
207 EditSectionType = SectType;
211 void frmContactEditorRelated::ProcessData( wxCommandEvent& event )
218 if (EditorMode == FALSE){
222 RelatedListPtr->insert(std::make_pair(RelatedListIndex, txtRelated->GetValue()));
224 // Work out the type of contact.
226 strValue = cmbType->GetValue();
228 if (strValue == _("Contact")){
230 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("contact")));
232 } else if (strValue == _("Acquaintance")){
234 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("acquaintance")));
236 } else if (strValue == _("Friend")){
238 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("friend")));
240 } else if (strValue == _("Met")){
242 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("met")));
244 } else if (strValue == _("Co-worker")){
246 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-worker")));
248 } else if (strValue == _("Colleague")){
250 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("colleague")));
252 } else if (strValue == _("Co-resident")){
254 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-resident")));
256 } else if (strValue == _("Neighbour")){
258 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("neighbor")));
260 } else if (strValue == _("Child")){
262 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("child")));
264 } else if (strValue == _("Parent")){
266 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("parent")));
268 } else if (strValue == _("Sibling")){
270 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sibling")));
272 } else if (strValue == _("Spouse")){
274 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("spouse")));
276 } else if (strValue == _("Kin")){
278 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("kin")));
280 } else if (strValue == _("Muse")){
282 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("muse")));
284 } else if (strValue == _("Crush")){
286 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("crush")));
288 } else if (strValue == _("Date")){
290 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("date")));
292 } else if (strValue == _("Sweetheart")){
294 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sweetheart")));
296 } else if (strValue == _("Me")){
298 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("me")));
300 } else if (strValue == _("Agent")){
302 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("agent")));
304 } else if (strValue == _("Emergency")){
306 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("emergency")));
310 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, strValue));
316 if (EditSectionType == CE_GENERAL){
318 RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("")));
320 } else if (EditSectionType == CE_HOME) {
322 RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("home")));
324 } else if (EditSectionType == CE_WORK) {
326 RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("work")));
330 // Add Related Priority.
332 if (priorityCtrl->IsPriorityChecked()){
334 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, priorityCtrl->GetValue()));
338 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, 0));
346 coldata.SetId(RelatedListIndex);
347 coldata.SetData(RelatedListIndex);
348 coldata.SetText(cmbType->GetValue());
349 ListCtrlIndex = RelatedListCtrlPtr->InsertItem(coldata);
351 RelatedListCtrlPtr->SetItem(ListCtrlIndex, 1, txtRelated->GetValue());
353 if (priorityCtrl->IsPriorityChecked()){
355 RelatedListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
361 } else if (EditorMode == TRUE) {
364 long longSelected = -1;
366 // Work out the type of contact.
368 strValue = cmbType->GetValue();
370 RelatedListRelTypePtr->erase(RelatedListIndex);
372 if (strValue == _("Contact")){
374 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("contact")));
376 } else if (strValue == _("Acquaintance")){
378 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("acquaintance")));
380 } else if (strValue == _("Friend")){
382 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("friend")));
384 } else if (strValue == _("Met")){
386 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("met")));
388 } else if (strValue == _("Co-worker")){
390 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-worker")));
392 } else if (strValue == _("Colleague")){
394 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("colleague")));
396 } else if (strValue == _("Co-resident")){
398 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-resident")));
400 } else if (strValue == _("Neighbour")){
402 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("neighbor")));
404 } else if (strValue == _("Child")){
406 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("child")));
408 } else if (strValue == _("Parent")){
410 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("parent")));
412 } else if (strValue == _("Sibling")){
414 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sibling")));
416 } else if (strValue == _("Spouse")){
418 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("spouse")));
420 } else if (strValue == _("Kin")){
422 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("kin")));
424 } else if (strValue == _("Muse")){
426 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("muse")));
428 } else if (strValue == _("Crush")){
430 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("crush")));
432 } else if (strValue == _("Date")){
434 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("date")));
436 } else if (strValue == _("Sweetheart")){
438 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sweetheart")));
440 } else if (strValue == _("Me")){
442 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("me")));
444 } else if (strValue == _("Agent")){
446 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("agent")));
448 } else if (strValue == _("Emergency")){
450 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("emergency")));
454 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, strValue));
458 RelatedListPrefPtr->erase(RelatedListIndex);
460 if (priorityCtrl->IsPriorityChecked()){
462 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, priorityCtrl->GetValue()));
466 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, 0));
470 // Get the related person/details.
472 RelatedListPtr->erase(RelatedListIndex);
473 RelatedListPtr->insert(std::make_pair(RelatedListIndex, txtRelated->GetValue()));
477 longSelected = RelatedListCtrlPtr->GetNextItem(longSelected,
479 wxLIST_STATE_SELECTED);
481 if (longSelected == -1){
485 RelatedListCtrlPtr->SetItem(longSelected, 0, cmbType->GetValue());
486 RelatedListCtrlPtr->SetItem(longSelected, 1, txtRelated->GetValue());
488 if (priorityCtrl->IsPriorityChecked()){
490 RelatedListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
494 RelatedListCtrlPtr->SetItem(longSelected, 2, wxT(""));
503 void frmContactEditorRelated::CloseWindow( wxCommandEvent& event )
506 // Close this window.
512 void frmContactEditorRelated::SetupPointers(std::map<int, wxString> *RelatedList,
513 std::map<int, wxString> *RelatedListRelType,
514 std::map<int, wxString> *RelatedListAltID,
515 std::map<int, wxString> *RelatedListPID,
516 std::map<int, wxString> *RelatedListType,
517 std::map<int, wxString> *RelatedListTokens,
518 std::map<int, int> *RelatedListPref,
519 wxListCtrl *RelatedListCtrl,
523 // Setup the pointers.
525 RelatedListPtr = RelatedList;
526 RelatedListRelTypePtr = RelatedListRelType;
527 RelatedListAltIDPtr = RelatedListAltID;
528 RelatedListPIDPtr = RelatedListPID;
529 RelatedListTypePtr = RelatedListType;
530 RelatedListTokensPtr = RelatedListTokens;
531 RelatedListPrefPtr = RelatedListPref;
532 RelatedListCtrlPtr = RelatedListCtrl;
533 RelatedListIndex = RelatedIndex;