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();
395 void wxETagProcessTimer::ReloadAccounts(){
397 // Get the account preferences file and setup each database accordingly.
406 wxString PrefFilename = GetUserPrefDir();
408 XABPreferences PrefData(PrefFilename);
410 wxString AccountName;
412 wxString AccountAddress;
413 wxString AccountUsername;
414 wxString AccountPassword;
415 wxString AccountPrefix;
416 wxString AccountType;
418 // Look for the account and get the friendly name for the account.
420 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
422 AccountDir = PrefData.accounts.GetAccountDirectory(i);
423 AccountType = PrefData.accounts.GetAccountType(i);
425 if (AccountDir.IsEmpty()){
429 if (AccountType != wxT("CardDAV") && AccountType != wxT("carddav")){
434 AccountDir.Append(wxT(".carddav"));
437 AccountDB.SetupDB(AccountDir);
439 ETagDBList.insert(std::make_pair(AccountDir, AccountDB));
450 ETagDB* wxETagProcessTimer::GetPointer(wxString AccountName){
452 // Get the pointer of the ETag Database.
454 ETagDB *ETagDBPtr = NULL;
456 std::map<wxString,ETagDB>::iterator ETagIter;
458 ETagIter = ETagDBList.find(AccountName);
460 if (ETagIter != ETagDBList.end()){
462 ETagDBPtr = &ETagIter->second;
470 void wxContactFileMonitorTimer::Notify(){
472 // Notify function for wxContactFileMonitorTimer.
474 if (Filename.IsEmpty()){
480 wxFileName FileCheck(Filename);
481 wxDateTime CurrentDateTime;
483 CurrentDateTime = FileCheck.GetModificationTime();
485 if (FileDateTime != CurrentDateTime){
487 // The dates & times of the file are different.
488 // Send an event to notify the user of this change.
490 wxCommandEvent dateevent(wxEVT_COMMAND_BUTTON_CLICKED);
491 wxPostEvent(frmCEPtr, dateevent);
497 void wxContactFileMonitorTimer::SetFilename(wxString FilenameInc){
499 // Set the filename for the wxContactFileMonitorTimer object.
501 Filename = FilenameInc;
503 wxFileName FileCheck(Filename);
504 FileDateTime = FileCheck.GetModificationTime();
508 void wxContactFileMonitorTimer::SetupPointers(frmContactEditor *frmCEPtrInc){
510 // Setup the pointers for the wxContactFileMonitorTimer object.
512 frmCEPtr = frmCEPtrInc;
516 void wxContactFileMonitorTimer::UpdateTimestamp(){
518 // Update the timestamp for the wxContactFileMonitorTimer object.
520 wxFileName FileCheck(Filename);
521 FileDateTime = FileCheck.GetModificationTime();
525 void wxContactWindowMonitor::Notify(){
527 // Notify function for the wxContactWindowMonitor object.
531 void wxContactWindowMonitor::SetupPointers(std::map<wxString, void*> *ContactWindowListPtrInc){
533 // Setup pointers for the wxContactWindowMonitor.
535 ContactWindowListPtr = ContactWindowListPtrInc;
539 void wxAccountSyncTimer::Notify(){
541 // Notify function for the wxAccountSyncTimer.
543 frmActivityMgr *ActMgrPtrProc = static_cast<frmActivityMgr*>(frmActMgrPtr);
545 // Disable the timer. (Don't go updating unless needed).
549 if (ActMgrPtrProc->GetTaskStatus(intTaskID) < 2){
556 // Add task to the activity manager.
558 intTaskID = ActMgrPtrProc->AddTask(3, wxT(""), AccName,
559 wxT(""), wxT(""), wxT(""), wxT(""));
561 // Go to sleep and wait for the task to be completed.
563 // Enable the timer as we are now finished syncronising.
569 void wxAccountSyncTimer::SetupData(wxString AccNameInc,
570 wxString AccNameFullInc){
572 // Setup the data for the wxAccountSyncTimer object.
574 // Set the account name.
576 AccName = AccNameInc;
577 AccNameFull = AccNameFullInc;
581 void wxAccountSyncTimer::SetupPointers(void *frmMainPtrInc,
582 void *frmActMgrPtrInc, ETagDB *ETagDBPtrInc){
584 // Setup the pointers for the wxAccountSyncTimer object.
586 frmMainPtr = frmMainPtrInc;
587 frmActMgrPtr = frmActMgrPtrInc;
588 ETagDBPtr = ETagDBPtrInc;
592 void SleepFor(unsigned long longSleepNanoSecs){
594 // Sleep for specified nano seconds.
597 ::Sleep((longSleepNanoSecs / 1000000));
605 n1.tv_nsec = longSleepNanoSecs;