summaryrefslogtreecommitdiff
path: root/menu.h
blob: 23442f2d7ecdcf52b9b40ee2c1dae1dea661bfbe (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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
/*
 * menu.h: EPG2VDR plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 */

#ifndef __EPG2VDR_MENU_H
#define __EPG2VDR_MENU_H

#include <vdr/osdbase.h>
#include <vdr/menuitems.h>

#include "lib/common.h"
#include "lib/db.h"
#include "lib/epgservice.h"
#include "lib/searchtimer.h"

#include "menu.h"
#include "ttools.h"
#include "parameters.h"

class cMenuEpgEditTimer;
class cTimerData;

//***************************************************************************
//
//***************************************************************************

#define NEWTIMERLIMIT    60 // seconds until the start time of a new timer created from the Schedule menu,
                            // within which it will go directly into the "Edit timer" menu to allow
                            // further parameter settings

#define MAXCHNAMWIDTH    16 // maximum number of characters of channels' short names shown in schedules menus

#if defined (APIVERSNUM) && (APIVERSNUM >= 20301)
#  define CHNUMWIDTH  (numdigits(cChannels::MaxNumber()) + 1)
#  define CHNAMWIDTH  (std::min(MAXCHNAMWIDTH, cChannels::MaxShortChannelNameLength() + 1))
#else
#  define CHNUMWIDTH  (numdigits(Channels.MaxNumber()) + 1)
#  define CHNAMWIDTH  (std::min(MAXCHNAMWIDTH, Channels.MaxShortChannelNameLength() + 1))
#endif

//***************************************************************************
// Class cMenuDb
//***************************************************************************

class cMenuDb : public cParameters
{
   friend class cMenuEpgEvent;
   friend class cMenuEpgEditTimer;
   friend class cMenuEpgWhatsOn;
   friend class cMenuEpgSchedule;
   friend class cMenuEpgTimers;
   friend class cMenuEpgSearchTimers;
   friend class cEpgMenuDones;
   friend class cEpgMenuSearchTimerEdit;
   friend class cMenuEpgMatchRecordings;
   friend class cEpgMenuSearchResult;
   friend class cMenuSetupEPG2VDR;
   friend class cMenuEpgScheduleItem;

   public:

      cMenuDb();
      virtual ~cMenuDb();

      int initDb();
      int exitDb();

      int initUserTimes();
      int initUserList(char**& userList, int& count, long int& loginEnabled);
      int lookupTimer(const cEvent* event, int& timerMatch, int& remote, int force = no);

      // timer db

      int createTimer(cDbRow* timerRow, const char* destUuid);
      int modifyTimer(cDbRow* timerRow, const char* destUuid = 0);
      int deleteTimer(long timerid);

      //

      int triggerVdrs(const char* trg, const char* uuid = "", const char* options = "");
      int triggerVdr(const char* uuid, const char* trg, const char* options = "");

   protected:

      virtual int dbConnected(int force = no)
      {
         return dbInitialized
            && connection
            && (!force || connection->check() == success);
      }

      // data

      long webLoginEnabled;
      std::string user;
      long startWithSched;

      cUserTimes* userTimes;
      char** vdrList;
      char** vdrUuidList;
      int vdrCount;

      // database

      int dbInitialized;
      cDbConnection* connection;

      cDbTable* timerDb;
      cDbTable* vdrDb;
      cDbTable* mapDb;
      cDbTable* timerDoneDb;
      cDbTable* userDb;
      cDbTable* searchtimerDb;
      cDbTable* recordingListDb;
      cDbTable* useeventsDb;

      cDbStatement* selectTimers;
      cDbStatement* selectEventById;
      cDbStatement* selectMaxUpdSp;
      cDbStatement* selectTimerById;
      cDbStatement* selectActiveVdrs;
      cDbStatement* selectAllVdrs;
      cDbStatement* selectDoneTimerByState;
      cDbStatement* selectAllUser;
      cDbStatement* selectSearchTimers;
      cDbStatement* selectSearchTimerByName;
      cDbStatement* selectDoneTimerByStateTitleOrder;
      cDbStatement* selectDoneTimerByStateTimeOrder;
      cDbStatement* selectRecordingForEvent;
      cDbStatement* selectRecordingForEventByLv;
      cDbStatement* selectChannelFromMap;

      cSearchTimer* search;

      cDbValue valueStartTime;
      cDbValue timerState;
      cDbValue timerAction;

      class cTimerInfo : public cListObject
      {
         public:

            uint timerid;
            char state;
            time_t starttime;
            uint eventid;
            char channelid[100];
            char uuid[sizeUuid+TB];
      };

      cList<cTimerInfo> timers;
      int timersCacheMaxUpdsp;
};

//***************************************************************************
// Class cMenuEditTimer
//***************************************************************************

class cMenuEpgEditTimer : public cOsdMenu
{
   public:

      cMenuEpgEditTimer(cMenuDb* db, cEpgTimer* Timer, bool New = no);
      virtual ~cMenuEpgEditTimer();

      virtual eOSState ProcessKey(eKeys Key);

   protected:

      eOSState SetFolder();
      void SetFirstDayItem();
      void SetHelpKeys();

   public:

      class cTimerData
      {
         public:

            cTimerData(cMenuDb* p)         { memset(this, 0, sizeof(cTimerData)); db = p; }
            ~cTimerData()                  { free(aux); }

            const char* getVdrName()       { return db->vdrList[vdrIndex]; }
            const char* getVdrUuid()       { return db->vdrUuidList[vdrIndex]; }
            const char* getLastVdrUuid()   { return lastVdrUuid; }
            long TimerId()                 { return timerid; }

            //**************************************************
            // From Timer
            //**************************************************

            void fromTimer(cEpgTimer* Timer, bool New = no)
            {
               weekdays = Timer->WeekDays();
               start = Timer->Start();
               stop = Timer->Stop();
               priority = Timer->Priority();
               lifetime = Timer->Lifetime();
               flags = Timer->Flags();
               channel = Timer->Channel();
               day = Timer->Day();
               strcpy(file, Timer->File());
               vdrIndex = 0;
               free(aux); aux = 0;

               if (New)
                  flags |= tfActive;

               if (!isEmpty(Timer->Aux()))
                  aux = strdup(Timer->Aux());

               timerid = Timer->TimerId();
               eventid = Timer->EventId();
               state = Timer->State();
               sprintf(stateInfo, "%.300s", Timer->StateInfo());
               action = Timer->Action();
               strcpy(lastVdrUuid, Timer->VdrUuid());

               for (int i = 0; i < db->vdrCount; i++)
                  if (strncmp(db->vdrList[i], Timer->VdrName(), strlen(db->vdrList[i])-1) == 0)
                     vdrIndex = i;

#ifdef WITH_PIN
               fskProtection = Timer->FskProtection();
#endif
            }

            int toRow(cDbRow* timerRow)
            {
               timerRow->clear();

               timerRow->setValue("ID", timerid);
               timerRow->setValue("VDRUUID", lastVdrUuid);
               timerRow->setValue("ACTIVE", (int)flags & tfActive);
               timerRow->setValue("CHILDLOCK", fskProtection);
               timerRow->setValue("CHANNELID", channel->GetChannelID().ToString());
               timerRow->setValue("FILE", file);
               timerRow->setValue("VPS", (int)flags & tfVps);
               timerRow->setValue("DAY", day);
               timerRow->setValue("WEEKDAYS", weekdays);
               timerRow->setValue("STARTTIME", start);
               timerRow->setValue("ENDTIME", stop);
               timerRow->setValue("PRIORITY", priority);
               timerRow->setValue("LIFETIME", lifetime);
               timerRow->setValue("EVENTID", eventid);

               return done;
            }

            long timerid;
            long eventid;
            int weekdays;                       // bitmask, lowest bits: SSFTWTM  (the 'M' is the LSB)
            int start;
            int stop;
            int priority;
            int fskProtection;
            int lifetime;
            uint flags;
            char state;
            char stateInfo[300+TB];
            char action;
            int vdrIndex;
            const cChannel* channel;
            mutable time_t day;
            mutable char file[NAME_MAX*2 + TB]; // *2 to be able to hold 'title' and 'episode', which can each be up to 255 characters long
            char* aux;

            cMenuDb* db;
            char lastVdrUuid[sizeUuid+TB];
      };

   protected:

      cMenuDb* menuDb;
      cTimerData data;
      int channelNr;
      cMenuEditStrItem* file;
      cMenuEditDateItem* day;
      cMenuEditDateItem* firstday;
};

//***************************************************************************
// class cEpgMenuTextItem
//***************************************************************************

class cEpgMenuTextItem : public cOsdItem
{
   public:

      cEpgMenuTextItem(long aId, const char* text)
      {
         cid = 0;
         id = aId;
         SetText(text);
      }

      cEpgMenuTextItem(const char* aId, const char* text)
      {
         cid = strdup(aId);
         SetText(text);
      }

      virtual ~cEpgMenuTextItem() { free(cid); }

      long getId() { return id; }
      const char* getCharId() { return cid; }

   protected:

      long id;
      char* cid;
};

//***************************************************************************
// Class cMenuEpgTimers
//***************************************************************************

class cMenuEpgTimers : public cOsdMenu
{
   public:

      cMenuEpgTimers();
      virtual ~cMenuEpgTimers();

      virtual eOSState ProcessKey(eKeys Key);
      int refresh();

   private:

      eOSState edit();
      eOSState create();
      eOSState remove();
      eOSState toggleState();
      eOSState info();
      cEpgTimer* currentTimer();
      void SetHelpKeys();

      cMenuDb* menuDb;
      int helpKeys;
      int timersMaxUpdsp;
};

//***************************************************************************
// Class cMenuEpgSearchTimers
//***************************************************************************

class cMenuEpgSearchTimers : public cOsdMenu
{
   public:

      cMenuEpgSearchTimers();
      virtual ~cMenuEpgSearchTimers();

      virtual eOSState ProcessKey(eKeys Key);
      int refresh();
      void setHelpKeys();

   private:

      cMenuDb* menuDb;
      // int helpKeys;
};

//***************************************************************************
// Class cMenuEpgEvent
//***************************************************************************

class cMenuEpgEvent : public cOsdMenu
{
   public:

      cMenuEpgEvent(cMenuDb* db, const cEvent* Event, const cSchedules* schedules,
                    int timerMatch, bool DispSchedule, bool CanSwitch = false);
      virtual void Display(void);
      virtual eOSState ProcessKey(eKeys Key);
      virtual const char* MenuKind() { return "MenuEvent"; }

   private:

      const cEvent* getNextPrevEvent(const cEvent* event, int step);
      int setEvent(const cEvent* Event, int timerMatch);

      cMenuDb* menuDb;
      const cSchedules* schedules;
      const cEvent* event;
      bool dispSchedule;
      bool canSwitch;

      std::string prevTime;
      std::string nextTime;
};

//***************************************************************************
// Class cMenuEpgScheduleItem
//***************************************************************************

class cMenuEpgScheduleItem : public cOsdItem
{
   public:

      enum eScheduleSortMode { ssmAllThis, ssmThisThis, ssmThisAll, ssmAllAll }; // "which event(s) on which channel(s)"

      cMenuEpgScheduleItem(cMenuDb* db, const cEvent* Event, const cChannel* Channel = 0, bool WithDate = no);
      ~cMenuEpgScheduleItem();

      static void SetSortMode(eScheduleSortMode SortMode)  { sortMode = SortMode; }
      static void IncSortMode()                            { sortMode = eScheduleSortMode((sortMode == ssmAllAll) ? ssmAllThis : sortMode + 1); }
      static eScheduleSortMode SortMode()                  { return sortMode; }

      virtual int Compare(const cListObject &ListObject) const;
      virtual bool Update(bool Force = false);
      virtual void SetMenuItem(cSkinDisplayMenu* DisplayMenu, int Index, bool Current, bool Selectable);

      const cEvent* event;
      const cChannel* channel;
      bool withDate;
      int timerMatch;

   private:

      cMenuDb* menuDb;
      static eScheduleSortMode sortMode;
};

//***************************************************************************
// Class cMenuEpgWhatsOn
//***************************************************************************

class cMenuEpgWhatsOn : public cOsdMenu
{
   public:

      cMenuEpgWhatsOn(const cEvent* aSearchEvent = 0);
      ~cMenuEpgWhatsOn();

      static int CurrentChannel()                   { return currentChannel; }
      static void SetCurrentChannel(int ChannelNr)  { currentChannel = ChannelNr; }
      virtual eOSState ProcessKey(eKeys Key);
      virtual void Display();

   private:

      int LoadAt();
      int LoadSearch(const cUserTimes::UserTime* userTime);
      int LoadSchedule();
      int LoadQuery(const cEvent* searchEvent);

      bool canSwitch;
      int helpKeys;
      time_t helpKeyTime;
      int helpKeyTimeMode;
      // int timerState;
      eOSState Record();
      eOSState Switch();
      bool Update();
      void SetHelpKeys();

      cMenuDb* menuDb;
      const cSchedules* schedules;
#if defined (APIVERSNUM) && (APIVERSNUM >= 20301)
      cStateKey schedulesKey;
#else
      cSchedulesLock* schedulesLock;
#endif
      const cEvent* searchEvent;
      int dispSchedule;

      static int currentChannel;
      static const cEvent* scheduleEvent;
};

//***************************************************************************
// class cEpgMenuDones
//***************************************************************************

class cEpgMenuDones : public cOsdMenu
{
   public:

      enum JournalFilter
      {
         jfAll = 0,

         jfFirst = 1,
         jfRecorded = jfFirst,
         jfCreated,
         jfFailed,
         jfDeleted,

         jfCount
      };

      cEpgMenuDones();
      virtual ~cEpgMenuDones();
      virtual eOSState ProcessKey(eKeys Key);

   protected:

      int refresh();
      void setHelp();

      // data

      cMenuDb* menuDb;
      int journalFilter;
      int order;
};

//***************************************************************************
// class cMenuEpgMatchRecordings
//***************************************************************************

class cMenuEpgMatchRecordings : public cOsdMenu
{
   public:

      cMenuEpgMatchRecordings(cMenuDb* db, const cEvent* event);
      virtual ~cMenuEpgMatchRecordings() {};
      virtual eOSState ProcessKey(eKeys Key);
};

//***************************************************************************

#endif  // __EPG2VDR_MENU_H