2 Copyright 2004-2007 Chris Tallon, 2014 Marten Richter
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "vepglistadvanced.h"
33 #include "movieinfo.h"
34 #include "seriesinfo.h"
37 #include "vepgsummary.h"
38 #include "vepgsettimer.h"
40 #include "staticartwork.h"
45 VEpgListAdvanced::VEpgListAdvanced(VVideoLiveTV *tvideolive, ChannelList* tchanList,ULONG initialChannelNumber)
47 channelNumber = initialChannelNumber;
49 videolive = tvideolive;
50 boxstack = BoxStack::getInstance();
54 setSize(640+40, 500+40); //old setSize(570, 420);
60 setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
61 TVMediaInfo *info= new TVMediaInfo();
62 info->setChannelLogo(channelNumber);
63 info->setStaticFallback(sa_tv);
64 setTitleBarIcon(info);
66 sl.setPosition(10, 30 + 5);
67 sl.setSize(area.w*42/100 - 20, area.h - 30 - 15 - 30);
68 sl.setLinesPerOption(2.4f);
71 Region slarea=sl.getRegionR();
73 epg.setParaMode(true);
74 epg.setPosition(slarea.x +slarea.w+10 ,30+5);
75 epg.setSize(area.w -slarea.x -slarea.w -10, area.h - 30 - 15 - 30);
78 epg.setVideoBackground();
79 epg.setBackgroundColour(DrawStyle::VIEWTRANSPARENTBACKGROUND);
81 epgTVmedia.setPosition(epg.getRegionR().w-100-10,10);
82 epgTVmedia.setSize(100,(UINT)(150/Osd::getInstance()->getPixelAspect()));
85 boxRed.setBackgroundColour(DrawStyle::RED);
86 boxRed.setPosition(165 /*54*/, sl.getY2()+8);
87 boxRed.setSize(18, 16);
90 textRed.setPosition(boxRed.getX2(), sl.getY2()+4);
91 textRed.setSize(116, 30);
95 boxGreen.setBackgroundColour(DrawStyle::GREEN);
96 boxGreen.setPosition(165 +1*110, sl.getY2()+8);
97 boxGreen.setSize(18, 16);
100 textGreen.setPosition(boxGreen.getX2(), sl.getY2()+4);
101 textGreen.setSize(116, 30);
104 boxYellow.setBackgroundColour(DrawStyle::YELLOW);
105 boxYellow.setPosition(165 +2*110, sl.getY2()+8);
106 boxYellow.setSize(18, 16);
109 textYellow.setPosition(boxYellow.getX2(), sl.getY2()+4);
110 textYellow.setSize(116, 30);
113 boxBlue.setBackgroundColour(DrawStyle::BLUE);
114 boxBlue.setPosition(165 +3*110, sl.getY2()+8);
115 boxBlue.setSize(18, 16);
118 textBlue.setPosition(boxBlue.getX2(), sl.getY2()+4);
119 textBlue.setSize(116, 30);
125 updateEpgDataChannel();
128 VEpgListAdvanced::~VEpgListAdvanced()
134 void VEpgListAdvanced::setButtonText()
139 textRed.setText(tr("Record"));
140 textGreen.setText(tr("Now"));
141 textYellow.setText(tr("Next"));
142 textBlue.setText(tr("Guide"));
146 textRed.setText(tr("Record"));
147 textGreen.setText(tr("Next"));
148 textYellow.setText(tr("Schedule"));
149 textBlue.setText(tr("Switch"));
152 textRed.setText(tr("Record"));
153 textGreen.setText(tr("Now"));
154 textYellow.setText(tr("Schedule"));
155 textBlue.setText(tr("Switch"));
161 void VEpgListAdvanced::doRed()
166 void VEpgListAdvanced::doGreen()
180 void VEpgListAdvanced::doYellow()
194 void VEpgListAdvanced::doBlue()
208 void VEpgListAdvanced::doNext()
210 Log::getInstance()->log("VEventListAdvanced", Log::DEBUG, "doNext");
211 if (mode!=OneChannel) {
212 Channel * chan=(*chanList)[ sl.getCurrentOptionData()];
213 channelNumber = chan->number;
216 updateEpgDataNowNext(true);
218 TVMediaInfo *info= new TVMediaInfo();
219 info->setStaticArtwork(sa_tv);
220 setTitleBarIcon(info);
222 boxstack->update(this);
224 void VEpgListAdvanced::doNow()
226 Log::getInstance()->log("VEventListAdvanced", Log::DEBUG, "doNow");
227 if (mode!=OneChannel) {
228 Channel * chan=(*chanList)[ sl.getCurrentOptionData()];
229 channelNumber = chan->number;
232 updateEpgDataNowNext(true);
234 TVMediaInfo *info= new TVMediaInfo();
235 info->setStaticArtwork(sa_tv);
236 setTitleBarIcon(info);
238 boxstack->update(this);
241 void VEpgListAdvanced::doProgramm()
243 Log::getInstance()->log("VEventListAdvanced", Log::DEBUG, "doProgram");
246 Channel * chan=(*chanList)[ sl.getCurrentOptionData()];
247 channelNumber = chan->number;
248 updateEpgDataChannel();
250 TVMediaInfo *info= new TVMediaInfo();
251 info->setChannelLogo(channelNumber);
252 info->setStaticFallback(sa_tv);
253 setTitleBarIcon(info);
255 boxstack->update(this);
258 void VEpgListAdvanced::doSwitch()
263 if (mode!=OneChannel) {
264 Channel * chan=(*chanList)[ sl.getCurrentOptionData()];
265 channelNumber = chan->number;
267 Log::getInstance()->log("VEventListAdvanced", Log::DEBUG, "doSwitch %d", channelNumber);
268 Message* m = new Message(); // Must be done after this view deleted
271 m->message = Message::CHANNEL_CHANGE;
272 m->parameter.num = channelNumber;
274 Command::getInstance()->postMessageNoLock(m);
278 void VEpgListAdvanced::doRecord()
281 Event* current = getCurrentOptionEvent(channel);
284 Log::getInstance()->log("VEventListAdvanced", Log::DEBUG, "Found the option you pointed at. %s %d", current->title, current->id);
285 unsigned int chanlistsize=chanList->size();
288 for(listIndex = 0; listIndex < chanlistsize; listIndex++)
290 chan = (*chanList)[listIndex];
291 if ((int)chan->number == channel) break;
294 Log::getInstance()->log("VEpgSummary", Log::DEBUG, "ID %lu TIME %lu DURATION %lu TITLE %s", current->id, current->time,
295 current->duration, current->title);
296 VEpgSetTimer* vs = new VEpgSetTimer(current, chan);
299 boxstack->update(vs);
304 void VEpgListAdvanced::doGrid()
307 if (mode!=OneChannel) {
308 Channel * chan=(*chanList)[ sl.getCurrentOptionData()];
309 channelNumber = chan->number;
312 unsigned int chanlistsize=chanList->size();
314 for(listIndex = 0; listIndex < chanlistsize; listIndex++)
316 chan = (*chanList)[listIndex];
317 if (chan->number == channelNumber) break;
320 VEpg* vepg = new VEpg(videolive, listIndex, chanList);
323 boxstack->update(vepg);
327 void VEpgListAdvanced::clearEventList()
329 std::vector<EventList*>::iterator itty = eventLista.begin();
330 while (itty!= eventLista.end()) {
344 * if (!chanList) return;
346 for(UINT listIndex = 0; listIndex < gridRows; listIndex++)
348 if(listTop + listIndex >= UINT(chanListbox.getBottomOption()))
350 chan = (*chanList)[listTop + listIndex];
351 eventLista[listIndex] = VDR::getInstance()->getChannelSchedule(chan->number, ltime - 1, window_width * 60 + 2); // ltime - 1 to get prog before window (allows cursor left past ltime). + 2 to get prog after window
356 void VEpgListAdvanced::updateEpgData()
361 //updateEpgDataChannel();
365 updateEpgDataNowNext(false);
371 void VEpgListAdvanced::updateEpgDataNowNext(bool changeState)
376 unsigned int chanlistsize=chanList->size();
379 eventLista.resize(chanList->size());
381 for(UINT listIndex = 0; listIndex < chanlistsize; listIndex++)
383 if (listIndex < 0) continue;
384 if (listIndex >= chanlistsize) continue;
385 chan = (*chanList)[listIndex];
386 if (chan->number == channelNumber) {
387 startupdate = listIndex-sl.getNumOptionsDisplayable()-2;
388 endupdate = listIndex+sl.getNumOptionsDisplayable()+2;
393 startupdate=sl.getTopOption()-2;
394 endupdate=sl.getBottomOption()+1;
401 for(int listIndex = startupdate; listIndex < endupdate; listIndex++)
403 if (listIndex < 0) continue;
404 if (listIndex >= (int)chanlistsize) continue;
406 chan = (*chanList)[listIndex];
407 if (!eventLista[listIndex]) eventLista[listIndex] = VDR::getInstance()->getChannelSchedule(chan->number, now, 4 * 60 *60);
413 void VEpgListAdvanced::updateEpgDataChannel()
416 eventLista.resize(1);
419 eventLista[0] = VDR::getInstance()->getChannelSchedule(channelNumber, now, 24 * 60 *60 *30); // one month
420 Log::getInstance()->log("VEventListAdvanced", Log::DEBUG, "Eventlist %x %d", eventLista[0],channelNumber);
424 void VEpgListAdvanced::drawData(bool doIndexPop)
429 drawDataChannel(doIndexPop);
432 drawDataNowNext(true, doIndexPop);
435 drawDataNowNext(false, doIndexPop);
441 void VEpgListAdvanced::drawDataChannel(bool doIndexPop)
443 int saveIndex = sl.getCurrentOption();
444 int saveTop = sl.getTopOption();
448 sl.addColumn(25 + 7);
449 sl.addColumn(25 + 7+ 7);
454 char tempA[300]; // FIXME this is guesswork!
455 char tempB[300]; // FIXME
456 char tempC[300]; // FIXME
462 Event* currentEvent = NULL;
463 EventList::iterator j;
464 EventList* eventList = eventLista[0];
466 for (j = eventList->begin(); j != eventList->end(); j++)
469 time_t eventStartTime = (time_t)currentEvent->time;
470 time_t eventEndTime = (time_t)(currentEvent->time + currentEvent->duration);
472 localtime_r(&eventStartTime, &btime);
473 strftime(tempA, 299, "%d/%m/%y %H:%M ", &btime);
474 localtime_r(&eventEndTime, &btime);
475 strftime(tempB, 299, "- %H:%M ", &btime);
477 sprintf(tempC, "\t %s\n \t \t%s%s", currentEvent->title,tempA,tempB);
479 TVMediaInfo *info= new TVMediaInfo();
480 info->setPosterThumb(channelNumber, currentEvent->id);
481 info->setStaticFallback(sa_defposter);
482 currentEvent->index = sl.addOption(tempC, currentEvent->id, first, info);
489 sl.hintSetCurrent(0);
493 sl.hintSetCurrent(saveIndex);
494 sl.hintSetTop(saveTop);
500 void VEpgListAdvanced::drawDataNowNext(bool next, bool doIndexPop)
502 int saveIndex = sl.getCurrentOption();
503 int saveTop = sl.getTopOption();
511 char tempA[300]; // FIXME this is guesswork!
512 char tempB[300]; // FIXME
513 char tempC[300]; // FIXME
519 Event* currentEvent = NULL;
520 EventList::iterator j;
522 if (next) minevents++;
523 int setcurrenthelper =0;
525 unsigned int chanlistsize=chanList->size();
526 for(UINT listIndex = 0; listIndex < chanlistsize; listIndex++)
529 chan = (*chanList)[listIndex];
531 EventList* eventList = eventLista[listIndex];
532 if (eventList && ((int)eventList->size() >= minevents)) {
533 j = eventList->begin();
535 currentEvent = j[minevents-1];
536 time_t eventStartTime = (time_t)currentEvent->time;
537 time_t eventEndTime = (time_t)(currentEvent->time + currentEvent->duration);
539 localtime_r(&eventStartTime, &btime);
540 strftime(tempA, 299, "%H:%M ", &btime);
541 localtime_r(&eventEndTime, &btime);
542 strftime(tempB, 299, "- %H:%M ", &btime);
544 sprintf(tempC, "%s\n%s\t %s%s", currentEvent->title, chan->name,tempA,tempB);
547 sprintf(tempC, "\n%s", chan->name);
550 TVMediaInfo *info= new TVMediaInfo();
551 if ((*chanList)[listIndex]->number == channelNumber) {
553 setcurrenthelper = listIndex;
555 info->setChannelLogo((*chanList)[listIndex]->number);
556 info->setStaticFallback(sa_tv);
557 int index =sl.addOption(tempC, listIndex, first, info);
558 if (currentEvent) currentEvent->index = index;
564 sl.hintSetCurrent(setcurrenthelper);
568 sl.hintSetCurrent(saveIndex);
569 sl.hintSetTop(saveTop);
574 void VEpgListAdvanced::draw(bool doIndexPop)
577 // Single channel mode
581 unsigned int chanlistsize=chanList->size();
584 for(listIndex = 0; listIndex < chanlistsize; listIndex++)
586 chan = (*chanList)[listIndex];
587 if (chan->number == channelNumber) break;
589 sprintf(tempA, tr("Schedule - %s"), (*chanList)[listIndex]->name);
593 setTitleText(tr("Now"));
596 setTitleText(tr("Next"));
602 drawData(doIndexPop);
616 localtime_r(&now, &btime);
617 strftime(freeSpace, 299, "%d/%m/%y", &btime);
619 drawTextRJ(freeSpace, getWidth(), 5, DrawStyle::LIGHTTEXT);
625 w.nextSymbol = WSymbol::UP;
626 w.setPosition(20, area.h-35);
628 w.nextSymbol = WSymbol::DOWN;
629 w.setPosition(50, area.h-35);
631 w.nextSymbol = WSymbol::SKIPBACK;
632 w.setPosition(85, area.h-35);
634 w.nextSymbol = WSymbol::SKIPFORWARD;
635 w.setPosition(115, area.h-35);
638 drawTextRJ(tr("[ok] = info"), 560+70, sl.getY2()+4, DrawStyle::LIGHTTEXT);
640 // All static stuff done
645 Event* VEpgListAdvanced::getCurrentOptionEvent(int& channel)
647 // version for channel
648 Event* currentEvent = NULL;
649 EventList::iterator j;
650 EventList* eventList = NULL;
654 eventList = eventLista[0];
656 channel = channelNumber;
657 for (j = eventList->begin(); j != eventList->end(); j++)
660 if (currentEvent->index == sl.getCurrentOption()) return currentEvent;
666 eventList = eventLista[sl.getCurrentOptionData()];
667 channel = (*chanList)[sl.getCurrentOptionData()]->number;
670 if (eventList && eventList->size()>1) {
671 j = eventList->begin();
678 eventList = eventLista[sl.getCurrentOptionData()];
679 channel = (*chanList)[sl.getCurrentOptionData()]->number;
681 if (eventList && eventList->size()>0) {
682 j = eventList->begin();
697 void VEpgListAdvanced::updateSelection()
700 if (mode==OneChannel) {
701 TVMediaInfo *info= new TVMediaInfo();
702 info->setChannelLogo(channelNumber);
703 info->setStaticFallback(sa_tv);
704 setTitleBarIcon(info);
706 Event* toShow = getCurrentOptionEvent(channel);
709 toShow->loadinfos(channel);
710 std::stringstream description;
712 description << "\n"<< toShow->title << "\n\n";
713 description << toShow->subtitle <<"\n";
714 description << toShow->description;
718 if (toShow->movieInfo) {
719 poster=toShow->movieInfo->poster;
721 if (toShow->seriesInfo) {
722 if (toShow->seriesInfo->seasonposter.height) {
723 poster=toShow->seriesInfo->seasonposter;
725 else if (toShow->seriesInfo->posters.size()) {
726 poster=toShow->seriesInfo->posters[0];
730 epgTVmedia.setTVMedia(poster.info, WTVMedia::ZoomHorizontal);
731 epgTVmedia.setVisible(true);
733 if (toShow->epgImage)
736 info.setPosterThumb(channel,toShow->id);
737 epgTVmedia.setTVMedia(info, WTVMedia::ZoomHorizontal);
738 epgTVmedia.setVisible(true);
739 }else if (mode!=OneChannel) {
741 info.setChannelLogo(channel);
742 epgTVmedia.setTVMedia(info, WTVMedia::ZoomHorizontal);
743 epgTVmedia.setVisible(true);
745 epgTVmedia.setVisible(false);
749 epg.setText(description.str().c_str());
752 if (mode!=OneChannel) {
754 info.setChannelLogo(channel);
755 epgTVmedia.setTVMedia(info, WTVMedia::ZoomHorizontal);
756 epgTVmedia.setVisible(true);
758 epgTVmedia.setVisible(false);
764 int VEpgListAdvanced::handleCommand(int command)
774 boxstack->update(this);
777 case Remote::DF_DOWN:
783 boxstack->update(this);
786 case Remote::SKIPBACK:
791 boxstack->update(this);
794 case Remote::SKIPFORWARD:
799 boxstack->update(this);
824 if (sl.getNumOptions() == 0) return 2;
828 Event* current = getCurrentOptionEvent(channel);
831 Log::getInstance()->log("VEventListAdvanced", Log::DEBUG, "Found the option you pointed at. %s %d", current->title, current->id);
832 unsigned int chanlistsize=chanList->size();
835 for(listIndex = 0; listIndex < chanlistsize; listIndex++)
837 chan = (*chanList)[listIndex];
838 if ((int)chan->number == channel) break;
841 VEpgSummary* vr = new VEpgSummary(current, (*chanList)[listIndex]);
844 boxstack->update(vr);
848 // should not get to here
856 // stop command getting to any more views
860 void VEpgListAdvanced::processMessage(Message* m)
862 Log::getInstance()->log("VEpgListAdvanced", Log::DEBUG, "Got message value %lu", m->message);
864 if (m->message == Message::MOUSE_MOVE)
866 if (sl.mouseMove((m->parameter.num>>16)-getScreenX(),(m->parameter.num&0xFFFF)-getScreenY()))
869 boxstack->update(this);
872 else if (m->message == Message::MOUSE_LBDOWN)
874 if (sl.mouseLBDOWN((m->parameter.num>>16)-getScreenX(),(m->parameter.num&0xFFFF)-getScreenY()))
876 boxstack->handleCommand(Remote::OK); //simulate OK press
878 else if (boxRed.mouseLBDOWN((m->parameter.num >> 16) - getScreenX(), (m->parameter.num & 0xFFFF) - getScreenY()))
880 boxstack->handleCommand(Remote::RED);
882 else if (boxGreen.mouseLBDOWN((m->parameter.num >> 16) - getScreenX(), (m->parameter.num & 0xFFFF) - getScreenY()))
884 boxstack->handleCommand(Remote::GREEN);
886 else if (boxYellow.mouseLBDOWN((m->parameter.num >> 16) - getScreenX(), (m->parameter.num & 0xFFFF) - getScreenY()))
888 boxstack->handleCommand(Remote::GREEN);
890 else if (boxBlue.mouseLBDOWN((m->parameter.num >> 16) - getScreenX(), (m->parameter.num & 0xFFFF) - getScreenY()))
892 boxstack->handleCommand(Remote::GREEN);
896 //check if press is outside this view! then simulate cancel
897 int x=(m->parameter.num>>16)-getScreenX();
898 int y=(m->parameter.num&0xFFFF)-getScreenY();
899 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
901 boxstack->handleCommand(Remote::BACK); //simulate cancel press
909 void VEpgListAdvanced::quickUpdate() { //only quick for plattform that need it!
912 #ifdef GRADIENT_DRAWING