Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
macOS: Added languages.cpp/.h to Xcode project.
[xestiaab/.git] / source / contacteditor / frmContactEditorNotes.cpp
1 // frmContactEditorNotes.cpp - frmContactEditorNotes 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 "frmContactEditorNotes.h"
21 frmContactEditorNotes::frmContactEditorNotes( wxWindow* parent )
22 :
23 frmContactEditorNotesADT( parent )
24 {
25         
26         // Setup the editor window.
27         
28         EditorMode = FALSE;
29         sliPriority->Disable();
30         
31         // Setup the language combo box.
32         
33         std::vector<std::string> LanguageCodeList = GetLanguageCodeList();
34         
35         wxArrayString LanguageList;
36         
37         for (auto LanguageItem : LanguageCodeList){
38                 
39                 LanguageList.Add((wxString)LanguageItem, 1);
40                 
41         }
42         
43         cmbLanguage->Append(LanguageList);
44         
45 }
47 void frmContactEditorNotes::EnablePriority( wxCommandEvent& event )
48 {
49         
50         // Enable/disable the priority setting.
51         
52         if (chkUsePref->IsChecked()){
53                 sliPriority->Enable();
54         } else {
55                 sliPriority->Disable();
56         }
57         
58 }
60 void frmContactEditorNotes::ProcessAction( wxCommandEvent& event )
61 {
62         
63         // Process action.
64         
65         long ListCtrlIndex;
66         
67         if (EditorMode == FALSE){
68         
69                 // Add the note to the list.
70         
71                 wxString strAddress;
72                 wxString strValue;
73                 
74                 // Add note.
75                 
76                 NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
77                 
78                 // Add note type.
79                 
80                 if (EditSectionType == CE_GENERAL){
81                 
82                         NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("")));
83                 
84                 } else if (EditSectionType == CE_HOME) {
85                 
86                         NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("home")));
87                 
88                 } else if (EditSectionType == CE_WORK) {
89                 
90                         NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("work")));
91                 
92                 }
93                 
94                 // Add note priority.
95                 
96                 if (chkUsePref->IsChecked()){
97                 
98                         NotesListPrefPtr->insert(std::make_pair(NotesListIndex, sliPriority->GetValue()));
99                 
100                 } else {
101                 
102                         NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));            
103                 
104                 }               
105                 
106                 // Add note language.
107                 
108                 strValue.Clear();
109                 
110                 if (!strValue.IsEmpty()){
111                 
112                         NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));              
113                 
114                 } else {
115                 
116                         NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
117                 
118                 }
119                 
120                 // Add the data to the form.
121                 
122                 wxListItem coldata;
123                 
124                 coldata.SetId(NotesListIndex);
125                 coldata.SetData(NotesListIndex);                
126                 coldata.SetText(txtNote->GetValue());
127                 ListCtrlIndex = NotesListCtrlPtr->InsertItem(coldata);
128                 
129                 if (chkUsePref->IsChecked()){
130                 
131                         NotesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
132                 
133                 }
134                 
135                 this->Close();
136         
137         } else if (EditorMode == TRUE){
138         
139                 // Edit the note.
140                 
141                 wxString strAddress;
142                 wxString strValue;
143                 long longSelected = -1;
145                 // Update the note.
147                 NotesListPtr->erase(NotesListIndex);
148                 NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
149                 
150                 // Update the note preference.
151                 
152                 NotesListPrefPtr->erase(NotesListIndex);
153                 
154                 if (chkUsePref->IsChecked()){
155                 
156                         NotesListPrefPtr->insert(std::make_pair(NotesListIndex, sliPriority->GetValue()));
157                 
158                 } else {
159                 
160                         NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));            
161                 
162                 }
163                 
164                 // Update the language.
165                 
166                 strValue.Clear();
167                 
168                 NotesListLangPtr->erase(NotesListIndex);
169                 
170                 if (!strValue.IsEmpty()){
171                 
172                         NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));              
173                 
174                 } else {
175                 
176                         NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
177                 
178                 }               
179                 
180                 // Update the form.
181                 
182                 longSelected = NotesListCtrlPtr->GetNextItem(longSelected, 
183                         wxLIST_NEXT_ALL,
184                         wxLIST_STATE_SELECTED);
185                         
186                 if (longSelected == -1){
187                         return;
188                 }
189                 
190                 NotesListCtrlPtr->SetItem(longSelected, 0, txtNote->GetValue());
191                 
192                 if (chkUsePref->IsChecked()){
193                 
194                         NotesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
195                 
196                 } else {
197                 
198                         NotesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
199                 
200                 }       
201                         
202                 this->Close();  
203         
204         }       
205         
208 void frmContactEditorNotes::SetEditorMode(bool EditMode, SectionType SectType)
210         
211         // Set the editor mode.
212         
213         // Set if the editor is adding or editing an address.
214         // FALSE = Add
215         // TRUE = Edit
216         
217         if (EditMode == FALSE){
218         
219                 EditorMode = FALSE;
220                 btnAction->SetLabel(_("Add"));
221                 this->SetTitle(_("Add Note"));
222         
223         } else if (EditMode == TRUE){
224         
225                 EditorMode = TRUE;
226                 btnAction->SetLabel(_("Modify"));
227                 this->SetTitle(_("Modify Note"));
228                 
229                 std::map<int,int>::iterator intiter;
230                 std::map<int,wxString>::iterator striter;               
231                 wxString strValue;              
232                 
233                 // Get the note.
234                 
235                 striter = NotesListPtr->find(NotesListIndex);
236                  
237                 if (striter->first == NotesListIndex){
238                 
239                         strValue = striter->second;
240                 
241                 }
242                 
243                 txtNote->SetValue(strValue);
244                 
245                 // Get the language.
246                 
247                 striter = NotesListLangPtr->find(NotesListIndex);
248                 
249                 strValue.clear();
250                 
251                 if (striter->first == NotesListIndex &&
252                         striter != NotesListLangPtr->end()){
253                 
254                         strValue = striter->second;
255                 
256                 }
257                 
258                 cmbLanguage->SetValue(strValue);
259                 
260                 // Get the priority.
261                 
262                 intiter = NotesListPrefPtr->find(NotesListIndex);
263                 
264                 if (intiter->first == NotesListIndex && intiter->second > 0 &&
265                         intiter != NotesListPrefPtr->end()){
266                 
267                         sliPriority->SetValue(intiter->second);
268                         sliPriority->Enable();
269                         chkUsePref->SetValue(TRUE);
270                 
271                 }
272                 
273         }
274         
275         EditSectionType = SectType;     
276                 
279 void frmContactEditorNotes::CloseWindow( wxCommandEvent& event )
281         
282         // Close the window.
283         
284         this->Close();
285         
289 void frmContactEditorNotes::SetupPointers(std::map<int, wxString> *NotesList,
290         std::map<int, wxString> *NotesListLang,
291         std::map<int, wxString> *NotesListAltID,
292         std::map<int, wxString> *NotesListPID,
293         std::map<int, wxString> *NotesListType,
294         std::map<int, wxString> *NotesListTokens,
295         std::map<int, int> *NotesListPref,
296         wxListCtrl *NotesListCtrl,
297         int NotesIndex )
300         // Setup the pointers.
301         
302         NotesListPtr = NotesList;
303         NotesListLangPtr = NotesListLang;
304         NotesListAltIDPtr = NotesListAltID;
305         NotesListPIDPtr = NotesListPID;
306         NotesListTypePtr = NotesListType;
307         NotesListTokensPtr = NotesListTokens;
308         NotesListPrefPtr = NotesListPref;
309         NotesListCtrlPtr = NotesListCtrl;
310         NotesListIndex = NotesIndex;
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