Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added code so that OSX is now supported.
[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         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){
253             
254             lstActivityPtr->SetItem(LongIter->second, 2, _("Stopped"));
255             iter->second = 6;
256             
257         } else if (iter->second == 4){
258             
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));
270         
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     }
293     
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){
301     
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;
313     
316 void wxActListProcTimer::EnableClearup(){
317     
318     ClearupProcessed = TRUE;
319     
322 void wxETagProcessTimer::Notify(){
323     
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     
342     
345 void wxETagProcessTimer::ReloadAccounts(){
346     
347     // Get the account preferences file and setup each database accordingly.
348     
349     ReloadLock.lock();
350     
351     // Stop the timer.
352     
353     this->Stop();
354     ETagDBList.clear();
355     
356     wxString PrefFilename = GetUserPrefDir();
357     
358     XABPreferences PrefData(PrefFilename);
359     
360     wxString AccountName;
361     wxString AccountDir;
362     wxString AccountAddress;
363     wxString AccountUsername;
364     wxString AccountPassword;
365     wxString AccountPrefix;
366     wxString AccountType;
367     
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);
374         
375         if (AccountDir.IsEmpty()){
376             continue;
377         }
378         
379         if (AccountType == wxT("Local") || AccountType == wxT("local")){
380             continue;
381         }
382         
383         AccountDir.Trim();
384         AccountDir.Append(wxT(".carddav"));
385         
386         ETagDB AccountDB;
387         AccountDB.SetupDB(AccountDir);
388         
389         ETagDBList.insert(std::make_pair(AccountDir, AccountDB));
390         
391         AccountDir.clear();
392         
393     }
394     
395     //raise(SIGABRT);
396     
397     /*for (int i = 0; i < PrefData.accounts.GetCount(); i++){
398      
399      AccountDir = PrefData.accounts.GetAccountDirectory(i);
400      
401      AccountDir.Trim();
402      AccountDir.Append(wxT(".carddav"));
403      
404      //AccountPrefix = PrefData.accounts.GetAccountDirPrefix(i);
405      
406      //ETagDB NewETagDB (AccountDir);
407      
408      ETagDB AccountDB;
409      AccountDB.SetupDB(AccountDir);
410      
411      //ETagDBList.insert(std::make_pair(AccountDir, Moo));
412      
413      //std::pair<wxString,ETagDB> Moo2;
414      
415      //ETagDB2 Meep;
416      
417      //ETagDBListv3.insert(std::make_pair(0,Meep));
418      
419      //ETagDBListv2.insert(std::make_pair(0, Moo));
420      
421      //ETagDBList.insert(Moo2);
422      
423      ETagDBList.insert(std::make_pair(AccountDir, AccountDB));
424      
425      //Moo55.insert(std::make_pair(wxT("Meep"), wxT("Meep")));
426      
427      //ETagDBList[AccountDir] = new ETagDB (AccountDir);
428      
429      }*/
430     
431     //ETagDB Test (AccountDir);
432     
433     //ETagDBList.insert(std::make_pair(AccountDir, Test));
434     
435     ReloadLock.unlock();
436     this->Start(15000);
437     
440 ETagDB* wxETagProcessTimer::GetPointer(wxString AccountName){
441     
442     ETagDB *ETagDBPtr = NULL;
443     
444     std::map<wxString,ETagDB>::iterator ETagIter;
445     
446     ETagIter = ETagDBList.find(AccountName);
447     
448     if (ETagIter != ETagDBList.end()){
449         
450         ETagDBPtr = &ETagIter->second;
451         
452     }
453     
454     return ETagDBPtr;
455     
458 void wxContactFileMonitorTimer::Notify(){
459     
460     if (Filename.IsEmpty()){
461         
462         return;
463         
464     }
465     
466     wxFileName FileCheck(Filename);
467     wxDateTime CurrentDateTime;
468     
469     CurrentDateTime = FileCheck.GetModificationTime();
470     
471     if (FileDateTime != CurrentDateTime){
472         
473         // The dates & times of the file are different.
474         // Send an event to notify the user of this change.
475         
476         wxCommandEvent dateevent(wxEVT_COMMAND_BUTTON_CLICKED);
477         wxPostEvent(frmCEPtr, dateevent);
478         
479     }
480     
483 void wxContactFileMonitorTimer::SetFilename(wxString FilenameInc){
484     
485     Filename = FilenameInc;
486     
487     wxFileName FileCheck(Filename);
488     FileDateTime = FileCheck.GetModificationTime();
489     
492 void wxContactFileMonitorTimer::SetupPointers(frmContactEditor *frmCEPtrInc){
493     
494     frmCEPtr = frmCEPtrInc;
495     
498 void wxContactFileMonitorTimer::UpdateTimestamp(){
499     
500     wxFileName FileCheck(Filename);
501     FileDateTime = FileCheck.GetModificationTime();
502     
505 void wxContactWindowMonitor::Notify(){
506     
507     // Look through the list of windows and see if any have
508     // closed. IF they have closed then delete and free the
509     // memory (also delete from the map).
510     
511     /*for(std::map<wxString, void*>::iterator iter = ContactWindowListPtr->begin();
512      iter != ContactWindowListPtr->end(); iter++){
513      
514      frmContact *ContactPtr = (frmContact*)iter->second;
515      
516      // Check if open.
517      
518      if (
519      
520      // Delete the form.
521      
522      // Delete the data from the map.
523      
524      }*/
525     
528 void wxContactWindowMonitor::SetupPointers(std::map<wxString, void*> *ContactWindowListPtrInc){
529     
530     ContactWindowListPtr = ContactWindowListPtrInc;
531     
534 void wxAccountSyncTimer::Notify(){
535     
536     frmActivityMgr *ActMgrPtrProc = static_cast<frmActivityMgr*>(frmActMgrPtr);
537     
538     // Disable the timer. (Don't go updating unless needed).
539     
540     this->Stop();
541     
542     if (ActMgrPtrProc->GetTaskStatus(intTaskID) < 2){
543         
544         this->Start();
545         return;
546         
547     }
548     
549     // Add task to the activity manager.
550     
551     intTaskID = ActMgrPtrProc->AddTask(3, wxT(""), AccName, 
552                                        wxT(""), wxT(""), wxT(""), wxT(""));
553     
554     // Go to sleep and wait for the task to be completed.
555     
556     // Enable the timer as we are now finished syncronising.
557     
558     this->Start();
559     
562 void wxAccountSyncTimer::SetupData(wxString AccNameInc,
563                                    wxString AccNameFullInc){
564     
565     // Set the account name.
566     
567     AccName = AccNameInc;
568     AccNameFull = AccNameFullInc;
569     
572 void wxAccountSyncTimer::SetupPointers(void *frmMainPtrInc, 
573                                        void *frmActMgrPtrInc, ETagDB *ETagDBPtrInc){
574     
575     // Set the pointers.
576     
577     frmMainPtr = frmMainPtrInc;
578     frmActMgrPtr = frmActMgrPtrInc;
579     ETagDBPtr = ETagDBPtrInc;
580     
583 void SleepFor(unsigned long longSleepNanoSecs){
584     
585 #ifdef __WIN32__
586     ::Sleep((longSleepNanoSecs / 1000000));
587 #elif __HAIKU__
588     
589 #else
590     
591     timespec n1, n2;
592     
593     n1.tv_sec = 0;
594     n1.tv_nsec = longSleepNanoSecs;
595     
596     nanosleep(&n1, &n2);
597     
598 #endif
599     
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