Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
abe6f5eeb32543c7c8ac3e63b60c8c188003d763
[xestiaab/.git] / source / common / timers.cpp
1 #include "../frmActivityMgr.h"
2 #include "../frmContact.h"
3 #include "../frmMain.h"
4 #include <wx/mstream.h>
5 #include <wx/file.h>
6 #include <wx/ffile.h>
7 #include <wx/filename.h>
8 #include <wx/tokenzr.h>
9 #include "../bitmaps.h"
10 #include "../enums.h"
11 #include "../common/preferences.h"
12 #include "../common/etag.h"
13 #include "../common/dirs.h"
15 void wxActTimer::Notify(){
16     
17     frmMain *frmMainPtrProc = static_cast<frmMain*>(frmMainPtr);
18     
19     wxCommandEvent shuffleevent(ACTMGR_SHUFFLE);
20     
21     if (intActivityProgress == 0){
22         
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);
27         
28         intActivityProgress++;
29         
30     } else if (intActivityProgress == 1){
31         
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);
36         
37         intActivityProgress++;
38         
39     } else if (intActivityProgress == 2){
40         
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);
45         
46         intActivityProgress++;
47         
48     } else if (intActivityProgress == 3){
49         
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);
54         
55         intActivityProgress++;
56         
57     } else if (intActivityProgress == 4){
58         
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);
63         
64         intActivityProgress++;
65         
66     } else if (intActivityProgress == 5){
67         
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);
72         
73         intActivityProgress++;
74         
75     } else if (intActivityProgress == 6){
76         
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);
81         
82         intActivityProgress++;
83         
84     } else if (intActivityProgress == 7){
85         
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);
90         
91         intActivityProgress++;
92         
93     } else if (intActivityProgress == 8){
94         
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);
99         
100         intActivityProgress++;
101         
102     } else if (intActivityProgress == 9){
103         
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);
108         
109         intActivityProgress++;
110         
111     } else if (intActivityProgress == 10){
112         
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);
117         
118         intActivityProgress++;
119         
120     } else if (intActivityProgress == 11){
121         
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);
126         
127         intActivityProgress = 0;
128         
129     }
130     
131     wxPostEvent(frmMainPtrProc, shuffleevent);
132     
135 void wxActTimer::SetBitmap(wxStaticBitmap *bitmap)
137     
138     bmpActivity = bitmap;
139     
142 void wxActTimer::SetSleepBitmap(wxBitmap *SleepBitmap)
144     
145     SleepBitmapPtr = SleepBitmap;
146     
149 void wxActTimer::StopAnimation()
151     
152     // Stop the icon animation.
153     
154     frmMain *frmMainPtrProc = static_cast<frmMain*>(frmMainPtr);
155     
156     wxCommandEvent actstop(ACTMGR_STOP);
157     wxPostEvent(frmMainPtrProc, actstop);
158     //frmMainPtrProc->ActivityIconStop();
159     
160     this->Stop();
161     bmpActivity->SetBitmap(*SleepBitmapPtr);
164 void wxActTimer::StartAnimation()
166     
167     frmMain *frmMainPtrProc = static_cast<frmMain*>(frmMainPtr);
168     wxCommandEvent actstart(ACTMGR_START);
169     wxPostEvent(frmMainPtrProc, actstart);
170     //frmMainPtrProc->ActivityIconStart();
171     
172     this->ResetBitmap();
173     this->Start(50, FALSE);
176 void wxActTimer::ResetBitmap()
178     
179     intActivityProgress = 0;
180     
183 void wxActTimer::SetupPointer(void *frmMainPtrIn)
185     
186     frmMainPtr = frmMainPtrIn;
187     
190 void wxActProcessTimer::Notify()
192     
193     // Pause the timer whilst processing to avoid problems.
194     
195     this->Stop();
196     
197     // Process Tasks.
198     
199     frmActivityMgr *ActMgrPtrProc = static_cast<frmActivityMgr*>(ActMgrPtr);
200     ActMgrPtrProc->ProcessTasks();
201     
204 void wxActProcessTimer::SetupPointers(void *ActMgr){
205     
206     ActMgrPtr = ActMgr;
207     
210 void wxActListProcTimer::Notify(){
211     
212     // Setup Label and get task data (update SetupPointers subroutine).
213     
214     this->Stop();
215     
216     for (std::map<int,int>::iterator iter = ActListPtr->begin();
217          iter != ActListPtr->end(); ++iter){
218         
219         // Check for any queued tasks and start one.        
220         
221         // 0 = Queued.
222         // 1 = Processing.
223         // 2 = Failed.
224         // 3 = Stopped.
225         // 4 = Completed.
226         // 5 = Failed (UI Updated).
227         // 6 = Stopped (UI Updated).
228         // 7 = (Reserved) (UI Updated).
229         // 8 = Completed. (UI Updated).
230         
231         std::map<int,long>::iterator LongIter = ActListUIPtr->find(iter->first);
232         
233         if (iter->second > 4){
234         
235             continue;
236         }
237         
238         std::map<int,wxString>::iterator DetailIter = ActListDetailPtr->find(iter->first);
239         
240         wxCommandEvent uevent(ACTMGR_UPDATESTATUSLABEL);
241         ActivityMgrLabelUpdate *ueventdata = new ActivityMgrLabelUpdate;
242         uevent.SetClientData(ueventdata);
243         
244         if (iter->second == 1){
245             
246             ueventdata->ItemIndex = LongIter->second;
247             ueventdata->ItemLabel = _("Processing...");     
248             ueventdata->ItemDes = _("Adding Contact '") + DetailIter->second + _("'...");
249             
250             wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
251             
252             /*lstActivityPtr->SetItem(LongIter->second, 2, _("Processing..."));
253             if (ActListDetailPtr->find(iter->first) != ActListDetailPtr->end()){
254                 lblDetailsPtr->SetLabel(_("Adding Contact '") + DetailIter->second + _("'..."));
255             }*/
256             
257         } else if (iter->second == 2){
258             
259             ueventdata->ItemIndex = LongIter->second;
260             ueventdata->ItemLabel = _("Failed");
261             
262             wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
263             iter->second = 5;       
265             //lstActivityPtr->SetItem(LongIter->second, 2, _("Failed"));
266            
267         } else if (iter->second == 3){
268  
269             ueventdata->ItemIndex = LongIter->second;
270             ueventdata->ItemLabel = _("Stopped");
271             
272             wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
273             iter->second = 5;
274             
275             //lstActivityPtr->SetItem(LongIter->second, 2, _("Stopped"));
276             //iter->second = 6;
277             
278         } else if (iter->second == 4){
279             
280             ueventdata->ItemIndex = LongIter->second;
281             ueventdata->ItemLabel = _("Completed");
282             
283             wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
284             iter->second = 8;
285             
286             //lstActivityPtr->SetItem(LongIter->second, 2, _("Completed"));
287             //iter->second = 8;
288             
289         }
290         
291         // Insert a finish date.
292         
293         wxDateTime adt;
294         adt = adt.Now();
295         
296         ActListFinDTPtr->insert(std::make_pair(iter->first, adt));
297         
298     }
299     
300     if (ClearupProcessed == TRUE){
301         
302         // Clear up processed items.
303         
304         // Delete the processed items.
305         
306         ClearupProcessed = FALSE;
307         
308     }
309     
310     if (*TasksActivePtr == FALSE){
311         
312         ActTimerPtr->StopAnimation();
313         lblDetailsPtr->SetLabel(_("No activity."));
314         
315     } else {
316         
317         this->Start();
318         
319     }
320     
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){
328     
329     ActListPtr = ActList;
330     ActListUIPtr = ActListUI;
331     ActListDetailPtr = ActListDetail;
332     TasksActivePtr = TasksActive;
333     lstActivityPtr = lstActivity;
334     lblDetailsPtr = lblDetails;
335     GauProgressPtr = GauProgress;
336     ActMgrPtr = ActMgr;
337     ActTimerPtr = ActTimer;
338     ActProcessTimerPtr = ActProcessTimer;
339     ActListFinDTPtr = ActListFinDT;
340     
343 void wxActListProcTimer::EnableClearup(){
344     
345     ClearupProcessed = TRUE;
346     
349 void wxETagProcessTimer::Notify(){
350     
351     // Check each ETagDB and see if writing to file is required.
352     
353     //ETagDB* ETagDBPtr;
354     //ETagDB ETagDBCopy;
355     
356     std::map<wxString,ETagDB>::iterator ETagIter;
357     
358     for (ETagIter = ETagDBList.begin();
359          ETagIter != ETagDBList.end(); ++ETagIter){
360         
361         if (ETagIter->second.GetWriteStatus() == TRUE){
362             
363             ETagIter->second.WriteETagDB();
364             
365         }
366         
367     }
368     
369     
372 void wxETagProcessTimer::ReloadAccounts(){
373     
374     // Get the account preferences file and setup each database accordingly.
375     
376     ReloadLock.lock();
377     
378     // Stop the timer.
379     
380     this->Stop();
381     ETagDBList.clear();
382     
383     wxString PrefFilename = GetUserPrefDir();
384     
385     XABPreferences PrefData(PrefFilename);
386     
387     wxString AccountName;
388     wxString AccountDir;
389     wxString AccountAddress;
390     wxString AccountUsername;
391     wxString AccountPassword;
392     wxString AccountPrefix;
393     wxString AccountType;
394     
395     // Look for the account and get the friendly name for the account.
396     
397     for (int i = 0; i < PrefData.accounts.GetCount(); i++){
398         
399         AccountDir = PrefData.accounts.GetAccountDirectory(i);
400         AccountType = PrefData.accounts.GetAccountType(i);
401         
402         if (AccountDir.IsEmpty()){
403             continue;
404         }
405         
406         if (AccountType == wxT("Local") || AccountType == wxT("local")){
407             continue;
408         }
409         
410         AccountDir.Trim();
411         AccountDir.Append(wxT(".carddav"));
412         
413         ETagDB AccountDB;
414         AccountDB.SetupDB(AccountDir);
415         
416         ETagDBList.insert(std::make_pair(AccountDir, AccountDB));
417         
418         AccountDir.clear();
419         
420     }
421     
422     //raise(SIGABRT);
423     
424     /*for (int i = 0; i < PrefData.accounts.GetCount(); i++){
425      
426      AccountDir = PrefData.accounts.GetAccountDirectory(i);
427      
428      AccountDir.Trim();
429      AccountDir.Append(wxT(".carddav"));
430      
431      //AccountPrefix = PrefData.accounts.GetAccountDirPrefix(i);
432      
433      //ETagDB NewETagDB (AccountDir);
434      
435      ETagDB AccountDB;
436      AccountDB.SetupDB(AccountDir);
437      
438      //ETagDBList.insert(std::make_pair(AccountDir, Moo));
439      
440      //std::pair<wxString,ETagDB> Moo2;
441      
442      //ETagDB2 Meep;
443      
444      //ETagDBListv3.insert(std::make_pair(0,Meep));
445      
446      //ETagDBListv2.insert(std::make_pair(0, Moo));
447      
448      //ETagDBList.insert(Moo2);
449      
450      ETagDBList.insert(std::make_pair(AccountDir, AccountDB));
451      
452      //Moo55.insert(std::make_pair(wxT("Meep"), wxT("Meep")));
453      
454      //ETagDBList[AccountDir] = new ETagDB (AccountDir);
455      
456      }*/
457     
458     //ETagDB Test (AccountDir);
459     
460     //ETagDBList.insert(std::make_pair(AccountDir, Test));
461     
462     ReloadLock.unlock();
463     this->Start(15000);
464     
467 ETagDB* wxETagProcessTimer::GetPointer(wxString AccountName){
468     
469     ETagDB *ETagDBPtr = NULL;
470     
471     std::map<wxString,ETagDB>::iterator ETagIter;
472     
473     ETagIter = ETagDBList.find(AccountName);
474     
475     if (ETagIter != ETagDBList.end()){
476         
477         ETagDBPtr = &ETagIter->second;
478         
479     }
480     
481     return ETagDBPtr;
482     
485 void wxContactFileMonitorTimer::Notify(){
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     Filename = FilenameInc;
513     
514     wxFileName FileCheck(Filename);
515     FileDateTime = FileCheck.GetModificationTime();
516     
519 void wxContactFileMonitorTimer::SetupPointers(frmContactEditor *frmCEPtrInc){
520     
521     frmCEPtr = frmCEPtrInc;
522     
525 void wxContactFileMonitorTimer::UpdateTimestamp(){
526     
527     wxFileName FileCheck(Filename);
528     FileDateTime = FileCheck.GetModificationTime();
529     
532 void wxContactWindowMonitor::Notify(){
533     
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).
537     
538     /*for(std::map<wxString, void*>::iterator iter = ContactWindowListPtr->begin();
539      iter != ContactWindowListPtr->end(); iter++){
540      
541      frmContact *ContactPtr = (frmContact*)iter->second;
542      
543      // Check if open.
544      
545      if (
546      
547      // Delete the form.
548      
549      // Delete the data from the map.
550      
551      }*/
552     
555 void wxContactWindowMonitor::SetupPointers(std::map<wxString, void*> *ContactWindowListPtrInc){
556     
557     ContactWindowListPtr = ContactWindowListPtrInc;
558     
561 void wxAccountSyncTimer::Notify(){
562     
563     frmActivityMgr *ActMgrPtrProc = static_cast<frmActivityMgr*>(frmActMgrPtr);
564     
565     // Disable the timer. (Don't go updating unless needed).
566     
567     this->Stop();
568     
569     if (ActMgrPtrProc->GetTaskStatus(intTaskID) < 2){
570         
571         this->Start();
572         return;
573         
574     }
575     
576     // Add task to the activity manager.
577     
578     intTaskID = ActMgrPtrProc->AddTask(3, wxT(""), AccName, 
579                                        wxT(""), wxT(""), wxT(""), wxT(""));
580     
581     // Go to sleep and wait for the task to be completed.
582     
583     // Enable the timer as we are now finished syncronising.
584     
585     this->Start();
586     
589 void wxAccountSyncTimer::SetupData(wxString AccNameInc,
590                                    wxString AccNameFullInc){
591     
592     // Set the account name.
593     
594     AccName = AccNameInc;
595     AccNameFull = AccNameFullInc;
596     
599 void wxAccountSyncTimer::SetupPointers(void *frmMainPtrInc, 
600                                        void *frmActMgrPtrInc, ETagDB *ETagDBPtrInc){
601     
602     // Set the pointers.
603     
604     frmMainPtr = frmMainPtrInc;
605     frmActMgrPtr = frmActMgrPtrInc;
606     ETagDBPtr = ETagDBPtrInc;
607     
610 void SleepFor(unsigned long longSleepNanoSecs){
611     
612 #ifdef __WIN32__
613     ::Sleep((longSleepNanoSecs / 1000000));
614 #elif __HAIKU__
615     
616 #else
617     
618     timespec n1, n2;
619     
620     n1.tv_sec = 0;
621     n1.tv_nsec = longSleepNanoSecs;
622     
623     nanosleep(&n1, &n2);
624     
625 #endif
626     
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