1 // timers.cpp - Timers subroutines.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
21 void wxActTimer::Notify(){
23 // Notify function for wxActTimer.
25 frmMain *frmMainPtrProc = static_cast<frmMain*>(frmMainPtr);
27 wxCommandEvent shuffleevent(ACTMGR_SHUFFLE);
29 if (intActivityProgress == 0){
31 wxMemoryInputStream istream(misc_activity1_png, sizeof(misc_activity1_png));
32 wxImage misc_activity1_pngi(istream, wxBITMAP_TYPE_PNG);
33 wxBitmap activityiconbmp(misc_activity1_pngi, -1);
34 bmpActivity->SetBitmap(activityiconbmp);
36 intActivityProgress++;
38 } else if (intActivityProgress == 1){
40 wxMemoryInputStream istream(misc_activity2_png, sizeof(misc_activity2_png));
41 wxImage misc_activity2_pngi(istream, wxBITMAP_TYPE_PNG);
42 wxBitmap activityiconbmp(misc_activity2_pngi, -1);
43 bmpActivity->SetBitmap(activityiconbmp);
45 intActivityProgress++;
47 } else if (intActivityProgress == 2){
49 wxMemoryInputStream istream(misc_activity3_png, sizeof(misc_activity3_png));
50 wxImage misc_activity3_pngi(istream, wxBITMAP_TYPE_PNG);
51 wxBitmap activityiconbmp(misc_activity3_pngi, -1);
52 bmpActivity->SetBitmap(activityiconbmp);
54 intActivityProgress++;
56 } else if (intActivityProgress == 3){
58 wxMemoryInputStream istream(misc_activity4_png, sizeof(misc_activity4_png));
59 wxImage misc_activity4_pngi(istream, wxBITMAP_TYPE_PNG);
60 wxBitmap activityiconbmp(misc_activity4_pngi, -1);
61 bmpActivity->SetBitmap(activityiconbmp);
63 intActivityProgress++;
65 } else if (intActivityProgress == 4){
67 wxMemoryInputStream istream(misc_activity5_png, sizeof(misc_activity5_png));
68 wxImage misc_activity5_pngi(istream, wxBITMAP_TYPE_PNG);
69 wxBitmap activityiconbmp(misc_activity5_pngi, -1);
70 bmpActivity->SetBitmap(activityiconbmp);
72 intActivityProgress++;
74 } else if (intActivityProgress == 5){
76 wxMemoryInputStream istream(misc_activity6_png, sizeof(misc_activity6_png));
77 wxImage misc_activity6_pngi(istream, wxBITMAP_TYPE_PNG);
78 wxBitmap activityiconbmp(misc_activity6_pngi, -1);
79 bmpActivity->SetBitmap(activityiconbmp);
81 intActivityProgress++;
83 } else if (intActivityProgress == 6){
85 wxMemoryInputStream istream(misc_activity7_png, sizeof(misc_activity7_png));
86 wxImage misc_activity7_pngi(istream, wxBITMAP_TYPE_PNG);
87 wxBitmap activityiconbmp(misc_activity7_pngi, -1);
88 bmpActivity->SetBitmap(activityiconbmp);
90 intActivityProgress++;
92 } else if (intActivityProgress == 7){
94 wxMemoryInputStream istream(misc_activity8_png, sizeof(misc_activity8_png));
95 wxImage misc_activity8_pngi(istream, wxBITMAP_TYPE_PNG);
96 wxBitmap activityiconbmp(misc_activity8_pngi, -1);
97 bmpActivity->SetBitmap(activityiconbmp);
99 intActivityProgress++;
101 } else if (intActivityProgress == 8){
103 wxMemoryInputStream istream(misc_activity9_png, sizeof(misc_activity9_png));
104 wxImage misc_activity9_pngi(istream, wxBITMAP_TYPE_PNG);
105 wxBitmap activityiconbmp(misc_activity9_pngi, -1);
106 bmpActivity->SetBitmap(activityiconbmp);
108 intActivityProgress++;
110 } else if (intActivityProgress == 9){
112 wxMemoryInputStream istream(misc_activity10_png, sizeof(misc_activity10_png));
113 wxImage misc_activity10_pngi(istream, wxBITMAP_TYPE_PNG);
114 wxBitmap activityiconbmp(misc_activity10_pngi, -1);
115 bmpActivity->SetBitmap(activityiconbmp);
117 intActivityProgress++;
119 } else if (intActivityProgress == 10){
121 wxMemoryInputStream istream(misc_activity11_png, sizeof(misc_activity11_png));
122 wxImage misc_activity11_pngi(istream, wxBITMAP_TYPE_PNG);
123 wxBitmap activityiconbmp(misc_activity11_pngi, -1);
124 bmpActivity->SetBitmap(activityiconbmp);
126 intActivityProgress++;
128 } else if (intActivityProgress == 11){
130 wxMemoryInputStream istream(misc_activity12_png, sizeof(misc_activity12_png));
131 wxImage misc_activity12_pngi(istream, wxBITMAP_TYPE_PNG);
132 wxBitmap activityiconbmp(misc_activity12_pngi, -1);
133 bmpActivity->SetBitmap(activityiconbmp);
135 intActivityProgress = 0;
139 wxPostEvent(frmMainPtrProc, shuffleevent);
143 void wxActTimer::SetBitmap(wxStaticBitmap *bitmap)
146 // Set the bitmap for wxActTimer.
148 bmpActivity = bitmap;
152 void wxActTimer::SetSleepBitmap(wxBitmap *SleepBitmap)
155 // Set the sleep bitmap for wxActTimer.
157 SleepBitmapPtr = SleepBitmap;
161 void wxActTimer::StopAnimation()
164 // Stop the icon animation.
166 frmMain *frmMainPtrProc = static_cast<frmMain*>(frmMainPtr);
168 wxCommandEvent actstop(ACTMGR_STOP);
169 wxPostEvent(frmMainPtrProc, actstop);
172 bmpActivity->SetBitmap(*SleepBitmapPtr);
176 void wxActTimer::StartAnimation()
179 frmMain *frmMainPtrProc = static_cast<frmMain*>(frmMainPtr);
180 wxCommandEvent actstart(ACTMGR_START);
181 wxPostEvent(frmMainPtrProc, actstart);
184 this->Start(50, FALSE);
188 void wxActTimer::ResetBitmap()
191 // Reset the bitmap for wxActTimer.
193 intActivityProgress = 0;
197 void wxActTimer::SetupPointer(void *frmMainPtrIn)
200 // Setup the pointer for wxActTimer.
202 frmMainPtr = frmMainPtrIn;
206 void wxActProcessTimer::Notify()
209 // Notify function for wxActProcessTimer.
211 // Pause the timer whilst processing to avoid problems.
217 frmActivityMgr *ActMgrPtrProc = static_cast<frmActivityMgr*>(ActMgrPtr);
218 ActMgrPtrProc->ProcessTasks();
222 void wxActProcessTimer::SetupPointers(void *ActMgr){
224 // Setup pointers for the wxActProcessTimer.
230 void wxActListProcTimer::Notify(){
232 // Notify function for wxActListProcTimer.
234 // Setup Label and get task data (update SetupPointers subroutine).
238 for (std::map<int,int>::iterator iter = ActListPtr->begin();
239 iter != ActListPtr->end(); ++iter){
241 // Check for any queued tasks and start one.
248 // 5 = Failed (UI Updated).
249 // 6 = Stopped (UI Updated).
250 // 7 = (Reserved) (UI Updated).
251 // 8 = Completed. (UI Updated).
253 std::map<int,long>::iterator LongIter = ActListUIPtr->find(iter->first);
255 if (iter->second > 4){
261 std::map<int,wxString>::iterator DetailIter = ActListDetailPtr->find(iter->first);
263 wxCommandEvent uevent(ACTMGR_UPDATESTATUSLABEL);
264 ActivityMgrLabelUpdate *ueventdata = new ActivityMgrLabelUpdate;
265 uevent.SetClientData(ueventdata);
267 if (iter->second == 1){
269 ueventdata->ItemIndex = LongIter->second;
270 ueventdata->ItemLabel = _("Processing...");
272 wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
274 } else if (iter->second == 2){
276 ueventdata->ItemIndex = LongIter->second;
277 ueventdata->ItemLabel = _("Failed");
279 wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
282 } else if (iter->second == 3){
284 ueventdata->ItemIndex = LongIter->second;
285 ueventdata->ItemLabel = _("Stopped");
287 wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
290 } else if (iter->second == 4){
292 ueventdata->ItemIndex = LongIter->second;
293 ueventdata->ItemLabel = _("Completed");
295 wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
300 // Delete the connection object if finished.
302 if (iter->second > 4){
304 std::map<int,ConnectionObject*>::iterator ConnObjectIter = ActListConnObjectsPtr->find(iter->first);
306 delete ConnObjectIter->second;
307 ConnObjectIter->second = nullptr;
311 // Insert a finish date.
316 ActListFinDTPtr->insert(std::make_pair(iter->first, adt));
320 if (ClearupProcessed == TRUE){
322 // Clear up processed items.
324 // Delete the processed items.
326 ClearupProcessed = FALSE;
330 if (*TasksActivePtr == FALSE){
332 ActTimerPtr->StopAnimation();
333 lblDetailsPtr->SetLabel(_("No activity."));
343 void wxActListProcTimer::SetupPointers(std::map<int,int> *ActList, std::map<int,long> *ActListUI,
344 std::map<int,wxString> *ActListDetail, bool *TasksActive,
345 wxListCtrl *lstActivity, wxStaticText *lblDetails, wxGauge *GauProgress,
346 void *ActMgr, wxActTimer *ActTimer, wxActProcessTimer *ActProcessTimer,
347 std::map<int,wxDateTime> *ActListFinDT, std::map<int,ConnectionObject*> *ActListConnObjects){
349 // Setup the pointers for wxActListProcTimer.
351 ActListPtr = ActList;
352 ActListUIPtr = ActListUI;
353 ActListDetailPtr = ActListDetail;
354 TasksActivePtr = TasksActive;
355 lstActivityPtr = lstActivity;
356 lblDetailsPtr = lblDetails;
357 GauProgressPtr = GauProgress;
359 ActTimerPtr = ActTimer;
360 ActProcessTimerPtr = ActProcessTimer;
361 ActListFinDTPtr = ActListFinDT;
362 ActListConnObjectsPtr = ActListConnObjects;
366 void wxActListProcTimer::EnableClearup(){
368 // Enable clearup of the wxActListProcTimer.
370 ClearupProcessed = TRUE;
374 void wxETagProcessTimer::Notify(){
376 // Notify function for wxETagProcessTimer.
378 // Check each ETagDB and see if writing to file is required.
380 std::map<wxString,ETagDB>::iterator ETagIter;
382 for (ETagIter = ETagDBList.begin();
383 ETagIter != ETagDBList.end(); ++ETagIter){
385 if (ETagIter->second.GetWriteStatus() == TRUE){
387 ETagIter->second.WriteETagDB();
396 void wxETagProcessTimer::ReloadAccounts(){
398 // Get the account preferences file and setup each database accordingly.
407 wxString PrefFilename = GetUserPrefDir();
409 XABPreferences PrefData(PrefFilename);
411 wxString AccountName;
413 wxString AccountAddress;
414 wxString AccountUsername;
415 wxString AccountPassword;
416 wxString AccountPrefix;
417 wxString AccountType;
419 // Look for the account and get the friendly name for the account.
421 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
423 AccountDir = PrefData.accounts.GetAccountDirectory(i);
424 AccountType = PrefData.accounts.GetAccountType(i);
426 if (AccountDir.IsEmpty()){
430 if (AccountType != wxT("CardDAV") && AccountType != wxT("carddav")){
435 AccountDir.Append(wxT(".carddav"));
438 AccountDB.SetupDB(AccountDir);
440 ETagDBList.insert(std::make_pair(AccountDir, AccountDB));
451 ETagDB* wxETagProcessTimer::GetPointer(wxString AccountName){
453 // Get the pointer of the ETag Database.
455 ETagDB *ETagDBPtr = NULL;
457 std::map<wxString,ETagDB>::iterator ETagIter;
459 ETagIter = ETagDBList.find(AccountName);
461 if (ETagIter != ETagDBList.end()){
463 ETagDBPtr = &ETagIter->second;
471 void wxContactFileMonitorTimer::Notify(){
473 // Notify function for wxContactFileMonitorTimer.
475 if (Filename.IsEmpty()){
481 wxFileName FileCheck(Filename);
482 wxDateTime CurrentDateTime;
484 CurrentDateTime = FileCheck.GetModificationTime();
486 if (FileDateTime != CurrentDateTime){
488 // The dates & times of the file are different.
489 // Send an event to notify the user of this change.
491 wxCommandEvent dateevent(wxEVT_COMMAND_BUTTON_CLICKED);
492 wxPostEvent(frmCEPtr, dateevent);
498 void wxContactFileMonitorTimer::SetFilename(wxString FilenameInc){
500 // Set the filename for the wxContactFileMonitorTimer object.
502 Filename = FilenameInc;
504 wxFileName FileCheck(Filename);
505 FileDateTime = FileCheck.GetModificationTime();
509 void wxContactFileMonitorTimer::SetupPointers(frmContactEditor *frmCEPtrInc){
511 // Setup the pointers for the wxContactFileMonitorTimer object.
513 frmCEPtr = frmCEPtrInc;
517 void wxContactFileMonitorTimer::UpdateTimestamp(){
519 // Update the timestamp for the wxContactFileMonitorTimer object.
521 wxFileName FileCheck(Filename);
522 FileDateTime = FileCheck.GetModificationTime();
526 void wxContactWindowMonitor::Notify(){
528 // Notify function for the wxContactWindowMonitor object.
532 void wxContactWindowMonitor::SetupPointers(std::map<wxString, void*> *ContactWindowListPtrInc){
534 // Setup pointers for the wxContactWindowMonitor.
536 ContactWindowListPtr = ContactWindowListPtrInc;
540 void wxAccountSyncTimer::Notify(){
542 // Notify function for the wxAccountSyncTimer.
544 frmActivityMgr *ActMgrPtrProc = static_cast<frmActivityMgr*>(frmActMgrPtr);
546 // Disable the timer. (Don't go updating unless needed).
550 if (ActMgrPtrProc->GetTaskStatus(intTaskID) < 2){
557 // Add task to the activity manager.
559 intTaskID = ActMgrPtrProc->AddTask(3, wxT(""), AccName,
560 wxT(""), wxT(""), wxT(""), wxT(""));
562 // Go to sleep and wait for the task to be completed.
564 // Enable the timer as we are now finished syncronising.
570 void wxAccountSyncTimer::SetupData(wxString AccNameInc,
571 wxString AccNameFullInc){
573 // Setup the data for the wxAccountSyncTimer object.
575 // Set the account name.
577 AccName = AccNameInc;
578 AccNameFull = AccNameFullInc;
582 void wxAccountSyncTimer::SetupPointers(void *frmMainPtrInc,
583 void *frmActMgrPtrInc, ETagDB *ETagDBPtrInc){
585 // Setup the pointers for the wxAccountSyncTimer object.
587 frmMainPtr = frmMainPtrInc;
588 frmActMgrPtr = frmActMgrPtrInc;
589 ETagDBPtr = ETagDBPtrInc;
593 void SleepFor(unsigned long longSleepNanoSecs){
595 // Sleep for specified nano seconds.
598 ::Sleep((longSleepNanoSecs / 1000000));
606 n1.tv_nsec = longSleepNanoSecs;