summaryrefslogtreecommitdiff
path: root/setupmenu.c
blob: 4d773824e1dcf3fa5f9b721b6a3ff801113b1ece (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

//***************************************************************************
// Includes
//***************************************************************************

#include <vdr/menuitems.h>
#include "setupmenu.h"
#include <ctype.h>               // isdigit

//***************************************************************************
// Object
//***************************************************************************

PinSetupMenu::PinSetupMenu()
{
   static const char* trProtectionModes[cPinPlugin::apmCount] = { 0 };

   hidePinCode = yes;
   // hidePinCode = no;

   if (hidePinCode)
   {
      for (int i = 0; i < cPinPlugin::sizePinCode; i++)
         pinCode[i] = '*';

      pinCode[cPinPlugin::sizePinCode] = 0;
   }
   else
   {
      strcpy(pinCode, cPinPlugin::pinCode);
   }

   skipChannelSilent = cPinPlugin::skipChannelSilent;
   pinResetTime = cPinPlugin::pinResetTime;
   autoMenuOpen = cPinPlugin::autoMenuOpen;
   autoProtectionMode = cPinPlugin::autoProtectionMode;
   hideProtectedMenus = cPinPlugin::hideProtectedMenus;    
   hideProtectedPlugins = cPinPlugin::hideProtectedPlugins;  
   hideProtectedRecordings = cPinPlugin::hideProtectedRecordings;

   // translate protection modes

   if (!trProtectionModes[0])
      for (int i = 0; i < cPinPlugin::apmCount; i++)
         trProtectionModes[i] = tr(cPinPlugin::autoProtectionModes[i]);

   if (hidePinCode)
      Add(new cMenuEditStrItem(tr("Pin code"), pinCode, cPinPlugin::sizePinCode+TB, "0123456789*"));
   else
      Add(new cMenuEditNumItem(tr("Pin code"), pinCode, cPinPlugin::sizePinCode, false));

   Add(new cMenuEditBoolItem(tr("Skip protected channel silent"), &skipChannelSilent));
   Add(new cMenuEditBoolItem(tr("Hide protected menus"), &hideProtectedMenus));
   Add(new cMenuEditBoolItem(tr("Hide protected plugins"), &hideProtectedPlugins));
   Add(new cMenuEditBoolItem(tr("Hide protected recordings"), &hideProtectedRecordings));
   Add(new cMenuEditBoolItem(tr("Open menu after pin request"), &autoMenuOpen));
   Add(new cMenuEditIntItem(tr("Pin inactivity time [min]"), &pinResetTime, 0, 5*60));  // max 5 hour
	Add(new cMenuEditStraItem(tr("Autoprotection of recordings"), &autoProtectionMode, 
                             cPinPlugin::apmCount, trProtectionModes));
   Add(new cMenuEditIntItem(tr("Log Level [0-5]"), &logLevel, 0, 5));
}

PinSetupMenu::~PinSetupMenu()
{
   // nothing yet
}

//***************************************************************************
// Store
//***************************************************************************

void PinSetupMenu::Store(void)
{
   int i = 0;
   int pinValid = yes;
   
   if (hidePinCode)
   {
      int pinChanged = no;

      // store only numerical pin codes

      for (i = 0; i < cPinPlugin::sizePinCode; i++)
      {
         if (pinCode[i] != '*')
         {
            pinChanged = yes;
            break;
         }
      }
      
      if (pinChanged)
      {
         i = 0;

         while (pinCode[i])
         {
            if (!isdigit(pinCode[i++]))
            {
               i--;
               pinCode[i] = 0;
               break;
            }
         }

         if (i < 2)
         {
            Skins.Message(mtError, tr("Ignoring invalid pin"));
            pinValid = no;
         }
      }
      else
         pinValid = no;
   }
   
   if (pinValid)
   {
      strncpy(cPinPlugin::pinCode, pinCode, cPinPlugin::sizePinCode);
      cPinPlugin::pinCode[cPinPlugin::sizePinCode] = 0;
      SetupStore("pinCode", cPinPlugin::pinCode);
   }
   
   cPinPlugin::skipChannelSilent = skipChannelSilent;
   cPinPlugin::pinResetTime = pinResetTime;
   cPinPlugin::autoMenuOpen = autoMenuOpen;
   cPinPlugin::autoProtectionMode = autoProtectionMode;

   cPinPlugin::hideProtectedMenus = hideProtectedMenus;     
   cPinPlugin::hideProtectedPlugins = hideProtectedPlugins;   
   cPinPlugin::hideProtectedRecordings = hideProtectedRecordings;

   SetupStore("skipChannelSilent", skipChannelSilent);
   SetupStore("hideProtectedMenus", hideProtectedMenus);
   SetupStore("hideProtectedPlugins", hideProtectedPlugins);
   SetupStore("hideProtectedRecordings", hideProtectedRecordings);
   SetupStore("pinResetTime", pinResetTime);
   SetupStore("autoMenuOpen", autoMenuOpen);
   SetupStore("autoProtectionMode", autoProtectionMode);
}