summaryrefslogtreecommitdiff
path: root/noncore/tools/remote/learntab.cpp
Unidiff
Diffstat (limited to 'noncore/tools/remote/learntab.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/remote/learntab.cpp132
1 files changed, 3 insertions, 129 deletions
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
@@ -21,13 +21,15 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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);
@@ -62,131 +64,3 @@ void LearnTab::edit()
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