author | ar <ar> | 2004-02-21 19:09:12 (UTC) |
---|---|---|
committer | ar <ar> | 2004-02-21 19:09:12 (UTC) |
commit | c7e563cbb26c20807e66dd4284d1ce9cbf8e1419 (patch) (unidiff) | |
tree | e55119af88abe930c1ce492f30efb72c929a730c /noncore/tools/remote/learntab.cpp | |
parent | 536f271b1e6a1d1886e96a28524a3503c4c38c4e (diff) | |
download | opie-c7e563cbb26c20807e66dd4284d1ce9cbf8e1419.zip opie-c7e563cbb26c20807e66dd4284d1ce9cbf8e1419.tar.gz opie-c7e563cbb26c20807e66dd4284d1ce9cbf8e1419.tar.bz2 |
improve support for BigScreen
Diffstat (limited to 'noncore/tools/remote/learntab.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/tools/remote/learntab.cpp | 311 |
1 files changed, 156 insertions, 155 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 | ||