source: titan/titan/pin.h @ 38961

Last change on this file since 38961 was 33667, checked in by obi, 9 years ago

fix

File size: 5.8 KB
Line 
1#ifndef PIN_H
2#define PIN_H
3
4//type = 0 (allways)
5//type = 1 (only if channelprotect yes)
6//type = 2 (only if menuprotect yes)
7//type = 3 (fix pin code)
8int screenpincheck(int type, char* pin)
9{
10        int oldaktpage = -1;
11
12        if(type == 1)
13        {
14                if(getconfigint("channelprotect", NULL) == 0) return 0;
15                if(time(NULL) < status.protecttime) return 0;
16                if(pin != NULL && ostrcmp(pin, getconfig("pincode", NULL)) == 0) return 0;
17        }
18        if(type == 2 && getconfigint("menuprotect", NULL) == 0) return 0;
19
20        int rcret = 0, ret = 1;
21        struct skin* pincheck = getscreen("pincheck");
22
23        changemask(pincheck, "****");
24        changeinput(pincheck, "****");
25
26        drawscreen(pincheck, 0, 0);
27        addscreenrc(pincheck, pincheck);
28
29        while(1)
30        {
31                rcret = waitrc(pincheck, 0, 0);
32       
33                if(rcret == getrcconfigint("rcexit", NULL)) break;
34
35                if(pincheck->aktpage == 1 && oldaktpage == 4 && rcnumber(rcret))
36                        rcret = getrcconfigint("rcok", NULL);
37                oldaktpage = pincheck->aktpage;
38
39                if(rcret == getrcconfigint("rcok", NULL))
40                {
41                        if(type == 1)
42                        {
43                                if(ostrcmp(pincheck->ret, getconfig("pincode", NULL)) == 0)
44                                {
45                                        status.protecttime = time(NULL) + (getconfigint("protecttime", NULL) * 60);
46                                        ret = 0;
47                                }
48                        }
49                        else if(type == 3)
50                        {
51                          if(ostrcmp(pincheck->ret, "9898") == 0)
52                                        ret = 0;
53                        }
54                        else if(type == 4)
55                        {
56                          if(ostrcmp(pincheck->ret, "1397") == 0)
57                                        ret = 0;
58                        }
59                        else
60                        {
61                                if(ostrcmp(pincheck->ret, getconfig("pincodemenu", NULL)) == 0)
62                                        ret = 0;
63                        }
64
65                        if(ret != 0)
66                        {
67                                long oldbgcol = pincheck->bgcol;
68                                pincheck->bgcol = status.markcol;
69                                drawscreen(pincheck, 0, 0);
70                                usleep(500000);
71                                pincheck->bgcol = oldbgcol;
72                        }
73
74                        break;
75                }
76        }
77
78        delownerrc(pincheck);
79        clearscreen(pincheck);
80        drawscreen(skin, 0, 0);
81        return ret;
82}
83
84void screenmenuprotect()
85{
86        int rcret = 0;
87        struct skin* node = skin;
88        struct skin* child = NULL;
89        struct skin* menuprotect = getscreen("menuprotect");
90        struct skin* listbox = getscreennode(menuprotect, "listbox");
91        struct skin* tmp = NULL;
92        char* tmpstr = NULL;
93
94        while(node != NULL)
95        {
96                child = node->child;
97                while(child != NULL)
98                {
99                        if(child->type & MENU)
100                        {
101                                tmp = addlistbox(menuprotect, listbox, tmp, 1);
102                                if(tmp != NULL)
103                                {
104                                        changetext(tmp, child->text);
105                                        changename(tmp, child->name);
106                                        tmp->type = CHOICEBOX;
107                                        tmp->del = 1;
108                                        tmp->height = listbox->fontsize + 2;
109                                        addchoicebox(tmp, "0", _("no"));
110                                        addchoicebox(tmp, "1", _("yes"));
111                                        addchoicebox(tmp, "2", _("hidden"));
112                                        tmpstr = ostrcat("protect_", tmp->name, 0, 0);
113                                        setchoiceboxselection(tmp, getconfig(tmpstr, NULL));
114                                        free(tmpstr);
115                                }
116                        }
117                        child = child->next;
118                }
119                node = node->next;
120        }
121
122        drawscreen(menuprotect, 0, 0);
123        addscreenrc(menuprotect, listbox);
124
125        tmp = listbox->select;
126        while(1)
127        {
128                addscreenrc(menuprotect, tmp);
129                rcret = waitrc(menuprotect, 0, 0);
130                tmp = listbox->select;
131       
132                if(rcret == getrcconfigint("rcexit", NULL)) break;
133                if(rcret == getrcconfigint("rcok", NULL))
134                {
135                        node = menuprotect->child;
136                        while(node != NULL)
137                        {
138                                tmpstr = ostrcat("protect_", node->name, 0, 0);
139                                addconfigscreencheck(tmpstr, node, "0");
140                                free(tmpstr); tmpstr = NULL;
141                                node = node->next;
142                        }
143                        break;
144                }
145        }
146
147        delmarkedscreennodes(menuprotect, 1);
148        delownerrc(menuprotect);
149        clearscreen(menuprotect);
150}
151
152void screenpin()
153{
154        char*tmpstr = NULL;
155
156        tmpstr = ostrcat("protect_", "childprotection", 0, 0);
157        if(getconfigint(tmpstr, NULL) == 0)
158        {
159                int pinret = screenpincheck(0, NULL);
160                if(pinret == 1) return;
161        }
162        free(tmpstr); tmpstr = NULL;
163
164        int rcret = 0;
165        struct skin* pin = getscreen("pin");
166        struct skin* listbox = getscreennode(pin, "listbox");
167        struct skin* pincode = getscreennode(pin, "pincode");
168        struct skin* pincodemenu = getscreennode(pin, "pincodemenu");
169        struct skin* channelprotect = getscreennode(pin, "channelprotect");
170        struct skin* ageprotect = getscreennode(pin, "ageprotect");
171        struct skin* menuprotect = getscreennode(pin, "menuprotect");
172        struct skin* protecttime = getscreennode(pin, "protecttime");
173        struct skin* tmp = NULL;
174
175        changemask(pincodemenu, "0000");
176        changeinput(pincodemenu, getconfig("pincodemenu", NULL));
177
178        changemask(pincode, "0000");
179        changeinput(pincode, getconfig("pincode", NULL));
180
181        addchoicebox(channelprotect, "0", _("no"));
182        addchoicebox(channelprotect, "1", _("yes"));
183        setchoiceboxselection(channelprotect, getconfig("channelprotect", NULL));
184       
185        addchoicebox(protecttime, "0", _("no"));
186        addchoicebox(protecttime, "30", "30");
187        addchoicebox(protecttime, "60", "60");
188        addchoicebox(protecttime, "90", "90");
189        addchoicebox(protecttime, "120", "120");
190        addchoicebox(protecttime, "150", "150");
191        addchoicebox(protecttime, "180", "180");
192        addchoicebox(protecttime, "210", "210");
193        addchoicebox(protecttime, "30000000", _("endless"));
194        setchoiceboxselection(protecttime, getconfig("protecttime", NULL));
195
196        changeinput(ageprotect, "0\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18");
197        setchoiceboxselection(ageprotect, getconfig("ageprotect", NULL));
198
199        addchoicebox(menuprotect, "0", _("no"));
200        addchoicebox(menuprotect, "1", _("yes"));
201        setchoiceboxselection(menuprotect, getconfig("menuprotect", NULL));
202
203        drawscreen(pin, 0, 0);
204        addscreenrc(pin, listbox);
205
206        tmp = listbox->select;
207        while(1)
208        {
209                addscreenrc(pin, tmp);
210                rcret = waitrc(pin, 0, 0);
211                tmp = listbox->select;
212       
213                if(rcret == getrcconfigint("rcexit", NULL)) break;
214                if(rcret == getrcconfigint("rcred", NULL))
215                {
216                        clearscreen(pin);
217                        screenmenuprotect();
218                        drawscreen(pin, 0, 0);
219                }
220                if(rcret == getrcconfigint("rcok", NULL))
221                {
222                        addconfigscreen("pincodemenu", pincodemenu);
223                        addconfigscreen("pincode", pincode);
224                        addconfigscreencheck("channelprotect", channelprotect, "0");
225                        addconfigscreencheck("ageprotect", ageprotect, "0");
226                        addconfigscreencheck("menuprotect", menuprotect, "0");
227                        addconfigscreencheck("protecttime", protecttime, "0");
228                        break;
229                }
230        }
231
232        delownerrc(pin);
233        clearscreen(pin);
234}
235
236#endif
Note: See TracBrowser for help on using the repository browser.