Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
macOS: Added languages.cpp/.h to Xcode project.
[xestiaab/.git] / source / contacteditor / frmContactEditorLanguages.cpp
1 // frmContactEditorLanguages.cpp - frmContactEditorLanguages 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 "frmContactEditorLanguages.h"
20 #include "../common/textprocessing.h"
21 #include <map>
23 frmContactEditorLanguages::frmContactEditorLanguages( wxWindow* parent )
24 :
25 frmContactEditorLanguagesADT( parent )
26 {
27         
28         // Setup the window.
29         
30         EditorMode = FALSE;
31         sliPriority->Disable();
32 }
34 void frmContactEditorLanguages::EnablePriority( wxCommandEvent& event )
35 {
36         
37         // Enable/disable the priority setting.
38         
39         if (chkUsePref->IsChecked()){
40                 sliPriority->Enable();
41         } else {
42                 sliPriority->Disable();
43         }
44         
45 }
47 void frmContactEditorLanguages::SetEditorMode(bool EditMode, SectionType SectType)
48 {
50         // Set the editor mode for adding or editing an email address.
52         if (EditMode == FALSE){
53         
54                 EditorMode = FALSE;
55                 btnAction->SetLabel(_("Add"));
56                 this->SetTitle(_("Add Language"));
57         
58         } else if (EditMode == TRUE){
59         
60                 EditorMode = TRUE;
61                 btnAction->SetLabel(_("Modify"));
62                 this->SetTitle(_("Modify Language"));
63         
64                 std::map<int,int>::iterator intiter;
65                 std::map<int,wxString>::iterator striter;
66                 wxString strValue;
67                 
68                 // Load the data into the form.
69                 
70                 striter = LanguageListPtr->find(LanguageListIndex);
71                  
72                 if (striter->first == LanguageListIndex){
73                 
74                         strValue = striter->second;
75                 
76                 }
77                 
78                 txtLanguage->SetValue(strValue);
79                 
80                 // Setup the Slider.
81                 
82                 intiter = LanguageListPrefPtr->find(LanguageListIndex);
83                 
84                 if (intiter->first == LanguageListIndex && intiter->second > 0 &&
85                         intiter != LanguageListPrefPtr->end()){
86                 
87                         sliPriority->SetValue(intiter->second);
88                         sliPriority->Enable();
89                         chkUsePref->SetValue(TRUE);
90                 
91                 }       
92                 
93         }
94         
95         EditSectionType = SectType;
96 }
98 void frmContactEditorLanguages::ProcessAction( wxCommandEvent& event )
99 {
101         // Process the action.
102         
103         long ListCtrlIndex;
105         if (EditorMode == FALSE){
106         
107                 // Add the language to the list.
109                 wxString strValue;
110                 
111                 // Add language.
112                 
113                 LanguageListPtr->insert(std::make_pair(LanguageListIndex, txtLanguage->GetValue()));
114                 
115                 // Add Email type.
116                 
117                 if (EditSectionType == CE_GENERAL){
118                 
119                         LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("")));
120                 
121                 } else if (EditSectionType == CE_HOME) {
122                 
123                         LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("home")));
124                 
125                 } else if (EditSectionType == CE_WORK) {
126                 
127                         LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("work")));
128                 
129                 }
130                 
131                 // Add Language priority.
132                 
133                 if (chkUsePref->IsChecked()){
134                 
135                         LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, sliPriority->GetValue()));
136                 
137                 } else {
138                 
139                         LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, 0));              
140                 
141                 }               
142                 
143                 // Add the data to the form.
144                 
145                 wxListItem coldata;
146                 
147                 coldata.SetId(LanguageListIndex);
148                 coldata.SetData(LanguageListIndex);             
149                 coldata.SetText(txtLanguage->GetValue());
150                 ListCtrlIndex = LanguageListCtrlPtr->InsertItem(coldata);
151                 
152                 if (chkUsePref->IsChecked()){
153                 
154                         LanguageListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
155                 
156                 }
157                 
158                 this->Close();          
159         
160         } else if (EditorMode == TRUE){
161         
162                 // Edit the language.
163                 
164                 wxString strAddress;
165                 wxString strValue;
166                 long longSelected = -1;
168                 LanguageListPtr->erase(LanguageListIndex);
169                 LanguageListPtr->insert(std::make_pair(LanguageListIndex, txtLanguage->GetValue()));
170                 
171                 LanguageListPrefPtr->erase(LanguageListIndex);
172                 
173                 if (chkUsePref->IsChecked()){
174                 
175                         LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, sliPriority->GetValue()));
176                 
177                 } else {
178                 
179                         LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, 0));              
180                 
181                 }
182                 
183                 longSelected = LanguageListCtrlPtr->GetNextItem(longSelected, 
184                         wxLIST_NEXT_ALL,
185                         wxLIST_STATE_SELECTED);
186                         
187                 if (longSelected == -1){
188                         return;
189                 }
190                 
191                 LanguageListCtrlPtr->SetItem(longSelected, 0, txtLanguage->GetValue());         
192                 
193                 if (chkUsePref->IsChecked()){
194                 
195                         LanguageListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
196                 
197                 } else {
198                 
199                         LanguageListCtrlPtr->SetItem(longSelected, 1, wxT(""));
200                 
201                 }       
202                         
203                 this->Close();
204         
205         }
209 void frmContactEditorLanguages::CloseWindow( wxCommandEvent& event )
212         // Close the window.
213         
214         this->Close();
218 void frmContactEditorLanguages::SetupPointers(std::map<int, wxString> *LanguageList,
219         std::map<int, wxString> *LanguageListAltID,
220         std::map<int, wxString> *LanguageListPID,
221         std::map<int, wxString> *LanguageListType,
222         std::map<int, wxString> *LanguageListTokens,
223         std::map<int, int> *LanguageListPref,
224         wxListCtrl *LanguageListCtrl,
225         int LanguageIndex )
228         // Setup the pointers so that the data can be processed without
229         // duplication.
231         LanguageListPtr = LanguageList;
232         LanguageListAltIDPtr = LanguageListAltID;
233         LanguageListPIDPtr = LanguageListPID;
234         LanguageListTypePtr = LanguageListType;
235         LanguageListTokensPtr = LanguageListTokens;
236         LanguageListPrefPtr = LanguageListPref;
237         LanguageListCtrlPtr = LanguageListCtrl;
238         LanguageListIndex = LanguageIndex;
239         
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