Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Fixed potential crash with frmContactEditorWebsites in Edit mode.
[xestiaab/.git] / source / contacteditor / frmContactEditorNickname.cpp
1 // frmContactEditorNickname.cpp - frmContactEditorNickname 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 "frmContactEditorNickname.h"
20 #include "../common/textprocessing.h"
22 frmContactEditorNickname::frmContactEditorNickname( wxWindow* parent )
23 :
24 frmContactEditorNicknameADT( parent )
25 {
27 }
29 void frmContactEditorNickname::InitAddressEditor( wxInitDialogEvent& event )
30 {
31         // Do nothing with this subroutine for the time being.
32 }
34 void frmContactEditorNickname::EnablePriority( wxCommandEvent& event )
35 {
36         if (chkUsePref->IsChecked()){
37                 sliPriority->Enable();
38         } else {
39                 sliPriority->Disable();
40         }
41 }
43 void frmContactEditorNickname::ProcessData( wxCommandEvent& event )
44 {
45         long ListCtrlIndex;
47         if (EditorMode == FALSE){
48         
49                 // Add the language to the list.
51                 wxString strValue;
52                 
53                 // Add nickname.
54                 
55                 NicknamesListPtr->insert(std::make_pair(NicknamesListIndex, txtNickname->GetValue()));
56                 
57                 // Add nickname type.
58                 
59                 if (EditSectionType == CE_GENERAL){
60                 
61                         NicknamesListTypePtr->insert(std::make_pair(NicknamesListIndex, wxT("")));
62                 
63                 } else if (EditSectionType == CE_HOME) {
64                 
65                         NicknamesListTypePtr->insert(std::make_pair(NicknamesListIndex, wxT("home")));
66                 
67                 } else if (EditSectionType == CE_WORK) {
68                 
69                         NicknamesListTypePtr->insert(std::make_pair(NicknamesListIndex, wxT("work")));
70                 
71                 }
72                 
73                 // Add nickname language.
74                 
75                 NicknamesListLanguagePtr->insert(std::make_pair(NicknamesListIndex, cmbLanguage->GetValue()));
76                 
77                 // Add nickname priority.
78                 
79                 if (chkUsePref->IsChecked()){
80                 
81                         NicknamesListPrefPtr->insert(std::make_pair(NicknamesListIndex, sliPriority->GetValue()));
82                 
83                 } else {
84                 
85                         NicknamesListPrefPtr->insert(std::make_pair(NicknamesListIndex, 0));            
86                 
87                 }               
88                 
89                 // Add the data to the form.
90                 
91                 wxListItem coldata;
92                 
93                 coldata.SetId(NicknamesListIndex);
94                 coldata.SetData(NicknamesListIndex);            
95                 coldata.SetText(txtNickname->GetValue());
96                 ListCtrlIndex = NicknamesListCtrlPtr->InsertItem(coldata);
97                 
98                 if (chkUsePref->IsChecked()){
99                 
100                         NicknamesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
101                 
102                 }
103                 
104                 this->Close();          
105         
106         } else if (EditorMode == TRUE){
107         
108                 // Edit the language.
109                 
110                 wxString strAddress;
111                 wxString strValue;
112                 long longSelected = -1;
114                 NicknamesListPtr->erase(NicknamesListIndex);
115                 NicknamesListPtr->insert(std::make_pair(NicknamesListIndex, txtNickname->GetValue()));
116                 
117                 NicknamesListPrefPtr->erase(NicknamesListIndex);
118                 
119                 if (chkUsePref->IsChecked()){
120                 
121                         NicknamesListPrefPtr->insert(std::make_pair(NicknamesListIndex, sliPriority->GetValue()));
122                 
123                 } else {
124                 
125                         NicknamesListPrefPtr->insert(std::make_pair(NicknamesListIndex, 0));            
126                 
127                 }
128                 
129                 NicknamesListLanguagePtr->erase(NicknamesListIndex);
130                 NicknamesListLanguagePtr->insert(std::make_pair(NicknamesListIndex, cmbLanguage->GetValue()));
131                 
132                 longSelected = NicknamesListCtrlPtr->GetNextItem(longSelected, 
133                         wxLIST_NEXT_ALL,
134                         wxLIST_STATE_SELECTED);
135                         
136                 if (longSelected == -1){
137                         return;
138                 }
139                 
140                 NicknamesListCtrlPtr->SetItem(longSelected, 0, txtNickname->GetValue());
141                 
142                 if (chkUsePref->IsChecked()){
143                 
144                         NicknamesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
145                 
146                 } else {
147                 
148                         NicknamesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
149                 
150                 }       
151                         
152                 this->Close();
153         
154         }
158 void frmContactEditorNickname::CloseWindow( wxCommandEvent& event )
160         this->Close();
163 void frmContactEditorNickname::SetEditorMode(bool EditMode, SectionType SectType)
165         // Set if the editor is adding or editing an address.
166         // FALSE = Add
167         // TRUE = Edit
168         
169         if (EditMode == FALSE){
170         
171                 EditorMode = FALSE;
172                 btnAction->SetLabel(_("Add"));
173                 this->SetTitle(_("Add Nickname"));
174         
175         } else if (EditMode == TRUE){
176         
177                 EditorMode = TRUE;
178                 btnAction->SetLabel(_("Modify"));
179                 this->SetTitle(_("Modify Nickname"));
180                 
181                 std::map<int,int>::iterator intiter;
182                 std::map<int,wxString>::iterator striter;               
183                 wxString strValue;
184                 
185                 // Load the data into the form. Get the website.
186                 
187                 striter = NicknamesListPtr->find(NicknamesListIndex);
188                  
189                 if (striter->first == NicknamesListIndex){
190                 
191                         strValue = striter->second;
192                 
193                 }
194                 
195                 txtNickname->SetValue(strValue);
196                 
197                 strValue.Clear();
198                 
199                 striter = NicknamesListLanguagePtr->find(NicknamesListIndex);
200                  
201                 if (striter->first == NicknamesListIndex &&
202                         striter != NicknamesListLanguagePtr->end()){
203                 
204                         strValue = striter->second;
205                 
206                 }
207                 
208                 cmbLanguage->SetValue(strValue);
209                 strValue.Clear();
210                 
211                 // Get the website priority.
212                 
213                 intiter = NicknamesListPrefPtr->find(NicknamesListIndex);
214                 
215                 if (intiter->first == NicknamesListIndex && intiter->second > 0 &&
216                         intiter != NicknamesListPrefPtr->end()){
217                 
218                         sliPriority->SetValue(intiter->second);
219                         sliPriority->Enable();
220                         chkUsePref->SetValue(TRUE);
221                 
222                 }       
223                 
224         }
225         
226         EditSectionType = SectType;     
227                 
230 void frmContactEditorNickname::SetupPointers(std::map<int, wxString> *NicknamesList,            
231         std::map<int, wxString> *NicknamesListAltID,
232         std::map<int, wxString> *NicknamesListPID,
233         std::map<int, wxString> *NicknamesListType,
234         std::map<int, wxString> *NicknamesListLanguage,
235         std::map<int, wxString> *NicknamesListTokens,
236         std::map<int, int> *NicknamesListPref,
237         wxListCtrl *NicknamesListCtrl,
238         int NicknamesIndex )
241         NicknamesListPtr = NicknamesList;
242         NicknamesListAltIDPtr = NicknamesListAltID;
243         NicknamesListPIDPtr = NicknamesListPID;
244         NicknamesListTypePtr = NicknamesListType;
245         NicknamesListLanguagePtr = NicknamesListLanguage;
246         NicknamesListTokensPtr = NicknamesListTokens;
247         NicknamesListPrefPtr = NicknamesListPref;
248         NicknamesListCtrlPtr = NicknamesListCtrl;
249         NicknamesListIndex = NicknamesIndex;
250         
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