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