Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Removed references of CardDAV and delete ConnectionObject when finished
[xestiaab/.git] / source / common / timers.cpp
1 // timers.cpp - Timers subroutines.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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/>
19 #include "../actmgr/frmActivityMgr.h"
20 #include "../frmContact.h"
21 #include "../frmMain.h"
22 #include <wx/mstream.h>
23 #include <wx/file.h>
24 #include <wx/ffile.h>
25 #include <wx/filename.h>
26 #include <wx/tokenzr.h>
27 #include "../bitmaps.h"
28 #include "../enums.h"
29 #include "../common/preferences.h"
30 #include "../common/etag.h"
31 #include "../common/dirs.h"
33 void wxActTimer::Notify(){
35         // Notify function for wxActTimer.
37         frmMain *frmMainPtrProc = static_cast<frmMain*>(frmMainPtr);
39         wxCommandEvent shuffleevent(ACTMGR_SHUFFLE);
41         if (intActivityProgress == 0){
43                 wxMemoryInputStream istream(misc_activity1_png, sizeof(misc_activity1_png));
44                 wxImage misc_activity1_pngi(istream, wxBITMAP_TYPE_PNG);
45                 wxBitmap activityiconbmp(misc_activity1_pngi, -1);
46                 bmpActivity->SetBitmap(activityiconbmp);
48                 intActivityProgress++;
50         } else if (intActivityProgress == 1){
52                 wxMemoryInputStream istream(misc_activity2_png, sizeof(misc_activity2_png));
53                 wxImage misc_activity2_pngi(istream, wxBITMAP_TYPE_PNG);
54                 wxBitmap activityiconbmp(misc_activity2_pngi, -1);
55                 bmpActivity->SetBitmap(activityiconbmp);
57                 intActivityProgress++;
59         } else if (intActivityProgress == 2){
61                 wxMemoryInputStream istream(misc_activity3_png, sizeof(misc_activity3_png));
62                 wxImage misc_activity3_pngi(istream, wxBITMAP_TYPE_PNG);
63                 wxBitmap activityiconbmp(misc_activity3_pngi, -1);
64                 bmpActivity->SetBitmap(activityiconbmp);
66                 intActivityProgress++;
68         } else if (intActivityProgress == 3){
70                 wxMemoryInputStream istream(misc_activity4_png, sizeof(misc_activity4_png));
71                 wxImage misc_activity4_pngi(istream, wxBITMAP_TYPE_PNG);
72                 wxBitmap activityiconbmp(misc_activity4_pngi, -1);
73                 bmpActivity->SetBitmap(activityiconbmp);
75                 intActivityProgress++;
77         } else if (intActivityProgress == 4){
79                 wxMemoryInputStream istream(misc_activity5_png, sizeof(misc_activity5_png));
80                 wxImage misc_activity5_pngi(istream, wxBITMAP_TYPE_PNG);
81                 wxBitmap activityiconbmp(misc_activity5_pngi, -1);
82                 bmpActivity->SetBitmap(activityiconbmp);
84                 intActivityProgress++;
86         } else if (intActivityProgress == 5){
88                 wxMemoryInputStream istream(misc_activity6_png, sizeof(misc_activity6_png));
89                 wxImage misc_activity6_pngi(istream, wxBITMAP_TYPE_PNG);
90                 wxBitmap activityiconbmp(misc_activity6_pngi, -1);
91                 bmpActivity->SetBitmap(activityiconbmp);
93                 intActivityProgress++;
95         } else if (intActivityProgress == 6){
97                 wxMemoryInputStream istream(misc_activity7_png, sizeof(misc_activity7_png));
98                 wxImage misc_activity7_pngi(istream, wxBITMAP_TYPE_PNG);
99                 wxBitmap activityiconbmp(misc_activity7_pngi, -1);
100                 bmpActivity->SetBitmap(activityiconbmp);
102                 intActivityProgress++;
104         } else if (intActivityProgress == 7){
106                 wxMemoryInputStream istream(misc_activity8_png, sizeof(misc_activity8_png));
107                 wxImage misc_activity8_pngi(istream, wxBITMAP_TYPE_PNG);
108                 wxBitmap activityiconbmp(misc_activity8_pngi, -1);
109                 bmpActivity->SetBitmap(activityiconbmp);
111                 intActivityProgress++;
113         } else if (intActivityProgress == 8){
115                 wxMemoryInputStream istream(misc_activity9_png, sizeof(misc_activity9_png));
116                 wxImage misc_activity9_pngi(istream, wxBITMAP_TYPE_PNG);
117                 wxBitmap activityiconbmp(misc_activity9_pngi, -1);
118                 bmpActivity->SetBitmap(activityiconbmp);
120                 intActivityProgress++;
122         } else if (intActivityProgress == 9){
124                 wxMemoryInputStream istream(misc_activity10_png, sizeof(misc_activity10_png));
125                 wxImage misc_activity10_pngi(istream, wxBITMAP_TYPE_PNG);
126                 wxBitmap activityiconbmp(misc_activity10_pngi, -1);
127                 bmpActivity->SetBitmap(activityiconbmp);
129                 intActivityProgress++;
131         } else if (intActivityProgress == 10){
133                 wxMemoryInputStream istream(misc_activity11_png, sizeof(misc_activity11_png));
134                 wxImage misc_activity11_pngi(istream, wxBITMAP_TYPE_PNG);
135                 wxBitmap activityiconbmp(misc_activity11_pngi, -1);
136                 bmpActivity->SetBitmap(activityiconbmp);
138                 intActivityProgress++;
140         } else if (intActivityProgress == 11){
142                 wxMemoryInputStream istream(misc_activity12_png, sizeof(misc_activity12_png));
143                 wxImage misc_activity12_pngi(istream, wxBITMAP_TYPE_PNG);
144                 wxBitmap activityiconbmp(misc_activity12_pngi, -1);
145                 bmpActivity->SetBitmap(activityiconbmp);
147                 intActivityProgress = 0;
149         }
151         wxPostEvent(frmMainPtrProc, shuffleevent);
152     
155 void wxActTimer::SetBitmap(wxStaticBitmap *bitmap)
157     
158         // Set the bitmap for wxActTimer.
159     
160         bmpActivity = bitmap;
161     
164 void wxActTimer::SetSleepBitmap(wxBitmap *SleepBitmap)
166     
167         // Set the sleep bitmap for wxActTimer.
168         
169         SleepBitmapPtr = SleepBitmap;
170     
173 void wxActTimer::StopAnimation()
175     
176         // Stop the icon animation.
177     
178         frmMain *frmMainPtrProc = static_cast<frmMain*>(frmMainPtr);
179     
180         wxCommandEvent actstop(ACTMGR_STOP);
181         wxPostEvent(frmMainPtrProc, actstop);
182     
183         this->Stop();
184         bmpActivity->SetBitmap(*SleepBitmapPtr);
185         
188 void wxActTimer::StartAnimation()
190     
191         frmMain *frmMainPtrProc = static_cast<frmMain*>(frmMainPtr);
192         wxCommandEvent actstart(ACTMGR_START);
193         wxPostEvent(frmMainPtrProc, actstart);
194     
195         this->ResetBitmap();
196         this->Start(50, FALSE);
197         
200 void wxActTimer::ResetBitmap()
202     
203         // Reset the bitmap for wxActTimer.
204     
205         intActivityProgress = 0;
206     
209 void wxActTimer::SetupPointer(void *frmMainPtrIn)
211     
212         // Setup the pointer for wxActTimer.
213     
214         frmMainPtr = frmMainPtrIn;
215     
218 void wxActProcessTimer::Notify()
220     
221         // Notify function for wxActProcessTimer.
222     
223         // Pause the timer whilst processing to avoid problems.
224     
225         this->Stop();
226     
227         // Process Tasks.
228     
229         frmActivityMgr *ActMgrPtrProc = static_cast<frmActivityMgr*>(ActMgrPtr);
230         ActMgrPtrProc->ProcessTasks();
231     
234 void wxActProcessTimer::SetupPointers(void *ActMgr){
235     
236         // Setup pointers for the wxActProcessTimer.
237     
238         ActMgrPtr = ActMgr;
239     
242 void wxActListProcTimer::Notify(){
243     
244         // Notify function for wxActListProcTimer.
245     
246         // Setup Label and get task data (update SetupPointers subroutine).
247     
248         this->Stop();
249     
250         for (std::map<int,int>::iterator iter = ActListPtr->begin();
251                 iter != ActListPtr->end(); ++iter){
252         
253                 // Check for any queued tasks and start one.        
254         
255                 // 0 = Queued.
256                 // 1 = Processing.
257                 // 2 = Failed.
258                 // 3 = Stopped.
259                 // 4 = Completed.
260                 // 5 = Failed (UI Updated).
261                 // 6 = Stopped (UI Updated).
262                 // 7 = (Reserved) (UI Updated).
263                 // 8 = Completed. (UI Updated).
264         
265                 std::map<int,long>::iterator LongIter = ActListUIPtr->find(iter->first);
266         
267                 if (iter->second > 4){
268         
269                         continue;
270                 
271                 }
272         
273                 std::map<int,wxString>::iterator DetailIter = ActListDetailPtr->find(iter->first);
274         
275                 wxCommandEvent uevent(ACTMGR_UPDATESTATUSLABEL);
276                 ActivityMgrLabelUpdate *ueventdata = new ActivityMgrLabelUpdate;
277                 uevent.SetClientData(ueventdata);
278         
279                 if (iter->second == 1){
280             
281                         ueventdata->ItemIndex = LongIter->second;
282                         ueventdata->ItemLabel = _("Processing...");         
283             
284                         wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
285             
286                 } else if (iter->second == 2){
287             
288                         ueventdata->ItemIndex = LongIter->second;
289                         ueventdata->ItemLabel = _("Failed");
290             
291                         wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
292                         iter->second = 5;           
294                 } else if (iter->second == 3){
295  
296                         ueventdata->ItemIndex = LongIter->second;
297                         ueventdata->ItemLabel = _("Stopped");
298             
299                         wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
300                         iter->second = 6;
301             
302                 } else if (iter->second == 4){
303             
304                         ueventdata->ItemIndex = LongIter->second;
305                         ueventdata->ItemLabel = _("Completed");
306             
307                         wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
308                         iter->second = 8;
309             
310                 }
311         
312                 // Delete the connection object if finished.
313                 
314                 if (iter->second > 4){
315                 
316                         std::map<int,ConnectionObject*>::iterator ConnObjectIter = ActListConnObjectsPtr->find(iter->first);
317                 
318                         delete ConnObjectIter->second;
319                         ConnObjectIter->second = nullptr;
320                         
321                 }
322                 
323                 // Insert a finish date.
324         
325                 wxDateTime adt;
326                 adt = adt.Now();
327         
328                 ActListFinDTPtr->insert(std::make_pair(iter->first, adt));
330         }
331     
332         if (ClearupProcessed == TRUE){
333         
334                 // Clear up processed items.
335         
336                 // Delete the processed items.
337         
338                 ClearupProcessed = FALSE;
339         
340         }
341     
342         if (*TasksActivePtr == FALSE){
343         
344                 ActTimerPtr->StopAnimation();
345                 lblDetailsPtr->SetLabel(_("No activity."));
346         
347         } else {
348         
349                 this->Start();
350         
351         }
352     
355 void wxActListProcTimer::SetupPointers(std::map<int,int> *ActList, std::map<int,long> *ActListUI,
356                                        std::map<int,wxString> *ActListDetail, bool *TasksActive,
357                                        wxListCtrl *lstActivity, wxStaticText *lblDetails, wxGauge *GauProgress,
358                                        void *ActMgr, wxActTimer *ActTimer, wxActProcessTimer *ActProcessTimer,
359                                        std::map<int,wxDateTime> *ActListFinDT, std::map<int,ConnectionObject*> *ActListConnObjects){
360     
361         // Setup the pointers for wxActListProcTimer.
362     
363         ActListPtr = ActList;
364         ActListUIPtr = ActListUI;
365         ActListDetailPtr = ActListDetail;
366         TasksActivePtr = TasksActive;
367         lstActivityPtr = lstActivity;
368         lblDetailsPtr = lblDetails;
369         GauProgressPtr = GauProgress;
370         ActMgrPtr = ActMgr;
371         ActTimerPtr = ActTimer;
372         ActProcessTimerPtr = ActProcessTimer;
373         ActListFinDTPtr = ActListFinDT;
374         ActListConnObjectsPtr = ActListConnObjects;
375     
378 void wxActListProcTimer::EnableClearup(){
379     
380         // Enable clearup of the wxActListProcTimer.
381     
382         ClearupProcessed = TRUE;
383     
386 void wxETagProcessTimer::Notify(){
387     
388         // Notify function for wxETagProcessTimer.
389     
390         // Check each ETagDB and see if writing to file is required.
391     
392         std::map<wxString,ETagDB>::iterator ETagIter;
393     
394         for (ETagIter = ETagDBList.begin();
395                 ETagIter != ETagDBList.end(); ++ETagIter){
396         
397                 if (ETagIter->second.GetWriteStatus() == TRUE){
398             
399                         ETagIter->second.WriteETagDB();
400             
401                 }
402         
403         }
404     
405     
408 void wxETagProcessTimer::ReloadAccounts(){
409     
410         // Get the account preferences file and setup each database accordingly.
411     
412         ReloadLock.lock();
413     
414         // Stop the timer.
415     
416         this->Stop();
417         ETagDBList.clear();
418     
419         wxString PrefFilename = GetUserPrefDir();
420     
421         XABPreferences PrefData(PrefFilename);
422     
423         wxString AccountName;
424         wxString AccountDir;
425         wxString AccountAddress;
426         wxString AccountUsername;
427         wxString AccountPassword;
428         wxString AccountPrefix;
429         wxString AccountType;
430     
431         // Look for the account and get the friendly name for the account.
432     
433         for (int i = 0; i < PrefData.accounts.GetCount(); i++){
434         
435                 AccountDir = PrefData.accounts.GetAccountDirectory(i);
436                 AccountType = PrefData.accounts.GetAccountType(i);
437                 
438                 if (AccountDir.IsEmpty()){
439                         continue;
440                 }
441         
442                 if (AccountType != wxT("CardDAV") && AccountType != wxT("carddav")){
443                         continue;
444                 }
445         
446                 AccountDir.Trim();
447                 AccountDir.Append(wxT(".carddav"));
448         
449                 ETagDB AccountDB;
450                 AccountDB.SetupDB(AccountDir);
451         
452                 ETagDBList.insert(std::make_pair(AccountDir, AccountDB));
453         
454                 AccountDir.clear();
455         
456         }
457     
458         ReloadLock.unlock();
459         this->Start(15000);
460     
463 ETagDB* wxETagProcessTimer::GetPointer(wxString AccountName){
464     
465         // Get the pointer of the ETag Database.
466     
467         ETagDB *ETagDBPtr = NULL;
468     
469         std::map<wxString,ETagDB>::iterator ETagIter;
470     
471         ETagIter = ETagDBList.find(AccountName);
473         if (ETagIter != ETagDBList.end()){
475                 ETagDBPtr = &ETagIter->second;
477         }
479         return ETagDBPtr;
480     
483 void wxContactFileMonitorTimer::Notify(){
484     
485         // Notify function for wxContactFileMonitorTimer.
486     
487         if (Filename.IsEmpty()){
488         
489                 return;
490         
491         }
492     
493         wxFileName FileCheck(Filename);
494         wxDateTime CurrentDateTime;
495     
496         CurrentDateTime = FileCheck.GetModificationTime();
497     
498         if (FileDateTime != CurrentDateTime){
499         
500                 // The dates & times of the file are different.
501                 // Send an event to notify the user of this change.
502         
503                 wxCommandEvent dateevent(wxEVT_COMMAND_BUTTON_CLICKED);
504                 wxPostEvent(frmCEPtr, dateevent);
505         
506         }
507     
510 void wxContactFileMonitorTimer::SetFilename(wxString FilenameInc){
511     
512         // Set the filename for the wxContactFileMonitorTimer object.
513     
514         Filename = FilenameInc;
515     
516         wxFileName FileCheck(Filename);
517         FileDateTime = FileCheck.GetModificationTime();
518     
521 void wxContactFileMonitorTimer::SetupPointers(frmContactEditor *frmCEPtrInc){
522     
523         // Setup the pointers for the wxContactFileMonitorTimer object.
524     
525         frmCEPtr = frmCEPtrInc;
526     
529 void wxContactFileMonitorTimer::UpdateTimestamp(){
530     
531         // Update the timestamp for the wxContactFileMonitorTimer object.
532     
533         wxFileName FileCheck(Filename);
534         FileDateTime = FileCheck.GetModificationTime();
535     
538 void wxContactWindowMonitor::Notify(){
539     
540         // Notify function for the wxContactWindowMonitor object.
541     
544 void wxContactWindowMonitor::SetupPointers(std::map<wxString, void*> *ContactWindowListPtrInc){
545     
546         // Setup pointers for the wxContactWindowMonitor.
547     
548         ContactWindowListPtr = ContactWindowListPtrInc;
549     
552 void wxAccountSyncTimer::Notify(){
553     
554         // Notify function for the wxAccountSyncTimer.
555     
556         frmActivityMgr *ActMgrPtrProc = static_cast<frmActivityMgr*>(frmActMgrPtr);
557     
558         // Disable the timer. (Don't go updating unless needed).
559     
560         this->Stop();
561     
562         if (ActMgrPtrProc->GetTaskStatus(intTaskID) < 2){
563         
564                 this->Start();
565                 return;
566         
567         }
568     
569         // Add task to the activity manager.
570     
571         intTaskID = ActMgrPtrProc->AddTask(3, wxT(""), AccName, 
572                 wxT(""), wxT(""), wxT(""), wxT(""));
573     
574         // Go to sleep and wait for the task to be completed.
575     
576         // Enable the timer as we are now finished syncronising.
577     
578         this->Start();
579     
582 void wxAccountSyncTimer::SetupData(wxString AccNameInc,
583                                    wxString AccNameFullInc){
584     
585         // Setup the data for the wxAccountSyncTimer object.
586     
587         // Set the account name.
588     
589         AccName = AccNameInc;
590         AccNameFull = AccNameFullInc;
591     
594 void wxAccountSyncTimer::SetupPointers(void *frmMainPtrInc, 
595                                        void *frmActMgrPtrInc, ETagDB *ETagDBPtrInc){
596     
597         // Setup the pointers for the wxAccountSyncTimer object.
598     
599         frmMainPtr = frmMainPtrInc;
600         frmActMgrPtr = frmActMgrPtrInc;
601         ETagDBPtr = ETagDBPtrInc;
602     
605 void SleepFor(unsigned long longSleepNanoSecs){
606     
607         // Sleep for specified nano seconds.
608     
609 #ifdef __WIN32__
610         ::Sleep((longSleepNanoSecs / 1000000));
611 #elif __HAIKU__
612     
613 #else
614     
615         timespec n1, n2;
616     
617         n1.tv_sec = 0;
618         n1.tv_nsec = longSleepNanoSecs;
619     
620         nanosleep(&n1, &n2);
621     
622 #endif
623     
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy