Diffstat (limited to 'noncore/tools/remote/learntab.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/tools/remote/learntab.cpp | 132 |
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 | |||
@@ -8,39 +8,41 @@ 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 "learntab.h" | 17 | #include "learntab.h" |
18 | 18 | ||
19 | /* OPIE */ | 19 | /* OPIE */ |
20 | #include <qpe/qpeapplication.h> | 20 | #include <qpe/qpeapplication.h> |
21 | 21 | ||
22 | LearnTab::LearnTab(QWidget *parent, const char *name):QWidget(parent,name) | 22 | LearnTab::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 | ||
@@ -49,144 +51,16 @@ LearnTab::LearnTab(QWidget *parent, const char *name):QWidget(parent,name) | |||
49 | connect(del, SIGNAL(clicked()), this, SLOT(del()) ); | 51 | connect(del, SIGNAL(clicked()), this, SLOT(del()) ); |
50 | } | 52 | } |
51 | 53 | ||
52 | void LearnTab::add() | 54 | void 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 | ||
59 | void LearnTab::edit() | 61 | void LearnTab::edit() |
60 | {} | 62 | {} |
61 | 63 | ||
62 | void LearnTab::del() | 64 | void LearnTab::del() |
63 | {} | 65 | {} |
64 | 66 | ||
65 | QStringList 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 | ||
137 | const 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 | |||