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 (StartupMode == false){
55 if (MemoryFSListPtr->find(SessionID) == MemoryFSListPtr->end()){
59 std::map<wxString, wxString>::iterator striter;
61 for (striter = MemoryFSListPtr->begin(); striter != MemoryFSListPtr->end(); striter++){
63 if (SessionID == striter->second){
65 // Delete the references from the wxMemoryFSHandler
66 // and the entry from the map.
68 wxMemoryFSHandler::RemoveFile(striter->first);
76 MemoryFSListPtr->erase(striter);
80 WindowData *WData = new WindowData;
83 WData->WindowPointer = this;
84 WData->WindowID = ContactUID;
86 wxCommandEvent delevent(WINDOW_CLOSE);
87 delevent.SetClientData(WData);
88 wxPostEvent(GetParent(), delevent);
96 bool frmContact::SetupContactData(vCard *vCardObj){
98 wxFileSystem::AddHandler(new wxMemoryFSHandler);
100 for (std::map<wxString, wxString>::iterator striter = MemoryFSListPtr->begin();
101 striter != MemoryFSListPtr->end(); striter++){
103 if (SessionID == striter->second){
105 // Delete the references from the wxMemoryFSHandler
106 // and the entry from the map.
108 wxMemoryFSHandler::RemoveFile(striter->first);
109 MemoryFSListPtr->erase(striter);
115 OldSessionID = SessionID;
116 SessionID = wxString::Format(wxT("%i"), rand() % 32768);
117 LoadContactData(vCardObj, htmContactData, SessionID, OldSessionID, MemoryFSListPtr);
118 ArrayvCardOutData FNList;
119 FNList = vCardObj->GetByPartial(wxT("FN"));
121 if (FNList.PropCount > 0){
122 FNList.PropValues[0].Trim();
123 SetTitle(FNList.PropValues[0]);
126 if (StartupMode == false){
128 WindowData *WData = new WindowData;
130 vCardFilename = vCardObj->GetFilename();
133 WData->WindowPointer = this;
134 WData->WindowID = ContactUID;
136 wxCommandEvent editevent(WINDOW_EDIT);
137 editevent.SetClientData(WData);
138 wxPostEvent(GetParent(), editevent);
145 void frmContact::SetMode(bool StartupModeIn){
147 StartupMode = StartupModeIn;
151 void frmContact::SetupPointers(std::map<wxString,wxString> *MemoryFSListIncPtr){
153 MemoryFSListPtr = MemoryFSListIncPtr;
157 void frmContact::SetUID(int UID){
163 wxString frmContact::GetFilename(){
165 return vCardFilename;