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