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){
104 strValue = striter->second;
108 if (strValue == wxT("contact")){
110 cmbType->SetValue(_("Contact"));
112 } else if (strValue == wxT("acquaintance")){
114 cmbType->SetValue(_("Acquaintance"));
116 } else if (strValue == wxT("friend")){
118 cmbType->SetValue(_("Friend"));
120 } else if (strValue == wxT("met")){
122 cmbType->SetValue(_("Met"));
124 } else if (strValue == wxT("co-worker")){
126 cmbType->SetValue(_("Co-worker"));
128 } else if (strValue == wxT("colleague")){
130 cmbType->SetValue(_("Colleague"));
132 } else if (strValue == wxT("co-resident")){
134 cmbType->SetValue(_("Co-resident"));
136 } else if (strValue == wxT("neighbor")){
138 cmbType->SetValue(_("Neighbour"));
140 } else if (strValue == wxT("child")){
142 cmbType->SetValue(_("Child"));
144 } else if (strValue == wxT("parent")){
146 cmbType->SetValue(_("Parent"));
148 } else if (strValue == wxT("sibling")){
150 cmbType->SetValue(_("Sibling"));
152 } else if (strValue == wxT("spouse")){
154 cmbType->SetValue(_("Spouse"));
156 } else if (strValue == wxT("kin")){
158 cmbType->SetValue(_("Kin"));
160 } else if (strValue == wxT("muse")){
162 cmbType->SetValue(_("Muse"));
164 } else if (strValue == wxT("crush")){
166 cmbType->SetValue(_("Crush"));
168 } else if (strValue == wxT("date")){
170 cmbType->SetValue(_("Date"));
172 } else if (strValue == wxT("sweetheart")){
174 cmbType->SetValue(_("Sweetheart"));
176 } else if (strValue == wxT("me")){
178 cmbType->SetValue(_("Me"));
180 } else if (strValue == wxT("agent")){
182 cmbType->SetValue(_("Agent"));
184 } else if (strValue == wxT("emergency")){
186 cmbType->SetValue(_("Emergency"));
190 cmbType->SetValue(strValue);
196 intiter = RelatedListPrefPtr->find(RelatedListIndex);
198 if (intiter->first == RelatedListIndex && intiter->second > 0){
200 sliPriority->SetValue(intiter->second);
201 sliPriority->Enable();
202 chkUsePref->SetValue(TRUE);
208 EditSectionType = SectType;
212 void frmContactEditorRelated::ProcessData( wxCommandEvent& event )
216 if (EditorMode == FALSE){
220 RelatedListPtr->insert(std::make_pair(RelatedListIndex, txtRelated->GetValue()));
222 // Work out the type of contact.
224 strValue = cmbType->GetValue();
226 if (strValue == _("Contact")){
228 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("contact")));
230 } else if (strValue == _("Acquaintance")){
232 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("acquaintance")));
234 } else if (strValue == _("Friend")){
236 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("friend")));
238 } else if (strValue == _("Met")){
240 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("met")));
242 } else if (strValue == _("Co-worker")){
244 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-worker")));
246 } else if (strValue == _("Colleague")){
248 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("colleague")));
250 } else if (strValue == _("Co-resident")){
252 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-resident")));
254 } else if (strValue == _("Neighbour")){
256 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("neighbor")));
258 } else if (strValue == _("Child")){
260 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("child")));
262 } else if (strValue == _("Parent")){
264 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("parent")));
266 } else if (strValue == _("Sibling")){
268 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sibling")));
270 } else if (strValue == _("Spouse")){
272 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("spouse")));
274 } else if (strValue == _("Kin")){
276 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("kin")));
278 } else if (strValue == _("Muse")){
280 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("muse")));
282 } else if (strValue == _("Crush")){
284 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("crush")));
286 } else if (strValue == _("Date")){
288 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("date")));
290 } else if (strValue == _("Sweetheart")){
292 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sweetheart")));
294 } else if (strValue == _("Me")){
296 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("me")));
298 } else if (strValue == _("Agent")){
300 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("agent")));
302 } else if (strValue == _("Emergency")){
304 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("emergency")));
308 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, strValue));
314 if (EditSectionType == CE_GENERAL){
316 RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("")));
318 } else if (EditSectionType == CE_HOME) {
320 RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("home")));
322 } else if (EditSectionType == CE_WORK) {
324 RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("work")));
328 // Add Related Priority.
330 if (chkUsePref->IsChecked()){
332 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, sliPriority->GetValue()));
336 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, 0));
344 coldata.SetId(RelatedListIndex);
345 coldata.SetData(RelatedListIndex);
346 coldata.SetText(cmbType->GetValue());
347 ListCtrlIndex = RelatedListCtrlPtr->InsertItem(coldata);
349 RelatedListCtrlPtr->SetItem(ListCtrlIndex, 1, txtRelated->GetValue());
351 if (chkUsePref->IsChecked()){
353 RelatedListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
359 } else if (EditorMode == TRUE) {
362 long longSelected = -1;
364 // Work out the type of contact.
366 strValue = cmbType->GetValue();
368 RelatedListRelTypePtr->erase(RelatedListIndex);
370 if (strValue == _("Contact")){
372 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("contact")));
374 } else if (strValue == _("Acquaintance")){
376 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("acquaintance")));
378 } else if (strValue == _("Friend")){
380 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("friend")));
382 } else if (strValue == _("Met")){
384 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("met")));
386 } else if (strValue == _("Co-worker")){
388 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-worker")));
390 } else if (strValue == _("Colleague")){
392 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("colleague")));
394 } else if (strValue == _("Co-resident")){
396 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-resident")));
398 } else if (strValue == _("Neighbour")){
400 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("neighbor")));
402 } else if (strValue == _("Child")){
404 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("child")));
406 } else if (strValue == _("Parent")){
408 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("parent")));
410 } else if (strValue == _("Sibling")){
412 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sibling")));
414 } else if (strValue == _("Spouse")){
416 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("spouse")));
418 } else if (strValue == _("Kin")){
420 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("kin")));
422 } else if (strValue == _("Muse")){
424 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("muse")));
426 } else if (strValue == _("Crush")){
428 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("crush")));
430 } else if (strValue == _("Date")){
432 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("date")));
434 } else if (strValue == _("Sweetheart")){
436 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sweetheart")));
438 } else if (strValue == _("Me")){
440 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("me")));
442 } else if (strValue == _("Agent")){
444 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("agent")));
446 } else if (strValue == _("Emergency")){
448 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("emergency")));
452 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, strValue));
456 RelatedListPrefPtr->erase(RelatedListIndex);
458 if (chkUsePref->IsChecked()){
460 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, sliPriority->GetValue()));
464 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, 0));
468 // Get the related person/details.
470 RelatedListPtr->erase(RelatedListIndex);
471 RelatedListPtr->insert(std::make_pair(RelatedListIndex, txtRelated->GetValue()));
475 longSelected = RelatedListCtrlPtr->GetNextItem(longSelected,
477 wxLIST_STATE_SELECTED);
479 if (longSelected == -1){
483 RelatedListCtrlPtr->SetItem(longSelected, 0, cmbType->GetValue());
484 RelatedListCtrlPtr->SetItem(longSelected, 1, txtRelated->GetValue());
486 if (chkUsePref->IsChecked()){
488 RelatedListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
492 RelatedListCtrlPtr->SetItem(longSelected, 2, wxT(""));
501 void frmContactEditorRelated::CloseWindow( wxCommandEvent& event )
506 void frmContactEditorRelated::SetupPointers(std::map<int, wxString> *RelatedList,
507 std::map<int, wxString> *RelatedListRelType,
508 std::map<int, wxString> *RelatedListAltID,
509 std::map<int, wxString> *RelatedListPID,
510 std::map<int, wxString> *RelatedListType,
511 std::map<int, wxString> *RelatedListTokens,
512 std::map<int, int> *RelatedListPref,
513 wxListCtrl *RelatedListCtrl,
517 RelatedListPtr = RelatedList;
518 RelatedListRelTypePtr = RelatedListRelType;
519 RelatedListAltIDPtr = RelatedListAltID;
520 RelatedListPIDPtr = RelatedListPID;
521 RelatedListTypePtr = RelatedListType;
522 RelatedListTokensPtr = RelatedListTokens;
523 RelatedListPrefPtr = RelatedListPref;
524 RelatedListCtrlPtr = RelatedListCtrl;
525 RelatedListIndex = RelatedIndex;