From 34f8460e254e2eb7fae1aafcf7c94ca2c3c38b02 Mon Sep 17 00:00:00 2001 From: louis Date: Sat, 20 Jul 2013 13:46:26 +0200 Subject: [PATCH] Added remotetimers support --- HISTORY | 2 + config.c | 4 ++ config.h | 4 +- detailview.c | 26 +++++++++ detailview.h | 1 + epggrid.c | 27 +++++++-- epggrid.h | 4 +- po/de_DE.po | 8 ++- recmanager.c | 145 ++++++++++++++++++++++++++++++++++++++++++----- recmanager.h | 10 +++- recmenumanager.c | 4 +- recmenus.c | 33 +++++++++-- setup.c | 5 ++ tvguideosd.c | 16 +++++- 14 files changed, 260 insertions(+), 29 deletions(-) diff --git a/HISTORY b/HISTORY index 688779e..fa45613 100644 --- a/HISTORY +++ b/HISTORY @@ -57,3 +57,5 @@ VDR Plugin 'tvguide' Revision History - recording folder also choosable for series timers - blue button also available in detail view - color buttons displayed as configured in VDR +- Added Setup Option to define if tvguide closes after channel switching +- Added remotetimers support (thanks @Saman for providing a patch) diff --git a/config.c b/config.c index 5fb64bc..6c2c708 100644 --- a/config.c +++ b/config.c @@ -49,6 +49,8 @@ cTvguideConfig::cTvguideConfig() { channelJumpMode = eNumJump; jumpChannels = 0; blueKeyMode = 0; + closeOnSwitch = 1; + useRemoteTimers = 0; hideLastGroup = 0; hideChannelLogos = 0; logoWidthRatio = 13; @@ -276,6 +278,8 @@ bool cTvguideConfig::SetupParse(const char *Name, const char *Value) { else if (strcmp(Name, "hugeStepHours") == 0) hugeStepHours = atoi(Value); else if (strcmp(Name, "channelJumpMode") == 0) channelJumpMode = atoi(Value); else if (strcmp(Name, "blueKeyMode") == 0) blueKeyMode = atoi(Value); + else if (strcmp(Name, "closeOnSwitch") == 0) closeOnSwitch = atoi(Value); + else if (strcmp(Name, "useRemoteTimers") == 0) useRemoteTimers = atoi(Value); else if (strcmp(Name, "hideLastGroup") == 0) hideLastGroup = atoi(Value); else if (strcmp(Name, "hideEpgImages") == 0) hideEpgImages = atoi(Value); else if (strcmp(Name, "epgImageWidth") == 0) epgImageWidth = atoi(Value); diff --git a/config.h b/config.h index 82cc5fa..e7ae176 100644 --- a/config.h +++ b/config.h @@ -50,6 +50,8 @@ class cTvguideConfig { int channelJumpMode; int jumpChannels; int blueKeyMode; + int closeOnSwitch; + int useRemoteTimers; int hideLastGroup; int hideChannelLogos; int logoWidthRatio; @@ -60,7 +62,7 @@ class cTvguideConfig { int epgImageWidth; int epgImageHeight; int numAdditionalEPGPictures; - int epgImageWidthLarge; + int epgImageWidthLarge; int epgImageHeightLarge; cString epgImagePath; cString iconPath; diff --git a/detailview.c b/detailview.c index dcca130..4f14bba 100644 --- a/detailview.c +++ b/detailview.c @@ -92,6 +92,32 @@ void cDetailView::drawHeader() { cString datetime = cString::sprintf("%s, %s - %s (%d min)", *event->GetDateString(), *event->GetTimeString(), *event->GetEndTimeString(), event->Duration()/60); header->DrawText(cPoint(textX, textY + lineHeight), *datetime, theme.Color(clrFont), colorTextBack, tvguideConfig.FontDetailView); header->DrawText(cPoint(textX, textY + 2 * lineHeight), event->ShortText(), theme.Color(clrFont), colorTextBack, tvguideConfig.FontDetailView); + + eTimerMatch timerMatch=tmNone; + cTimer *ti; + if (tvguideConfig.useRemoteTimers && pRemoteTimers) { + RemoteTimers_GetMatch_v1_0 rtMatch; + rtMatch.event = event; + pRemoteTimers->Service("RemoteTimers::GetMatch-v1.0", &rtMatch); + timerMatch = (eTimerMatch)rtMatch.timerMatch; + ti = rtMatch.timer; + } else { + ti=Timers.GetMatch(event, &timerMatch); + } + if (timerMatch == tmFull) { + drawRecIcon(); + } +} + +void cDetailView::drawRecIcon() { + cString recIconText(" REC "); + int headerWidth = tvguideConfig.osdWidth - 2*borderWidth; + int width = tvguideConfig.FontDetailHeader->Width(*recIconText); + int height = tvguideConfig.FontDetailHeader->Height()+10; + int posX = headerWidth - width - 20; + int posY = 20; + header->DrawRectangle( cRect(posX, posY, width, height), theme.Color(clrButtonRed)); + header->DrawText(cPoint(posX, posY+5), *recIconText, theme.Color(clrFont), theme.Color(clrButtonRed), tvguideConfig.FontDetailHeader); } void cDetailView::drawContent() { diff --git a/detailview.h b/detailview.h index 61128e5..43c73a6 100644 --- a/detailview.h +++ b/detailview.h @@ -28,6 +28,7 @@ private: void loadReruns(void); int heightEPGPics(void); void drawEPGPictures(int height); + void drawRecIcon(void); cImage *createScrollbar(int width, int height, tColor clrBgr, tColor clrBlend); void scrollUp(); void scrollDown(); diff --git a/epggrid.c b/epggrid.c index 434a612..edcf757 100644 --- a/epggrid.c +++ b/epggrid.c @@ -5,11 +5,9 @@ cEpgGrid::cEpgGrid(cChannelColumn *c, const cEvent *event) : cGrid(c) { this->event = event; extText = new cTextWrapper(); hasTimer = false; - if (column->HasTimer()) - hasTimer = event->HasTimer(); + SetTimer(); hasSwitchTimer = false; - if (column->HasSwitchTimer()) - hasSwitchTimer = SwitchTimers.EventInSwitchList(event); + SetSwitchTimer(); dummy = false; } @@ -62,6 +60,27 @@ void cEpgGrid::PositionPixmap() { } +void cEpgGrid::SetTimer() { + if (tvguideConfig.useRemoteTimers && pRemoteTimers) { + RemoteTimers_Event_v1_0 rt; + rt.event = event; + if (pRemoteTimers->Service("RemoteTimers::GetTimerByEvent-v1.0", &rt)) + hasTimer = true; + } else if (column->HasTimer()) { + hasTimer = event->HasTimer(); + } else { + hasTimer = false; + } +} + +void cEpgGrid::SetSwitchTimer() { + if (column->HasSwitchTimer()) { + hasSwitchTimer = SwitchTimers.EventInSwitchList(event); + } else { + hasSwitchTimer = false; + } +} + void cEpgGrid::setText() { if (tvguideConfig.displayMode == eVertical) { cString strText; diff --git a/epggrid.h b/epggrid.h index 0465d06..0bf7536 100644 --- a/epggrid.h +++ b/epggrid.h @@ -20,8 +20,8 @@ public: const cEvent *GetEvent() {return event;}; time_t StartTime() { return event->StartTime(); }; time_t EndTime() { return event->EndTime(); }; - void SetTimer() {hasTimer = event->HasTimer();}; - void SetSwitchTimer() {hasSwitchTimer = SwitchTimers.EventInSwitchList(event);}; + void SetTimer(); + void SetSwitchTimer(); cString getTimeString(void); void debug(); }; diff --git a/po/de_DE.po b/po/de_DE.po index 51ee192..d279b76 100755 --- a/po/de_DE.po +++ b/po/de_DE.po @@ -3,7 +3,7 @@ msgid "" msgstr "" "Project-Id-Version: vdr-tvguide 0.0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2013-07-18 17:18+0200\n" +"POT-Creation-Date: 2013-07-20 12:02+0200\n" "PO-Revision-Date: 2012-08-25 17:49+0200\n" "Last-Translator: Horst\n" "Language-Team: \n" @@ -420,6 +420,9 @@ msgstr "Kanalsprung Modus (Tasten grün / gelb)" msgid "Keys Blue and OK" msgstr "Tasten Blau und OK" +msgid "Close TVGuide after channel switch" +msgstr "TVGuide nach Umschalten schließen" + msgid "Hide last Channel Group" msgstr "Letzte Kanalgruppe verstecken" @@ -438,6 +441,9 @@ msgstr "Zeitformat (12h/24h)" msgid "Use folders for instant records" msgstr "Bei Sofortaufnahmen Verzeichnisse benutzen" +msgid "Use Remotetimers" +msgstr "RemoteTimers benutzen" + msgid "Display Reruns in detailed EPG View" msgstr "Wiederholungen in der detailierten EPG Ansicht anzeigen" diff --git a/recmanager.c b/recmanager.c index b1f21fb..59eddcb 100644 --- a/recmanager.c +++ b/recmanager.c @@ -30,24 +30,95 @@ void cRecManager::SetEPGSearchPlugin(void) { } } +bool cRecManager::RefreshRemoteTimers(void) { + cString errorMsg; + if (!pRemoteTimers->Service("RemoteTimers::RefreshTimers-v1.0", &errorMsg)) { + esyslog("tvguide: %s", *errorMsg); + return false; + } + return true; +} + +bool cRecManager::CheckEventForTimer(const cEvent *event) { + bool hasTimer = false; + + if (tvguideConfig.useRemoteTimers && pRemoteTimers) { + RemoteTimers_GetMatch_v1_0 rtMatch; + rtMatch.event = event; + pRemoteTimers->Service("RemoteTimers::GetMatch-v1.0", &rtMatch); + if (rtMatch.timerMatch == tmFull) + hasTimer = true; + } else + hasTimer = event->HasTimer(); + + return hasTimer; +} + +cTimer *cRecManager::GetTimerForEvent(const cEvent *event) { + cTimer *timer = NULL; + if (tvguideConfig.useRemoteTimers && pRemoteTimers) { + RemoteTimers_GetMatch_v1_0 rtMatch; + rtMatch.event = event; + pRemoteTimers->Service("RemoteTimers::GetMatch-v1.0", &rtMatch); + timer = rtMatch.timer; + } else + timer = Timers.GetMatch(event); + return timer; +} + cTimer *cRecManager::createTimer(const cEvent *event, std::string path) { + cTimer *timer = NULL; + if (tvguideConfig.useRemoteTimers && pRemoteTimers) { + timer = createRemoteTimer(event, path); + } else { + timer = createLocalTimer(event, path); + } + return timer; +} + +cTimer *cRecManager::createLocalTimer(const cEvent *event, std::string path) { cTimer *timer = new cTimer(event); - Timers.Add(timer); + cTimer *t = Timers.GetTimer(timer); + if (t) { + t->OnOff(); + t->SetEventFromSchedule(); + delete timer; + timer = t; + isyslog("timer %s reactivated", *t->ToDescr()); + } else { + Timers.Add(timer); + isyslog("timer %s added (active)", *timer->ToDescr()); + } + SetTimerPath(timer, path); Timers.SetModified(); + return timer; +} + +cTimer *cRecManager::createRemoteTimer(const cEvent *event, std::string path) { + cTimer *t = new cTimer(event); + SetTimerPath(t, path); + RemoteTimers_Timer_v1_0 rt; + rt.timer = t; + pRemoteTimers->Service("RemoteTimers::GetTimer-v1.0", &rt.timer); + if (rt.timer) { + rt.timer->OnOff(); + if (!pRemoteTimers->Service("RemoteTimers::ModTimer-v1.0", &rt)) + rt.timer = NULL; + } else { + rt.timer = t; + if (!pRemoteTimers->Service("RemoteTimers::NewTimer-v1.0", &rt)) + isyslog("%s", *rt.errorMsg); + } + RefreshRemoteTimers(); + return rt.timer; +} + +void cRecManager::SetTimerPath(cTimer *timer, std::string path) { if (path.size() > 0) { std::replace(path.begin(), path.end(), '/', '~'); cString newFileName = cString::sprintf("%s~%s", path.c_str(), timer->File()); timer->SetFile(*newFileName); } - isyslog("timer %s added (active)", *timer->ToDescr()); - return timer; -} - -void cRecManager::DeleteTimer(const cEvent *event) { - cTimer *t = Timers.GetMatch(event); - if (!t) - return; - DeleteTimer(t); } void cRecManager::DeleteTimer(int timerID) { @@ -57,6 +128,22 @@ void cRecManager::DeleteTimer(int timerID) { DeleteTimer(t); } +void cRecManager::DeleteTimer(const cEvent *event) { + if (tvguideConfig.useRemoteTimers && pRemoteTimers) { + DeleteRemoteTimer(event); + } else { + DeleteLocalTimer(event); + } +} + +void cRecManager::DeleteLocalTimer(const cEvent *event) { + cTimer *t = Timers.GetMatch(event); + if (!t) + return; + DeleteTimer(t); +} + + void cRecManager::DeleteTimer(cTimer *timer) { if (timer->Recording()) { timer->Skip(); @@ -67,6 +154,20 @@ void cRecManager::DeleteTimer(cTimer *timer) { Timers.SetModified(); } +void cRecManager::DeleteRemoteTimer(const cEvent *event) { + RemoteTimers_GetMatch_v1_0 rtMatch; + rtMatch.event = event; + pRemoteTimers->Service("RemoteTimers::GetMatch-v1.0", &rtMatch); + if (rtMatch.timer) { + RemoteTimers_Timer_v1_0 rt; + rt.timer = rtMatch.timer; + isyslog("remotetimer %s deleted", *rt.timer->ToDescr()); + if (!pRemoteTimers->Service("RemoteTimers::DelTimer-v1.0", &rt)) + isyslog("remotetimer error"); + RefreshRemoteTimers(); + } +} + void cRecManager::SaveTimer(cTimer *timer, cRecMenu *menu) { if (!timer) return; @@ -90,7 +191,15 @@ void cRecManager::SaveTimer(cTimer *timer, cRecMenu *menu) { timer->SetFlags(tfActive); timer->SetEventFromSchedule(); - Timers.SetModified(); + if (tvguideConfig.useRemoteTimers && pRemoteTimers) { + RemoteTimers_Timer_v1_0 rt; + rt.timer = timer; + if (!pRemoteTimers->Service("RemoteTimers::ModTimer-v1.0", &rt)) + rt.timer = NULL; + RefreshRemoteTimers(); + } else { + Timers.SetModified(); + } } bool cRecManager::IsRecorded(const cEvent *event) { @@ -227,8 +336,18 @@ cTimer *cRecManager::CreateSeriesTimer(cRecMenu *menu, std::string path) { else seriesTimer->SetFlags(tfNone); seriesTimer->SetEventFromSchedule(); - Timers.Add(seriesTimer); - Timers.SetModified(); + + if (tvguideConfig.useRemoteTimers && pRemoteTimers) { + RemoteTimers_Timer_v1_0 rt; + rt.timer = seriesTimer; + if (!pRemoteTimers->Service("RemoteTimers::NewTimer-v1.0", &rt)) + isyslog("%s", *rt.errorMsg); + RefreshRemoteTimers(); + seriesTimer = NULL; + } else { + Timers.Add(seriesTimer); + Timers.SetModified(); + } return seriesTimer; } diff --git a/recmanager.h b/recmanager.h index 648d4c2..6deb681 100644 --- a/recmanager.h +++ b/recmanager.h @@ -30,9 +30,17 @@ public: cRecManager (void); void SetEPGSearchPlugin(void); bool EpgSearchAvailable(void) {return epgSearchAvailable;}; + bool RefreshRemoteTimers(void); + bool CheckEventForTimer(const cEvent *event); + cTimer *GetTimerForEvent(const cEvent *event); cTimer *createTimer(const cEvent *event, std::string path); - void DeleteTimer(const cEvent *event); + cTimer *createLocalTimer(const cEvent *event, std::string path); + cTimer *createRemoteTimer(const cEvent *event, std::string path); + void SetTimerPath(cTimer *timer, std::string path); void DeleteTimer(int timerID); + void DeleteTimer(const cEvent *event); + void DeleteLocalTimer(const cEvent *event); + void DeleteRemoteTimer(const cEvent *event); void SaveTimer(cTimer *timer, cRecMenu *menu); bool IsRecorded(const cEvent *event); std::vector CheckTimerConflict(void); diff --git a/recmenumanager.c b/recmenumanager.c index 17d89ec..0e4871d 100644 --- a/recmenumanager.c +++ b/recmenumanager.c @@ -38,7 +38,7 @@ void cRecMenuManager::Start(const cEvent *event) { detailViewActive = false; SetBackground(); this->event = event; - activeMenu = new cRecMenuMain(recManager->EpgSearchAvailable(), event->HasTimer(), SwitchTimers.EventInSwitchList(event)); + activeMenu = new cRecMenuMain(recManager->EpgSearchAvailable(), recManager->CheckEventForTimer(event), SwitchTimers.EventInSwitchList(event)); activeMenu->Display(); osdManager.flush(); } @@ -180,7 +180,7 @@ eOSState cRecMenuManager::StateMachine(eRecMenuState nextState) { break; case rmsEditTimer: { //edit timer for active event - timer = Timers.GetMatch(event); + timer = recManager->GetTimerForEvent(event); if (timer) { delete activeMenu; activeMenu = new cRecMenuEditTimer(timer, rmsSaveTimer); diff --git a/recmenus.c b/recmenus.c index 0327a10..0676240 100644 --- a/recmenus.c +++ b/recmenus.c @@ -116,7 +116,18 @@ public: SetWidthPercent(50); cString channelName = Channels.GetByChannelID(event->ChannelID())->Name(); cString message; - if (event->HasTimer()) { + bool eventHasTimer = false; + if (tvguideConfig.useRemoteTimers && pRemoteTimers) { + RemoteTimers_GetMatch_v1_0 rtMatch; + rtMatch.event = event; + pRemoteTimers->Service("RemoteTimers::GetMatch-v1.0", &rtMatch); + if (rtMatch.timerMatch == tmFull) { + eventHasTimer = true; + } + } else { + eventHasTimer = event->HasTimer(); + } + if (eventHasTimer) { message = tr("Timer created"); } else { message = tr("Timer NOT created"); @@ -322,7 +333,18 @@ public: infoItem->CalculateHeight(width - 2 * border); AddMenuItem(infoItem); - bool timerActive = timer->HasFlags(tfActive); + bool timerActive = false; + if (tvguideConfig.useRemoteTimers && pRemoteTimers) { + RemoteTimers_GetMatch_v1_0 rtMatch; + rtMatch.event = timer->Event(); + pRemoteTimers->Service("RemoteTimers::GetMatch-v1.0", &rtMatch); + if (rtMatch.timer) { + if (rtMatch.timerMatch == tmFull) + timerActive = true; + } + } else + timerActive = timer->HasFlags(tfActive); + time_t day = timer->Day(); int start = timer->Start(); int stop = timer->Stop(); @@ -395,8 +417,11 @@ public: cRecMenuConfirmSeriesTimer(cTimer *seriesTimer) { SetWidthPercent(50); cString message = tr("Series Timer created"); - cString days = cTimer::PrintDay(seriesTimer->Day(), seriesTimer->WeekDays(), true); - cString infoText = cString::sprintf("%s\n%s, %s: %s, %s: %s", *message, *days, tr("Start"), *TimeString(seriesTimer->StartTime()), tr("Stop"), *TimeString(seriesTimer->StopTime())); + cString infoText = message; + if (seriesTimer) { + cString days = cTimer::PrintDay(seriesTimer->Day(), seriesTimer->WeekDays(), true); + infoText = cString::sprintf("%s\n%s, %s: %s, %s: %s", *message, *days, tr("Start"), *TimeString(seriesTimer->StartTime()), tr("Stop"), *TimeString(seriesTimer->StopTime())); + } cRecMenuItemInfo *infoItem = new cRecMenuItemInfo(*infoText); infoItem->CalculateHeight(width - 2 * border); AddMenuItem(infoItem); diff --git a/setup.c b/setup.c index 2197a6e..b38e838 100644 --- a/setup.c +++ b/setup.c @@ -65,6 +65,8 @@ void cTvguideSetup::Store(void) { SetupStore("hugeStepHours", tvguideConfig.hugeStepHours); SetupStore("channelJumpMode", tvguideConfig.channelJumpMode); SetupStore("blueKeyMode", tvguideConfig.blueKeyMode); + SetupStore("useRemoteTimers", tvguideConfig.useRemoteTimers); + SetupStore("closeOnSwitch", tvguideConfig.closeOnSwitch); SetupStore("hideLastGroup", tvguideConfig.hideLastGroup); SetupStore("hideChannelLogos", tvguideConfig.hideChannelLogos); SetupStore("logoExtension", tvguideConfig.logoExtension); @@ -163,12 +165,15 @@ void cMenuSetupGeneral::Set(void) { Add(new cMenuEditStraItem(tr("Channel Jump Mode (Keys Green / Yellow)"), &tmpTvguideConfig->channelJumpMode, 2, jumpMode)); Add(new cMenuEditStraItem(tr("Keys Blue and OK"), &tmpTvguideConfig->blueKeyMode, 2, blueMode)); + Add(new cMenuEditBoolItem(tr("Close TVGuide after channel switch"), &tmpTvguideConfig->closeOnSwitch)); Add(new cMenuEditBoolItem(tr("Hide last Channel Group"), &tmpTvguideConfig->hideLastGroup)); Add(new cMenuEditIntItem(tr("Time to display in minutes"), &tmpTvguideConfig->displayTime, 120, 320)); Add(new cMenuEditIntItem(tr("Big Step (Keys 1 / 3) in hours"), &tmpTvguideConfig->bigStepHours, 1, 12)); Add(new cMenuEditIntItem(tr("Huge Step (Keys 4 / 6) in hours"), &tmpTvguideConfig->hugeStepHours, 13, 48)); Add(new cMenuEditStraItem(tr("Time Format (12h/24h)"), &tmpTvguideConfig->timeFormat, 2, timeFormatItems)); Add(new cMenuEditBoolItem(tr("Use folders for instant records"), &tmpTvguideConfig->recMenuAskFolder)); + if (pRemoteTimers) + Add(new cMenuEditBoolItem(tr("Use Remotetimers"), &tmpTvguideConfig->useRemoteTimers)); Add(new cMenuEditBoolItem(tr("Display Reruns in detailed EPG View"), &tmpTvguideConfig->displayRerunsDetailEPGView)); if (tmpTvguideConfig->displayRerunsDetailEPGView) { Add(new cMenuEditIntItem(cString::sprintf("%s%s", indent, tr("Number of reruns to display")), &tmpTvguideConfig->numReruns, 1, 10)); diff --git a/tvguideosd.c b/tvguideosd.c index dd701d0..6c0b582 100644 --- a/tvguideosd.c +++ b/tvguideosd.c @@ -60,6 +60,9 @@ cTvguideConfig tvguideConfig; cOsdManager osdManager; #include "services/epgsearch.h" +#include "services/remotetimers.h" +cPlugin* pRemoteTimers = NULL; + #include "tools.c" #include "switchtimer.c" #include "setup.c" @@ -122,6 +125,16 @@ void cTvGuideOsd::Show(void) { myTime->Now(); SwitchTimers.Load(AddDirectory(cPlugin::ConfigDirectory("epgsearch"), "epgsearchswitchtimers.conf")); recMenuManager = new cRecMenuManager(); + pRemoteTimers = cPluginManager::CallFirstService("RemoteTimers::RefreshTimers-v1.0", NULL); + if (pRemoteTimers) { + isyslog("tvguide: remotetimers-plugin is available"); + } + if (tvguideConfig.useRemoteTimers && pRemoteTimers) { + cString errorMsg; + if (!pRemoteTimers->Service("RemoteTimers::RefreshTimers-v1.0", &errorMsg)) { + esyslog("tvguide: %s", *errorMsg); + } + } drawOsd(); } esyslog("tvguide: Rendering took %d ms", int(cTimeMs::Now()-start)); @@ -556,7 +569,8 @@ eOSState cTvGuideOsd::ChannelSwitch() { const cChannel *currentChannel = activeGrid->column->getChannel(); if (currentChannel) { cDevice::PrimaryDevice()->SwitchChannel(currentChannel, true); - return osEnd; + if (tvguideConfig.closeOnSwitch) + return osEnd; } return osContinue; }