adzap: re-format code

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

Origin message was:
------------------
- adzap: re-format code
This commit is contained in:
vanhofen
2016-02-28 01:21:36 +01:00
parent 06aae05e48
commit f7997f67e0
2 changed files with 229 additions and 237 deletions

View File

@@ -1,31 +1,25 @@
/* /*
* adzap.cpp adzap.cpp
*
* (C)2012-2013 by martii (C) 2012-2013 by martii
* (C) 2016 Sven Hoefer (svenhoefer)
* License: GPL
* License: GPL
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by This program is free software; you can redistribute it and/or modify
* the Free Software Foundation; either version 2 of the License, or it under the terms of the GNU General Public License as published by
* (at your option) any later version. the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of This program is distributed in the hope that it will be useful,
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the but WITHOUT ANY WARRANTY; without even the implied warranty of
* GNU General Public License for more details. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software You should have received a copy of the GNU General Public License
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. along with this program; if not, write to the Free Software
*/ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
/*
* AS SOME FOLKS DON'T SEEM TO UNDERSTAND THE GPL: YOU ARE FREE TO USE
* THIS CODE FOR YOUR OWN LITTLE STB IMAGE. BUT IF YOU ARE DISTRIBUTING
* THAT IMAGE, YOU ARE BOUND TO THE GPL, AND YOU HAVE TO DISTRIBUTE THE
* SOURCE CODE, TOO. IF YOU DON'T: A) YOU ACKNOWLEDGE THAT YOU'RE AN
* ABSOLUTE JERK, AND B) YOU'RE NOT PERMITTED TO USE THIS CODE. AT ALL.
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
@@ -101,63 +95,72 @@ void *CAdZapMenu::Run(void *arg)
void CAdZapMenu::Run() void CAdZapMenu::Run()
{ {
set_threadname("CAdZapMenu::Run"); set_threadname("CAdZapMenu::Run");
while (true) { while (true)
{
CChannelList *channelList = NULL; CChannelList *channelList = NULL;
t_channel_id curChannelId = -1; t_channel_id curChannelId = -1;
if (monitor) { if (monitor)
{
struct timespec ts; struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts); clock_gettime(CLOCK_REALTIME, &ts);
ts.tv_sec += 1; ts.tv_sec += 1;
sem_timedwait(&sem, &ts); sem_timedwait(&sem, &ts);
if (monitor && (monitorLifeTime.tv_sec > ts.tv_sec)) { if (monitor && (monitorLifeTime.tv_sec > ts.tv_sec))
{
channelList = CNeutrinoApp::getInstance()->channelList; channelList = CNeutrinoApp::getInstance()->channelList;
curChannelId = curChannelId = channelList ? channelList->getActiveChannel_ChannelID() : -1;
channelList ? channelList->getActiveChannel_ChannelID() if (!armed && (channelId != curChannelId))
: -1; {
if (!armed && (channelId != curChannelId)) {
armed = true; armed = true;
clock_gettime(CLOCK_REALTIME, &zapBackTime); clock_gettime(CLOCK_REALTIME, &zapBackTime);
zapBackTime.tv_sec += zapBackTime.tv_sec += g_settings.adzap_zapBackPeriod - ZAPBACK_ALERT_PERIOD;
g_settings.adzap_zapBackPeriod -
ZAPBACK_ALERT_PERIOD;
alerted = false; alerted = false;
} else if (channelId == curChannelId) { }
else if (channelId == curChannelId)
{
armed = false; armed = false;
alerted = false; alerted = false;
} }
} else { }
else
{
monitor = false; monitor = false;
armed = false; armed = false;
alerted = false; alerted = false;
} }
} else if (armed) }
else if (armed)
sem_timedwait(&sem, &zapBackTime); sem_timedwait(&sem, &zapBackTime);
else else
sem_wait(&sem); sem_wait(&sem);
if (armed) { if (armed)
{
struct timespec ts; struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts); clock_gettime(CLOCK_REALTIME, &ts);
if (ts.tv_sec >= zapBackTime.tv_sec) { if (ts.tv_sec >= zapBackTime.tv_sec)
if (!channelList) { {
if (!channelList)
{
channelList = CNeutrinoApp::getInstance()->channelList; channelList = CNeutrinoApp::getInstance()->channelList;
curChannelId = curChannelId = channelList ? channelList->getActiveChannel_ChannelID() : -1;
channelList ?
channelList->getActiveChannel_ChannelID() : -1;
} }
if (!alerted) { if (!alerted)
if (channelId != curChannelId) { {
std::string name = if (channelId != curChannelId)
g_Locale->getText(LOCALE_ADZAP_ANNOUNCE); {
std::string name = g_Locale->getText(LOCALE_ADZAP_ANNOUNCE);
name += "\n" + channelName; name += "\n" + channelName;
ShowHint(LOCALE_ADZAP, name.c_str()); ShowHint(LOCALE_ADZAP, name.c_str());
} }
alerted = true; alerted = true;
zapBackTime.tv_sec += ZAPBACK_ALERT_PERIOD; zapBackTime.tv_sec += ZAPBACK_ALERT_PERIOD;
} else { }
else
{
alerted = false; alerted = false;
if (channelList) if (channelList)
channelList->zapTo_ChannelID(channelId); channelList->zapTo_ChannelID(channelId);
@@ -172,29 +175,32 @@ int CAdZapMenu::exec(CMenuTarget *parent, const std::string & actionKey)
{ {
int res = menu_return::RETURN_EXIT_ALL; int res = menu_return::RETURN_EXIT_ALL;
if (actionKey == "enable") { if (actionKey == "enable")
{
if (!monitor) if (!monitor)
armed = true; armed = true;
alerted = false; alerted = false;
Update(); Update();
return res; return res;
} }
if (actionKey == "disable") { if (actionKey == "disable")
{
armed = false; armed = false;
monitor = false; monitor = false;
alerted = false; alerted = false;
Update(); Update();
return res; return res;
} }
if (actionKey == "monitor") { if (actionKey == "monitor")
{
armed = false; armed = false;
monitor = true; monitor = true;
alerted = false; alerted = false;
Update(); Update();
return res; return res;
} }
if (actionKey == "adzap")
if (actionKey == "adzap") { {
if (armed || monitor) { if (armed || monitor) {
armed = false; armed = false;
monitor = false; monitor = false;
@@ -204,7 +210,8 @@ int CAdZapMenu::exec(CMenuTarget *parent, const std::string & actionKey)
return res; return res;
} }
} }
if (actionKey.length() == 1) { if (actionKey.length() == 1)
{
g_settings.adzap_zapBackPeriod = actionKey[0] - '0'; g_settings.adzap_zapBackPeriod = actionKey[0] - '0';
for (int shortcut = 1; shortcut < 10; shortcut++) for (int shortcut = 1; shortcut < 10; shortcut++)
forwarders[shortcut - 1]->setMarked(shortcut == g_settings.adzap_zapBackPeriod); forwarders[shortcut - 1]->setMarked(shortcut == g_settings.adzap_zapBackPeriod);
@@ -223,24 +230,18 @@ int CAdZapMenu::exec(CMenuTarget *parent, const std::string & actionKey)
void CAdZapMenu::Settings() void CAdZapMenu::Settings()
{ {
CChannelList *channelList = CNeutrinoApp::getInstance()->channelList; CChannelList *channelList = CNeutrinoApp::getInstance()->channelList;
channelId = channelId = channelList ? channelList->getActiveChannel_ChannelID() : -1;
channelList ? channelList->getActiveChannel_ChannelID() : -1;
channelName = channelList->getActiveChannelName(); channelName = channelList->getActiveChannelName();
CMenuWidget *menu = new CMenuWidget(LOCALE_ADZAP, "settings", width); CMenuWidget *menu = new CMenuWidget(LOCALE_ADZAP, "settings", width);
menu->addItem(new menu->addItem(new CMenuSeparator(CMenuSeparator::LINE | CMenuSeparator::STRING, LOCALE_ADZAP_SWITCHBACK));
CMenuSeparator(CMenuSeparator::LINE |
CMenuSeparator::STRING,
LOCALE_ADZAP_SWITCHBACK));
neutrino_locale_t minute = LOCALE_ADZAP_MINUTE; neutrino_locale_t minute = LOCALE_ADZAP_MINUTE;
for (int shortcut = 1; shortcut < 10; shortcut++) { for (int shortcut = 1; shortcut < 10; shortcut++) {
char actionKey[2]; char actionKey[2];
actionKey[0] = '0' + shortcut; actionKey[0] = '0' + shortcut;
actionKey[1] = 0; actionKey[1] = 0;
bool selected = g_settings.adzap_zapBackPeriod == 60 * shortcut; bool selected = g_settings.adzap_zapBackPeriod == 60 * shortcut;
forwarders[shortcut - 1] = forwarders[shortcut - 1] = new CMenuForwarder(minute, true, NULL, this, actionKey, CRCInput::convertDigitToKey(shortcut));
new CMenuForwarder(minute, true, NULL, this, actionKey,
CRCInput::convertDigitToKey(shortcut));
forwarders[shortcut - 1]->setMarked(selected); forwarders[shortcut - 1]->setMarked(selected);
menu->addItem(forwarders[shortcut - 1], selected); menu->addItem(forwarders[shortcut - 1], selected);
minute = LOCALE_ADZAP_MINUTES; minute = LOCALE_ADZAP_MINUTES;
@@ -248,28 +249,22 @@ void CAdZapMenu::Settings()
menu->addItem(GenericMenuSeparatorLine); menu->addItem(GenericMenuSeparatorLine);
menu->addItem(new menu->addItem(new CMenuForwarder(LOCALE_ADZAP_DISABLE, true, NULL, this, "disable", CRCInput::RC_red));
CMenuForwarder(LOCALE_ADZAP_DISABLE, true, NULL, this, menu->addItem(new CMenuForwarder(LOCALE_ADZAP_ENABLE, true, NULL, this, "enable", CRCInput::RC_green));
"disable", CRCInput::RC_red,
NEUTRINO_ICON_BUTTON_RED));
menu->addItem(new
CMenuForwarder(LOCALE_ADZAP_ENABLE, true, NULL, this,
"enable", CRCInput::RC_green,
NEUTRINO_ICON_BUTTON_GREEN));
CChannelEventList evtlist; CChannelEventList evtlist;
CEitManager::getInstance()->getEventsServiceKey(channelId & CEitManager::getInstance()->getEventsServiceKey(channelId & 0xFFFFFFFFFFFFULL, evtlist);
0xFFFFFFFFFFFFULL,
evtlist);
monitorLifeTime.tv_sec = 0; monitorLifeTime.tv_sec = 0;
if (!evtlist.empty()) { if (!evtlist.empty())
{
sort(evtlist.begin(), evtlist.end(), sortByDateTime); sort(evtlist.begin(), evtlist.end(), sortByDateTime);
CChannelEventList::iterator eli; CChannelEventList::iterator eli;
struct timespec ts; struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts); clock_gettime(CLOCK_REALTIME, &ts);
for (eli = evtlist.begin(); eli != evtlist.end(); ++eli) { for (eli = evtlist.begin(); eli != evtlist.end(); ++eli)
if ((u_int) eli->startTime + (u_int) eli->duration > {
(u_int) ts.tv_sec) { if ((u_int) eli->startTime + (u_int) eli->duration > (u_int) ts.tv_sec)
{
monitorLifeTime.tv_sec = (uint) eli->startTime + eli->duration; monitorLifeTime.tv_sec = (uint) eli->startTime + eli->duration;
Update(); Update();
break; break;
@@ -277,11 +272,7 @@ void CAdZapMenu::Settings()
} }
} }
menu->addItem(new menu->addItem(new CMenuForwarder(LOCALE_ADZAP_MONITOR, monitorLifeTime.tv_sec, NULL, this, "monitor", CRCInput::RC_blue));
CMenuForwarder(LOCALE_ADZAP_MONITOR,
monitorLifeTime.tv_sec, NULL, this,
"monitor", CRCInput::RC_blue,
NEUTRINO_ICON_BUTTON_BLUE));
monitor = false; monitor = false;
menu->exec(NULL, ""); menu->exec(NULL, "");

View File

@@ -1,25 +1,26 @@
/* /*
* adzap.h adzap.h
*
* (C)2012 by martii
*
* License: GPL
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
(C) 2012-2013 by martii
(C) 2016 Sven Hoefer (svenhoefer)
License: GPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __adzap__ #ifndef __adzap__
#define __adzap__ #define __adzap__