Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Check if std::string version of ProcessSaveDataStrProc has data before processing
[xestiaab/.git] / source / contacteditor / frmContactEditor.cpp
1 // frmContactEditor.cpp - Main frmContactEditor form section.
2 //
3 // (c) 2012-2016 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 <map>
20 #include <string>
21 #include <thread>
22 #include <vector>
23 #include <stdlib.h>
25 #include <wx/wx.h>
26 #include <wx/ffile.h>
27 #include <wx/tokenzr.h>
28 #include <wx/mstream.h>
29 #include <wx/fs_mem.h>
30 #include <wx/datetime.h>
32 #include "frmContactEditor.h"
33 #include "frmContactEditorNickname.h"
34 #include "frmContactEditorAddress.h"
35 #include "frmContactEditorEmail.h"
36 #include "frmContactEditorIM.h"
37 #include "frmContactEditorTelephone.h"
38 #include "frmContactEditorLanguages.h"
39 #include "frmContactEditorTimezones.h"
40 #include "frmContactEditorRelated.h"
41 #include "frmContactEditorWebsites.h"
42 #include "frmContactEditorTitles.h"
43 #include "frmContactEditorRoles.h"
44 #include "frmContactEditorGeoposition.h"
45 #include "frmContactEditorGroups.h"
46 #include "frmContactEditorOrganisations.h"
47 #include "frmContactEditorNotes.h"
48 #include "frmContactEditorCategory.h"
49 #include "frmContactEditorSound.h"
50 #include "frmContactEditorPicture.h"
51 #include "frmContactEditorCalAdr.h"
52 #include "frmContactEditorKey.h"
53 #include "frmContactEditorVendor.h"
54 #include "frmContactEditorXToken.h"
55 #include "../frmMain.h"
57 #include "../enums.h"
58 #include "../version.h"
59 #include "../vcard/vcard.h"
60 #include "../vcard/vcard34conv.h"
61 #include "../bitmaps.h"
62 #include "../common/base64.h"
63 #include "../common/textprocessing.h"
64 #include "../common/preferences.h"
65 #include "../common/uuid.h"
66 #include "../common/dirs.h"
68 // TODO: Investigate problems with SFML & PulseAudio - CPU usage problems when
69 // not being used.
71 // Replace intResult with intValueSeek.
73 BEGIN_EVENT_TABLE(frmContactEditor, wxFrame)
74 EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, frmContactEditor::ContactFileChanged)
75 END_EVENT_TABLE()
77 frmContactEditor::frmContactEditor( wxWindow* parent )
78 :
79 frmContactEditorADT( parent )
80 {
81         
82         boolContactModified = FALSE;
83         wxDateTime NoDate;
84         dapAnniversary->SetValue(NoDate);
85         dapBirthday->SetValue(NoDate);
86         tabMembers->Hide();
87     
88         // Setup the buttons.
89     
90         wxMemoryInputStream istream(buttons_play_png, sizeof(buttons_play_png));
91         wxImage button_play_pngi(istream, wxBITMAP_TYPE_PNG);
92         wxBitmap playiconbmp(button_play_pngi, -1);
93         btnPlay->SetBitmapLabel(playiconbmp);
94     
95         wxMemoryInputStream istream2(buttons_stop_png, sizeof(buttons_stop_png));
96         wxImage button_stop_pngi(istream2, wxBITMAP_TYPE_PNG);
97         wxBitmap stopiconbmp(button_stop_pngi, -1);
98         btnStop->SetBitmapLabel(stopiconbmp);
99         btnStop->Disable();
100         FMTimer.SetupPointers(this);
101         //wxIcon contacticon;
102         //contacticon.CopyFromBitmap(contacticonbmp);
103     
104         nbkContact->SetSelection(0);
105     
108 void frmContactEditor::CloseContact( wxCommandEvent& event )
110     
111         Close();
112     
115 void frmContactEditor::CloseWindow( wxCloseEvent& event )
117     
118         // TODO: Check if any changes have been made,
119         // ask if the changes should be made, process
120         // action based on question and then close.
121     
122         WindowData *WData = new WindowData;
123     
124         if (StartupEditMode == FALSE){
125     
126                 WData->DataType = 1;
127                 WData->WindowPointer = this;
128                 WData->WindowID = ContactEditorUID;
129     
130                 wxCommandEvent delevent(WINDOW_CLOSE);
131                 delevent.SetClientData(WData);
132                 wxPostEvent(GetParent(), delevent);
133     
134         }
135     
136         Destroy();
137     
140 void frmContactEditor::CutText( wxCommandEvent& event )
142         // This function left empty for future implementation.
145 void frmContactEditor::CopyText( wxCommandEvent& event )
147         // This function left empty for future implementation.
150 void frmContactEditor::PasteText( wxCommandEvent& event )
152         // This function left empty for future implementation.
155 void frmContactEditor::SetupContact( wxString AccountName )
157     
158         wxSContactAccount = AccountName;
159     
162 int frmContactEditor::GetLastInt(std::map<int, wxString> *MapData){
163     
164         /*
165         int intResult = 0;
166      
167         std::map<int,wxString>::iterator iwxsit;
168      
169         for( iwxsit=(*MapData).begin(); iwxsit != (*MapData).end(); iwxsit++){
170         intResult = (*iwxsit).first;
171         }
172      
173         return intResult;
174         */
175     
176         intValueSeek++;
177         return intValueSeek;
178     
181 int frmContactEditor::GetLastInt(std::map<int, std::string> *MapData){
182     
183         /* int intResult = 0;
184      
185         std::map<int,std::string>::iterator iwxsit;
186      
187         for( iwxsit=(*MapData).begin(); iwxsit != (*MapData).end(); iwxsit++){
188         intResult = (*iwxsit).first;
189         }*/
190     
191         intValueSeek++;
192         return intValueSeek;
193     
196 bool frmContactEditor::GetSelectedItem(wxListCtrl *ListCtrlPtr, 
197                                        long *longSelected,
198                                        int *intSelectedData){
199     
200         *longSelected = -1;
201         *intSelectedData = 0;
202     
203         *longSelected = ListCtrlPtr->GetNextItem(*longSelected, 
204                 wxLIST_NEXT_ALL,
205                 wxLIST_STATE_SELECTED);
206     
207         *intSelectedData = (int)ListCtrlPtr->GetItemData(*longSelected);
208     
209         if (*longSelected == -1){
210                 return FALSE;
211         } else {
212                 return TRUE;
213         }
214     
217 void frmContactEditor::DeleteMapDataProcess(int IndexNum, std::map<int, std::string>* MapData){
218         MapData->erase(IndexNum);
221 void frmContactEditor::DeleteMapDataProcess(int IndexNum, std::map<int, wxString>* MapData){
222         MapData->erase(IndexNum);
225 void frmContactEditor::DeleteMapDataProcess(int IndexNum, std::map<int, int>* MapData){
226         MapData->erase(IndexNum);
229 void frmContactEditor::DeleteMapDataProcess(int IndexNum, std::map<int, bool>* MapData){
230         MapData->erase(IndexNum);
233 void frmContactEditor::ProcessSaveDataProc( wxString PropName,
234                                            std::map<int,int>* MapData){
235     
236         int intIterVal = (*iterDataPtr)->first;
237     
238         std::map<int,int>::iterator intIter;
239     
240         intIter = MapData->find(intIterVal);
241     
242         int intPropValue; 
243     
244         if (intIter->first == intIterVal){
245         
246                 intPropValue = intIter->second;
247         
248                 if (intPropValue){
249             
250                         if (*boolAdditionalPtr == TRUE){
251                 
252                                 strPropertyPtr->Append(wxT(";"));
253                 
254                         } else {
255                 
256                                 *boolAdditionalPtr = TRUE;
257                 
258                         }
259             
260                 strPropertyPtr->Append(PropName + wxT("=") + wxString::Format(wxT("%i"), intPropValue));
261             
262                 *boolExtraPtr = TRUE;
263             
264                 }
265         
266         }
267     
270 void frmContactEditor::ProcessSaveDataProc( wxString PropName,
271                                            std::map<int,wxString>* MapData){
272     
273         int intIterVal;
274     
275         intIterVal = (*iterDataPtr)->first;
276     
277         std::map<int,wxString>::iterator strIter;
278     
279         strIter = MapData->find(intIterVal);
280     
281         if (strIter == MapData->end()){
282         
283                 return;
284         
285         }
286     
287         wxString strPropValue;
288     
289         if (strIter->first == intIterVal){
290         
291                 strPropValue = strIter->second;
292         
293                 if (!strPropValue.IsEmpty() && PropName.IsEmpty()){
294             
295                 strPropValue.Trim();
296                 strPropValue.Trim();
297             
298                         if (*boolAdditionalPtr == TRUE){
299                 
300                                 strPropertyPtr->Append(wxT(";"));
301                 
302                         } else {
303                 
304                                 *boolAdditionalPtr = TRUE;
305                 
306                         }
307             
308                 strPropertyPtr->Append(strPropValue);   
309             
310                 *boolExtraPtr = TRUE;
311             
312                 return;
313             
314                 }
315         
316                 if (!strPropValue.IsEmpty()){
317             
318                         strPropValue.Trim();
319                         strPropValue.Trim();
320             
321                         if (*boolAdditionalPtr == TRUE){
322                 
323                                 strPropertyPtr->Append(wxT(";"));
324                 
325                         } else {
326                 
327                                 *boolAdditionalPtr = TRUE;
328                 
329                         }
330             
331                         // Look for semi-colon in property name and if there is then
332                         // quote the value.
333             
334                         if (PropName != wxT("TYPE")){
335                 
336                                 EscapeString(&strPropValue, FALSE);     
337                 
338                         }
339             
340                         if (strPropValue.find(wxT(";")) == wxNOT_FOUND && strPropValue.find(wxT(":")) == wxNOT_FOUND &&
341                                 strPropValue.find(wxT(",")) == wxNOT_FOUND){
342                 
343                                 strPropertyPtr->Append(PropName + wxT("=") + strPropValue);
344                 
345                         } else {
346                 
347                                 strPropertyPtr->Append(PropName + wxT("=\"") + strPropValue + wxT("\""));
348                 
349                         }
350             
351                         *boolExtraPtr = TRUE;
352             
353                 }
354         
355         }
356     
359 void frmContactEditor::ProcessSaveDataStrProc( wxString PropName,
360                                               std::map<int,std::string>* MapData){
361     
362         int intIterVal = (*iterDataStringPtr)->first;
363     
364         //std::map<int,wxString>::iterator strIter;
365     
366         std::map<int,std::string>::iterator stdstrIter;
367     
368         stdstrIter = MapData->find(intIterVal); 
369                                                 
370         if (stdstrIter->first == intIterVal){
371         
372                 wxString strPropValue(stdstrIter->second.c_str(), wxConvUTF8);
373         
374                 if (!strPropValue.IsEmpty() && PropName.IsEmpty()){
375             
376                         strPropValue.Trim();
377                         strPropValue.Trim();
378             
379                         if (*boolAdditionalPtr == TRUE){
380                 
381                                 strPropertyPtr->Append(wxT(";"));
382                 
383                         } else {
384                 
385                                 *boolAdditionalPtr = TRUE;
386                 
387                         }
388             
389                         strPropertyPtr->Append(strPropValue);
390             
391                         *boolExtraPtr = TRUE;
392             
393                         return;
394             
395                 }
396         
397                 if (!strPropValue.IsEmpty()){
398             
399                         strPropValue.Trim();
400                         strPropValue.Trim();
401             
402                         if (*boolAdditionalPtr == TRUE){
403                 
404                                 strPropertyPtr->Append(wxT(";"));
405                 
406                         } else {
407                 
408                                 *boolAdditionalPtr = TRUE;
409                 
410                         }
411             
412                         // Look for semi-colon in property name and if there is then
413                         // quote the value.
414             
415                         if (PropName != wxT("TYPE")){
416                 
417                                 EscapeString(&strPropValue, FALSE);
418                 
419                         }
420             
421                         if (strPropValue.find(wxT(";")) == wxNOT_FOUND && strPropValue.find(wxT(":")) == wxNOT_FOUND &&
422                                 strPropValue.find(wxT(",")) == wxNOT_FOUND){
423                 
424                                 strPropertyPtr->Append(PropName + wxT("=") + strPropValue);
425                 
426                         } else {
427                 
428                                 strPropertyPtr->Append(PropName + wxT("=\"") + strPropValue + wxT("\""));
429                 
430                         }
431             
432                         *boolExtraPtr = TRUE;
433             
434                 }
435         
436         }
437     
441 void frmContactEditor::ProcessSaveDataStrProc( wxString PropName,
442                                               std::map<int,int>* MapData){
443     
444         int intIterVal = (*iterDataStringPtr)->first;
445     
446         std::map<int,int>::iterator intIter;
447     
448         intIter = MapData->find(intIterVal);
449     
450         int intPropValue; 
451     
452         if (intIter->first == intIterVal){
453         
454                 intPropValue = intIter->second;
455         
456                 if (intPropValue){
457             
458                         if (*boolAdditionalPtr == TRUE){
459                 
460                                 strPropertyPtr->Append(wxT(";"));
461                 
462                         } else {
463                 
464                                 *boolAdditionalPtr = TRUE;
465                 
466                         }
467             
468                         strPropertyPtr->Append(PropName + wxT("=") + wxString::Format(wxT("%i"), intPropValue));
469             
470                         *boolExtraPtr = TRUE;
471             
472                 }
473         
474         }
475     
478 void frmContactEditor::ProcessSaveDataStrProc( wxString PropName,
479                                               std::map<int,wxString>* MapData){
480     
481         int intIterVal;
482     
483         intIterVal = (*iterDataStringPtr)->first;
484     
485         std::map<int,wxString>::iterator strIter;
486     
487         strIter = MapData->find(intIterVal);
488     
489         if (strIter == MapData->end()){
490                 
491                 // Ignore this section and return.
492                 
493                 return;
494                 
495         }
496                                                       
497         wxString strPropValue;
499         if (strIter->first == intIterVal){
500         
501                 strPropValue = strIter->second;
502         
503                 if (!strPropValue.IsEmpty() && PropName.IsEmpty()){
504             
505                         strPropValue.Trim();
506                         strPropValue.Trim();
507             
508                         if (*boolAdditionalPtr == TRUE){
509                 
510                                 strPropertyPtr->Append(wxT(";"));
511                 
512                         } else {
513                 
514                                 *boolAdditionalPtr = TRUE;
515                 
516                         }
517             
518                         strPropertyPtr->Append(strPropValue);   
519             
520                         *boolExtraPtr = TRUE;
521         
522                         return;
523             
524                 }
525         
526                 if (!strPropValue.IsEmpty()){
527             
528                         strPropValue.Trim();
529                         strPropValue.Trim();
530             
531                         if (*boolAdditionalPtr == TRUE){
532                 
533                                 strPropertyPtr->Append(wxT(";"));
534                 
535                         } else {
536                 
537                                 *boolAdditionalPtr = TRUE;
538                 
539                         }       
540             
541                         // Look for semi-colon in property name and if there is then
542                         // quote the value.
543             
544                         if (PropName != wxT("TYPE")){
545                 
546                                 EscapeString(&strPropValue, FALSE);
547                 
548                         }
549             
550                         if (strPropValue.find(wxT(";")) == wxNOT_FOUND && strPropValue.find(wxT(":")) == wxNOT_FOUND &&
551                                 strPropValue.find(wxT(",")) == wxNOT_FOUND){
552                 
553                                 strPropertyPtr->Append(PropName + wxT("=") + strPropValue);
554                 
555                         } else {
556                 
557                                 strPropertyPtr->Append(PropName + wxT("=\"") + strPropValue + wxT("\""));
558                 
559                         }
560             
561                         *boolExtraPtr = TRUE;
562             
563                 }
564         
565         }
566     
569 void frmContactEditor::ProcessCaptureStringsProc(wxString *strCapture){
570     
571         CaptureString(strCapture, FALSE);
572     
575 void frmContactEditor::ResetSaveProcessData(){
576     
577         strValue.Clear();
578         strValue2.Clear();
579         strValue3.Clear();    
580     
581         boolValue = FALSE;
582         boolValue2 = FALSE;    
583         intValue2 = 0;
584         intValue  = 0;
585     
588 void frmContactEditor::SetupPointers(frmActivityMgr *ActMgr, wxETagProcessTimer *ETagProc,
589                                      frmMain *MainPtrInc){
590     
591         ActMgrPtr = ActMgr;
592         ETagTmrPtr = ETagProc;
593         MainPtr = MainPtrInc;
594     
597 void frmContactEditor::ContactFileChanged( wxCommandEvent &event ){
598     
599         // Stop the timer.
600     
601         FMTimer.Stop();
602     
603         // Check if a dialog is already open.
604     
605         if (DialogOpen == TRUE){
606         
607                 FMTimer.Start(1000, FALSE);
608                 return;
609         
610         }
611     
612         // Bring up a Yes/No modal dialog asking if the changed file should be reloaded.
613     
614         int QuestionResponse;
615     
616         QuestionResponse = wxMessageBox(_("This contact has changed. Saving the contact may overwrite or lose any changes done by that change. Do you want to reload the contact with the changes made?"), _("Contact information has changed"), wxYES_NO, this);
617     
618         if (QuestionResponse == wxYES){
619         
620                 // Reload the contact.
621                 wxString wxSReloadContactName = wxSContactFilename;
622                 ClearContact();
623                 LoadContact(wxSReloadContactName);
624         
625         } else {
626         
627                 // Do nothing other than update the timestamp so this message
628                 // doesn't appear until the next time it changes.
629         
630                 FMTimer.UpdateTimestamp();
631         
632         }  
633     
634         // Start the timer.
635     
636         FMTimer.Start();
637     
640 void frmContactEditor::UpdateMembersTab( wxCommandEvent &event ){
641     
642         if (cmbType->GetCurrentSelection() == 2){
643         
644                 tabMembers->Show();
645         
646         } else {
647         
648                 tabMembers->Hide();
649         
650         }
651     
654 void frmContactEditor::SetUID(int UID){
655     
656         ContactEditorUID = UID;
657     
660 void frmContactEditor::SetMode(bool StartupEditModeIn){
662         StartupEditMode = StartupEditModeIn;
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