Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Removed unused code from 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     
177         this->Stop();
178         bmpActivity->SetBitmap(*SleepBitmapPtr);
179         
182 void wxActTimer::StartAnimation()
184     
185         frmMain *frmMainPtrProc = static_cast<frmMain*>(frmMainPtr);
186         wxCommandEvent actstart(ACTMGR_START);
187         wxPostEvent(frmMainPtrProc, actstart);
188         //frmMainPtrProc->ActivityIconStart();
189     
190         this->ResetBitmap();
191         this->Start(50, FALSE);
192         
195 void wxActTimer::ResetBitmap()
197     
198         intActivityProgress = 0;
199     
202 void wxActTimer::SetupPointer(void *frmMainPtrIn)
204     
205         frmMainPtr = frmMainPtrIn;
206     
209 void wxActProcessTimer::Notify()
211     
212         // Pause the timer whilst processing to avoid problems.
213     
214         this->Stop();
215     
216         // Process Tasks.
217     
218         frmActivityMgr *ActMgrPtrProc = static_cast<frmActivityMgr*>(ActMgrPtr);
219         ActMgrPtrProc->ProcessTasks();
220     
223 void wxActProcessTimer::SetupPointers(void *ActMgr){
224     
225         ActMgrPtr = ActMgr;
226     
229 void wxActListProcTimer::Notify(){
230     
231         // Setup Label and get task data (update SetupPointers subroutine).
232     
233         this->Stop();
234     
235         for (std::map<int,int>::iterator iter = ActListPtr->begin();
236                 iter != ActListPtr->end(); ++iter){
237         
238                 // Check for any queued tasks and start one.        
239         
240                 // 0 = Queued.
241                 // 1 = Processing.
242                 // 2 = Failed.
243                 // 3 = Stopped.
244                 // 4 = Completed.
245                 // 5 = Failed (UI Updated).
246                 // 6 = Stopped (UI Updated).
247                 // 7 = (Reserved) (UI Updated).
248                 // 8 = Completed. (UI Updated).
249         
250                 std::map<int,long>::iterator LongIter = ActListUIPtr->find(iter->first);
251         
252                 if (iter->second > 4){
253         
254                         continue;
255                 
256                 }
257         
258                 std::map<int,wxString>::iterator DetailIter = ActListDetailPtr->find(iter->first);
259         
260                 wxCommandEvent uevent(ACTMGR_UPDATESTATUSLABEL);
261                 ActivityMgrLabelUpdate *ueventdata = new ActivityMgrLabelUpdate;
262                 uevent.SetClientData(ueventdata);
263         
264                 if (iter->second == 1){
265             
266                         ueventdata->ItemIndex = LongIter->second;
267                         ueventdata->ItemLabel = _("Processing...");         
268             
269                         wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
270             
271                 } else if (iter->second == 2){
272             
273                         ueventdata->ItemIndex = LongIter->second;
274                         ueventdata->ItemLabel = _("Failed");
275             
276                         wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
277                         iter->second = 5;           
279                         //lstActivityPtr->SetItem(LongIter->second, 2, _("Failed"));
280            
281                 } else if (iter->second == 3){
282  
283                         ueventdata->ItemIndex = LongIter->second;
284                         ueventdata->ItemLabel = _("Stopped");
285             
286                         wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
287                         iter->second = 5;
288             
289                         //lstActivityPtr->SetItem(LongIter->second, 2, _("Stopped"));
290                         //iter->second = 6;
291             
292                 } else if (iter->second == 4){
293             
294                         ueventdata->ItemIndex = LongIter->second;
295                         ueventdata->ItemLabel = _("Completed");
296             
297                         wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
298                         iter->second = 8;
299             
300                         //lstActivityPtr->SetItem(LongIter->second, 2, _("Completed"));
301                         //iter->second = 8;
302             
303                 }
304         
305                 // Insert a finish date.
306         
307                 wxDateTime adt;
308                 adt = adt.Now();
309         
310                 ActListFinDTPtr->insert(std::make_pair(iter->first, adt));
311         
312                 // Delete the connection object.
313         
314                 std::map<int, CardDAV*>::iterator ConnObject = ActListConnPtr->find(iter->first);
315                 delete ConnObject->second;
316                 ConnObject->second = NULL;
317         
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, CardDAV*> *ActListConn){
348     
349         ActListPtr = ActList;
350         ActListUIPtr = ActListUI;
351         ActListDetailPtr = ActListDetail;
352         TasksActivePtr = TasksActive;
353         lstActivityPtr = lstActivity;
354         lblDetailsPtr = lblDetails;
355         GauProgressPtr = GauProgress;
356         ActMgrPtr = ActMgr;
357         ActTimerPtr = ActTimer;
358         ActProcessTimerPtr = ActProcessTimer;
359         ActListFinDTPtr = ActListFinDT;
360         ActListConnPtr = ActListConn;
361     
364 void wxActListProcTimer::EnableClearup(){
365     
366         ClearupProcessed = TRUE;
367     
370 void wxETagProcessTimer::Notify(){
371     
372         // Check each ETagDB and see if writing to file is required.
373     
374         std::map<wxString,ETagDB>::iterator ETagIter;
375     
376         for (ETagIter = ETagDBList.begin();
377                 ETagIter != ETagDBList.end(); ++ETagIter){
378         
379                 if (ETagIter->second.GetWriteStatus() == TRUE){
380             
381                         ETagIter->second.WriteETagDB();
382             
383                 }
384         
385         }
386     
387     
390 void wxETagProcessTimer::ReloadAccounts(){
391     
392         // Get the account preferences file and setup each database accordingly.
393     
394         ReloadLock.lock();
395     
396         // Stop the timer.
397     
398         this->Stop();
399         ETagDBList.clear();
400     
401         wxString PrefFilename = GetUserPrefDir();
402     
403         XABPreferences PrefData(PrefFilename);
404     
405         wxString AccountName;
406         wxString AccountDir;
407         wxString AccountAddress;
408         wxString AccountUsername;
409         wxString AccountPassword;
410         wxString AccountPrefix;
411         wxString AccountType;
412     
413         // Look for the account and get the friendly name for the account.
414     
415         for (int i = 0; i < PrefData.accounts.GetCount(); i++){
416         
417                 AccountDir = PrefData.accounts.GetAccountDirectory(i);
418                 AccountType = PrefData.accounts.GetAccountType(i);
419         
420                 if (AccountDir.IsEmpty()){
421                         continue;
422                 }
423         
424                 if (AccountType == wxT("Local") || AccountType == wxT("local")){
425                 continue;
426                 }
427         
428                 AccountDir.Trim();
429                 AccountDir.Append(wxT(".carddav"));
430         
431                 ETagDB AccountDB;
432                 AccountDB.SetupDB(AccountDir);
433         
434                 ETagDBList.insert(std::make_pair(AccountDir, AccountDB));
435         
436                 AccountDir.clear();
437         
438         }
439     
440         ReloadLock.unlock();
441         this->Start(15000);
442     
445 ETagDB* wxETagProcessTimer::GetPointer(wxString AccountName){
446     
447         ETagDB *ETagDBPtr = NULL;
448     
449         std::map<wxString,ETagDB>::iterator ETagIter;
450     
451         ETagIter = ETagDBList.find(AccountName);
453         if (ETagIter != ETagDBList.end()){
455                 ETagDBPtr = &ETagIter->second;
457         }
459         return ETagDBPtr;
460     
463 void wxContactFileMonitorTimer::Notify(){
464     
465         if (Filename.IsEmpty()){
466         
467                 return;
468         
469         }
470     
471         wxFileName FileCheck(Filename);
472         wxDateTime CurrentDateTime;
473     
474         CurrentDateTime = FileCheck.GetModificationTime();
475     
476         if (FileDateTime != CurrentDateTime){
477         
478                 // The dates & times of the file are different.
479                 // Send an event to notify the user of this change.
480         
481                 wxCommandEvent dateevent(wxEVT_COMMAND_BUTTON_CLICKED);
482                 wxPostEvent(frmCEPtr, dateevent);
483         
484         }
485     
488 void wxContactFileMonitorTimer::SetFilename(wxString FilenameInc){
489     
490         Filename = FilenameInc;
491     
492         wxFileName FileCheck(Filename);
493         FileDateTime = FileCheck.GetModificationTime();
494     
497 void wxContactFileMonitorTimer::SetupPointers(frmContactEditor *frmCEPtrInc){
498     
499         frmCEPtr = frmCEPtrInc;
500     
503 void wxContactFileMonitorTimer::UpdateTimestamp(){
504     
505         wxFileName FileCheck(Filename);
506         FileDateTime = FileCheck.GetModificationTime();
507     
510 void wxContactWindowMonitor::Notify(){
511     
512         // Look through the list of windows and see if any have
513         // closed. IF they have closed then delete and free the
514         // memory (also delete from the map).
515     
516         /*for(std::map<wxString, void*>::iterator iter = ContactWindowListPtr->begin();
517         iter != ContactWindowListPtr->end(); iter++){
518      
519         frmContact *ContactPtr = (frmContact*)iter->second;
520      
521      // Check if open.
522      
523      if (
524      
525      // Delete the form.
526      
527      // Delete the data from the map.
528      
529      }*/
530     
533 void wxContactWindowMonitor::SetupPointers(std::map<wxString, void*> *ContactWindowListPtrInc){
534     
535         ContactWindowListPtr = ContactWindowListPtrInc;
536     
539 void wxAccountSyncTimer::Notify(){
540     
541         frmActivityMgr *ActMgrPtrProc = static_cast<frmActivityMgr*>(frmActMgrPtr);
542     
543         // Disable the timer. (Don't go updating unless needed).
544     
545         this->Stop();
546     
547         if (ActMgrPtrProc->GetTaskStatus(intTaskID) < 2){
548         
549                 this->Start();
550                 return;
551         
552         }
553     
554         // Add task to the activity manager.
555     
556         intTaskID = ActMgrPtrProc->AddTask(3, wxT(""), AccName, 
557                 wxT(""), wxT(""), wxT(""), wxT(""));
558     
559         // Go to sleep and wait for the task to be completed.
560     
561         // Enable the timer as we are now finished syncronising.
562     
563         this->Start();
564     
567 void wxAccountSyncTimer::SetupData(wxString AccNameInc,
568                                    wxString AccNameFullInc){
569     
570         // Set the account name.
571     
572         AccName = AccNameInc;
573         AccNameFull = AccNameFullInc;
574     
577 void wxAccountSyncTimer::SetupPointers(void *frmMainPtrInc, 
578                                        void *frmActMgrPtrInc, ETagDB *ETagDBPtrInc){
579     
580         // Set the pointers.
581     
582         frmMainPtr = frmMainPtrInc;
583         frmActMgrPtr = frmActMgrPtrInc;
584         ETagDBPtr = ETagDBPtrInc;
585     
588 void SleepFor(unsigned long longSleepNanoSecs){
589     
590 #ifdef __WIN32__
591         ::Sleep((longSleepNanoSecs / 1000000));
592 #elif __HAIKU__
593     
594 #else
595     
596         timespec n1, n2;
597     
598         n1.tv_sec = 0;
599         n1.tv_nsec = longSleepNanoSecs;
600     
601         nanosleep(&n1, &n2);
602     
603 #endif
604     
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