Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

remotetab.cpp

Go to the documentation of this file.
00001 /*
00002 Opie-Remote.  emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie.
00003 Copyright (C) 2002 Thomas Stephens
00004 
00005 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
00006 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
00007 version.
00008 
00009 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
00010 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
00011 Public License for more details.
00012 
00013 You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
00014 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00015 */
00016 
00017 #include "remotetab.h"
00018 
00019 RemoteTab::RemoteTab(QWidget *parent, const char *name):QWidget(parent,name)
00020 {
00021         QVBoxLayout *layout = new QVBoxLayout(this);
00022 
00023         topGroup = new TopGroup(this);
00024 //      topGroup->setMaximumHeight(22);
00025         layout->addWidget(topGroup, 0, 0);
00026         printf("%d %d", topGroup->width(), topGroup->height());
00027 
00028         layout->addSpacing(1);
00029 
00030         dvdGroup = new DVDGroup(this);
00031 //      dvdGroup->setMaximumHeight(68);
00032         layout->addWidget(dvdGroup, 0, 0);
00033 
00034         layout->addSpacing(1);
00035 
00036         vcrGroup = new VCRGroup(this);
00037         layout->addWidget(vcrGroup, 0, 0);
00038 //      vcrGroup->setMaximumHeight(45);
00039 
00040         layout->addSpacing(1);
00041 
00042         channelGroup = new ChannelGroup(this);
00043 //      channelGroup->setMaximumHeight(91);
00044         layout->addWidget(channelGroup, 0, 0);
00045 
00046         this->setMaximumWidth(240);
00047 
00048         timeout = 0;
00049 
00050         addr.sun_family=AF_UNIX;
00051         strcpy(addr.sun_path,"/dev/lircd");
00052 }
00053 
00054 int RemoteTab::sendIR()
00055 {
00056         const QObject *button = sender();
00057         QString string = cfg->readEntry(button->name());
00058         string+='\n';
00059         const char *write_buffer = string.latin1();
00060         const char *read_buffer;
00061         bool done=false;
00062 
00063         fd = socket(AF_UNIX, SOCK_STREAM, 0);
00064         if(fd == -1)
00065         {
00066                 QMessageBox *mb = new QMessageBox("Error!",
00067                                                                                         "couldnt connect to socket",
00068                                                                                         QMessageBox::NoIcon,
00069                                                                                         QMessageBox::Ok,
00070                                                                                         QMessageBox::NoButton,
00071                                                                                         QMessageBox::NoButton);
00072                 mb->exec();
00073                 perror("RemoteTab::SendIR");
00074                 return 0;
00075         }
00076 
00077 
00078         if(::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1)
00079         {
00080                 QMessageBox *mb = new QMessageBox("Error!",
00081                                                                                         "couldnt connect to socket",
00082                                                                                         QMessageBox::NoIcon,
00083                                                                                         QMessageBox::Ok,
00084                                                                                         QMessageBox::NoButton,
00085                                                                                         QMessageBox::NoButton);
00086                 mb->exec();
00087                 perror("RemoteTab::SendIR");
00088         }
00089 
00090         printf("fd2: %d\n", fd);
00091         printf("%s", write_buffer);
00092 
00093         printf("1\n");
00094         printf("%d\n", write(fd, write_buffer, strlen(write_buffer) ) );
00095         printf("2\n");
00096         while(!done)
00097         {
00098                 read_buffer=readPacket();
00099                 printf("%s\n", read_buffer);
00100                 if(strcasecmp(read_buffer, "END") == 0)
00101                 {
00102                         printf("done reading packet\n");
00103                         done=true;
00104                 }
00105         }
00106         ::close(fd);
00107 }
00108 
00109 //              printf("%s\n", readPacket());
00110 //              printf("%d\n", read(fd, read_buffer,sizeof(read_buffer)) );
00111 //              printf("%s", read_buffer);
00112 
00113 //this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html
00114 const char *RemoteTab::readPacket()
00115 {
00116         static char buffer[PACKET_SIZE+1]="";
00117         char *end;
00118         static int ptr=0,end_len=0;
00119         ssize_t ret;
00120 
00121         if(ptr>0)
00122         {
00123                 memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1);
00124                 ptr=strlen(buffer);
00125                 end=strchr(buffer,'\n');
00126         }
00127         else
00128         {
00129                 end=NULL;
00130         }
00131         alarm(TIMEOUT);
00132         while(end==NULL)
00133         {
00134                 if(PACKET_SIZE<=ptr)
00135                 {
00136 //                      fprintf(stderr,"%s: bad packet\n",progname);
00137                         ptr=0;
00138                         return(NULL);
00139                 }
00140                 ret=read(fd,buffer+ptr,PACKET_SIZE-ptr);
00141 
00142                 if(ret<=0 || timeout)
00143                 {
00144                         if(timeout)
00145                         {
00146 //                              fprintf(stderr,"%s: timeout\n",progname);
00147                         }
00148                         else
00149                         {
00150                                 alarm(0);
00151                         }
00152                         ptr=0;
00153                         return(NULL);
00154                 }
00155                 buffer[ptr+ret]=0;
00156                 ptr=strlen(buffer);
00157                 end=strchr(buffer,'\n');
00158         }
00159         alarm(0);timeout=0;
00160 
00161         end[0]=0;
00162         ptr=strlen(buffer)+1;
00163 //#       ifdef DEBUG
00164 //      printf("buffer: -%s-\n",buffer);
00165 //#       endif
00166         return(buffer);
00167 }
00168 
00169 void RemoteTab::setIRSocket(int newfd)
00170 {
00171         fd = newfd;
00172 }
00173 
00174 void RemoteTab::setConfig(Config *newCfg)
00175 {
00176         cfg = newCfg;
00177         cfg->setGroup("Remotes");
00178         topGroup->updateRemotes(cfg);
00179 }
00180 
00181 void RemoteTab::remoteSelected(const QString &string)
00182 {
00183         printf("1%s\n", string.latin1() );
00184         cfg->setGroup(string);
00185         const QObject *obj;
00186 
00187         const QObjectList *objList = topGroup->children();
00188         for(obj = ((QObjectList *)objList)->first(); obj != 0; obj=((QObjectList *)objList)->next())
00189         {
00190                 if(obj->inherits("QPushButton"))
00191                 {
00192                         if(cfg->hasKey((QString)obj->name()+"Label"))
00193                         {
00194                                 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") );
00195                         }
00196                         else
00197                         {
00198                                 cfg->setGroup("Default");
00199                                 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") );
00200                                 cfg->setGroup(string);
00201                         }
00202                 }
00203         }
00204         
00205         objList = dvdGroup->children();
00206         for(obj = ((QObjectList *)objList)->first(); obj != 0; obj=((QObjectList *)objList)->next())
00207         {
00208                 if(obj->inherits("QPushButton"))
00209                 {
00210                         if(cfg->hasKey((QString)obj->name()+"Label"))
00211                         {
00212                                 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") );
00213                         }
00214                         else
00215                         {
00216                                 cfg->setGroup("Default");
00217                                 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") );
00218                                 cfg->setGroup(string);
00219                         }
00220                 }
00221         }
00222 
00223         objList = vcrGroup->children();
00224         for(obj = ((QObjectList *)objList)->first(); obj != 0; obj=((QObjectList *)objList)->next())
00225         {
00226                 if(obj->inherits("QPushButton"))
00227                 {
00228                         if(cfg->hasKey((QString)obj->name()+"Label"))
00229                         {
00230                                 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") );
00231                         }
00232                         else
00233                         {
00234                                 cfg->setGroup("Default");
00235                                 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") );
00236                                 cfg->setGroup(string);
00237                         }
00238                 }
00239         }
00240 
00241         objList = channelGroup->children();
00242         for(obj = ((QObjectList *)objList)->first(); obj != 0; obj=((QObjectList *)objList)->next())
00243         {
00244                 if(obj->inherits("QPushButton"))
00245                 {
00246                         if(cfg->hasKey((QString)obj->name()+"Label"))
00247                         {
00248                                 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") );
00249                         }
00250                         else
00251                         {
00252                                 cfg->setGroup("Default");
00253                                 ((QPushButton *)obj)->setText(cfg->readEntry((QString)obj->name()+"Label") );
00254                                 cfg->setGroup(string);
00255                         }
00256                 }
00257         }
00258 }
00259 
00260 void RemoteTab::updateRemotesList()
00261 {
00262         topGroup->updateRemotes(cfg);
00263 }

Generated on Sat Nov 5 16:18:03 2005 for OPIE by  doxygen 1.4.2