1 #include "../frmActivityMgr.h"
2 #include "../frmContact.h"
3 #include "../frmMain.h"
4 #include <wx/mstream.h>
7 #include <wx/filename.h>
8 #include <wx/tokenzr.h>
9 #include "../bitmaps.h"
11 #include "../common/preferences.h"
12 #include "../common/etag.h"
13 #include "../common/dirs.h"
15 void wxActTimer::Notify(){
17 frmMain *frmMainPtrProc = static_cast<frmMain*>(frmMainPtr);
19 wxCommandEvent shuffleevent(ACTMGR_SHUFFLE);
21 if (intActivityProgress == 0){
23 wxMemoryInputStream istream(misc_activity1_png, sizeof(misc_activity1_png));
24 wxImage misc_activity1_pngi(istream, wxBITMAP_TYPE_PNG);
25 wxBitmap activityiconbmp(misc_activity1_pngi, -1);
26 bmpActivity->SetBitmap(activityiconbmp);
28 intActivityProgress++;
30 } else if (intActivityProgress == 1){
32 wxMemoryInputStream istream(misc_activity2_png, sizeof(misc_activity2_png));
33 wxImage misc_activity2_pngi(istream, wxBITMAP_TYPE_PNG);
34 wxBitmap activityiconbmp(misc_activity2_pngi, -1);
35 bmpActivity->SetBitmap(activityiconbmp);
37 intActivityProgress++;
39 } else if (intActivityProgress == 2){
41 wxMemoryInputStream istream(misc_activity3_png, sizeof(misc_activity3_png));
42 wxImage misc_activity3_pngi(istream, wxBITMAP_TYPE_PNG);
43 wxBitmap activityiconbmp(misc_activity3_pngi, -1);
44 bmpActivity->SetBitmap(activityiconbmp);
46 intActivityProgress++;
48 } else if (intActivityProgress == 3){
50 wxMemoryInputStream istream(misc_activity4_png, sizeof(misc_activity4_png));
51 wxImage misc_activity4_pngi(istream, wxBITMAP_TYPE_PNG);
52 wxBitmap activityiconbmp(misc_activity4_pngi, -1);
53 bmpActivity->SetBitmap(activityiconbmp);
55 intActivityProgress++;
57 } else if (intActivityProgress == 4){
59 wxMemoryInputStream istream(misc_activity5_png, sizeof(misc_activity5_png));
60 wxImage misc_activity5_pngi(istream, wxBITMAP_TYPE_PNG);
61 wxBitmap activityiconbmp(misc_activity5_pngi, -1);
62 bmpActivity->SetBitmap(activityiconbmp);
64 intActivityProgress++;
66 } else if (intActivityProgress == 5){
68 wxMemoryInputStream istream(misc_activity6_png, sizeof(misc_activity6_png));
69 wxImage misc_activity6_pngi(istream, wxBITMAP_TYPE_PNG);
70 wxBitmap activityiconbmp(misc_activity6_pngi, -1);
71 bmpActivity->SetBitmap(activityiconbmp);
73 intActivityProgress++;
75 } else if (intActivityProgress == 6){
77 wxMemoryInputStream istream(misc_activity7_png, sizeof(misc_activity7_png));
78 wxImage misc_activity7_pngi(istream, wxBITMAP_TYPE_PNG);
79 wxBitmap activityiconbmp(misc_activity7_pngi, -1);
80 bmpActivity->SetBitmap(activityiconbmp);
82 intActivityProgress++;
84 } else if (intActivityProgress == 7){
86 wxMemoryInputStream istream(misc_activity8_png, sizeof(misc_activity8_png));
87 wxImage misc_activity8_pngi(istream, wxBITMAP_TYPE_PNG);
88 wxBitmap activityiconbmp(misc_activity8_pngi, -1);
89 bmpActivity->SetBitmap(activityiconbmp);
91 intActivityProgress++;
93 } else if (intActivityProgress == 8){
95 wxMemoryInputStream istream(misc_activity9_png, sizeof(misc_activity9_png));
96 wxImage misc_activity9_pngi(istream, wxBITMAP_TYPE_PNG);
97 wxBitmap activityiconbmp(misc_activity9_pngi, -1);
98 bmpActivity->SetBitmap(activityiconbmp);
100 intActivityProgress++;
102 } else if (intActivityProgress == 9){
104 wxMemoryInputStream istream(misc_activity10_png, sizeof(misc_activity10_png));
105 wxImage misc_activity10_pngi(istream, wxBITMAP_TYPE_PNG);
106 wxBitmap activityiconbmp(misc_activity10_pngi, -1);
107 bmpActivity->SetBitmap(activityiconbmp);
109 intActivityProgress++;
111 } else if (intActivityProgress == 10){
113 wxMemoryInputStream istream(misc_activity11_png, sizeof(misc_activity11_png));
114 wxImage misc_activity11_pngi(istream, wxBITMAP_TYPE_PNG);
115 wxBitmap activityiconbmp(misc_activity11_pngi, -1);
116 bmpActivity->SetBitmap(activityiconbmp);
118 intActivityProgress++;
120 } else if (intActivityProgress == 11){
122 wxMemoryInputStream istream(misc_activity12_png, sizeof(misc_activity12_png));
123 wxImage misc_activity12_pngi(istream, wxBITMAP_TYPE_PNG);
124 wxBitmap activityiconbmp(misc_activity12_pngi, -1);
125 bmpActivity->SetBitmap(activityiconbmp);
127 intActivityProgress = 0;
131 wxPostEvent(frmMainPtrProc, shuffleevent);
135 void wxActTimer::SetBitmap(wxStaticBitmap *bitmap)
138 bmpActivity = bitmap;
142 void wxActTimer::SetSleepBitmap(wxBitmap *SleepBitmap)
145 SleepBitmapPtr = SleepBitmap;
149 void wxActTimer::StopAnimation()
152 // Stop the icon animation.
154 frmMain *frmMainPtrProc = static_cast<frmMain*>(frmMainPtr);
156 wxCommandEvent actstop(ACTMGR_STOP);
157 wxPostEvent(frmMainPtrProc, actstop);
158 //frmMainPtrProc->ActivityIconStop();
161 bmpActivity->SetBitmap(*SleepBitmapPtr);
164 void wxActTimer::StartAnimation()
167 frmMain *frmMainPtrProc = static_cast<frmMain*>(frmMainPtr);
168 wxCommandEvent actstart(ACTMGR_START);
169 wxPostEvent(frmMainPtrProc, actstart);
170 //frmMainPtrProc->ActivityIconStart();
173 this->Start(50, FALSE);
176 void wxActTimer::ResetBitmap()
179 intActivityProgress = 0;
183 void wxActTimer::SetupPointer(void *frmMainPtrIn)
186 frmMainPtr = frmMainPtrIn;
190 void wxActProcessTimer::Notify()
193 // Pause the timer whilst processing to avoid problems.
199 frmActivityMgr *ActMgrPtrProc = static_cast<frmActivityMgr*>(ActMgrPtr);
200 ActMgrPtrProc->ProcessTasks();
204 void wxActProcessTimer::SetupPointers(void *ActMgr){
210 void wxActListProcTimer::Notify(){
212 // Setup Label and get task data (update SetupPointers subroutine).
216 for (std::map<int,int>::iterator iter = ActListPtr->begin();
217 iter != ActListPtr->end(); ++iter){
219 // Check for any queued tasks and start one.
226 // 5 = Failed (UI Updated).
227 // 6 = Stopped (UI Updated).
228 // 7 = (Reserved) (UI Updated).
229 // 8 = Completed. (UI Updated).
231 std::map<int,long>::iterator LongIter = ActListUIPtr->find(iter->first);
233 if (iter->second > 4){
238 std::map<int,wxString>::iterator DetailIter = ActListDetailPtr->find(iter->first);
240 wxCommandEvent uevent(ACTMGR_UPDATESTATUSLABEL);
241 ActivityMgrLabelUpdate *ueventdata = new ActivityMgrLabelUpdate;
242 uevent.SetClientData(ueventdata);
244 if (iter->second == 1){
246 ueventdata->ItemIndex = LongIter->second;
247 ueventdata->ItemLabel = _("Processing...");
248 ueventdata->ItemDes = _("Adding Contact '") + DetailIter->second + _("'...");
250 wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
252 /*lstActivityPtr->SetItem(LongIter->second, 2, _("Processing..."));
253 if (ActListDetailPtr->find(iter->first) != ActListDetailPtr->end()){
254 lblDetailsPtr->SetLabel(_("Adding Contact '") + DetailIter->second + _("'..."));
257 } else if (iter->second == 2){
259 ueventdata->ItemIndex = LongIter->second;
260 ueventdata->ItemLabel = _("Failed");
262 wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
265 //lstActivityPtr->SetItem(LongIter->second, 2, _("Failed"));
267 } else if (iter->second == 3){
269 ueventdata->ItemIndex = LongIter->second;
270 ueventdata->ItemLabel = _("Stopped");
272 wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
275 //lstActivityPtr->SetItem(LongIter->second, 2, _("Stopped"));
278 } else if (iter->second == 4){
280 ueventdata->ItemIndex = LongIter->second;
281 ueventdata->ItemLabel = _("Completed");
283 wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
286 //lstActivityPtr->SetItem(LongIter->second, 2, _("Completed"));
291 // Insert a finish date.
296 ActListFinDTPtr->insert(std::make_pair(iter->first, adt));
300 if (ClearupProcessed == TRUE){
302 // Clear up processed items.
304 // Delete the processed items.
306 ClearupProcessed = FALSE;
310 if (*TasksActivePtr == FALSE){
312 ActTimerPtr->StopAnimation();
313 lblDetailsPtr->SetLabel(_("No activity."));
323 void wxActListProcTimer::SetupPointers(std::map<int,int> *ActList, std::map<int,long> *ActListUI,
324 std::map<int,wxString> *ActListDetail, bool *TasksActive,
325 wxListCtrl *lstActivity, wxStaticText *lblDetails, wxGauge *GauProgress,
326 void *ActMgr, wxActTimer *ActTimer, wxActProcessTimer *ActProcessTimer,
327 std::map<int,wxDateTime> *ActListFinDT){
329 ActListPtr = ActList;
330 ActListUIPtr = ActListUI;
331 ActListDetailPtr = ActListDetail;
332 TasksActivePtr = TasksActive;
333 lstActivityPtr = lstActivity;
334 lblDetailsPtr = lblDetails;
335 GauProgressPtr = GauProgress;
337 ActTimerPtr = ActTimer;
338 ActProcessTimerPtr = ActProcessTimer;
339 ActListFinDTPtr = ActListFinDT;
343 void wxActListProcTimer::EnableClearup(){
345 ClearupProcessed = TRUE;
349 void wxETagProcessTimer::Notify(){
351 // Check each ETagDB and see if writing to file is required.
356 std::map<wxString,ETagDB>::iterator ETagIter;
358 for (ETagIter = ETagDBList.begin();
359 ETagIter != ETagDBList.end(); ++ETagIter){
361 if (ETagIter->second.GetWriteStatus() == TRUE){
363 ETagIter->second.WriteETagDB();
372 void wxETagProcessTimer::ReloadAccounts(){
374 // Get the account preferences file and setup each database accordingly.
383 wxString PrefFilename = GetUserPrefDir();
385 XABPreferences PrefData(PrefFilename);
387 wxString AccountName;
389 wxString AccountAddress;
390 wxString AccountUsername;
391 wxString AccountPassword;
392 wxString AccountPrefix;
393 wxString AccountType;
395 // Look for the account and get the friendly name for the account.
397 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
399 AccountDir = PrefData.accounts.GetAccountDirectory(i);
400 AccountType = PrefData.accounts.GetAccountType(i);
402 if (AccountDir.IsEmpty()){
406 if (AccountType == wxT("Local") || AccountType == wxT("local")){
411 AccountDir.Append(wxT(".carddav"));
414 AccountDB.SetupDB(AccountDir);
416 ETagDBList.insert(std::make_pair(AccountDir, AccountDB));
424 /*for (int i = 0; i < PrefData.accounts.GetCount(); i++){
426 AccountDir = PrefData.accounts.GetAccountDirectory(i);
429 AccountDir.Append(wxT(".carddav"));
431 //AccountPrefix = PrefData.accounts.GetAccountDirPrefix(i);
433 //ETagDB NewETagDB (AccountDir);
436 AccountDB.SetupDB(AccountDir);
438 //ETagDBList.insert(std::make_pair(AccountDir, Moo));
440 //std::pair<wxString,ETagDB> Moo2;
444 //ETagDBListv3.insert(std::make_pair(0,Meep));
446 //ETagDBListv2.insert(std::make_pair(0, Moo));
448 //ETagDBList.insert(Moo2);
450 ETagDBList.insert(std::make_pair(AccountDir, AccountDB));
452 //Moo55.insert(std::make_pair(wxT("Meep"), wxT("Meep")));
454 //ETagDBList[AccountDir] = new ETagDB (AccountDir);
458 //ETagDB Test (AccountDir);
460 //ETagDBList.insert(std::make_pair(AccountDir, Test));
467 ETagDB* wxETagProcessTimer::GetPointer(wxString AccountName){
469 ETagDB *ETagDBPtr = NULL;
471 std::map<wxString,ETagDB>::iterator ETagIter;
473 ETagIter = ETagDBList.find(AccountName);
475 if (ETagIter != ETagDBList.end()){
477 ETagDBPtr = &ETagIter->second;
485 void wxContactFileMonitorTimer::Notify(){
487 if (Filename.IsEmpty()){
493 wxFileName FileCheck(Filename);
494 wxDateTime CurrentDateTime;
496 CurrentDateTime = FileCheck.GetModificationTime();
498 if (FileDateTime != CurrentDateTime){
500 // The dates & times of the file are different.
501 // Send an event to notify the user of this change.
503 wxCommandEvent dateevent(wxEVT_COMMAND_BUTTON_CLICKED);
504 wxPostEvent(frmCEPtr, dateevent);
510 void wxContactFileMonitorTimer::SetFilename(wxString FilenameInc){
512 Filename = FilenameInc;
514 wxFileName FileCheck(Filename);
515 FileDateTime = FileCheck.GetModificationTime();
519 void wxContactFileMonitorTimer::SetupPointers(frmContactEditor *frmCEPtrInc){
521 frmCEPtr = frmCEPtrInc;
525 void wxContactFileMonitorTimer::UpdateTimestamp(){
527 wxFileName FileCheck(Filename);
528 FileDateTime = FileCheck.GetModificationTime();
532 void wxContactWindowMonitor::Notify(){
534 // Look through the list of windows and see if any have
535 // closed. IF they have closed then delete and free the
536 // memory (also delete from the map).
538 /*for(std::map<wxString, void*>::iterator iter = ContactWindowListPtr->begin();
539 iter != ContactWindowListPtr->end(); iter++){
541 frmContact *ContactPtr = (frmContact*)iter->second;
549 // Delete the data from the map.
555 void wxContactWindowMonitor::SetupPointers(std::map<wxString, void*> *ContactWindowListPtrInc){
557 ContactWindowListPtr = ContactWindowListPtrInc;
561 void wxAccountSyncTimer::Notify(){
563 frmActivityMgr *ActMgrPtrProc = static_cast<frmActivityMgr*>(frmActMgrPtr);
565 // Disable the timer. (Don't go updating unless needed).
569 if (ActMgrPtrProc->GetTaskStatus(intTaskID) < 2){
576 // Add task to the activity manager.
578 intTaskID = ActMgrPtrProc->AddTask(3, wxT(""), AccName,
579 wxT(""), wxT(""), wxT(""), wxT(""));
581 // Go to sleep and wait for the task to be completed.
583 // Enable the timer as we are now finished syncronising.
589 void wxAccountSyncTimer::SetupData(wxString AccNameInc,
590 wxString AccNameFullInc){
592 // Set the account name.
594 AccName = AccNameInc;
595 AccNameFull = AccNameFullInc;
599 void wxAccountSyncTimer::SetupPointers(void *frmMainPtrInc,
600 void *frmActMgrPtrInc, ETagDB *ETagDBPtrInc){
604 frmMainPtr = frmMainPtrInc;
605 frmActMgrPtr = frmActMgrPtrInc;
606 ETagDBPtr = ETagDBPtrInc;
610 void SleepFor(unsigned long longSleepNanoSecs){
613 ::Sleep((longSleepNanoSecs / 1000000));
621 n1.tv_nsec = longSleepNanoSecs;