Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
30a20b49f5c27ef4ba643eea7f5f2709eb9f9987
[xestiaab/.git] / source / contacteditor / frmContactEditorRoles.cpp
1 // frmContactEditorRoles.cpp - frmContactEditorRoles form.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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 "frmContactEditorRoles.h"
21 #include <map>
22 #include "../enums.h"
23 #include "../common/textprocessing.h"
25 frmContactEditorRoles::frmContactEditorRoles( wxWindow* parent )
26 :
27 frmContactEditorRolesADT( parent )
28 {
29         
30         // Setup the window.
31         
32         EditorMode = FALSE;
33         sliPriority->Disable();
34 }
36 void frmContactEditorRoles::EnablePriority( wxCommandEvent& event )
37 {
38         
39         // Enable/disable the priority setting.
40         
41         if (chkUsePref->IsChecked()){
42                 sliPriority->Enable();
43         } else {
44                 sliPriority->Disable();
45         }
46         
47 }
49 void frmContactEditorRoles::ProcessAction( wxCommandEvent& event )
50 {
51         
52         // Process action.
53         
54         // Set if the editor is adding or editing an address.
55         // FALSE = Add
56         // TRUE = Edit
58         long ListCtrlIndex;
59         
60         if (EditorMode == FALSE){
61         
62                 wxString strValue;
63                 
64                 // Get the website address.
65                 
66                 RolesListPtr->insert(std::make_pair(RolesListIndex, txtRole->GetValue()));
67                 
68                 // Get the type of website.
69                 
70                 if (EditSectionType == CE_GENERAL){
71                 
72                         RolesListTypePtr->insert(std::make_pair(RolesListIndex, wxT("")));
73                 
74                 } else if (EditSectionType == CE_HOME) {
75                 
76                         RolesListTypePtr->insert(std::make_pair(RolesListIndex, wxT("home")));
77                 
78                 } else if (EditSectionType == CE_WORK) {
79                 
80                         RolesListTypePtr->insert(std::make_pair(RolesListIndex, wxT("work")));
81                 
82                 }
83                 
84                 // Add the website priority.
85                 
86                 if (chkUsePref->IsChecked()){
87                 
88                         RolesListPrefPtr->insert(std::make_pair(RolesListIndex, sliPriority->GetValue()));
89                 
90                 } else {
91                 
92                         RolesListPrefPtr->insert(std::make_pair(RolesListIndex, 0));            
93                 
94                 }
95                 
96                 // Add to the form.
97                 
98                 wxListItem coldata;
99                 
100                 coldata.SetId(RolesListIndex);
101                 coldata.SetData(RolesListIndex);                
102                 coldata.SetText(txtRole->GetValue());
103                 ListCtrlIndex = RolesListCtrlPtr->InsertItem(coldata);
104                 
105                 if (chkUsePref->IsChecked()){
106                 
107                         RolesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
108                 
109                 }               
110         
111                 this->Close();          
112         
113         } else {
114         
115                 // Update the title.
116                 long longSelected = -1;         
117                 wxString strValue;              
118                 RolesListPtr->erase(RolesListIndex);
119                 RolesListPtr->insert(std::make_pair(RolesListIndex, txtRole->GetValue()));
120                 
121                 // Update the slider priority.
122                 
123                 RolesListPrefPtr->erase(RolesListIndex);
124                 
125                 if (chkUsePref->IsChecked()){
126                 
127                         RolesListPrefPtr->insert(std::make_pair(RolesListIndex, sliPriority->GetValue()));
128                 
129                 } else {
130                 
131                         RolesListPrefPtr->insert(std::make_pair(RolesListIndex, 0));
132                 
133                 }               
134                 
135                 // Update the form.
136                 
137                 longSelected = RolesListCtrlPtr->GetNextItem(longSelected, 
138                         wxLIST_NEXT_ALL,
139                         wxLIST_STATE_SELECTED);
140                         
141                 if (longSelected == -1){
142                         return;
143                 }               
144                 
145                 RolesListCtrlPtr->SetItem(longSelected, 0, txtRole->GetValue());
146                 
147                 if (chkUsePref->IsChecked()){
148                 
149                         RolesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
150                 
151                 } else {
152                 
153                         RolesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
154                 
155                 }               
156         
157                 this->Close();
158         
159         }
162 void frmContactEditorRoles::SetEditorMode(bool EditMode, SectionType SectType)
164         
165         // Set the editor mode.
166         
167         // Set if the editor is adding or editing an address.
168         // FALSE = Add
169         // TRUE = Edit
170         
171         if (EditMode == FALSE){
172         
173                 EditorMode = FALSE;
174                 btnAction->SetLabel(_("Add"));
175                 this->SetTitle(_("Add Title"));
176         
177         } else if (EditMode == TRUE){
178         
179                 EditorMode = TRUE;
180                 btnAction->SetLabel(_("Modify"));
181                 this->SetTitle(_("Modify Title"));
182                 
183                 std::map<int,int>::iterator intiter;
184                 std::map<int,wxString>::iterator striter;               
185                 wxString strValue;
186                 
187                 // Load the data into the form. Get the website.
188                 
189                 striter = RolesListPtr->find(RolesListIndex);
190                  
191                 if (striter->first == RolesListIndex){
192                 
193                         strValue = striter->second;
194                 
195                 }
196                 
197                 txtRole->SetValue(strValue);
198                 
199                 strValue.Clear();
200                 
201                 // Get the website priority.
202                 
203                 intiter = RolesListPrefPtr->find(RolesListIndex);
204                 
205                 if (intiter->first == RolesListIndex && intiter->second > 0 &&
206                         intiter != RolesListPrefPtr->end()){
207                 
208                         sliPriority->SetValue(intiter->second);
209                         sliPriority->Enable();
210                         chkUsePref->SetValue(TRUE);
211                 
212                 }       
213                 
214         }
215         
216         EditSectionType = SectType;     
217                 
220 void frmContactEditorRoles::CloseWindow( wxCommandEvent& event )
222         
223         // Close this window.
224         
225         this->Close();
226         
229 void frmContactEditorRoles::SetupPointers(std::map<int, wxString> *RolesList,
230         std::map<int, wxString> *RolesListLanguage,
231         std::map<int, wxString> *RolesListAltID,
232         std::map<int, wxString> *RolesListPID,
233         std::map<int, wxString> *RolesListType,
234         std::map<int, wxString> *RolesListTokens,
235         std::map<int, int> *RolesListPref,
236         wxListCtrl *RolesListCtrl,
237         int RolesIndex )
240         // Setup the pointers.
241         
242         RolesListPtr = RolesList;
243         RolesListLanguagePtr = RolesListLanguage;
244         RolesListAltIDPtr = RolesListAltID;
245         RolesListPIDPtr = RolesListPID;
246         RolesListTypePtr = RolesListType;
247         RolesListTokensPtr = RolesListTokens;
248         RolesListPrefPtr = RolesListPref;
249         RolesListCtrlPtr = RolesListCtrl;
250         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