Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Removed more 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     
189         this->ResetBitmap();
190         this->Start(50, FALSE);
191         
194 void wxActTimer::ResetBitmap()
196     
197         intActivityProgress = 0;
198     
201 void wxActTimer::SetupPointer(void *frmMainPtrIn)
203     
204         frmMainPtr = frmMainPtrIn;
205     
208 void wxActProcessTimer::Notify()
210     
211         // Pause the timer whilst processing to avoid problems.
212     
213         this->Stop();
214     
215         // Process Tasks.
216     
217         frmActivityMgr *ActMgrPtrProc = static_cast<frmActivityMgr*>(ActMgrPtr);
218         ActMgrPtrProc->ProcessTasks();
219     
222 void wxActProcessTimer::SetupPointers(void *ActMgr){
223     
224         ActMgrPtr = ActMgr;
225     
228 void wxActListProcTimer::Notify(){
229     
230         // Setup Label and get task data (update SetupPointers subroutine).
231     
232         this->Stop();
233     
234         for (std::map<int,int>::iterator iter = ActListPtr->begin();
235                 iter != ActListPtr->end(); ++iter){
236         
237                 // Check for any queued tasks and start one.        
238         
239                 // 0 = Queued.
240                 // 1 = Processing.
241                 // 2 = Failed.
242                 // 3 = Stopped.
243                 // 4 = Completed.
244                 // 5 = Failed (UI Updated).
245                 // 6 = Stopped (UI Updated).
246                 // 7 = (Reserved) (UI Updated).
247                 // 8 = Completed. (UI Updated).
248         
249                 std::map<int,long>::iterator LongIter = ActListUIPtr->find(iter->first);
250         
251                 if (iter->second > 4){
252         
253                         continue;
254                 
255                 }
256         
257                 std::map<int,wxString>::iterator DetailIter = ActListDetailPtr->find(iter->first);
258         
259                 wxCommandEvent uevent(ACTMGR_UPDATESTATUSLABEL);
260                 ActivityMgrLabelUpdate *ueventdata = new ActivityMgrLabelUpdate;
261                 uevent.SetClientData(ueventdata);
262         
263                 if (iter->second == 1){
264             
265                         ueventdata->ItemIndex = LongIter->second;
266                         ueventdata->ItemLabel = _("Processing...");         
267             
268                         wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
269             
270                 } else if (iter->second == 2){
271             
272                         ueventdata->ItemIndex = LongIter->second;
273                         ueventdata->ItemLabel = _("Failed");
274             
275                         wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
276                         iter->second = 5;           
278                 } else if (iter->second == 3){
279  
280                         ueventdata->ItemIndex = LongIter->second;
281                         ueventdata->ItemLabel = _("Stopped");
282             
283                         wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
284                         iter->second = 5;
285             
286                 } else if (iter->second == 4){
287             
288                         ueventdata->ItemIndex = LongIter->second;
289                         ueventdata->ItemLabel = _("Completed");
290             
291                         wxPostEvent(static_cast<frmActivityMgr*>(ActMgrPtr), uevent);
292                         iter->second = 8;
293             
294                 }
295         
296                 // Insert a finish date.
297         
298                 wxDateTime adt;
299                 adt = adt.Now();
300         
301                 ActListFinDTPtr->insert(std::make_pair(iter->first, adt));
302         
303                 // Delete the connection object.
304         
305                 std::map<int, CardDAV*>::iterator ConnObject = ActListConnPtr->find(iter->first);
306                 delete ConnObject->second;
307                 ConnObject->second = NULL;
308         
309         }
310     
311         if (ClearupProcessed == TRUE){
312         
313                 // Clear up processed items.
314         
315                 // Delete the processed items.
316         
317                 ClearupProcessed = FALSE;
318         
319         }
320     
321         if (*TasksActivePtr == FALSE){
322         
323                 ActTimerPtr->StopAnimation();
324                 lblDetailsPtr->SetLabel(_("No activity."));
325         
326         } else {
327         
328                 this->Start();
329         
330         }
331     
334 void wxActListProcTimer::SetupPointers(std::map<int,int> *ActList, std::map<int,long> *ActListUI,
335                                        std::map<int,wxString> *ActListDetail, bool *TasksActive,
336                                        wxListCtrl *lstActivity, wxStaticText *lblDetails, wxGauge *GauProgress,
337                                        void *ActMgr, wxActTimer *ActTimer, wxActProcessTimer *ActProcessTimer,
338                                        std::map<int,wxDateTime> *ActListFinDT, std::map<int, CardDAV*> *ActListConn){
339     
340         ActListPtr = ActList;
341         ActListUIPtr = ActListUI;
342         ActListDetailPtr = ActListDetail;
343         TasksActivePtr = TasksActive;
344         lstActivityPtr = lstActivity;
345         lblDetailsPtr = lblDetails;
346         GauProgressPtr = GauProgress;
347         ActMgrPtr = ActMgr;
348         ActTimerPtr = ActTimer;
349         ActProcessTimerPtr = ActProcessTimer;
350         ActListFinDTPtr = ActListFinDT;
351         ActListConnPtr = ActListConn;
352     
355 void wxActListProcTimer::EnableClearup(){
356     
357         ClearupProcessed = TRUE;
358     
361 void wxETagProcessTimer::Notify(){
362     
363         // Check each ETagDB and see if writing to file is required.
364     
365         std::map<wxString,ETagDB>::iterator ETagIter;
366     
367         for (ETagIter = ETagDBList.begin();
368                 ETagIter != ETagDBList.end(); ++ETagIter){
369         
370                 if (ETagIter->second.GetWriteStatus() == TRUE){
371             
372                         ETagIter->second.WriteETagDB();
373             
374                 }
375         
376         }
377     
378     
381 void wxETagProcessTimer::ReloadAccounts(){
382     
383         // Get the account preferences file and setup each database accordingly.
384     
385         ReloadLock.lock();
386     
387         // Stop the timer.
388     
389         this->Stop();
390         ETagDBList.clear();
391     
392         wxString PrefFilename = GetUserPrefDir();
393     
394         XABPreferences PrefData(PrefFilename);
395     
396         wxString AccountName;
397         wxString AccountDir;
398         wxString AccountAddress;
399         wxString AccountUsername;
400         wxString AccountPassword;
401         wxString AccountPrefix;
402         wxString AccountType;
403     
404         // Look for the account and get the friendly name for the account.
405     
406         for (int i = 0; i < PrefData.accounts.GetCount(); i++){
407         
408                 AccountDir = PrefData.accounts.GetAccountDirectory(i);
409                 AccountType = PrefData.accounts.GetAccountType(i);
410         
411                 if (AccountDir.IsEmpty()){
412                         continue;
413                 }
414         
415                 if (AccountType == wxT("Local") || AccountType == wxT("local")){
416                 continue;
417                 }
418         
419                 AccountDir.Trim();
420                 AccountDir.Append(wxT(".carddav"));
421         
422                 ETagDB AccountDB;
423                 AccountDB.SetupDB(AccountDir);
424         
425                 ETagDBList.insert(std::make_pair(AccountDir, AccountDB));
426         
427                 AccountDir.clear();
428         
429         }
430     
431         ReloadLock.unlock();
432         this->Start(15000);
433     
436 ETagDB* wxETagProcessTimer::GetPointer(wxString AccountName){
437     
438         ETagDB *ETagDBPtr = NULL;
439     
440         std::map<wxString,ETagDB>::iterator ETagIter;
441     
442         ETagIter = ETagDBList.find(AccountName);
444         if (ETagIter != ETagDBList.end()){
446                 ETagDBPtr = &ETagIter->second;
448         }
450         return ETagDBPtr;
451     
454 void wxContactFileMonitorTimer::Notify(){
455     
456         if (Filename.IsEmpty()){
457         
458                 return;
459         
460         }
461     
462         wxFileName FileCheck(Filename);
463         wxDateTime CurrentDateTime;
464     
465         CurrentDateTime = FileCheck.GetModificationTime();
466     
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         }
476     
479 void wxContactFileMonitorTimer::SetFilename(wxString FilenameInc){
480     
481         Filename = FilenameInc;
482     
483         wxFileName FileCheck(Filename);
484         FileDateTime = FileCheck.GetModificationTime();
485     
488 void wxContactFileMonitorTimer::SetupPointers(frmContactEditor *frmCEPtrInc){
489     
490         frmCEPtr = frmCEPtrInc;
491     
494 void wxContactFileMonitorTimer::UpdateTimestamp(){
495     
496         wxFileName FileCheck(Filename);
497         FileDateTime = FileCheck.GetModificationTime();
498     
501 void wxContactWindowMonitor::Notify(){
502     
505 void wxContactWindowMonitor::SetupPointers(std::map<wxString, void*> *ContactWindowListPtrInc){
506     
507         ContactWindowListPtr = ContactWindowListPtrInc;
508     
511 void wxAccountSyncTimer::Notify(){
512     
513         frmActivityMgr *ActMgrPtrProc = static_cast<frmActivityMgr*>(frmActMgrPtr);
514     
515         // Disable the timer. (Don't go updating unless needed).
516     
517         this->Stop();
518     
519         if (ActMgrPtrProc->GetTaskStatus(intTaskID) < 2){
520         
521                 this->Start();
522                 return;
523         
524         }
525     
526         // Add task to the activity manager.
527     
528         intTaskID = ActMgrPtrProc->AddTask(3, wxT(""), AccName, 
529                 wxT(""), wxT(""), wxT(""), wxT(""));
530     
531         // Go to sleep and wait for the task to be completed.
532     
533         // Enable the timer as we are now finished syncronising.
534     
535         this->Start();
536     
539 void wxAccountSyncTimer::SetupData(wxString AccNameInc,
540                                    wxString AccNameFullInc){
541     
542         // Set the account name.
543     
544         AccName = AccNameInc;
545         AccNameFull = AccNameFullInc;
546     
549 void wxAccountSyncTimer::SetupPointers(void *frmMainPtrInc, 
550                                        void *frmActMgrPtrInc, ETagDB *ETagDBPtrInc){
551     
552         // Set the pointers.
553     
554         frmMainPtr = frmMainPtrInc;
555         frmActMgrPtr = frmActMgrPtrInc;
556         ETagDBPtr = ETagDBPtrInc;
557     
560 void SleepFor(unsigned long longSleepNanoSecs){
561     
562 #ifdef __WIN32__
563         ::Sleep((longSleepNanoSecs / 1000000));
564 #elif __HAIKU__
565     
566 #else
567     
568         timespec n1, n2;
569     
570         n1.tv_sec = 0;
571         n1.tv_nsec = longSleepNanoSecs;
572     
573         nanosleep(&n1, &n2);
574     
575 #endif
576     
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