Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Initial import of code already done for Xestia Address Book
[xestiaab/.git] / source / contacteditor / frmContactEditorRoles.cpp
1 #include "frmContactEditorRoles.h"
3 #include <map>
4 #include "../enums.h"
5 #include "../common/textprocessing.h"
7 frmContactEditorRoles::frmContactEditorRoles( wxWindow* parent )
8 :
9 frmContactEditorRolesADT( parent )
10 {
11         EditorMode = FALSE;
12         sliPriority->Disable();
13 }
15 void frmContactEditorRoles::EnablePriority( wxCommandEvent& event )
16 {
17         if (chkUsePref->IsChecked()){
18                 sliPriority->Enable();
19         } else {
20                 sliPriority->Disable();
21         }
22 }
24 void frmContactEditorRoles::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                 RolesListPtr->insert(std::make_pair(RolesListIndex, txtRole->GetValue()));
39                 
40                 // Get the type of website.
41                 
42                 if (EditSectionType == CE_GENERAL){
43                 
44                         RolesListTypePtr->insert(std::make_pair(RolesListIndex, wxT("")));
45                 
46                 } else if (EditSectionType == CE_HOME) {
47                 
48                         RolesListTypePtr->insert(std::make_pair(RolesListIndex, wxT("home")));
49                 
50                 } else if (EditSectionType == CE_WORK) {
51                 
52                         RolesListTypePtr->insert(std::make_pair(RolesListIndex, wxT("work")));
53                 
54                 }
55                 
56                 // Add the website priority.
57                 
58                 if (chkUsePref->IsChecked()){
59                 
60                         RolesListPrefPtr->insert(std::make_pair(RolesListIndex, sliPriority->GetValue()));
61                 
62                 } else {
63                 
64                         RolesListPrefPtr->insert(std::make_pair(RolesListIndex, 0));            
65                 
66                 }
67                 
68                 // Add to the form.
69                 
70                 wxListItem coldata;
71                 
72                 coldata.SetId(RolesListIndex);
73                 coldata.SetData(RolesListIndex);                
74                 coldata.SetText(txtRole->GetValue());
75                 ListCtrlIndex = RolesListCtrlPtr->InsertItem(coldata);
76                 
77                 if (chkUsePref->IsChecked()){
78                 
79                         RolesListCtrlPtr->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                 RolesListPtr->erase(RolesListIndex);
91                 RolesListPtr->insert(std::make_pair(RolesListIndex, txtRole->GetValue()));
92                 
93                 // Update the slider priority.
94                 
95                 RolesListPrefPtr->erase(RolesListIndex);
96                 
97                 if (chkUsePref->IsChecked()){
98                 
99                         RolesListPrefPtr->insert(std::make_pair(RolesListIndex, sliPriority->GetValue()));
100                 
101                 } else {
102                 
103                         RolesListPrefPtr->insert(std::make_pair(RolesListIndex, 0));
104                 
105                 }               
106                 
107                 // Update the form.
108                 
109                 longSelected = RolesListCtrlPtr->GetNextItem(longSelected, 
110                         wxLIST_NEXT_ALL,
111                         wxLIST_STATE_SELECTED);
112                         
113                 if (longSelected == -1){
114                         return;
115                 }               
116                 
117                 RolesListCtrlPtr->SetItem(longSelected, 0, txtRole->GetValue());
118                 
119                 if (chkUsePref->IsChecked()){
120                 
121                         RolesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
122                 
123                 } else {
124                 
125                         RolesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
126                 
127                 }               
128         
129                 this->Close();
130         
131         }
134 void frmContactEditorRoles::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 = RolesListPtr->find(RolesListIndex);
159                  
160                 if (striter->first == RolesListIndex){
161                 
162                         strValue = striter->second;
163                 
164                 }
165                 
166                 txtRole->SetValue(strValue);
167                 
168                 strValue.Clear();
169                 
170                 // Get the website priority.
171                 
172                 intiter = RolesListPrefPtr->find(RolesListIndex);
173                 
174                 if (intiter->first == RolesListIndex && 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 frmContactEditorRoles::CloseWindow( wxCommandEvent& event )
190         this->Close();
193 void frmContactEditorRoles::SetupPointers(std::map<int, wxString> *RolesList,
194         std::map<int, wxString> *RolesListLanguage,
195         std::map<int, wxString> *RolesListAltID,
196         std::map<int, wxString> *RolesListPID,
197         std::map<int, wxString> *RolesListType,
198         std::map<int, wxString> *RolesListTokens,
199         std::map<int, int> *RolesListPref,
200         wxListCtrl *RolesListCtrl,
201         int RolesIndex )
204         RolesListPtr = RolesList;
205         RolesListLanguagePtr = RolesListLanguage;
206         RolesListAltIDPtr = RolesListAltID;
207         RolesListPIDPtr = RolesListPID;
208         RolesListTypePtr = RolesListType;
209         RolesListTokensPtr = RolesListTokens;
210         RolesListPrefPtr = RolesListPref;
211         RolesListCtrlPtr = RolesListCtrl;
212         RolesListIndex = RolesIndex;
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