Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Check if application is running normally before sending events.
[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     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     if (StartupEditMode == FALSE){
124     
125         WData->DataType = 1;
126         WData->WindowPointer = this;
127         WData->WindowID = ContactEditorUID;
128     
129         wxCommandEvent delevent(WINDOW_CLOSE);
130         delevent.SetClientData(WData);
131         wxPostEvent(GetParent(), delevent);
132     
133     }
134     
135     Destroy();
136     
139 void frmContactEditor::CutText( wxCommandEvent& event )
141     // This function left empty for future implementation.
144 void frmContactEditor::CopyText( wxCommandEvent& event )
146     // This function left empty for future implementation.
149 void frmContactEditor::PasteText( wxCommandEvent& event )
151     // This function left empty for future implementation.
154 void frmContactEditor::SetupContact( wxString AccountName )
156     
157     wxSContactAccount = AccountName;
158     
161 int frmContactEditor::GetLastInt(std::map<int, wxString> *MapData){
162     
163     /*
164      int intResult = 0;
165      
166      std::map<int,wxString>::iterator iwxsit;
167      
168      for( iwxsit=(*MapData).begin(); iwxsit != (*MapData).end(); iwxsit++){
169      intResult = (*iwxsit).first;
170      }
171      
172      return intResult;
173      */
174     
175     intValueSeek++;
176     return intValueSeek;
177     
180 int frmContactEditor::GetLastInt(std::map<int, std::string> *MapData){
181     
182     /* int intResult = 0;
183      
184      std::map<int,std::string>::iterator iwxsit;
185      
186      for( iwxsit=(*MapData).begin(); iwxsit != (*MapData).end(); iwxsit++){
187      intResult = (*iwxsit).first;
188      }*/
189     
190     intValueSeek++;
191     return intValueSeek;
192     
195 bool frmContactEditor::GetSelectedItem(wxListCtrl *ListCtrlPtr, 
196                                        long *longSelected,
197                                        int *intSelectedData){
198     
199     *longSelected = -1;
200     *intSelectedData = 0;
201     
202     *longSelected = ListCtrlPtr->GetNextItem(*longSelected, 
203                                              wxLIST_NEXT_ALL,
204                                              wxLIST_STATE_SELECTED);
205     
206     *intSelectedData = (int)ListCtrlPtr->GetItemData(*longSelected);
207     
208     if (*longSelected == -1){
209         return FALSE;
210     }
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     wxString strPropValue;
490     
491     if (strIter->first == intIterVal){
492         
493         strPropValue = strIter->second;
494         
495         if (!strPropValue.IsEmpty() && PropName.IsEmpty()){
496             
497             strPropValue.Trim();
498             strPropValue.Trim();
499             
500             if (*boolAdditionalPtr == TRUE){
501                 
502                 strPropertyPtr->Append(wxT(";"));
503                 
504             } else {
505                 
506                 *boolAdditionalPtr = TRUE;
507                 
508             }
509             
510             strPropertyPtr->Append(strPropValue);       
511             
512             *boolExtraPtr = TRUE;
513             
514             return;
515             
516         }
517         
518         if (!strPropValue.IsEmpty()){
519             
520             strPropValue.Trim();
521             strPropValue.Trim();
522             
523             if (*boolAdditionalPtr == TRUE){
524                 
525                 strPropertyPtr->Append(wxT(";"));
526                 
527             } else {
528                 
529                 *boolAdditionalPtr = TRUE;
530                 
531             }
532             
533             // Look for semi-colon in property name and if there is then
534             // quote the value.
535             
536             if (PropName != wxT("TYPE")){
537                 
538                 EscapeString(&strPropValue, FALSE);
539                 
540             }
541             
542             if (strPropValue.find(wxT(";")) == wxNOT_FOUND && strPropValue.find(wxT(":")) == wxNOT_FOUND &&
543                 strPropValue.find(wxT(",")) == wxNOT_FOUND){
544                 
545                 strPropertyPtr->Append(PropName + wxT("=") + strPropValue);
546                 
547             } else {
548                 
549                 strPropertyPtr->Append(PropName + wxT("=\"") + strPropValue + wxT("\""));
550                 
551             }
552             
553             *boolExtraPtr = TRUE;
554             
555         }
556         
557     }
558     
561 void frmContactEditor::ProcessCaptureStringsProc(wxString *strCapture){
562     
563     CaptureString(strCapture, FALSE);
564     
567 void frmContactEditor::ResetSaveProcessData(){
568     
569     strValue.Clear();
570     strValue2.Clear();
571     strValue3.Clear();    
572     
573     boolValue = FALSE;
574     boolValue2 = FALSE;    
575     intValue2 = 0;
576     intValue  = 0;
577     
580 void frmContactEditor::SetupPointers(frmActivityMgr *ActMgr, wxETagProcessTimer *ETagProc,
581                                      frmMain *MainPtrInc){
582     
583     ActMgrPtr = ActMgr;
584     ETagTmrPtr = ETagProc;
585     MainPtr = MainPtrInc;
586     
589 void frmContactEditor::ContactFileChanged( wxCommandEvent &event ){
590     
591     // Stop the timer.
592     
593     FMTimer.Stop();
594     
595     // Check if a dialog is already open.
596     
597     if (DialogOpen == TRUE){
598         
599         FMTimer.Start(1000, FALSE);
600         return;
601         
602     }
603     
604     // Bring up a Yes/No modal dialog asking if the changed file should be reloaded.
605     
606     int QuestionResponse;
607     
608     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);
609     
610     if (QuestionResponse == wxYES){
611         
612         // Reload the contact.
613         wxString wxSReloadContactName = wxSContactFilename;
614         ClearContact();
615         LoadContact(wxSReloadContactName);
616         
617     } else {
618         
619         // Do nothing other than update the timestamp so this message
620         // doesn't appear until the next time it changes.
621         
622         FMTimer.UpdateTimestamp();
623         
624     }  
625     
626     // Start the timer.
627     
628     FMTimer.Start();
629     
632 void frmContactEditor::UpdateMembersTab( wxCommandEvent &event ){
633     
634     if (cmbType->GetCurrentSelection() == 2){
635         
636         tabMembers->Show();
637         
638     } else {
639         
640         tabMembers->Hide();
641         
642     }
643     
646 void frmContactEditor::SetUID(int UID){
647     
648     ContactEditorUID = UID;
649     
652 void frmContactEditor::SetMode(bool StartupEditModeIn){
654     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