1 /*
2  *  This file is part of nzbget. See <http://nzbget.net>.
3  *
4  *  Copyright (C) 2019 Andrey Prygunkov <hugbug@users.sourceforge.net>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program 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
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 
21 #ifndef WORKSTATE_H
22 #define WORKSTATE_H
23 
24 #include "Observer.h"
25 
26 // WorkState is observable but notifications are not 100% reliable.
27 // The changes via Set-methods and readings via Get-methods are not synchronized throughout the program.
28 // As result race conditions may occur and some changes may go unnoticed.
29 // When waiting for changes don't wait too long to avoid lock ups.
30 
31 class WorkState : public Subject
32 {
33 public:
SetPauseDownload(bool pauseDownload)34 	void SetPauseDownload(bool pauseDownload) { m_pauseDownload = pauseDownload; Changed(); }
GetPauseDownload()35 	bool GetPauseDownload() const { return m_pauseDownload; }
SetPausePostProcess(bool pausePostProcess)36 	void SetPausePostProcess(bool pausePostProcess) { m_pausePostProcess = pausePostProcess; Changed(); }
GetPausePostProcess()37 	bool GetPausePostProcess() const { return m_pausePostProcess; }
SetPauseScan(bool pauseScan)38 	void SetPauseScan(bool pauseScan) { m_pauseScan = pauseScan; Changed(); }
GetPauseScan()39 	bool GetPauseScan() const { return m_pauseScan; }
SetTempPauseDownload(bool tempPauseDownload)40 	void SetTempPauseDownload(bool tempPauseDownload) { m_tempPauseDownload = tempPauseDownload; Changed(); }
GetTempPauseDownload()41 	bool GetTempPauseDownload() const { return m_tempPauseDownload; }
SetTempPausePostprocess(bool tempPausePostprocess)42 	void SetTempPausePostprocess(bool tempPausePostprocess) { m_tempPausePostprocess = tempPausePostprocess; Changed(); }
GetTempPausePostprocess()43 	bool GetTempPausePostprocess() const { return m_tempPausePostprocess; }
SetPauseFrontend(bool pauseFrontend)44 	void SetPauseFrontend(bool pauseFrontend) { m_pauseFrontend = pauseFrontend; Changed(); }
GetPauseFrontend()45 	bool GetPauseFrontend() const { return m_pauseFrontend; }
SetSpeedLimit(int speedLimit)46 	void SetSpeedLimit(int speedLimit) { m_speedLimit = speedLimit; Changed(); }
GetSpeedLimit()47 	int GetSpeedLimit() const { return m_speedLimit; }
SetResumeTime(time_t resumeTime)48 	void SetResumeTime(time_t resumeTime) { m_resumeTime = resumeTime; Changed(); }
GetResumeTime()49 	time_t GetResumeTime() const { return m_resumeTime; }
SetLocalTimeOffset(int localTimeOffset)50 	void SetLocalTimeOffset(int localTimeOffset) { m_localTimeOffset = localTimeOffset; Changed(); }
GetLocalTimeOffset()51 	int GetLocalTimeOffset() { return m_localTimeOffset; }
SetQuotaReached(bool quotaReached)52 	void SetQuotaReached(bool quotaReached) { m_quotaReached = quotaReached; Changed(); }
GetQuotaReached()53 	bool GetQuotaReached() { return m_quotaReached; }
SetDownloading(bool downloading)54 	void SetDownloading(bool downloading) { m_downloading = downloading; Changed(); }
GetDownloading()55 	bool GetDownloading() { return m_downloading; }
56 
57 private:
58 	bool m_pauseDownload = false;
59 	bool m_pausePostProcess = false;
60 	bool m_pauseScan = false;
61 	bool m_tempPauseDownload = true;
62 	bool m_tempPausePostprocess = true;
63 	bool m_pauseFrontend = false;
64 	int m_downloadRate = 0;
65 	time_t m_resumeTime = 0;
66 	int m_localTimeOffset = 0;
67 	bool m_quotaReached = false;
68 	int m_speedLimit = 0;
69 	bool m_downloading = false;
70 
71 	void Changed();
72 };
73 
74 extern WorkState* g_WorkState;
75 
76 #endif
77