From 07da9cecdc5085e7df11e96e27ac923dcee3eaeb Mon Sep 17 00:00:00 2001 From: svenhoefer Date: Tue, 14 May 2013 22:20:40 +0200 Subject: [PATCH] - sleeptimer: allow only one instance * remove unneeded includes --- src/gui/sleeptimer.cpp | 29 ++++++++++++++++++----------- src/gui/sleeptimer.h | 7 +++++-- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/gui/sleeptimer.cpp b/src/gui/sleeptimer.cpp index be0c70d32..08ebbbc20 100644 --- a/src/gui/sleeptimer.cpp +++ b/src/gui/sleeptimer.cpp @@ -4,13 +4,6 @@ Copyright (C) 2001 Steffen Hehn 'McClean' Homepage: http://dbox.cyberphoria.org/ - Kommentar: - - Diese GUI wurde von Grund auf neu programmiert und sollte nun vom - Aufbau und auch den Ausbaumoeglichkeiten gut aussehen. Neutrino basiert - auf der Client-Server Idee, diese GUI ist also von der direkten DBox- - Steuerung getrennt. Diese wird dann von Daemons uebernommen. - License: GPL @@ -35,22 +28,30 @@ #include -#include -#include #include #include #include -#include +#include extern CRemoteControl * g_RemoteControl; /* neutrino.cpp */ #include +bool CSleepTimerWidget::is_running = false; + int CSleepTimerWidget::exec(CMenuTarget* parent, const std::string &actionKey) { - int res = menu_return::RETURN_REPAINT; + int res = menu_return::RETURN_REPAINT; + + if (is_running) + { + printf("[CSleepTimerWidget] %s: another instance is already running.\n", __FUNCTION__); + return res; + } + is_running = true; + int shutdown_min = 0; char value[16]; CStringInput *inbox; @@ -88,7 +89,10 @@ int CSleepTimerWidget::exec(CMenuTarget* parent, const std::string &actionKey) /* exit pressed, cancel timer setup */ if(ret == menu_return::RETURN_EXIT_REPAINT) + { + is_running = false; return res; + } int new_val = atoi(value); if(permanent) { @@ -107,5 +111,8 @@ int CSleepTimerWidget::exec(CMenuTarget* parent, const std::string &actionKey) else // set the sleeptimer to actual time + shutdown mins and announce 1 min before g_Timerd->setSleeptimer(time(NULL) + ((shutdown_min -1) * 60),time(NULL) + shutdown_min * 60,0); } + + is_running = false; + return res; } diff --git a/src/gui/sleeptimer.h b/src/gui/sleeptimer.h index 8215c34d2..dd02a34a8 100644 --- a/src/gui/sleeptimer.h +++ b/src/gui/sleeptimer.h @@ -27,8 +27,11 @@ class CSleepTimerWidget: public CMenuTarget { - public: - int exec(CMenuTarget* parent, const std::string & actionKey); + private: + static bool is_running; + + public: + int exec(CMenuTarget* parent, const std::string & actionKey); };