Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Ignore build* directories
[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 "timers.h"
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;
137         }
139         wxPostEvent(frmMainPtrProc, shuffleevent);
140     
143 void wxActTimer::SetBitmap(wxStaticBitmap *bitmap)
145     
146         // Set the bitmap for wxActTimer.
147     
148         bmpActivity = bitmap;
149     
152 void wxActTimer::SetSleepBitmap(wxBitmap *SleepBitmap)
154     
155         // Set the sleep bitmap for wxActTimer.
156         
157         SleepBitmapPtr = SleepBitmap;
158     
161 void wxActTimer::StopAnimation()
163     
164         // Stop the icon animation.
165     
166         frmMain *frmMainPtrProc = static_cast<frmMain*>(frmMainPtr);
167     
168         wxCommandEvent actstop(ACTMGR_STOP);
169         wxPostEvent(frmMainPtrProc, actstop);
170     
171         this->Stop();
172         bmpActivity->SetBitmap(*SleepBitmapPtr);
173         
176 void wxActTimer::StartAnimation()
178     
179         frmMain *frmMainPtrProc = static_cast<frmMain*>(frmMainPtr);
180         wxCommandEvent actstart(ACTMGR_START);
181         wxPostEvent(frmMainPtrProc, actstart);
182     
183         this->ResetBitmap();
184         this->Start(50, FALSE);
185         
188 void wxActTimer::ResetBitmap()
190     
191         // Reset the bitmap for wxActTimer.
192     
193         intActivityProgress = 0;
194     
197 void wxActTimer::SetupPointer(void *frmMainPtrIn)
199     
200         // Setup the pointer for wxActTimer.
201     
202         frmMainPtr = frmMainPtrIn;
203     
206 void wxActProcessTimer::Notify()
208     
209         // Notify function for wxActProcessTimer.
210     
211         // Pause the timer whilst processing to avoid problems.
212     
213         this->Stop();
214     
215         // Process Tasks.
216     
217         frmActivityMgr *ActMgrPtrProc = static_cast<frmActivityMgr*>(ActMgrPtr);
218         ActMgrPtrProc->ProcessTasks();
219     
222 void wxActProcessTimer::SetupPointers(void *ActMgr){
223     
224         // Setup pointers for the wxActProcessTimer.
225     
226         ActMgrPtr = ActMgr;
227     
230 void wxActListProcTimer::Notify(){
231     
232         // Notify function for wxActListProcTimer.
233     
234         // Setup Label and get task data (update SetupPointers subroutine).
235     
236         this->Stop();
237     
238         for (std::map<int,int>::iterator iter = ActListPtr->begin();
239                 iter != ActListPtr->end(); ++iter){
240         
241                 // Check for any queued tasks and start one.        
242         
243                 // 0 = Queued.
244                 // 1 = Processing.
245                 // 2 = Failed.
246                 // 3 = Stopped.
247                 // 4 = Completed.
248                 // 5 = Failed (UI Updated).
249                 // 6 = Stopped (UI Updated).
250                 // 7 = (Reserved) (UI Updated).
251                 // 8 = Completed. (UI Updated).
252         
253                 std::map<int,long>::iterator LongIter = ActListUIPtr->find(iter->first);
254         
255                 if (iter->second > 4){
256         
257                         continue;
258                 
259                 }
260         
261                 std::map<int,wxString>::iterator DetailIter = ActListDetailPtr->find(iter->first);
262         
263                 wxCommandEvent uevent(ACTMGR_UPDATESTATUSLABEL);
264                 ActivityMgrLabelUpdate *ueventdata = new ActivityMgrLabelUpdate;
265                 uevent.SetClientData(ueventdata);
266         
267                 if (iter->second == 1){
268             
269                         ueventdata->ItemIndex = LongIter->second;
270                         ueventdata->ItemLabel = _("Processing...");         
271             
272                         wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
273             
274                 } else if (iter->second == 2){
275             
276                         ueventdata->ItemIndex = LongIter->second;
277                         ueventdata->ItemLabel = _("Failed");
278             
279                         wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
280                         iter->second = 5;           
282                 } else if (iter->second == 3){
283  
284                         ueventdata->ItemIndex = LongIter->second;
285                         ueventdata->ItemLabel = _("Stopped");
286             
287                         wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
288                         iter->second = 6;
289             
290                 } else if (iter->second == 4){
291             
292                         ueventdata->ItemIndex = LongIter->second;
293                         ueventdata->ItemLabel = _("Completed");
294             
295                         wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
296                         iter->second = 8;
297             
298                 }
299         
300                 // Delete the connection object if finished.
301                 
302                 if (iter->second > 4){
303                 
304                         std::map<int,ConnectionObject*>::iterator ConnObjectIter = ActListConnObjectsPtr->find(iter->first);
305                 
306                         delete ConnObjectIter->second;
307                         ConnObjectIter->second = nullptr;
308                         
309                 }
310                 
311                 // Insert a finish date.
312         
313                 wxDateTime adt;
314                 adt = adt.Now();
315         
316                 ActListFinDTPtr->insert(std::make_pair(iter->first, adt));
318         }
319     
320         if (ClearupProcessed == TRUE){
321         
322                 // Clear up processed items.
323         
324                 // Delete the processed items.
325         
326                 ClearupProcessed = FALSE;
327         
328         }
329     
330         if (*TasksActivePtr == FALSE){
331         
332                 ActTimerPtr->StopAnimation();
333                 lblDetailsPtr->SetLabel(_("No activity."));
334         
335         } else {
336         
337                 this->Start();
338         
339         }
340     
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){
348     
349         // Setup the pointers for wxActListProcTimer.
350     
351         ActListPtr = ActList;
352         ActListUIPtr = ActListUI;
353         ActListDetailPtr = ActListDetail;
354         TasksActivePtr = TasksActive;
355         lstActivityPtr = lstActivity;
356         lblDetailsPtr = lblDetails;
357         GauProgressPtr = GauProgress;
358         ActMgrPtr = ActMgr;
359         ActTimerPtr = ActTimer;
360         ActProcessTimerPtr = ActProcessTimer;
361         ActListFinDTPtr = ActListFinDT;
362         ActListConnObjectsPtr = ActListConnObjects;
363     
366 void wxActListProcTimer::EnableClearup(){
367     
368         // Enable clearup of the wxActListProcTimer.
369     
370         ClearupProcessed = TRUE;
371     
374 void wxETagProcessTimer::Notify(){
375     
376         // Notify function for wxETagProcessTimer.
377     
378         // Check each ETagDB and see if writing to file is required.
379     
380         std::map<wxString,ETagDB>::iterator ETagIter;
381     
382         for (ETagIter = ETagDBList.begin();
383                 ETagIter != ETagDBList.end(); ++ETagIter){
384         
385                 if (ETagIter->second.GetWriteStatus() == TRUE){
386             
387                         ETagIter->second.WriteETagDB();
388             
389                 }
390         
391         }
392     
395 void wxETagProcessTimer::ReloadAccounts(){
396     
397         // Get the account preferences file and setup each database accordingly.
398     
399         ReloadLock.lock();
400     
401         // Stop the timer.
402     
403         this->Stop();
404         ETagDBList.clear();
405     
406         wxString PrefFilename = GetUserPrefDir();
407     
408         XABPreferences PrefData(PrefFilename);
409     
410         wxString AccountName;
411         wxString AccountDir;
412         wxString AccountAddress;
413         wxString AccountUsername;
414         wxString AccountPassword;
415         wxString AccountPrefix;
416         wxString AccountType;
417     
418         // Look for the account and get the friendly name for the account.
419     
420         for (int i = 0; i < PrefData.accounts.GetCount(); i++){
421         
422                 AccountDir = PrefData.accounts.GetAccountDirectory(i);
423                 AccountType = PrefData.accounts.GetAccountType(i);
424                 
425                 if (AccountDir.IsEmpty()){
426                         continue;
427                 }
428         
429                 if (AccountType != wxT("CardDAV") && AccountType != wxT("carddav")){
430                         continue;
431                 }
432         
433                 AccountDir.Trim();
434                 AccountDir.Append(wxT(".carddav"));
435         
436                 ETagDB AccountDB;
437                 AccountDB.SetupDB(AccountDir);
438         
439                 ETagDBList.insert(std::make_pair(AccountDir, AccountDB));
440         
441                 AccountDir.clear();
442         
443         }
444     
445         ReloadLock.unlock();
446         this->Start(15000);
447     
450 ETagDB* wxETagProcessTimer::GetPointer(wxString AccountName){
451     
452         // Get the pointer of the ETag Database.
453     
454         ETagDB *ETagDBPtr = NULL;
455     
456         std::map<wxString,ETagDB>::iterator ETagIter;
457     
458         ETagIter = ETagDBList.find(AccountName);
460         if (ETagIter != ETagDBList.end()){
462                 ETagDBPtr = &ETagIter->second;
464         }
466         return ETagDBPtr;
467     
470 void wxContactFileMonitorTimer::Notify(){
471     
472         // Notify function for wxContactFileMonitorTimer.
473     
474         if (Filename.IsEmpty()){
475         
476                 return;
477         
478         }
479     
480         wxFileName FileCheck(Filename);
481         wxDateTime CurrentDateTime;
482     
483         CurrentDateTime = FileCheck.GetModificationTime();
484     
485         if (FileDateTime != CurrentDateTime){
486         
487                 // The dates & times of the file are different.
488                 // Send an event to notify the user of this change.
489         
490                 wxCommandEvent dateevent(wxEVT_COMMAND_BUTTON_CLICKED);
491                 wxPostEvent(frmCEPtr, dateevent);
492         
493         }
494     
497 void wxContactFileMonitorTimer::SetFilename(wxString FilenameInc){
498     
499         // Set the filename for the wxContactFileMonitorTimer object.
500     
501         Filename = FilenameInc;
502     
503         wxFileName FileCheck(Filename);
504         FileDateTime = FileCheck.GetModificationTime();
505     
508 void wxContactFileMonitorTimer::SetupPointers(frmContactEditor *frmCEPtrInc){
509     
510         // Setup the pointers for the wxContactFileMonitorTimer object.
511     
512         frmCEPtr = frmCEPtrInc;
513     
516 void wxContactFileMonitorTimer::UpdateTimestamp(){
517     
518         // Update the timestamp for the wxContactFileMonitorTimer object.
519     
520         wxFileName FileCheck(Filename);
521         FileDateTime = FileCheck.GetModificationTime();
522     
525 void wxContactWindowMonitor::Notify(){
526     
527         // Notify function for the wxContactWindowMonitor object.
528     
531 void wxContactWindowMonitor::SetupPointers(std::map<wxString, void*> *ContactWindowListPtrInc){
532     
533         // Setup pointers for the wxContactWindowMonitor.
534     
535         ContactWindowListPtr = ContactWindowListPtrInc;
536     
539 void wxAccountSyncTimer::Notify(){
540     
541         // Notify function for the wxAccountSyncTimer.
542     
543         frmActivityMgr *ActMgrPtrProc = static_cast<frmActivityMgr*>(frmActMgrPtr);
544     
545         // Disable the timer. (Don't go updating unless needed).
546     
547         this->Stop();
548     
549         if (ActMgrPtrProc->GetTaskStatus(intTaskID) < 2){
550         
551                 this->Start();
552                 return;
553         
554         }
555     
556         // Add task to the activity manager.
557     
558         intTaskID = ActMgrPtrProc->AddTask(3, wxT(""), AccName, 
559                 wxT(""), wxT(""), wxT(""), wxT(""));
560     
561         // Go to sleep and wait for the task to be completed.
562     
563         // Enable the timer as we are now finished syncronising.
564     
565         this->Start();
566     
569 void wxAccountSyncTimer::SetupData(wxString AccNameInc,
570                                    wxString AccNameFullInc){
571     
572         // Setup the data for the wxAccountSyncTimer object.
573     
574         // Set the account name.
575     
576         AccName = AccNameInc;
577         AccNameFull = AccNameFullInc;
578     
581 void wxAccountSyncTimer::SetupPointers(void *frmMainPtrInc, 
582                                        void *frmActMgrPtrInc, ETagDB *ETagDBPtrInc){
583     
584         // Setup the pointers for the wxAccountSyncTimer object.
585     
586         frmMainPtr = frmMainPtrInc;
587         frmActMgrPtr = frmActMgrPtrInc;
588         ETagDBPtr = ETagDBPtrInc;
589     
592 void SleepFor(unsigned long longSleepNanoSecs){
593     
594         // Sleep for specified nano seconds.
595     
596 #ifdef __WIN32__
597         ::Sleep((longSleepNanoSecs / 1000000));
598 #elif __HAIKU__
599     
600 #else
601     
602         timespec n1, n2;
603     
604         n1.tv_sec = 0;
605         n1.tv_nsec = longSleepNanoSecs;
606     
607         nanosleep(&n1, &n2);
608     
609 #endif
610     
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