summaryrefslogtreecommitdiff
path: root/control.c
blob: 051e4561ef53e6bec09b70ae861c2ae53e6b0057 (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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/**
 * based on control.c,v 1.4 2007/06/18 17:58:52 lordjaxom
 *
 * version by Midas
 *
 */

#include "control.h"
#include "config.h"
#include "common.h"

#include <vdr/remote.h>

inline uint64_t BlockTimeout() { return SetupBlock.MessageTimeout * 1000; }

bool cControlBlock::mRequested = false;

cControlBlock::cControlBlock(const cChannel *Channel, const cEvent *Present, const cEvent *Following):
    cControl(new cPlayer),
		mChannel(Channel),
		mPresent(Present),
		mFollowing(Following),
		mStart(0),
		mSwitch(true),
		mOsd(NULL),
		direction(0)
{
#if APIVERSNUM >= 10500
	SetNeedsFastResponse(true);
#else
	needsFastResponse = true;
#endif

  cRemote::Put(kBack,true); //Hide OSD new version
}

cControlBlock::~cControlBlock()
{
	if (mOsd != NULL)
		delete mOsd;
        if (mRequested)
        {
#ifdef LOGGING
          dsyslog("plugin-block: userint user requested to watch blocked channel");
#endif  
          //if (mChannel!=0)
          if (mChannel != NULL)
          {
            cDevice::PrimaryDevice()->SwitchChannel(mChannel, true);
          }
          else
          {
             //don't know if this is necessary - just taken from plugin taste
             //seems that mChannel cannot be 0 because it is an object reference
             //changed that to NULL
             dsyslog("plugin-block: userint Cannot switch - channel unknown!");
          }
          mRequested=false;
        }

	if (mSwitch) {
	        int lastchannel=cSetupBlock::LastChannel;
		// possibly first or last available channel, fall back to old channel

		if (direction == 0)
			direction = 1;
		if (!cDevice::SwitchChannel(direction) && (lastchannel != 0))
			Channels.SwitchTo(lastchannel);

	}
}

void cControlBlock::Show(void)
{
	if (mOsd == NULL)
		mOsd = Skins.Current()->DisplayChannel(true);

	mOsd->SetChannel(mChannel, 0);
	mOsd->SetEvents(mPresent, mFollowing);
	mOsd->SetMessage(mtError, tr("Current show blocked!"));
	mOsd->Flush();

	mStart = time_ms();
}

eOSState cControlBlock::ProcessKey(eKeys Key)
{
#ifdef LOGGING
	dsyslog("plugin-block: userint cControlBlock::ProcessKey(%d) this = %p", Key, this);
#endif

  switch (Key) {

	case kOk:
#ifdef LOGGING
		dsyslog("plugin-block: userint Processing 'Ok' event");
#endif		
		if (cSetupBlock::OkAllowed==1)
		{
		  mRequested = true;
		  mSwitch = false;
		  return osEnd;
                }
                else
                {
                  mRequested = false;
                  mSwitch = true;
                  if (mOsd != NULL)
                  {
                    mOsd->SetMessage(mtError, tr("Permission denied!"));
                    mOsd->Flush();
                  }
                }
                return osContinue;
                
	case kNone:
#ifdef LOGGING
dsyslog("plugin-block: userint Processing kNone (no user interaction)");
#endif
		if (mStart == 0)
		{
			Show();
                }
		else if (time_ms() - mStart > BlockTimeout()) {
		direction = mChannel->Number() - cSetupBlock::LastChannel;
			mSwitch = true;
			return osEnd;
		}
	  return osContinue;

	case kChanUp:
                //workaround cause 'normal' code wont work here; vdr does not react on code/destructor here o.O
                //this is because in case of chan +/- keys have a chance to get eaten by vdr itself
                cRemote::Put(kUp,true);
                return osContinue;
                break;
        
	case kUp:                
#ifdef LOGGING
dsyslog("plugin-block: userint Processing up event (userrequest)");
#endif
		if (mStart == 0)
			Show();
		else 
		{
		  mRequested=false;//TODO:necessary? as above
		  direction = 1;
		  mSwitch = true;
		  return osEnd;
		}
	        break;

	case kChanDn:
                //workaround cause 'normal' code wont work here; vdr does not react on code/destructor here o.O
                //this is because in case of chan +/- keys have a chance to get eaten by vdr itself
                cRemote::Put(kDown,true);
                return osContinue;
                break;
        
	case kDown:
#ifdef LOGGING
dsyslog("plugin-block: userint Processing down event (userrequest)");
#endif
		if (mStart == 0)
			Show();
		else 
		{
		  mRequested=false;//TODO:necessary? as above
		  direction = -1;
		  mSwitch = true;
		  return osEnd;
		}
	        break;

        default:
                break;
  }
  return osContinue;
}