Diffstat (limited to 'noncore/tools/remote/remotetab.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/tools/remote/remotetab.cpp | 122 |
1 files changed, 4 insertions, 118 deletions
diff --git a/noncore/tools/remote/remotetab.cpp b/noncore/tools/remote/remotetab.cpp index 5b02e94..84038ca 100644 --- a/noncore/tools/remote/remotetab.cpp +++ b/noncore/tools/remote/remotetab.cpp | |||
@@ -6,24 +6,25 @@ This program is free software; you can redistribute it and/or modify it under th | |||
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 "remotetab.h" | 17 | #include "remotetab.h" |
18 | #include "lirchandler.h" | ||
18 | 19 | ||
19 | RemoteTab::RemoteTab(QWidget *parent, const char *name):QWidget(parent,name) | 20 | RemoteTab::RemoteTab(QWidget *parent, const char *name):QWidget(parent,name) |
20 | { | 21 | { |
21 | QVBoxLayout *layout = new QVBoxLayout(this); | 22 | QVBoxLayout *layout = new QVBoxLayout(this); |
22 | 23 | ||
23 | topGroup = new TopGroup(this); | 24 | topGroup = new TopGroup(this); |
24 | //topGroup->setMaximumHeight(22); | 25 | //topGroup->setMaximumHeight(22); |
25 | layout->addWidget(topGroup, 0, 0); | 26 | layout->addWidget(topGroup, 0, 0); |
26 | printf("%d %d", topGroup->width(), topGroup->height()); | 27 | printf("%d %d", topGroup->width(), topGroup->height()); |
27 | 28 | ||
28 | layout->addSpacing(1); | 29 | layout->addSpacing(1); |
29 | 30 | ||
@@ -35,149 +36,34 @@ RemoteTab::RemoteTab(QWidget *parent, const char *name):QWidget(parent,name) | |||
35 | 36 | ||
36 | vcrGroup = new VCRGroup(this); | 37 | vcrGroup = new VCRGroup(this); |
37 | layout->addWidget(vcrGroup, 0, 0); | 38 | layout->addWidget(vcrGroup, 0, 0); |
38 | //vcrGroup->setMaximumHeight(45); | 39 | //vcrGroup->setMaximumHeight(45); |
39 | 40 | ||
40 | layout->addSpacing(1); | 41 | layout->addSpacing(1); |
41 | 42 | ||
42 | channelGroup = new ChannelGroup(this); | 43 | channelGroup = new ChannelGroup(this); |
43 | //channelGroup->setMaximumHeight(91); | 44 | //channelGroup->setMaximumHeight(91); |
44 | layout->addWidget(channelGroup, 0, 0); | 45 | layout->addWidget(channelGroup, 0, 0); |
45 | 46 | ||
46 | this->setMaximumWidth(240); | 47 | this->setMaximumWidth(240); |
47 | |||
48 | timeout = 0; | ||
49 | |||
50 | addr.sun_family=AF_UNIX; | ||
51 | strcpy(addr.sun_path,"/dev/lircd"); | ||
52 | } | 48 | } |
53 | 49 | ||
54 | int RemoteTab::sendIR() | 50 | int RemoteTab::sendIR() |
55 | { | 51 | { |
56 | const QObject *button = sender(); | 52 | const QObject *button = sender(); |
57 | QString string = cfg->readEntry(button->name()); | 53 | QString string = cfg->readEntry(button->name()); |
58 | string+='\n'; | 54 | string+='\n'; |
59 | const char *write_buffer = string.latin1(); | 55 | |
60 | const char *read_buffer; | 56 | LircHandler lh; |
61 | bool done=false; | 57 | return lh.sendIR(string.latin1()); |
62 | |||
63 | fd = socket(AF_UNIX, SOCK_STREAM, 0); | ||
64 | if(fd == -1) | ||
65 | { | ||
66 | QMessageBox *mb = new QMessageBox("Error!", | ||
67 | "couldnt connect to socket", | ||
68 | QMessageBox::NoIcon, | ||
69 | QMessageBox::Ok, | ||
70 | QMessageBox::NoButton, | ||
71 | QMessageBox::NoButton); | ||
72 | mb->exec(); | ||
73 | perror("RemoteTab::SendIR"); | ||
74 | return 0; | ||
75 | } | ||
76 | |||
77 | |||
78 | if(::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) | ||
79 | { | ||
80 | QMessageBox *mb = new QMessageBox("Error!", | ||
81 | "couldnt connect to socket", | ||
82 | QMessageBox::NoIcon, | ||
83 | QMessageBox::Ok, | ||
84 | QMessageBox::NoButton, | ||
85 | QMessageBox::NoButton); | ||
86 | mb->exec(); | ||
87 | perror("RemoteTab::SendIR"); | ||
88 | } | ||
89 | |||
90 | printf("fd2: %d\n", fd); | ||
91 | printf("%s", write_buffer); | ||
92 | |||
93 | printf("1\n"); | ||
94 | printf("%d\n", write(fd, write_buffer, strlen(write_buffer) ) ); | ||
95 | printf("2\n"); | ||
96 | while(!done) | ||
97 | { | ||
98 | read_buffer=readPacket(); | ||
99 | printf("%s\n", read_buffer); | ||
100 | if(strcasecmp(read_buffer, "END") == 0) | ||
101 | { | ||
102 | printf("done reading packet\n"); | ||
103 | done=true; | ||
104 | } | ||
105 | } | ||
106 | ::close(fd); | ||
107 | } | ||
108 | |||
109 | // printf("%s\n", readPacket()); | ||
110 | // printf("%d\n", read(fd, read_buffer,sizeof(read_buffer)) ); | ||
111 | // printf("%s", read_buffer); | ||
112 | |||
113 | //this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html | ||
114 | const char *RemoteTab::readPacket() | ||
115 | { | ||
116 | static char buffer[PACKET_SIZE+1]=""; | ||
117 | char *end; | ||
118 | static int ptr=0,end_len=0; | ||
119 | ssize_t ret; | ||
120 | |||
121 | if(ptr>0) | ||
122 | { | ||
123 | memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1); | ||
124 | ptr=strlen(buffer); | ||
125 | end=strchr(buffer,'\n'); | ||
126 | } | ||
127 | else | ||
128 | { | ||
129 | end=NULL; | ||
130 | } | ||
131 | alarm(TIMEOUT); | ||
132 | while(end==NULL) | ||
133 | { | ||
134 | if(PACKET_SIZE<=ptr) | ||
135 | { | ||
136 | // fprintf(stderr,"%s: bad packet\n",progname); | ||
137 | ptr=0; | ||
138 | return(NULL); | ||
139 | } | ||
140 | ret=read(fd,buffer+ptr,PACKET_SIZE-ptr); | ||
141 | |||
142 | if(ret<=0 || timeout) | ||
143 | { | ||
144 | if(timeout) | ||
145 | { | ||
146 | // fprintf(stderr,"%s: timeout\n",progname); | ||
147 | } | ||
148 | else | ||
149 | { | ||
150 | alarm(0); | ||
151 | } | ||
152 | ptr=0; | ||
153 | return(NULL); | ||
154 | } | ||
155 | buffer[ptr+ret]=0; | ||
156 | ptr=strlen(buffer); | ||
157 | end=strchr(buffer,'\n'); | ||
158 | } | ||
159 | alarm(0);timeout=0; | ||
160 | |||
161 | end[0]=0; | ||
162 | ptr=strlen(buffer)+1; | ||
163 | //# ifdef DEBUG | ||
164 | //printf("buffer: -%s-\n",buffer); | ||
165 | //# endif | ||
166 | return(buffer); | ||
167 | } | ||
168 | |||
169 | void RemoteTab::setIRSocket(int newfd) | ||
170 | { | ||
171 | fd = newfd; | ||
172 | } | 58 | } |
173 | 59 | ||
174 | void RemoteTab::setConfig(Config *newCfg) | 60 | void RemoteTab::setConfig(Config *newCfg) |
175 | { | 61 | { |
176 | cfg = newCfg; | 62 | cfg = newCfg; |
177 | cfg->setGroup("Remotes"); | 63 | cfg->setGroup("Remotes"); |
178 | topGroup->updateRemotes(cfg); | 64 | topGroup->updateRemotes(cfg); |
179 | } | 65 | } |
180 | 66 | ||
181 | void RemoteTab::remoteSelected(const QString &string) | 67 | void RemoteTab::remoteSelected(const QString &string) |
182 | { | 68 | { |
183 | printf("1%s\n", string.latin1() ); | 69 | printf("1%s\n", string.latin1() ); |