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