summaryrefslogtreecommitdiff
path: root/detailview.c
blob: ca351ab3e9daceeb6f6441261d7247e62b6b0399 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include "detailview.h"

cDetailView::cDetailView(const cEvent *event, cFooter *footer) {
    this->event = event;
    this->footer = footer;
}

cDetailView::~cDetailView(void){
    Cancel(-1);
    while (Active())
        cCondWait::SleepMs(10);
    footer->LeaveDetailedViewMode(Channels.GetByChannelID(event->ChannelID()));
    if (view)
        delete view;
}

void cDetailView::InitiateView(void) {
    static cPlugin *pScraper2Vdr = cPluginManager::GetPlugin("scraper2vdr");
    ScraperGetEventType call;
    if (!event)
        return;
    call.event = event;
    if (!pScraper2Vdr) {
        view = new cEPGView();
    } else if (pScraper2Vdr->Service("GetEventType", &call)) {
        if (call.type == tMovie) {
            view = new cMovieView(call.movieId);
        } else if (call.type == tSeries) {
            view = new cSeriesView(call.seriesId, call.episodeId);
        }
    } else {
        view = new cEPGView();                
    }
    view->SetTitle(event->Title());
    view->SetSubTitle(event->ShortText());
    view->SetInfoText(event->Description());
    cString dateTime;
    time_t vps = event->Vps();
    if (vps) {
        dateTime = cString::sprintf("%s  %s - %s (%d %s) VPS: %s", *event->GetDateString(), *event->GetTimeString(), *event->GetEndTimeString(), event->Duration()/60, tr("min"), *TimeString(vps));
    } else {
        dateTime = cString::sprintf("%s  %s - %s (%d %s)", *event->GetDateString(), *event->GetTimeString(), *event->GetEndTimeString(), event->Duration()/60, tr("min"));
    }
    view->SetDateTime(*dateTime);
    view->SetChannel(Channels.GetByChannelID(event->ChannelID(), true));
    view->SetEventID(event->EventID());
    view->SetEvent(event);
}

std::string cDetailView::LoadReruns(void) {
    if (!event)
        return "";
    
    cPlugin *epgSearchPlugin = cPluginManager::GetPlugin("epgsearch");
    if (!epgSearchPlugin)
        return "";

    if (isempty(event->Title()))
        return "";
    
    std::stringstream sstrReruns;
    sstrReruns << tr("Reruns of ") << "\"" << event->Title() << "\":" << std::endl << std::endl;

    Epgsearch_searchresults_v1_0 data;
    std::string strQuery = event->Title();

    if (tvguideConfig.displayRerunsDetailEPGView > 0) {
        if (tvguideConfig.useSubtitleRerun == 2 && !isempty(event->ShortText())) {
            strQuery += "~";
            strQuery += event->ShortText();
        }
        data.useSubTitle = true;
    } else {
        data.useSubTitle = false;
    }
    data.query = (char *)strQuery.c_str();
    data.mode = 0;
    data.channelNr = 0;
    data.useTitle = true;
    data.useDescription = false;

    bool foundRerun = false;
    if (epgSearchPlugin->Service("Epgsearch-searchresults-v1.0", &data)) {
        cList<Epgsearch_searchresults_v1_0::cServiceSearchResult>* list = data.pResultList;
        if (list && (list->Count() > 1)) {
            foundRerun = true;
            int i = 0;
            for (Epgsearch_searchresults_v1_0::cServiceSearchResult *r = list->First(); r && i < tvguideConfig.numReruns; r = list->Next(r)) {
                if ((event->ChannelID() == r->event->ChannelID()) && (event->StartTime() == r->event->StartTime()))
                    continue;
                i++;
                sstrReruns  << *DayDateTime(r->event->StartTime());
                cChannel *channel = Channels.GetByChannelID(r->event->ChannelID(), true, true);
                if (channel) {
                    sstrReruns << ", " << trVDR("Channel") << " " << channel->Number() << ":";
                    sstrReruns << " " << channel->ShortName(true);
                }
                sstrReruns << "\n" << r->event->Title();
                if (!isempty(r->event->ShortText()))
                    sstrReruns << "~" << r->event->ShortText();
                sstrReruns << std::endl << std::endl;
            }
            delete list;
        }
    }

    if (!foundRerun) {
        sstrReruns << std::endl << tr("No reruns found");        
    }
    return sstrReruns.str();
}


void cDetailView::Action(void) {
    InitiateView();
    if (!view)
        return;
    view->SetFonts();
    view->SetGeometry();
    view->LoadMedia();
    view->Start();
    if (event)
        view->SetAdditionalInfoText(LoadReruns());
}

eOSState cDetailView::ProcessKey(eKeys Key) {
    eOSState state = osContinue;
    if (Running())
        return state;
    switch (Key & ~k_Repeat) {
        case kUp: {
            bool scrolled = view->KeyUp();
            if (scrolled) {
                view->DrawScrollbar();
                osdManager.flush();
            }
            break; }
        case kDown: {
            bool scrolled = view->KeyDown();
            if (scrolled) {
                view->DrawScrollbar();
                osdManager.flush();
            }
            break; }
        case kLeft:
            view->KeyLeft();
            view->Start();
            break;
        case kRight:
            view->KeyRight();
            view->Start();
            break;
        case kOk:
        case kBack:
            state = osEnd;
            break;
    }
    return state;
}