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 sliPriority->Disable();
34 // Setup the list of types for the related drop down box.
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"));
59 void frmContactEditorRelated::EnablePriority( wxCommandEvent& event )
62 // Enable/disable the priority setting.
64 if (chkUsePref->IsChecked()){
65 sliPriority->Enable();
67 sliPriority->Disable();
72 void frmContactEditorRelated::SetEditorMode(bool EditMode, SectionType SectType)
75 // Set the editor mode.
77 if (EditMode == FALSE){
80 btnAction->SetLabel(_("Add"));
81 this->SetTitle(_("Add Related"));
83 } else if (EditMode == TRUE){
86 btnAction->SetLabel(_("Modify"));
87 this->SetTitle(_("Modify Related"));
89 std::map<int,int>::iterator intiter;
90 std::map<int,wxString>::iterator striter;
93 // Get the related data.
95 striter = RelatedListPtr->find(RelatedListIndex);
97 if (striter->first == RelatedListIndex){
99 strValue = striter->second;
103 txtRelated->SetValue(strValue);
107 // Get the related type.
109 striter = RelatedListRelTypePtr->find(RelatedListIndex);
111 if (striter->first == RelatedListIndex &&
112 striter != RelatedListRelTypePtr->end()){
114 strValue = striter->second;
118 if (strValue == wxT("contact")){
120 cmbType->SetValue(_("Contact"));
122 } else if (strValue == wxT("acquaintance")){
124 cmbType->SetValue(_("Acquaintance"));
126 } else if (strValue == wxT("friend")){
128 cmbType->SetValue(_("Friend"));
130 } else if (strValue == wxT("met")){
132 cmbType->SetValue(_("Met"));
134 } else if (strValue == wxT("co-worker")){
136 cmbType->SetValue(_("Co-worker"));
138 } else if (strValue == wxT("colleague")){
140 cmbType->SetValue(_("Colleague"));
142 } else if (strValue == wxT("co-resident")){
144 cmbType->SetValue(_("Co-resident"));
146 } else if (strValue == wxT("neighbor")){
148 cmbType->SetValue(_("Neighbour"));
150 } else if (strValue == wxT("child")){
152 cmbType->SetValue(_("Child"));
154 } else if (strValue == wxT("parent")){
156 cmbType->SetValue(_("Parent"));
158 } else if (strValue == wxT("sibling")){
160 cmbType->SetValue(_("Sibling"));
162 } else if (strValue == wxT("spouse")){
164 cmbType->SetValue(_("Spouse"));
166 } else if (strValue == wxT("kin")){
168 cmbType->SetValue(_("Kin"));
170 } else if (strValue == wxT("muse")){
172 cmbType->SetValue(_("Muse"));
174 } else if (strValue == wxT("crush")){
176 cmbType->SetValue(_("Crush"));
178 } else if (strValue == wxT("date")){
180 cmbType->SetValue(_("Date"));
182 } else if (strValue == wxT("sweetheart")){
184 cmbType->SetValue(_("Sweetheart"));
186 } else if (strValue == wxT("me")){
188 cmbType->SetValue(_("Me"));
190 } else if (strValue == wxT("agent")){
192 cmbType->SetValue(_("Agent"));
194 } else if (strValue == wxT("emergency")){
196 cmbType->SetValue(_("Emergency"));
200 cmbType->SetValue(strValue);
206 intiter = RelatedListPrefPtr->find(RelatedListIndex);
208 if (intiter->first == RelatedListIndex && intiter->second > 0 &&
209 intiter != RelatedListPrefPtr->end()){
211 sliPriority->SetValue(intiter->second);
212 sliPriority->Enable();
213 chkUsePref->SetValue(TRUE);
219 EditSectionType = SectType;
223 void frmContactEditorRelated::ProcessData( wxCommandEvent& event )
230 if (EditorMode == FALSE){
234 RelatedListPtr->insert(std::make_pair(RelatedListIndex, txtRelated->GetValue()));
236 // Work out the type of contact.
238 strValue = cmbType->GetValue();
240 if (strValue == _("Contact")){
242 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("contact")));
244 } else if (strValue == _("Acquaintance")){
246 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("acquaintance")));
248 } else if (strValue == _("Friend")){
250 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("friend")));
252 } else if (strValue == _("Met")){
254 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("met")));
256 } else if (strValue == _("Co-worker")){
258 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-worker")));
260 } else if (strValue == _("Colleague")){
262 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("colleague")));
264 } else if (strValue == _("Co-resident")){
266 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-resident")));
268 } else if (strValue == _("Neighbour")){
270 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("neighbor")));
272 } else if (strValue == _("Child")){
274 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("child")));
276 } else if (strValue == _("Parent")){
278 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("parent")));
280 } else if (strValue == _("Sibling")){
282 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sibling")));
284 } else if (strValue == _("Spouse")){
286 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("spouse")));
288 } else if (strValue == _("Kin")){
290 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("kin")));
292 } else if (strValue == _("Muse")){
294 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("muse")));
296 } else if (strValue == _("Crush")){
298 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("crush")));
300 } else if (strValue == _("Date")){
302 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("date")));
304 } else if (strValue == _("Sweetheart")){
306 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sweetheart")));
308 } else if (strValue == _("Me")){
310 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("me")));
312 } else if (strValue == _("Agent")){
314 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("agent")));
316 } else if (strValue == _("Emergency")){
318 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("emergency")));
322 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, strValue));
328 if (EditSectionType == CE_GENERAL){
330 RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("")));
332 } else if (EditSectionType == CE_HOME) {
334 RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("home")));
336 } else if (EditSectionType == CE_WORK) {
338 RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("work")));
342 // Add Related Priority.
344 if (chkUsePref->IsChecked()){
346 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, sliPriority->GetValue()));
350 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, 0));
358 coldata.SetId(RelatedListIndex);
359 coldata.SetData(RelatedListIndex);
360 coldata.SetText(cmbType->GetValue());
361 ListCtrlIndex = RelatedListCtrlPtr->InsertItem(coldata);
363 RelatedListCtrlPtr->SetItem(ListCtrlIndex, 1, txtRelated->GetValue());
365 if (chkUsePref->IsChecked()){
367 RelatedListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
373 } else if (EditorMode == TRUE) {
376 long longSelected = -1;
378 // Work out the type of contact.
380 strValue = cmbType->GetValue();
382 RelatedListRelTypePtr->erase(RelatedListIndex);
384 if (strValue == _("Contact")){
386 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("contact")));
388 } else if (strValue == _("Acquaintance")){
390 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("acquaintance")));
392 } else if (strValue == _("Friend")){
394 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("friend")));
396 } else if (strValue == _("Met")){
398 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("met")));
400 } else if (strValue == _("Co-worker")){
402 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-worker")));
404 } else if (strValue == _("Colleague")){
406 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("colleague")));
408 } else if (strValue == _("Co-resident")){
410 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-resident")));
412 } else if (strValue == _("Neighbour")){
414 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("neighbor")));
416 } else if (strValue == _("Child")){
418 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("child")));
420 } else if (strValue == _("Parent")){
422 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("parent")));
424 } else if (strValue == _("Sibling")){
426 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sibling")));
428 } else if (strValue == _("Spouse")){
430 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("spouse")));
432 } else if (strValue == _("Kin")){
434 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("kin")));
436 } else if (strValue == _("Muse")){
438 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("muse")));
440 } else if (strValue == _("Crush")){
442 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("crush")));
444 } else if (strValue == _("Date")){
446 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("date")));
448 } else if (strValue == _("Sweetheart")){
450 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sweetheart")));
452 } else if (strValue == _("Me")){
454 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("me")));
456 } else if (strValue == _("Agent")){
458 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("agent")));
460 } else if (strValue == _("Emergency")){
462 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("emergency")));
466 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, strValue));
470 RelatedListPrefPtr->erase(RelatedListIndex);
472 if (chkUsePref->IsChecked()){
474 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, sliPriority->GetValue()));
478 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, 0));
482 // Get the related person/details.
484 RelatedListPtr->erase(RelatedListIndex);
485 RelatedListPtr->insert(std::make_pair(RelatedListIndex, txtRelated->GetValue()));
489 longSelected = RelatedListCtrlPtr->GetNextItem(longSelected,
491 wxLIST_STATE_SELECTED);
493 if (longSelected == -1){
497 RelatedListCtrlPtr->SetItem(longSelected, 0, cmbType->GetValue());
498 RelatedListCtrlPtr->SetItem(longSelected, 1, txtRelated->GetValue());
500 if (chkUsePref->IsChecked()){
502 RelatedListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
506 RelatedListCtrlPtr->SetItem(longSelected, 2, wxT(""));
515 void frmContactEditorRelated::CloseWindow( wxCommandEvent& event )
518 // Close this window.
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,
535 // Setup the pointers.
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;