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