-rw-r--r-- | noncore/tools/remote/buttondialog.cpp | 25 | ||||
-rw-r--r-- | noncore/tools/remote/remotetab.cpp | 15 | ||||
-rw-r--r-- | noncore/tools/remote/remotetab.h | 2 |
3 files changed, 40 insertions, 2 deletions
diff --git a/noncore/tools/remote/buttondialog.cpp b/noncore/tools/remote/buttondialog.cpp index e7ff4b4..7479e85 100644 --- a/noncore/tools/remote/buttondialog.cpp +++ b/noncore/tools/remote/buttondialog.cpp @@ -53,156 +53,181 @@ ButtonDialog::ButtonDialog(QString buttonName, QWidget *parent=0, const char*nam hlayout2->addWidget(button); hlayout2->addSpacing(5); button->insertItem("Button "); connect(button, SIGNAL(activated(const QString &)), this, SLOT(buttonSelected(const QString&)) ); label = new QLineEdit(this, "label"); label->setText(buttonName); QLabel *labelLabel = new QLabel(label, "Label: ", this, "labelLabel"); hlayout3->addSpacing(5); hlayout3->addWidget(labelLabel); hlayout3->addSpacing(5); hlayout3->addWidget(label); hlayout3->addSpacing(5); } void ButtonDialog::remoteSelected(const QString &string) { button->insertStringList(getButtons(string.latin1()) ); list="SEND_ONCE"; list+=string; } void ButtonDialog::buttonSelected(const QString &string) { list+=string; } QStringList ButtonDialog::getList() { return list; } QString ButtonDialog::getLabel() { return label->text(); } QStringList ButtonDialog::getRemotes() { const char write_buffer[] = "LIST\n"; const char *readbuffer; int i, numlines; QStringList list; addr.sun_family=AF_UNIX; strcpy(addr.sun_path,"/dev/lircd"); fd = socket(AF_UNIX, SOCK_STREAM, 0); + if(fd == -1) + { + QMessageBox *mb = new QMessageBox("Error!", + "couldnt connect to socket", + QMessageBox::NoIcon, + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton); + mb->exec(); + perror("ButtonDialog::GetRemotes"); + return NULL; + } if(std::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) { QMessageBox *mb = new QMessageBox("Error!", "couldnt connect to socket", QMessageBox::NoIcon, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton); mb->exec(); perror("ButtonDialog::GetRemotes"); return NULL; } write(fd, write_buffer, strlen(write_buffer)); for(i=0; i<5; i++) { printf("%d\n", i); readbuffer = readPacket(); printf("%s", readbuffer); printf("%d\n", i); } numlines = atoi(readbuffer); for(i=0; i<numlines; i++) { list+=readPacket(); } if(strcasecmp(readPacket(), "END") != 0) { QMessageBox *mb = new QMessageBox("Error!", "bad packet", QMessageBox::NoIcon, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton); mb->exec(); perror("ButtonDialog::GetRemotes"); return NULL; } std::close(fd); return list; } QStringList ButtonDialog::getButtons(const char *remoteName) { QString write_buffer = "LIST "; const char *readbuffer; int i, j, numlines; QStringList list; QString string; write_buffer += remoteName; write_buffer += '\n'; fd = socket(AF_UNIX, SOCK_STREAM, 0); + if(fd == -1) + { + QMessageBox *mb = new QMessageBox("Error!", + "couldnt connect to socket", + QMessageBox::NoIcon, + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton); + mb->exec(); + perror("ButtonDialog::GetButtons"); + return NULL; + } + if(std::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) { QMessageBox *mb = new QMessageBox("Error!", "couldnt connect to socket", QMessageBox::NoIcon, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton); mb->exec(); perror("ButtonDialog::GetButtons"); return NULL; } write(fd, write_buffer.latin1(), strlen(write_buffer) ); for(i=0; i<5; i++) { readbuffer = readPacket(); } numlines = atoi(readbuffer); for(i=0; i<numlines; i++) { list+=readPacket(); for(j=0; j<list[i].length(); j++) { if(list[i][j] == ' ') break; } list[i].remove(0, j+1); } if(strcasecmp(readPacket(), "END") != 0) { QMessageBox *mb = new QMessageBox("Error!", "bad packet", QMessageBox::NoIcon, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton); mb->exec(); perror("ButtonDialog::GetButtons"); return NULL; } std::close(fd); diff --git a/noncore/tools/remote/remotetab.cpp b/noncore/tools/remote/remotetab.cpp index f3a8945..64b8ee4 100644 --- a/noncore/tools/remote/remotetab.cpp +++ b/noncore/tools/remote/remotetab.cpp @@ -6,106 +6,119 @@ This program is free software; you can redistribute it and/or modify it under th License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "remotetab.h" RemoteTab::RemoteTab(QWidget *parent=0, const char *name=0):QWidget(parent,name) { QVBoxLayout *layout = new QVBoxLayout(this); topGroup = new TopGroup(this); // topGroup->setMaximumHeight(22); layout->addWidget(topGroup, 0, 0); printf("%d %d", topGroup->width(), topGroup->height()); layout->addSpacing(1); dvdGroup = new DVDGroup(this); // dvdGroup->setMaximumHeight(68); layout->addWidget(dvdGroup, 0, 0); layout->addSpacing(1); vcrGroup = new VCRGroup(this); layout->addWidget(vcrGroup, 0, 0); // vcrGroup->setMaximumHeight(45); layout->addSpacing(1); channelGroup = new ChannelGroup(this); // channelGroup->setMaximumHeight(91); layout->addWidget(channelGroup, 0, 0); this->setMaximumWidth(240); timeout = 0; addr.sun_family=AF_UNIX; strcpy(addr.sun_path,"/dev/lircd"); } -void RemoteTab::sendIR() +int RemoteTab::sendIR() { const QObject *button = sender(); QString string = cfg->readEntry(button->name()); string+='\n'; const char *write_buffer = string.latin1(); const char *read_buffer; bool done=false; fd = socket(AF_UNIX, SOCK_STREAM, 0); + if(fd == -1) + { + QMessageBox *mb = new QMessageBox("Error!", + "couldnt connect to socket", + QMessageBox::NoIcon, + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton); + mb->exec(); + perror("RemoteTab::SendIR"); + return NULL; + } + if(std::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) { QMessageBox *mb = new QMessageBox("Error!", "couldnt connect to socket", QMessageBox::NoIcon, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton); mb->exec(); perror("RemoteTab::SendIR"); } printf("fd2: %d\n", fd); printf("%s", write_buffer); printf("1\n"); printf("%d\n", write(fd, write_buffer, strlen(write_buffer) ) ); printf("2\n"); while(!done) { read_buffer=readPacket(); printf("%s\n", read_buffer); if(strcasecmp(read_buffer, "END") == 0) { printf("done reading packet\n"); done=true; } } std::close(fd); } // printf("%s\n", readPacket()); // printf("%d\n", read(fd, read_buffer,sizeof(read_buffer)) ); // printf("%s", read_buffer); //this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html const char *RemoteTab::readPacket() { static char buffer[PACKET_SIZE+1]=""; char *end; static int ptr=0,end_len=0; ssize_t ret; if(ptr>0) { memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1); ptr=strlen(buffer); diff --git a/noncore/tools/remote/remotetab.h b/noncore/tools/remote/remotetab.h index 77a7318..38b58e9 100644 --- a/noncore/tools/remote/remotetab.h +++ b/noncore/tools/remote/remotetab.h @@ -5,60 +5,60 @@ Copyright (C) 2002 Thomas Stephens This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <qpe/config.h> #include <qwidget.h> #include <qlayout.h> #include <qvbox.h> #include <qmessagebox.h> #include <qstring.h> #include <qsize.h> #include <qobjectlist.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/socket.h> #include <sys/types.h> #include <sys/un.h> #include <unistd.h> #include <errno.h> #include "topgroup.h" #include "dvdgroup.h" #include "channelgroup.h" #include "vcrgroup.h" #define PACKET_SIZE 256 #define TIMEOUT 3 class RemoteTab : public QWidget { Q_OBJECT public: RemoteTab(QWidget *parent=0, const char *name=0); void setIRSocket(int newfd); const char *readPacket(); void setConfig(Config *newCfg); void updateRemotesList(); public slots: - void sendIR(); + int sendIR(); void remoteSelected(const QString &string); private: int fd; int timeout; struct sockaddr_un addr; Config *cfg; TopGroup *topGroup; DVDGroup *dvdGroup; VCRGroup *vcrGroup; ChannelGroup *channelGroup; }; |