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"
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
53 // Replace intResult with intValueSeek.
55 BEGIN_EVENT_TABLE(frmContactEditor, wxFrame)
56 EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, frmContactEditor::ContactFileChanged)
59 frmContactEditor::frmContactEditor( wxWindow* parent )
61 frmContactEditorADT( parent )
63 boolContactModified = FALSE;
65 dapAnniversary->SetValue(NoDate);
66 dapBirthday->SetValue(NoDate);
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);
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);
81 FMTimer.SetupPointers(this);
83 //contacticon.CopyFromBitmap(contacticonbmp);
85 nbkContact->SetSelection(0);
89 void frmContactEditor::CloseContact( wxCommandEvent& event )
96 void frmContactEditor::CloseWindow( wxCloseEvent& event )
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.
103 WindowData *WData = new WindowData;
106 WData->WindowPointer = this;
107 WData->WindowID = ContactEditorUID;
109 wxCommandEvent delevent(WINDOW_CLOSE);
110 delevent.SetClientData(WData);
111 wxPostEvent(GetParent(), delevent);
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 )
135 wxSContactAccount = AccountName;
139 int frmContactEditor::GetLastInt(std::map<int, wxString> *MapData){
144 std::map<int,wxString>::iterator iwxsit;
146 for( iwxsit=(*MapData).begin(); iwxsit != (*MapData).end(); iwxsit++){
147 intResult = (*iwxsit).first;
158 int frmContactEditor::GetLastInt(std::map<int, std::string> *MapData){
160 /* int intResult = 0;
162 std::map<int,std::string>::iterator iwxsit;
164 for( iwxsit=(*MapData).begin(); iwxsit != (*MapData).end(); iwxsit++){
165 intResult = (*iwxsit).first;
173 bool frmContactEditor::GetSelectedItem(wxListCtrl *ListCtrlPtr,
175 int *intSelectedData){
178 *intSelectedData = 0;
180 *longSelected = ListCtrlPtr->GetNextItem(*longSelected,
182 wxLIST_STATE_SELECTED);
184 *intSelectedData = (int)ListCtrlPtr->GetItemData(*longSelected);
186 if (*longSelected == -1){
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){
214 int intIterVal = (*iterDataPtr)->first;
216 std::map<int,int>::iterator intIter;
218 intIter = MapData->find(intIterVal);
222 if (intIter->first == intIterVal){
224 intPropValue = intIter->second;
228 if (*boolAdditionalPtr == TRUE){
230 strPropertyPtr->Append(wxT(";"));
234 *boolAdditionalPtr = TRUE;
238 strPropertyPtr->Append(PropName + wxT("=") + wxString::Format(wxT("%i"), intPropValue));
240 *boolExtraPtr = TRUE;
248 void frmContactEditor::ProcessSaveDataProc( wxString PropName,
249 std::map<int,wxString>* MapData){
253 intIterVal = (*iterDataPtr)->first;
255 std::map<int,wxString>::iterator strIter;
257 strIter = MapData->find(intIterVal);
259 if (strIter == MapData->end()){
265 wxString strPropValue;
267 if (strIter->first == intIterVal){
269 strPropValue = strIter->second;
271 if (!strPropValue.IsEmpty() && PropName.IsEmpty()){
276 if (*boolAdditionalPtr == TRUE){
278 strPropertyPtr->Append(wxT(";"));
282 *boolAdditionalPtr = TRUE;
286 strPropertyPtr->Append(strPropValue);
288 *boolExtraPtr = TRUE;
294 if (!strPropValue.IsEmpty()){
299 if (*boolAdditionalPtr == TRUE){
301 strPropertyPtr->Append(wxT(";"));
305 *boolAdditionalPtr = TRUE;
309 // Look for semi-colon in property name and if there is then
312 if (PropName != wxT("TYPE")){
314 EscapeString(&strPropValue, FALSE);
318 if (strPropValue.find(wxT(";")) == wxNOT_FOUND && strPropValue.find(wxT(":")) == wxNOT_FOUND &&
319 strPropValue.find(wxT(",")) == wxNOT_FOUND){
321 strPropertyPtr->Append(PropName + wxT("=") + strPropValue);
325 strPropertyPtr->Append(PropName + wxT("=\"") + strPropValue + wxT("\""));
329 *boolExtraPtr = TRUE;
337 void frmContactEditor::ProcessSaveDataStrProc( wxString PropName,
338 std::map<int,std::string>* MapData){
340 int intIterVal = (*iterDataStringPtr)->first;
342 //std::map<int,wxString>::iterator strIter;
344 std::map<int,std::string>::iterator stdstrIter;
346 stdstrIter = MapData->find(intIterVal);
348 if (stdstrIter->first == intIterVal){
350 wxString strPropValue(stdstrIter->second.c_str(), wxConvUTF8);
352 if (!strPropValue.IsEmpty() && PropName.IsEmpty()){
357 if (*boolAdditionalPtr == TRUE){
359 strPropertyPtr->Append(wxT(";"));
363 *boolAdditionalPtr = TRUE;
367 strPropertyPtr->Append(strPropValue);
369 *boolExtraPtr = TRUE;
375 if (!strPropValue.IsEmpty()){
380 if (*boolAdditionalPtr == TRUE){
382 strPropertyPtr->Append(wxT(";"));
386 *boolAdditionalPtr = TRUE;
390 // Look for semi-colon in property name and if there is then
393 if (PropName != wxT("TYPE")){
395 EscapeString(&strPropValue, FALSE);
399 if (strPropValue.find(wxT(";")) == wxNOT_FOUND && strPropValue.find(wxT(":")) == wxNOT_FOUND &&
400 strPropValue.find(wxT(",")) == wxNOT_FOUND){
402 strPropertyPtr->Append(PropName + wxT("=") + strPropValue);
406 strPropertyPtr->Append(PropName + wxT("=\"") + strPropValue + wxT("\""));
410 *boolExtraPtr = TRUE;
419 void frmContactEditor::ProcessSaveDataStrProc( wxString PropName,
420 std::map<int,int>* MapData){
422 int intIterVal = (*iterDataStringPtr)->first;
424 std::map<int,int>::iterator intIter;
426 intIter = MapData->find(intIterVal);
430 if (intIter->first == intIterVal){
432 intPropValue = intIter->second;
436 if (*boolAdditionalPtr == TRUE){
438 strPropertyPtr->Append(wxT(";"));
442 *boolAdditionalPtr = TRUE;
446 strPropertyPtr->Append(PropName + wxT("=") + wxString::Format(wxT("%i"), intPropValue));
448 *boolExtraPtr = TRUE;
456 void frmContactEditor::ProcessSaveDataStrProc( wxString PropName,
457 std::map<int,wxString>* MapData){
461 intIterVal = (*iterDataStringPtr)->first;
463 std::map<int,wxString>::iterator strIter;
465 strIter = MapData->find(intIterVal);
467 wxString strPropValue;
469 if (strIter->first == intIterVal){
471 strPropValue = strIter->second;
473 if (!strPropValue.IsEmpty() && PropName.IsEmpty()){
478 if (*boolAdditionalPtr == TRUE){
480 strPropertyPtr->Append(wxT(";"));
484 *boolAdditionalPtr = TRUE;
488 strPropertyPtr->Append(strPropValue);
490 *boolExtraPtr = TRUE;
496 if (!strPropValue.IsEmpty()){
501 if (*boolAdditionalPtr == TRUE){
503 strPropertyPtr->Append(wxT(";"));
507 *boolAdditionalPtr = TRUE;
511 // Look for semi-colon in property name and if there is then
514 if (PropName != wxT("TYPE")){
516 EscapeString(&strPropValue, FALSE);
520 if (strPropValue.find(wxT(";")) == wxNOT_FOUND && strPropValue.find(wxT(":")) == wxNOT_FOUND &&
521 strPropValue.find(wxT(",")) == wxNOT_FOUND){
523 strPropertyPtr->Append(PropName + wxT("=") + strPropValue);
527 strPropertyPtr->Append(PropName + wxT("=\"") + strPropValue + wxT("\""));
531 *boolExtraPtr = TRUE;
539 void frmContactEditor::ProcessCaptureStringsProc(wxString *strCapture){
541 CaptureString(strCapture, FALSE);
545 void frmContactEditor::ResetSaveProcessData(){
558 void frmContactEditor::SetupPointers(frmActivityMgr *ActMgr, wxETagProcessTimer *ETagProc,
559 frmMain *MainPtrInc){
562 ETagTmrPtr = ETagProc;
563 MainPtr = MainPtrInc;
567 void frmContactEditor::ContactFileChanged( wxCommandEvent &event ){
573 // Check if a dialog is already open.
575 if (DialogOpen == TRUE){
577 FMTimer.Start(1000, FALSE);
582 // Bring up a Yes/No modal dialog asking if the changed file should be reloaded.
584 int QuestionResponse;
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);
588 if (QuestionResponse == wxYES){
590 // Reload the contact.
591 wxString wxSReloadContactName = wxSContactFilename;
593 LoadContact(wxSReloadContactName);
597 // Do nothing other than update the timestamp so this message
598 // doesn't appear until the next time it changes.
600 FMTimer.UpdateTimestamp();
610 void frmContactEditor::UpdateMembersTab( wxCommandEvent &event ){
612 if (cmbType->GetCurrentSelection() == 2){
624 void frmContactEditor::SetUID(int UID){
626 ContactEditorUID = UID;