Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditorLanguages: Implemented priority control
[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         priorityCtrl = new XABPriorityCtrl(tabGeneral);
32         szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
33         
34 }
36 void frmContactEditorLanguages::SetEditorMode(bool EditMode, SectionType SectType)
37 {
39         // Set the editor mode for adding or editing an email address.
41         if (EditMode == FALSE){
42         
43                 EditorMode = FALSE;
44                 btnAction->SetLabel(_("Add"));
45                 this->SetTitle(_("Add Language"));
46         
47         } else if (EditMode == TRUE){
48         
49                 EditorMode = TRUE;
50                 btnAction->SetLabel(_("Modify"));
51                 this->SetTitle(_("Modify Language"));
52         
53                 std::map<int,int>::iterator intiter;
54                 std::map<int,wxString>::iterator striter;
55                 wxString strValue;
56                 
57                 // Load the data into the form.
58                 
59                 striter = LanguageListPtr->find(LanguageListIndex);
60                  
61                 if (striter->first == LanguageListIndex){
62                 
63                         strValue = striter->second;
64                 
65                 }
66                 
67                 txtLanguage->SetValue(strValue);
68                 
69                 // Setup the Slider.
70                 
71                 intiter = LanguageListPrefPtr->find(LanguageListIndex);
72                 
73                 if (intiter->first == LanguageListIndex && intiter->second > 0 &&
74                         intiter != LanguageListPrefPtr->end()){
75                 
76                         priorityCtrl->SetValue(intiter->second);
77                         priorityCtrl->EnablePriority(true);
78                 
79                 }       
80                 
81         }
82         
83         EditSectionType = SectType;
84 }
86 void frmContactEditorLanguages::ProcessAction( wxCommandEvent& event )
87 {
89         // Process the action.
90         
91         long ListCtrlIndex;
93         if (EditorMode == FALSE){
94         
95                 // Add the language to the list.
97                 wxString strValue;
98                 
99                 // Add language.
100                 
101                 LanguageListPtr->insert(std::make_pair(LanguageListIndex, txtLanguage->GetValue()));
102                 
103                 // Add Email type.
104                 
105                 if (EditSectionType == CE_GENERAL){
106                 
107                         LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("")));
108                 
109                 } else if (EditSectionType == CE_HOME) {
110                 
111                         LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("home")));
112                 
113                 } else if (EditSectionType == CE_WORK) {
114                 
115                         LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("work")));
116                 
117                 }
118                 
119                 // Add Language priority.
120                 
121                 if (priorityCtrl->IsPriorityChecked()){
122                 
123                         LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, priorityCtrl->GetValue()));
124                 
125                 } else {
126                 
127                         LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, 0));              
128                 
129                 }               
130                 
131                 // Add the data to the form.
132                 
133                 wxListItem coldata;
134                 
135                 coldata.SetId(LanguageListIndex);
136                 coldata.SetData(LanguageListIndex);             
137                 coldata.SetText(txtLanguage->GetValue());
138                 ListCtrlIndex = LanguageListCtrlPtr->InsertItem(coldata);
139                 
140                 if (priorityCtrl->IsPriorityChecked()){
141                 
142                         LanguageListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
143                 
144                 }
145                 
146                 this->Close();          
147         
148         } else if (EditorMode == TRUE){
149         
150                 // Edit the language.
151                 
152                 wxString strAddress;
153                 wxString strValue;
154                 long longSelected = -1;
156                 LanguageListPtr->erase(LanguageListIndex);
157                 LanguageListPtr->insert(std::make_pair(LanguageListIndex, txtLanguage->GetValue()));
158                 
159                 LanguageListPrefPtr->erase(LanguageListIndex);
160                 
161                 if (priorityCtrl->IsPriorityChecked()){
162                 
163                         LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, priorityCtrl->GetValue()));
164                 
165                 } else {
166                 
167                         LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, 0));              
168                 
169                 }
170                 
171                 longSelected = LanguageListCtrlPtr->GetNextItem(longSelected, 
172                         wxLIST_NEXT_ALL,
173                         wxLIST_STATE_SELECTED);
174                         
175                 if (longSelected == -1){
176                         return;
177                 }
178                 
179                 LanguageListCtrlPtr->SetItem(longSelected, 0, txtLanguage->GetValue());         
180                 
181                 if (priorityCtrl->IsPriorityChecked()){
182                 
183                         LanguageListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
184                 
185                 } else {
186                 
187                         LanguageListCtrlPtr->SetItem(longSelected, 1, wxT(""));
188                 
189                 }       
190                         
191                 this->Close();
192         
193         }
197 void frmContactEditorLanguages::CloseWindow( wxCommandEvent& event )
200         // Close the window.
201         
202         this->Close();
206 void frmContactEditorLanguages::SetupPointers(std::map<int, wxString> *LanguageList,
207         std::map<int, wxString> *LanguageListAltID,
208         std::map<int, wxString> *LanguageListPID,
209         std::map<int, wxString> *LanguageListType,
210         std::map<int, wxString> *LanguageListTokens,
211         std::map<int, int> *LanguageListPref,
212         wxListCtrl *LanguageListCtrl,
213         int LanguageIndex )
216         // Setup the pointers so that the data can be processed without
217         // duplication.
219         LanguageListPtr = LanguageList;
220         LanguageListAltIDPtr = LanguageListAltID;
221         LanguageListPIDPtr = LanguageListPID;
222         LanguageListTypePtr = LanguageListType;
223         LanguageListTokensPtr = LanguageListTokens;
224         LanguageListPrefPtr = LanguageListPref;
225         LanguageListCtrlPtr = LanguageListCtrl;
226         LanguageListIndex = LanguageIndex;
227         
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