summaryrefslogtreecommitdiff
authorpaule <paule>2007-01-28 04:04:14 (UTC)
committer paule <paule>2007-01-28 04:04:14 (UTC)
commitec2309cb69365847762db542c41951629cd06cbe (patch) (unidiff)
tree2f0101c1f0d6268207dbd15eb21f40c812a4fff5
parent3cd37427b5c5f26f62cff583fbde914467ddafe3 (diff)
downloadopie-ec2309cb69365847762db542c41951629cd06cbe.zip
opie-ec2309cb69365847762db542c41951629cd06cbe.tar.gz
opie-ec2309cb69365847762db542c41951629cd06cbe.tar.bz2
Refactored out all communication with LIRC into new LircHandler class
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/tools/remote/buttondialog.cpp216
-rw-r--r--noncore/tools/remote/buttondialog.h12
-rw-r--r--noncore/tools/remote/learntab.cpp132
-rw-r--r--noncore/tools/remote/learntab.h9
-rw-r--r--noncore/tools/remote/lirchandler.cpp270
-rw-r--r--noncore/tools/remote/lirchandler.h38
-rw-r--r--noncore/tools/remote/mainview.cpp13
-rw-r--r--noncore/tools/remote/mainview.h3
-rw-r--r--noncore/tools/remote/packetread.h200
-rw-r--r--noncore/tools/remote/remote.cpp61
-rw-r--r--noncore/tools/remote/remote.pro4
-rw-r--r--noncore/tools/remote/remotetab.cpp120
-rw-r--r--noncore/tools/remote/remotetab.h7
13 files changed, 337 insertions, 748 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
@@ -1,293 +1,95 @@
1/* 1/*
2Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. 2Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie.
3Copyright (C) 2002 Thomas Stephens 3Copyright (C) 2002 Thomas Stephens
4 4
5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public 5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later 6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7version. 7version.
8 8
9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11Public License for more details. 11Public License for more details.
12 12
13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free 13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15*/ 15*/
16 16
17#include "buttondialog.h" 17#include "buttondialog.h"
18 18
19ButtonDialog::ButtonDialog(QString buttonName, QWidget *parent, const char*name, bool modal, WFlags f):QDialog(parent, name, modal, f) 19ButtonDialog::ButtonDialog(QString buttonName, QWidget *parent, const char*name, bool modal, WFlags f):QDialog(parent, name, modal, f)
20{ 20{
21 setCaption(tr(buttonName)); 21 setCaption(tr(buttonName));
22 22
23 QVBoxLayout *layout = new QVBoxLayout(this); 23 QVBoxLayout *layout = new QVBoxLayout(this);
24 24
25 QHBoxLayout *hlayout1 = new QHBoxLayout(this); 25 QHBoxLayout *hlayout1 = new QHBoxLayout(this);
26 QHBoxLayout *hlayout2 = new QHBoxLayout(this); 26 QHBoxLayout *hlayout2 = new QHBoxLayout(this);
27 QHBoxLayout *hlayout3 = new QHBoxLayout(this); 27 QHBoxLayout *hlayout3 = new QHBoxLayout(this);
28 28
29 layout->addSpacing(5); 29 layout->addSpacing(5);
30 layout->addLayout(hlayout1); 30 layout->addLayout(hlayout1);
31 layout->addSpacing(5); 31 layout->addSpacing(5);
32 layout->addLayout(hlayout2); 32 layout->addLayout(hlayout2);
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 36
37 lh = new LircHandler();
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");
39 hlayout1->addSpacing(5); 41 hlayout1->addSpacing(5);
40 hlayout1->addWidget(remoteLabel); 42 hlayout1->addWidget(remoteLabel);
41 hlayout1->addSpacing(5); 43 hlayout1->addSpacing(5);
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");
49 QLabel *buttonLabel = new QLabel(remote, "Button: ", this, "buttonLabel"); 51 QLabel *buttonLabel = new QLabel(remote, "Button: ", this, "buttonLabel");
50 hlayout2->addSpacing(5); 52 hlayout2->addSpacing(5);
51 hlayout2->addWidget(buttonLabel); 53 hlayout2->addWidget(buttonLabel);
52 hlayout2->addSpacing(5); 54 hlayout2->addSpacing(5);
53 hlayout2->addWidget(button); 55 hlayout2->addWidget(button);
54 hlayout2->addSpacing(5); 56 hlayout2->addSpacing(5);
55 button->insertItem("Button "); 57 button->insertItem("Button ");
56 connect(button, SIGNAL(activated(const QString&)), this, SLOT(buttonSelected(const QString&)) ); 58 connect(button, SIGNAL(activated(const QString&)), this, SLOT(buttonSelected(const QString&)) );
57 59
58 label = new QLineEdit(this, "label"); 60 label = new QLineEdit(this, "label");
59 label->setText(buttonName); 61 label->setText(buttonName);
60 QLabel *labelLabel = new QLabel(label, "Label: ", this, "labelLabel"); 62 QLabel *labelLabel = new QLabel(label, "Label: ", this, "labelLabel");
61 hlayout3->addSpacing(5); 63 hlayout3->addSpacing(5);
62 hlayout3->addWidget(labelLabel); 64 hlayout3->addWidget(labelLabel);
63 hlayout3->addSpacing(5); 65 hlayout3->addSpacing(5);
64 hlayout3->addWidget(label); 66 hlayout3->addWidget(label);
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}
74 81
75void ButtonDialog::buttonSelected(const QString &string) 82void ButtonDialog::buttonSelected(const QString &string)
76{ 83{
77 list+=string; 84 list+=string;
78} 85}
79 86
80QStringList ButtonDialog::getList() 87QStringList ButtonDialog::getList()
81{ 88{
82 return list; 89 return list;
83} 90}
84 91
85QString ButtonDialog::getLabel() 92QString 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}
diff --git a/noncore/tools/remote/buttondialog.h b/noncore/tools/remote/buttondialog.h
index 33dc4ef..cc697b5 100644
--- a/noncore/tools/remote/buttondialog.h
+++ b/noncore/tools/remote/buttondialog.h
@@ -1,59 +1,53 @@
1/* 1/*
2Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. 2Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie.
3Copyright (C) 2002 Thomas Stephens 3Copyright (C) 2002 Thomas Stephens
4 4
5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public 5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later 6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7version. 7version.
8 8
9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11Public License for more details. 11Public License for more details.
12 12
13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free 13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15*/ 15*/
16 16
17#include <qdialog.h> 17#include <qdialog.h>
18#include <qstring.h> 18#include <qstring.h>
19#include <qstringlist.h> 19#include <qstringlist.h>
20#include <qcombobox.h> 20#include <qcombobox.h>
21#include <qlayout.h> 21#include <qlayout.h>
22#include <qlabel.h> 22#include <qlabel.h>
23#include <qlineedit.h> 23#include <qlineedit.h>
24#include <qmessagebox.h> 24#include <qmessagebox.h>
25#include <stdio.h> 25#include <stdio.h>
26#include <stdlib.h> 26#include <stdlib.h>
27#include <string.h> 27#include <string.h>
28#include <sys/socket.h> 28#include <sys/socket.h>
29#include <sys/types.h> 29#include <sys/types.h>
30#include <sys/un.h> 30#include <sys/un.h>
31#include <unistd.h> 31#include <unistd.h>
32#include <errno.h> 32#include <errno.h>
33 33
34#define PACKET_SIZE 256 34#include "lirchandler.h"
35#define TIMEOUT 3
36 35
37class ButtonDialog : public QDialog 36class ButtonDialog : public QDialog
38{ 37{
39 Q_OBJECT 38 Q_OBJECT
40public: 39public:
41 ButtonDialog(QString buttonName, QWidget *parent=0, const char*name=0, bool modal=FALSE, WFlags f=0); 40 ButtonDialog(QString buttonName, QWidget *parent=0, const char*name=0, bool modal=FALSE, WFlags f=0);
42 void setIRSocket(int newfd); 41 ~ButtonDialog();
43 const char *readPacket();
44 QStringList getRemotes();
45 QStringList getButtons(const char *remoteName);
46 QStringList getList(); 42 QStringList getList();
47 QString getLabel(); 43 QString getLabel();
48public slots: 44public slots:
49 void remoteSelected(const QString &string); 45 void remoteSelected(const QString &string);
50 void buttonSelected(const QString &string); 46 void buttonSelected(const QString &string);
51private: 47private:
52 QComboBox *remote; 48 QComboBox *remote;
53 QComboBox *button; 49 QComboBox *button;
54 QStringList list; 50 QStringList list;
55 QLineEdit *label; 51 QLineEdit *label;
56 int fd; 52 LircHandler *lh;
57 int timeout;
58 struct sockaddr_un addr;
59}; 53};
diff --git a/noncore/tools/remote/learntab.cpp b/noncore/tools/remote/learntab.cpp
index 335a3e9..69d2e7f 100644
--- a/noncore/tools/remote/learntab.cpp
+++ b/noncore/tools/remote/learntab.cpp
@@ -1,192 +1,66 @@
1/* 1/*
2Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. 2Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie.
3Copyright (C) 2002 Thomas Stephens 3Copyright (C) 2002 Thomas Stephens
4 4
5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public 5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later 6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7version. 7version.
8 8
9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11Public License for more details. 11Public License for more details.
12 12
13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free 13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15*/ 15*/
16 16
17#include "learntab.h" 17#include "learntab.h"
18 18
19/* OPIE */ 19/* OPIE */
20#include <qpe/qpeapplication.h> 20#include <qpe/qpeapplication.h>
21 21
22LearnTab::LearnTab(QWidget *parent, const char *name):QWidget(parent,name) 22LearnTab::LearnTab(QWidget *parent, const char *name):QWidget(parent,name)
23{ 23{
24 LircHandler lh;
25
24 QVBoxLayout *layout = new QVBoxLayout(this); 26 QVBoxLayout *layout = new QVBoxLayout(this);
25 QHBoxLayout *bottomLayout = new QHBoxLayout(this); 27 QHBoxLayout *bottomLayout = new QHBoxLayout(this);
26 28
27 layout->insertSpacing(0,5); 29 layout->insertSpacing(0,5);
28 remotesBox = new QListBox(this, "remotesBox"); 30 remotesBox = new QListBox(this, "remotesBox");
29 layout->insertWidget(0, remotesBox, 1); 31 layout->insertWidget(0, remotesBox, 1);
30 remotesBox->insertStringList(getRemotes()); 32 remotesBox->insertStringList(lh.getRemotes());
31 33
32 layout->insertSpacing(-1,5); 34 layout->insertSpacing(-1,5);
33 layout->insertLayout(-1, bottomLayout); 35 layout->insertLayout(-1, bottomLayout);
34 layout->insertSpacing(-1,5); 36 layout->insertSpacing(-1,5);
35 37
36 QPushButton *add = new QPushButton("Add", this, "add"); 38 QPushButton *add = new QPushButton("Add", this, "add");
37 bottomLayout->insertSpacing(-1, 5); 39 bottomLayout->insertSpacing(-1, 5);
38 bottomLayout->insertWidget(-1, add); 40 bottomLayout->insertWidget(-1, add);
39 bottomLayout->insertSpacing(-1, 5); 41 bottomLayout->insertSpacing(-1, 5);
40 QPushButton *edit = new QPushButton("Edit", this, "edit"); 42 QPushButton *edit = new QPushButton("Edit", this, "edit");
41 bottomLayout->insertWidget(-1, edit); 43 bottomLayout->insertWidget(-1, edit);
42 bottomLayout->insertSpacing(-1, 5); 44 bottomLayout->insertSpacing(-1, 5);
43 QPushButton *del = new QPushButton("Delete", this, "delete"); 45 QPushButton *del = new QPushButton("Delete", this, "delete");
44 bottomLayout->insertWidget(-1, del); 46 bottomLayout->insertWidget(-1, del);
45 bottomLayout->insertSpacing(-1, 5); 47 bottomLayout->insertSpacing(-1, 5);
46 48
47 connect(add, SIGNAL(clicked()), this, SLOT(add()) ); 49 connect(add, SIGNAL(clicked()), this, SLOT(add()) );
48 connect(edit, SIGNAL(clicked()), this, SLOT(edit()) ); 50 connect(edit, SIGNAL(clicked()), this, SLOT(edit()) );
49 connect(del, SIGNAL(clicked()), this, SLOT(del()) ); 51 connect(del, SIGNAL(clicked()), this, SLOT(del()) );
50} 52}
51 53
52void LearnTab::add() 54void LearnTab::add()
53{ 55{
54 printf("LearnTab::add: add pressed\n"); 56 printf("LearnTab::add: add pressed\n");
55 RecordDialog *dialog = new RecordDialog(this); 57 RecordDialog *dialog = new RecordDialog(this);
56 QPEApplication::showDialog( dialog ); 58 QPEApplication::showDialog( dialog );
57} 59}
58 60
59void LearnTab::edit() 61void LearnTab::edit()
60{} 62{}
61 63
62void LearnTab::del() 64void LearnTab::del()
63{} 65{}
64 66
65QStringList LearnTab::getRemotes()
66{
67 const char write_buffer[] = "LIST\n";
68 const char *readbuffer;
69 int i, numlines;
70 QStringList list;
71
72 addr.sun_family=AF_UNIX;
73 strcpy(addr.sun_path,"/dev/lircd");
74
75 fd = socket(AF_UNIX, SOCK_STREAM, 0);
76 if(fd == -1)
77 {
78 QMessageBox *mb = new QMessageBox("Error!",
79 "couldnt connect to socket",
80 QMessageBox::NoIcon,
81 QMessageBox::Ok,
82 QMessageBox::NoButton,
83 QMessageBox::NoButton);
84 mb->exec();
85 perror("LearnTab::GetRemotes");
86 return NULL;
87 }
88
89 if(::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1)
90 {
91 QMessageBox *mb = new QMessageBox("Error!",
92 "couldnt connect to socket",
93 QMessageBox::NoIcon,
94 QMessageBox::Ok,
95 QMessageBox::NoButton,
96 QMessageBox::NoButton);
97 mb->exec();
98 perror("LearnTab::GetRemotes");
99 return NULL;
100 }
101
102 write(fd, write_buffer, strlen(write_buffer));
103
104 for(i=0; i<5; i++)
105 {
106 printf("%d\n", i);
107 readbuffer = readPacket();
108 printf("%s", readbuffer);
109 printf("%d\n", i);
110 }
111
112 numlines = atoi(readbuffer);
113
114 for(i=0; i<numlines; i++)
115 {
116 list+=readPacket();
117 }
118
119 if(strcasecmp(readPacket(), "END") != 0)
120 {
121 QMessageBox *mb = new QMessageBox("Error!",
122 "bad packet",
123 QMessageBox::NoIcon,
124 QMessageBox::Ok,
125 QMessageBox::NoButton,
126 QMessageBox::NoButton);
127 mb->exec();
128 perror("LearnTab::GetRemotes");
129 return NULL;
130 }
131
132 ::close(fd);
133 return list;
134}
135
136//this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html
137const char *LearnTab::readPacket()
138{
139 static char buffer[PACKET_SIZE+1]="";
140 char *end;
141 static int ptr=0,end_len=0;
142 ssize_t ret;
143 timeout = 0;
144
145 if(ptr>0)
146 {
147 memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1);
148 ptr=strlen(buffer);
149 end=strchr(buffer,'\n');
150 }
151 else
152 {
153 end=NULL;
154 }
155 alarm(TIMEOUT);
156 while(end==NULL)
157 {
158 if(PACKET_SIZE<=ptr)
159 {
160 fprintf(stderr,"bad packet\n");
161 ptr=0;
162 return(NULL);
163 }
164 ret=read(fd,buffer+ptr,PACKET_SIZE-ptr);
165
166 if(ret<=0 || timeout)
167 {
168 if(timeout)
169 {
170 fprintf(stderr,"timeout\n");
171 }
172 else
173 {
174 alarm(0);
175 }
176 ptr=0;
177 return(NULL);
178 }
179 buffer[ptr+ret]=0;
180 ptr=strlen(buffer);
181 end=strchr(buffer,'\n');
182 }
183 alarm(0);timeout=0;
184
185 end[0]=0;
186 ptr=strlen(buffer)+1;
187 //# ifdef DEBUG
188 //printf("buffer: -%s-\n",buffer);
189 //# endif
190 return(buffer);
191}
192
diff --git a/noncore/tools/remote/learntab.h b/noncore/tools/remote/learntab.h
index cb84600..c9d8e41 100644
--- a/noncore/tools/remote/learntab.h
+++ b/noncore/tools/remote/learntab.h
@@ -1,55 +1,48 @@
1/* 1/*
2Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. 2Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie.
3Copyright (C) 2002 Thomas Stephens 3Copyright (C) 2002 Thomas Stephens
4 4
5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public 5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later 6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7version. 7version.
8 8
9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11Public License for more details. 11Public License for more details.
12 12
13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free 13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15*/ 15*/
16 16
17#include <qwidget.h> 17#include <qwidget.h>
18#include <qlistbox.h> 18#include <qlistbox.h>
19#include <qstring.h> 19#include <qstring.h>
20#include <qstringlist.h> 20#include <qstringlist.h>
21#include <qlayout.h> 21#include <qlayout.h>
22#include <qpushbutton.h> 22#include <qpushbutton.h>
23#include <qmessagebox.h> 23#include <qmessagebox.h>
24 24
25#include <stdio.h> 25#include <stdio.h>
26#include <stdlib.h> 26#include <stdlib.h>
27#include <string.h> 27#include <string.h>
28#include <sys/socket.h> 28#include <sys/socket.h>
29#include <sys/types.h> 29#include <sys/types.h>
30#include <sys/un.h> 30#include <sys/un.h>
31#include <unistd.h> 31#include <unistd.h>
32#include <errno.h> 32#include <errno.h>
33 33
34#include "recorddialog.h" 34#include "recorddialog.h"
35 35#include "lirchandler.h"
36#define PACKET_SIZE 256
37#define TIMEOUT 3
38 36
39class LearnTab : public QWidget 37class LearnTab : public QWidget
40{ 38{
41 Q_OBJECT 39 Q_OBJECT
42public: 40public:
43 LearnTab(QWidget *parent=0, const char *name=0); 41 LearnTab(QWidget *parent=0, const char *name=0);
44 const char *readPacket();
45 QStringList getRemotes();
46public slots: 42public slots:
47 void add(); 43 void add();
48 void edit(); 44 void edit();
49 void del(); 45 void del();
50private: 46private:
51 QListBox *remotesBox; 47 QListBox *remotesBox;
52 int fd;
53 int timeout;
54 struct sockaddr_un addr;
55}; 48};
diff --git a/noncore/tools/remote/lirchandler.cpp b/noncore/tools/remote/lirchandler.cpp
new file mode 100644
index 0000000..f44806e
--- a/dev/null
+++ b/noncore/tools/remote/lirchandler.cpp
@@ -0,0 +1,270 @@
1/*
2Opie-Remote. emulates remote controls on an iPaq (and maybe a Zaurus) in Opie.
3Copyright (C) 2007 Paul Eggleton & Thomas Stephens
4
5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7version.
8
9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11Public License for more details.
12
13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15*/
16
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20#include <sys/socket.h>
21#include <sys/types.h>
22#include <sys/un.h>
23#include <unistd.h>
24#include <errno.h>
25
26#include <qstring.h>
27#include <qmessagebox.h>
28#include <qobject.h>
29#include <opie2/oprocess.h>
30
31#include "lirchandler.h"
32
33#define PACKET_SIZE 256
34#define TIMEOUT 3
35#define LIRCD_SOCKET "/dev/lircd"
36#define LIRCD_SERVICECMD "/etc/init.d/lircd"
37
38using namespace Opie::Core;
39
40LircHandler::LircHandler(void)
41{
42 fd = 0;
43 addr.sun_family=AF_UNIX;
44 strcpy(addr.sun_path, LIRCD_SOCKET);
45}
46
47bool LircHandler::connectLirc(void)
48{
49 fd = socket(AF_UNIX, SOCK_STREAM, 0);
50 if(fd == -1)
51 {
52 QMessageBox *mb = new QMessageBox(QObject::tr("Error"),
53 QObject::tr("Unable to create socket"),
54 QMessageBox::Critical,
55 QMessageBox::Ok,
56 QMessageBox::NoButton,
57 QMessageBox::NoButton);
58 mb->exec();
59 perror("LircHandler::connectLirc");
60 return false;
61 }
62
63 if(::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1)
64 {
65 QMessageBox *mb = new QMessageBox(QObject::tr("Error"),
66 QObject::tr("Could not connect to lircd"),
67 QMessageBox::Critical,
68 QMessageBox::Ok,
69 QMessageBox::NoButton,
70 QMessageBox::NoButton);
71 mb->exec();
72 perror("LircHandler::connectLirc");
73 return false;
74 }
75
76 return true;
77}
78
79//this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html
80const char *LircHandler::readPacket()
81{
82 static char buffer[PACKET_SIZE+1]="";
83 char *end;
84 static int ptr=0;
85 ssize_t ret;
86 int timeout = 0;
87
88 if(ptr>0)
89 {
90 memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1);
91 ptr=strlen(buffer);
92 end=strchr(buffer,'\n');
93 }
94 else
95 {
96 end=NULL;
97 }
98 alarm(TIMEOUT);
99 while(end==NULL)
100 {
101 if(PACKET_SIZE<=ptr)
102 {
103 fprintf(stderr,"readPacket: bad packet\n");
104 ptr=0;
105 return(NULL);
106 }
107 ret=read(fd,buffer+ptr,PACKET_SIZE-ptr);
108
109 if(ret<=0 || timeout)
110 {
111 if(timeout)
112 {
113 fprintf(stderr,"readPacket: timeout\n");
114 }
115 else
116 {
117 alarm(0);
118 }
119 ptr=0;
120 return(NULL);
121 }
122 buffer[ptr+ret]=0;
123 ptr=strlen(buffer);
124 end=strchr(buffer,'\n');
125 }
126 alarm(0);
127
128 end[0]=0;
129 ptr=strlen(buffer)+1;
130//# ifdef DEBUG
131 //printf("buffer: -%s-\n",buffer);
132//# endif
133 return(buffer);
134}
135
136QStringList LircHandler::getRemotes(void)
137{
138 const char write_buffer[] = "LIST\n";
139 const char *readbuffer;
140 int i, numlines;
141 QStringList list;
142
143 if(connectLirc()) {
144 write(fd, write_buffer, strlen(write_buffer) );
145
146 for(i=0; i<5; i++)
147 {
148 readbuffer = readPacket();
149 }
150
151 numlines = atoi(readbuffer);
152
153 for(i=0; i<numlines; i++)
154 {
155 list+=readPacket();
156 }
157
158 if(strcasecmp(readPacket(), "END") != 0)
159 {
160 QMessageBox *mb = new QMessageBox(QObject::tr("Error"),
161 QObject::tr("Bad packet while communicating with lircd"),
162 QMessageBox::Critical,
163 QMessageBox::Ok,
164 QMessageBox::NoButton,
165 QMessageBox::NoButton);
166 mb->exec();
167 perror("LircHandler::getRemotes");
168 return NULL;
169 }
170
171 ::close(fd);
172 }
173
174 return list;
175}
176
177QStringList LircHandler::getButtons(const char *remoteName)
178{
179 QString write_buffer = "LIST ";
180 const char *readbuffer;
181 int i, j, numlines;
182 QStringList list;
183 QString string;
184
185 write_buffer += remoteName;
186 write_buffer += '\n';
187
188 if(connectLirc()) {
189 write(fd, write_buffer.latin1(), strlen(write_buffer) );
190
191 for(i=0; i<5; i++)
192 {
193 readbuffer = readPacket();
194 }
195
196 numlines = atoi(readbuffer);
197
198 for(i=0; i<numlines; i++)
199 {
200 list+=readPacket();
201 for(j=0; j<list[i].length(); j++)
202 {
203 if(list[i][j] == ' ')
204 break;
205 }
206 list[i].remove(0, j+1);
207 }
208
209 if(strcasecmp(readPacket(), "END") != 0)
210 {
211 QMessageBox *mb = new QMessageBox(QObject::tr("Error"),
212 QObject::tr("Bad packet while communicating with lircd"),
213 QMessageBox::Critical,
214 QMessageBox::Ok,
215 QMessageBox::NoButton,
216 QMessageBox::NoButton);
217 mb->exec();
218 perror("LircHandler::getRemotes");
219 return NULL;
220 }
221
222 ::close(fd);
223 }
224
225 return list;
226}
227
228int LircHandler::sendIR(const char *irbutton)
229{
230 const char *read_buffer;
231 bool done=false;
232
233 if(connectLirc()) {
234 printf("fd2: %d\n", fd);
235 printf("%s", irbutton);
236
237 printf("1\n");
238 printf("%d\n", write(fd, irbutton, strlen(irbutton) ) );
239 printf("2\n");
240 while(!done)
241 {
242 read_buffer=readPacket();
243 printf("%s\n", read_buffer);
244 if(strcasecmp(read_buffer, "END") == 0)
245 {
246 printf("done reading packet\n");
247 done=true;
248 }
249 }
250 ::close(fd);
251 return 1;
252 }
253 else
254 return 0;
255}
256
257bool LircHandler::startLircd(void)
258{
259 return (system(LIRCD_SERVICECMD " start") == 0);
260}
261
262bool LircHandler::stopLircd(void)
263{
264 return (system(LIRCD_SERVICECMD " stop") == 0);
265}
266
267bool LircHandler::isLircdRunning(void)
268{
269 return (OProcess::processPID("lircd") != 0);
270}
diff --git a/noncore/tools/remote/lirchandler.h b/noncore/tools/remote/lirchandler.h
new file mode 100644
index 0000000..29894b4
--- a/dev/null
+++ b/noncore/tools/remote/lirchandler.h
@@ -0,0 +1,38 @@
1/*
2Opie-Remote. emulates remote controls on an iPaq (and maybe a Zaurus) in Opie.
3Copyright (C) 2007 Paul Eggleton & Thomas Stephens
4
5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7version.
8
9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11Public License for more details.
12
13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15*/
16
17#ifndef LIRCHANDLER_H
18#define LIRCHANDLER_H
19
20class LircHandler
21{
22private:
23 bool connectLirc(void);
24 const char *readPacket();
25
26 struct sockaddr_un addr;
27 int fd;
28public:
29 LircHandler(void);
30 QStringList getRemotes(void);
31 QStringList getButtons(const char *remoteName);
32 int sendIR(const char *irbutton);
33 bool startLircd(void);
34 bool stopLircd(void);
35 bool isLircdRunning(void);
36};
37
38#endif
diff --git a/noncore/tools/remote/mainview.cpp b/noncore/tools/remote/mainview.cpp
index 724eba9..8c87785 100644
--- a/noncore/tools/remote/mainview.cpp
+++ b/noncore/tools/remote/mainview.cpp
@@ -1,67 +1,54 @@
1/* 1/*
2Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. 2Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie.
3Copyright (C) 2002 Thomas Stephens 3Copyright (C) 2002 Thomas Stephens
4 4
5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public 5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later 6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7version. 7version.
8 8
9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11Public License for more details. 11Public License for more details.
12 12
13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free 13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15*/ 15*/
16 16
17#include "mainview.h" 17#include "mainview.h"
18 18
19#include <opie2/oresource.h> 19#include <opie2/oresource.h>
20 20
21MainView::MainView(QWidget *parent, const char *name) : QWidget(parent, name) 21MainView::MainView(QWidget *parent, const char *name) : QWidget(parent, name)
22{ 22{
23 setIcon( Opie::Core::OResource::loadPixmap( "remote", Opie::Core::OResource::SmallIcon ) ); 23 setIcon( Opie::Core::OResource::loadPixmap( "remote", Opie::Core::OResource::SmallIcon ) );
24 setCaption(tr("Remote") ); 24 setCaption(tr("Remote") );
25 25
26 QVBoxLayout *layout = new QVBoxLayout(this); 26 QVBoxLayout *layout = new QVBoxLayout(this);
27 QTabWidget *tabs = new QTabWidget(this); 27 QTabWidget *tabs = new QTabWidget(this);
28 28
29 layout->addWidget(tabs); 29 layout->addWidget(tabs);
30 30
31 remote = new RemoteTab(tabs); 31 remote = new RemoteTab(tabs);
32 learn = new LearnTab(tabs); 32 learn = new LearnTab(tabs);
33 config = new ConfigTab(tabs); 33 config = new ConfigTab(tabs);
34 help = new HelpTab(tabs); 34 help = new HelpTab(tabs);
35 connect(config, SIGNAL(remotesChanged()), this, SLOT(updateRemotesList()) ); 35 connect(config, SIGNAL(remotesChanged()), this, SLOT(updateRemotesList()) );
36 36
37 remote->setIRSocket(fd);
38
39 tabs->addTab(remote, tr("Remote") ); 37 tabs->addTab(remote, tr("Remote") );
40 tabs->addTab(learn,tr("Learn") ); 38 tabs->addTab(learn,tr("Learn") );
41 tabs->addTab(config,tr("Config") ); 39 tabs->addTab(config,tr("Config") );
42 tabs->addTab(help, tr("Help") ); 40 tabs->addTab(help, tr("Help") );
43 41
44 printf("1\n"); 42 printf("1\n");
45 cfg = new Config("Remote"); 43 cfg = new Config("Remote");
46 printf("2\n"); 44 printf("2\n");
47 45
48 remote->setConfig(cfg); 46 remote->setConfig(cfg);
49 config->setConfig(cfg); 47 config->setConfig(cfg);
50} 48}
51 49
52int MainView::getIRSocket()
53{
54 return fd;
55}
56
57void MainView::setIRSocket(int newfd)
58{
59 fd = newfd;
60 remote->setIRSocket(fd);
61}
62
63void MainView::updateRemotesList() 50void MainView::updateRemotesList()
64{ 51{
65 remote->updateRemotesList(); 52 remote->updateRemotesList();
66 printf("MainView: got remotes changed signal\n"); 53 printf("MainView: got remotes changed signal\n");
67} 54}
diff --git a/noncore/tools/remote/mainview.h b/noncore/tools/remote/mainview.h
index 7ea82a6..b1ddde4 100644
--- a/noncore/tools/remote/mainview.h
+++ b/noncore/tools/remote/mainview.h
@@ -1,55 +1,52 @@
1/* 1/*
2Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. 2Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie.
3Copyright (C) 2002 Thomas Stephens 3Copyright (C) 2002 Thomas Stephens
4 4
5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public 5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later 6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7version. 7version.
8 8
9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11Public License for more details. 11Public License for more details.
12 12
13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free 13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15*/ 15*/
16 16
17#include <qpe/qpeapplication.h> 17#include <qpe/qpeapplication.h>
18#include <qpe/config.h> 18#include <qpe/config.h>
19#include <qpushbutton.h> 19#include <qpushbutton.h>
20#include <qtabwidget.h> 20#include <qtabwidget.h>
21#include <qlayout.h> 21#include <qlayout.h>
22#include <qmessagebox.h> 22#include <qmessagebox.h>
23#include <qpaintdevice.h> 23#include <qpaintdevice.h>
24#include <qobject.h> 24#include <qobject.h>
25#include <sys/socket.h> 25#include <sys/socket.h>
26#include <sys/types.h> 26#include <sys/types.h>
27#include <sys/un.h> 27#include <sys/un.h>
28#include <unistd.h> 28#include <unistd.h>
29#include <stdio.h> 29#include <stdio.h>
30#include <signal.h> 30#include <signal.h>
31 31
32#include "remotetab.h" 32#include "remotetab.h"
33#include "learntab.h" 33#include "learntab.h"
34#include "configtab.h" 34#include "configtab.h"
35#include "helptab.h" 35#include "helptab.h"
36 36
37#define BUFFERSIZE 256 37#define BUFFERSIZE 256
38 38
39class MainView : public QWidget 39class MainView : public QWidget
40{ 40{
41 Q_OBJECT 41 Q_OBJECT
42public: 42public:
43 MainView(QWidget *parent=0, const char *name=0); 43 MainView(QWidget *parent=0, const char *name=0);
44 int getIRSocket();
45 void setIRSocket(int newfd);
46public slots: 44public slots:
47 void updateRemotesList(); 45 void updateRemotesList();
48private: 46private:
49 int fd;
50 RemoteTab *remote; 47 RemoteTab *remote;
51 ConfigTab *config; 48 ConfigTab *config;
52 LearnTab *learn; 49 LearnTab *learn;
53 HelpTab *help; 50 HelpTab *help;
54 Config *cfg; 51 Config *cfg;
55}; 52};
diff --git a/noncore/tools/remote/packetread.h b/noncore/tools/remote/packetread.h
deleted file mode 100644
index 5dc1ad4..0000000
--- a/noncore/tools/remote/packetread.h
+++ b/dev/null
@@ -1,200 +0,0 @@
1/*
2Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie.
3Copyright (C) 2002 Thomas Stephens
4
5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7version.
8
9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11Public License for more details.
12
13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
16file not used
17*/
18
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22#include <sys/socket.h>
23#include <sys/types.h>
24#include <sys/un.h>
25#include <unistd.h>
26#include <errno.h>
27
28#define PACKET_SIZE 256
29#define TIMEOUT 3
30
31//this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html
32const char *readPacket(int fd)
33{
34 static char buffer[PACKET_SIZE+1]="";
35 char *end;
36 static int ptr=0,end_len=0;
37 ssize_t ret;
38
39 if(ptr>0)
40 {
41 memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1);
42 ptr=strlen(buffer);
43 end=strchr(buffer,'\n');
44 }
45 else
46 {
47 end=NULL;
48 }
49 alarm(TIMEOUT);
50 while(end==NULL)
51 {
52 if(PACKET_SIZE<=ptr)
53 {
54 // fprintf(stderr,"%s: bad packet\n",progname);
55 ptr=0;
56 return(NULL);
57 }
58 ret=read(fd,buffer+ptr,PACKET_SIZE-ptr);
59
60 if(ret<=0 || timeout)
61 {
62 if(timeout)
63 {
64 // fprintf(stderr,"%s: timeout\n",progname);
65 }
66 else
67 {
68 alarm(0);
69 }
70 ptr=0;
71 return(NULL);
72 }
73 buffer[ptr+ret]=0;
74 ptr=strlen(buffer);
75 end=strchr(buffer,'\n');
76 }
77 alarm(0);timeout=0;
78
79 end[0]=0;
80 ptr=strlen(buffer)+1;
81//# ifdef DEBUG
82 //printf("buffer: -%s-\n",buffer);
83//# endif
84 return(buffer);
85}
86QStringList getRemotes(int fd)
87{
88 const char write_buffer[] = "LIST\n";
89 const char *readbuffer;
90 int i, numlines;
91 QStringList list;
92
93 fd = socket(AF_UNIX, SOCK_STREAM, 0);
94
95 if(std::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1)
96 {
97 QMessageBox *mb = new QMessageBox("Error!",
98 "couldnt connect to socket",
99 QMessageBox::NoIcon,
100 QMessageBox::Ok,
101 QMessageBox::NoButton,
102 QMessageBox::NoButton);
103 mb->exec();
104 perror("ConfigTab::GetRemotes");
105 return NULL;
106 }
107
108 write(fd, write_buffer, strlen(write_buffer) );
109
110 for(i=0; i<5; i++)
111 {
112 readbuffer = readPacket(int fd);
113 }
114
115 numlines = atoi(readbuffer);
116
117 for(i=0; i<numlines; i++)
118 {
119 list+=readPacket();
120 }
121
122 if(strcasecmp(readPacket(), "END") != 0)
123 {
124 QMessageBox *mb = new QMessageBox("Error!",
125 "bad packet",
126 QMessageBox::NoIcon,
127 QMessageBox::Ok,
128 QMessageBox::NoButton,
129 QMessageBox::NoButton);
130 mb->exec();
131 perror("ConfigTab::GetRemotes");
132 return NULL;
133 }
134
135 std::close(fd);
136 return list;
137}
138
139QStringList getButtons(int fd, const char *remoteName)
140{
141 QString write_buffer = "LIST ";
142 const char *readbuffer;
143 int i, j, numlines;
144 QStringList list;
145 QString string;
146
147 write_buffer += remoteName;
148 write_buffer += '\n';
149
150 fd = socket(AF_UNIX, SOCK_STREAM, 0);
151
152 if(std::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1)
153 {
154 QMessageBox *mb = new QMessageBox("Error!",
155 "couldnt connect to socket",
156 QMessageBox::NoIcon,
157 QMessageBox::Ok,
158 QMessageBox::NoButton,
159 QMessageBox::NoButton);
160 mb->exec();
161 perror("ConfigTab::GetRemotes");
162 return NULL;
163 }
164
165 write(fd, write_buffer.latin1(), strlen(write_buffer) );
166
167 for(i=0; i<5; i++)
168 {
169 readbuffer = readPacket();
170 }
171
172 numlines = atoi(readbuffer);
173
174 for(i=0; i<numlines; i++)
175 {
176 list+=readPacket();
177 for(j=0; j<list[i].length(); j++)
178 {
179 if(list[i][j] == ' ')
180 break;
181 }
182 list[i].remove(0, j+1);
183 }
184
185 if(strcasecmp(readPacket(), "END") != 0)
186 {
187 QMessageBox *mb = new QMessageBox("Error!",
188 "bad packet",
189 QMessageBox::NoIcon,
190 QMessageBox::Ok,
191 QMessageBox::NoButton,
192 QMessageBox::NoButton);
193 mb->exec();
194 perror("ConfigTab::GetRemotes");
195 return NULL;
196 }
197
198 std::close(fd);
199 return list;
200}
diff --git a/noncore/tools/remote/remote.cpp b/noncore/tools/remote/remote.cpp
index 35d06bc..67fc57d 100644
--- a/noncore/tools/remote/remote.cpp
+++ b/noncore/tools/remote/remote.cpp
@@ -1,105 +1,60 @@
1/* 1/*
2Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. 2Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie.
3Copyright (C) 2002 Thomas Stephens 3Copyright (C) 2002 Thomas Stephens
4 4
5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public 5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later 6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7version. 7version.
8 8
9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11Public License for more details. 11Public License for more details.
12 12
13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free 13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15*/ 15*/
16 16
17#include "mainview.h" 17#include "mainview.h"
18 18
19/* OPIE */ 19/* OPIE */
20#include <qpe/qpeapplication.h> 20#include <qpe/qpeapplication.h>
21#include <qpe/config.h> 21#include <qpe/config.h>
22 22
23/* QT */ 23/* QT */
24#include <qpushbutton.h> 24#include <qpushbutton.h>
25#include <qtabwidget.h> 25#include <qtabwidget.h>
26#include <qlayout.h> 26#include <qlayout.h>
27#include <qmessagebox.h> 27#include <qmessagebox.h>
28#include <qpaintdevice.h> 28#include <qpaintdevice.h>
29#include <qobject.h> 29#include <qobject.h>
30 30
31/* STD */ 31/* STD */
32#include <sys/socket.h> 32#include <sys/socket.h>
33#include <sys/types.h> 33#include <sys/types.h>
34#include <sys/un.h> 34#include <sys/un.h>
35#include <unistd.h> 35#include <unistd.h>
36#include <stdio.h> 36#include <stdio.h>
37#include <signal.h> 37#include <signal.h>
38 38
39 39
40/*void reconnect(int &fd)
41{
42 //struct sockaddr_un addr;
43
44 addr.sun_family=AF_UNIX;
45 strcpy(addr.sun_path,"/dev/lircd");
46 fd = socket(AF_UNIX, SOCK_STREAM, 0);
47
48 if(connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1)
49 {
50 QMessageBox *mb = new QMessageBox("error",
51 "couldnt connect to socket",
52 QMessageBox::NoIcon,
53 QMessageBox::Ok,
54 QMessageBox::NoButton,
55 QMessageBox::NoButton);
56 mb->exec();
57 }
58}
59*/
60
61int main( int argc, char **argv ) 40int main( int argc, char **argv )
62{ 41{
63 QPEApplication a( argc, argv ); 42 QPEApplication a( argc, argv );
64 MainView w; 43 MainView w;
44 a.setMainWidget( &w );
45 QPEApplication::showWidget( &w );
65 46
66 int fd; 47 LircHandler lh;
67 //struct sockaddr_un addr; 48 if(!lh.isLircdRunning()) {
68 //char read_buffer[BUFFERSIZE+1]; 49 QMessageBox mb("Error!",
69 //char write_buffer[] = "LIST\n"; 50 "Lircd is not running",
70
71 //addr.sun_family=AF_UNIX;
72 //strcpy(addr.sun_path,"/dev/lircd");
73 //fd = socket(AF_UNIX, SOCK_STREAM, 0);
74
75 //printf("fd1: %d\n", fd);
76 /*
77 if(connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1)
78 {
79 QMessageBox *mb = new QMessageBox("error",
80 "couldnt connect to socket",
81 QMessageBox::NoIcon, 51 QMessageBox::NoIcon,
82 QMessageBox::Ok, 52 QMessageBox::Ok,
83 QMessageBox::NoButton, 53 QMessageBox::NoButton,
84 QMessageBox::NoButton); 54 QMessageBox::NoButton);
85 mb->exec(); 55 mb.exec();
86 }
87 */
88
89 //printf("%d\n", write(fd, write_buffer, sizeof(write_buffer) ) );
90
91 //printf("%d\n", read(fd, read_buffer, BUFFERSIZE ) );
92 56
93 //QMessageBox *mbtest = new QMessageBox("lirc test", 57 }
94 // *new QString((const char *) read_buffer),
95 // QMessageBox::NoIcon,
96 // QMessageBox::Ok,
97 // QMessageBox::NoButton,
98 // QMessageBox::NoButton);
99 //mbtest->exec();
100 58
101 a.setMainWidget( &w );
102 w.setIRSocket(fd);
103 QPEApplication::showWidget( &w );
104 return a.exec(); 59 return a.exec();
105} 60}
diff --git a/noncore/tools/remote/remote.pro b/noncore/tools/remote/remote.pro
index 880856c..59ea81b 100644
--- a/noncore/tools/remote/remote.pro
+++ b/noncore/tools/remote/remote.pro
@@ -1,11 +1,11 @@
1 TEMPLATE=app 1 TEMPLATE=app
2 CONFIG +=qt warn_on 2 CONFIG +=qt warn_on
3 DESTDIR =$(OPIEDIR)/bin 3 DESTDIR =$(OPIEDIR)/bin
4 HEADERS = remotetab.h learntab.h configtab.h topgroup.h dvdgroup.h channelgroup.h vcrgroup.h buttondialog.h topgroupconf.h dvdgroupconf.h channelgroupconf.h vcrgroupconf.h mainview.h recorddialog.h helptab.h 4 HEADERS = remotetab.h learntab.h configtab.h topgroup.h dvdgroup.h channelgroup.h vcrgroup.h buttondialog.h topgroupconf.h dvdgroupconf.h channelgroupconf.h vcrgroupconf.h mainview.h recorddialog.h helptab.h lirchandler.h
5 SOURCES =remote.cpp remotetab.cpp learntab.cpp configtab.cpp topgroup.cpp dvdgroup.cpp channelgroup.cpp vcrgroup.cpp buttondialog.cpp topgroupconf.cpp dvdgroupconf.cpp channelgroupconf.cpp vcrgroupconf.cpp mainview.cpp recorddialog.cpp helptab.cpp 5 SOURCES =remote.cpp remotetab.cpp learntab.cpp configtab.cpp topgroup.cpp dvdgroup.cpp channelgroup.cpp vcrgroup.cpp buttondialog.cpp topgroupconf.cpp dvdgroupconf.cpp channelgroupconf.cpp vcrgroupconf.cpp mainview.cpp recorddialog.cpp helptab.cpp lirchandler.cpp
6 INCLUDEPATH+=$(OPIEDIR)/include 6 INCLUDEPATH+=$(OPIEDIR)/include
7 DEPENDPATH+=$(OPIEDIR)/include 7 DEPENDPATH+=$(OPIEDIR)/include
8 LIBS +=-lqpe -lopiecore2 8 LIBS +=-lqpe -lopiecore2
9TARGET = remote 9TARGET = remote
10 10
11include( $(OPIEDIR)/include.pro ) 11include( $(OPIEDIR)/include.pro )
diff --git a/noncore/tools/remote/remotetab.cpp b/noncore/tools/remote/remotetab.cpp
index 5b02e94..84038ca 100644
--- a/noncore/tools/remote/remotetab.cpp
+++ b/noncore/tools/remote/remotetab.cpp
@@ -1,263 +1,149 @@
1/* 1/*
2Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. 2Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie.
3Copyright (C) 2002 Thomas Stephens 3Copyright (C) 2002 Thomas Stephens
4 4
5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public 5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later 6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7version. 7version.
8 8
9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11Public License for more details. 11Public License for more details.
12 12
13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free 13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15*/ 15*/
16 16
17#include "remotetab.h" 17#include "remotetab.h"
18#include "lirchandler.h"
18 19
19RemoteTab::RemoteTab(QWidget *parent, const char *name):QWidget(parent,name) 20RemoteTab::RemoteTab(QWidget *parent, const char *name):QWidget(parent,name)
20{ 21{
21 QVBoxLayout *layout = new QVBoxLayout(this); 22 QVBoxLayout *layout = new QVBoxLayout(this);
22 23
23 topGroup = new TopGroup(this); 24 topGroup = new TopGroup(this);
24 //topGroup->setMaximumHeight(22); 25 //topGroup->setMaximumHeight(22);
25 layout->addWidget(topGroup, 0, 0); 26 layout->addWidget(topGroup, 0, 0);
26 printf("%d %d", topGroup->width(), topGroup->height()); 27 printf("%d %d", topGroup->width(), topGroup->height());
27 28
28 layout->addSpacing(1); 29 layout->addSpacing(1);
29 30
30 dvdGroup = new DVDGroup(this); 31 dvdGroup = new DVDGroup(this);
31 //dvdGroup->setMaximumHeight(68); 32 //dvdGroup->setMaximumHeight(68);
32 layout->addWidget(dvdGroup, 0, 0); 33 layout->addWidget(dvdGroup, 0, 0);
33 34
34 layout->addSpacing(1); 35 layout->addSpacing(1);
35 36
36 vcrGroup = new VCRGroup(this); 37 vcrGroup = new VCRGroup(this);
37 layout->addWidget(vcrGroup, 0, 0); 38 layout->addWidget(vcrGroup, 0, 0);
38 //vcrGroup->setMaximumHeight(45); 39 //vcrGroup->setMaximumHeight(45);
39 40
40 layout->addSpacing(1); 41 layout->addSpacing(1);
41 42
42 channelGroup = new ChannelGroup(this); 43 channelGroup = new ChannelGroup(this);
43 //channelGroup->setMaximumHeight(91); 44 //channelGroup->setMaximumHeight(91);
44 layout->addWidget(channelGroup, 0, 0); 45 layout->addWidget(channelGroup, 0, 0);
45 46
46 this->setMaximumWidth(240); 47 this->setMaximumWidth(240);
47
48 timeout = 0;
49
50 addr.sun_family=AF_UNIX;
51 strcpy(addr.sun_path,"/dev/lircd");
52} 48}
53 49
54int RemoteTab::sendIR() 50int RemoteTab::sendIR()
55{ 51{
56 const QObject *button = sender(); 52 const QObject *button = sender();
57 QString string = cfg->readEntry(button->name()); 53 QString string = cfg->readEntry(button->name());
58 string+='\n'; 54 string+='\n';
59 const char *write_buffer = string.latin1();
60 const char *read_buffer;
61 bool done=false;
62
63 fd = socket(AF_UNIX, SOCK_STREAM, 0);
64 if(fd == -1)
65 {
66 QMessageBox *mb = new QMessageBox("Error!",
67 "couldnt connect to socket",
68 QMessageBox::NoIcon,
69 QMessageBox::Ok,
70 QMessageBox::NoButton,
71 QMessageBox::NoButton);
72 mb->exec();
73 perror("RemoteTab::SendIR");
74 return 0;
75 }
76
77
78 if(::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1)
79 {
80 QMessageBox *mb = new QMessageBox("Error!",
81 "couldnt connect to socket",
82 QMessageBox::NoIcon,
83 QMessageBox::Ok,
84 QMessageBox::NoButton,
85 QMessageBox::NoButton);
86 mb->exec();
87 perror("RemoteTab::SendIR");
88 }
89
90 printf("fd2: %d\n", fd);
91 printf("%s", write_buffer);
92
93 printf("1\n");
94 printf("%d\n", write(fd, write_buffer, strlen(write_buffer) ) );
95 printf("2\n");
96 while(!done)
97 {
98 read_buffer=readPacket();
99 printf("%s\n", read_buffer);
100 if(strcasecmp(read_buffer, "END") == 0)
101 {
102 printf("done reading packet\n");
103 done=true;
104 }
105 }
106 ::close(fd);
107}
108
109 // printf("%s\n", readPacket());
110 // printf("%d\n", read(fd, read_buffer,sizeof(read_buffer)) );
111 // printf("%s", read_buffer);
112
113//this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html
114const char *RemoteTab::readPacket()
115{
116 static char buffer[PACKET_SIZE+1]="";
117 char *end;
118 static int ptr=0,end_len=0;
119 ssize_t ret;
120
121 if(ptr>0)
122 {
123 memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1);
124 ptr=strlen(buffer);
125 end=strchr(buffer,'\n');
126 }
127 else
128 {
129 end=NULL;
130 }
131 alarm(TIMEOUT);
132 while(end==NULL)
133 {
134 if(PACKET_SIZE<=ptr)
135 {
136 // fprintf(stderr,"%s: bad packet\n",progname);
137 ptr=0;
138 return(NULL);
139 }
140 ret=read(fd,buffer+ptr,PACKET_SIZE-ptr);
141
142 if(ret<=0 || timeout)
143 {
144 if(timeout)
145 {
146 // fprintf(stderr,"%s: timeout\n",progname);
147 }
148 else
149 {
150 alarm(0);
151 }
152 ptr=0;
153 return(NULL);
154 }
155 buffer[ptr+ret]=0;
156 ptr=strlen(buffer);
157 end=strchr(buffer,'\n');
158 }
159 alarm(0);timeout=0;
160 55
161 end[0]=0; 56 LircHandler lh;
162 ptr=strlen(buffer)+1; 57 return lh.sendIR(string.latin1());
163//# ifdef DEBUG
164 //printf("buffer: -%s-\n",buffer);
165//# endif
166 return(buffer);
167}
168
169void RemoteTab::setIRSocket(int newfd)
170{
171 fd = newfd;
172} 58}
173 59
174void RemoteTab::setConfig(Config *newCfg) 60void RemoteTab::setConfig(Config *newCfg)
175{ 61{
176 cfg = newCfg; 62 cfg = newCfg;
177 cfg->setGroup("Remotes"); 63 cfg->setGroup("Remotes");
178 topGroup->updateRemotes(cfg); 64 topGroup->updateRemotes(cfg);
179} 65}
180 66
181void RemoteTab::remoteSelected(const QString &string) 67void RemoteTab::remoteSelected(const QString &string)
182{ 68{
183 printf("1%s\n", string.latin1() ); 69 printf("1%s\n", string.latin1() );
184 cfg->setGroup(string); 70 cfg->setGroup(string);
185 const QObject *obj; 71 const QObject *obj;
186 72
187 const QObjectList *objList = topGroup->children(); 73 const QObjectList *objList = topGroup->children();
188 for(obj = ((QObjectList *)objList)->first(); obj != 0; obj=((QObjectList *)objList)->next()) 74 for(obj = ((QObjectList *)objList)->first(); obj != 0; obj=((QObjectList *)objList)->next())
189 { 75 {
190 if(obj->inherits("QPushButton")) 76 if(obj->inherits("QPushButton"))
191 { 77 {
192 if(cfg->hasKey((QString)obj->name()+"Label")) 78 if(cfg->hasKey((QString)obj->name()+"Label"))
193 { 79 {
194 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") ); 80 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") );
195 } 81 }
196 else 82 else
197 { 83 {
198 cfg->setGroup("Default"); 84 cfg->setGroup("Default");
199 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") ); 85 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") );
200 cfg->setGroup(string); 86 cfg->setGroup(string);
201 } 87 }
202 } 88 }
203 } 89 }
204 90
205 objList = dvdGroup->children(); 91 objList = dvdGroup->children();
206 for(obj = ((QObjectList *)objList)->first(); obj != 0; obj=((QObjectList *)objList)->next()) 92 for(obj = ((QObjectList *)objList)->first(); obj != 0; obj=((QObjectList *)objList)->next())
207 { 93 {
208 if(obj->inherits("QPushButton")) 94 if(obj->inherits("QPushButton"))
209 { 95 {
210 if(cfg->hasKey((QString)obj->name()+"Label")) 96 if(cfg->hasKey((QString)obj->name()+"Label"))
211 { 97 {
212 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") ); 98 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") );
213 } 99 }
214 else 100 else
215 { 101 {
216 cfg->setGroup("Default"); 102 cfg->setGroup("Default");
217 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") ); 103 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") );
218 cfg->setGroup(string); 104 cfg->setGroup(string);
219 } 105 }
220 } 106 }
221 } 107 }
222 108
223 objList = vcrGroup->children(); 109 objList = vcrGroup->children();
224 for(obj = ((QObjectList *)objList)->first(); obj != 0; obj=((QObjectList *)objList)->next()) 110 for(obj = ((QObjectList *)objList)->first(); obj != 0; obj=((QObjectList *)objList)->next())
225 { 111 {
226 if(obj->inherits("QPushButton")) 112 if(obj->inherits("QPushButton"))
227 { 113 {
228 if(cfg->hasKey((QString)obj->name()+"Label")) 114 if(cfg->hasKey((QString)obj->name()+"Label"))
229 { 115 {
230 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") ); 116 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") );
231 } 117 }
232 else 118 else
233 { 119 {
234 cfg->setGroup("Default"); 120 cfg->setGroup("Default");
235 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") ); 121 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") );
236 cfg->setGroup(string); 122 cfg->setGroup(string);
237 } 123 }
238 } 124 }
239 } 125 }
240 126
241 objList = channelGroup->children(); 127 objList = channelGroup->children();
242 for(obj = ((QObjectList *)objList)->first(); obj != 0; obj=((QObjectList *)objList)->next()) 128 for(obj = ((QObjectList *)objList)->first(); obj != 0; obj=((QObjectList *)objList)->next())
243 { 129 {
244 if(obj->inherits("QPushButton")) 130 if(obj->inherits("QPushButton"))
245 { 131 {
246 if(cfg->hasKey((QString)obj->name()+"Label")) 132 if(cfg->hasKey((QString)obj->name()+"Label"))
247 { 133 {
248 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") ); 134 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") );
249 } 135 }
250 else 136 else
251 { 137 {
252 cfg->setGroup("Default"); 138 cfg->setGroup("Default");
253 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") ); 139 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") );
254 cfg->setGroup(string); 140 cfg->setGroup(string);
255 } 141 }
256 } 142 }
257 } 143 }
258} 144}
259 145
260void RemoteTab::updateRemotesList() 146void RemoteTab::updateRemotesList()
261{ 147{
262 topGroup->updateRemotes(cfg); 148 topGroup->updateRemotes(cfg);
263} 149}
diff --git a/noncore/tools/remote/remotetab.h b/noncore/tools/remote/remotetab.h
index 38b58e9..da0a543 100644
--- a/noncore/tools/remote/remotetab.h
+++ b/noncore/tools/remote/remotetab.h
@@ -1,64 +1,57 @@
1/* 1/*
2Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. 2Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie.
3Copyright (C) 2002 Thomas Stephens 3Copyright (C) 2002 Thomas Stephens
4 4
5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public 5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later 6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7version. 7version.
8 8
9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11Public License for more details. 11Public License for more details.
12 12
13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free 13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15*/ 15*/
16 16
17#include <qpe/config.h> 17#include <qpe/config.h>
18#include <qwidget.h> 18#include <qwidget.h>
19#include <qlayout.h> 19#include <qlayout.h>
20#include <qvbox.h> 20#include <qvbox.h>
21#include <qmessagebox.h> 21#include <qmessagebox.h>
22#include <qstring.h> 22#include <qstring.h>
23#include <qsize.h> 23#include <qsize.h>
24#include <qobjectlist.h> 24#include <qobjectlist.h>
25 25
26#include <stdio.h> 26#include <stdio.h>
27#include <stdlib.h> 27#include <stdlib.h>
28#include <string.h> 28#include <string.h>
29#include <sys/socket.h> 29#include <sys/socket.h>
30#include <sys/types.h> 30#include <sys/types.h>
31#include <sys/un.h> 31#include <sys/un.h>
32#include <unistd.h> 32#include <unistd.h>
33#include <errno.h> 33#include <errno.h>
34 34
35#include "topgroup.h" 35#include "topgroup.h"
36#include "dvdgroup.h" 36#include "dvdgroup.h"
37#include "channelgroup.h" 37#include "channelgroup.h"
38#include "vcrgroup.h" 38#include "vcrgroup.h"
39 39
40#define PACKET_SIZE 256
41#define TIMEOUT 3
42
43class RemoteTab : public QWidget 40class RemoteTab : public QWidget
44{ 41{
45 Q_OBJECT 42 Q_OBJECT
46public: 43public:
47 RemoteTab(QWidget *parent=0, const char *name=0); 44 RemoteTab(QWidget *parent=0, const char *name=0);
48 void setIRSocket(int newfd);
49 const char *readPacket(); 45 const char *readPacket();
50 void setConfig(Config *newCfg); 46 void setConfig(Config *newCfg);
51 void updateRemotesList(); 47 void updateRemotesList();
52public slots: 48public slots:
53 int sendIR(); 49 int sendIR();
54 void remoteSelected(const QString &string); 50 void remoteSelected(const QString &string);
55private: 51private:
56 int fd;
57 int timeout;
58 struct sockaddr_un addr;
59 Config *cfg; 52 Config *cfg;
60 TopGroup *topGroup; 53 TopGroup *topGroup;
61 DVDGroup *dvdGroup; 54 DVDGroup *dvdGroup;
62 VCRGroup *vcrGroup; 55 VCRGroup *vcrGroup;
63 ChannelGroup *channelGroup; 56 ChannelGroup *channelGroup;
64}; 57};