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,32 +1,26 @@
/* /*
* adzap.cpp adzap.cpp
*
* (C)2012-2013 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
* AS SOME FOLKS DON'T SEEM TO UNDERSTAND THE GPL: YOU ARE FREE TO USE (C) 2016 Sven Hoefer (svenhoefer)
* 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 License: GPL
* 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. 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.
*/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
@@ -50,242 +44,239 @@ static CAdZapMenu *azm = NULL;
CAdZapMenu *CAdZapMenu::getInstance() CAdZapMenu *CAdZapMenu::getInstance()
{ {
if (!azm) if (!azm)
azm = new CAdZapMenu(); azm = new CAdZapMenu();
return azm; return azm;
} }
CAdZapMenu::CAdZapMenu() CAdZapMenu::CAdZapMenu()
{ {
frameBuffer = CFrameBuffer::getInstance(); frameBuffer = CFrameBuffer::getInstance();
width = w_max(40, 10); width = w_max(40, 10);
hheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight(); hheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight();
mheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight(); mheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight();
height = hheight + 13 * mheight + 10; height = hheight + 13 * mheight + 10;
x = (((g_settings.screen_EndX - g_settings.screen_StartX) - width) / 2) + g_settings.screen_StartX; x = (((g_settings.screen_EndX - g_settings.screen_StartX) - width) / 2) + g_settings.screen_StartX;
y = (((g_settings.screen_EndY - g_settings.screen_StartY) - height) / 2) + g_settings.screen_StartY; y = (((g_settings.screen_EndY - g_settings.screen_StartY) - height) / 2) + g_settings.screen_StartY;
sem_init(&sem, 0, 0); sem_init(&sem, 0, 0);
pthread_t thr; pthread_t thr;
if (pthread_create(&thr, 0, CAdZapMenu::Run, this)) if (pthread_create(&thr, 0, CAdZapMenu::Run, this))
fprintf(stderr, "ERROR: pthread_create(CAdZapMenu::CAdZapMenu)\n"); fprintf(stderr, "ERROR: pthread_create(CAdZapMenu::CAdZapMenu)\n");
else else
pthread_detach(thr); pthread_detach(thr);
channelId = -1; channelId = -1;
armed = false; armed = false;
monitor = false; monitor = false;
alerted = false; alerted = false;
} }
static bool sortByDateTime(const CChannelEvent & a, const CChannelEvent & b) static bool sortByDateTime(const CChannelEvent & a, const CChannelEvent & b)
{ {
return a.startTime < b.startTime; return a.startTime < b.startTime;
} }
void CAdZapMenu::Update() void CAdZapMenu::Update()
{ {
clock_gettime(CLOCK_REALTIME, &zapBackTime); clock_gettime(CLOCK_REALTIME, &zapBackTime);
zapBackTime.tv_sec += g_settings.adzap_zapBackPeriod - ZAPBACK_ALERT_PERIOD; zapBackTime.tv_sec += g_settings.adzap_zapBackPeriod - ZAPBACK_ALERT_PERIOD;
sem_post(&sem); sem_post(&sem);
} }
void *CAdZapMenu::Run(void *arg) void *CAdZapMenu::Run(void *arg)
{ {
CAdZapMenu *me = (CAdZapMenu *) arg; CAdZapMenu *me = (CAdZapMenu *) arg;
me->Run(); me->Run();
pthread_exit(NULL); pthread_exit(NULL);
} }
void CAdZapMenu::Run() void CAdZapMenu::Run()
{ {
set_threadname("CAdZapMenu::Run"); set_threadname("CAdZapMenu::Run");
while (true) { while (true)
CChannelList *channelList = NULL; {
t_channel_id curChannelId = -1; CChannelList *channelList = NULL;
t_channel_id curChannelId = -1;
if (monitor) { if (monitor)
struct timespec ts; {
clock_gettime(CLOCK_REALTIME, &ts); struct timespec ts;
ts.tv_sec += 1; clock_gettime(CLOCK_REALTIME, &ts);
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; {
curChannelId = channelList = CNeutrinoApp::getInstance()->channelList;
channelList ? channelList->getActiveChannel_ChannelID() curChannelId = channelList ? channelList->getActiveChannel_ChannelID() : -1;
: -1; if (!armed && (channelId != curChannelId))
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 - alerted = false;
ZAPBACK_ALERT_PERIOD; }
alerted = false; else if (channelId == curChannelId)
} else if (channelId == curChannelId) { {
armed = false; armed = false;
alerted = false; alerted = false;
}
}
else
{
monitor = false;
armed = false;
alerted = false;
}
} }
} else { else if (armed)
monitor = false; sem_timedwait(&sem, &zapBackTime);
armed = false; else
alerted = false; sem_wait(&sem);
}
} else if (armed)
sem_timedwait(&sem, &zapBackTime);
else
sem_wait(&sem);
if (armed) { if (armed)
struct timespec ts; {
clock_gettime(CLOCK_REALTIME, &ts); struct timespec ts;
if (ts.tv_sec >= zapBackTime.tv_sec) { clock_gettime(CLOCK_REALTIME, &ts);
if (!channelList) { if (ts.tv_sec >= zapBackTime.tv_sec)
channelList = CNeutrinoApp::getInstance()->channelList; {
curChannelId = if (!channelList)
channelList ? {
channelList->getActiveChannel_ChannelID() : -1; channelList = CNeutrinoApp::getInstance()->channelList;
curChannelId = channelList ? channelList->getActiveChannel_ChannelID() : -1;
}
if (!alerted)
{
if (channelId != curChannelId)
{
std::string name = g_Locale->getText(LOCALE_ADZAP_ANNOUNCE);
name += "\n" + channelName;
ShowHint(LOCALE_ADZAP, name.c_str());
}
alerted = true;
zapBackTime.tv_sec += ZAPBACK_ALERT_PERIOD;
}
else
{
alerted = false;
if (channelList)
channelList->zapTo_ChannelID(channelId);
armed = false;
}
}
} }
if (!alerted) {
if (channelId != curChannelId) {
std::string name =
g_Locale->getText(LOCALE_ADZAP_ANNOUNCE);
name += "\n" + channelName;
ShowHint(LOCALE_ADZAP, name.c_str());
}
alerted = true;
zapBackTime.tv_sec += ZAPBACK_ALERT_PERIOD;
} else {
alerted = false;
if (channelList)
channelList->zapTo_ChannelID(channelId);
armed = false;
}
}
} }
}
} }
int CAdZapMenu::exec(CMenuTarget *parent, const std::string & actionKey) 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) {
armed = true; if (!monitor)
alerted = false; armed = true;
Update(); alerted = false;
return res; Update();
} return res;
if (actionKey == "disable") { }
armed = false; if (actionKey == "disable")
monitor = false; {
alerted = false; armed = false;
Update(); monitor = false;
return res; alerted = false;
} Update();
if (actionKey == "monitor") { return res;
armed = false; }
monitor = true; if (actionKey == "monitor")
alerted = false; {
Update(); armed = false;
return res; monitor = true;
} alerted = false;
Update();
if (actionKey == "adzap") { return res;
if (armed || monitor) { }
armed = false; if (actionKey == "adzap")
monitor = false; {
alerted = false; if (armed || monitor) {
Update(); armed = false;
ShowHint(LOCALE_ADZAP, LOCALE_ADZAP_CANCEL, 450, 1); monitor = false;
return res; alerted = false;
Update();
ShowHint(LOCALE_ADZAP, LOCALE_ADZAP_CANCEL, 450, 1);
return res;
}
}
if (actionKey.length() == 1)
{
g_settings.adzap_zapBackPeriod = actionKey[0] - '0';
for (int shortcut = 1; shortcut < 10; shortcut++)
forwarders[shortcut - 1]->setMarked(shortcut == g_settings.adzap_zapBackPeriod);
g_settings.adzap_zapBackPeriod *= 60;
return menu_return::RETURN_REPAINT;
} }
}
if (actionKey.length() == 1) {
g_settings.adzap_zapBackPeriod = actionKey[0] - '0';
for (int shortcut = 1; shortcut < 10; shortcut++)
forwarders[shortcut - 1]->setMarked(shortcut == g_settings.adzap_zapBackPeriod);
g_settings.adzap_zapBackPeriod *= 60;
return menu_return::RETURN_REPAINT;
}
if (parent) if (parent)
parent->hide(); parent->hide();
Settings(); Settings();
return res; return res;
} }
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 | neutrino_locale_t minute = LOCALE_ADZAP_MINUTE;
CMenuSeparator::STRING, for (int shortcut = 1; shortcut < 10; shortcut++) {
LOCALE_ADZAP_SWITCHBACK)); char actionKey[2];
neutrino_locale_t minute = LOCALE_ADZAP_MINUTE; actionKey[0] = '0' + shortcut;
for (int shortcut = 1; shortcut < 10; shortcut++) { actionKey[1] = 0;
char actionKey[2]; bool selected = g_settings.adzap_zapBackPeriod == 60 * shortcut;
actionKey[0] = '0' + shortcut; forwarders[shortcut - 1] = new CMenuForwarder(minute, true, NULL, this, actionKey, CRCInput::convertDigitToKey(shortcut));
actionKey[1] = 0; forwarders[shortcut - 1]->setMarked(selected);
bool selected = g_settings.adzap_zapBackPeriod == 60 * shortcut; menu->addItem(forwarders[shortcut - 1], selected);
forwarders[shortcut - 1] = minute = LOCALE_ADZAP_MINUTES;
new CMenuForwarder(minute, true, NULL, this, actionKey,
CRCInput::convertDigitToKey(shortcut));
forwarders[shortcut - 1]->setMarked(selected);
menu->addItem(forwarders[shortcut - 1], selected);
minute = LOCALE_ADZAP_MINUTES;
}
menu->addItem(GenericMenuSeparatorLine);
menu->addItem(new
CMenuForwarder(LOCALE_ADZAP_DISABLE, true, NULL, this,
"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;
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;
}
} }
}
menu->addItem(new menu->addItem(GenericMenuSeparatorLine);
CMenuForwarder(LOCALE_ADZAP_MONITOR,
monitorLifeTime.tv_sec, NULL, this,
"monitor", CRCInput::RC_blue,
NEUTRINO_ICON_BUTTON_BLUE));
monitor = false; menu->addItem(new CMenuForwarder(LOCALE_ADZAP_DISABLE, true, NULL, this, "disable", CRCInput::RC_red));
menu->exec(NULL, ""); menu->addItem(new CMenuForwarder(LOCALE_ADZAP_ENABLE, true, NULL, this, "enable", CRCInput::RC_green));
menu->hide();
delete menu; CChannelEventList evtlist;
Update(); 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;
}
}
}
menu->addItem(new CMenuForwarder(LOCALE_ADZAP_MONITOR, monitorLifeTime.tv_sec, NULL, this, "monitor", CRCInput::RC_blue));
monitor = false;
menu->exec(NULL, "");
menu->hide();
delete menu;
Update();
} }

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__
@@ -58,4 +59,4 @@ class CAdZapMenu: public CMenuTarget
static CAdZapMenu *getInstance(); static CAdZapMenu *getInstance();
int exec(CMenuTarget * parent, const std::string & actionKey); int exec(CMenuTarget * parent, const std::string & actionKey);
}; };
#endif // __adzap__ #endif // __adzap__