summaryrefslogtreecommitdiff
path: root/epg_item.c
blob: 8ce25bbc6425ee62d81ff253a0e233723b8dfa62 (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
/*
 * epg_item.c: A plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id$
 */

#include <string>
#include <math.h>
#include <vdr/menu.h>
#include <locale.h>
#include <langinfo.h>
#include "epg_item.h"

#define HOURS(x) ((x)/100)
#define MINUTES(x) ((x)%100)

#define SHORTTEXT(EVENT) \
    ((EVENT) && !isempty((EVENT)->ShortText())) ? " ~ ":"", \
((EVENT) && !isempty((EVENT)->ShortText())) ? (EVENT)->ShortText():""

//extern int exitToMainMenu;

// --- Icons ------------------------------------------------------------------
bool Icons::IsUTF8 = false;

void Icons::InitCharSet()
{
    // Taken from VDR's vdr.c
    char *CodeSet = NULL;
    if(setlocale(LC_CTYPE, ""))
        CodeSet = nl_langinfo(CODESET);
    else
    {
        char *LangEnv = getenv("LANG"); // last resort in case locale stuff isn't installed
        if(LangEnv)
        {
            CodeSet = strchr(LangEnv,'.');
            if( CodeSet )
                CodeSet++; // skip the dot
        }
    }

    if( CodeSet && strcasestr(CodeSet,"UTF-8") != 0 )
        IsUTF8 = true;
}


// --- cMenuMyScheduleItem ------------------------------------------------------
    cMenuMyScheduleItem::cMenuMyScheduleItem(const cEvent *Event, cZapHistoryChannel *Channel, int Progress)
:cZapHistoryOsdItem(Channel)
{
    event = Event;
    progress = Progress;
    timerMatch = tmNone;
    Update(true);
}

bool cMenuMyScheduleItem::Update(bool Force)
{
    bool result = false;
    const cChannel* channel = zapChannel->GetChannel();

    eTimerMatch OldTimerMatch = timerMatch;
    cTimer* hasMatch = NULL;

    if (event)
        hasMatch = Timers.GetMatch(event, &timerMatch);

    if (Force || timerMatch != OldTimerMatch) 
    {
        char szChannelpart[20] = "";
        if (channel)
	        snprintf(szChannelpart, 20, "%s\t", channel->Name() );

        char szProgressPart[50] = "";
        if (progress > 0 && channel && event )
        {
            strcpy(szProgressPart, "\t");
            
            if( ZapHistorySetup.ProgressView == 1 ) { // VDRSymbols
                std::string ProgressBar;
                ProgressBar += Icons::ProgressStart();
                int frac = (int)roundf( (float)(time(NULL) - event->StartTime()) / (float)(event->Duration()) * 10.0 );
                frac = min(10,max(0, frac));
                for(int i=0;i < 10;i++)
                {
                    if(i < frac)
                        ProgressBar += Icons::ProgressFilled();
                    else
                        ProgressBar += Icons::ProgressEmpty();
                }
                ProgressBar += Icons::ProgressEnd();
                sprintf(szProgressPart, "%s\t", ProgressBar.c_str());
            } else if( ZapHistorySetup.ProgressView == 0 ) {
                char szProgress[9] = "";
                int frac = (int)roundf( (float)(time(NULL) - event->StartTime()) / (float)(event->Duration()) * 8.0 );
                frac = min(8,max(0, frac));

                for(int i = 0; i < frac; i++)
                    szProgress[i] = (progress == 1 ? '|' : 127);
                szProgress[frac]=0;
                sprintf(szProgressPart, "%c%-8s%c\t", progress==1?'[':128, szProgress, progress==1?']':129);
            } else {
                float frac = (int)roundf( (float)(time(NULL) - event->StartTime()) / (float)(event->Duration()) * 100.0 );
                sprintf(szProgressPart, "%3.0f%%", frac);
            }
        }

        char t = event && hasMatch ? (timerMatch == tmFull) ? 'T' : 't' : ' ';
        char v = event && event->Vps() && (event->Vps() - event->StartTime()) ? 'V' : ' ';
        char r = event && event->IsRunning() ? '*' : ' ';

        char szEventDescr[100] = "";
        snprintf(szEventDescr, 100, "%s%s%s", 
	            event?event->Title():tr("no info"), 
	            SHORTTEXT(event) );

        char *buffer = NULL;
        if (channel) // menu "What's on"
	        asprintf(&buffer, "%s%s\t%s %c%c%c \t%s", 
		            szChannelpart,
		            event?*(event->GetTimeString() ):"", 
		            szProgressPart,
		            t, v, r, 
		            szEventDescr);

        SetText(buffer, false);
        return true;
    }
    return result;
}