Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
ad16901adc458d774ad2eeda0e9201965f756352
[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 BEGIN_EVENT_TABLE(frmContactEditor, wxFrame)
69 EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, frmContactEditor::ContactFileChanged)
70 END_EVENT_TABLE()
72 frmContactEditor::frmContactEditor( wxWindow* parent )
73 :
74 frmContactEditorADT( parent )
75 {
76         
77         boolContactModified = FALSE;
78         wxDateTime NoDate;
79         dapAnniversary->SetValue(NoDate);
80         dapBirthday->SetValue(NoDate);
81         tabMembers->Hide();
82     
83         // Setup the buttons.
84     
85         wxMemoryInputStream istream(buttons_play_png, sizeof(buttons_play_png));
86         wxImage button_play_pngi(istream, wxBITMAP_TYPE_PNG);
87         wxBitmap playiconbmp(button_play_pngi, -1);
88         btnPlay->SetBitmapLabel(playiconbmp);
89     
90         wxMemoryInputStream istream2(buttons_stop_png, sizeof(buttons_stop_png));
91         wxImage button_stop_pngi(istream2, wxBITMAP_TYPE_PNG);
92         wxBitmap stopiconbmp(button_stop_pngi, -1);
93         btnStop->SetBitmapLabel(stopiconbmp);
94         btnStop->Disable();
95         FMTimer.SetupPointers(this);
96         //wxIcon contacticon;
97         //contacticon.CopyFromBitmap(contacticonbmp);
98     
99         nbkContact->SetSelection(0);
100     
103 frmContactEditor::~frmContactEditor()
105         
106         if (AudioStreamPlaybackPointer != nullptr)
107         {
108                 
109                 delete AudioStreamPlaybackPointer;
110                 AudioStreamPlaybackPointer = nullptr;
111                 
112         }
113         
116 void frmContactEditor::CloseContact( wxCommandEvent& event )
118     
119         Close();
120     
123 void frmContactEditor::CloseWindow( wxCloseEvent& event )
125     
126         // TODO: Check if any changes have been made,
127         // ask if the changes should be made, process
128         // action based on question and then close.
129     
130         WindowData *WData = new WindowData;
131     
132         if (StartupEditMode == FALSE){
133     
134                 WData->DataType = 1;
135                 WData->WindowPointer = this;
136                 WData->WindowID = ContactEditorUID;
137     
138                 wxCommandEvent delevent(WINDOW_CLOSE);
139                 delevent.SetClientData(WData);
140                 wxPostEvent(GetParent(), delevent);
141     
142         }
143     
144         Destroy();
145     
148 void frmContactEditor::CutText( wxCommandEvent& event )
150         // This function left empty for future implementation.
153 void frmContactEditor::CopyText( wxCommandEvent& event )
155         // This function left empty for future implementation.
158 void frmContactEditor::PasteText( wxCommandEvent& event )
160         // This function left empty for future implementation.
163 void frmContactEditor::SetupContact( wxString AccountName )
165     
166         wxSContactAccount = AccountName;
167     
170 void frmContactEditor::SetupAccountData(bool UnsupportedAccount){
171         
172         boolUnsupportedAccount = UnsupportedAccount;
173         
176 int frmContactEditor::GetLastInt(std::map<int, wxString> *MapData){
177     
178         intValueSeek++;
179         return intValueSeek;
180     
183 int frmContactEditor::GetLastInt(std::map<int, std::string> *MapData){
184     
185         intValueSeek++;
186         return intValueSeek;
187     
190 bool frmContactEditor::GetSelectedItem(wxListCtrl *ListCtrlPtr, 
191                                        long *longSelected,
192                                        int *intSelectedData){
193     
194         *longSelected = -1;
195         *intSelectedData = 0;
196     
197         *longSelected = ListCtrlPtr->GetNextItem(*longSelected, 
198                 wxLIST_NEXT_ALL,
199                 wxLIST_STATE_SELECTED);
200     
201         if (*longSelected == -1){
202                 return FALSE;
203         }
204     
205         *intSelectedData = (int)ListCtrlPtr->GetItemData(*longSelected);
207         return TRUE;    
208         
211 void frmContactEditor::DeleteMapDataProcess(int IndexNum, std::map<int, std::string>* MapData){
212         MapData->erase(IndexNum);
215 void frmContactEditor::DeleteMapDataProcess(int IndexNum, std::map<int, wxString>* MapData){
216         MapData->erase(IndexNum);
219 void frmContactEditor::DeleteMapDataProcess(int IndexNum, std::map<int, int>* MapData){
220         MapData->erase(IndexNum);
223 void frmContactEditor::DeleteMapDataProcess(int IndexNum, std::map<int, bool>* MapData){
224         MapData->erase(IndexNum);
227 void frmContactEditor::ProcessSaveDataProc( wxString PropName,
228                                            std::map<int,int>* MapData){
229     
230         int intIterVal = (*iterDataPtr)->first;
231     
232         std::map<int,int>::iterator intIter;
233     
234         intIter = MapData->find(intIterVal);
235     
236         int intPropValue; 
237     
238         if (intIter->first == intIterVal){
239         
240                 intPropValue = intIter->second;
241         
242                 if (intPropValue){
243             
244                         if (*boolAdditionalPtr == TRUE){
245                 
246                                 strPropertyPtr->Append(wxT(";"));
247                 
248                         } else {
249                 
250                                 *boolAdditionalPtr = TRUE;
251                 
252                         }
253             
254                 strPropertyPtr->Append(PropName + wxT("=") + wxString::Format(wxT("%i"), intPropValue));
255             
256                 *boolExtraPtr = TRUE;
257             
258                 }
259         
260         }
261     
264 void frmContactEditor::ProcessSaveDataProc( wxString PropName,
265                                            std::map<int,wxString>* MapData){
266     
267         int intIterVal;
268     
269         intIterVal = (*iterDataPtr)->first;
270     
271         std::map<int,wxString>::iterator strIter;
272     
273         strIter = MapData->find(intIterVal);
274     
275         if (strIter == MapData->end()){
276         
277                 return;
278         
279         }
280     
281         wxString strPropValue;
282     
283         if (strIter->first == intIterVal){
284         
285                 strPropValue = strIter->second;
286         
287                 if (!strPropValue.IsEmpty() && PropName.IsEmpty()){
288             
289                 strPropValue.Trim();
290                 strPropValue.Trim();
291             
292                         if (*boolAdditionalPtr == TRUE){
293                 
294                                 strPropertyPtr->Append(wxT(";"));
295                 
296                         } else {
297                 
298                                 *boolAdditionalPtr = TRUE;
299                 
300                         }
301             
302                 strPropertyPtr->Append(strPropValue);   
303             
304                 *boolExtraPtr = TRUE;
305             
306                 return;
307             
308                 }
309         
310                 if (!strPropValue.IsEmpty()){
311             
312                         strPropValue.Trim();
313                         strPropValue.Trim();
314             
315                         if (*boolAdditionalPtr == TRUE){
316                 
317                                 strPropertyPtr->Append(wxT(";"));
318                 
319                         } else {
320                 
321                                 *boolAdditionalPtr = TRUE;
322                 
323                         }
324             
325                         // Look for semi-colon in property name and if there is then
326                         // quote the value.
327             
328                         if (PropName != wxT("TYPE")){
329                 
330                                 EscapeString(&strPropValue, FALSE);     
331                 
332                         }
333             
334                         if (strPropValue.find(wxT(";")) == wxNOT_FOUND && strPropValue.find(wxT(":")) == wxNOT_FOUND &&
335                                 strPropValue.find(wxT(",")) == wxNOT_FOUND){
336                 
337                                 strPropertyPtr->Append(PropName + wxT("=") + strPropValue);
338                 
339                         } else {
340                 
341                                 strPropertyPtr->Append(PropName + wxT("=\"") + strPropValue + wxT("\""));
342                 
343                         }
344             
345                         *boolExtraPtr = TRUE;
346             
347                 }
348         
349         }
350     
353 void frmContactEditor::ProcessSaveDataStrProc( wxString PropName,
354                                               std::map<int,std::string>* MapData){
355     
356         int intIterVal = (*iterDataStringPtr)->first;
357     
358         //std::map<int,wxString>::iterator strIter;
359     
360         std::map<int,std::string>::iterator stdstrIter;
361     
362         stdstrIter = MapData->find(intIterVal); 
363                                                 
364         if (stdstrIter->first == intIterVal){
365         
366                 wxString strPropValue(stdstrIter->second.c_str(), wxConvUTF8);
367         
368                 if (!strPropValue.IsEmpty() && PropName.IsEmpty()){
369             
370                         strPropValue.Trim();
371                         strPropValue.Trim();
372             
373                         if (*boolAdditionalPtr == TRUE){
374                 
375                                 strPropertyPtr->Append(wxT(";"));
376                 
377                         } else {
378                 
379                                 *boolAdditionalPtr = TRUE;
380                 
381                         }
382             
383                         strPropertyPtr->Append(strPropValue);
384             
385                         *boolExtraPtr = TRUE;
386             
387                         return;
388             
389                 }
390         
391                 if (!strPropValue.IsEmpty()){
392             
393                         strPropValue.Trim();
394                         strPropValue.Trim();
395             
396                         if (*boolAdditionalPtr == TRUE){
397                 
398                                 strPropertyPtr->Append(wxT(";"));
399                 
400                         } else {
401                 
402                                 *boolAdditionalPtr = TRUE;
403                 
404                         }
405             
406                         // Look for semi-colon in property name and if there is then
407                         // quote the value.
408             
409                         if (PropName != wxT("TYPE")){
410                 
411                                 EscapeString(&strPropValue, FALSE);
412                 
413                         }
414             
415                         if (strPropValue.find(wxT(";")) == wxNOT_FOUND && strPropValue.find(wxT(":")) == wxNOT_FOUND &&
416                                 strPropValue.find(wxT(",")) == wxNOT_FOUND){
417                 
418                                 strPropertyPtr->Append(PropName + wxT("=") + strPropValue);
419                 
420                         } else {
421                 
422                                 strPropertyPtr->Append(PropName + wxT("=\"") + strPropValue + wxT("\""));
423                 
424                         }
425             
426                         *boolExtraPtr = TRUE;
427             
428                 }
429         
430         }
431     
435 void frmContactEditor::ProcessSaveDataStrProc( wxString PropName,
436                                               std::map<int,int>* MapData){
437     
438         int intIterVal = (*iterDataStringPtr)->first;
439     
440         std::map<int,int>::iterator intIter;
441     
442         intIter = MapData->find(intIterVal);
443     
444         int intPropValue; 
445     
446         if (intIter->first == intIterVal){
447         
448                 intPropValue = intIter->second;
449         
450                 if (intPropValue){
451             
452                         if (*boolAdditionalPtr == TRUE){
453                 
454                                 strPropertyPtr->Append(wxT(";"));
455                 
456                         } else {
457                 
458                                 *boolAdditionalPtr = TRUE;
459                 
460                         }
461             
462                         strPropertyPtr->Append(PropName + wxT("=") + wxString::Format(wxT("%i"), intPropValue));
463             
464                         *boolExtraPtr = TRUE;
465             
466                 }
467         
468         }
469     
472 void frmContactEditor::ProcessSaveDataStrProc( wxString PropName,
473                                               std::map<int,wxString>* MapData){
474     
475         int intIterVal;
476     
477         intIterVal = (*iterDataStringPtr)->first;
478     
479         std::map<int,wxString>::iterator strIter;
480     
481         strIter = MapData->find(intIterVal);
482     
483         if (strIter == MapData->end()){
484                 
485                 // Ignore this section and return.
486                 
487                 return;
488                 
489         }
490                                                       
491         wxString strPropValue;
493         if (strIter->first == intIterVal){
494         
495                 strPropValue = strIter->second;
496         
497                 if (!strPropValue.IsEmpty() && PropName.IsEmpty()){
498             
499                         strPropValue.Trim();
500                         strPropValue.Trim();
501             
502                         if (*boolAdditionalPtr == TRUE){
503                 
504                                 strPropertyPtr->Append(wxT(";"));
505                 
506                         } else {
507                 
508                                 *boolAdditionalPtr = TRUE;
509                 
510                         }
511             
512                         strPropertyPtr->Append(strPropValue);   
513             
514                         *boolExtraPtr = TRUE;
515         
516                         return;
517             
518                 }
519         
520                 if (!strPropValue.IsEmpty()){
521             
522                         strPropValue.Trim();
523                         strPropValue.Trim();
524             
525                         if (*boolAdditionalPtr == TRUE){
526                 
527                                 strPropertyPtr->Append(wxT(";"));
528                 
529                         } else {
530                 
531                                 *boolAdditionalPtr = TRUE;
532                 
533                         }       
534             
535                         // Look for semi-colon in property name and if there is then
536                         // quote the value.
537             
538                         if (PropName != wxT("TYPE")){
539                 
540                                 EscapeString(&strPropValue, FALSE);
541                 
542                         }
543             
544                         if (strPropValue.find(wxT(";")) == wxNOT_FOUND && strPropValue.find(wxT(":")) == wxNOT_FOUND &&
545                                 strPropValue.find(wxT(",")) == wxNOT_FOUND){
546                 
547                                 strPropertyPtr->Append(PropName + wxT("=") + strPropValue);
548                 
549                         } else {
550                 
551                                 strPropertyPtr->Append(PropName + wxT("=\"") + strPropValue + wxT("\""));
552                 
553                         }
554             
555                         *boolExtraPtr = TRUE;
556             
557                 }
558         
559         }
560     
563 void frmContactEditor::ProcessCaptureStringsProc(wxString *strCapture){
564     
565         CaptureString(strCapture, FALSE);
566     
569 void frmContactEditor::ResetSaveProcessData(){
570     
571         strValue.Clear();
572         strValue2.Clear();
573         strValue3.Clear();    
574     
575         boolValue = FALSE;
576         boolValue2 = FALSE;    
577         intValue2 = 0;
578         intValue  = 0;
579     
582 void frmContactEditor::SetupPointers(frmActivityMgr *ActMgr, wxETagProcessTimer *ETagProc,
583                                      frmMain *MainPtrInc){
584     
585         ActMgrPtr = ActMgr;
586         ETagTmrPtr = ETagProc;
587         MainPtr = MainPtrInc;
588     
591 void frmContactEditor::ContactFileChanged( wxCommandEvent &event ){
592     
593         // Stop the timer.
594     
595         FMTimer.Stop();
596     
597         // Check if a dialog is already open.
598     
599         if (DialogOpen == TRUE){
600         
601                 FMTimer.Start(1000, FALSE);
602                 return;
603         
604         }
605     
606         // Bring up a Yes/No modal dialog asking if the changed file should be reloaded.
607     
608         int QuestionResponse;
609     
610         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);
611     
612         if (QuestionResponse == wxYES){
613         
614                 // Reload the contact.
615                 wxString wxSReloadContactName = wxSContactFilename;
616                 ClearContact();
617                 LoadContact(wxSReloadContactName);
618         
619         } else {
620         
621                 // Do nothing other than update the timestamp so this message
622                 // doesn't appear until the next time it changes.
623         
624                 FMTimer.UpdateTimestamp();
625         
626         }  
627     
628         // Start the timer.
629     
630         FMTimer.Start();
631     
634 void frmContactEditor::UpdateMembersTab( wxCommandEvent &event ){
635     
636         if (cmbType->GetCurrentSelection() == 2){
637         
638                 tabMembers->Show();
639         
640         } else {
641         
642                 tabMembers->Hide();
643         
644         }
645     
648 void frmContactEditor::SetUID(int UID){
649     
650         ContactEditorUID = UID;
651     
654 void frmContactEditor::SetMode(bool StartupEditModeIn){
656         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