you can now delete characters in the timerentry description with the mute-key
[enigma2.git] / lib / dvb_ci / dvbci_ui.cpp
1 #include <lib/dvb_ci/dvbci_ui.h>
2 #include <lib/dvb_ci/dvbci.h>
3
4 #include <unistd.h>
5 #include <fcntl.h>
6 #include <sys/ioctl.h>
7
8 #include <string>
9
10 #include <lib/base/init.h>
11 #include <lib/base/init_num.h>
12 #include <lib/base/econfig.h>
13 #include <lib/base/eerror.h>
14
15 eDVBCI_UI *eDVBCI_UI::instance = 0;
16
17 eDVBCI_UI::eDVBCI_UI()
18 {
19         int i;
20         
21         for(i=0;i<MAX_SLOTS;i++)
22                 state[i] = 0;           //no module
23
24         ASSERT(!instance);
25         instance = this;
26         mmiScreenReady = 0;
27 }
28
29 eDVBCI_UI::~eDVBCI_UI()
30 {
31 }
32
33 eDVBCI_UI *eDVBCI_UI::getInstance()
34 {
35         return instance;
36 }
37
38 int eDVBCI_UI::getState(int slot)
39 {
40         return state[slot];     //exploit me ;)
41 }
42
43 void eDVBCI_UI::setState(int slot, int newState)
44 {
45         state[slot] = newState;
46 }
47
48 std::string eDVBCI_UI::getAppName(int slot)
49 {
50         return appName;
51 }
52
53 void eDVBCI_UI::setAppName(int slot, const char *name)
54 {
55         //printf("set name to -%c-\n", name);
56         appName = name;
57 }
58
59 void eDVBCI_UI::setReset(int slot)
60 {
61         eDVBCIInterfaces::getInstance()->reset(slot);
62 }
63
64 int eDVBCI_UI::startMMI(int slot)
65 {
66         eDVBCIInterfaces::getInstance()->startMMI(slot);
67 }
68
69 int eDVBCI_UI::stopMMI(int slot)
70 {
71         eDVBCIInterfaces::getInstance()->stopMMI(slot);
72 }
73
74 int eDVBCI_UI::initialize(int slot)
75 {
76         eDVBCIInterfaces::getInstance()->initialize(slot);
77 }
78
79 int eDVBCI_UI::answerMenu(int slot, int answer)
80 {
81         eDVBCIInterfaces::getInstance()->answerText(slot, answer);
82 }
83
84 int eDVBCI_UI::answerEnq(int slot, char *value)
85 {
86         eDVBCIInterfaces::getInstance()->answerEnq(slot, value);
87 }
88
89 int eDVBCI_UI::cancelEnq(int slot)
90 {
91         eDVBCIInterfaces::getInstance()->cancelEnq(slot);
92 }
93
94 int eDVBCI_UI::availableMMI(int slot)
95 {
96         return mmiScreenReady;
97 }
98
99 int eDVBCI_UI::mmiScreenEnq(int slot, int blind, int answerLen, char *text)
100 {
101         mmiScreenReady = 0;
102
103         mmiScreen = PyList_New(2);
104
105   PyObject *tuple = PyTuple_New(1);
106         PyTuple_SetItem(tuple, 0, PyString_FromString("ENQ"));
107   PyList_SetItem(mmiScreen, 0, tuple);
108
109   tuple = PyTuple_New(4);
110         
111         PyTuple_SetItem(tuple, 0, PyString_FromString("PIN"));
112   PyTuple_SetItem(tuple, 1, PyInt_FromLong(answerLen));
113         PyTuple_SetItem(tuple, 2, PyString_FromString(text));
114   PyTuple_SetItem(tuple, 3, PyInt_FromLong(blind));
115   PyList_SetItem(mmiScreen, 1, tuple);
116
117         mmiScreenReady = 1;
118
119         return 0;
120 }
121
122 int eDVBCI_UI::mmiScreenBegin(int slot, int listmenu)
123 {
124         printf("eDVBCI_UI::mmiScreenBegin\n");
125
126         mmiScreenReady = 0;
127         
128         mmiScreen = PyList_New(1);
129
130   PyObject *tuple = PyTuple_New(1);
131         if(listmenu == 0)                               //menu
132                 PyTuple_SetItem(tuple, 0, PyString_FromString("MENU"));
133         else    //list
134                 PyTuple_SetItem(tuple, 0, PyString_FromString("LIST"));
135                 
136   PyList_SetItem(mmiScreen, 0, tuple);
137         
138         mmiTuplePos = 1;
139         
140         return 0;
141 }
142
143 int eDVBCI_UI::mmiScreenAddText(int slot, int type, char *value)
144 {
145         printf("eDVBCI_UI::mmiScreenAddText(%s)\n",value);
146
147   PyObject *tuple = PyTuple_New(3);
148         
149         if(type == 0)                                                   //title
150                 PyTuple_SetItem(tuple, 0, PyString_FromString("TITLE"));
151         else if(type == 1)                              //subtitle
152                 PyTuple_SetItem(tuple, 0, PyString_FromString("SUBTITLE"));
153         else if(type == 2)                              //bottom
154                 PyTuple_SetItem(tuple, 0, PyString_FromString("BOTTOM"));
155         else
156                 PyTuple_SetItem(tuple, 0, PyString_FromString("TEXT"));
157
158         printf("addText %s with id %d\n", value, type);
159
160         PyTuple_SetItem(tuple, 1, PyString_FromString(value));
161         
162         if(type > 2)
163           PyTuple_SetItem(tuple, 2, PyInt_FromLong(type-2));
164         else    
165           PyTuple_SetItem(tuple, 2, PyInt_FromLong(-1));
166         
167         PyList_Append(mmiScreen, tuple);
168         
169         return 0;
170 }
171
172 int eDVBCI_UI::mmiScreenFinish(int slot)
173 {
174         printf("eDVBCI_UI::mmiScreenFinish\n");
175
176         mmiScreenReady = 1;
177
178         return 0;
179 }
180
181 int eDVBCI_UI::getMMIState(int slot)
182 {
183         return eDVBCIInterfaces::getInstance()->getMMIState(slot);
184 }
185
186 PyObject *eDVBCI_UI::getMMIScreen(int slot)
187 {
188         if(mmiScreenReady != 1)
189                 return Py_None;
190                 
191         mmiScreenReady = 0;
192
193         return mmiScreen;
194 }
195
196 //FIXME: correct "run/startlevel"
197 eAutoInitP0<eDVBCI_UI> init_dvbciui(eAutoInitNumbers::rc, "DVB-CI UI");