Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Merge branch 'master' of ssh://gelforn.xestia.co.uk/scmrepos/xestiaab
[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 void frmContactEditor::SetupAccountData(bool UnsupportedAccount){
163         
164         boolUnsupportedAccount = UnsupportedAccount;
165         
168 int frmContactEditor::GetLastInt(std::map<int, wxString> *MapData){
169     
170         /*
171         int intResult = 0;
172      
173         std::map<int,wxString>::iterator iwxsit;
174      
175         for( iwxsit=(*MapData).begin(); iwxsit != (*MapData).end(); iwxsit++){
176         intResult = (*iwxsit).first;
177         }
178      
179         return intResult;
180         */
181     
182         intValueSeek++;
183         return intValueSeek;
184     
187 int frmContactEditor::GetLastInt(std::map<int, std::string> *MapData){
188     
189         /* int intResult = 0;
190      
191         std::map<int,std::string>::iterator iwxsit;
192      
193         for( iwxsit=(*MapData).begin(); iwxsit != (*MapData).end(); iwxsit++){
194         intResult = (*iwxsit).first;
195         }*/
196     
197         intValueSeek++;
198         return intValueSeek;
199     
202 bool frmContactEditor::GetSelectedItem(wxListCtrl *ListCtrlPtr, 
203                                        long *longSelected,
204                                        int *intSelectedData){
205     
206         *longSelected = -1;
207         *intSelectedData = 0;
208     
209         *longSelected = ListCtrlPtr->GetNextItem(*longSelected, 
210                 wxLIST_NEXT_ALL,
211                 wxLIST_STATE_SELECTED);
212     
213         *intSelectedData = (int)ListCtrlPtr->GetItemData(*longSelected);
214     
215         if (*longSelected == -1){
216                 return FALSE;
217         } else {
218                 return TRUE;
219         }
220     
223 void frmContactEditor::DeleteMapDataProcess(int IndexNum, std::map<int, std::string>* MapData){
224         MapData->erase(IndexNum);
227 void frmContactEditor::DeleteMapDataProcess(int IndexNum, std::map<int, wxString>* MapData){
228         MapData->erase(IndexNum);
231 void frmContactEditor::DeleteMapDataProcess(int IndexNum, std::map<int, int>* MapData){
232         MapData->erase(IndexNum);
235 void frmContactEditor::DeleteMapDataProcess(int IndexNum, std::map<int, bool>* MapData){
236         MapData->erase(IndexNum);
239 void frmContactEditor::ProcessSaveDataProc( wxString PropName,
240                                            std::map<int,int>* MapData){
241     
242         int intIterVal = (*iterDataPtr)->first;
243     
244         std::map<int,int>::iterator intIter;
245     
246         intIter = MapData->find(intIterVal);
247     
248         int intPropValue; 
249     
250         if (intIter->first == intIterVal){
251         
252                 intPropValue = intIter->second;
253         
254                 if (intPropValue){
255             
256                         if (*boolAdditionalPtr == TRUE){
257                 
258                                 strPropertyPtr->Append(wxT(";"));
259                 
260                         } else {
261                 
262                                 *boolAdditionalPtr = TRUE;
263                 
264                         }
265             
266                 strPropertyPtr->Append(PropName + wxT("=") + wxString::Format(wxT("%i"), intPropValue));
267             
268                 *boolExtraPtr = TRUE;
269             
270                 }
271         
272         }
273     
276 void frmContactEditor::ProcessSaveDataProc( wxString PropName,
277                                            std::map<int,wxString>* MapData){
278     
279         int intIterVal;
280     
281         intIterVal = (*iterDataPtr)->first;
282     
283         std::map<int,wxString>::iterator strIter;
284     
285         strIter = MapData->find(intIterVal);
286     
287         if (strIter == MapData->end()){
288         
289                 return;
290         
291         }
292     
293         wxString strPropValue;
294     
295         if (strIter->first == intIterVal){
296         
297                 strPropValue = strIter->second;
298         
299                 if (!strPropValue.IsEmpty() && PropName.IsEmpty()){
300             
301                 strPropValue.Trim();
302                 strPropValue.Trim();
303             
304                         if (*boolAdditionalPtr == TRUE){
305                 
306                                 strPropertyPtr->Append(wxT(";"));
307                 
308                         } else {
309                 
310                                 *boolAdditionalPtr = TRUE;
311                 
312                         }
313             
314                 strPropertyPtr->Append(strPropValue);   
315             
316                 *boolExtraPtr = TRUE;
317             
318                 return;
319             
320                 }
321         
322                 if (!strPropValue.IsEmpty()){
323             
324                         strPropValue.Trim();
325                         strPropValue.Trim();
326             
327                         if (*boolAdditionalPtr == TRUE){
328                 
329                                 strPropertyPtr->Append(wxT(";"));
330                 
331                         } else {
332                 
333                                 *boolAdditionalPtr = TRUE;
334                 
335                         }
336             
337                         // Look for semi-colon in property name and if there is then
338                         // quote the value.
339             
340                         if (PropName != wxT("TYPE")){
341                 
342                                 EscapeString(&strPropValue, FALSE);     
343                 
344                         }
345             
346                         if (strPropValue.find(wxT(";")) == wxNOT_FOUND && strPropValue.find(wxT(":")) == wxNOT_FOUND &&
347                                 strPropValue.find(wxT(",")) == wxNOT_FOUND){
348                 
349                                 strPropertyPtr->Append(PropName + wxT("=") + strPropValue);
350                 
351                         } else {
352                 
353                                 strPropertyPtr->Append(PropName + wxT("=\"") + strPropValue + wxT("\""));
354                 
355                         }
356             
357                         *boolExtraPtr = TRUE;
358             
359                 }
360         
361         }
362     
365 void frmContactEditor::ProcessSaveDataStrProc( wxString PropName,
366                                               std::map<int,std::string>* MapData){
367     
368         int intIterVal = (*iterDataStringPtr)->first;
369     
370         //std::map<int,wxString>::iterator strIter;
371     
372         std::map<int,std::string>::iterator stdstrIter;
373     
374         stdstrIter = MapData->find(intIterVal); 
375                                                 
376         if (stdstrIter->first == intIterVal){
377         
378                 wxString strPropValue(stdstrIter->second.c_str(), wxConvUTF8);
379         
380                 if (!strPropValue.IsEmpty() && PropName.IsEmpty()){
381             
382                         strPropValue.Trim();
383                         strPropValue.Trim();
384             
385                         if (*boolAdditionalPtr == TRUE){
386                 
387                                 strPropertyPtr->Append(wxT(";"));
388                 
389                         } else {
390                 
391                                 *boolAdditionalPtr = TRUE;
392                 
393                         }
394             
395                         strPropertyPtr->Append(strPropValue);
396             
397                         *boolExtraPtr = TRUE;
398             
399                         return;
400             
401                 }
402         
403                 if (!strPropValue.IsEmpty()){
404             
405                         strPropValue.Trim();
406                         strPropValue.Trim();
407             
408                         if (*boolAdditionalPtr == TRUE){
409                 
410                                 strPropertyPtr->Append(wxT(";"));
411                 
412                         } else {
413                 
414                                 *boolAdditionalPtr = TRUE;
415                 
416                         }
417             
418                         // Look for semi-colon in property name and if there is then
419                         // quote the value.
420             
421                         if (PropName != wxT("TYPE")){
422                 
423                                 EscapeString(&strPropValue, FALSE);
424                 
425                         }
426             
427                         if (strPropValue.find(wxT(";")) == wxNOT_FOUND && strPropValue.find(wxT(":")) == wxNOT_FOUND &&
428                                 strPropValue.find(wxT(",")) == wxNOT_FOUND){
429                 
430                                 strPropertyPtr->Append(PropName + wxT("=") + strPropValue);
431                 
432                         } else {
433                 
434                                 strPropertyPtr->Append(PropName + wxT("=\"") + strPropValue + wxT("\""));
435                 
436                         }
437             
438                         *boolExtraPtr = TRUE;
439             
440                 }
441         
442         }
443     
447 void frmContactEditor::ProcessSaveDataStrProc( wxString PropName,
448                                               std::map<int,int>* MapData){
449     
450         int intIterVal = (*iterDataStringPtr)->first;
451     
452         std::map<int,int>::iterator intIter;
453     
454         intIter = MapData->find(intIterVal);
455     
456         int intPropValue; 
457     
458         if (intIter->first == intIterVal){
459         
460                 intPropValue = intIter->second;
461         
462                 if (intPropValue){
463             
464                         if (*boolAdditionalPtr == TRUE){
465                 
466                                 strPropertyPtr->Append(wxT(";"));
467                 
468                         } else {
469                 
470                                 *boolAdditionalPtr = TRUE;
471                 
472                         }
473             
474                         strPropertyPtr->Append(PropName + wxT("=") + wxString::Format(wxT("%i"), intPropValue));
475             
476                         *boolExtraPtr = TRUE;
477             
478                 }
479         
480         }
481     
484 void frmContactEditor::ProcessSaveDataStrProc( wxString PropName,
485                                               std::map<int,wxString>* MapData){
486     
487         int intIterVal;
488     
489         intIterVal = (*iterDataStringPtr)->first;
490     
491         std::map<int,wxString>::iterator strIter;
492     
493         strIter = MapData->find(intIterVal);
494     
495         if (strIter == MapData->end()){
496                 
497                 // Ignore this section and return.
498                 
499                 return;
500                 
501         }
502                                                       
503         wxString strPropValue;
505         if (strIter->first == intIterVal){
506         
507                 strPropValue = strIter->second;
508         
509                 if (!strPropValue.IsEmpty() && PropName.IsEmpty()){
510             
511                         strPropValue.Trim();
512                         strPropValue.Trim();
513             
514                         if (*boolAdditionalPtr == TRUE){
515                 
516                                 strPropertyPtr->Append(wxT(";"));
517                 
518                         } else {
519                 
520                                 *boolAdditionalPtr = TRUE;
521                 
522                         }
523             
524                         strPropertyPtr->Append(strPropValue);   
525             
526                         *boolExtraPtr = TRUE;
527         
528                         return;
529             
530                 }
531         
532                 if (!strPropValue.IsEmpty()){
533             
534                         strPropValue.Trim();
535                         strPropValue.Trim();
536             
537                         if (*boolAdditionalPtr == TRUE){
538                 
539                                 strPropertyPtr->Append(wxT(";"));
540                 
541                         } else {
542                 
543                                 *boolAdditionalPtr = TRUE;
544                 
545                         }       
546             
547                         // Look for semi-colon in property name and if there is then
548                         // quote the value.
549             
550                         if (PropName != wxT("TYPE")){
551                 
552                                 EscapeString(&strPropValue, FALSE);
553                 
554                         }
555             
556                         if (strPropValue.find(wxT(";")) == wxNOT_FOUND && strPropValue.find(wxT(":")) == wxNOT_FOUND &&
557                                 strPropValue.find(wxT(",")) == wxNOT_FOUND){
558                 
559                                 strPropertyPtr->Append(PropName + wxT("=") + strPropValue);
560                 
561                         } else {
562                 
563                                 strPropertyPtr->Append(PropName + wxT("=\"") + strPropValue + wxT("\""));
564                 
565                         }
566             
567                         *boolExtraPtr = TRUE;
568             
569                 }
570         
571         }
572     
575 void frmContactEditor::ProcessCaptureStringsProc(wxString *strCapture){
576     
577         CaptureString(strCapture, FALSE);
578     
581 void frmContactEditor::ResetSaveProcessData(){
582     
583         strValue.Clear();
584         strValue2.Clear();
585         strValue3.Clear();    
586     
587         boolValue = FALSE;
588         boolValue2 = FALSE;    
589         intValue2 = 0;
590         intValue  = 0;
591     
594 void frmContactEditor::SetupPointers(frmActivityMgr *ActMgr, wxETagProcessTimer *ETagProc,
595                                      frmMain *MainPtrInc){
596     
597         ActMgrPtr = ActMgr;
598         ETagTmrPtr = ETagProc;
599         MainPtr = MainPtrInc;
600     
603 void frmContactEditor::ContactFileChanged( wxCommandEvent &event ){
604     
605         // Stop the timer.
606     
607         FMTimer.Stop();
608     
609         // Check if a dialog is already open.
610     
611         if (DialogOpen == TRUE){
612         
613                 FMTimer.Start(1000, FALSE);
614                 return;
615         
616         }
617     
618         // Bring up a Yes/No modal dialog asking if the changed file should be reloaded.
619     
620         int QuestionResponse;
621     
622         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);
623     
624         if (QuestionResponse == wxYES){
625         
626                 // Reload the contact.
627                 wxString wxSReloadContactName = wxSContactFilename;
628                 ClearContact();
629                 LoadContact(wxSReloadContactName);
630         
631         } else {
632         
633                 // Do nothing other than update the timestamp so this message
634                 // doesn't appear until the next time it changes.
635         
636                 FMTimer.UpdateTimestamp();
637         
638         }  
639     
640         // Start the timer.
641     
642         FMTimer.Start();
643     
646 void frmContactEditor::UpdateMembersTab( wxCommandEvent &event ){
647     
648         if (cmbType->GetCurrentSelection() == 2){
649         
650                 tabMembers->Show();
651         
652         } else {
653         
654                 tabMembers->Hide();
655         
656         }
657     
660 void frmContactEditor::SetUID(int UID){
661     
662         ContactEditorUID = UID;
663     
666 void frmContactEditor::SetMode(bool StartupEditModeIn){
668         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