-rw-r--r-- | noncore/tools/remote/learntab.cpp | 311 | ||||
-rw-r--r-- | noncore/tools/remote/remote.cpp | 102 |
2 files changed, 210 insertions, 203 deletions
diff --git a/noncore/tools/remote/learntab.cpp b/noncore/tools/remote/learntab.cpp index 7582161..335a3e9 100644 --- a/noncore/tools/remote/learntab.cpp +++ b/noncore/tools/remote/learntab.cpp | |||
@@ -2,13 +2,13 @@ | |||
2 | Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. | 2 | Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. |
3 | Copyright (C) 2002 Thomas Stephens | 3 | Copyright (C) 2002 Thomas Stephens |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public | 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 | 6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later |
7 | version. | 7 | version. |
8 | 8 | ||
9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the | 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 | 10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
11 | Public License for more details. | 11 | Public License for more details. |
12 | 12 | ||
13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free | 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 | 14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
@@ -17,118 +17,119 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
17 | #include "learntab.h" | 17 | #include "learntab.h" |
18 | 18 | ||
19 | /* OPIE */ | ||
20 | #include <qpe/qpeapplication.h> | ||
21 | |||
19 | LearnTab::LearnTab(QWidget *parent, const char *name):QWidget(parent,name) | 22 | LearnTab::LearnTab(QWidget *parent, const char *name):QWidget(parent,name) |
20 | { | 23 | { |
21 | QVBoxLayout *layout = new QVBoxLayout(this); | 24 | QVBoxLayout *layout = new QVBoxLayout(this); |
22 | QHBoxLayout *bottomLayout = new QHBoxLayout(this); | 25 | QHBoxLayout *bottomLayout = new QHBoxLayout(this); |
23 | 26 | ||
24 | layout->insertSpacing(0,5); | 27 | layout->insertSpacing(0,5); |
25 | remotesBox = new QListBox(this, "remotesBox"); | 28 | remotesBox = new QListBox(this, "remotesBox"); |
26 | layout->insertWidget(0, remotesBox, 1); | 29 | layout->insertWidget(0, remotesBox, 1); |
27 | remotesBox->insertStringList(getRemotes()); | 30 | remotesBox->insertStringList(getRemotes()); |
28 | 31 | ||
29 | layout->insertSpacing(-1,5); | 32 | layout->insertSpacing(-1,5); |
30 | layout->insertLayout(-1, bottomLayout); | 33 | layout->insertLayout(-1, bottomLayout); |
31 | layout->insertSpacing(-1,5); | 34 | layout->insertSpacing(-1,5); |
32 | 35 | ||
33 | QPushButton *add = new QPushButton("Add", this, "add"); | 36 | QPushButton *add = new QPushButton("Add", this, "add"); |
34 | bottomLayout->insertSpacing(-1, 5); | 37 | bottomLayout->insertSpacing(-1, 5); |
35 | bottomLayout->insertWidget(-1, add); | 38 | bottomLayout->insertWidget(-1, add); |
36 | bottomLayout->insertSpacing(-1, 5); | 39 | bottomLayout->insertSpacing(-1, 5); |
37 | QPushButton *edit = new QPushButton("Edit", this, "edit"); | 40 | QPushButton *edit = new QPushButton("Edit", this, "edit"); |
38 | bottomLayout->insertWidget(-1, edit); | 41 | bottomLayout->insertWidget(-1, edit); |
39 | bottomLayout->insertSpacing(-1, 5); | 42 | bottomLayout->insertSpacing(-1, 5); |
40 | QPushButton *del = new QPushButton("Delete", this, "delete"); | 43 | QPushButton *del = new QPushButton("Delete", this, "delete"); |
41 | bottomLayout->insertWidget(-1, del); | 44 | bottomLayout->insertWidget(-1, del); |
42 | bottomLayout->insertSpacing(-1, 5); | 45 | bottomLayout->insertSpacing(-1, 5); |
43 | 46 | ||
44 | connect(add, SIGNAL(clicked()), this, SLOT(add()) ); | 47 | connect(add, SIGNAL(clicked()), this, SLOT(add()) ); |
45 | connect(edit, SIGNAL(clicked()), this, SLOT(edit()) ); | 48 | connect(edit, SIGNAL(clicked()), this, SLOT(edit()) ); |
46 | connect(del, SIGNAL(clicked()), this, SLOT(del()) ); | 49 | connect(del, SIGNAL(clicked()), this, SLOT(del()) ); |
47 | } | 50 | } |
48 | 51 | ||
49 | void LearnTab::add() | 52 | void LearnTab::add() |
50 | { | 53 | { |
51 | printf("LearnTab::add: add pressed\n"); | 54 | printf("LearnTab::add: add pressed\n"); |
52 | RecordDialog *dialog = new RecordDialog(this); | 55 | RecordDialog *dialog = new RecordDialog(this); |
53 | dialog->showMaximized(); | 56 | QPEApplication::showDialog( dialog ); |
54 | } | 57 | } |
55 | 58 | ||
56 | void LearnTab::edit() | 59 | void LearnTab::edit() |
57 | { | 60 | {} |
58 | } | ||
59 | 61 | ||
60 | void LearnTab::del() | 62 | void LearnTab::del() |
61 | { | 63 | {} |
62 | } | ||
63 | 64 | ||
64 | QStringList LearnTab::getRemotes() | 65 | QStringList LearnTab::getRemotes() |
65 | { | 66 | { |
66 | const char write_buffer[] = "LIST\n"; | 67 | const char write_buffer[] = "LIST\n"; |
67 | const char *readbuffer; | 68 | const char *readbuffer; |
68 | int i, numlines; | 69 | int i, numlines; |
69 | QStringList list; | 70 | QStringList list; |
70 | 71 | ||
71 | addr.sun_family=AF_UNIX; | 72 | addr.sun_family=AF_UNIX; |
72 | strcpy(addr.sun_path,"/dev/lircd"); | 73 | strcpy(addr.sun_path,"/dev/lircd"); |
73 | 74 | ||
74 | fd = socket(AF_UNIX, SOCK_STREAM, 0); | 75 | fd = socket(AF_UNIX, SOCK_STREAM, 0); |
75 | if(fd == -1) | 76 | if(fd == -1) |
76 | { | 77 | { |
77 | QMessageBox *mb = new QMessageBox("Error!", | 78 | QMessageBox *mb = new QMessageBox("Error!", |
78 | "couldnt connect to socket", | 79 | "couldnt connect to socket", |
79 | QMessageBox::NoIcon, | 80 | QMessageBox::NoIcon, |
80 | QMessageBox::Ok, | 81 | QMessageBox::Ok, |
81 | QMessageBox::NoButton, | 82 | QMessageBox::NoButton, |
82 | QMessageBox::NoButton); | 83 | QMessageBox::NoButton); |
83 | mb->exec(); | 84 | mb->exec(); |
84 | perror("LearnTab::GetRemotes"); | 85 | perror("LearnTab::GetRemotes"); |
85 | return NULL; | 86 | return NULL; |
86 | } | 87 | } |
87 | 88 | ||
88 | if(::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) | 89 | if(::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) |
89 | { | 90 | { |
90 | QMessageBox *mb = new QMessageBox("Error!", | 91 | QMessageBox *mb = new QMessageBox("Error!", |
91 | "couldnt connect to socket", | 92 | "couldnt connect to socket", |
92 | QMessageBox::NoIcon, | 93 | QMessageBox::NoIcon, |
93 | QMessageBox::Ok, | 94 | QMessageBox::Ok, |
94 | QMessageBox::NoButton, | 95 | QMessageBox::NoButton, |
95 | QMessageBox::NoButton); | 96 | QMessageBox::NoButton); |
96 | mb->exec(); | 97 | mb->exec(); |
97 | perror("LearnTab::GetRemotes"); | 98 | perror("LearnTab::GetRemotes"); |
98 | return NULL; | 99 | return NULL; |
99 | } | 100 | } |
100 | 101 | ||
101 | write(fd, write_buffer, strlen(write_buffer)); | 102 | write(fd, write_buffer, strlen(write_buffer)); |
102 | 103 | ||
103 | for(i=0; i<5; i++) | 104 | for(i=0; i<5; i++) |
104 | { | 105 | { |
105 | printf("%d\n", i); | 106 | printf("%d\n", i); |
106 | readbuffer = readPacket(); | 107 | readbuffer = readPacket(); |
107 | printf("%s", readbuffer); | 108 | printf("%s", readbuffer); |
108 | printf("%d\n", i); | 109 | printf("%d\n", i); |
109 | } | 110 | } |
110 | 111 | ||
111 | numlines = atoi(readbuffer); | 112 | numlines = atoi(readbuffer); |
112 | 113 | ||
113 | for(i=0; i<numlines; i++) | 114 | for(i=0; i<numlines; i++) |
114 | { | 115 | { |
115 | list+=readPacket(); | 116 | list+=readPacket(); |
116 | } | 117 | } |
117 | 118 | ||
118 | if(strcasecmp(readPacket(), "END") != 0) | 119 | if(strcasecmp(readPacket(), "END") != 0) |
119 | { | 120 | { |
120 | QMessageBox *mb = new QMessageBox("Error!", | 121 | QMessageBox *mb = new QMessageBox("Error!", |
121 | "bad packet", | 122 | "bad packet", |
122 | QMessageBox::NoIcon, | 123 | QMessageBox::NoIcon, |
123 | QMessageBox::Ok, | 124 | QMessageBox::Ok, |
124 | QMessageBox::NoButton, | 125 | QMessageBox::NoButton, |
125 | QMessageBox::NoButton); | 126 | QMessageBox::NoButton); |
126 | mb->exec(); | 127 | mb->exec(); |
127 | perror("LearnTab::GetRemotes"); | 128 | perror("LearnTab::GetRemotes"); |
128 | return NULL; | 129 | return NULL; |
129 | } | 130 | } |
130 | 131 | ||
131 | ::close(fd); | 132 | ::close(fd); |
132 | return list; | 133 | return list; |
133 | } | 134 | } |
134 | 135 | ||
@@ -136,56 +137,56 @@ QStringList LearnTab::getRemotes() | |||
136 | const char *LearnTab::readPacket() | 137 | const char *LearnTab::readPacket() |
137 | { | 138 | { |
138 | static char buffer[PACKET_SIZE+1]=""; | 139 | static char buffer[PACKET_SIZE+1]=""; |
139 | char *end; | 140 | char *end; |
140 | static int ptr=0,end_len=0; | 141 | static int ptr=0,end_len=0; |
141 | ssize_t ret; | 142 | ssize_t ret; |
142 | timeout = 0; | 143 | timeout = 0; |
143 | 144 | ||
144 | if(ptr>0) | 145 | if(ptr>0) |
145 | { | 146 | { |
146 | memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1); | 147 | memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1); |
147 | ptr=strlen(buffer); | 148 | ptr=strlen(buffer); |
148 | end=strchr(buffer,'\n'); | 149 | end=strchr(buffer,'\n'); |
149 | } | 150 | } |
150 | else | 151 | else |
151 | { | 152 | { |
152 | end=NULL; | 153 | end=NULL; |
153 | } | 154 | } |
154 | alarm(TIMEOUT); | 155 | alarm(TIMEOUT); |
155 | while(end==NULL) | 156 | while(end==NULL) |
156 | { | 157 | { |
157 | if(PACKET_SIZE<=ptr) | 158 | if(PACKET_SIZE<=ptr) |
158 | { | 159 | { |
159 | fprintf(stderr,"bad packet\n"); | 160 | fprintf(stderr,"bad packet\n"); |
160 | ptr=0; | 161 | ptr=0; |
161 | return(NULL); | 162 | return(NULL); |
162 | } | 163 | } |
163 | ret=read(fd,buffer+ptr,PACKET_SIZE-ptr); | 164 | ret=read(fd,buffer+ptr,PACKET_SIZE-ptr); |
164 | 165 | ||
165 | if(ret<=0 || timeout) | 166 | if(ret<=0 || timeout) |
166 | { | 167 | { |
167 | if(timeout) | 168 | if(timeout) |
168 | { | 169 | { |
169 | fprintf(stderr,"timeout\n"); | 170 | fprintf(stderr,"timeout\n"); |
170 | } | 171 | } |
171 | else | 172 | else |
172 | { | 173 | { |
173 | alarm(0); | 174 | alarm(0); |
174 | } | 175 | } |
175 | ptr=0; | 176 | ptr=0; |
176 | return(NULL); | 177 | return(NULL); |
177 | } | 178 | } |
178 | buffer[ptr+ret]=0; | 179 | buffer[ptr+ret]=0; |
179 | ptr=strlen(buffer); | 180 | ptr=strlen(buffer); |
180 | end=strchr(buffer,'\n'); | 181 | end=strchr(buffer,'\n'); |
181 | } | 182 | } |
182 | alarm(0);timeout=0; | 183 | alarm(0);timeout=0; |
183 | 184 | ||
184 | end[0]=0; | 185 | end[0]=0; |
185 | ptr=strlen(buffer)+1; | 186 | ptr=strlen(buffer)+1; |
186 | //# ifdef DEBUG | 187 | //# ifdef DEBUG |
187 | //printf("buffer: -%s-\n",buffer); | 188 | //printf("buffer: -%s-\n",buffer); |
188 | //# endif | 189 | //# endif |
189 | return(buffer); | 190 | return(buffer); |
190 | } | 191 | } |
191 | 192 | ||
diff --git a/noncore/tools/remote/remote.cpp b/noncore/tools/remote/remote.cpp index 7972def..638629f 100644 --- a/noncore/tools/remote/remote.cpp +++ b/noncore/tools/remote/remote.cpp | |||
@@ -2,20 +2,25 @@ | |||
2 | Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. | 2 | Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. |
3 | Copyright (C) 2002 Thomas Stephens | 3 | Copyright (C) 2002 Thomas Stephens |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public | 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 | 6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later |
7 | version. | 7 | version. |
8 | 8 | ||
9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the | 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 | 10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
11 | Public License for more details. | 11 | Public License for more details. |
12 | 12 | ||
13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free | 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 | 14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include "mainview.h" | ||
18 | |||
19 | /* OPIE */ | ||
17 | #include <qpe/qpeapplication.h> | 20 | #include <qpe/qpeapplication.h> |
18 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
19 | #include <qpe/config.h> | 22 | #include <qpe/config.h> |
23 | |||
24 | /* QT */ | ||
20 | #include <qpushbutton.h> | 25 | #include <qpushbutton.h> |
21 | #include <qtabwidget.h> | 26 | #include <qtabwidget.h> |
@@ -24,4 +29,6 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
24 | #include <qpaintdevice.h> | 29 | #include <qpaintdevice.h> |
25 | #include <qobject.h> | 30 | #include <qobject.h> |
31 | |||
32 | /* STD */ | ||
26 | #include <sys/socket.h> | 33 | #include <sys/socket.h> |
27 | #include <sys/types.h> | 34 | #include <sys/types.h> |
@@ -31,14 +38,13 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
31 | #include <signal.h> | 38 | #include <signal.h> |
32 | 39 | ||
33 | #include "mainview.h" | ||
34 | 40 | ||
35 | /*void reconnect(int &fd) | 41 | /*void reconnect(int &fd) |
36 | { | 42 | { |
37 | //struct sockaddr_un addr; | 43 | //struct sockaddr_un addr; |
38 | 44 | ||
39 | addr.sun_family=AF_UNIX; | 45 | addr.sun_family=AF_UNIX; |
40 | strcpy(addr.sun_path,"/dev/lircd"); | 46 | strcpy(addr.sun_path,"/dev/lircd"); |
41 | fd = socket(AF_UNIX, SOCK_STREAM, 0); | 47 | fd = socket(AF_UNIX, SOCK_STREAM, 0); |
42 | 48 | ||
43 | if(connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) | 49 | if(connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) |
44 | { | 50 | { |
@@ -56,45 +62,45 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
56 | int main( int argc, char **argv ) | 62 | int main( int argc, char **argv ) |
57 | { | 63 | { |
58 | QPEApplication a( argc, argv ); | 64 | QPEApplication a( argc, argv ); |
59 | MainView w; | 65 | MainView w; |
60 | 66 | ||
61 | int fd; | 67 | int fd; |
62 | //struct sockaddr_un addr; | 68 | //struct sockaddr_un addr; |
63 | //char read_buffer[BUFFERSIZE+1]; | 69 | //char read_buffer[BUFFERSIZE+1]; |
64 | //char write_buffer[] = "LIST\n"; | 70 | //char write_buffer[] = "LIST\n"; |
65 | 71 | ||
66 | //addr.sun_family=AF_UNIX; | 72 | //addr.sun_family=AF_UNIX; |
67 | //strcpy(addr.sun_path,"/dev/lircd"); | 73 | //strcpy(addr.sun_path,"/dev/lircd"); |
68 | //fd = socket(AF_UNIX, SOCK_STREAM, 0); | 74 | //fd = socket(AF_UNIX, SOCK_STREAM, 0); |
69 | 75 | ||
70 | //printf("fd1: %d\n", fd); | 76 | //printf("fd1: %d\n", fd); |
71 | /* | 77 | /* |
72 | if(connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) | 78 | if(connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) |
73 | { | 79 | { |
74 | QMessageBox *mb = new QMessageBox("error", | 80 | QMessageBox *mb = new QMessageBox("error", |
75 | "couldnt connect to socket", | 81 | "couldnt connect to socket", |
76 | QMessageBox::NoIcon, | 82 | QMessageBox::NoIcon, |
77 | QMessageBox::Ok, | 83 | QMessageBox::Ok, |
78 | QMessageBox::NoButton, | 84 | QMessageBox::NoButton, |
79 | QMessageBox::NoButton); | 85 | QMessageBox::NoButton); |
80 | mb->exec(); | 86 | mb->exec(); |
81 | } | 87 | } |
82 | */ | 88 | */ |
83 | 89 | ||
84 | //printf("%d\n", write(fd, write_buffer, sizeof(write_buffer) ) ); | 90 | //printf("%d\n", write(fd, write_buffer, sizeof(write_buffer) ) ); |
85 | 91 | ||
86 | //printf("%d\n", read(fd, read_buffer, BUFFERSIZE ) ); | 92 | //printf("%d\n", read(fd, read_buffer, BUFFERSIZE ) ); |
87 | 93 | ||
88 | //QMessageBox *mbtest = new QMessageBox("lirc test", | 94 | //QMessageBox *mbtest = new QMessageBox("lirc test", |
89 | // *new QString((const char *) read_buffer), | 95 | // *new QString((const char *) read_buffer), |
90 | // QMessageBox::NoIcon, | 96 | // QMessageBox::NoIcon, |
91 | // QMessageBox::Ok, | 97 | // QMessageBox::Ok, |
92 | // QMessageBox::NoButton, | 98 | // QMessageBox::NoButton, |
93 | // QMessageBox::NoButton); | 99 | // QMessageBox::NoButton); |
94 | //mbtest->exec(); | 100 | //mbtest->exec(); |
95 | 101 | ||
96 | a.setMainWidget( &w ); | 102 | a.setMainWidget( &w ); |
97 | w.setIRSocket(fd); | 103 | w.setIRSocket(fd); |
98 | w.showMaximized(); | 104 | QPEApplication::showWidget( &w ); |
99 | return a.exec(); | 105 | return a.exec(); |
100 | } | 106 | } |