Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Indented properly code in common/timers.cpp
[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         frmMain *frmMainPtrProc = static_cast<frmMain*>(frmMainPtr);
37         wxCommandEvent shuffleevent(ACTMGR_SHUFFLE);
39         if (intActivityProgress == 0){
41                 wxMemoryInputStream istream(misc_activity1_png, sizeof(misc_activity1_png));
42                 wxImage misc_activity1_pngi(istream, wxBITMAP_TYPE_PNG);
43                 wxBitmap activityiconbmp(misc_activity1_pngi, -1);
44                 bmpActivity->SetBitmap(activityiconbmp);
46                 intActivityProgress++;
48         } else if (intActivityProgress == 1){
50                 wxMemoryInputStream istream(misc_activity2_png, sizeof(misc_activity2_png));
51                 wxImage misc_activity2_pngi(istream, wxBITMAP_TYPE_PNG);
52                 wxBitmap activityiconbmp(misc_activity2_pngi, -1);
53                 bmpActivity->SetBitmap(activityiconbmp);
55                 intActivityProgress++;
57         } else if (intActivityProgress == 2){
59                 wxMemoryInputStream istream(misc_activity3_png, sizeof(misc_activity3_png));
60                 wxImage misc_activity3_pngi(istream, wxBITMAP_TYPE_PNG);
61                 wxBitmap activityiconbmp(misc_activity3_pngi, -1);
62                 bmpActivity->SetBitmap(activityiconbmp);
64                 intActivityProgress++;
66         } else if (intActivityProgress == 3){
68                 wxMemoryInputStream istream(misc_activity4_png, sizeof(misc_activity4_png));
69                 wxImage misc_activity4_pngi(istream, wxBITMAP_TYPE_PNG);
70                 wxBitmap activityiconbmp(misc_activity4_pngi, -1);
71                 bmpActivity->SetBitmap(activityiconbmp);
73                 intActivityProgress++;
75         } else if (intActivityProgress == 4){
77                 wxMemoryInputStream istream(misc_activity5_png, sizeof(misc_activity5_png));
78                 wxImage misc_activity5_pngi(istream, wxBITMAP_TYPE_PNG);
79                 wxBitmap activityiconbmp(misc_activity5_pngi, -1);
80                 bmpActivity->SetBitmap(activityiconbmp);
82                 intActivityProgress++;
84         } else if (intActivityProgress == 5){
86                 wxMemoryInputStream istream(misc_activity6_png, sizeof(misc_activity6_png));
87                 wxImage misc_activity6_pngi(istream, wxBITMAP_TYPE_PNG);
88                 wxBitmap activityiconbmp(misc_activity6_pngi, -1);
89                 bmpActivity->SetBitmap(activityiconbmp);
91                 intActivityProgress++;
93         } else if (intActivityProgress == 6){
95                 wxMemoryInputStream istream(misc_activity7_png, sizeof(misc_activity7_png));
96                 wxImage misc_activity7_pngi(istream, wxBITMAP_TYPE_PNG);
97                 wxBitmap activityiconbmp(misc_activity7_pngi, -1);
98                 bmpActivity->SetBitmap(activityiconbmp);
100                 intActivityProgress++;
102         } else if (intActivityProgress == 7){
104                 wxMemoryInputStream istream(misc_activity8_png, sizeof(misc_activity8_png));
105                 wxImage misc_activity8_pngi(istream, wxBITMAP_TYPE_PNG);
106                 wxBitmap activityiconbmp(misc_activity8_pngi, -1);
107                 bmpActivity->SetBitmap(activityiconbmp);
109                 intActivityProgress++;
111         } else if (intActivityProgress == 8){
113                 wxMemoryInputStream istream(misc_activity9_png, sizeof(misc_activity9_png));
114                 wxImage misc_activity9_pngi(istream, wxBITMAP_TYPE_PNG);
115                 wxBitmap activityiconbmp(misc_activity9_pngi, -1);
116                 bmpActivity->SetBitmap(activityiconbmp);
118                 intActivityProgress++;
120         } else if (intActivityProgress == 9){
122                 wxMemoryInputStream istream(misc_activity10_png, sizeof(misc_activity10_png));
123                 wxImage misc_activity10_pngi(istream, wxBITMAP_TYPE_PNG);
124                 wxBitmap activityiconbmp(misc_activity10_pngi, -1);
125                 bmpActivity->SetBitmap(activityiconbmp);
127                 intActivityProgress++;
129         } else if (intActivityProgress == 10){
131                 wxMemoryInputStream istream(misc_activity11_png, sizeof(misc_activity11_png));
132                 wxImage misc_activity11_pngi(istream, wxBITMAP_TYPE_PNG);
133                 wxBitmap activityiconbmp(misc_activity11_pngi, -1);
134                 bmpActivity->SetBitmap(activityiconbmp);
136                 intActivityProgress++;
138         } else if (intActivityProgress == 11){
140                 wxMemoryInputStream istream(misc_activity12_png, sizeof(misc_activity12_png));
141                 wxImage misc_activity12_pngi(istream, wxBITMAP_TYPE_PNG);
142                 wxBitmap activityiconbmp(misc_activity12_pngi, -1);
143                 bmpActivity->SetBitmap(activityiconbmp);
145                 intActivityProgress = 0;
147         }
149         wxPostEvent(frmMainPtrProc, shuffleevent);
150     
153 void wxActTimer::SetBitmap(wxStaticBitmap *bitmap)
155     
156         bmpActivity = bitmap;
157     
160 void wxActTimer::SetSleepBitmap(wxBitmap *SleepBitmap)
162     
163         SleepBitmapPtr = SleepBitmap;
164     
167 void wxActTimer::StopAnimation()
169     
170         // Stop the icon animation.
171     
172         frmMain *frmMainPtrProc = static_cast<frmMain*>(frmMainPtr);
173     
174         wxCommandEvent actstop(ACTMGR_STOP);
175         wxPostEvent(frmMainPtrProc, actstop);
176         //frmMainPtrProc->ActivityIconStop();
177     
178         this->Stop();
179         bmpActivity->SetBitmap(*SleepBitmapPtr);
180         
183 void wxActTimer::StartAnimation()
185     
186         frmMain *frmMainPtrProc = static_cast<frmMain*>(frmMainPtr);
187         wxCommandEvent actstart(ACTMGR_START);
188         wxPostEvent(frmMainPtrProc, actstart);
189         //frmMainPtrProc->ActivityIconStart();
190     
191         this->ResetBitmap();
192         this->Start(50, FALSE);
193         
196 void wxActTimer::ResetBitmap()
198     
199         intActivityProgress = 0;
200     
203 void wxActTimer::SetupPointer(void *frmMainPtrIn)
205     
206         frmMainPtr = frmMainPtrIn;
207     
210 void wxActProcessTimer::Notify()
212     
213         // Pause the timer whilst processing to avoid problems.
214     
215         this->Stop();
216     
217         // Process Tasks.
218     
219         frmActivityMgr *ActMgrPtrProc = static_cast<frmActivityMgr*>(ActMgrPtr);
220         ActMgrPtrProc->ProcessTasks();
221     
224 void wxActProcessTimer::SetupPointers(void *ActMgr){
225     
226         ActMgrPtr = ActMgr;
227     
230 void wxActListProcTimer::Notify(){
231     
232         // Setup Label and get task data (update SetupPointers subroutine).
233     
234         this->Stop();
235     
236         for (std::map<int,int>::iterator iter = ActListPtr->begin();
237                 iter != ActListPtr->end(); ++iter){
238         
239         // Check for any queued tasks and start one.        
240         
241         // 0 = Queued.
242         // 1 = Processing.
243         // 2 = Failed.
244         // 3 = Stopped.
245         // 4 = Completed.
246         // 5 = Failed (UI Updated).
247         // 6 = Stopped (UI Updated).
248         // 7 = (Reserved) (UI Updated).
249         // 8 = Completed. (UI Updated).
250         
251                 std::map<int,long>::iterator LongIter = ActListUIPtr->find(iter->first);
252         
253                 if (iter->second > 4){
254         
255                         continue;
256                 
257                 }
258         
259                 std::map<int,wxString>::iterator DetailIter = ActListDetailPtr->find(iter->first);
260         
261                 wxCommandEvent uevent(ACTMGR_UPDATESTATUSLABEL);
262                 ActivityMgrLabelUpdate *ueventdata = new ActivityMgrLabelUpdate;
263                 uevent.SetClientData(ueventdata);
264         
265                 if (iter->second == 1){
266             
267                         ueventdata->ItemIndex = LongIter->second;
268                         ueventdata->ItemLabel = _("Processing...");         
269                         //ueventdata->ItemDes = _("Adding Contact '") + DetailIter->second + _("'...");
270             
271                         wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
272             
273                         /*lstActivityPtr->SetItem(LongIter->second, 2, _("Processing..."));
274                         if (ActListDetailPtr->find(iter->first) != ActListDetailPtr->end()){
275                         lblDetailsPtr->SetLabel(_("Adding Contact '") + DetailIter->second + _("'..."));
276                         }*/
277             
278                 } else if (iter->second == 2){
279             
280                         ueventdata->ItemIndex = LongIter->second;
281                         ueventdata->ItemLabel = _("Failed");
282             
283                         wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
284                         iter->second = 5;           
286                         //lstActivityPtr->SetItem(LongIter->second, 2, _("Failed"));
287            
288                 } else if (iter->second == 3){
289  
290                         ueventdata->ItemIndex = LongIter->second;
291                         ueventdata->ItemLabel = _("Stopped");
292             
293                         wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
294                         iter->second = 5;
295             
296                         //lstActivityPtr->SetItem(LongIter->second, 2, _("Stopped"));
297                         //iter->second = 6;
298             
299                 } else if (iter->second == 4){
300             
301                         ueventdata->ItemIndex = LongIter->second;
302                         ueventdata->ItemLabel = _("Completed");
303             
304                         wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
305                         iter->second = 8;
306             
307                         //lstActivityPtr->SetItem(LongIter->second, 2, _("Completed"));
308                         //iter->second = 8;
309             
310                 }
311         
312                 // Insert a finish date.
313         
314                 wxDateTime adt;
315                 adt = adt.Now();
316         
317                 ActListFinDTPtr->insert(std::make_pair(iter->first, adt));
318         
319                 // Delete the connection object.
320         
321                 std::map<int, CardDAV*>::iterator ConnObject = ActListConnPtr->find(iter->first);
322                 delete ConnObject->second;
323                 ConnObject->second = NULL;
324         
325         }
326     
327         if (ClearupProcessed == TRUE){
328         
329                 // Clear up processed items.
330         
331                 // Delete the processed items.
332         
333                 ClearupProcessed = FALSE;
334         
335         }
336     
337         if (*TasksActivePtr == FALSE){
338         
339                 ActTimerPtr->StopAnimation();
340                 lblDetailsPtr->SetLabel(_("No activity."));
341         
342         } else {
343         
344                 this->Start();
345         
346         }
347     
350 void wxActListProcTimer::SetupPointers(std::map<int,int> *ActList, std::map<int,long> *ActListUI,
351                                        std::map<int,wxString> *ActListDetail, bool *TasksActive,
352                                        wxListCtrl *lstActivity, wxStaticText *lblDetails, wxGauge *GauProgress,
353                                        void *ActMgr, wxActTimer *ActTimer, wxActProcessTimer *ActProcessTimer,
354                                        std::map<int,wxDateTime> *ActListFinDT, std::map<int, CardDAV*> *ActListConn){
355     
356         ActListPtr = ActList;
357         ActListUIPtr = ActListUI;
358         ActListDetailPtr = ActListDetail;
359         TasksActivePtr = TasksActive;
360         lstActivityPtr = lstActivity;
361         lblDetailsPtr = lblDetails;
362         GauProgressPtr = GauProgress;
363         ActMgrPtr = ActMgr;
364         ActTimerPtr = ActTimer;
365         ActProcessTimerPtr = ActProcessTimer;
366         ActListFinDTPtr = ActListFinDT;
367         ActListConnPtr = ActListConn;
368     
371 void wxActListProcTimer::EnableClearup(){
372     
373         ClearupProcessed = TRUE;
374     
377 void wxETagProcessTimer::Notify(){
378     
379         // Check each ETagDB and see if writing to file is required.
380     
381         //ETagDB* ETagDBPtr;
382         //ETagDB ETagDBCopy;
383     
384         std::map<wxString,ETagDB>::iterator ETagIter;
385     
386         for (ETagIter = ETagDBList.begin();
387                 ETagIter != ETagDBList.end(); ++ETagIter){
388         
389                 if (ETagIter->second.GetWriteStatus() == TRUE){
390             
391                         ETagIter->second.WriteETagDB();
392             
393                 }
394         
395         }
396     
397     
400 void wxETagProcessTimer::ReloadAccounts(){
401     
402         // Get the account preferences file and setup each database accordingly.
403     
404         ReloadLock.lock();
405     
406         // Stop the timer.
407     
408         this->Stop();
409         ETagDBList.clear();
410     
411         wxString PrefFilename = GetUserPrefDir();
412     
413         XABPreferences PrefData(PrefFilename);
414     
415         wxString AccountName;
416         wxString AccountDir;
417         wxString AccountAddress;
418         wxString AccountUsername;
419         wxString AccountPassword;
420         wxString AccountPrefix;
421         wxString AccountType;
422     
423         // Look for the account and get the friendly name for the account.
424     
425         for (int i = 0; i < PrefData.accounts.GetCount(); i++){
426         
427                 AccountDir = PrefData.accounts.GetAccountDirectory(i);
428                 AccountType = PrefData.accounts.GetAccountType(i);
429         
430                 if (AccountDir.IsEmpty()){
431                         continue;
432                 }
433         
434                 if (AccountType == wxT("Local") || AccountType == wxT("local")){
435                 continue;
436                 }
437         
438                 AccountDir.Trim();
439                 AccountDir.Append(wxT(".carddav"));
440         
441                 ETagDB AccountDB;
442                 AccountDB.SetupDB(AccountDir);
443         
444                 ETagDBList.insert(std::make_pair(AccountDir, AccountDB));
445         
446                 AccountDir.clear();
447         
448         }
449     
450         //raise(SIGABRT);
451     
452         /*for (int i = 0; i < PrefData.accounts.GetCount(); i++){
453      
454         AccountDir = PrefData.accounts.GetAccountDirectory(i);
455      
456         AccountDir.Trim();
457         AccountDir.Append(wxT(".carddav"));
459         //AccountPrefix = PrefData.accounts.GetAccountDirPrefix(i);
461         //ETagDB NewETagDB (AccountDir);
463         ETagDB AccountDB;
464         AccountDB.SetupDB(AccountDir);
466         //ETagDBList.insert(std::make_pair(AccountDir, Moo));
468         //std::pair<wxString,ETagDB> Moo2;
470         //ETagDB2 Meep;
472         //ETagDBListv3.insert(std::make_pair(0,Meep));
474         //ETagDBListv2.insert(std::make_pair(0, Moo));
476         //ETagDBList.insert(Moo2);
478         ETagDBList.insert(std::make_pair(AccountDir, AccountDB));
480         //Moo55.insert(std::make_pair(wxT("Meep"), wxT("Meep")));
482         //ETagDBList[AccountDir] = new ETagDB (AccountDir);
484         }*/
486         //ETagDB Test (AccountDir);
488         //ETagDBList.insert(std::make_pair(AccountDir, Test));
489     
490         ReloadLock.unlock();
491         this->Start(15000);
492     
495 ETagDB* wxETagProcessTimer::GetPointer(wxString AccountName){
496     
497         ETagDB *ETagDBPtr = NULL;
498     
499         std::map<wxString,ETagDB>::iterator ETagIter;
500     
501         ETagIter = ETagDBList.find(AccountName);
503         if (ETagIter != ETagDBList.end()){
505                 ETagDBPtr = &ETagIter->second;
507         }
509         return ETagDBPtr;
510     
513 void wxContactFileMonitorTimer::Notify(){
514     
515         if (Filename.IsEmpty()){
516         
517                 return;
518         
519         }
520     
521         wxFileName FileCheck(Filename);
522         wxDateTime CurrentDateTime;
523     
524         CurrentDateTime = FileCheck.GetModificationTime();
525     
526         if (FileDateTime != CurrentDateTime){
527         
528                 // The dates & times of the file are different.
529                 // Send an event to notify the user of this change.
530         
531                 wxCommandEvent dateevent(wxEVT_COMMAND_BUTTON_CLICKED);
532                 wxPostEvent(frmCEPtr, dateevent);
533         
534         }
535     
538 void wxContactFileMonitorTimer::SetFilename(wxString FilenameInc){
539     
540         Filename = FilenameInc;
541     
542         wxFileName FileCheck(Filename);
543         FileDateTime = FileCheck.GetModificationTime();
544     
547 void wxContactFileMonitorTimer::SetupPointers(frmContactEditor *frmCEPtrInc){
548     
549         frmCEPtr = frmCEPtrInc;
550     
553 void wxContactFileMonitorTimer::UpdateTimestamp(){
554     
555         wxFileName FileCheck(Filename);
556         FileDateTime = FileCheck.GetModificationTime();
557     
560 void wxContactWindowMonitor::Notify(){
561     
562         // Look through the list of windows and see if any have
563         // closed. IF they have closed then delete and free the
564         // memory (also delete from the map).
565     
566         /*for(std::map<wxString, void*>::iterator iter = ContactWindowListPtr->begin();
567         iter != ContactWindowListPtr->end(); iter++){
568      
569         frmContact *ContactPtr = (frmContact*)iter->second;
570      
571      // Check if open.
572      
573      if (
574      
575      // Delete the form.
576      
577      // Delete the data from the map.
578      
579      }*/
580     
583 void wxContactWindowMonitor::SetupPointers(std::map<wxString, void*> *ContactWindowListPtrInc){
584     
585         ContactWindowListPtr = ContactWindowListPtrInc;
586     
589 void wxAccountSyncTimer::Notify(){
590     
591         frmActivityMgr *ActMgrPtrProc = static_cast<frmActivityMgr*>(frmActMgrPtr);
592     
593         // Disable the timer. (Don't go updating unless needed).
594     
595         this->Stop();
596     
597         if (ActMgrPtrProc->GetTaskStatus(intTaskID) < 2){
598         
599                 this->Start();
600                 return;
601         
602         }
603     
604         // Add task to the activity manager.
605     
606         intTaskID = ActMgrPtrProc->AddTask(3, wxT(""), AccName, 
607                 wxT(""), wxT(""), wxT(""), wxT(""));
608     
609         // Go to sleep and wait for the task to be completed.
610     
611         // Enable the timer as we are now finished syncronising.
612     
613         this->Start();
614     
617 void wxAccountSyncTimer::SetupData(wxString AccNameInc,
618                                    wxString AccNameFullInc){
619     
620         // Set the account name.
621     
622         AccName = AccNameInc;
623         AccNameFull = AccNameFullInc;
624     
627 void wxAccountSyncTimer::SetupPointers(void *frmMainPtrInc, 
628                                        void *frmActMgrPtrInc, ETagDB *ETagDBPtrInc){
629     
630         // Set the pointers.
631     
632         frmMainPtr = frmMainPtrInc;
633         frmActMgrPtr = frmActMgrPtrInc;
634         ETagDBPtr = ETagDBPtrInc;
635     
638 void SleepFor(unsigned long longSleepNanoSecs){
639     
640 #ifdef __WIN32__
641         ::Sleep((longSleepNanoSecs / 1000000));
642 #elif __HAIKU__
643     
644 #else
645     
646         timespec n1, n2;
647     
648         n1.tv_sec = 0;
649         n1.tv_nsec = longSleepNanoSecs;
650     
651         nanosleep(&n1, &n2);
652     
653 #endif
654     
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