adzap: move non-menu code to Init() function

Origin commit data
------------------
Commit: a5bc5093e7
Author: vanhofen <vanhofen@gmx.de>
Date: 2016-02-28 (Sun, 28 Feb 2016)

Origin message was:
------------------
- adzap: move non-menu code to Init() function
This commit is contained in:
vanhofen
2016-02-28 22:02:42 +01:00
parent a984e9f829
commit 21a01e1745
2 changed files with 32 additions and 26 deletions

View File

@@ -79,6 +79,32 @@ static bool sortByDateTime(const CChannelEvent & a, const CChannelEvent & b)
return a.startTime < b.startTime;
}
void CAdZapMenu::Init()
{
CChannelList *channelList = CNeutrinoApp::getInstance()->channelList;
channelId = channelList ? channelList->getActiveChannel_ChannelID() : -1;
channelName = channelList->getActiveChannelName();
CChannelEventList evtlist;
CEitManager::getInstance()->getEventsServiceKey(channelId & 0xFFFFFFFFFFFFULL, evtlist);
monitorLifeTime.tv_sec = 0;
if (!evtlist.empty())
{
sort(evtlist.begin(), evtlist.end(), sortByDateTime);
CChannelEventList::iterator eli;
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
for (eli = evtlist.begin(); eli != evtlist.end(); ++eli)
{
if ((u_int) eli->startTime + (u_int) eli->duration > (u_int) ts.tv_sec)
{
monitorLifeTime.tv_sec = (uint) eli->startTime + eli->duration;
Update();
break;
}
}
}
}
void CAdZapMenu::Update()
{
clock_gettime(CLOCK_REALTIME, &zapBackTime);
@@ -174,6 +200,8 @@ void CAdZapMenu::Run()
int CAdZapMenu::exec(CMenuTarget *parent, const std::string & actionKey)
{
Init();
int res = menu_return::RETURN_EXIT_ALL;
if (actionKey == "enable")
@@ -223,6 +251,7 @@ int CAdZapMenu::exec(CMenuTarget *parent, const std::string & actionKey)
if (parent)
parent->hide();
monitor = false;
Settings();
return res;
@@ -230,31 +259,7 @@ int CAdZapMenu::exec(CMenuTarget *parent, const std::string & actionKey)
void CAdZapMenu::Settings()
{
CChannelList *channelList = CNeutrinoApp::getInstance()->channelList;
channelId = channelList ? channelList->getActiveChannel_ChannelID() : -1;
channelName = channelList->getActiveChannelName();
CChannelEventList evtlist;
CEitManager::getInstance()->getEventsServiceKey(channelId & 0xFFFFFFFFFFFFULL, evtlist);
monitorLifeTime.tv_sec = 0;
bool show_monitor = false;
if (!evtlist.empty())
{
sort(evtlist.begin(), evtlist.end(), sortByDateTime);
CChannelEventList::iterator eli;
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
for (eli = evtlist.begin(); eli != evtlist.end(); ++eli)
{
if ((u_int) eli->startTime + (u_int) eli->duration > (u_int) ts.tv_sec)
{
monitorLifeTime.tv_sec = (uint) eli->startTime + eli->duration;
show_monitor = true;
Update();
break;
}
}
}
monitor = false;
bool show_monitor = monitorLifeTime.tv_sec;
CMenuWidget *menu = new CMenuWidget(LOCALE_ADZAP, "settings", width);
menu->addKey(CRCInput::RC_red, this, "disable");

View File

@@ -47,6 +47,7 @@ class CAdZapMenu: public CMenuTarget
t_channel_id channelId;
sem_t sem;
CAdZapMenu();
void Init();
void Settings();
void Update();
void Run(void);