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 ){
48 void frmContact::CloseWindow( wxCloseEvent& event ){
50 // Off for peppermint tea. Better clean up first or
51 // we'll be in for it later.
53 wxFileSystem::AddHandler(new wxMemoryFSHandler);
55 // Check if frmContact is the main window, if not
56 // then do some clear up.
58 if (StartupMode == false){
60 if (MemoryFSListPtr->find(SessionID) == MemoryFSListPtr->end()){
64 std::map<wxString, wxString>::iterator striter;
66 for (striter = MemoryFSListPtr->begin(); striter != MemoryFSListPtr->end(); striter++){
68 if (SessionID == striter->second){
70 // Delete the references from the wxMemoryFSHandler
71 // and the entry from the map.
73 wxMemoryFSHandler::RemoveFile(striter->first);
81 MemoryFSListPtr->erase(striter);
85 WindowData *WData = new WindowData;
88 WData->WindowPointer = this;
89 WData->WindowID = ContactUID;
91 wxCommandEvent delevent(WINDOW_CLOSE);
92 delevent.SetClientData(WData);
93 wxPostEvent(GetParent(), delevent);
101 bool frmContact::SetupContactData(vCard *vCardObj){
103 // Setup the contact information.
105 wxFileSystem::AddHandler(new wxMemoryFSHandler);
107 for (std::map<wxString, wxString>::iterator striter = MemoryFSListPtr->begin();
108 striter != MemoryFSListPtr->end(); striter++){
110 if (SessionID == striter->second){
112 // Delete the references from the wxMemoryFSHandler
113 // and the entry from the map.
115 wxMemoryFSHandler::RemoveFile(striter->first);
116 MemoryFSListPtr->erase(striter);
122 OldSessionID = SessionID;
123 SessionID = wxString::Format(wxT("%i"), rand() % 32768);
124 LoadContactData(vCardObj, htmContactData, SessionID, OldSessionID, MemoryFSListPtr);
125 ArrayvCardOutData FNList;
126 FNList = vCardObj->GetByPartial(wxT("FN"));
128 if (FNList.PropCount > 0){
129 FNList.PropValues[0].Trim();
130 SetTitle(FNList.PropValues[0]);
133 if (StartupMode == false){
135 WindowData *WData = new WindowData;
137 vCardFilename = vCardObj->GetFilename();
140 WData->WindowPointer = this;
141 WData->WindowID = ContactUID;
143 wxCommandEvent editevent(WINDOW_EDIT);
144 editevent.SetClientData(WData);
145 wxPostEvent(GetParent(), editevent);
152 void frmContact::SetMode(bool StartupModeIn){
154 // Set the mode which frmContact will be operating.
156 StartupMode = StartupModeIn;
160 void frmContact::SetupPointers(std::map<wxString,wxString> *MemoryFSListIncPtr){
162 // Set the pointer for the Memory Filesystem map.
164 MemoryFSListPtr = MemoryFSListIncPtr;
168 void frmContact::SetUID(int UID){
170 // Set the UID of the contact window.
176 wxString frmContact::GetFilename(){
178 // Get the filename of the contact being displayed.
180 return vCardFilename;