Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added copyright and license header to the C++ source and header files in the contacte...
[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"
20 #include "../common/textprocessing.h"
21 #include <wx/tokenzr.h>
23 frmContactEditorNotes::frmContactEditorNotes( wxWindow* parent )
24 :
25 frmContactEditorNotesADT( parent )
26 {
27         EditorMode = FALSE;
28         sliPriority->Disable();
29 }
31 void frmContactEditorNotes::EnablePriority( wxCommandEvent& event )
32 {
33         if (chkUsePref->IsChecked()){
34                 sliPriority->Enable();
35         } else {
36                 sliPriority->Disable();
37         }
38 }
40 void frmContactEditorNotes::ProcessAction( wxCommandEvent& event )
41 {
42         long ListCtrlIndex;
43         
44         if (EditorMode == FALSE){
45         
46                 // Add the note to the list.
47         
48                 wxString strAddress;
49                 wxString strValue;
50                 
51                 // Add note.
52                 
53                 NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
54                 
55                 // Add note type.
56                 
57                 if (EditSectionType == CE_GENERAL){
58                 
59                         NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("")));
60                 
61                 } else if (EditSectionType == CE_HOME) {
62                 
63                         NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("home")));
64                 
65                 } else if (EditSectionType == CE_WORK) {
66                 
67                         NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("work")));
68                 
69                 }
70                 
71                 // Add note priority.
72                 
73                 if (chkUsePref->IsChecked()){
74                 
75                         NotesListPrefPtr->insert(std::make_pair(NotesListIndex, sliPriority->GetValue()));
76                 
77                 } else {
78                 
79                         NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));            
80                 
81                 }               
82                 
83                 // Add note language.
84                 
85                 strValue.Clear();
86                 
87                 if (!strValue.IsEmpty()){
88                 
89                         NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));              
90                 
91                 } else {
92                 
93                         NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
94                 
95                 }
96                 
97                 // Add the data to the form.
98                 
99                 wxListItem coldata;
100                 
101                 coldata.SetId(NotesListIndex);
102                 coldata.SetData(NotesListIndex);                
103                 coldata.SetText(txtNote->GetValue());
104                 ListCtrlIndex = NotesListCtrlPtr->InsertItem(coldata);
105                 
106                 if (chkUsePref->IsChecked()){
107                 
108                         NotesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
109                 
110                 }
111                 
112                 this->Close();
113         
114         } else if (EditorMode == TRUE){
115         
116                 // Edit the note.
117                 
118                 wxString strAddress;
119                 wxString strValue;
120                 long longSelected = -1;
122                 // Update the note.
124                 NotesListPtr->erase(NotesListIndex);
125                 NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
126                 
127                 // Update the note preference.
128                 
129                 NotesListPrefPtr->erase(NotesListIndex);
130                 
131                 if (chkUsePref->IsChecked()){
132                 
133                         NotesListPrefPtr->insert(std::make_pair(NotesListIndex, sliPriority->GetValue()));
134                 
135                 } else {
136                 
137                         NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));            
138                 
139                 }
140                 
141                 // Update the language.
142                 
143                 strValue.Clear();
144                 
145                 NotesListLangPtr->erase(NotesListIndex);
146                 
147                 if (!strValue.IsEmpty()){
148                 
149                         NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));              
150                 
151                 } else {
152                 
153                         NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
154                 
155                 }               
156                 
157                 // Update the form.
158                 
159                 longSelected = NotesListCtrlPtr->GetNextItem(longSelected, 
160                         wxLIST_NEXT_ALL,
161                         wxLIST_STATE_SELECTED);
162                         
163                 if (longSelected == -1){
164                         return;
165                 }
166                 
167                 NotesListCtrlPtr->SetItem(longSelected, 0, txtNote->GetValue());
168                 
169                 if (chkUsePref->IsChecked()){
170                 
171                         NotesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
172                 
173                 } else {
174                 
175                         NotesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
176                 
177                 }       
178                         
179                 this->Close();  
180         
181         }       
182         
185 void frmContactEditorNotes::SetEditorMode(bool EditMode, SectionType SectType)
187         // Set if the editor is adding or editing an address.
188         // FALSE = Add
189         // TRUE = Edit
190         
191         if (EditMode == FALSE){
192         
193                 EditorMode = FALSE;
194                 btnAction->SetLabel(_("Add"));
195                 this->SetTitle(_("Add Note"));
196         
197         } else if (EditMode == TRUE){
198         
199                 EditorMode = TRUE;
200                 btnAction->SetLabel(_("Modify"));
201                 this->SetTitle(_("Modify Note"));
202                 
203                 std::map<int,int>::iterator intiter;
204                 std::map<int,wxString>::iterator striter;               
205                 wxString strValue;              
206                 
207                 // Get the note.
208                 
209                 striter = NotesListPtr->find(NotesListIndex);
210                  
211                 if (striter->first == NotesListIndex){
212                 
213                         strValue = striter->second;
214                 
215                 }
216                 
217                 txtNote->SetValue(strValue);
218                 
219                 // Get the language.
220                 
221                 striter = NotesListLangPtr->find(NotesListIndex);
222                 
223                 if (striter->first == NotesListIndex){
224                 
225                         strValue = striter->second;
226                 
227                 }
228                 
229                 cmbLanguage->SetValue(strValue);
230                 
231                 // Get the priority.
232                 
233                 intiter = NotesListPrefPtr->find(NotesListIndex);
234                 
235                 if (intiter->first == NotesListIndex && intiter->second > 0){
236                 
237                         sliPriority->SetValue(intiter->second);
238                         sliPriority->Enable();
239                         chkUsePref->SetValue(TRUE);
240                 
241                 }
242                 
243         }
244         
245         EditSectionType = SectType;     
246                 
249 void frmContactEditorNotes::CloseWindow( wxCommandEvent& event )
251         this->Close();
255 void frmContactEditorNotes::SetupPointers(std::map<int, wxString> *NotesList,
256         std::map<int, wxString> *NotesListLang,
257         std::map<int, wxString> *NotesListAltID,
258         std::map<int, wxString> *NotesListPID,
259         std::map<int, wxString> *NotesListType,
260         std::map<int, wxString> *NotesListTokens,
261         std::map<int, int> *NotesListPref,
262         wxListCtrl *NotesListCtrl,
263         int NotesIndex )
266         NotesListPtr = NotesList;
267         NotesListLangPtr = NotesListLang;
268         NotesListAltIDPtr = NotesListAltID;
269         NotesListPIDPtr = NotesListPID;
270         NotesListTypePtr = NotesListType;
271         NotesListTokensPtr = NotesListTokens;
272         NotesListPrefPtr = NotesListPref;
273         NotesListCtrlPtr = NotesListCtrl;
274         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