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 )
30 sliPriority->Disable();
32 // Setup the list of types for the related drop down box.
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"));
57 void frmContactEditorRelated::EnablePriority( wxCommandEvent& event )
59 if (chkUsePref->IsChecked()){
60 sliPriority->Enable();
62 sliPriority->Disable();
66 void frmContactEditorRelated::SetEditorMode(bool EditMode, SectionType SectType)
68 if (EditMode == FALSE){
71 btnAction->SetLabel(_("Add"));
72 this->SetTitle(_("Add Related"));
74 } else if (EditMode == TRUE){
77 btnAction->SetLabel(_("Modify"));
78 this->SetTitle(_("Modify Related"));
80 std::map<int,int>::iterator intiter;
81 std::map<int,wxString>::iterator striter;
84 // Get the related data.
86 striter = RelatedListPtr->find(RelatedListIndex);
88 if (striter->first == RelatedListIndex){
90 strValue = striter->second;
94 txtRelated->SetValue(strValue);
98 // Get the related type.
100 striter = RelatedListRelTypePtr->find(RelatedListIndex);
102 if (striter->first == RelatedListIndex &&
103 striter != RelatedListRelTypePtr->end()){
105 strValue = striter->second;
109 if (strValue == wxT("contact")){
111 cmbType->SetValue(_("Contact"));
113 } else if (strValue == wxT("acquaintance")){
115 cmbType->SetValue(_("Acquaintance"));
117 } else if (strValue == wxT("friend")){
119 cmbType->SetValue(_("Friend"));
121 } else if (strValue == wxT("met")){
123 cmbType->SetValue(_("Met"));
125 } else if (strValue == wxT("co-worker")){
127 cmbType->SetValue(_("Co-worker"));
129 } else if (strValue == wxT("colleague")){
131 cmbType->SetValue(_("Colleague"));
133 } else if (strValue == wxT("co-resident")){
135 cmbType->SetValue(_("Co-resident"));
137 } else if (strValue == wxT("neighbor")){
139 cmbType->SetValue(_("Neighbour"));
141 } else if (strValue == wxT("child")){
143 cmbType->SetValue(_("Child"));
145 } else if (strValue == wxT("parent")){
147 cmbType->SetValue(_("Parent"));
149 } else if (strValue == wxT("sibling")){
151 cmbType->SetValue(_("Sibling"));
153 } else if (strValue == wxT("spouse")){
155 cmbType->SetValue(_("Spouse"));
157 } else if (strValue == wxT("kin")){
159 cmbType->SetValue(_("Kin"));
161 } else if (strValue == wxT("muse")){
163 cmbType->SetValue(_("Muse"));
165 } else if (strValue == wxT("crush")){
167 cmbType->SetValue(_("Crush"));
169 } else if (strValue == wxT("date")){
171 cmbType->SetValue(_("Date"));
173 } else if (strValue == wxT("sweetheart")){
175 cmbType->SetValue(_("Sweetheart"));
177 } else if (strValue == wxT("me")){
179 cmbType->SetValue(_("Me"));
181 } else if (strValue == wxT("agent")){
183 cmbType->SetValue(_("Agent"));
185 } else if (strValue == wxT("emergency")){
187 cmbType->SetValue(_("Emergency"));
191 cmbType->SetValue(strValue);
197 intiter = RelatedListPrefPtr->find(RelatedListIndex);
199 if (intiter->first == RelatedListIndex && intiter->second > 0 &&
200 intiter != RelatedListPrefPtr->end()){
202 sliPriority->SetValue(intiter->second);
203 sliPriority->Enable();
204 chkUsePref->SetValue(TRUE);
210 EditSectionType = SectType;
214 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 (chkUsePref->IsChecked()){
334 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, sliPriority->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 (chkUsePref->IsChecked()){
355 RelatedListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->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 (chkUsePref->IsChecked()){
462 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, sliPriority->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 (chkUsePref->IsChecked()){
490 RelatedListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
494 RelatedListCtrlPtr->SetItem(longSelected, 2, wxT(""));
503 void frmContactEditorRelated::CloseWindow( wxCommandEvent& event )
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,
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;