Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Indented code properly in frmContactEditor
[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 int frmContactEditor::GetLastInt(std::map<int, wxString> *MapData){
163     
164         /*
165         int intResult = 0;
166      
167         std::map<int,wxString>::iterator iwxsit;
168      
169         for( iwxsit=(*MapData).begin(); iwxsit != (*MapData).end(); iwxsit++){
170         intResult = (*iwxsit).first;
171         }
172      
173         return intResult;
174         */
175     
176         intValueSeek++;
177         return intValueSeek;
178     
181 int frmContactEditor::GetLastInt(std::map<int, std::string> *MapData){
182     
183         /* int intResult = 0;
184      
185         std::map<int,std::string>::iterator iwxsit;
186      
187         for( iwxsit=(*MapData).begin(); iwxsit != (*MapData).end(); iwxsit++){
188         intResult = (*iwxsit).first;
189         }*/
190     
191         intValueSeek++;
192         return intValueSeek;
193     
196 bool frmContactEditor::GetSelectedItem(wxListCtrl *ListCtrlPtr, 
197                                        long *longSelected,
198                                        int *intSelectedData){
199     
200         *longSelected = -1;
201         *intSelectedData = 0;
202     
203         *longSelected = ListCtrlPtr->GetNextItem(*longSelected, 
204                 wxLIST_NEXT_ALL,
205                 wxLIST_STATE_SELECTED);
206     
207         *intSelectedData = (int)ListCtrlPtr->GetItemData(*longSelected);
208     
209         if (*longSelected == -1){
210                 return FALSE;
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