diff --git a/src/gui/timerlist.cpp b/src/gui/timerlist.cpp index f751add38..557e1f56e 100644 --- a/src/gui/timerlist.cpp +++ b/src/gui/timerlist.cpp @@ -335,7 +335,7 @@ int CTimerList::exec(CMenuTarget* parent, const std::string & actionKey) } return menu_return::RETURN_EXIT; } - else if (strcmp(key, "send_remotetimer") == 0) + else if ((strcmp(key, "send_remotetimer") == 0) && remoteChanExists(timerlist[selected].channel_id)) { CHTTPTool httpTool; std::string r_url; @@ -354,7 +354,7 @@ int CTimerList::exec(CMenuTarget* parent, const std::string & actionKey) if (r_url=="ok") Timer->removeTimerEvent(timerlist[selected].eventID); } - else if (strcmp(key, "fetch_remotetimer") == 0) + else if ((strcmp(key, "fetch_remotetimer") == 0) && localChanExists(timerlist[selected].channel_id)) { CHTTPTool httpTool; std::string r_url; @@ -570,6 +570,41 @@ void CTimerList::updateEvents(void) y = getScreenStartY(height); } +bool CTimerList::remoteChanExists(t_channel_id channel_id) +{ + if (g_settings.remotebox_address.empty()) + return false; + CHTTPTool httpTool; + std::string r_url; + r_url = "http://"; + r_url += g_settings.remotebox_address; + r_url += "/control/getchannel?format=json&id="; + r_url += string_printf_helper(PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS, channel_id); + r_url = httpTool.downloadString(r_url); + + Json::Value root; + Json::Reader reader; + bool parsedSuccess = reader.parse(r_url, root, false); + if (!parsedSuccess) { + printf("Failed to parse JSON\n"); + printf("%s\n", reader.getFormattedErrorMessages().c_str()); + } + + r_url = root.get("success","false").asString(); + return (r_url == "true"); +} + +bool CTimerList::localChanExists(t_channel_id channel_id) +{ + if (g_settings.remotebox_address.empty()) + return false; + CZapitChannel * channel = CServiceManager::getInstance()->FindChannel(channel_id); + if (channel) + return true; + else + return false; +} + void CTimerList::remoteTimerList(CTimerd::TimerList &rtimerlist) { if (g_settings.remotebox_address.empty()) diff --git a/src/gui/timerlist.h b/src/gui/timerlist.h index 4c83cc467..1f84e1f46 100644 --- a/src/gui/timerlist.h +++ b/src/gui/timerlist.h @@ -87,6 +87,8 @@ class CTimerList : public CMenuTarget, public CListHelpers int saved_dispmode; void remoteTimerList(CTimerd::TimerList &timerlist); void enterRemoteBox(); + bool remoteChanExists(t_channel_id channel_id); + bool localChanExists(t_channel_id channel_id); int rem_pre,rem_post; public: