summaryrefslogtreecommitdiff
path: root/noncore/tools/remote/buttondialog.cpp
Unidiff
Diffstat (limited to 'noncore/tools/remote/buttondialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/remote/buttondialog.cpp216
1 files changed, 9 insertions, 207 deletions
diff --git a/noncore/tools/remote/buttondialog.cpp b/noncore/tools/remote/buttondialog.cpp
index 580f101..56738d1 100644
--- a/noncore/tools/remote/buttondialog.cpp
+++ b/noncore/tools/remote/buttondialog.cpp
@@ -33,6 +33,8 @@ ButtonDialog::ButtonDialog(QString buttonName, QWidget *parent, const char*name,
33 layout->addSpacing(5); 33 layout->addSpacing(5);
34 layout->addLayout(hlayout3); 34 layout->addLayout(hlayout3);
35 layout->addSpacing(5); 35 layout->addSpacing(5);
36
37 lh = new LircHandler();
36 38
37 remote = new QComboBox(false, this, "remote"); 39 remote = new QComboBox(false, this, "remote");
38 QLabel *remoteLabel = new QLabel(remote, "Remote: ", this, "remoteLabel"); 40 QLabel *remoteLabel = new QLabel(remote, "Remote: ", this, "remoteLabel");
@@ -42,7 +44,7 @@ ButtonDialog::ButtonDialog(QString buttonName, QWidget *parent, const char*name,
42 hlayout1->addWidget(remote); 44 hlayout1->addWidget(remote);
43 hlayout1->addSpacing(5); 45 hlayout1->addSpacing(5);
44 remote->insertItem("Remote "); 46 remote->insertItem("Remote ");
45 remote->insertStringList(getRemotes()); 47 remote->insertStringList(lh->getRemotes());
46 connect(remote, SIGNAL(activated(const QString&)), this, SLOT(remoteSelected(const QString&)) ); 48 connect(remote, SIGNAL(activated(const QString&)), this, SLOT(remoteSelected(const QString&)) );
47 49
48 button = new QComboBox(false, this, "button"); 50 button = new QComboBox(false, this, "button");
@@ -65,9 +67,14 @@ ButtonDialog::ButtonDialog(QString buttonName, QWidget *parent, const char*name,
65 hlayout3->addSpacing(5); 67 hlayout3->addSpacing(5);
66} 68}
67 69
70ButtonDialog::~ButtonDialog()
71{
72 delete lh;
73}
74
68void ButtonDialog::remoteSelected(const QString &string) 75void ButtonDialog::remoteSelected(const QString &string)
69{ 76{
70 button->insertStringList(getButtons(string.latin1()) ); 77 button->insertStringList(lh->getButtons(string.latin1()) );
71 list="SEND_ONCE"; 78 list="SEND_ONCE";
72 list+=string; 79 list+=string;
73} 80}
@@ -86,208 +93,3 @@ QString ButtonDialog::getLabel()
86{ 93{
87 return label->text(); 94 return label->text();
88} 95}
89
90QStringList ButtonDialog::getRemotes()
91{
92 const char write_buffer[] = "LIST\n";
93 const char *readbuffer;
94 int i, numlines;
95 QStringList list;
96
97 addr.sun_family=AF_UNIX;
98 strcpy(addr.sun_path,"/dev/lircd");
99
100 fd = socket(AF_UNIX, SOCK_STREAM, 0);
101 if(fd == -1)
102 {
103 QMessageBox *mb = new QMessageBox("Error!",
104 "couldnt connect to socket",
105 QMessageBox::NoIcon,
106 QMessageBox::Ok,
107 QMessageBox::NoButton,
108 QMessageBox::NoButton);
109 mb->exec();
110 perror("ButtonDialog::GetRemotes");
111 return NULL;
112 }
113
114 if(::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1)
115 {
116 QMessageBox *mb = new QMessageBox("Error!",
117 "couldnt connect to socket",
118 QMessageBox::NoIcon,
119 QMessageBox::Ok,
120 QMessageBox::NoButton,
121 QMessageBox::NoButton);
122 mb->exec();
123 perror("ButtonDialog::GetRemotes");
124 return NULL;
125 }
126
127 write(fd, write_buffer, strlen(write_buffer));
128
129 for(i=0; i<5; i++)
130 {
131 printf("%d\n", i);
132 readbuffer = readPacket();
133 printf("%s", readbuffer);
134 printf("%d\n", i);
135 }
136
137 numlines = atoi(readbuffer);
138
139 for(i=0; i<numlines; i++)
140 {
141 list+=readPacket();
142 }
143
144 if(strcasecmp(readPacket(), "END") != 0)
145 {
146 QMessageBox *mb = new QMessageBox("Error!",
147 "bad packet",
148 QMessageBox::NoIcon,
149 QMessageBox::Ok,
150 QMessageBox::NoButton,
151 QMessageBox::NoButton);
152 mb->exec();
153 perror("ButtonDialog::GetRemotes");
154 return NULL;
155 }
156
157 ::close(fd);
158 return list;
159}
160
161QStringList ButtonDialog::getButtons(const char *remoteName)
162{
163 QString write_buffer = "LIST ";
164 const char *readbuffer;
165 int i, j, numlines;
166 QStringList list;
167 QString string;
168
169 write_buffer += remoteName;
170 write_buffer += '\n';
171
172 fd = socket(AF_UNIX, SOCK_STREAM, 0);
173 if(fd == -1)
174 {
175 QMessageBox *mb = new QMessageBox("Error!",
176 "couldnt connect to socket",
177 QMessageBox::NoIcon,
178 QMessageBox::Ok,
179 QMessageBox::NoButton,
180 QMessageBox::NoButton);
181 mb->exec();
182 perror("ButtonDialog::GetButtons");
183 return NULL;
184 }
185
186
187 if(::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1)
188 {
189 QMessageBox *mb = new QMessageBox("Error!",
190 "couldnt connect to socket",
191 QMessageBox::NoIcon,
192 QMessageBox::Ok,
193 QMessageBox::NoButton,
194 QMessageBox::NoButton);
195 mb->exec();
196 perror("ButtonDialog::GetButtons");
197 return NULL;
198 }
199
200 write(fd, write_buffer.latin1(), strlen(write_buffer) );
201
202 for(i=0; i<5; i++)
203 {
204 readbuffer = readPacket();
205 }
206
207 numlines = atoi(readbuffer);
208
209 for(i=0; i<numlines; i++)
210 {
211 list+=readPacket();
212 for(j=0; j<list[i].length(); j++)
213 {
214 if(list[i][j] == ' ')
215 break;
216 }
217 list[i].remove(0, j+1);
218 }
219
220 if(strcasecmp(readPacket(), "END") != 0)
221 {
222 QMessageBox *mb = new QMessageBox("Error!",
223 "bad packet",
224 QMessageBox::NoIcon,
225 QMessageBox::Ok,
226 QMessageBox::NoButton,
227 QMessageBox::NoButton);
228 mb->exec();
229 perror("ButtonDialog::GetButtons");
230 return NULL;
231 }
232
233 ::close(fd);
234 return list;
235}
236
237
238//this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html
239const char *ButtonDialog::readPacket()
240{
241 static char buffer[PACKET_SIZE+1]="";
242 char *end;
243 static int ptr=0,end_len=0;
244 ssize_t ret;
245 timeout = 0;
246
247 if(ptr>0)
248 {
249 memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1);
250 ptr=strlen(buffer);
251 end=strchr(buffer,'\n');
252 }
253 else
254 {
255 end=NULL;
256 }
257 alarm(TIMEOUT);
258 while(end==NULL)
259 {
260 if(PACKET_SIZE<=ptr)
261 {
262 fprintf(stderr,"bad packet\n");
263 ptr=0;
264 return(NULL);
265 }
266 ret=read(fd,buffer+ptr,PACKET_SIZE-ptr);
267
268 if(ret<=0 || timeout)
269 {
270 if(timeout)
271 {
272 fprintf(stderr,"timeout\n");
273 }
274 else
275 {
276 alarm(0);
277 }
278 ptr=0;
279 return(NULL);
280 }
281 buffer[ptr+ret]=0;
282 ptr=strlen(buffer);
283 end=strchr(buffer,'\n');
284 }
285 alarm(0);timeout=0;
286
287 end[0]=0;
288 ptr=strlen(buffer)+1;
289//# ifdef DEBUG
290 //printf("buffer: -%s-\n",buffer);
291//# endif
292 return(buffer);
293}