7 #include <wx/tokenzr.h>
9 #include <wx/mstream.h>
10 #include <wx/fs_mem.h>
12 #include <wx/filesys.h>
14 #include <wx/stdpaths.h>
15 #include <wx/fileconf.h>
16 //#include <boost/filesystem/fstream.hpp>
22 #include "frmPreferences.h"
23 #include "frmNewAccount.h"
24 #include "frmActivityMgr.h"
25 #include "frmContact.h"
26 #include "frmConflictResolution.h"
27 #include "frmInvalidSSLCertificate.h"
28 #include "frmSearch.h"
29 #include "frmSSLCertificate.h"
30 #include "frmUpdate.h"
33 #include "common/preferences.h"
34 #include "common/getcontactinfo.h"
35 #include "common/events.h"
36 #include "common/dirs.h"
37 #include "vcard/vcard.h"
38 #include "carddav/carddav.h"
39 #include "contacteditor/frmContactEditor.h"
40 #include "import/import.h"
41 #include "export/export.h"
42 #include "widgets/XABAccountView2.h"
46 //extern const wxEventType MyHaremEvent = wxNewEventType();
48 //#define CE_UPDATECONTACTLIST 7700
49 //#define CE_UPDATEACCOUNTLIST 7701
51 DEFINE_EVENT_TYPE(CE_UPDATECONTACTLIST);
52 DEFINE_EVENT_TYPE(CE_UPDATEACCOUNTLIST);
53 DEFINE_EVENT_TYPE(SE_UPDATECONTACTNOTIF);
54 DEFINE_EVENT_TYPE(CE_OPENCONTACT);
55 DEFINE_EVENT_TYPE(CE_EDITCONTACT);
56 DEFINE_EVENT_TYPE(CE_REVEALCONTACT);
57 DEFINE_EVENT_TYPE(CE_REMOVECONTACT);
58 DEFINE_EVENT_TYPE(CE_REMOVESEARCH);
59 DEFINE_EVENT_TYPE(SYNC_EMPTYSERVER);
60 DEFINE_EVENT_TYPE(ACTMGR_START);
61 DEFINE_EVENT_TYPE(ACTMGR_SHUFFLE);
62 DEFINE_EVENT_TYPE(ACTMGR_STOP);
63 DEFINE_EVENT_TYPE(WINDOW_ADD);
64 DEFINE_EVENT_TYPE(WINDOW_EDIT);
65 //DEFINE_EVENT_TYPE(WINDOW_DELETE);
66 DEFINE_EVENT_TYPE(WINDOW_CLOSE);
67 DEFINE_EVENT_TYPE(CONNSTAT_UPDATE);
68 DEFINE_EVENT_TYPE(INVALIDSSLCERT);
69 DEFINE_EVENT_TYPE(GETSELECTEDLIST);
70 DEFINE_EVENT_TYPE(SYNCACCOUNT);
72 BEGIN_EVENT_TABLE(frmMain, wxFrame)
73 EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, frmMain::ConflictResolution)
74 EVT_COMMAND(wxID_ANY, CE_UPDATECONTACTLIST, frmMain::UpdateContactList)
75 EVT_COMMAND(wxID_ANY, CE_UPDATEACCOUNTLIST, frmMain::UpdateAccountList)
76 EVT_COMMAND(wxID_ANY, SE_UPDATECONTACTNOTIF, frmMain::UpdateSearchContactLists)
77 EVT_COMMAND(wxID_ANY, CE_OPENCONTACT, frmMain::OpenContactInfo)
78 EVT_COMMAND(wxID_ANY, CE_EDITCONTACT, frmMain::ShowContactEditorEdit)
79 EVT_COMMAND(wxID_ANY, CE_REVEALCONTACT, frmMain::RevealContact)
80 EVT_COMMAND(wxID_ANY, CE_REMOVESEARCH, frmMain::RemoveContactsWindowPointer)
81 EVT_COMMAND(wxID_ANY, SYNC_EMPTYSERVER, frmMain::EmptyServerDialog)
82 EVT_COMMAND(wxID_ANY, ACTMGR_START, frmMain::ActivityIconStart)
83 EVT_COMMAND(wxID_ANY, ACTMGR_SHUFFLE, frmMain::ActivityIconShuffle)
84 EVT_COMMAND(wxID_ANY, ACTMGR_STOP, frmMain::ActivityIconStop)
85 EVT_COMMAND(wxID_ANY, WINDOW_ADD, frmMain::WindowAdd)
86 EVT_COMMAND(wxID_ANY, WINDOW_EDIT, frmMain::WindowEdit)
87 EVT_COMMAND(wxID_ANY, WINDOW_CLOSE, frmMain::WindowDelete)
88 EVT_COMMAND(wxID_ANY, CONNSTAT_UPDATE, frmMain::UpdateConnectionStatus)
89 EVT_COMMAND(wxID_ANY, INVALIDSSLCERT, frmMain::InvalidSSLCertificate)
90 EVT_COMMAND(wxID_ANY, GETSELECTEDLIST, frmMain::GetSelectedList)
91 EVT_COMMAND(wxID_ANY, SYNCACCOUNT, frmMain::SyncAccount)
94 frmMain::frmMain( wxWindow* parent )
99 // Setup the account icons.
101 wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png));
102 wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
103 wxMemoryInputStream cstream(icons_accgroup_png, sizeof(icons_accgroup_png));
104 wxMemoryInputStream dstream(icons_accnone_png, sizeof(icons_accnone_png));
106 wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
107 wxBitmap AccInet(icons_accinet_png, -1);
109 wxIAccInet.CopyFromBitmap(AccInet);
111 wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG);
112 wxBitmap AccNIcon(icons_acclocal_png, -1);
114 wxIAccNIcon.CopyFromBitmap(AccNIcon);
116 wxImage icons_accgroup_png(cstream, wxBITMAP_TYPE_PNG);
117 wxBitmap AccGrp(icons_accgroup_png, -1);
119 wxIAccGrp.CopyFromBitmap(AccGrp);
121 wxImage icons_accnone_png(dstream, wxBITMAP_TYPE_PNG);
122 wxBitmap AccNone(icons_accnone_png, -1);
124 wxIAccNone.CopyFromBitmap(AccNone);
126 AccountID = AccImgList->Add(wxIAccNIcon);
127 AccountNetID = AccImgList->Add(wxIAccInet);
128 AccountGrpID = AccImgList->Add(wxIAccGrp);
129 AccountNoneID = AccImgList->Add(wxIAccNone);
131 bmpIcon->SetIcon(AccImgList->GetIcon(AccountNoneID));
133 // Setup the status bar icons.
137 wxMemoryInputStream sslstream(icons_ssl_png, sizeof(icons_ssl_png));
138 wxMemoryInputStream sslwarningstream(icons_sslwarning_png, sizeof(icons_sslwarning_png));
139 wxMemoryInputStream nosslstream(icons_nossl_png, sizeof(icons_nossl_png));
141 wxImage icons_ssl_png(sslstream, wxBITMAP_TYPE_PNG);
142 imgSSL = new wxBitmap(icons_ssl_png, -1);
144 wxImage icons_sslwarning_png(sslwarningstream, wxBITMAP_TYPE_PNG);
145 imgSSLWarning = new wxBitmap(icons_sslwarning_png, -1);
147 wxImage icons_nossl_png(nosslstream, wxBITMAP_TYPE_PNG);
148 imgNoSSL = new wxBitmap(icons_nossl_png, -1);
152 wxMemoryInputStream act1(icons_act1_png, sizeof(icons_act1_png));
153 wxMemoryInputStream act2(icons_act2_png, sizeof(icons_act2_png));
154 wxMemoryInputStream act3(icons_act3_png, sizeof(icons_act3_png));
155 wxMemoryInputStream act4(icons_act4_png, sizeof(icons_act4_png));
156 wxMemoryInputStream actsleep(icons_actsleep_png, sizeof(icons_actsleep_png));
158 wxImage icons_actsleep_png(actsleep, wxBITMAP_TYPE_PNG);
159 imgActIconSleep = new wxBitmap (icons_actsleep_png, -1);
161 wxImage icons_act1_png(act1, wxBITMAP_TYPE_PNG);
162 imgActIcon1 = new wxBitmap (icons_act1_png, -1);
164 wxIAct1icon.CopyFromBitmap(*imgActIcon1);
166 wxImage icons_act2_png(act2, wxBITMAP_TYPE_PNG);
167 imgActIcon2 = new wxBitmap (icons_act2_png, -1);
169 wxIAct2icon.CopyFromBitmap(*imgActIcon2);
171 wxImage icons_act3_png(act3, wxBITMAP_TYPE_PNG);
172 imgActIcon3 = new wxBitmap (icons_act3_png, -1);
174 wxIAct3icon.CopyFromBitmap(*imgActIcon3);
176 wxImage icons_act4_png(act4, wxBITMAP_TYPE_PNG);
177 imgActIcon4 = new wxBitmap (icons_act4_png, -1);
179 wxIAct4icon.CopyFromBitmap(*imgActIcon4);
181 // Online/Offline icons.
183 wxMemoryInputStream onlinestream(icons_online_png, sizeof(icons_online_png));
184 wxMemoryInputStream offlinestream(icons_offline_png, sizeof(icons_offline_png));
186 wxImage icons_online_png(onlinestream, wxBITMAP_TYPE_PNG);
187 imgOnline = new wxBitmap(icons_online_png, -1);
189 wxImage icons_offline_png(offlinestream, wxBITMAP_TYPE_PNG);
190 imgOffline = new wxBitmap(icons_offline_png, -1);
192 // Setup the account view.
194 AccCtrl->SetPopupControl(treAccounts);
195 AccCtrl->SetPopupMaxHeight(175);
196 AccCtrl->SetPopupMinWidth(250);
197 treAccounts->AssignImageList(AccImgList);
199 wxRect AccTextCtrlSize = AccCtrl->GetTextRect();
201 /*wxStaticBitmap* BeepBoop = new wxStaticBitmap(AccCtrl, wxID_ANY, wxNullBitmap, wxPoint(AccTextCtrlSize.GetX() + 3, AccTextCtrlSize.GetY() + 2), wxDefaultSize, 0);
203 icons_accgroup_png.SetMask(new wxMask(icons_accgroup_png, wxSystemSettings::GetColour(wxSYS_COLOUR_BACKGROUND)));
205 BeepBoop->SetBackgroundColour(AccCtrl->GetBackgroundColour());
206 BeepBoop->SetBitmap(icons_accgroup_png);*/
208 //szrContactList->Insert(0, XABV2, 1, wxEXPAND | wxALL, 0);
210 /*AccControl->UseAltPopupWindow();
211 AccControl->SetPopupControl(treAccounts);
212 AccControl->SetPopupMaxHeight(175);
214 treAccounts->AssignImageList(AccImgList);
215 szrContactList->Insert(0, AccControl, 1, wxEXPAND|wxALL, 0);
216 szrAccList->Add(AccIcon, 0, wxLEFT|wxTOP|wxEXPAND, 3);
220 //szrContactList->Layout();
221 //szrContactList->RecalcSizes();
223 wxListItem ColumnData;
225 ColumnData.SetText(wxT("Name0"));
226 ColumnData.SetWidth(320);
227 lstContacts->InsertColumn(0, ColumnData);
229 //Connect(wxID_ANY, ContactConflictCmdEnv,
230 // ContactConflictEventHandler(frmMain::ConflictResolution), NULL, this);
232 //Connect(wxID_ANY, MyFooCommandEvent,
233 // MyFooEventHandler(frmMain::DoSomething), NULL, this);
235 //Bind(ContactConflictCmdEnv, ContactConflictEventHandler(frmMain::ConflictResolution), this, wxID_ANY);
237 treAccounts->Connect(wxEVT_LEFT_DCLICK, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
238 treAccounts->Connect(wxEVT_TREE_SEL_CHANGED, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
240 #if defined(__HAIKU__)
242 #elif defined(__WIN32__)
244 int stbBottomData [4] = { -1, 8, 8, 8 };
248 int stbBottomData [4] = { -1, 20, 20, 20 };
252 stbBottom->SetFieldsCount(4, stbBottomData);
253 stbBottom->SetMinHeight(16);
258 stbBottom->GetFieldRect(1, rectOnline);
259 stbBottom->GetFieldRect(2, rectSSL);
260 stbBottom->GetFieldRect(3, rectActivity);
262 SSLToolTip = new wxToolTip(wxT(""));
264 imgConnStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectOnline.GetX()),(rectOnline.GetY())), wxDefaultSize, 0 );
265 imgConnStatus->SetBitmap(*imgOnline);
266 imgConnStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ToggleConnectionStatus ), NULL, this );
268 imgSSLStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectSSL.GetX()),(rectSSL.GetY())), wxDefaultSize, 0 );
269 imgSSLStatus->SetBitmap(*imgNoSSL);
270 imgSSLStatus->SetToolTip(SSLToolTip);
271 imgSSLStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowSSLCertificates ), NULL, this );
273 imgActivityStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectActivity.GetX()),(rectActivity.GetY())), wxDefaultSize, 0);
274 imgActivityStatus->SetBitmap(*imgActIconSleep);
275 imgActivityStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowActivityWindow ), NULL, this );
277 // Setup the window menu.
279 // By default should be:
284 // Contact editor windows:
290 mnuContactWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact windows:") ), wxEmptyString, wxITEM_NORMAL );
291 mnuWindow->Append( mnuContactWindows );
293 mnuWindow->AppendSeparator();
295 mnuContactEditorWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact editor windows:") ), wxEmptyString, wxITEM_NORMAL );
296 mnuWindow->Append( mnuContactEditorWindows );
298 mnuWindow->AppendSeparator();
300 mnuSearchWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( wxT("Search windows:") ), wxEmptyString, wxITEM_NORMAL );
301 mnuWindow->Append( mnuSearchWindows );
303 #if defined(__WIN32__)
308 mnuContactWindows->SetFont(fontstyle);
309 mnuContactEditorWindows->SetFont(fontstyle);
310 mnuSearchWindows->SetFont(fontstyle);
314 mnuContactWindows->Enable(FALSE);
315 mnuContactEditorWindows->Enable(FALSE);
316 mnuSearchWindows->Enable(FALSE);
320 // Hide unimplemented functions.
326 void frmMain::QuitApp( wxCommandEvent& event )
328 //-------------------------------------------------------------------
329 // frmMain::QuitApp: Quits the application by simply closing this
330 // window which causes the exit as frmMain is the main window.
332 // wxCommandEvent Accepts a referenced event command.
333 //-------------------------------------------------------------------
335 //Go through the windows and close each one (be it search
336 //or contact editor). Abort if user wants to cancel.
338 // Close the contact editor windows.
340 // Close the contact windows.
342 // Close the search windows.
344 // Write out the ETag databases.
346 // Save Preferences: Save the window position if that option is enabled.
348 wxString SetFilename = GetUserPrefDir();
350 #if defined(__HAIKU__)
354 #elif defined(__WIN32__)
356 SetFilename.Append(wxT("settings"));
362 SetFilename.Append(wxT("settings"));
366 wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
368 bool SaveWindowPos = FALSE;
369 wxString SaveWindowInc;
370 cfgfile->Read(wxT("SaveWindowPosition"), &SaveWindowInc);
372 if (SaveWindowInc == wxT("true")){
374 SaveWindowPos = TRUE;
378 if (SaveWindowPos == TRUE){
380 wxRect frmMainPos = this->GetRect();
382 cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
383 cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
384 cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight());
385 cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth());
393 //Everything closed... exit.
399 void frmMain::QuitApp()
401 //-------------------------------------------------------------------
402 // frmMain::QuitApp: Quits the application by simply closing this
403 // window which causes the exit as frmMain is the main window.
405 // wxCommandEvent Accepts a referenced event command.
406 //-------------------------------------------------------------------
411 void frmMain::ShowActivityWindow( wxCommandEvent& event )
414 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
415 frameActMgr->OpenWindow();
420 void frmMain::ShowAboutWindow( wxCommandEvent& event )
422 //-------------------------------------------------------------------
423 // frmMain::ShowAboutWindow: Shows the About window as a modal
424 // dialog and then cleans up when finished.
426 // wxCommandEvent Accepts a referenced event command.
427 //-------------------------------------------------------------------
429 frmAbout *frameAbout = new frmAbout ( this );
430 frameAbout->SetupAboutWindow();
431 frameAbout->ShowModal();
437 void frmMain::OpenPreferences( wxCommandEvent& event)
439 //-------------------------------------------------------------------
440 // frmMain::ShowAboutWindow: Opens the Preferences window as a modal
441 // dialog and then cleans up when finished.
443 // wxCommandEvent Accepts a referenced event command.
444 //-------------------------------------------------------------------
446 ReloadAccounts = FALSE;
448 frmPreferences *framePreferences = new frmPreferences ( this );
449 framePreferences->SetupPointers(&ReloadAccounts);
450 framePreferences->ShowModal();
451 delete framePreferences;
452 framePreferences = NULL;
454 if (ReloadAccounts == TRUE){
456 // Reload the accounts as a change has been made within
459 this->LoadPreferences();
465 void frmMain::OpenNewABDialog( wxCommandEvent& event)
467 //-------------------------------------------------------------------
468 // frmMain::ShowAboutWindow: Opens the Preferences window as a modal
469 // dialog and then cleans up when finished.
471 // wxCommandEvent Accepts a referenced event command.
472 //-------------------------------------------------------------------
474 ReloadAccounts = FALSE;
476 frmNewAccount *frameNewAccount = new frmNewAccount ( this );
477 frameNewAccount->SetupPointers(&ReloadAccounts);
478 frameNewAccount->ShowModal();
479 delete frameNewAccount;
480 frameNewAccount = NULL;
482 if (ReloadAccounts == TRUE){
484 // Reload the accounts as a change has been made within
487 this->LoadPreferences();
493 void frmMain::LoadContactList( wxTreeEvent& event )
496 // Clear all existing variables.
498 lstContacts->DeleteAllItems();
500 treAccounts->SetAccount();
502 wxTreeItemIdValue cookie;
503 wxTreeItemId next = treAccounts->GetRootItem();
504 wxString AccountName;
505 wxString AccountDir, AccountType, AccountDirFinal, AccountTypeFinal;
506 wxString AccountDirCmb;
507 long selectedaccount = 0;
509 wxTreeItemId selectedChild = treAccounts->GetSelection();
510 wxTreeItemId nextChild;
512 wxTreeItemId ActiveItemId = treAccounts->GetFocusedItem();
513 int ActiveItemIcon = treAccounts->GetItemImage(ActiveItemId, wxTreeItemIcon_Normal);
515 int SCImg = treAccounts->GetItemImage(selectedChild);
516 int AccountIndex = 0;
518 bmpIcon->SetIcon(AccImgList->GetIcon(SCImg));
520 for (int i = 0; i < prefaccounts.GetCount(); i++){
522 if (ActiveItemIcon == 2){
524 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
525 std::multimap<int, wxString>::iterator AGFiter = AccountGroupFilename.find(AGTiter->second);
526 std::multimap<int, int>::iterator AGLiter = AccountGroupList.find(AGTiter->second);
527 int ActiveAccountG = AGLiter->second;
529 if (i == ActiveAccountG){
531 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
532 AccountType.Append(prefaccounts.GetAccountType(i));
537 if (AccountType == wxT("CardDAV")){
538 AccountTypeFinal.Append(wxT("carddav"));
540 else if (AccountType == wxT("Local")){
541 imgSSLStatus->SetBitmap(*imgOffline);
542 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
543 AccountTypeFinal.Append(wxT("local"));
554 nextChild = treAccounts->GetFirstChild(next, cookie);
557 nextChild = treAccounts->GetNextSibling(nextChild);
560 AccountName = treAccounts->GetItemText(nextChild);
562 if (nextChild == selectedChild){
563 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
564 AccountType.Append(prefaccounts.GetAccountType(i));
569 if (AccountType == wxT("CardDAV")){
570 AccountTypeFinal.Append(wxT("carddav"));
572 else if (AccountType == wxT("Local")){
573 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
574 AccountTypeFinal.Append(wxT("local"));
583 if (selectedaccount >= prefaccounts.GetCount()){
585 // The account selected isn't there so return.
593 // Open the directory and get the list of .vcf files
594 // in that directory.
596 ActiveAccount = AccountDir + wxT(".") + AccountTypeFinal;
597 ActiveAccountType = AccountType;
599 SetupSSLStatus(AccountIndex);
601 AccountDirFinal.Clear();
602 AccountDirFinal = GetAccountDir(AccountDir + wxT(".") + AccountTypeFinal, FALSE);
604 ContactsFileIndex.Clear();
606 //wxString vcardfilenamewxs;
607 wxString vCardFilename;
608 wxString vCardFilenameFull;
609 wxString vCardDataString;
610 wxStringTokenizer vcardfileline;
612 wxString setname, setvalue;
613 //vCardNames = new std::map<wxString, wxString, std::greater<wxString>>;
614 std::multimap<wxString, wxString, std::greater<wxString>> vCardNamesAsc;
615 std::multimap<wxString, wxString, std::less<wxString>> vCardNamesDsc;
616 long ContactIndex = 1;
617 long ContactSeekPoint = 0;
619 wxDir vcardaccdir(AccountDirFinal);
621 // Get the wxTreeItemId and image icon and compare it to the list.
623 if (ActiveItemIcon == AccountGrpID){
625 // It's a group so load the file containing the group and
626 // get the members of the group.
631 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
632 std::multimap<int, wxString>::iterator AGFiter = AccountGroupFilename.find(AGTiter->second);
633 //std::multimap<wxTreeItemId, int>::iterator AGFiter = AccountGroupTreeId.find(ActiveItemId);
635 Group.LoadFile(AGFiter->second);
637 ArrayvCardOutData vCardMember = Group.GetByPartial(wxT("MEMBER"));
639 for (int i = 0; i < vCardMember.PropCount; i++){
641 vCardMember.PropValues[i].Trim();
642 if (vCardMember.PropValues[i].Left(9) == wxT("urn:uuid:")){
644 wxString NewPropValue;
645 NewPropValue = vCardMember.PropValues[i].Mid(9, wxString::npos);
646 vCardMember.PropValues[i] = NewPropValue;
653 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
656 if (vCardFilename.Right(4) == wxT(".vcf") ||
657 vCardFilename.Right(4) == wxT(".VCF") ||
658 vCardFilename.Right(5) == wxT(".vcard") ||
659 vCardFilename.Right(5) == wxT(".VCARD")){
662 bool FoundMember = FALSE;
664 vCardFilenameFull.Append(AccountDirFinal);
665 vCardFilenameFull.Append(wxT("/"));
666 vCardFilenameFull.Append(vCardFilename);
668 Person.LoadFile(vCardFilenameFull);
670 UIDCode = Person.Get(wxT("UID"));
672 for (int i = 0; i < vCardMember.PropCount; i++){
674 if (vCardMember.PropValues[i] == UIDCode){
682 if (FoundMember == FALSE){
684 vCardFilename.Clear();
685 vCardFilenameFull.Clear();
686 vCardDataString.Clear();
687 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
692 if (Person.MeetBaseSpecification()){
696 // Split the name into sections.
698 vCardDataString = Person.Get(wxT("N"));
700 vCardName NameData = Person.GetName();
702 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
704 } else if (SortMode == 2){
706 // Split the name into sections.
708 vCardName NameData = Person.GetName();
710 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
712 } else if (SortMode == 3){
714 // Check and make sure that the top most nickname is used.
716 vCardDataString = Person.Get(wxT("NICKNAME"));
718 if (vCardDataString.IsEmpty()){
720 vCardDataString = wxT("(no nickname)");
724 } else if (SortMode == 4){
726 vCardDataString = Person.Get(wxT("FN"));
730 if (AscendingMode == TRUE){
731 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
733 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
742 vCardFilename.Clear();
743 vCardFilenameFull.Clear();
744 vCardDataString.Clear();
745 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
750 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
753 if (vCardFilename.Right(4) == wxT(".vcf") ||
754 vCardFilename.Right(4) == wxT(".VCF") ||
755 vCardFilename.Right(5) == wxT(".vcard") ||
756 vCardFilename.Right(5) == wxT(".VCARD")){
760 vCardFilenameFull.Append(AccountDirFinal);
761 vCardFilenameFull.Append(wxT("/"));
762 vCardFilenameFull.Append(vCardFilename);
764 Person.LoadFile(vCardFilenameFull);
766 if (Person.MeetBaseSpecification()){
770 // Split the name into sections.
772 vCardDataString = Person.Get(wxT("N"));
774 vCardName NameData = Person.GetName();
776 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
778 } else if (SortMode == 2){
780 // Split the name into sections.
782 vCardName NameData = Person.GetName();
784 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
786 } else if (SortMode == 3){
788 // Check and make sure that the top most nickname is used.
790 vCardDataString = Person.Get(wxT("NICKNAME"));
792 if (vCardDataString.IsEmpty()){
794 vCardDataString = wxT("(no nickname)");
798 } else if (SortMode == 4){
800 vCardDataString = Person.Get(wxT("FN"));
804 if (AscendingMode == TRUE){
805 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
807 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
816 vCardFilename.Clear();
817 vCardFilenameFull.Clear();
818 vCardDataString.Clear();
819 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
826 // Insert the data into the control.
828 if (AscendingMode == TRUE){
829 for (std::map<wxString, wxString>::iterator iter = vCardNamesAsc.begin();
830 iter != vCardNamesAsc.end(); ++iter){
832 wxListItem ContactInfo;
834 ContactInfo.SetId(0);
835 ContactInfo.SetText(_("Mooo"));
836 ContactInfo.SetData(ContactSeekPoint);
837 ContactIndex = lstContacts->InsertItem(ContactInfo);
839 lstContacts->SetItem(ContactIndex, 0, iter->first);
840 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
847 for (std::map<wxString, wxString>::iterator iter = vCardNamesDsc.begin();
848 iter != vCardNamesDsc.end(); ++iter){
850 wxListItem ContactInfo;
852 ContactInfo.SetId(0);
853 ContactInfo.SetText(_("Mooo"));
854 ContactInfo.SetData(ContactSeekPoint);
855 ContactIndex = lstContacts->InsertItem(ContactInfo);
857 lstContacts->SetItem(ContactIndex, 0, iter->first);
858 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
867 void frmMain::ShowContactInfo( wxListEvent& event )
870 long intSelected = -1;
871 int intSelectedData = 0;
872 long ContactSeekNum = -1;
874 // intSelected = lstContacts->GetSelection();
876 // Check if several contacts have been selected.
878 int ContactTotal = 0;
882 intSelected = lstContacts->GetNextItem(intSelected,
884 wxLIST_STATE_SELECTED);
886 if (intSelected == -1){
896 if (ContactTotal == 0){
897 htmContactData->SetPage(wxT(""));
901 if (ContactTotal > 1){
903 htmContactData->SetPage(wxString::Format(wxT("%i contacts selected."), ContactTotal));
904 ActiveFilename.Clear();
909 intSelected = lstContacts->GetNextItem(intSelected,
911 wxLIST_STATE_SELECTED);
913 ContactSeekNum = lstContacts->GetItemData(intSelected);
916 wxString wxSContactString;
917 wxString ContactLine;
921 bool ExtraLineSeek = FALSE;
924 bool PropertyFind = FALSE;
925 bool QuoteMode = FALSE;
927 wxString wxSPropertyNextLine;
928 wxString wxSProperty;
929 wxString wxSPropertySeg1;
930 wxString wxSPropertySeg2;
932 // Check if we are using wxWidgets version 2.8 or less and
933 // execute the required command accordingly.
935 #if wxABI_VERSION < 20900
936 ContactFile.Open(ContactsFileIndex[ContactSeekNum].c_str(), wxT("r"));
938 ContactFile.Open(ContactsFileIndex[ContactSeekNum], wxT("r"));
941 if (ContactFile.IsOpened() == FALSE){
947 ContactFile.ReadAll(&wxSContactString, wxConvAuto());
951 std::map<int, wxString> ContactFileLines;
952 std::map<int, wxString>::iterator striter;
954 wxStringTokenizer wSTContactFileLines(wxSContactString, wxT("\r\n"));
956 int ContactLineSeek = 0;
958 while (wSTContactFileLines.HasMoreTokens() == TRUE){
960 ContactLine = wSTContactFileLines.GetNextToken();
961 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
966 if (ContactSeekNum < 0){
970 for (std::map<int, wxString>::iterator iter = ContactFileLines.begin();
971 iter != ContactFileLines.end(); ++iter){
973 // Find the colon which splits the start bit from the data part.
975 ContactLine = iter->second;
977 while (ExtraLineSeek == TRUE){
979 // Check if there is extra data on the next line
980 // (indicated by space or tab at the start) and add data.
984 if (iter == ContactFileLines.end()){
991 wxSPropertyNextLine = iter->second;
994 if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
996 wxSPropertyNextLine.Remove(0, 1);
997 //wxSPropertyNextLine.Trim(FALSE);
998 //ContactLine.Trim();
999 ContactLine.Append(wxSPropertyNextLine);
1004 ExtraLineSeek = FALSE;
1010 ContactLineLen = ContactLine.Len();
1012 // Make sure we are not in quotation mode.
1013 // Make sure colon does not have \ or \\ before it.
1015 for (int i = 0; i <= ContactLineLen; i++){
1017 if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
1019 PropertyFind = FALSE;
1021 } else if (PropertyFind == TRUE){
1023 wxSProperty.Append(ContactLine.Mid(i, 1));
1027 if (ContactLine.Mid(i, 1) == wxT("\"")){
1029 if (QuoteMode == TRUE){
1041 if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
1043 QuoteBreakPoint = i;
1050 // Split that line at the point into two variables (ignore the colon).
1052 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
1053 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
1055 // Insert both into the vCard data file.
1057 Person.AddRaw(wxSPropertySeg1, wxSPropertySeg2);
1060 PropertyFind = TRUE;
1061 ExtraLineSeek = TRUE;
1063 QuoteBreakPoint = 0;
1064 ContactLine.Clear();
1065 wxSProperty.Clear();
1069 OldSessionID = SessionID;
1070 SessionID = wxString::Format(wxT("%i"), rand() % 32768);
1071 LoadContactData(&Person, htmContactData, SessionID, OldSessionID, &MemoryFileList);
1072 ActiveFilename = ContactsFileIndex[ContactSeekNum];
1076 void frmMain::ShowContactEditorNew( wxCommandEvent& event )
1079 // Check if there is an account selected and if not
1080 // return immediately.
1082 if (ActiveAccount.IsEmpty()){
1088 // Add Pointer to SetupPointers for the ETagDB.
1090 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1091 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1092 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1094 contacticon.CopyFromBitmap(contacticonbmp);
1096 frmContactEditor *ContactEditor = new frmContactEditor( this );
1100 ContactEditor->SetUID(WindowMenuItemID);
1102 WindowData *WData = new WindowData;
1104 WData->DataType = 1;
1105 WData->WindowPointer = (void*)ContactEditor;
1106 WData->WindowID = WindowMenuItemID;
1108 wxCommandEvent addevent(WINDOW_ADD);
1109 addevent.SetClientData(WData);
1110 wxPostEvent(this, addevent);
1112 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1113 ContactEditor->SetupHeaders();
1114 ContactEditor->SetupContact(ActiveAccount);
1115 ContactEditor->SetIcon(contacticon);
1116 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1117 ContactEditor->Show(true);
1121 void frmMain::ShowContactEditorEdit( wxCommandEvent& event )
1124 // Check if there is an account selected and if not
1125 // return immediately.
1127 int DataCheck = event.GetInt();
1129 if (ActiveAccount.IsEmpty() && DataCheck == 0){
1135 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1136 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1137 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1139 contacticon.CopyFromBitmap(contacticonbmp);
1141 // Check if a contact has been selected.
1143 long intSelected = -1;
1144 int intSelectedData = 0;
1145 long intContactSeekNum = -1;
1147 // intSelected = lstContacts->GetSelection();
1149 intSelected = lstContacts->GetNextItem(intSelected,
1151 wxLIST_STATE_SELECTED);
1153 if (intSelected == -1){
1157 intContactSeekNum = lstContacts->GetItemData(intSelected);
1159 // Get the filename of the selected contact.
1161 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1162 frmContactEditor *ContactEditor = new frmContactEditor( this );
1166 ContactEditor->SetUID(WindowMenuItemID);
1168 WindowData *WData = new WindowData;
1170 WData->DataType = 1;
1171 WData->WindowPointer = (void*)ContactEditor;
1172 WData->WindowID = WindowMenuItemID;
1174 wxCommandEvent addevent(WINDOW_ADD);
1175 addevent.SetClientData(WData);
1176 wxPostEvent(this, addevent);
1178 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1179 ContactEditor->SetupHeaders();
1181 // Check if pointer is NULL (not from the search forms) or not.
1183 if (DataCheck == 0){
1185 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1186 ContactEditor->SetupContact(ActiveAccount);
1190 UCNotif *uc = (UCNotif*)event.GetClientData();
1194 ContactEditor->SetupContact(ActiveAccount);
1195 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1199 ContactEditor->SetupContact(uc->ContactAccount);
1200 ContactEditor->LoadContact(uc->ContactFilename);
1210 ContactEditor->SetIcon(contacticon);
1211 ContactEditor->Show(true);
1215 void frmMain::RefreshAddressBook( wxCommandEvent& event ){
1217 // TODO: Check Account Type.
1219 if (!ActiveAccount.IsEmpty()){
1221 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1222 frameActMgr->AddTask(3, wxT(""), ActiveAccount,
1223 wxT(""), wxT(""), wxT(""), wxT(""));
1229 void frmMain::OpenContactInfo( wxListEvent& event )
1232 wxStringTokenizer vcardfileline;
1235 wxString setname, setvalue;
1239 long intSelected = -1;
1240 int intSelectedData = 0;
1241 long intContactSeekNum = -1;
1243 intSelected = lstContacts->GetNextItem(intSelected,
1245 wxLIST_STATE_SELECTED);
1247 intContactSeekNum = lstContacts->GetItemData(intSelected);
1249 if (intContactSeekNum == -1){
1253 Person.LoadFile(ContactsFileIndex[intContactSeekNum]);
1255 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1256 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1257 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1259 contacticon.CopyFromBitmap(contacticonbmp);
1261 frmContact *Contact = new frmContact( this );
1263 // Add to window list.
1267 Contact->SetUID(WindowMenuItemID);
1269 WindowData *WData = new WindowData;
1271 WData->DataType = 0;
1272 WData->WindowPointer = (void*)Contact;
1273 WData->WindowID = WindowMenuItemID;
1275 wxCommandEvent addevent(WINDOW_ADD);
1276 addevent.SetClientData(WData);
1277 wxPostEvent(this, addevent);
1279 Contact->SetupPointers(&MemoryFileList);
1280 Contact->SetupContactData(&Person);
1282 Contact->SetIcon(contacticon);
1283 Contact->Show(true);
1287 void frmMain::OpenContactInfo( wxCommandEvent& event )
1290 UCNotif *uc = (UCNotif*)event.GetClientData();
1292 wxStringTokenizer vcardfileline;
1295 wxString setname, setvalue;
1298 //std::fstream vcardfile;
1300 long intSelected = -1;
1301 int intSelectedData = 0;
1302 long intContactSeekNum = -1;
1304 Person.LoadFile(uc->ContactFilename);
1306 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1307 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1308 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1310 contacticon.CopyFromBitmap(contacticonbmp);
1312 frmContact *Contact = new frmContact( this );
1314 // Add to window list.
1318 Contact->SetUID(WindowMenuItemID);
1320 WindowData *WData = new WindowData;
1322 WData->DataType = 0;
1323 WData->WindowPointer = (void*)Contact;
1324 WData->WindowID = WindowMenuItemID;
1326 wxCommandEvent addevent(WINDOW_ADD);
1327 addevent.SetClientData(WData);
1328 wxPostEvent(this, addevent);
1330 Contact->SetupPointers(&MemoryFileList);
1331 Contact->SetupContactData(&Person);
1333 Contact->SetIcon(contacticon);
1334 Contact->Show(true);
1339 void frmMain::LoadPreferences( wxActivateEvent& event)
1341 this->LoadPreferences();
1344 void frmMain::LoadPreferences(){
1346 // Load the preferences.
1348 wxString preffilename = GetUserPrefDir();
1350 XABPreferences preferences(preffilename);
1352 // Setup the main window position (if needed).
1354 bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
1355 bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
1357 if (SaveWindowPos == TRUE){
1359 this->SetSize(preferences.GetMainWindowData());
1363 treAccounts->DeleteAllItems();
1365 wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"));
1367 // Stop all account timers and remove the accounts.
1369 for (std::map<wxString, wxAccountSyncTimer*>::iterator iter = AccountSyncTimers.begin();
1370 iter != AccountSyncTimers.end(); iter++){
1372 wxAccountSyncTimer *AccTmrPtr = iter->second;
1380 AccountSyncTimers.clear();
1383 for (int i = (preferences.accounts.GetCount() - 1); i > 0; --i){
1384 treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i));
1389 wxString AccDirFull;
1390 wxString AccDirFullSfx;
1392 wxString AccDirFinal;
1393 AccountAccDirList.clear();
1394 AccountGroupList.clear();
1395 AccountGroupFilename.clear();
1396 AccountGroupTreeId.clear();
1397 wxTreeItemId AccountTreeId;
1398 wxTreeItemId GroupTreeId;
1401 for (int i = 0; i < preferences.accounts.GetCount(); i++){
1403 if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
1404 preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
1410 AccDir = preferences.accounts.GetAccountDirectory(i);
1411 AccDirFull = preferences.accounts.GetAccountDirectory(i);
1413 AccDirFull.Append(wxT("."));
1414 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
1415 AccDirFullSfx.LowerCase();
1416 AccDirFullSfx.Trim();
1417 AccDirFull.Append(AccDirFullSfx);
1418 AccName = preferences.accounts.GetAccountName(i);
1420 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
1422 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
1423 preferences.accounts.GetAccountType(i) == wxT("carddav")){
1425 // Add a new timer using the existing account details.
1427 wxAccountSyncTimer *ActTmrPtr = new wxAccountSyncTimer;
1429 ActTmrPtr->SetupData(AccDirFull, AccName);
1430 ActTmrPtr->SetupPointers(this, ActMgrPtr, ETagProcTimer.GetPointer(AccDirFull));
1431 ActTmrPtr->Start(preferences.accounts.GetAccountRefresh(i) * 1000);
1432 ActTmrPtr->SetOwner(this);
1433 ActTmrPtr->Notify();
1435 // Add the timer to the list of timers.
1437 AccountSyncTimers.insert(std::make_pair(AccDirFull, ActTmrPtr));
1439 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
1443 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
1447 // Go through the account directory and find contact files with
1448 // 'KIND:group' set and add them to the list of groups for the account.
1450 AccDirFinal = GetAccountDir(AccDirFull, FALSE);
1452 wxDir vcardaccdir(AccDirFinal);
1454 wxString vCardFilename;
1455 wxString vCardDataString;
1456 wxString vCardFilenameFull;
1457 //bool ProcFiles = FALSE;
1459 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
1462 if (vCardFilename.Right(4) == wxT(".vcf") ||
1463 vCardFilename.Right(4) == wxT(".VCF") ||
1464 vCardFilename.Right(5) == wxT(".vcard") ||
1465 vCardFilename.Right(5) == wxT(".VCARD")){
1469 vCardFilenameFull.Append(AccDirFinal);
1470 vCardFilenameFull.Append(wxT("/"));
1471 vCardFilenameFull.Append(vCardFilename);
1473 Person.LoadFile(vCardFilenameFull);
1475 if (Person.MeetBaseSpecification()){
1477 vCardDataString = Person.Get(wxT("KIND"));
1479 if (vCardDataString == wxT("group")){
1481 // The vCard kind is a group. Add to the account's group list.
1483 GroupTreeId = treAccounts->AppendItem(AccountTreeId, Person.Get(wxT("FN")), AccountGrpID, -1);
1484 treAccounts->SetItemHasChildren(AccountTreeId, TRUE);
1485 AccountGroupList.insert(std::make_pair(intGroupID, i));
1486 AccountGroupFilename.insert(std::make_pair(intGroupID, vCardFilenameFull));
1487 AccountGroupTreeId.insert(std::make_pair(GroupTreeId, intGroupID));
1491 /*if (SortMode == 1){
1493 // Split the name into sections.
1495 vCardName NameData = Person.GetName();
1497 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
1499 } else if (SortMode == 2){
1501 // Split the name into sections.
1503 vCardName NameData = Person.GetName();
1505 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
1507 } else if (SortMode == 3){
1509 // Check and make sure that the top most nickname is used.
1511 vCardDataString = Person.Get(wxT("NICKNAME"));
1513 if (vCardDataString.IsEmpty()){
1515 vCardDataString = wxT("(no nickname)");
1519 } else if (SortMode == 4){
1521 vCardDataString = Person.Get(wxT("FN"));
1525 if (AscendingMode == TRUE){
1526 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
1528 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
1539 vCardFilename.Clear();
1540 vCardFilenameFull.Clear();
1541 vCardDataString.Clear();
1542 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1546 // Clearup for next account.
1550 AccDirFullSfx.clear();
1551 AccDirFinal.clear();
1556 // Load the account settings as they are needed for connecting
1559 prefaccounts = preferences.accounts;
1563 void frmMain::ConflictResolution(wxCommandEvent& event){
1565 frmConflictResolution *frameCR = new frmConflictResolution ( this );
1566 vCardConflictObj *vCardConfObj = (vCardConflictObj*)event.GetClientData();
1567 vCard *ClientDataPtr = vCardConfObj->vCardLocalData;
1568 vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1569 //vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1570 //wxString Moo = ClientDataPtr->WriteString();
1571 //vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1572 frameCR->LoadData(ClientDataPtr, ServerDataPtr, &MemoryFileList);
1573 //frameCR->LoadData(vCardConfObj->vCardLocalData, vCardConfObj->vCardServerData, &MemoryFileList);
1574 frameCR->ShowModal();
1576 int FinalConflictResult = frameCR->GetResult();
1578 wxCommandEvent event2(ACTMGR_RESUMEPROC);
1579 event2.SetClientData(vCardConfObj->QRNotifData);
1580 event2.SetInt(FinalConflictResult);
1585 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1586 wxPostEvent(frameActMgr, event2);
1590 void frmMain::UpdateContactList(wxCommandEvent& event){
1592 UCNotif *ucd = (UCNotif*)event.GetClientData();
1594 // Check if the active account is being displayed in the
1595 // main window. If not, skip and delete the data.
1597 long longSelected = -1;
1598 int intSelectedData = 0;
1600 if (ActiveAccount == ucd->ContactAccount){
1602 // Look at the list of contacts and if it matches the
1603 // filename then update the name.
1607 longSelected = lstContacts->GetNextItem(longSelected,
1609 wxLIST_STATE_DONTCARE);
1611 if (longSelected == -1){
1617 intSelectedData = lstContacts->GetItemData(longSelected);
1619 if (ucd->ContactFilename == ContactsFileIndex[intSelectedData]){
1621 // Work out which sorting mode we are in.
1625 // First Name, Last Name.
1627 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Forename + wxT(" ") + ucd->ContactNameArray.Surname);
1629 } else if (SortMode == 2){
1631 // Last Name, First Name.
1633 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Surname + wxT(", ") + ucd->ContactNameArray.Forename);
1635 } else if (SortMode == 3){
1639 lstContacts->SetItem(longSelected, 0, ucd->ContactNickname);
1641 } else if (SortMode == 4){
1645 lstContacts->SetItem(longSelected, 0, ucd->ContactName);
1652 // If the filename is the one loaded into the
1653 // browser control, then update this too.
1655 if (ActiveFilename == ContactsFileIndex[intSelectedData]){
1657 wxListEvent nullevent;
1658 ShowContactInfo(nullevent);
1666 for (std::map<int, void*>::iterator WindowIter = WindowListPointers.begin();
1667 WindowIter != WindowListPointers.end(); WindowIter++){
1669 if (WindowListType[WindowIter->first] != 0){
1675 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
1677 if (frmContactPtr->GetFilename() == ucd->ContactFilename){
1679 vCard UpdatedPerson;
1680 UpdatedPerson.LoadFile(ucd->ContactFilename);
1681 frmContactPtr->SetupContactData(&UpdatedPerson);
1687 // Send message to search window controller subroutine and
1688 // pass that notification onto the search windows.
1690 // Setup the new pointer to use the existing UCNotif without
1693 UCNotif *ucd2 = ucd;
1695 wxCommandEvent sup(SE_UPDATECONTACTNOTIF);
1696 sup.SetClientData(ucd2);
1697 wxPostEvent(this, sup);
1699 // Clear up the unused pointer.
1705 void frmMain::UpdateAccountList(wxCommandEvent& event){
1709 void frmMain::SetupPointers(void *ActMgrPtrInc){
1711 ActMgrPtr = ActMgrPtrInc;
1715 void frmMain::SetupForm(){
1717 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1718 frameActMgr->SetupPointers(&ETagProcTimer, this);
1720 // Setup the contact information icons for later.
1722 wxFileSystem::AddHandler(new wxMemoryFSHandler);
1726 wxMemoryInputStream ciptostream(icons_cipto_png, sizeof(icons_cipto_png));
1727 ciicon_png.LoadFile(ciptostream, wxBITMAP_TYPE_PNG);
1728 wxMemoryFSHandler::AddFile(wxT("cipto.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1730 wxMemoryInputStream cilogstream(icons_cilog_png, sizeof(icons_cilog_png));
1731 ciicon_png.LoadFile(cilogstream, wxBITMAP_TYPE_PNG);
1732 wxMemoryFSHandler::AddFile(wxT("cilog.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1734 wxMemoryInputStream cisndstream(icons_cisnd_png, sizeof(icons_cisnd_png));
1735 ciicon_png.LoadFile(cisndstream, wxBITMAP_TYPE_PNG);
1736 wxMemoryFSHandler::AddFile(wxT("cisnd.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1738 wxMemoryInputStream cikeystream(icons_cikey_png, sizeof(icons_cikey_png));
1739 ciicon_png.LoadFile(cikeystream, wxBITMAP_TYPE_PNG);
1740 wxMemoryFSHandler::AddFile(wxT("cikey.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1742 wxMemoryInputStream civenstream(icons_civen_png, sizeof(icons_civen_png));
1743 ciicon_png.LoadFile(civenstream, wxBITMAP_TYPE_PNG);
1744 wxMemoryFSHandler::AddFile(wxT("civen.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1746 wxMemoryInputStream ciextstream(icons_ciext_png, sizeof(icons_ciext_png));
1747 ciicon_png.LoadFile(ciextstream, wxBITMAP_TYPE_PNG);
1748 wxMemoryFSHandler::AddFile(wxT("ciext.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1754 void frmMain::UpdateSearchContactLists(wxCommandEvent& event){
1756 // Go through each of the search windows and
1757 // send the required notification to update the
1758 // contact information.
1760 // Get the event notification data.
1762 UCNotif *ucd = (UCNotif*)event.GetClientData();
1764 // Process each search window giving the new details.
1766 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1767 switer != SearchWindowList.end(); switer++){
1769 // Duplicate the event notification data.
1771 UCNotif *ucd2 = new UCNotif;
1773 ucd2->ContactAccount = ucd->ContactAccount;
1774 ucd2->ContactFilename = ucd->ContactFilename;
1775 ucd2->ContactName = ucd->ContactName;
1776 ucd2->ContactNickname = ucd->ContactNickname;
1777 ucd2->ContactNameArray = ucd->ContactNameArray;
1779 // Pass the data to the search window for processing.
1781 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1782 wxCommandEvent schupdate(SE_UPDATERESULT);
1783 schupdate.SetClientData(ucd2);
1784 wxPostEvent(frameSCH, schupdate);
1786 // Clear up the pointer prior to variable deletion.
1797 void frmMain::OpenFindContactsWindow(wxCommandEvent& event){
1801 frmSearch *frameSCH = new frmSearch ( this );
1802 frameSCH->SetUID(WindowMenuItemID);
1803 frameSCH->Show(true);
1805 WindowData *WData = new WindowData;
1807 WData->DataType = 2;
1808 WData->WindowPointer = (void*)frameSCH;
1809 WData->WindowID = WindowMenuItemID;
1811 wxCommandEvent addevent(WINDOW_ADD);
1812 addevent.SetClientData(WData);
1813 wxPostEvent(this, addevent);
1815 // Add pointer to the list of open search windows.
1817 SearchWindowList.insert(std::make_pair(frameSCH, wxT("Search")));
1823 void frmMain::RemoveContactsWindowPointer(wxCommandEvent& event){
1825 //frmSearch *frameSCH = static_cast<frmSearch*>(ActMgrPtr);
1826 void *frameSCH = (void*)event.GetClientData();
1828 SearchWindowList.erase(frameSCH);
1834 void frmMain::RemoveContactEditorWindowPointer(wxCommandEvent& event){
1836 void *frameSCH = (void*)event.GetClientData();
1838 SearchWindowList.erase(frameSCH);
1844 void frmMain::UpdateWindowList(wxCommandEvent& event){
1846 // Update the Window List.
1848 // Delete the existing items in the window menu.
1850 // Get the list of contacts.
1852 // Insert a separator.
1854 // Get the list of search windows.
1858 void frmMain::RevealContact(wxCommandEvent& event){
1860 UCNotif *uc = (UCNotif*)event.GetClientData();
1862 // Switch the account to the one passed.
1864 wxTreeItemIdValue cookie;
1865 wxTreeItemId next = treAccounts->GetRootItem();
1866 wxTreeItemId nextChild;
1868 for (int i = 0; i < prefaccounts.GetCount(); i++){
1871 nextChild = treAccounts->GetFirstChild(next, cookie);
1873 nextChild = treAccounts->GetNextSibling(nextChild);
1876 //AccountName = treAccounts->GetItemText(nextChild);
1878 if (uc->ContactAccount == AccountAccDirList[i]){
1881 treAccounts->SelectItem(nextChild, TRUE);
1882 AccCtrl->SetText(treAccounts->GetItemText(nextChild));
1888 // Switch the contact to the one passed.
1890 long longSelected = -1;
1891 int intSelectedData = 0;
1895 longSelected = lstContacts->GetNextItem(longSelected,
1897 wxLIST_STATE_DONTCARE);
1899 if (longSelected == -1){
1905 intSelectedData = lstContacts->GetItemData(longSelected);
1907 // Compare the filename with the one received.
1908 // If they match then select it.
1910 if (ContactsFileIndex[intSelectedData] == uc->ContactFilename){
1914 lstContacts->SetItemState(longSelected, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1915 lstContacts->EnsureVisible(longSelected);
1925 void frmMain::DeleteContact(wxCommandEvent& event){
1927 // Check if a contact is selected.
1929 long intSelected = -1;
1930 int intSelectedData = 0;
1931 long intContactSeekNum = -1;
1932 wxString wxSContactName;
1934 intSelected = lstContacts->GetNextItem(intSelected,
1936 wxLIST_STATE_SELECTED);
1938 if (intSelected == -1){
1942 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1944 // Get the item data of the contact.
1946 intContactSeekNum = lstContacts->GetItemData(intSelected);
1948 // Get the name of the contact.
1950 wxSContactName = lstContacts->GetItemText(intSelected);
1952 // Display a message confirming if the contact should
1955 int QuestionResponse;
1957 QuestionResponse = wxMessageBox(_("Are you sure you want to delete this contact?"), _("Delete contact"), wxYES_NO, this);
1959 if (QuestionResponse == wxNO){
1961 // Exit the subroutine
1967 // Delete the contact.
1969 if (!wxRemoveFile(ContactsFileIndex[intContactSeekNum])){
1971 wxMessageBox(_("Unable to delete the contact."), _("Cannot delete contact"), wxOK, this);
1976 // Remove the contact from the list.
1978 lstContacts->DeleteItem(intSelected);
1980 // Update the search windows, removing the deleted
1983 UCNotif *ucd = new UCNotif;
1985 ucd->ContactAccount = ActiveAccount;
1986 ucd->ContactFilename = ContactsFileIndex[intContactSeekNum];
1988 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1989 switer != SearchWindowList.end(); switer++){
1991 // Duplicate the event notification data.
1993 UCNotif *ucd2 = new UCNotif;
1995 ucd2->ContactAccount = ucd->ContactAccount;
1996 ucd2->ContactFilename = ucd->ContactFilename;
1998 // Pass the data to the search window for processing.
2000 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
2001 wxCommandEvent schdelete(SE_DELETERESULT);
2002 schdelete.SetClientData(ucd2);
2003 wxPostEvent(frameSCH, schdelete);
2005 // Clear up the pointer prior to variable deletion.
2012 // Clear the wxHTMLWindow.
2014 wxString EmptyPage = wxT("");
2016 htmContactData->SetPage(EmptyPage);
2018 wxStringTokenizer wSTFilename(ContactsFileIndex[intContactSeekNum], wxT("/"));
2020 wxString wxSplitFilename;
2021 wxString wxSDataURL;
2023 while(wSTFilename.HasMoreTokens()){
2025 wxSplitFilename = wSTFilename.GetNextToken();
2029 if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
2031 // Update the ETagDB and mark it as deleted.
2033 ETagDB *ETagDBPtr = ETagProcTimer.GetPointer(ActiveAccount);
2035 ETagDBPtr->UpdateETag(wxSplitFilename, wxT("DELETED"));
2037 // Get the Data URL.
2039 wxTreeItemIdValue cookie;
2040 wxTreeItemId next = treAccounts->GetRootItem();
2042 wxTreeItemId selectedChild = treAccounts->GetSelection();
2043 wxTreeItemId nextChild;
2045 for (int i = 0; i < prefaccounts.GetCount(); i++){
2048 nextChild = treAccounts->GetFirstChild(next, cookie);
2051 nextChild = treAccounts->GetNextSibling(nextChild);
2054 if (nextChild == selectedChild){
2055 wxSDataURL = prefaccounts.GetAccountDirPrefix(i) + wxT("/") + wxSplitFilename;
2061 // Add task to the activity monitor to delete the contact.
2063 frameActMgr->AddTask(2, wxSContactName, ActiveAccount, wxSDataURL, wxSplitFilename, ContactsFileIndex[intContactSeekNum], wxT(""));
2067 // Clear the variable. Don't delete as it will mess things up.
2069 ContactsFileIndex[intContactSeekNum] = wxT("");
2076 void frmMain::EmptyServerDialog(wxCommandEvent& event){
2078 QRNotif *qrn = (QRNotif *)event.GetClientData();
2080 int QResponse = wxMessageBox(_("The list of contacts on the server is empty. Upload all locally stored contacts for this account now?"), _("No contacts on server"), wxYES_NO, this);
2082 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2083 event2.SetInt(*qrn->QResponse);
2084 event2.SetClientData(qrn->PausePtr);
2086 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2088 wxPostEvent(frameActMgr, event2);
2092 void frmMain::DeleteContactSync(wxString &Account, wxString &Filename){
2094 // Remove the contact from the window after syncronising.
2096 // Check which account is currently active in the window.
2097 // If it is different from the one passed to this subroutine then
2098 // exit from the subroutine.
2100 if (Account != ActiveAccount){
2104 long longSelected = -1;
2105 int intSelectedData = 0;
2109 longSelected = lstContacts->GetNextItem(longSelected,
2111 wxLIST_STATE_DONTCARE);
2113 if (longSelected == -1){
2119 intSelectedData = lstContacts->GetItemData(longSelected);
2121 // Compare the filename with the one received.
2122 // If they match then select it.
2124 if (ContactsFileIndex[intSelectedData] == Filename){
2126 // Remove the contact from the window.
2128 lstContacts->DeleteItem(intSelectedData);
2130 // Check if contact is the selected contact in the HTML window and
2131 // if it is then clear the window.
2133 if (ActiveFilename == Filename){
2135 wxString EmptyPage = wxT("");
2136 htmContactData->SetPage(EmptyPage);
2150 void frmMain::SortFNLN( wxCommandEvent& event ) {
2152 wxTreeEvent NullEvent;
2154 LoadContactList(NullEvent);
2158 void frmMain::SortLNFN( wxCommandEvent& event ) {
2160 wxTreeEvent NullEvent;
2162 LoadContactList(NullEvent);
2166 void frmMain::SortNickname( wxCommandEvent& event ) {
2168 wxTreeEvent NullEvent;
2170 LoadContactList(NullEvent);
2174 void frmMain::SortDisplayAs( wxCommandEvent& event ) {
2176 wxTreeEvent NullEvent;
2178 LoadContactList(NullEvent);
2182 void frmMain::SortAscending( wxCommandEvent& event ) {
2184 wxTreeEvent NullEvent;
2185 AscendingMode = TRUE;
2186 LoadContactList(NullEvent);
2190 void frmMain::SortDescending( wxCommandEvent& event ) {
2192 wxTreeEvent NullEvent;
2193 AscendingMode = FALSE;
2194 LoadContactList(NullEvent);
2198 void frmMain::ToggleStatusBar( wxCommandEvent& event ) {
2200 if (stbBottom->IsShown() == TRUE){
2214 void frmMain::ActivityIconStart( wxCommandEvent& event ){
2216 // Display the activity icon.
2218 imgActivityStatus->SetBitmap(*imgActIcon1);
2219 ActivityIconStatus = 0;
2223 void frmMain::ActivityIconShuffle( wxCommandEvent& event ){
2225 switch (ActivityIconStatus){
2228 imgActivityStatus->SetBitmap(*imgActIcon1);
2229 ActivityIconStatus = 1;
2232 imgActivityStatus->SetBitmap(*imgActIcon2);
2233 ActivityIconStatus = 2;
2236 imgActivityStatus->SetBitmap(*imgActIcon3);
2237 ActivityIconStatus = 3;
2240 imgActivityStatus->SetBitmap(*imgActIcon4);
2241 ActivityIconStatus = 0;
2244 ActivityIconStatus = 0;
2250 void frmMain::ActivityIconStop( wxCommandEvent& event ){
2252 // Display the sleep icon.
2254 imgActivityStatus->SetBitmap(*imgActIconSleep);
2258 void frmMain::UpdateSBIconPlacement( wxSizeEvent& event ){
2260 if (imgConnStatus == 0 || imgSSLStatus == 0 || imgActivityStatus == 0){
2268 wxRect rectActivity;
2269 stbBottom->GetFieldRect(1, rectOnline);
2270 stbBottom->GetFieldRect(2, rectSSL);
2271 stbBottom->GetFieldRect(3, rectActivity);
2273 imgConnStatus->Move(rectOnline.GetX(),rectOnline.GetY());
2274 imgSSLStatus->Move(rectSSL.GetX(),rectSSL.GetY());
2275 imgActivityStatus->Move(rectActivity.GetX(),rectActivity.GetY());
2279 XABViewMode frmMain::GetViewMode(){
2283 xvm.SortMode = SortMode;
2284 xvm.AscendingMode = AscendingMode;
2290 void frmMain::WindowAdd( wxCommandEvent &event ){
2292 WindowData *WData = (WindowData*)event.GetClientData();
2296 if (WData->DataType == 0){
2300 int intID = mnuContactWindows->GetId();
2302 mnuWindow->FindChildItem(intID, &pos);
2303 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2304 mnuNewItem->SetId(WData->WindowID);
2305 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2306 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2307 WindowListType.insert(std::make_pair(WData->WindowID, 0));
2308 mnuWindow->Insert((pos + 1), mnuNewItem);
2309 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2311 } else if (WData->DataType == 1){
2313 // Contact Editor Window
2315 int intID = mnuContactEditorWindows->GetId();
2317 mnuWindow->FindChildItem(intID, &pos);
2318 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Editor Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2319 mnuNewItem->SetId(WData->WindowID);
2320 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2321 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2322 WindowListType.insert(std::make_pair(WData->WindowID, 1));
2323 mnuWindow->Insert((pos + 1), mnuNewItem);
2324 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2326 } else if (WData->DataType == 2){
2330 int intID = mnuSearchWindows->GetId();
2332 mnuWindow->FindChildItem(intID, &pos);
2333 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Search Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2334 mnuNewItem->SetId(WData->WindowID);
2335 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2336 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2337 WindowListType.insert(std::make_pair(WData->WindowID, 2));
2338 mnuWindow->Insert((pos + 1), mnuNewItem);
2339 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowSearchWindow));
2348 void frmMain::WindowEdit( wxCommandEvent &event ){
2350 WindowData *WData = (WindowData*)event.GetClientData();
2352 if (WData->DataType == 0){
2356 int intID = mnuContactWindows->GetId();
2358 // Get the window title and use that.
2360 frmContact *frmContactPtr = static_cast<frmContact*>(WData->WindowPointer);
2362 wxString WindowTitle = frmContactPtr->GetTitle();
2364 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2366 MenuIter->second->SetItemLabel(WindowTitle);
2368 //mnuWindow->FindChildItem(intID, &pos);
2369 //wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, WindowTitle, WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2370 //mnuNewItem->SetId(WData->WindowID);
2371 //ContactWindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2372 //ContactWindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2373 //mnuWindow->Insert((pos + 1), mnuNewItem);
2374 //this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2376 } else if (WData->DataType == 1){
2378 // Contact Editor Window
2380 int intID = mnuContactEditorWindows->GetId();
2382 // Get the window title and use that.
2384 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WData->WindowPointer);
2386 wxString WindowTitle = frmCEPtr->GetTitle();
2388 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2390 if (WindowTitle.IsEmpty()){
2392 MenuIter->second->SetItemLabel(_("Unnamed Contact"));
2396 MenuIter->second->SetItemLabel(WindowTitle);
2400 //mnuWindow->FindChildItem(intID, &pos);
2401 //wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, WindowTitle, WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2402 //mnuNewItem->SetId(WData->WindowID);
2403 //ContactEditorWindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2404 //ContactEditorWindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2405 //mnuWindow->Insert((pos + 1), mnuNewItem);
2406 //this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2415 void frmMain::WindowDelete( wxCommandEvent &event ){
2417 WindowData *WData = (WindowData*)event.GetClientData();
2419 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2421 mnuWindow->Remove(MenuIter->second);
2423 delete MenuIter->second;
2424 MenuIter->second = NULL;
2426 WindowListPointersMenu.erase(WData->WindowID);
2427 WindowListPointers.erase(WData->WindowID);
2428 WindowListType.erase(WData->WindowID);
2435 void frmMain::ShowContactWindow( wxCommandEvent &event ){
2437 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2439 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
2441 frmContactPtr->Show();
2442 frmContactPtr->Raise();
2446 void frmMain::ShowContactEditorWindow( wxCommandEvent &event ){
2448 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2450 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WindowIter->second);
2457 void frmMain::ShowSearchWindow( wxCommandEvent &event ){
2459 // Look through the Search Window List Pointers, grab the
2460 // window point and show the window.
2462 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2464 frmSearch *frmSearchPtr = static_cast<frmSearch*>(WindowIter->second);
2466 frmSearchPtr->Show();
2467 frmSearchPtr->Raise();
2471 void frmMain::ToggleConnectionStatus( wxCommandEvent &event ){
2473 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2474 wxCommandEvent toggconn(ACTMGR_TOGGLECONN);
2475 wxPostEvent(frameActMgr, toggconn);
2479 void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
2481 // Check the account type before continuing.
2483 wxString SeekAccount;
2484 wxString AccTypeLower;
2486 std::map<int, SSLCertCollection>::iterator SSLColIter;
2488 for (int i = 0; i < prefaccounts.GetCount(); i++){
2490 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2491 AccType.Append(prefaccounts.GetAccountType(i));
2492 AccTypeLower = AccType.MakeLower();
2493 SeekAccount.Append(wxT("."));
2494 SeekAccount.Append(AccTypeLower);
2496 if (SeekAccount == ActiveAccount){
2498 if (AccTypeLower == wxT("local")){
2504 SSLColIter = AccountSSLData.find(i);
2506 SSLCertCollection SSLCertInfo = SSLColIter->second;
2508 frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
2509 frameSSLCert->StartCertFrom(0);
2510 frameSSLCert->SetupCerts(SSLCertInfo);
2511 frameSSLCert->ShowModal();
2513 delete frameSSLCert;
2514 frameSSLCert = NULL;
2518 SeekAccount.Clear();
2519 AccTypeLower.Clear();
2526 void frmMain::ShowSSLInfo( wxCommandEvent &event ){
2528 // Check the account type before continuing.
2532 void frmMain::HideSSLInfo( wxCommandEvent &event ){
2534 // Check the account type before continuing.
2538 void frmMain::UpdateConnectionStatus( wxCommandEvent &event ){
2540 if (event.GetInt() == 0){
2542 imgConnStatus->SetBitmap(*imgOnline);
2546 imgConnStatus->SetBitmap(*imgOffline);
2552 void frmMain::SetupSSLStatus( int AccountID ){
2554 // Check if account ID given is
2555 // the active account and if not, do nothing.
2558 wxString AccTypeLower;
2560 AccType = prefaccounts.GetAccountType(AccountID);
2561 AccTypeLower = AccType.MakeLower();
2563 wxString AccountIDName = prefaccounts.GetAccountDirectory(AccountID) + wxT(".") +
2566 if (AccountIDName != ActiveAccount){
2572 // Check if the account has SSL enabled.
2574 bool SSLInUse = prefaccounts.GetAccountSSL(AccountID);
2576 if (SSLInUse == FALSE){
2578 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2579 imgSSLStatus->SetBitmap(*imgNoSSL);
2583 // Get the SSL Collection Data.
2585 std::map<int,int>::iterator SSLResultIter = AccountSSLResult.find(AccountID);
2587 if (SSLResultIter->second == 1){
2589 imgSSLStatus->SetBitmap(*imgSSLWarning);
2590 SSLToolTip->SetTip(wxT("Invalid certificate(s) received for '") +
2591 prefaccounts.GetAccountName(AccountID) +
2592 wxT("' (Connection denied by user)\n\nDouble click for more information."));
2595 } else if (SSLResultIter->second == 0){
2597 imgSSLStatus->SetBitmap(*imgSSL);
2598 SSLToolTip->SetTip(wxT("Account '") +
2599 prefaccounts.GetAccountName(AccountID) +
2600 wxT("' secured using SSL\n\nDouble click for more information."));
2608 void frmMain::InvalidSSLCertificate( wxCommandEvent &event ){
2610 frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2611 SSLInvalidCertNotifObj *SSLICNObj = (SSLInvalidCertNotifObj*)event.GetClientData();
2612 SSLCertCollection SSLCCData = SSLICNObj->CertCollection;
2613 wxString AccountName = SSLICNObj->AccountName;
2614 frameISC->LoadData(SSLCCData, AccountName);
2615 frameISC->ShowModal();
2617 int FinalConflictResult = frameISC->GetResult();
2619 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2620 event2.SetClientData(SSLICNObj->QRNotifData);
2621 event2.SetInt(FinalConflictResult);
2626 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2627 wxPostEvent(frameActMgr, event2);
2630 void frmMain::PauseAllTimers(){
2632 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2633 ASTiter != AccountSyncTimers.end(); ASTiter++){
2635 ASTiter->second->Stop();
2641 void frmMain::ResumeAllTimers(){
2643 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2644 ASTiter != AccountSyncTimers.end(); ASTiter++){
2646 ASTiter->second->Start();
2652 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollection SSLCertInc){
2654 // Delete existing data.
2656 AccountSSLData.erase(AccountID);
2657 AccountSSLResult.erase(AccountID);
2661 AccountSSLData.insert(std::make_pair(AccountID, SSLCertInc));
2662 AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2666 void frmMain::CheckUpdates( wxCommandEvent& event ){
2668 frmUpdate *frameUpdate = new frmUpdate ( this );
2669 frameUpdate->FetchData();
2670 frameUpdate->ShowModal();
2674 void frmMain::OpenImportDialog( wxCommandEvent& event ){
2676 // Run the import contacts system.
2682 void frmMain::OpenExportDialog( wxCommandEvent& event ){
2684 // Check if an account and at least one contact is selected
2685 // before continuing.
2687 wxArrayString ArrData;
2689 if (ActiveAccount.IsEmpty()){
2695 int ContactSelected = 0;
2696 int ContactsCollected = 0;
2697 long longSelected = -1;
2701 longSelected = lstContacts->GetNextItem(longSelected,
2703 wxLIST_STATE_SELECTED);
2705 if (longSelected == -1){
2711 int FileID = lstContacts->GetItemData(longSelected);
2713 ArrData.Insert(ContactsFileIndex[FileID],
2714 ContactsCollected, 1);
2720 if (ContactSelected == 0){
2726 // Run the export contacts system.
2728 ExportRun(this, &ArrData);
2732 void frmMain::GetListControl(wxListCtrl *lstContactsPtr,
2733 wxArrayString *ContactsFileIndexPtr){
2735 lstContactsPtr = lstContacts;
2736 ContactsFileIndexPtr = &ContactsFileIndex;
2740 void frmMain::GetSelectedList( wxCommandEvent& event ){
2742 // Get the array of contact filenames.
2744 wxArrayString *ArrData = (wxArrayString*)event.GetClientData();
2746 // Process them into an array of files.
2748 long longSelected = -1;
2749 int ContactsCollected = 0;
2750 wxString ContactFilename;
2754 longSelected = lstContacts->GetNextItem(longSelected,
2756 wxLIST_STATE_SELECTED);
2758 if (longSelected == -1){
2764 // Get the file information and add to the list.
2766 int FileID = lstContacts->GetItemData(longSelected);
2768 ArrData->Insert(ContactsFileIndex[FileID],
2769 ContactsCollected, 1);
2771 ContactsCollected++;
2772 ContactFilename.Clear();
2780 void frmMain::SyncAccount( wxCommandEvent& event ){
2782 wxString *AccNameInc = (wxString*)event.GetClientData();
2784 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2785 frameActMgr->AddTask(3, wxT(""), *AccNameInc,
2786 wxT(""), wxT(""), wxT(""), wxT(""));
2790 void frmMain::ShowHelp( wxCommandEvent& event ){
2792 // Based on the operating system, work out where
2793 // the documentation should be.
2797 #if defined(__HAIKU__)
2799 #elif defined(__WIN32__)
2805 if (wxFileExists("/usr/share/doc/xestiaab/index.html")){
2807 wxLaunchDefaultBrowser(wxT("file:///usr/share/doc/xestiaab/index.html"));
2810 #if XSDAB_RELEASE == 0
2812 } else if (wxFileExists("/usr/local/share/doc/xestiaab/index.html")){
2814 wxLaunchDefaultBrowser(wxT("file:///usr/local/share/doc/xestiaab/index.html"));
2823 #if XSDAB_RELEASE == 0
2825 wxMessageBox(_("The help documentation is not available.\n\nYou can view the documentation that came with your source package."), _("Help documentation missing!"));
2829 wxMessageBox(_("The help documentation is not available in the usual locations on the system. Please visit http://documentation.xestia.co.uk/xestiaab/ for documentation"), _("Help documentation missing!"));