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/XABAccountView.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 //-------------------------------------------------------------------
412 void frmMain::ShowActivityWindow( wxCommandEvent& event )
415 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
416 frameActMgr->OpenWindow();
421 void frmMain::ShowAboutWindow( wxCommandEvent& event )
423 //-------------------------------------------------------------------
424 // frmMain::ShowAboutWindow: Shows the About window as a modal
425 // dialog and then cleans up when finished.
427 // wxCommandEvent Accepts a referenced event command.
428 //-------------------------------------------------------------------
430 frmAbout *frameAbout = new frmAbout ( this );
431 frameAbout->SetupAboutWindow();
432 frameAbout->ShowModal();
438 void frmMain::OpenPreferences( wxCommandEvent& event)
440 //-------------------------------------------------------------------
441 // frmMain::ShowAboutWindow: Opens the Preferences window as a modal
442 // dialog and then cleans up when finished.
444 // wxCommandEvent Accepts a referenced event command.
445 //-------------------------------------------------------------------
447 ReloadAccounts = FALSE;
449 frmPreferences *framePreferences = new frmPreferences ( this );
450 framePreferences->SetupPointers(&ReloadAccounts);
451 framePreferences->ShowModal();
452 delete framePreferences;
453 framePreferences = NULL;
455 if (ReloadAccounts == TRUE){
457 // Reload the accounts as a change has been made within
460 this->LoadPreferences();
466 void frmMain::OpenNewABDialog( wxCommandEvent& event)
468 //-------------------------------------------------------------------
469 // frmMain::ShowAboutWindow: Opens the Preferences window as a modal
470 // dialog and then cleans up when finished.
472 // wxCommandEvent Accepts a referenced event command.
473 //-------------------------------------------------------------------
475 ReloadAccounts = FALSE;
477 frmNewAccount *frameNewAccount = new frmNewAccount ( this );
478 frameNewAccount->SetupPointers(&ReloadAccounts);
479 frameNewAccount->ShowModal();
480 delete frameNewAccount;
481 frameNewAccount = NULL;
483 if (ReloadAccounts == TRUE){
485 // Reload the accounts as a change has been made within
488 this->LoadPreferences();
494 void frmMain::LoadContactList( wxTreeEvent& event )
497 // Clear all existing variables.
499 lstContacts->DeleteAllItems();
501 treAccounts->SetAccount();
503 wxTreeItemIdValue cookie;
504 wxTreeItemId next = treAccounts->GetRootItem();
505 wxString AccountName;
506 wxString AccountDir, AccountType, AccountDirFinal, AccountTypeFinal;
507 wxString AccountDirCmb;
508 long selectedaccount = 0;
510 wxTreeItemId selectedChild = treAccounts->GetSelection();
511 wxTreeItemId nextChild;
513 wxTreeItemId ActiveItemId = treAccounts->GetFocusedItem();
514 int ActiveItemIcon = treAccounts->GetItemImage(ActiveItemId, wxTreeItemIcon_Normal);
516 int SCImg = treAccounts->GetItemImage(selectedChild);
517 int AccountIndex = 0;
519 bmpIcon->SetIcon(AccImgList->GetIcon(SCImg));
521 for (int i = 0; i < prefaccounts.GetCount(); i++){
523 if (ActiveItemIcon == 2){
525 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
526 std::multimap<int, wxString>::iterator AGFiter = AccountGroupFilename.find(AGTiter->second);
527 std::multimap<int, int>::iterator AGLiter = AccountGroupList.find(AGTiter->second);
528 int ActiveAccountG = AGLiter->second;
530 if (i == ActiveAccountG){
532 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
533 AccountType.Append(prefaccounts.GetAccountType(i));
538 if (AccountType == wxT("CardDAV")){
539 AccountTypeFinal.Append(wxT("carddav"));
541 else if (AccountType == wxT("Local")){
542 imgSSLStatus->SetBitmap(*imgOffline);
543 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
544 AccountTypeFinal.Append(wxT("local"));
555 nextChild = treAccounts->GetFirstChild(next, cookie);
558 nextChild = treAccounts->GetNextSibling(nextChild);
561 AccountName = treAccounts->GetItemText(nextChild);
563 if (nextChild == selectedChild){
564 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
565 AccountType.Append(prefaccounts.GetAccountType(i));
570 if (AccountType == wxT("CardDAV")){
571 AccountTypeFinal.Append(wxT("carddav"));
573 else if (AccountType == wxT("Local")){
574 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
575 AccountTypeFinal.Append(wxT("local"));
584 if (selectedaccount >= prefaccounts.GetCount()){
586 // The account selected isn't there so return.
594 // Open the directory and get the list of .vcf files
595 // in that directory.
597 ActiveAccount = AccountDir + wxT(".") + AccountTypeFinal;
598 ActiveAccountType = AccountType;
600 SetupSSLStatus(AccountIndex);
602 AccountDirFinal.Clear();
603 AccountDirFinal = GetAccountDir(AccountDir + wxT(".") + AccountTypeFinal, FALSE);
605 ContactsFileIndex.Clear();
607 //wxString vcardfilenamewxs;
608 wxString vCardFilename;
609 wxString vCardFilenameFull;
610 wxString vCardDataString;
611 wxStringTokenizer vcardfileline;
613 wxString setname, setvalue;
614 //vCardNames = new std::map<wxString, wxString, std::greater<wxString>>;
615 std::multimap<wxString, wxString, std::greater<wxString>> vCardNamesAsc;
616 std::multimap<wxString, wxString, std::less<wxString>> vCardNamesDsc;
617 long ContactIndex = 1;
618 long ContactSeekPoint = 0;
620 wxDir vcardaccdir(AccountDirFinal);
622 // Get the wxTreeItemId and image icon and compare it to the list.
624 if (ActiveItemIcon == AccountGrpID){
626 // It's a group so load the file containing the group and
627 // get the members of the group.
632 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
633 std::multimap<int, wxString>::iterator AGFiter = AccountGroupFilename.find(AGTiter->second);
634 //std::multimap<wxTreeItemId, int>::iterator AGFiter = AccountGroupTreeId.find(ActiveItemId);
636 Group.LoadFile(AGFiter->second);
638 ArrayvCardOutData vCardMember = Group.GetByPartial(wxT("MEMBER"));
640 for (int i = 0; i < vCardMember.PropCount; i++){
642 vCardMember.PropValues[i].Trim();
643 if (vCardMember.PropValues[i].Left(9) == wxT("urn:uuid:")){
645 wxString NewPropValue;
646 NewPropValue = vCardMember.PropValues[i].Mid(9, wxString::npos);
647 vCardMember.PropValues[i] = NewPropValue;
654 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
657 if (vCardFilename.Right(4) == wxT(".vcf") ||
658 vCardFilename.Right(4) == wxT(".VCF") ||
659 vCardFilename.Right(5) == wxT(".vcard") ||
660 vCardFilename.Right(5) == wxT(".VCARD")){
663 bool FoundMember = FALSE;
665 vCardFilenameFull.Append(AccountDirFinal);
666 vCardFilenameFull.Append(wxT("/"));
667 vCardFilenameFull.Append(vCardFilename);
669 Person.LoadFile(vCardFilenameFull);
671 UIDCode = Person.Get(wxT("UID"));
673 for (int i = 0; i < vCardMember.PropCount; i++){
675 if (vCardMember.PropValues[i] == UIDCode){
683 if (FoundMember == FALSE){
685 vCardFilename.Clear();
686 vCardFilenameFull.Clear();
687 vCardDataString.Clear();
688 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
693 if (Person.MeetBaseSpecification()){
697 // Split the name into sections.
699 vCardDataString = Person.Get(wxT("N"));
701 vCardName NameData = Person.GetName();
703 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
705 } else if (SortMode == 2){
707 // Split the name into sections.
709 vCardName NameData = Person.GetName();
711 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
713 } else if (SortMode == 3){
715 // Check and make sure that the top most nickname is used.
717 vCardDataString = Person.Get(wxT("NICKNAME"));
719 if (vCardDataString.IsEmpty()){
721 vCardDataString = wxT("(no nickname)");
725 } else if (SortMode == 4){
727 vCardDataString = Person.Get(wxT("FN"));
731 if (AscendingMode == TRUE){
732 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
734 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
743 vCardFilename.Clear();
744 vCardFilenameFull.Clear();
745 vCardDataString.Clear();
746 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
751 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
754 if (vCardFilename.Right(4) == wxT(".vcf") ||
755 vCardFilename.Right(4) == wxT(".VCF") ||
756 vCardFilename.Right(5) == wxT(".vcard") ||
757 vCardFilename.Right(5) == wxT(".VCARD")){
761 vCardFilenameFull.Append(AccountDirFinal);
762 vCardFilenameFull.Append(wxT("/"));
763 vCardFilenameFull.Append(vCardFilename);
765 Person.LoadFile(vCardFilenameFull);
767 if (Person.MeetBaseSpecification()){
771 // Split the name into sections.
773 vCardDataString = Person.Get(wxT("N"));
775 vCardName NameData = Person.GetName();
777 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
779 } else if (SortMode == 2){
781 // Split the name into sections.
783 vCardName NameData = Person.GetName();
785 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
787 } else if (SortMode == 3){
789 // Check and make sure that the top most nickname is used.
791 vCardDataString = Person.Get(wxT("NICKNAME"));
793 if (vCardDataString.IsEmpty()){
795 vCardDataString = wxT("(no nickname)");
799 } else if (SortMode == 4){
801 vCardDataString = Person.Get(wxT("FN"));
805 if (AscendingMode == TRUE){
806 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
808 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
817 vCardFilename.Clear();
818 vCardFilenameFull.Clear();
819 vCardDataString.Clear();
820 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
827 // Insert the data into the control.
829 if (AscendingMode == TRUE){
830 for (std::map<wxString, wxString>::iterator iter = vCardNamesAsc.begin();
831 iter != vCardNamesAsc.end(); ++iter){
833 wxListItem ContactInfo;
835 ContactInfo.SetId(0);
836 ContactInfo.SetText(_("Mooo"));
837 ContactInfo.SetData(ContactSeekPoint);
838 ContactIndex = lstContacts->InsertItem(ContactInfo);
840 lstContacts->SetItem(ContactIndex, 0, iter->first);
841 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
848 for (std::map<wxString, wxString>::iterator iter = vCardNamesDsc.begin();
849 iter != vCardNamesDsc.end(); ++iter){
851 wxListItem ContactInfo;
853 ContactInfo.SetId(0);
854 ContactInfo.SetText(_("Mooo"));
855 ContactInfo.SetData(ContactSeekPoint);
856 ContactIndex = lstContacts->InsertItem(ContactInfo);
858 lstContacts->SetItem(ContactIndex, 0, iter->first);
859 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
868 void frmMain::ShowContactInfo( wxListEvent& event )
871 long intSelected = -1;
872 int intSelectedData = 0;
873 long ContactSeekNum = -1;
875 // intSelected = lstContacts->GetSelection();
877 // Check if several contacts have been selected.
879 int ContactTotal = 0;
883 intSelected = lstContacts->GetNextItem(intSelected,
885 wxLIST_STATE_SELECTED);
887 if (intSelected == -1){
897 if (ContactTotal == 0){
898 htmContactData->SetPage(wxT(""));
902 if (ContactTotal > 1){
904 htmContactData->SetPage(wxString::Format(wxT("%i contacts selected."), ContactTotal));
905 ActiveFilename.Clear();
910 intSelected = lstContacts->GetNextItem(intSelected,
912 wxLIST_STATE_SELECTED);
914 ContactSeekNum = lstContacts->GetItemData(intSelected);
917 wxString wxSContactString;
918 wxString ContactLine;
922 bool ExtraLineSeek = FALSE;
925 bool PropertyFind = FALSE;
926 bool QuoteMode = FALSE;
928 wxString wxSPropertyNextLine;
929 wxString wxSProperty;
930 wxString wxSPropertySeg1;
931 wxString wxSPropertySeg2;
933 // Check if we are using wxWidgets version 2.8 or less and
934 // execute the required command accordingly.
936 #if wxABI_VERSION < 20900
937 ContactFile.Open(ContactsFileIndex[ContactSeekNum].c_str(), wxT("r"));
939 ContactFile.Open(ContactsFileIndex[ContactSeekNum], wxT("r"));
942 if (ContactFile.IsOpened() == FALSE){
948 ContactFile.ReadAll(&wxSContactString, wxConvAuto());
952 std::map<int, wxString> ContactFileLines;
953 std::map<int, wxString>::iterator striter;
955 wxStringTokenizer wSTContactFileLines(wxSContactString, wxT("\r\n"));
957 int ContactLineSeek = 0;
959 while (wSTContactFileLines.HasMoreTokens() == TRUE){
961 ContactLine = wSTContactFileLines.GetNextToken();
962 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
967 if (ContactSeekNum < 0){
971 for (std::map<int, wxString>::iterator iter = ContactFileLines.begin();
972 iter != ContactFileLines.end(); ++iter){
974 // Find the colon which splits the start bit from the data part.
976 ContactLine = iter->second;
978 while (ExtraLineSeek == TRUE){
980 // Check if there is extra data on the next line
981 // (indicated by space or tab at the start) and add data.
985 if (iter == ContactFileLines.end()){
992 wxSPropertyNextLine = iter->second;
995 if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
997 wxSPropertyNextLine.Remove(0, 1);
998 //wxSPropertyNextLine.Trim(FALSE);
999 //ContactLine.Trim();
1000 ContactLine.Append(wxSPropertyNextLine);
1005 ExtraLineSeek = FALSE;
1011 ContactLineLen = ContactLine.Len();
1013 // Make sure we are not in quotation mode.
1014 // Make sure colon does not have \ or \\ before it.
1016 for (int i = 0; i <= ContactLineLen; i++){
1018 if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
1020 PropertyFind = FALSE;
1022 } else if (PropertyFind == TRUE){
1024 wxSProperty.Append(ContactLine.Mid(i, 1));
1028 if (ContactLine.Mid(i, 1) == wxT("\"")){
1030 if (QuoteMode == TRUE){
1042 if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
1044 QuoteBreakPoint = i;
1051 // Split that line at the point into two variables (ignore the colon).
1053 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
1054 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
1056 // Insert both into the vCard data file.
1058 Person.AddRaw(wxSPropertySeg1, wxSPropertySeg2);
1061 PropertyFind = TRUE;
1062 ExtraLineSeek = TRUE;
1064 QuoteBreakPoint = 0;
1065 ContactLine.Clear();
1066 wxSProperty.Clear();
1070 OldSessionID = SessionID;
1071 SessionID = wxString::Format(wxT("%i"), rand() % 32768);
1072 LoadContactData(&Person, htmContactData, SessionID, OldSessionID, &MemoryFileList);
1073 ActiveFilename = ContactsFileIndex[ContactSeekNum];
1077 void frmMain::ShowContactEditorNew( wxCommandEvent& event )
1080 // Check if there is an account selected and if not
1081 // return immediately.
1083 if (ActiveAccount.IsEmpty()){
1089 // Add Pointer to SetupPointers for the ETagDB.
1091 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1092 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1093 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1095 contacticon.CopyFromBitmap(contacticonbmp);
1097 frmContactEditor *ContactEditor = new frmContactEditor( this );
1101 ContactEditor->SetUID(WindowMenuItemID);
1103 WindowData *WData = new WindowData;
1105 WData->DataType = 1;
1106 WData->WindowPointer = (void*)ContactEditor;
1107 WData->WindowID = WindowMenuItemID;
1109 wxCommandEvent addevent(WINDOW_ADD);
1110 addevent.SetClientData(WData);
1111 wxPostEvent(this, addevent);
1113 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1114 ContactEditor->SetupHeaders();
1115 ContactEditor->SetupContact(ActiveAccount);
1116 ContactEditor->SetIcon(contacticon);
1117 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1118 ContactEditor->Show(true);
1122 void frmMain::ShowContactEditorEdit( wxCommandEvent& event )
1125 // Check if there is an account selected and if not
1126 // return immediately.
1128 int DataCheck = event.GetInt();
1130 if (ActiveAccount.IsEmpty() && DataCheck == 0){
1136 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1137 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1138 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1140 contacticon.CopyFromBitmap(contacticonbmp);
1142 // Check if a contact has been selected.
1144 long intSelected = -1;
1145 int intSelectedData = 0;
1146 long intContactSeekNum = -1;
1148 // intSelected = lstContacts->GetSelection();
1150 intSelected = lstContacts->GetNextItem(intSelected,
1152 wxLIST_STATE_SELECTED);
1154 if (intSelected == -1){
1158 intContactSeekNum = lstContacts->GetItemData(intSelected);
1160 // Get the filename of the selected contact.
1162 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1163 frmContactEditor *ContactEditor = new frmContactEditor( this );
1167 ContactEditor->SetUID(WindowMenuItemID);
1169 WindowData *WData = new WindowData;
1171 WData->DataType = 1;
1172 WData->WindowPointer = (void*)ContactEditor;
1173 WData->WindowID = WindowMenuItemID;
1175 wxCommandEvent addevent(WINDOW_ADD);
1176 addevent.SetClientData(WData);
1177 wxPostEvent(this, addevent);
1179 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1180 ContactEditor->SetupHeaders();
1182 // Check if pointer is NULL (not from the search forms) or not.
1184 if (DataCheck == 0){
1186 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1187 ContactEditor->SetupContact(ActiveAccount);
1191 UCNotif *uc = (UCNotif*)event.GetClientData();
1195 ContactEditor->SetupContact(ActiveAccount);
1196 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1200 ContactEditor->SetupContact(uc->ContactAccount);
1201 ContactEditor->LoadContact(uc->ContactFilename);
1211 ContactEditor->SetIcon(contacticon);
1212 ContactEditor->Show(true);
1216 void frmMain::RefreshAddressBook( wxCommandEvent& event ){
1218 // TODO: Check Account Type.
1220 if (!ActiveAccount.IsEmpty()){
1222 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1223 frameActMgr->AddTask(3, wxT(""), ActiveAccount,
1224 wxT(""), wxT(""), wxT(""), wxT(""));
1230 void frmMain::OpenContactInfo( wxListEvent& event )
1233 wxStringTokenizer vcardfileline;
1236 wxString setname, setvalue;
1240 long intSelected = -1;
1241 int intSelectedData = 0;
1242 long intContactSeekNum = -1;
1244 intSelected = lstContacts->GetNextItem(intSelected,
1246 wxLIST_STATE_SELECTED);
1248 intContactSeekNum = lstContacts->GetItemData(intSelected);
1250 if (intContactSeekNum == -1){
1254 Person.LoadFile(ContactsFileIndex[intContactSeekNum]);
1256 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1257 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1258 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1260 contacticon.CopyFromBitmap(contacticonbmp);
1262 frmContact *Contact = new frmContact( this );
1264 // Add to window list.
1268 Contact->SetUID(WindowMenuItemID);
1270 WindowData *WData = new WindowData;
1272 WData->DataType = 0;
1273 WData->WindowPointer = (void*)Contact;
1274 WData->WindowID = WindowMenuItemID;
1276 wxCommandEvent addevent(WINDOW_ADD);
1277 addevent.SetClientData(WData);
1278 wxPostEvent(this, addevent);
1280 Contact->SetupPointers(&MemoryFileList);
1281 Contact->SetupContactData(&Person);
1283 Contact->SetIcon(contacticon);
1284 Contact->Show(true);
1288 void frmMain::OpenContactInfo( wxCommandEvent& event )
1291 UCNotif *uc = (UCNotif*)event.GetClientData();
1293 wxStringTokenizer vcardfileline;
1296 wxString setname, setvalue;
1299 //std::fstream vcardfile;
1301 long intSelected = -1;
1302 int intSelectedData = 0;
1303 long intContactSeekNum = -1;
1305 Person.LoadFile(uc->ContactFilename);
1307 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1308 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1309 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1311 contacticon.CopyFromBitmap(contacticonbmp);
1313 frmContact *Contact = new frmContact( this );
1315 // Add to window list.
1319 Contact->SetUID(WindowMenuItemID);
1321 WindowData *WData = new WindowData;
1323 WData->DataType = 0;
1324 WData->WindowPointer = (void*)Contact;
1325 WData->WindowID = WindowMenuItemID;
1327 wxCommandEvent addevent(WINDOW_ADD);
1328 addevent.SetClientData(WData);
1329 wxPostEvent(this, addevent);
1331 Contact->SetupPointers(&MemoryFileList);
1332 Contact->SetupContactData(&Person);
1334 Contact->SetIcon(contacticon);
1335 Contact->Show(true);
1340 void frmMain::LoadPreferences( wxActivateEvent& event)
1342 this->LoadPreferences();
1345 void frmMain::LoadPreferences(){
1347 // Load the preferences.
1349 wxString preffilename = GetUserPrefDir();
1351 XABPreferences preferences(preffilename);
1353 // Setup the main window position (if needed).
1355 bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
1356 bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
1358 if (SaveWindowPos == TRUE){
1360 this->SetSize(preferences.GetMainWindowData());
1364 treAccounts->DeleteAllItems();
1366 wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"), AccountNoneID);
1368 // Stop all account timers and remove the accounts.
1370 for (std::map<wxString, wxAccountSyncTimer*>::iterator iter = AccountSyncTimers.begin();
1371 iter != AccountSyncTimers.end(); iter++){
1373 wxAccountSyncTimer *AccTmrPtr = iter->second;
1381 AccountSyncTimers.clear();
1384 for (int i = (preferences.accounts.GetCount() - 1); i > 0; --i){
1385 treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i));
1390 wxString AccDirFull;
1391 wxString AccDirFullSfx;
1393 wxString AccDirFinal;
1394 AccountAccDirList.clear();
1395 AccountGroupList.clear();
1396 AccountGroupFilename.clear();
1397 AccountGroupTreeId.clear();
1398 wxTreeItemId AccountTreeId;
1399 wxTreeItemId GroupTreeId;
1402 for (int i = 0; i < preferences.accounts.GetCount(); i++){
1404 if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
1405 preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
1411 if (preferences.accounts.GetAccountDirectory(i).IsEmpty()){
1417 AccDir = preferences.accounts.GetAccountDirectory(i);
1418 AccDirFull = preferences.accounts.GetAccountDirectory(i);
1420 AccDirFull.Append(wxT("."));
1421 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
1422 AccDirFullSfx.LowerCase();
1423 AccDirFullSfx.Trim();
1424 AccDirFull.Append(AccDirFullSfx);
1425 AccName = preferences.accounts.GetAccountName(i);
1427 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
1429 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
1430 preferences.accounts.GetAccountType(i) == wxT("carddav")){
1432 // Check if the directory exists before doing anything.
1436 // Add a new timer using the existing account details.
1438 wxAccountSyncTimer *ActTmrPtr = new wxAccountSyncTimer;
1440 ActTmrPtr->SetupData(AccDirFull, AccName);
1441 ActTmrPtr->SetupPointers(this, ActMgrPtr, ETagProcTimer.GetPointer(AccDirFull));
1442 ActTmrPtr->Start(preferences.accounts.GetAccountRefresh(i) * 1000);
1443 ActTmrPtr->SetOwner(this);
1444 ActTmrPtr->Notify();
1446 // Add the timer to the list of timers.
1448 AccountSyncTimers.insert(std::make_pair(AccDirFull, ActTmrPtr));
1450 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
1454 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
1458 // Go through the account directory and find contact files with
1459 // 'KIND:group' set and add them to the list of groups for the account.
1461 AccDirFinal = GetAccountDir(AccDirFull, FALSE);
1463 wxDir vcardaccdir(AccDirFinal);
1465 wxString vCardFilename;
1466 wxString vCardDataString;
1467 wxString vCardFilenameFull;
1468 //bool ProcFiles = FALSE;
1470 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
1473 if (vCardFilename.Right(4) == wxT(".vcf") ||
1474 vCardFilename.Right(4) == wxT(".VCF") ||
1475 vCardFilename.Right(5) == wxT(".vcard") ||
1476 vCardFilename.Right(5) == wxT(".VCARD")){
1480 vCardFilenameFull.Append(AccDirFinal);
1481 vCardFilenameFull.Append(wxT("/"));
1482 vCardFilenameFull.Append(vCardFilename);
1484 Person.LoadFile(vCardFilenameFull);
1486 if (Person.MeetBaseSpecification()){
1488 vCardDataString = Person.Get(wxT("KIND"));
1490 if (vCardDataString == wxT("group")){
1492 // The vCard kind is a group. Add to the account's group list.
1494 GroupTreeId = treAccounts->AppendItem(AccountTreeId, Person.Get(wxT("FN")), AccountGrpID, -1);
1495 treAccounts->SetItemHasChildren(AccountTreeId, TRUE);
1496 AccountGroupList.insert(std::make_pair(intGroupID, i));
1497 AccountGroupFilename.insert(std::make_pair(intGroupID, vCardFilenameFull));
1498 AccountGroupTreeId.insert(std::make_pair(GroupTreeId, intGroupID));
1510 vCardFilename.Clear();
1511 vCardFilenameFull.Clear();
1512 vCardDataString.Clear();
1513 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1517 // Clearup for next account.
1521 AccDirFullSfx.clear();
1522 AccDirFinal.clear();
1527 // Load the account settings as they are needed for connecting
1530 prefaccounts = preferences.accounts;
1534 void frmMain::ConflictResolution(wxCommandEvent& event){
1536 frmConflictResolution *frameCR = new frmConflictResolution ( this );
1537 vCardConflictObj *vCardConfObj = (vCardConflictObj*)event.GetClientData();
1538 vCard *ClientDataPtr = vCardConfObj->vCardLocalData;
1539 vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1540 //vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1541 //wxString Moo = ClientDataPtr->WriteString();
1542 //vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1543 frameCR->LoadData(ClientDataPtr, ServerDataPtr, &MemoryFileList);
1544 //frameCR->LoadData(vCardConfObj->vCardLocalData, vCardConfObj->vCardServerData, &MemoryFileList);
1545 frameCR->ShowModal();
1547 int FinalConflictResult = frameCR->GetResult();
1549 wxCommandEvent event2(ACTMGR_RESUMEPROC);
1550 event2.SetClientData(vCardConfObj->QRNotifData);
1551 event2.SetInt(FinalConflictResult);
1556 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1557 wxPostEvent(frameActMgr, event2);
1561 void frmMain::UpdateContactList(wxCommandEvent& event){
1563 UCNotif *ucd = (UCNotif*)event.GetClientData();
1565 // Check if the active account is being displayed in the
1566 // main window. If not, skip and delete the data.
1568 long longSelected = -1;
1569 int intSelectedData = 0;
1571 if (ActiveAccount == ucd->ContactAccount){
1573 // Look at the list of contacts and if it matches the
1574 // filename then update the name.
1578 longSelected = lstContacts->GetNextItem(longSelected,
1580 wxLIST_STATE_DONTCARE);
1582 if (longSelected == -1){
1588 intSelectedData = lstContacts->GetItemData(longSelected);
1590 if (ucd->ContactFilename == ContactsFileIndex[intSelectedData]){
1592 // Work out which sorting mode we are in.
1596 // First Name, Last Name.
1598 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Forename + wxT(" ") + ucd->ContactNameArray.Surname);
1600 } else if (SortMode == 2){
1602 // Last Name, First Name.
1604 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Surname + wxT(", ") + ucd->ContactNameArray.Forename);
1606 } else if (SortMode == 3){
1610 lstContacts->SetItem(longSelected, 0, ucd->ContactNickname);
1612 } else if (SortMode == 4){
1616 lstContacts->SetItem(longSelected, 0, ucd->ContactName);
1623 // If the filename is the one loaded into the
1624 // browser control, then update this too.
1626 if (ActiveFilename == ContactsFileIndex[intSelectedData]){
1628 wxListEvent nullevent;
1629 ShowContactInfo(nullevent);
1637 for (std::map<int, void*>::iterator WindowIter = WindowListPointers.begin();
1638 WindowIter != WindowListPointers.end(); WindowIter++){
1640 if (WindowListType[WindowIter->first] != 0){
1646 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
1648 if (frmContactPtr->GetFilename() == ucd->ContactFilename){
1650 vCard UpdatedPerson;
1651 UpdatedPerson.LoadFile(ucd->ContactFilename);
1652 frmContactPtr->SetupContactData(&UpdatedPerson);
1658 // Send message to search window controller subroutine and
1659 // pass that notification onto the search windows.
1661 // Setup the new pointer to use the existing UCNotif without
1664 UCNotif *ucd2 = ucd;
1666 wxCommandEvent sup(SE_UPDATECONTACTNOTIF);
1667 sup.SetClientData(ucd2);
1668 wxPostEvent(this, sup);
1670 // Clear up the unused pointer.
1676 void frmMain::UpdateAccountList(wxCommandEvent& event){
1680 void frmMain::SetupPointers(void *ActMgrPtrInc){
1682 ActMgrPtr = ActMgrPtrInc;
1686 void frmMain::SetupForm(){
1688 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1689 frameActMgr->SetupPointers(&ETagProcTimer, this);
1691 // Setup the contact information icons for later.
1693 wxFileSystem::AddHandler(new wxMemoryFSHandler);
1697 wxMemoryInputStream ciptostream(icons_cipto_png, sizeof(icons_cipto_png));
1698 ciicon_png.LoadFile(ciptostream, wxBITMAP_TYPE_PNG);
1699 wxMemoryFSHandler::AddFile(wxT("cipto.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1701 wxMemoryInputStream cilogstream(icons_cilog_png, sizeof(icons_cilog_png));
1702 ciicon_png.LoadFile(cilogstream, wxBITMAP_TYPE_PNG);
1703 wxMemoryFSHandler::AddFile(wxT("cilog.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1705 wxMemoryInputStream cisndstream(icons_cisnd_png, sizeof(icons_cisnd_png));
1706 ciicon_png.LoadFile(cisndstream, wxBITMAP_TYPE_PNG);
1707 wxMemoryFSHandler::AddFile(wxT("cisnd.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1709 wxMemoryInputStream cikeystream(icons_cikey_png, sizeof(icons_cikey_png));
1710 ciicon_png.LoadFile(cikeystream, wxBITMAP_TYPE_PNG);
1711 wxMemoryFSHandler::AddFile(wxT("cikey.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1713 wxMemoryInputStream civenstream(icons_civen_png, sizeof(icons_civen_png));
1714 ciicon_png.LoadFile(civenstream, wxBITMAP_TYPE_PNG);
1715 wxMemoryFSHandler::AddFile(wxT("civen.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1717 wxMemoryInputStream ciextstream(icons_ciext_png, sizeof(icons_ciext_png));
1718 ciicon_png.LoadFile(ciextstream, wxBITMAP_TYPE_PNG);
1719 wxMemoryFSHandler::AddFile(wxT("ciext.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1725 void frmMain::UpdateSearchContactLists(wxCommandEvent& event){
1727 // Go through each of the search windows and
1728 // send the required notification to update the
1729 // contact information.
1731 // Get the event notification data.
1733 UCNotif *ucd = (UCNotif*)event.GetClientData();
1735 // Process each search window giving the new details.
1737 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1738 switer != SearchWindowList.end(); switer++){
1740 // Duplicate the event notification data.
1742 UCNotif *ucd2 = new UCNotif;
1744 ucd2->ContactAccount = ucd->ContactAccount;
1745 ucd2->ContactFilename = ucd->ContactFilename;
1746 ucd2->ContactName = ucd->ContactName;
1747 ucd2->ContactNickname = ucd->ContactNickname;
1748 ucd2->ContactNameArray = ucd->ContactNameArray;
1750 // Pass the data to the search window for processing.
1752 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1753 wxCommandEvent schupdate(SE_UPDATERESULT);
1754 schupdate.SetClientData(ucd2);
1755 wxPostEvent(frameSCH, schupdate);
1757 // Clear up the pointer prior to variable deletion.
1768 void frmMain::OpenFindContactsWindow(wxCommandEvent& event){
1772 frmSearch *frameSCH = new frmSearch ( this );
1773 frameSCH->SetUID(WindowMenuItemID);
1774 frameSCH->Show(true);
1776 WindowData *WData = new WindowData;
1778 WData->DataType = 2;
1779 WData->WindowPointer = (void*)frameSCH;
1780 WData->WindowID = WindowMenuItemID;
1782 wxCommandEvent addevent(WINDOW_ADD);
1783 addevent.SetClientData(WData);
1784 wxPostEvent(this, addevent);
1786 // Add pointer to the list of open search windows.
1788 SearchWindowList.insert(std::make_pair(frameSCH, wxT("Search")));
1794 void frmMain::RemoveContactsWindowPointer(wxCommandEvent& event){
1796 //frmSearch *frameSCH = static_cast<frmSearch*>(ActMgrPtr);
1797 void *frameSCH = (void*)event.GetClientData();
1799 SearchWindowList.erase(frameSCH);
1805 void frmMain::RemoveContactEditorWindowPointer(wxCommandEvent& event){
1807 void *frameSCH = (void*)event.GetClientData();
1809 SearchWindowList.erase(frameSCH);
1815 void frmMain::UpdateWindowList(wxCommandEvent& event){
1817 // Update the Window List.
1819 // Delete the existing items in the window menu.
1821 // Get the list of contacts.
1823 // Insert a separator.
1825 // Get the list of search windows.
1829 void frmMain::RevealContact(wxCommandEvent& event){
1831 UCNotif *uc = (UCNotif*)event.GetClientData();
1833 // Switch the account to the one passed.
1835 wxTreeItemIdValue cookie;
1836 wxTreeItemId next = treAccounts->GetRootItem();
1837 wxTreeItemId nextChild;
1839 for (int i = 0; i < prefaccounts.GetCount(); i++){
1842 nextChild = treAccounts->GetFirstChild(next, cookie);
1844 nextChild = treAccounts->GetNextSibling(nextChild);
1847 //AccountName = treAccounts->GetItemText(nextChild);
1849 if (uc->ContactAccount == AccountAccDirList[i]){
1852 treAccounts->SelectItem(nextChild, TRUE);
1853 AccCtrl->SetText(treAccounts->GetItemText(nextChild));
1859 // Switch the contact to the one passed.
1861 long longSelected = -1;
1862 int intSelectedData = 0;
1866 longSelected = lstContacts->GetNextItem(longSelected,
1868 wxLIST_STATE_DONTCARE);
1870 if (longSelected == -1){
1876 intSelectedData = lstContacts->GetItemData(longSelected);
1878 // Compare the filename with the one received.
1879 // If they match then select it.
1881 if (ContactsFileIndex[intSelectedData] == uc->ContactFilename){
1885 lstContacts->SetItemState(longSelected, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1886 lstContacts->EnsureVisible(longSelected);
1896 void frmMain::DeleteContact(wxCommandEvent& event){
1898 // Check if a contact is selected.
1900 long intSelected = -1;
1901 int intSelectedData = 0;
1902 long intContactSeekNum = -1;
1903 wxString wxSContactName;
1905 intSelected = lstContacts->GetNextItem(intSelected,
1907 wxLIST_STATE_SELECTED);
1909 if (intSelected == -1){
1913 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1915 // Get the item data of the contact.
1917 intContactSeekNum = lstContacts->GetItemData(intSelected);
1919 // Get the name of the contact.
1921 wxSContactName = lstContacts->GetItemText(intSelected);
1923 // Display a message confirming if the contact should
1926 int QuestionResponse;
1928 QuestionResponse = wxMessageBox(_("Are you sure you want to delete this contact?"), _("Delete contact"), wxYES_NO, this);
1930 if (QuestionResponse == wxNO){
1932 // Exit the subroutine
1938 // Delete the contact.
1940 if (!wxRemoveFile(ContactsFileIndex[intContactSeekNum])){
1942 wxMessageBox(_("Unable to delete the contact."), _("Cannot delete contact"), wxOK, this);
1947 // Remove the contact from the list.
1949 lstContacts->DeleteItem(intSelected);
1951 // Update the search windows, removing the deleted
1954 UCNotif *ucd = new UCNotif;
1956 ucd->ContactAccount = ActiveAccount;
1957 ucd->ContactFilename = ContactsFileIndex[intContactSeekNum];
1959 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1960 switer != SearchWindowList.end(); switer++){
1962 // Duplicate the event notification data.
1964 UCNotif *ucd2 = new UCNotif;
1966 ucd2->ContactAccount = ucd->ContactAccount;
1967 ucd2->ContactFilename = ucd->ContactFilename;
1969 // Pass the data to the search window for processing.
1971 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1972 wxCommandEvent schdelete(SE_DELETERESULT);
1973 schdelete.SetClientData(ucd2);
1974 wxPostEvent(frameSCH, schdelete);
1976 // Clear up the pointer prior to variable deletion.
1983 // Clear the wxHTMLWindow.
1985 wxString EmptyPage = wxT("");
1987 htmContactData->SetPage(EmptyPage);
1989 wxStringTokenizer wSTFilename(ContactsFileIndex[intContactSeekNum], wxT("/"));
1991 wxString wxSplitFilename;
1992 wxString wxSDataURL;
1994 while(wSTFilename.HasMoreTokens()){
1996 wxSplitFilename = wSTFilename.GetNextToken();
2000 if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
2002 // Update the ETagDB and mark it as deleted.
2004 ETagDB *ETagDBPtr = ETagProcTimer.GetPointer(ActiveAccount);
2006 ETagDBPtr->UpdateETag(wxSplitFilename, wxT("DELETED"));
2008 // Get the Data URL.
2010 wxTreeItemIdValue cookie;
2011 wxTreeItemId next = treAccounts->GetRootItem();
2013 wxTreeItemId selectedChild = treAccounts->GetSelection();
2014 wxTreeItemId nextChild;
2016 for (int i = 0; i < prefaccounts.GetCount(); i++){
2019 nextChild = treAccounts->GetFirstChild(next, cookie);
2022 nextChild = treAccounts->GetNextSibling(nextChild);
2025 if (nextChild == selectedChild){
2026 wxSDataURL = prefaccounts.GetAccountDirPrefix(i) + wxT("/") + wxSplitFilename;
2032 // Add task to the activity monitor to delete the contact.
2034 frameActMgr->AddTask(2, wxSContactName, ActiveAccount, wxSDataURL, wxSplitFilename, ContactsFileIndex[intContactSeekNum], wxT(""));
2038 // Clear the variable. Don't delete as it will mess things up.
2040 ContactsFileIndex[intContactSeekNum] = wxT("");
2047 void frmMain::EmptyServerDialog(wxCommandEvent& event){
2049 QRNotif *qrn = (QRNotif *)event.GetClientData();
2051 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);
2053 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2054 event2.SetInt(*qrn->QResponse);
2055 event2.SetClientData(qrn->PausePtr);
2057 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2059 wxPostEvent(frameActMgr, event2);
2063 void frmMain::DeleteContactSync(wxString &Account, wxString &Filename){
2065 // Remove the contact from the window after syncronising.
2067 // Check which account is currently active in the window.
2068 // If it is different from the one passed to this subroutine then
2069 // exit from the subroutine.
2071 if (Account != ActiveAccount){
2075 long longSelected = -1;
2076 int intSelectedData = 0;
2080 longSelected = lstContacts->GetNextItem(longSelected,
2082 wxLIST_STATE_DONTCARE);
2084 if (longSelected == -1){
2090 intSelectedData = lstContacts->GetItemData(longSelected);
2092 // Compare the filename with the one received.
2093 // If they match then select it.
2095 if (ContactsFileIndex[intSelectedData] == Filename){
2097 // Remove the contact from the window.
2099 lstContacts->DeleteItem(intSelectedData);
2101 // Check if contact is the selected contact in the HTML window and
2102 // if it is then clear the window.
2104 if (ActiveFilename == Filename){
2106 wxString EmptyPage = wxT("");
2107 htmContactData->SetPage(EmptyPage);
2121 void frmMain::SortFNLN( wxCommandEvent& event ) {
2123 wxTreeEvent NullEvent;
2125 LoadContactList(NullEvent);
2129 void frmMain::SortLNFN( wxCommandEvent& event ) {
2131 wxTreeEvent NullEvent;
2133 LoadContactList(NullEvent);
2137 void frmMain::SortNickname( wxCommandEvent& event ) {
2139 wxTreeEvent NullEvent;
2141 LoadContactList(NullEvent);
2145 void frmMain::SortDisplayAs( wxCommandEvent& event ) {
2147 wxTreeEvent NullEvent;
2149 LoadContactList(NullEvent);
2153 void frmMain::SortAscending( wxCommandEvent& event ) {
2155 wxTreeEvent NullEvent;
2156 AscendingMode = TRUE;
2157 LoadContactList(NullEvent);
2161 void frmMain::SortDescending( wxCommandEvent& event ) {
2163 wxTreeEvent NullEvent;
2164 AscendingMode = FALSE;
2165 LoadContactList(NullEvent);
2169 void frmMain::ToggleStatusBar( wxCommandEvent& event ) {
2171 if (stbBottom->IsShown() == TRUE){
2185 void frmMain::ActivityIconStart( wxCommandEvent& event ){
2187 // Display the activity icon.
2189 imgActivityStatus->SetBitmap(*imgActIcon1);
2190 ActivityIconStatus = 0;
2194 void frmMain::ActivityIconShuffle( wxCommandEvent& event ){
2196 switch (ActivityIconStatus){
2199 imgActivityStatus->SetBitmap(*imgActIcon1);
2200 ActivityIconStatus = 1;
2203 imgActivityStatus->SetBitmap(*imgActIcon2);
2204 ActivityIconStatus = 2;
2207 imgActivityStatus->SetBitmap(*imgActIcon3);
2208 ActivityIconStatus = 3;
2211 imgActivityStatus->SetBitmap(*imgActIcon4);
2212 ActivityIconStatus = 0;
2215 ActivityIconStatus = 0;
2221 void frmMain::ActivityIconStop( wxCommandEvent& event ){
2223 // Display the sleep icon.
2225 imgActivityStatus->SetBitmap(*imgActIconSleep);
2229 void frmMain::UpdateSBIconPlacement( wxSizeEvent& event ){
2231 if (imgConnStatus == 0 || imgSSLStatus == 0 || imgActivityStatus == 0){
2239 wxRect rectActivity;
2240 stbBottom->GetFieldRect(1, rectOnline);
2241 stbBottom->GetFieldRect(2, rectSSL);
2242 stbBottom->GetFieldRect(3, rectActivity);
2244 imgConnStatus->Move(rectOnline.GetX(),rectOnline.GetY());
2245 imgSSLStatus->Move(rectSSL.GetX(),rectSSL.GetY());
2246 imgActivityStatus->Move(rectActivity.GetX(),rectActivity.GetY());
2250 XABViewMode frmMain::GetViewMode(){
2254 xvm.SortMode = SortMode;
2255 xvm.AscendingMode = AscendingMode;
2261 void frmMain::WindowAdd( wxCommandEvent &event ){
2263 WindowData *WData = (WindowData*)event.GetClientData();
2267 if (WData->DataType == 0){
2271 int intID = mnuContactWindows->GetId();
2273 mnuWindow->FindChildItem(intID, &pos);
2274 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2275 mnuNewItem->SetId(WData->WindowID);
2276 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2277 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2278 WindowListType.insert(std::make_pair(WData->WindowID, 0));
2279 mnuWindow->Insert((pos + 1), mnuNewItem);
2280 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2282 } else if (WData->DataType == 1){
2284 // Contact Editor Window
2286 int intID = mnuContactEditorWindows->GetId();
2288 mnuWindow->FindChildItem(intID, &pos);
2289 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Editor Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2290 mnuNewItem->SetId(WData->WindowID);
2291 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2292 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2293 WindowListType.insert(std::make_pair(WData->WindowID, 1));
2294 mnuWindow->Insert((pos + 1), mnuNewItem);
2295 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2297 } else if (WData->DataType == 2){
2301 int intID = mnuSearchWindows->GetId();
2303 mnuWindow->FindChildItem(intID, &pos);
2304 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Search Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2305 mnuNewItem->SetId(WData->WindowID);
2306 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2307 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2308 WindowListType.insert(std::make_pair(WData->WindowID, 2));
2309 mnuWindow->Insert((pos + 1), mnuNewItem);
2310 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowSearchWindow));
2319 void frmMain::WindowEdit( wxCommandEvent &event ){
2321 WindowData *WData = (WindowData*)event.GetClientData();
2323 if (WData->DataType == 0){
2327 int intID = mnuContactWindows->GetId();
2329 // Get the window title and use that.
2331 frmContact *frmContactPtr = static_cast<frmContact*>(WData->WindowPointer);
2333 wxString WindowTitle = frmContactPtr->GetTitle();
2335 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2337 MenuIter->second->SetItemLabel(WindowTitle);
2339 //mnuWindow->FindChildItem(intID, &pos);
2340 //wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, WindowTitle, WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2341 //mnuNewItem->SetId(WData->WindowID);
2342 //ContactWindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2343 //ContactWindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2344 //mnuWindow->Insert((pos + 1), mnuNewItem);
2345 //this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2347 } else if (WData->DataType == 1){
2349 // Contact Editor Window
2351 int intID = mnuContactEditorWindows->GetId();
2353 // Get the window title and use that.
2355 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WData->WindowPointer);
2357 wxString WindowTitle = frmCEPtr->GetTitle();
2359 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2361 if (WindowTitle.IsEmpty()){
2363 MenuIter->second->SetItemLabel(_("Unnamed Contact"));
2367 MenuIter->second->SetItemLabel(WindowTitle);
2371 //mnuWindow->FindChildItem(intID, &pos);
2372 //wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, WindowTitle, WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2373 //mnuNewItem->SetId(WData->WindowID);
2374 //ContactEditorWindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2375 //ContactEditorWindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2376 //mnuWindow->Insert((pos + 1), mnuNewItem);
2377 //this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2386 void frmMain::WindowDelete( wxCommandEvent &event ){
2388 WindowData *WData = (WindowData*)event.GetClientData();
2390 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2392 mnuWindow->Remove(MenuIter->second);
2394 delete MenuIter->second;
2395 MenuIter->second = NULL;
2397 WindowListPointersMenu.erase(WData->WindowID);
2398 WindowListPointers.erase(WData->WindowID);
2399 WindowListType.erase(WData->WindowID);
2406 void frmMain::ShowContactWindow( wxCommandEvent &event ){
2408 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2410 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
2412 frmContactPtr->Show();
2413 frmContactPtr->Raise();
2417 void frmMain::ShowContactEditorWindow( wxCommandEvent &event ){
2419 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2421 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WindowIter->second);
2428 void frmMain::ShowSearchWindow( wxCommandEvent &event ){
2430 // Look through the Search Window List Pointers, grab the
2431 // window point and show the window.
2433 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2435 frmSearch *frmSearchPtr = static_cast<frmSearch*>(WindowIter->second);
2437 frmSearchPtr->Show();
2438 frmSearchPtr->Raise();
2442 void frmMain::ToggleConnectionStatus( wxCommandEvent &event ){
2444 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2445 wxCommandEvent toggconn(ACTMGR_TOGGLECONN);
2446 wxPostEvent(frameActMgr, toggconn);
2450 void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
2452 // Check the account type before continuing.
2454 wxString SeekAccount;
2455 wxString AccTypeLower;
2458 std::map<int, SSLCertCollection>::iterator SSLColIter;
2460 for (int i = 0; i < prefaccounts.GetCount(); i++){
2462 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2463 AccType.Append(prefaccounts.GetAccountType(i));
2464 AccountSSL = prefaccounts.GetAccountSSL(i);
2465 AccTypeLower = AccType.MakeLower();
2466 SeekAccount.Append(wxT("."));
2467 SeekAccount.Append(AccTypeLower);
2469 if (SeekAccount == ActiveAccount){
2471 if (AccTypeLower == wxT("local")){
2477 if (AccountSSL == false){
2483 SSLColIter = AccountSSLData.find(i);
2485 SSLCertCollection SSLCertInfo = SSLColIter->second;
2487 frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
2488 frameSSLCert->StartCertFrom(0);
2489 frameSSLCert->SetupCerts(SSLCertInfo);
2490 frameSSLCert->ShowModal();
2492 delete frameSSLCert;
2493 frameSSLCert = NULL;
2497 SeekAccount.Clear();
2498 AccTypeLower.Clear();
2505 void frmMain::ShowSSLInfo( wxCommandEvent &event ){
2507 // Check the account type before continuing.
2511 void frmMain::HideSSLInfo( wxCommandEvent &event ){
2513 // Check the account type before continuing.
2517 void frmMain::UpdateConnectionStatus( wxCommandEvent &event ){
2519 if (event.GetInt() == 0){
2521 imgConnStatus->SetBitmap(*imgOnline);
2525 imgConnStatus->SetBitmap(*imgOffline);
2531 void frmMain::SetupSSLStatus( int AccountID ){
2533 // Check if account ID given is
2534 // the active account and if not, do nothing.
2537 wxString AccTypeLower;
2539 AccType = prefaccounts.GetAccountType(AccountID);
2540 AccTypeLower = AccType.MakeLower();
2542 wxString AccountIDName = prefaccounts.GetAccountDirectory(AccountID) + wxT(".") +
2545 if (AccountIDName != ActiveAccount){
2551 // Check if the account has SSL enabled.
2553 bool SSLInUse = prefaccounts.GetAccountSSL(AccountID);
2555 if (SSLInUse == FALSE){
2557 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2558 imgSSLStatus->SetBitmap(*imgNoSSL);
2562 // Get the SSL Collection Data.
2564 std::map<int,int>::iterator SSLResultIter = AccountSSLResult.find(AccountID);
2566 if (SSLResultIter->second == 1){
2568 imgSSLStatus->SetBitmap(*imgSSLWarning);
2569 SSLToolTip->SetTip(wxT("Invalid certificate(s) received for '") +
2570 prefaccounts.GetAccountName(AccountID) +
2571 wxT("' (Connection denied by user)\n\nDouble click for more information."));
2574 } else if (SSLResultIter->second == 0){
2576 imgSSLStatus->SetBitmap(*imgSSL);
2577 SSLToolTip->SetTip(wxT("Account '") +
2578 prefaccounts.GetAccountName(AccountID) +
2579 wxT("' secured using SSL\n\nDouble click for more information."));
2587 void frmMain::InvalidSSLCertificate( wxCommandEvent &event ){
2589 frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2590 SSLInvalidCertNotifObj *SSLICNObj = (SSLInvalidCertNotifObj*)event.GetClientData();
2591 SSLCertCollection SSLCCData = SSLICNObj->CertCollection;
2592 wxString AccountName = SSLICNObj->AccountName;
2593 frameISC->LoadData(SSLCCData, AccountName);
2594 frameISC->ShowModal();
2596 int FinalConflictResult = frameISC->GetResult();
2598 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2599 event2.SetClientData(SSLICNObj->QRNotifData);
2600 event2.SetInt(FinalConflictResult);
2605 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2606 wxPostEvent(frameActMgr, event2);
2609 void frmMain::PauseAllTimers(){
2611 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2612 ASTiter != AccountSyncTimers.end(); ASTiter++){
2614 ASTiter->second->Stop();
2620 void frmMain::ResumeAllTimers(){
2622 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2623 ASTiter != AccountSyncTimers.end(); ASTiter++){
2625 ASTiter->second->Start();
2631 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollection SSLCertInc){
2633 // Delete existing data.
2635 AccountSSLData.erase(AccountID);
2636 AccountSSLResult.erase(AccountID);
2640 AccountSSLData.insert(std::make_pair(AccountID, SSLCertInc));
2641 AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2645 void frmMain::CheckUpdates( wxCommandEvent& event ){
2647 frmUpdate *frameUpdate = new frmUpdate ( this );
2648 frameUpdate->FetchData();
2649 frameUpdate->ShowModal();
2653 void frmMain::OpenImportDialog( wxCommandEvent& event ){
2655 // Run the import contacts system.
2661 void frmMain::OpenExportDialog( wxCommandEvent& event ){
2663 // Check if an account and at least one contact is selected
2664 // before continuing.
2666 wxArrayString ArrData;
2668 if (ActiveAccount.IsEmpty()){
2674 int ContactSelected = 0;
2675 int ContactsCollected = 0;
2676 long longSelected = -1;
2680 longSelected = lstContacts->GetNextItem(longSelected,
2682 wxLIST_STATE_SELECTED);
2684 if (longSelected == -1){
2690 int FileID = lstContacts->GetItemData(longSelected);
2692 ArrData.Insert(ContactsFileIndex[FileID],
2693 ContactsCollected, 1);
2699 if (ContactSelected == 0){
2705 // Run the export contacts system.
2707 ExportRun(this, &ArrData);
2711 void frmMain::GetListControl(wxListCtrl *lstContactsPtr,
2712 wxArrayString *ContactsFileIndexPtr){
2714 lstContactsPtr = lstContacts;
2715 ContactsFileIndexPtr = &ContactsFileIndex;
2719 void frmMain::GetSelectedList( wxCommandEvent& event ){
2721 // Get the array of contact filenames.
2723 wxArrayString *ArrData = (wxArrayString*)event.GetClientData();
2725 // Process them into an array of files.
2727 long longSelected = -1;
2728 int ContactsCollected = 0;
2729 wxString ContactFilename;
2733 longSelected = lstContacts->GetNextItem(longSelected,
2735 wxLIST_STATE_SELECTED);
2737 if (longSelected == -1){
2743 // Get the file information and add to the list.
2745 int FileID = lstContacts->GetItemData(longSelected);
2747 ArrData->Insert(ContactsFileIndex[FileID],
2748 ContactsCollected, 1);
2750 ContactsCollected++;
2751 ContactFilename.Clear();
2759 void frmMain::SyncAccount( wxCommandEvent& event ){
2761 wxString *AccNameInc = (wxString*)event.GetClientData();
2763 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2764 frameActMgr->AddTask(3, wxT(""), *AccNameInc,
2765 wxT(""), wxT(""), wxT(""), wxT(""));
2769 void frmMain::ShowHelp( wxCommandEvent& event ){
2771 // Based on the operating system, work out where
2772 // the documentation should be.
2776 #if defined(__HAIKU__)
2778 #elif defined(__WIN32__)
2784 if (wxFileExists("/usr/share/doc/xestiaab/index.html")){
2786 wxLaunchDefaultBrowser(wxT("file:///usr/share/doc/xestiaab/index.html"));
2789 #if XSDAB_RELEASE == 0
2791 } else if (wxFileExists("/usr/local/share/doc/xestiaab/index.html")){
2793 wxLaunchDefaultBrowser(wxT("file:///usr/local/share/doc/xestiaab/index.html"));
2802 #if XSDAB_RELEASE == 0
2804 wxMessageBox(_("The help documentation is not available.\n\nYou can view the documentation that came with your source package."), _("Help documentation missing!"));
2808 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!"));