Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Initial import of code already done for Xestia Address Book
[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(){
17         frmMain *frmMainPtrProc = static_cast<frmMain*>(frmMainPtr);
19         wxCommandEvent shuffleevent(ACTMGR_SHUFFLE);
21         if (intActivityProgress == 0){
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){
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);
37                 intActivityProgress++;
38         
39         } else if (intActivityProgress == 2){
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);
46                 intActivityProgress++;
47         
48         } else if (intActivityProgress == 3){
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);
55                 intActivityProgress++;
56         
57         } else if (intActivityProgress == 4){
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);
64                 intActivityProgress++;
65         
66         } else if (intActivityProgress == 5){
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);
73                 intActivityProgress++;
74         
75         } else if (intActivityProgress == 6){
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);
82                 intActivityProgress++;
83         
84         } else if (intActivityProgress == 7){
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);
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){
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);
135 void wxActTimer::SetBitmap(wxStaticBitmap *bitmap)
138         bmpActivity = bitmap;
142 void wxActTimer::SetSleepBitmap(wxBitmap *SleepBitmap)
145         SleepBitmapPtr = SleepBitmap;
149 void wxActTimer::StopAnimation()
152         // Stop the icon animation.
154         frmMain *frmMainPtrProc = static_cast<frmMain*>(frmMainPtr);
155         
156         wxCommandEvent actstop(ACTMGR_STOP);
157         wxPostEvent(frmMainPtrProc, actstop);
158         //frmMainPtrProc->ActivityIconStop();
160         this->Stop();
161         bmpActivity->SetBitmap(*SleepBitmapPtr);
164 void wxActTimer::StartAnimation()
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()
179         intActivityProgress = 0;
183 void wxActTimer::SetupPointer(void *frmMainPtrIn)
186         frmMainPtr = frmMainPtrIn;
190 void wxActProcessTimer::Notify()
193         // Pause the timer whilst processing to avoid problems.
195         this->Stop();
197         // Process Tasks.
198         
199         frmActivityMgr *ActMgrPtrProc = static_cast<frmActivityMgr*>(ActMgrPtr);
200         ActMgrPtrProc->ProcessTasks();
204 void wxActProcessTimer::SetupPointers(void *ActMgr){
206         ActMgrPtr = ActMgr;
210 void wxActListProcTimer::Notify(){
212         // Setup Label and get task data (update SetupPointers subroutine).
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                 if (iter->second > 4){
222                         continue;
223                 }
224                 
225                 
226                 // 0 = Queued.
227                 // 1 = Processing.
228                 // 2 = Failed.
229                 // 3 = Stopped.
230                 // 4 = Completed.
231                 // 5 = Failed (UI Updated).
232                 // 6 = Stopped (UI Updated).
233                 // 7 = (Reserved) (UI Updated).
234                 // 8 = Completed. (UI Updated). 
235                 
236                 std::map<int,long>::iterator LongIter = ActListUIPtr->find(iter->first);
237                 std::map<int,wxString>::iterator DetailIter = ActListDetailPtr->find(iter->first);
238                 
239                 if (iter->second == 1){
240                                 
241                         lstActivityPtr->SetItem(LongIter->second, 2, _("Processing..."));
242                         if (ActListDetailPtr->find(iter->first) != ActListDetailPtr->end()){
243                                 lblDetailsPtr->SetLabel(_("Adding Contact '") + DetailIter->second + _("'..."));
244                         }
245                         //CardDAVIter->second.
246                         
247                 } else if (iter->second == 2){
248                 
249                         lstActivityPtr->SetItem(LongIter->second, 2, _("Failed"));
250                         iter->second = 5;
251                 
252                 } else if (iter->second == 3){
254                         lstActivityPtr->SetItem(LongIter->second, 2, _("Stopped"));
255                         iter->second = 6;
256                 
257                 } else if (iter->second == 4){
259                         lstActivityPtr->SetItem(LongIter->second, 2, _("Completed"));
260                         iter->second = 8;
261                 
262                 }
263                 
264                 // Insert a finish date.
265                 
266                 wxDateTime adt;
267                 adt = adt.Now();
268                 
269                 ActListFinDTPtr->insert(std::make_pair(iter->first, adt));
271         }
272         
273         if (ClearupProcessed == TRUE){
274         
275                 // Clear up processed items.
276                 
277                 // Delete the processed items.
278                 
279                 ClearupProcessed = FALSE;
280         
281         }
282         
283         if (*TasksActivePtr == FALSE){
284         
285                 ActTimerPtr->StopAnimation();
286                 lblDetailsPtr->SetLabel(_("No activity."));
287         
288         } else {
289         
290                 this->Start();
291         
292         }
296 void wxActListProcTimer::SetupPointers(std::map<int,int> *ActList, std::map<int,long> *ActListUI, 
297                         std::map<int,wxString> *ActListDetail, bool *TasksActive,
298                         wxListCtrl *lstActivity, wxStaticText *lblDetails, wxGauge *GauProgress,
299                         void *ActMgr, wxActTimer *ActTimer, wxActProcessTimer *ActProcessTimer,
300                         std::map<int,wxDateTime> *ActListFinDT){
302         ActListPtr = ActList;
303         ActListUIPtr = ActListUI;
304         ActListDetailPtr = ActListDetail;
305         TasksActivePtr = TasksActive;
306         lstActivityPtr = lstActivity;
307         lblDetailsPtr = lblDetails;
308         GauProgressPtr = GauProgress;
309         ActMgrPtr = ActMgr;
310         ActTimerPtr = ActTimer;
311         ActProcessTimerPtr = ActProcessTimer;
312         ActListFinDTPtr = ActListFinDT;
316 void wxActListProcTimer::EnableClearup(){
318         ClearupProcessed = TRUE;
322 void wxETagProcessTimer::Notify(){
324         // Check each ETagDB and see if writing to file is required.
325         
326         //ETagDB* ETagDBPtr;
327         //ETagDB ETagDBCopy;
328         
329         std::map<wxString,ETagDB>::iterator ETagIter;
330         
331         for (ETagIter = ETagDBList.begin(); 
332          ETagIter != ETagDBList.end(); ++ETagIter){
333         
334                 if (ETagIter->second.GetWriteStatus() == TRUE){
335                 
336                         ETagIter->second.WriteETagDB();
337                 
338                 }
339          
340         }
341         
345 void wxETagProcessTimer::ReloadAccounts(){
347         // Get the account preferences file and setup each database accordingly.
348         
349         ReloadLock.lock();
350         
351         // Stop the timer.
353         this->Stop();
354         ETagDBList.clear();
355         
356         wxString PrefFilename = GetUserPrefDir();       
357         
358         XABPreferences PrefData(PrefFilename);
360         wxString AccountName;
361         wxString AccountDir;
362         wxString AccountAddress;
363         wxString AccountUsername;
364         wxString AccountPassword;
365         wxString AccountPrefix;
366         wxString AccountType;
368         // Look for the account and get the friendly name for the account.
369         
370         for (int i = 0; i < PrefData.accounts.GetCount(); i++){
371         
372                 AccountDir = PrefData.accounts.GetAccountDirectory(i);
373                 AccountType = PrefData.accounts.GetAccountType(i);
375                 if (AccountType == wxT("Local") || AccountType == wxT("local")){
376                         continue;
377                 }
379                 AccountDir.Trim();
380                 AccountDir.Append(wxT(".carddav"));
381                         
382                 ETagDB AccountDB;
383                 AccountDB.SetupDB(AccountDir);
384                                 
385                 ETagDBList.insert(std::make_pair(AccountDir, AccountDB));
386                 
387                 AccountDir.clear();
388         
389         }
390         
391         //raise(SIGABRT);
392         
393         /*for (int i = 0; i < PrefData.accounts.GetCount(); i++){
394         
395                 AccountDir = PrefData.accounts.GetAccountDirectory(i);
396                 
397                 AccountDir.Trim();
398                 AccountDir.Append(wxT(".carddav"));
399         
400                 //AccountPrefix = PrefData.accounts.GetAccountDirPrefix(i);
402                 //ETagDB NewETagDB (AccountDir);
403                 
404                 ETagDB AccountDB;
405                 AccountDB.SetupDB(AccountDir);
406                 
407                 //ETagDBList.insert(std::make_pair(AccountDir, Moo));
408                 
409                 //std::pair<wxString,ETagDB> Moo2;
410                 
411                 //ETagDB2 Meep;
412                 
413                 //ETagDBListv3.insert(std::make_pair(0,Meep));
414                 
415                 //ETagDBListv2.insert(std::make_pair(0, Moo));
416                 
417                 //ETagDBList.insert(Moo2);
418                 
419                 ETagDBList.insert(std::make_pair(AccountDir, AccountDB));
420                 
421                 //Moo55.insert(std::make_pair(wxT("Meep"), wxT("Meep")));
422                 
423                 //ETagDBList[AccountDir] = new ETagDB (AccountDir);
424         
425         }*/
426         
427         //ETagDB Test (AccountDir);
428         
429         //ETagDBList.insert(std::make_pair(AccountDir, Test));
430         
431         ReloadLock.unlock();
432         this->Start(15000);
436 ETagDB* wxETagProcessTimer::GetPointer(wxString AccountName){
438         ETagDB *ETagDBPtr = NULL;
440         std::map<wxString,ETagDB>::iterator ETagIter;
442         ETagIter = ETagDBList.find(AccountName);
444         if (ETagIter != ETagDBList.end()){
445         
446                 ETagDBPtr = &ETagIter->second;
447         
448         }
450         return ETagDBPtr;
454 void wxContactFileMonitorTimer::Notify(){
456         if (Filename.IsEmpty()){
457         
458                 return;
459         
460         }
462         wxFileName FileCheck(Filename);
463         wxDateTime CurrentDateTime;
464         
465         CurrentDateTime = FileCheck.GetModificationTime();
467         if (FileDateTime != CurrentDateTime){
468         
469                 // The dates & times of the file are different.
470                 // Send an event to notify the user of this change.
471                 
472                 wxCommandEvent dateevent(wxEVT_COMMAND_BUTTON_CLICKED);
473                 wxPostEvent(frmCEPtr, dateevent);
474         
475         }
479 void wxContactFileMonitorTimer::SetFilename(wxString FilenameInc){
481         Filename = FilenameInc;
482         
483         wxFileName FileCheck(Filename);
484         FileDateTime = FileCheck.GetModificationTime();
488 void wxContactFileMonitorTimer::SetupPointers(frmContactEditor *frmCEPtrInc){
490         frmCEPtr = frmCEPtrInc;
494 void wxContactFileMonitorTimer::UpdateTimestamp(){
496         wxFileName FileCheck(Filename);
497         FileDateTime = FileCheck.GetModificationTime();
501 void wxContactWindowMonitor::Notify(){
503         // Look through the list of windows and see if any have
504         // closed. IF they have closed then delete and free the
505         // memory (also delete from the map).
506         
507         /*for(std::map<wxString, void*>::iterator iter = ContactWindowListPtr->begin();
508         iter != ContactWindowListPtr->end(); iter++){
509         
510                 frmContact *ContactPtr = (frmContact*)iter->second;
511                 
512                 // Check if open.
513                 
514                 if (
515                 
516                 // Delete the form.
517                 
518                 // Delete the data from the map.
519         
520         }*/
524 void wxContactWindowMonitor::SetupPointers(std::map<wxString, void*> *ContactWindowListPtrInc){
526         ContactWindowListPtr = ContactWindowListPtrInc;
530 void wxAccountSyncTimer::Notify(){
532         frmActivityMgr *ActMgrPtrProc = static_cast<frmActivityMgr*>(frmActMgrPtr);
534         // Disable the timer. (Don't go updating unless needed).
535         
536         this->Stop();
537         
538         if (ActMgrPtrProc->GetTaskStatus(intTaskID) < 2){
539         
540                 this->Start();
541                 return;
542         
543         }
544         
545         // Add task to the activity manager.
546         
547         intTaskID = ActMgrPtrProc->AddTask(3, wxT(""), AccName, 
548                         wxT(""), wxT(""), wxT(""), wxT(""));
549         
550         // Go to sleep and wait for the task to be completed.
551         
552         // Enable the timer as we are now finished syncronising.
553         
554         this->Start();
555         
558 void wxAccountSyncTimer::SetupData(wxString AccNameInc,
559         wxString AccNameFullInc){
561         // Set the account name.
562                 
563         AccName = AccNameInc;
564         AccNameFull = AccNameFullInc;
568 void wxAccountSyncTimer::SetupPointers(void *frmMainPtrInc, 
569         void *frmActMgrPtrInc, ETagDB *ETagDBPtrInc){
571         // Set the pointers.
572         
573         frmMainPtr = frmMainPtrInc;
574         frmActMgrPtr = frmActMgrPtrInc;
575         ETagDBPtr = ETagDBPtrInc;
579 void SleepFor(unsigned long longSleepNanoSecs){
581 #ifdef __WIN32__
582         ::Sleep((longSleepNanoSecs / 1000000));
583 #elif __HAIKU__
585 #else
587         timespec n1, n2;
589         n1.tv_sec = 0;
590         n1.tv_nsec = longSleepNanoSecs;
592         nanosleep(&n1, &n2);
594 #endif
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