1 // frmContact.cpp - Contact information form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
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.
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.
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 "frmContact.h"
20 #include "common/getcontactinfo.h"
22 #include <wx/fs_mem.h>
23 #include <wx/filesys.h>
26 BEGIN_EVENT_TABLE(frmContact, wxFrame)
29 frmContact::frmContact( wxWindow* parent )
31 frmContactADT( parent )
36 void frmContact::CloseWindowProcessing(){
40 void frmContact::CloseWindow( wxCommandEvent& event ){
46 void frmContact::CloseWindow( wxCloseEvent& event ){
48 // Off for peppermint tea. Better clean up first or
49 // we'll be in for it later.
51 wxFileSystem::AddHandler(new wxMemoryFSHandler);
53 if (MemoryFSListPtr->find(SessionID) == MemoryFSListPtr->end()){
57 std::map<wxString, wxString>::iterator striter;
59 for (striter = MemoryFSListPtr->begin(); striter != MemoryFSListPtr->end(); striter++){
61 if (SessionID == striter->second){
63 // Delete the references from the wxMemoryFSHandler
64 // and the entry from the map.
66 wxMemoryFSHandler::RemoveFile(striter->first);
74 MemoryFSListPtr->erase(striter);
78 WindowData *WData = new WindowData;
81 WData->WindowPointer = this;
82 WData->WindowID = ContactUID;
84 wxCommandEvent delevent(WINDOW_CLOSE);
85 delevent.SetClientData(WData);
86 wxPostEvent(GetParent(), delevent);
94 bool frmContact::SetupContactData(vCard *vCardObj){
96 wxFileSystem::AddHandler(new wxMemoryFSHandler);
98 for (std::map<wxString, wxString>::iterator striter = MemoryFSListPtr->begin();
99 striter != MemoryFSListPtr->end(); striter++){
101 if (SessionID == striter->second){
103 // Delete the references from the wxMemoryFSHandler
104 // and the entry from the map.
106 wxMemoryFSHandler::RemoveFile(striter->first);
107 MemoryFSListPtr->erase(striter);
113 OldSessionID = SessionID;
114 SessionID = wxString::Format(wxT("%i"), rand() % 32768);
115 LoadContactData(vCardObj, htmContactData, SessionID, OldSessionID, MemoryFSListPtr);
116 SetTitle(vCardObj->Get(wxT("FN")));
118 WindowData *WData = new WindowData;
120 vCardFilename = vCardObj->GetFilename();
123 WData->WindowPointer = this;
124 WData->WindowID = ContactUID;
126 wxCommandEvent editevent(WINDOW_EDIT);
127 editevent.SetClientData(WData);
128 wxPostEvent(GetParent(), editevent);
133 void frmContact::SetupPointers(std::map<wxString,wxString> *MemoryFSListIncPtr){
135 MemoryFSListPtr = MemoryFSListIncPtr;
139 void frmContact::SetUID(int UID){
145 wxString frmContact::GetFilename(){
147 return vCardFilename;