summaryrefslogtreecommitdiff
path: root/tvtv.c
blob: c96e1bb2dbf5936b42b0999d732c96c5e6726ef2 (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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/*
 * tvtv.c: TVTV plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 */

#include "config.h"
#include "update.h"


static const char *VERSION        = "0.3.3p8";
static const char *DESCRIPTION    = "TVTV Timers update";
static const char *MAINMENUENTRY  = "TVTV";

cUpdate *oUpdate;

class cPluginTVTV : public cPlugin {
private:
#if VDRVERSNUM >= 10307
  cSkinDisplayMessage *displayMessage;
#endif
public:
  cPluginTVTV(void);
  virtual ~cPluginTVTV();
  virtual const char *Version(void) { return VERSION; }
  virtual const char *Description(void) { return tr(DESCRIPTION); }
  virtual const char *CommandLineHelp(void);
#if VDRVERSNUM >= 10331
  virtual const char **SVDRPHelpPages(void);
  virtual cString SVDRPCommand(const char *Cmd, const char *Option, int &ReplyCode);
#endif
  virtual bool Start(void);
  virtual const char *MainMenuEntry(void) { return (TVTVConfig.show_in_mainmenu ? MAINMENUENTRY : NULL); }
  virtual cOsdMenu *MainMenuAction(void);
  virtual cMenuSetupPage *SetupMenu(void);
  virtual bool SetupParse(const char *Name, const char *Value);

  void DisplayMessage(const char *s);
  };

// --- cMenuSetupTVTV -------------------------------------------------------

class cMenuSetupTVTV : public cMenuSetupPage {
private:
  cTVTVConfig data; 
  virtual void Setup(void);
  const char *cRecordNames[eRecordName_MAX];
  const char *timeshiftbugfixmodes[eTimeShiftBugfixMAX];
  const char *timezonebugfixmodes[eTimeZoneBugfixMAX];
protected:
  virtual eOSState ProcessKey(eKeys Key);
  virtual void Store(void);
public:
  cMenuSetupTVTV(void);
  };

cMenuSetupTVTV::cMenuSetupTVTV(void) {
  data = TVTVConfig;
  Setup();
}

void cMenuSetupTVTV::Setup(void) {
  int current = Current();
  
  Clear();

  cRecordNames[eRecordName_Title]             = tr("Title");
  cRecordNames[eRecordName_NatureTitle]       = tr("Nature/Title");
  cRecordNames[eRecordName_TitleNature]       = tr("Title/Nature");
  cRecordNames[eRecordName_FormatNatureTitle] = tr("Format/Nature/Title");
  cRecordNames[eRecordName_FormatTitleNature] = tr("Format/Title/Nature");

  timeshiftbugfixmodes[eTimeShiftBugfixOff]    = tr("off");
  timeshiftbugfixmodes[eTimeShiftBugfixAuto]   = tr("auto (timezone)");
  timeshiftbugfixmodes[eTimeShiftBugfixManual] = tr("manual");

  timezonebugfixmodes[eTimeZoneBugfixOff]          = tr("off");
  timezonebugfixmodes[eTimeZoneBugfixAuto]         = tr("auto (timezone)");
  timezonebugfixmodes[eTimeZoneBugfixManual]       = tr("manual");
  timezonebugfixmodes[eTimeZoneBugfixManualDST]    = tr("manual (DST only)");
  timezonebugfixmodes[eTimeZoneBugfixManualNonDST] = tr("manual (non-DST only)");
  timezonebugfixmodes[eTimeZoneBugfixIgnore]       = tr("ignore timezone");

  Add(new cMenuEditStraItem(  tr("TVTV Server"), &data.tvtv_server, TVTVSRV_CNT, TVTV_SERVERS));
  Add(new cMenuEditStrItem(   tr("TVTV User Name"), data.username, sizeof(data.username), tr(FileNameChars)));
  Add(new cMenuEditStrItem(   tr("TVTV Password"), data.password, sizeof(data.password), tr(FileNameChars)));
  Add(new cMenuEditBoolItem(  tr("Use HTTP Proxy"), &data.useproxy));
  if (data.useproxy)
    Add(new cMenuEditStrItem( tr("  HTTP Proxy"), data.httpproxy, sizeof(data.httpproxy), tr(FileNameChars)));
  Add(new cMenuEditBoolItem(  tr("Auto Update"), &data.autoupdate));
  Add(new cMenuEditIntItem(   tr("Updatetime (min)"), &data.updatetime));
  Add(new cMenuEditBoolItem(  tr("Show In Main Menu"), &data.show_in_mainmenu));
  Add(new cMenuEditBoolItem(  tr("Add ongoing non-VPS timers"), &data.AddOngoingNonVpsTimers));

// VPS was introduced with VDR 1.3.5
#if VDRVERSNUM >= 10305
  Add(new cMenuEditBoolItem(  tr("Use VPS"), &data.usevps));
#endif
  
  Add(new cMenuEditStraItem(  tr("Format of File Name"), &data.FormatRecordName, eRecordName_MAX, cRecordNames));
  Add(new cMenuEditBoolItem(  tr("Use Station Name within File Name"), &data.usestation));

// Starting with VDR 1.3.44, the description of a recording is 
// taken from EPG. This switch decides whether or not the description
// coming from TVTV will be added as a comment to info.vdr.
#if VDRVERSNUM >= 10344
  Add(new cMenuEditBoolItem(  tr("Use TVTV description in info.vdr"), &data.usetvtvdescr));
#endif

  Add(new cMenuEditStraItem(  tr("Timer update time shift bugfix"), &data.tvtv_bugfix, eTimeShiftBugfixMAX, timeshiftbugfixmodes));
  if (data.tvtv_bugfix == eTimeShiftBugfixManual)
    Add(new cMenuEditIntItem( tr("  Time shift check (hrs)"), &data.tvtv_bugfix_hrs, -23, 23));

  Add(new cMenuEditStraItem(  tr("TimeZone Shift BugFix"), &data.TimeZoneShiftBugFix, eTimeZoneBugfixMAX, timezonebugfixmodes));
  if (data.TimeZoneShiftBugFix == eTimeZoneBugfixManual || data.TimeZoneShiftBugFix == eTimeZoneBugfixManualDST || data.TimeZoneShiftBugFix == eTimeZoneBugfixManualNonDST)
    Add(new cMenuEditIntItem( tr("TimeZone Shift (hrs)"), &data.TimeZoneShiftHours, -1, 1));

  Add(new cOsdItem(tr("Reload ChannelMap"),osUser9));

  SetCurrent(Get(current));
  Display();
}


eOSState cMenuSetupTVTV::ProcessKey(eKeys Key) {
    int olduseproxy = data.useproxy;
    int oldtvtvbugfix = data.tvtv_bugfix;
    int oldtvtvtzbugfix = data.TimeZoneShiftBugFix;
    eOSState state = cMenuSetupPage::ProcessKey(Key);

    switch(state) {
      case osUser9:
        state=osContinue;
        if(Interface->Confirm(tr("Really reload ChannelMap?"))) {
	  if (oUpdate) oUpdate->ReloadChannelMap();
	  state=osEnd;
	}
        break;

      case osContinue:
        if(NORMALKEY(Key)==kUp || NORMALKEY(Key)==kDown) {
          cOsdItem *item=Get(Current());
          if(item) item->ProcessKey(kNone);
        }
      break;
					
      default:
      break;
    }

    if (Key != kNone && ((data.useproxy != olduseproxy) || (data.tvtv_bugfix != oldtvtvbugfix) || (data.TimeZoneShiftBugFix != oldtvtvtzbugfix))) Setup();
    return state;
}


void cMenuSetupTVTV::Store(void)
{
  dsyslog("TVTV: cMenuSetupTVTV::Store()");
  TVTVConfig = data;
  SetupStore("TVTVServer", TVTVConfig.tvtv_server);
  SetupStore("UserName", TVTVConfig.username);
  SetupStore("Password", TVTVConfig.password);
  SetupStore("UseProxy", TVTVConfig.useproxy);
  SetupStore("HTTPProxy", TVTVConfig.httpproxy);
  SetupStore("AutoUpdate", TVTVConfig.autoupdate);
  SetupStore("AddOngoingNonVpstimers", TVTVConfig.AddOngoingNonVpsTimers);
  SetupStore("UpdateTime", TVTVConfig.updatetime);
  SetupStore("FormatRecordName", TVTVConfig.FormatRecordName);
  SetupStore("UseStationInFName", TVTVConfig.usestation);
  SetupStore("ShowInMainMenu", TVTVConfig.show_in_mainmenu);

// VPS was introduced with VDR 1.3.5
#if VDRVERSNUM >= 10305
  SetupStore("UseVps", TVTVConfig.usevps);
#endif	        

#if VDRVERSNUM >= 10344
  SetupStore("UseTVTVDescr", TVTVConfig.usetvtvdescr);
#endif

  SetupStore("TVTVBugfix", TVTVConfig.tvtv_bugfix);
  SetupStore("TVTVBugfixHrs", TVTVConfig.tvtv_bugfix_hrs);
  SetupStore("TVTVTimeZoneShiftBugFix", TVTVConfig.TimeZoneShiftBugFix);
  SetupStore("TVTVTimeZoneShiftHrs", TVTVConfig.TimeZoneShiftHours);

  if (TVTVConfig.autoupdate)
    if (oUpdate)
	oUpdate->StartUpdate();
}

// --- cPluginTVTV ----------------------------------------------------------

cPluginTVTV::cPluginTVTV(void)
{
  // Initialize any member variables here.
  // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
  // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
    oUpdate = NULL;
}

cPluginTVTV::~cPluginTVTV()
{
  // Clean up after yourself!
    if (oUpdate)
	delete oUpdate;
}


void cPluginTVTV::DisplayMessage(const char *s) {

  isyslog("TVTV: %s", s);

#if VDRVERSNUM >= 10307
  if (!Skins.Current()) return;
  if (!cSkinDisplay::Current() && !displayMessage)
     displayMessage = Skins.Current()->DisplayMessage();
  cSkinDisplay::Current()->SetMessage(mtWarning, s);
  cSkinDisplay::Current()->Flush();
  cStatus::MsgOsdStatusMessage(s);
  Interface->Wait(0);
  if (displayMessage) {
     displayMessage = NULL;
     delete displayMessage;
     cStatus::MsgOsdClear();
  }
  else {
    cSkinDisplay::Current()->SetMessage(mtWarning, NULL);
    cStatus::MsgOsdStatusMessage(NULL);
  }
#else
  Interface->Open(Setup.OSDwidth, -1);
  Interface->Status(s, clrBlack, clrYellow);

  // Wait some seconds
  time_t timeout = time(NULL) + Setup.OSDMessageTime;
  for (;;) { if (time(NULL) > timeout) break; }

  Interface->Status(NULL);
  Interface->Close();
#endif
}


const char *cPluginTVTV::CommandLineHelp(void)
{
  // Return a string that describes all known command line options.
  return NULL; 
}

#if VDRVERSNUM >= 10331
const char **cPluginTVTV::SVDRPHelpPages(void) {
  static const char *HelpPages[] = {
      "RELOAD\n"
      "    Reloads the channel map configuration file.",
      "UPDATE\n"
      "    Update TVTV timer list.",
      NULL
      };
  return HelpPages;
}

cString cPluginTVTV::SVDRPCommand(const char *Cmd, const char *Option, int &ReplyCode) {
  if (strcasecmp(Cmd, "RELOAD") == 0) {
    oUpdate->ReloadChannelMap();
    return "Channel map reloaded.";
  }
  else if (strcasecmp(Cmd, "UPDATE") == 0) {
    oUpdate->StartUpdate();
    return "TVTV update done.";
  }
  return NULL;
}
#endif

bool cPluginTVTV::Start(void)
{
    // Start any background activities the plugin shall perform.
    
    oUpdate = new cUpdate();
    
    if (oUpdate && TVTVConfig.autoupdate)
	oUpdate->StartUpdate();
    
    return (oUpdate != NULL);
}

cOsdMenu *cPluginTVTV::MainMenuAction(void)
{
  // Perform the action when selected from the main VDR menu.
  if (oUpdate) oUpdate->StartUpdate();
  DisplayMessage(tr("TVTV update will be started"));
  return NULL;
}


cMenuSetupPage *cPluginTVTV::SetupMenu(void)
{
  // Return a setup menu in case the plugin supports one.
  return new cMenuSetupTVTV;
}

bool cPluginTVTV::SetupParse(const char *Name, const char *Value)
{
  // Parse your own setup parameters and store their values.

  if      (!strcasecmp(Name, "TVTVServer"))  TVTVConfig.tvtv_server = atoi(Value);
  else if (!strcasecmp(Name, "UserName"))    strcpy(TVTVConfig.username, Value);
  else if (!strcasecmp(Name, "Password"))    strcpy(TVTVConfig.password, Value);
  else if (!strcasecmp(Name, "UseProxy"))    TVTVConfig.useproxy = atoi(Value);
  else if (!strcasecmp(Name, "HTTPProxy"))   strcpy(TVTVConfig.httpproxy, Value);
  else if (!strcasecmp(Name, "AutoUpdate"))  TVTVConfig.autoupdate = atoi(Value);
  else if (!strcasecmp(Name, "AddOngoingNonVpsTimers"))  TVTVConfig.AddOngoingNonVpsTimers = atoi(Value);
  else if (!strcasecmp(Name, "UpdateTime"))  TVTVConfig.updatetime = atoi(Value);
  else if (!strcasecmp(Name, "FormatRecordName")) TVTVConfig.FormatRecordName = atoi(Value);
  else if (!strcasecmp(Name, "UseStationInFName")) TVTVConfig.usestation = atoi(Value);
  else if (!strcasecmp(Name, "ShowInMainMenu")) TVTVConfig.show_in_mainmenu = atoi(Value);
// VPS was introduced with VDR 1.3.5
#if VDRVERSNUM >= 10305
  else if (!strcasecmp(Name, "UseVps"))         TVTVConfig.usevps = atoi(Value);
#endif
  
#if VDRVERSNUM >= 10344
  else if (!strcasecmp(Name, "UseTVTVDescr"))   TVTVConfig.usetvtvdescr = atoi(Value);
#endif

  else if (!strcasecmp(Name, "TVTVBugfix"))  TVTVConfig.tvtv_bugfix = atoi(Value);
  else if (!strcasecmp(Name, "TVTVBugfixHrs"))  TVTVConfig.tvtv_bugfix_hrs = atoi(Value);
  else if (!strcasecmp(Name, "TVTVTimeZoneShiftBugFix"))  TVTVConfig.TimeZoneShiftBugFix = atoi(Value);
  else if (!strcasecmp(Name, "TVTVTimeZoneShiftHrs"))  TVTVConfig.TimeZoneShiftHours = atoi(Value);

  else
     return false;
  return true;
}

VDRPLUGINCREATOR(cPluginTVTV); // Don't touch this!