author | harlekin <harlekin> | 2002-05-12 08:39:15 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-05-12 08:39:15 (UTC) |
commit | 8362e586d0fd9a0ad6cea3f26d624a05196a60f8 (patch) (unidiff) | |
tree | 82bd5b113cd9f526c6555888cffbfdd907406eb9 /noncore/tools/remote/remotetab.cpp | |
parent | 28e86f19c9da68dca417b531e63e534c4545916b (diff) | |
download | opie-8362e586d0fd9a0ad6cea3f26d624a05196a60f8.zip opie-8362e586d0fd9a0ad6cea3f26d624a05196a60f8.tar.gz opie-8362e586d0fd9a0ad6cea3f26d624a05196a60f8.tar.bz2 |
opie remote control
Diffstat (limited to 'noncore/tools/remote/remotetab.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/tools/remote/remotetab.cpp | 250 |
1 files changed, 250 insertions, 0 deletions
diff --git a/noncore/tools/remote/remotetab.cpp b/noncore/tools/remote/remotetab.cpp new file mode 100644 index 0000000..f3a8945 --- a/dev/null +++ b/noncore/tools/remote/remotetab.cpp | |||
@@ -0,0 +1,250 @@ | |||
1 | /* | ||
2 | Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. | ||
3 | Copyright (C) 2002 Thomas Stephens | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public | ||
6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later | ||
7 | version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the | ||
10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
11 | Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free | ||
14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
15 | */ | ||
16 | |||
17 | #include "remotetab.h" | ||
18 | |||
19 | RemoteTab::RemoteTab(QWidget *parent=0, const char *name=0):QWidget(parent,name) | ||
20 | { | ||
21 | QVBoxLayout *layout = new QVBoxLayout(this); | ||
22 | |||
23 | topGroup = new TopGroup(this); | ||
24 | //topGroup->setMaximumHeight(22); | ||
25 | layout->addWidget(topGroup, 0, 0); | ||
26 | printf("%d %d", topGroup->width(), topGroup->height()); | ||
27 | |||
28 | layout->addSpacing(1); | ||
29 | |||
30 | dvdGroup = new DVDGroup(this); | ||
31 | //dvdGroup->setMaximumHeight(68); | ||
32 | layout->addWidget(dvdGroup, 0, 0); | ||
33 | |||
34 | layout->addSpacing(1); | ||
35 | |||
36 | vcrGroup = new VCRGroup(this); | ||
37 | layout->addWidget(vcrGroup, 0, 0); | ||
38 | //vcrGroup->setMaximumHeight(45); | ||
39 | |||
40 | layout->addSpacing(1); | ||
41 | |||
42 | channelGroup = new ChannelGroup(this); | ||
43 | //channelGroup->setMaximumHeight(91); | ||
44 | layout->addWidget(channelGroup, 0, 0); | ||
45 | |||
46 | this->setMaximumWidth(240); | ||
47 | |||
48 | timeout = 0; | ||
49 | |||
50 | addr.sun_family=AF_UNIX; | ||
51 | strcpy(addr.sun_path,"/dev/lircd"); | ||
52 | } | ||
53 | |||
54 | void RemoteTab::sendIR() | ||
55 | { | ||
56 | const QObject *button = sender(); | ||
57 | QString string = cfg->readEntry(button->name()); | ||
58 | 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 | |||
65 | if(std::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) | ||
66 | { | ||
67 | QMessageBox *mb = new QMessageBox("Error!", | ||
68 | "couldnt connect to socket", | ||
69 | QMessageBox::NoIcon, | ||
70 | QMessageBox::Ok, | ||
71 | QMessageBox::NoButton, | ||
72 | QMessageBox::NoButton); | ||
73 | mb->exec(); | ||
74 | perror("RemoteTab::SendIR"); | ||
75 | } | ||
76 | |||
77 | printf("fd2: %d\n", fd); | ||
78 | printf("%s", write_buffer); | ||
79 | |||
80 | printf("1\n"); | ||
81 | printf("%d\n", write(fd, write_buffer, strlen(write_buffer) ) ); | ||
82 | printf("2\n"); | ||
83 | while(!done) | ||
84 | { | ||
85 | read_buffer=readPacket(); | ||
86 | printf("%s\n", read_buffer); | ||
87 | if(strcasecmp(read_buffer, "END") == 0) | ||
88 | { | ||
89 | printf("done reading packet\n"); | ||
90 | done=true; | ||
91 | } | ||
92 | } | ||
93 | std::close(fd); | ||
94 | } | ||
95 | |||
96 | // printf("%s\n", readPacket()); | ||
97 | // printf("%d\n", read(fd, read_buffer,sizeof(read_buffer)) ); | ||
98 | // printf("%s", read_buffer); | ||
99 | |||
100 | //this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html | ||
101 | const char *RemoteTab::readPacket() | ||
102 | { | ||
103 | static char buffer[PACKET_SIZE+1]=""; | ||
104 | char *end; | ||
105 | static int ptr=0,end_len=0; | ||
106 | ssize_t ret; | ||
107 | |||
108 | if(ptr>0) | ||
109 | { | ||
110 | memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1); | ||
111 | ptr=strlen(buffer); | ||
112 | end=strchr(buffer,'\n'); | ||
113 | } | ||
114 | else | ||
115 | { | ||
116 | end=NULL; | ||
117 | } | ||
118 | alarm(TIMEOUT); | ||
119 | while(end==NULL) | ||
120 | { | ||
121 | if(PACKET_SIZE<=ptr) | ||
122 | { | ||
123 | // fprintf(stderr,"%s: bad packet\n",progname); | ||
124 | ptr=0; | ||
125 | return(NULL); | ||
126 | } | ||
127 | ret=read(fd,buffer+ptr,PACKET_SIZE-ptr); | ||
128 | |||
129 | if(ret<=0 || timeout) | ||
130 | { | ||
131 | if(timeout) | ||
132 | { | ||
133 | // fprintf(stderr,"%s: timeout\n",progname); | ||
134 | } | ||
135 | else | ||
136 | { | ||
137 | alarm(0); | ||
138 | } | ||
139 | ptr=0; | ||
140 | return(NULL); | ||
141 | } | ||
142 | buffer[ptr+ret]=0; | ||
143 | ptr=strlen(buffer); | ||
144 | end=strchr(buffer,'\n'); | ||
145 | } | ||
146 | alarm(0);timeout=0; | ||
147 | |||
148 | end[0]=0; | ||
149 | ptr=strlen(buffer)+1; | ||
150 | //# ifdef DEBUG | ||
151 | //printf("buffer: -%s-\n",buffer); | ||
152 | //# endif | ||
153 | return(buffer); | ||
154 | } | ||
155 | |||
156 | void RemoteTab::setIRSocket(int newfd) | ||
157 | { | ||
158 | fd = newfd; | ||
159 | } | ||
160 | |||
161 | void RemoteTab::setConfig(Config *newCfg) | ||
162 | { | ||
163 | cfg = newCfg; | ||
164 | cfg->setGroup("Remotes"); | ||
165 | topGroup->updateRemotes(cfg); | ||
166 | } | ||
167 | |||
168 | void RemoteTab::remoteSelected(const QString &string) | ||
169 | { | ||
170 | printf("1%s\n", string.latin1() ); | ||
171 | cfg->setGroup(string); | ||
172 | const QObject *obj; | ||
173 | |||
174 | const QObjectList *objList = topGroup->children(); | ||
175 | for(obj = ((QObjectList *)objList)->first(); obj != 0; obj=((QObjectList *)objList)->next()) | ||
176 | { | ||
177 | if(obj->inherits("QPushButton")) | ||
178 | { | ||
179 | if(cfg->hasKey((QString)obj->name()+"Label")) | ||
180 | { | ||
181 | ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") ); | ||
182 | } | ||
183 | else | ||
184 | { | ||
185 | cfg->setGroup("Default"); | ||
186 | ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") ); | ||
187 | cfg->setGroup(string); | ||
188 | } | ||
189 | } | ||
190 | } | ||
191 | |||
192 | objList = dvdGroup->children(); | ||
193 | for(obj = ((QObjectList *)objList)->first(); obj != 0; obj=((QObjectList *)objList)->next()) | ||
194 | { | ||
195 | if(obj->inherits("QPushButton")) | ||
196 | { | ||
197 | if(cfg->hasKey((QString)obj->name()+"Label")) | ||
198 | { | ||
199 | ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") ); | ||
200 | } | ||
201 | else | ||
202 | { | ||
203 | cfg->setGroup("Default"); | ||
204 | ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") ); | ||
205 | cfg->setGroup(string); | ||
206 | } | ||
207 | } | ||
208 | } | ||
209 | |||
210 | objList = vcrGroup->children(); | ||
211 | for(obj = ((QObjectList *)objList)->first(); obj != 0; obj=((QObjectList *)objList)->next()) | ||
212 | { | ||
213 | if(obj->inherits("QPushButton")) | ||
214 | { | ||
215 | if(cfg->hasKey((QString)obj->name()+"Label")) | ||
216 | { | ||
217 | ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") ); | ||
218 | } | ||
219 | else | ||
220 | { | ||
221 | cfg->setGroup("Default"); | ||
222 | ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") ); | ||
223 | cfg->setGroup(string); | ||
224 | } | ||
225 | } | ||
226 | } | ||
227 | |||
228 | objList = channelGroup->children(); | ||
229 | for(obj = ((QObjectList *)objList)->first(); obj != 0; obj=((QObjectList *)objList)->next()) | ||
230 | { | ||
231 | if(obj->inherits("QPushButton")) | ||
232 | { | ||
233 | if(cfg->hasKey((QString)obj->name()+"Label")) | ||
234 | { | ||
235 | ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") ); | ||
236 | } | ||
237 | else | ||
238 | { | ||
239 | cfg->setGroup("Default"); | ||
240 | ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") ); | ||
241 | cfg->setGroup(string); | ||
242 | } | ||
243 | } | ||
244 | } | ||
245 | } | ||
246 | |||
247 | void RemoteTab::updateRemotesList() | ||
248 | { | ||
249 | topGroup->updateRemotes(cfg); | ||
250 | } | ||