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);
35 // Setup the list of types for the related drop down box.
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"));
60 void frmContactEditorRelated::SetEditorMode(bool EditMode, SectionType SectType)
63 // Set the editor mode.
65 if (EditMode == FALSE){
68 btnAction->SetLabel(_("Add"));
69 this->SetTitle(_("Add Related"));
71 } else if (EditMode == TRUE){
74 btnAction->SetLabel(_("Modify"));
75 this->SetTitle(_("Modify Related"));
77 std::map<int,int>::iterator intiter;
78 std::map<int,wxString>::iterator striter;
81 // Get the related data.
83 striter = RelatedListPtr->find(RelatedListIndex);
85 if (striter->first == RelatedListIndex){
87 strValue = striter->second;
91 txtRelated->SetValue(strValue);
95 // Get the related type.
97 striter = RelatedListRelTypePtr->find(RelatedListIndex);
99 if (striter->first == RelatedListIndex &&
100 striter != RelatedListRelTypePtr->end()){
102 strValue = striter->second;
106 if (strValue == wxT("contact")){
108 cmbType->SetValue(_("Contact"));
110 } else if (strValue == wxT("acquaintance")){
112 cmbType->SetValue(_("Acquaintance"));
114 } else if (strValue == wxT("friend")){
116 cmbType->SetValue(_("Friend"));
118 } else if (strValue == wxT("met")){
120 cmbType->SetValue(_("Met"));
122 } else if (strValue == wxT("co-worker")){
124 cmbType->SetValue(_("Co-worker"));
126 } else if (strValue == wxT("colleague")){
128 cmbType->SetValue(_("Colleague"));
130 } else if (strValue == wxT("co-resident")){
132 cmbType->SetValue(_("Co-resident"));
134 } else if (strValue == wxT("neighbor")){
136 cmbType->SetValue(_("Neighbour"));
138 } else if (strValue == wxT("child")){
140 cmbType->SetValue(_("Child"));
142 } else if (strValue == wxT("parent")){
144 cmbType->SetValue(_("Parent"));
146 } else if (strValue == wxT("sibling")){
148 cmbType->SetValue(_("Sibling"));
150 } else if (strValue == wxT("spouse")){
152 cmbType->SetValue(_("Spouse"));
154 } else if (strValue == wxT("kin")){
156 cmbType->SetValue(_("Kin"));
158 } else if (strValue == wxT("muse")){
160 cmbType->SetValue(_("Muse"));
162 } else if (strValue == wxT("crush")){
164 cmbType->SetValue(_("Crush"));
166 } else if (strValue == wxT("date")){
168 cmbType->SetValue(_("Date"));
170 } else if (strValue == wxT("sweetheart")){
172 cmbType->SetValue(_("Sweetheart"));
174 } else if (strValue == wxT("me")){
176 cmbType->SetValue(_("Me"));
178 } else if (strValue == wxT("agent")){
180 cmbType->SetValue(_("Agent"));
182 } else if (strValue == wxT("emergency")){
184 cmbType->SetValue(_("Emergency"));
188 cmbType->SetValue(strValue);
194 intiter = RelatedListPrefPtr->find(RelatedListIndex);
196 if (intiter->first == RelatedListIndex && intiter->second > 0 &&
197 intiter != RelatedListPrefPtr->end()){
199 priorityCtrl->SetValue(intiter->second);
200 priorityCtrl->EnablePriority(true);
206 EditSectionType = SectType;
210 void frmContactEditorRelated::ProcessData( wxCommandEvent& event )
217 if (EditorMode == FALSE){
221 RelatedListPtr->insert(std::make_pair(RelatedListIndex, txtRelated->GetValue()));
223 // Work out the type of contact.
225 strValue = cmbType->GetValue();
227 if (strValue == _("Contact")){
229 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("contact")));
231 } else if (strValue == _("Acquaintance")){
233 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("acquaintance")));
235 } else if (strValue == _("Friend")){
237 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("friend")));
239 } else if (strValue == _("Met")){
241 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("met")));
243 } else if (strValue == _("Co-worker")){
245 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-worker")));
247 } else if (strValue == _("Colleague")){
249 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("colleague")));
251 } else if (strValue == _("Co-resident")){
253 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-resident")));
255 } else if (strValue == _("Neighbour")){
257 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("neighbor")));
259 } else if (strValue == _("Child")){
261 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("child")));
263 } else if (strValue == _("Parent")){
265 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("parent")));
267 } else if (strValue == _("Sibling")){
269 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sibling")));
271 } else if (strValue == _("Spouse")){
273 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("spouse")));
275 } else if (strValue == _("Kin")){
277 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("kin")));
279 } else if (strValue == _("Muse")){
281 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("muse")));
283 } else if (strValue == _("Crush")){
285 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("crush")));
287 } else if (strValue == _("Date")){
289 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("date")));
291 } else if (strValue == _("Sweetheart")){
293 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sweetheart")));
295 } else if (strValue == _("Me")){
297 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("me")));
299 } else if (strValue == _("Agent")){
301 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("agent")));
303 } else if (strValue == _("Emergency")){
305 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("emergency")));
309 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, strValue));
315 if (EditSectionType == CE_GENERAL){
317 RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("")));
319 } else if (EditSectionType == CE_HOME) {
321 RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("home")));
323 } else if (EditSectionType == CE_WORK) {
325 RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("work")));
329 // Add Related Priority.
331 if (priorityCtrl->IsPriorityChecked()){
333 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, priorityCtrl->GetValue()));
337 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, 0));
345 coldata.SetId(RelatedListIndex);
346 coldata.SetData(RelatedListIndex);
347 coldata.SetText(cmbType->GetValue());
348 ListCtrlIndex = RelatedListCtrlPtr->InsertItem(coldata);
350 RelatedListCtrlPtr->SetItem(ListCtrlIndex, 1, txtRelated->GetValue());
352 if (priorityCtrl->IsPriorityChecked()){
354 RelatedListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
360 } else if (EditorMode == TRUE) {
363 long longSelected = -1;
365 // Work out the type of contact.
367 strValue = cmbType->GetValue();
369 RelatedListRelTypePtr->erase(RelatedListIndex);
371 if (strValue == _("Contact")){
373 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("contact")));
375 } else if (strValue == _("Acquaintance")){
377 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("acquaintance")));
379 } else if (strValue == _("Friend")){
381 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("friend")));
383 } else if (strValue == _("Met")){
385 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("met")));
387 } else if (strValue == _("Co-worker")){
389 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-worker")));
391 } else if (strValue == _("Colleague")){
393 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("colleague")));
395 } else if (strValue == _("Co-resident")){
397 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-resident")));
399 } else if (strValue == _("Neighbour")){
401 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("neighbor")));
403 } else if (strValue == _("Child")){
405 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("child")));
407 } else if (strValue == _("Parent")){
409 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("parent")));
411 } else if (strValue == _("Sibling")){
413 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sibling")));
415 } else if (strValue == _("Spouse")){
417 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("spouse")));
419 } else if (strValue == _("Kin")){
421 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("kin")));
423 } else if (strValue == _("Muse")){
425 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("muse")));
427 } else if (strValue == _("Crush")){
429 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("crush")));
431 } else if (strValue == _("Date")){
433 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("date")));
435 } else if (strValue == _("Sweetheart")){
437 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sweetheart")));
439 } else if (strValue == _("Me")){
441 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("me")));
443 } else if (strValue == _("Agent")){
445 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("agent")));
447 } else if (strValue == _("Emergency")){
449 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("emergency")));
453 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, strValue));
457 RelatedListPrefPtr->erase(RelatedListIndex);
459 if (priorityCtrl->IsPriorityChecked()){
461 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, priorityCtrl->GetValue()));
465 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, 0));
469 // Get the related person/details.
471 RelatedListPtr->erase(RelatedListIndex);
472 RelatedListPtr->insert(std::make_pair(RelatedListIndex, txtRelated->GetValue()));
476 longSelected = RelatedListCtrlPtr->GetNextItem(longSelected,
478 wxLIST_STATE_SELECTED);
480 if (longSelected == -1){
484 RelatedListCtrlPtr->SetItem(longSelected, 0, cmbType->GetValue());
485 RelatedListCtrlPtr->SetItem(longSelected, 1, txtRelated->GetValue());
487 if (priorityCtrl->IsPriorityChecked()){
489 RelatedListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
493 RelatedListCtrlPtr->SetItem(longSelected, 2, wxT(""));
502 void frmContactEditorRelated::CloseWindow( wxCommandEvent& event )
505 // Close this window.
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,
522 // Setup the pointers.
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;