Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Initial import of code already done for Xestia Address Book
[xestiaab/.git] / source / contacteditor / frmContactEditorTitles.cpp
1 #include "frmContactEditorTitles.h"
3 #include <map>
4 #include "../enums.h"
5 #include "../common/textprocessing.h"
7 frmContactEditorTitles::frmContactEditorTitles( wxWindow* parent )
8 :
9 frmContactEditorTitlesADT( parent )
10 {
11         EditorMode = FALSE;
12         sliPriority->Disable();
13 }
15 void frmContactEditorTitles::EnablePriority( wxCommandEvent& event )
16 {
17         if (chkUsePref->IsChecked()){
18                 sliPriority->Enable();
19         } else {
20                 sliPriority->Disable();
21         }
22 }
24 void frmContactEditorTitles::ProcessAction( wxCommandEvent& event )
25 {
26         // Set if the editor is adding or editing an address.
27         // FALSE = Add
28         // TRUE = Edit
30         long ListCtrlIndex;
31         
32         if (EditorMode == FALSE){
33         
34                 wxString strValue;
35                 
36                 // Get the website address.
37                 
38                 TitlesListPtr->insert(std::make_pair(TitlesListIndex, txtTitle->GetValue()));
39                 
40                 // Get the type of website.
41                 
42                 if (EditSectionType == CE_GENERAL){
43                 
44                         TitlesListTypePtr->insert(std::make_pair(TitlesListIndex, wxT("")));
45                 
46                 } else if (EditSectionType == CE_HOME) {
47                 
48                         TitlesListTypePtr->insert(std::make_pair(TitlesListIndex, wxT("home")));
49                 
50                 } else if (EditSectionType == CE_WORK) {
51                 
52                         TitlesListTypePtr->insert(std::make_pair(TitlesListIndex, wxT("work")));
53                 
54                 }
55                 
56                 // Add the website priority.
57                 
58                 if (chkUsePref->IsChecked()){
59                 
60                         TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, sliPriority->GetValue()));
61                 
62                 } else {
63                 
64                         TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, 0));          
65                 
66                 }
67                 
68                 // Add to the form.
69                 
70                 wxListItem coldata;
71                 
72                 coldata.SetId(TitlesListIndex);
73                 coldata.SetData(TitlesListIndex);               
74                 coldata.SetText(txtTitle->GetValue());
75                 ListCtrlIndex = TitlesListCtrlPtr->InsertItem(coldata);
76                 
77                 if (chkUsePref->IsChecked()){
78                 
79                         TitlesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
80                 
81                 }               
82         
83                 this->Close();          
84         
85         } else {
86         
87                 // Update the title.
88                 long longSelected = -1;         
89                 wxString strValue;
90                 TitlesListPtr->erase(TitlesListIndex);
91                 TitlesListPtr->insert(std::make_pair(TitlesListIndex, txtTitle->GetValue()));
92                 
93                 // Update the slider priority.
94                 
95                 TitlesListPrefPtr->erase(TitlesListIndex);
96                 
97                 if (chkUsePref->IsChecked()){
98                 
99                         TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, sliPriority->GetValue()));
100                 
101                 } else {
102                 
103                         TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, 0));
104                 
105                 }               
106                 
107                 // Update the form.
108                 
109                 longSelected = TitlesListCtrlPtr->GetNextItem(longSelected, 
110                         wxLIST_NEXT_ALL,
111                         wxLIST_STATE_SELECTED);
112                         
113                 if (longSelected == -1){
114                         return;
115                 }               
116                 
117                 TitlesListCtrlPtr->SetItem(longSelected, 0, txtTitle->GetValue());
118                 
119                 if (chkUsePref->IsChecked()){
120                 
121                         TitlesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
122                 
123                 } else {
124                 
125                         TitlesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
126                 
127                 }               
128         
129                 this->Close();
130         
131         }
134 void frmContactEditorTitles::SetEditorMode(bool EditMode, SectionType SectType)
136         // Set if the editor is adding or editing an address.
137         // FALSE = Add
138         // TRUE = Edit
139         
140         if (EditMode == FALSE){
141         
142                 EditorMode = FALSE;
143                 btnAction->SetLabel(_("Add"));
144                 this->SetTitle(_("Add Title"));
145         
146         } else if (EditMode == TRUE){
147         
148                 EditorMode = TRUE;
149                 btnAction->SetLabel(_("Modify"));
150                 this->SetTitle(_("Modify Title"));
151                 
152                 std::map<int,int>::iterator intiter;
153                 std::map<int,wxString>::iterator striter;               
154                 wxString strValue;
155                 
156                 // Load the data into the form. Get the website.
157                 
158                 striter = TitlesListPtr->find(TitlesListIndex);
159                  
160                 if (striter->first == TitlesListIndex){
161                 
162                         strValue = striter->second;
163                 
164                 }
165                 
166                 txtTitle->SetValue(strValue);
167                 
168                 strValue.Clear();
169                 
170                 // Get the website priority.
171                 
172                 intiter = TitlesListPrefPtr->find(TitlesListIndex);
173                 
174                 if (intiter->first == TitlesListIndex && intiter->second > 0){
175                 
176                         sliPriority->SetValue(intiter->second);
177                         sliPriority->Enable();
178                         chkUsePref->SetValue(TRUE);
179                 
180                 }       
181                 
182         }
183         
184         EditSectionType = SectType;
185                 
188 void frmContactEditorTitles::CloseWindow( wxCommandEvent& event )
190         this->Close();
193 void frmContactEditorTitles::SetupPointers(std::map<int, wxString> *TitlesList,
194         std::map<int, wxString> *TitlesListLanguage,
195         std::map<int, wxString> *TitlesListAltID,
196         std::map<int, wxString> *TitlesListPID,
197         std::map<int, wxString> *TitlesListType,
198         std::map<int, wxString> *TitlesListTokens,
199         std::map<int, int> *TitlesListPref,
200         wxListCtrl *TitlesListCtrl,
201         int TitlesIndex )
204         TitlesListPtr = TitlesList;
205         TitlesListLanguagePtr = TitlesListLanguage;
206         TitlesListAltIDPtr = TitlesListAltID;
207         TitlesListPIDPtr = TitlesListPID;
208         TitlesListTypePtr = TitlesListType;
209         TitlesListTokensPtr = TitlesListTokens;
210         TitlesListPrefPtr = TitlesListPref;
211         TitlesListCtrlPtr = TitlesListCtrl;
212         TitlesListIndex = TitlesIndex;
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy