summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/remote/buttondialog.cpp216
-rw-r--r--noncore/tools/remote/buttondialog.h12
-rw-r--r--noncore/tools/remote/learntab.cpp132
-rw-r--r--noncore/tools/remote/learntab.h9
-rw-r--r--noncore/tools/remote/lirchandler.cpp270
-rw-r--r--noncore/tools/remote/lirchandler.h38
-rw-r--r--noncore/tools/remote/mainview.cpp13
-rw-r--r--noncore/tools/remote/mainview.h3
-rw-r--r--noncore/tools/remote/packetread.h200
-rw-r--r--noncore/tools/remote/remote.cpp73
-rw-r--r--noncore/tools/remote/remote.pro4
-rw-r--r--noncore/tools/remote/remotetab.cpp122
-rw-r--r--noncore/tools/remote/remotetab.h7
13 files changed, 344 insertions, 755 deletions
diff --git a/noncore/tools/remote/buttondialog.cpp b/noncore/tools/remote/buttondialog.cpp
index 580f101..56738d1 100644
--- a/noncore/tools/remote/buttondialog.cpp
+++ b/noncore/tools/remote/buttondialog.cpp
@@ -35,2 +35,4 @@ ButtonDialog::ButtonDialog(QString buttonName, QWidget *parent, const char*name,
layout->addSpacing(5);
+
+ lh = new LircHandler();
@@ -44,3 +46,3 @@ ButtonDialog::ButtonDialog(QString buttonName, QWidget *parent, const char*name,
remote->insertItem("Remote ");
- remote->insertStringList(getRemotes());
+ remote->insertStringList(lh->getRemotes());
connect(remote, SIGNAL(activated(const QString&)), this, SLOT(remoteSelected(const QString&)) );
@@ -67,5 +69,10 @@ ButtonDialog::ButtonDialog(QString buttonName, QWidget *parent, const char*name,
+ButtonDialog::~ButtonDialog()
+{
+ delete lh;
+}
+
void ButtonDialog::remoteSelected(const QString &string)
{
- button->insertStringList(getButtons(string.latin1()) );
+ button->insertStringList(lh->getButtons(string.latin1()) );
list="SEND_ONCE";
@@ -88,206 +95 @@ QString ButtonDialog::getLabel()
}
-
-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(::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;
- }
-
- ::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(::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;
- }
-
- ::close(fd);
- return list;
-}
-
-
-//this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html
-const char *ButtonDialog::readPacket()
-{
- static char buffer[PACKET_SIZE+1]="";
- char *end;
- static int ptr=0,end_len=0;
- ssize_t ret;
- timeout = 0;
-
- if(ptr>0)
- {
- memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1);
- ptr=strlen(buffer);
- end=strchr(buffer,'\n');
- }
- else
- {
- end=NULL;
- }
- alarm(TIMEOUT);
- while(end==NULL)
- {
- if(PACKET_SIZE<=ptr)
- {
- fprintf(stderr,"bad packet\n");
- ptr=0;
- return(NULL);
- }
- ret=read(fd,buffer+ptr,PACKET_SIZE-ptr);
-
- if(ret<=0 || timeout)
- {
- if(timeout)
- {
- fprintf(stderr,"timeout\n");
- }
- else
- {
- alarm(0);
- }
- ptr=0;
- return(NULL);
- }
- buffer[ptr+ret]=0;
- ptr=strlen(buffer);
- end=strchr(buffer,'\n');
- }
- alarm(0);timeout=0;
-
- end[0]=0;
- ptr=strlen(buffer)+1;
-//# ifdef DEBUG
-// printf("buffer: -%s-\n",buffer);
-//# endif
- return(buffer);
-}
diff --git a/noncore/tools/remote/buttondialog.h b/noncore/tools/remote/buttondialog.h
index 33dc4ef..cc697b5 100644
--- a/noncore/tools/remote/buttondialog.h
+++ b/noncore/tools/remote/buttondialog.h
@@ -33,4 +33,3 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#define PACKET_SIZE 256
-#define TIMEOUT 3
+#include "lirchandler.h"
@@ -41,6 +40,3 @@ public:
ButtonDialog(QString buttonName, QWidget *parent=0, const char*name=0, bool modal=FALSE, WFlags f=0);
- void setIRSocket(int newfd);
- const char *readPacket();
- QStringList getRemotes();
- QStringList getButtons(const char *remoteName);
+ ~ButtonDialog();
QStringList getList();
@@ -55,5 +51,3 @@ private:
QLineEdit *label;
- int fd;
- int timeout;
- struct sockaddr_un addr;
+ LircHandler *lh;
};
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
@@ -23,2 +23,4 @@ LearnTab::LearnTab(QWidget *parent, const char *name):QWidget(parent,name)
{
+ LircHandler lh;
+
QVBoxLayout *layout = new QVBoxLayout(this);
@@ -29,3 +31,3 @@ LearnTab::LearnTab(QWidget *parent, const char *name):QWidget(parent,name)
layout->insertWidget(0, remotesBox, 1);
- remotesBox->insertStringList(getRemotes());
+ remotesBox->insertStringList(lh.getRemotes());
@@ -64,129 +66 @@ void LearnTab::del()
-QStringList LearnTab::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("LearnTab::GetRemotes");
- return NULL;
- }
-
- if(::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("LearnTab::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("LearnTab::GetRemotes");
- return NULL;
- }
-
- ::close(fd);
- return list;
-}
-
-//this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html
-const char *LearnTab::readPacket()
-{
- static char buffer[PACKET_SIZE+1]="";
- char *end;
- static int ptr=0,end_len=0;
- ssize_t ret;
- timeout = 0;
-
- if(ptr>0)
- {
- memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1);
- ptr=strlen(buffer);
- end=strchr(buffer,'\n');
- }
- else
- {
- end=NULL;
- }
- alarm(TIMEOUT);
- while(end==NULL)
- {
- if(PACKET_SIZE<=ptr)
- {
- fprintf(stderr,"bad packet\n");
- ptr=0;
- return(NULL);
- }
- ret=read(fd,buffer+ptr,PACKET_SIZE-ptr);
-
- if(ret<=0 || timeout)
- {
- if(timeout)
- {
- fprintf(stderr,"timeout\n");
- }
- else
- {
- alarm(0);
- }
- ptr=0;
- return(NULL);
- }
- buffer[ptr+ret]=0;
- ptr=strlen(buffer);
- end=strchr(buffer,'\n');
- }
- alarm(0);timeout=0;
-
- end[0]=0;
- ptr=strlen(buffer)+1;
- //# ifdef DEBUG
- // printf("buffer: -%s-\n",buffer);
- //# endif
- return(buffer);
-}
-
diff --git a/noncore/tools/remote/learntab.h b/noncore/tools/remote/learntab.h
index cb84600..c9d8e41 100644
--- a/noncore/tools/remote/learntab.h
+++ b/noncore/tools/remote/learntab.h
@@ -34,5 +34,3 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "recorddialog.h"
-
-#define PACKET_SIZE 256
-#define TIMEOUT 3
+#include "lirchandler.h"
@@ -43,4 +41,2 @@ public:
LearnTab(QWidget *parent=0, const char *name=0);
- const char *readPacket();
- QStringList getRemotes();
public slots:
@@ -51,5 +47,2 @@ private:
QListBox *remotesBox;
- int fd;
- int timeout;
- struct sockaddr_un addr;
};
diff --git a/noncore/tools/remote/lirchandler.cpp b/noncore/tools/remote/lirchandler.cpp
new file mode 100644
index 0000000..f44806e
--- a/dev/null
+++ b/noncore/tools/remote/lirchandler.cpp
@@ -0,0 +1,270 @@
+/*
+Opie-Remote. emulates remote controls on an iPaq (and maybe a Zaurus) in Opie.
+Copyright (C) 2007 Paul Eggleton & 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 <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 <qstring.h>
+#include <qmessagebox.h>
+#include <qobject.h>
+#include <opie2/oprocess.h>
+
+#include "lirchandler.h"
+
+#define PACKET_SIZE 256
+#define TIMEOUT 3
+#define LIRCD_SOCKET "/dev/lircd"
+#define LIRCD_SERVICECMD "/etc/init.d/lircd"
+
+using namespace Opie::Core;
+
+LircHandler::LircHandler(void)
+{
+ fd = 0;
+ addr.sun_family=AF_UNIX;
+ strcpy(addr.sun_path, LIRCD_SOCKET);
+}
+
+bool LircHandler::connectLirc(void)
+{
+ fd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if(fd == -1)
+ {
+ QMessageBox *mb = new QMessageBox(QObject::tr("Error"),
+ QObject::tr("Unable to create socket"),
+ QMessageBox::Critical,
+ QMessageBox::Ok,
+ QMessageBox::NoButton,
+ QMessageBox::NoButton);
+ mb->exec();
+ perror("LircHandler::connectLirc");
+ return false;
+ }
+
+ if(::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1)
+ {
+ QMessageBox *mb = new QMessageBox(QObject::tr("Error"),
+ QObject::tr("Could not connect to lircd"),
+ QMessageBox::Critical,
+ QMessageBox::Ok,
+ QMessageBox::NoButton,
+ QMessageBox::NoButton);
+ mb->exec();
+ perror("LircHandler::connectLirc");
+ return false;
+ }
+
+ return true;
+}
+
+//this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html
+const char *LircHandler::readPacket()
+{
+ static char buffer[PACKET_SIZE+1]="";
+ char *end;
+ static int ptr=0;
+ ssize_t ret;
+ int timeout = 0;
+
+ if(ptr>0)
+ {
+ memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1);
+ ptr=strlen(buffer);
+ end=strchr(buffer,'\n');
+ }
+ else
+ {
+ end=NULL;
+ }
+ alarm(TIMEOUT);
+ while(end==NULL)
+ {
+ if(PACKET_SIZE<=ptr)
+ {
+ fprintf(stderr,"readPacket: bad packet\n");
+ ptr=0;
+ return(NULL);
+ }
+ ret=read(fd,buffer+ptr,PACKET_SIZE-ptr);
+
+ if(ret<=0 || timeout)
+ {
+ if(timeout)
+ {
+ fprintf(stderr,"readPacket: timeout\n");
+ }
+ else
+ {
+ alarm(0);
+ }
+ ptr=0;
+ return(NULL);
+ }
+ buffer[ptr+ret]=0;
+ ptr=strlen(buffer);
+ end=strchr(buffer,'\n');
+ }
+ alarm(0);
+
+ end[0]=0;
+ ptr=strlen(buffer)+1;
+//# ifdef DEBUG
+// printf("buffer: -%s-\n",buffer);
+//# endif
+ return(buffer);
+}
+
+QStringList LircHandler::getRemotes(void)
+{
+ const char write_buffer[] = "LIST\n";
+ const char *readbuffer;
+ int i, numlines;
+ QStringList list;
+
+ if(connectLirc()) {
+ write(fd, write_buffer, strlen(write_buffer) );
+
+ for(i=0; i<5; i++)
+ {
+ readbuffer = readPacket();
+ }
+
+ numlines = atoi(readbuffer);
+
+ for(i=0; i<numlines; i++)
+ {
+ list+=readPacket();
+ }
+
+ if(strcasecmp(readPacket(), "END") != 0)
+ {
+ QMessageBox *mb = new QMessageBox(QObject::tr("Error"),
+ QObject::tr("Bad packet while communicating with lircd"),
+ QMessageBox::Critical,
+ QMessageBox::Ok,
+ QMessageBox::NoButton,
+ QMessageBox::NoButton);
+ mb->exec();
+ perror("LircHandler::getRemotes");
+ return NULL;
+ }
+
+ ::close(fd);
+ }
+
+ return list;
+}
+
+QStringList LircHandler::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';
+
+ if(connectLirc()) {
+ 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(QObject::tr("Error"),
+ QObject::tr("Bad packet while communicating with lircd"),
+ QMessageBox::Critical,
+ QMessageBox::Ok,
+ QMessageBox::NoButton,
+ QMessageBox::NoButton);
+ mb->exec();
+ perror("LircHandler::getRemotes");
+ return NULL;
+ }
+
+ ::close(fd);
+ }
+
+ return list;
+}
+
+int LircHandler::sendIR(const char *irbutton)
+{
+ const char *read_buffer;
+ bool done=false;
+
+ if(connectLirc()) {
+ printf("fd2: %d\n", fd);
+ printf("%s", irbutton);
+
+ printf("1\n");
+ printf("%d\n", write(fd, irbutton, strlen(irbutton) ) );
+ 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;
+ }
+ }
+ ::close(fd);
+ return 1;
+ }
+ else
+ return 0;
+}
+
+bool LircHandler::startLircd(void)
+{
+ return (system(LIRCD_SERVICECMD " start") == 0);
+}
+
+bool LircHandler::stopLircd(void)
+{
+ return (system(LIRCD_SERVICECMD " stop") == 0);
+}
+
+bool LircHandler::isLircdRunning(void)
+{
+ return (OProcess::processPID("lircd") != 0);
+}
diff --git a/noncore/tools/remote/lirchandler.h b/noncore/tools/remote/lirchandler.h
new file mode 100644
index 0000000..29894b4
--- a/dev/null
+++ b/noncore/tools/remote/lirchandler.h
@@ -0,0 +1,38 @@
+/*
+Opie-Remote. emulates remote controls on an iPaq (and maybe a Zaurus) in Opie.
+Copyright (C) 2007 Paul Eggleton & 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
+*/
+
+#ifndef LIRCHANDLER_H
+#define LIRCHANDLER_H
+
+class LircHandler
+{
+private:
+ bool connectLirc(void);
+ const char *readPacket();
+
+ struct sockaddr_un addr;
+ int fd;
+public:
+ LircHandler(void);
+ QStringList getRemotes(void);
+ QStringList getButtons(const char *remoteName);
+ int sendIR(const char *irbutton);
+ bool startLircd(void);
+ bool stopLircd(void);
+ bool isLircdRunning(void);
+};
+
+#endif
diff --git a/noncore/tools/remote/mainview.cpp b/noncore/tools/remote/mainview.cpp
index 724eba9..8c87785 100644
--- a/noncore/tools/remote/mainview.cpp
+++ b/noncore/tools/remote/mainview.cpp
@@ -36,4 +36,2 @@ MainView::MainView(QWidget *parent, const char *name) : QWidget(parent, name)
- remote->setIRSocket(fd);
-
tabs->addTab(remote, tr("Remote") );
@@ -51,13 +49,2 @@ MainView::MainView(QWidget *parent, const char *name) : QWidget(parent, name)
-int MainView::getIRSocket()
-{
- return fd;
-}
-
-void MainView::setIRSocket(int newfd)
-{
- fd = newfd;
- remote->setIRSocket(fd);
-}
-
void MainView::updateRemotesList()
diff --git a/noncore/tools/remote/mainview.h b/noncore/tools/remote/mainview.h
index 7ea82a6..b1ddde4 100644
--- a/noncore/tools/remote/mainview.h
+++ b/noncore/tools/remote/mainview.h
@@ -43,4 +43,2 @@ public:
MainView(QWidget *parent=0, const char *name=0);
- int getIRSocket();
- void setIRSocket(int newfd);
public slots:
@@ -48,3 +46,2 @@ public slots:
private:
- int fd;
RemoteTab *remote;
diff --git a/noncore/tools/remote/packetread.h b/noncore/tools/remote/packetread.h
deleted file mode 100644
index 5dc1ad4..0000000
--- a/noncore/tools/remote/packetread.h
+++ b/dev/null
@@ -1,200 +0,0 @@
-/*
-Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie.
-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
-
-file not used
-*/
-
-#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>
-
-#define PACKET_SIZE 256
-#define TIMEOUT 3
-
-//this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html
-const char *readPacket(int fd)
-{
- 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);
- end=strchr(buffer,'\n');
- }
- else
- {
- end=NULL;
- }
- alarm(TIMEOUT);
- while(end==NULL)
- {
- if(PACKET_SIZE<=ptr)
- {
-// fprintf(stderr,"%s: bad packet\n",progname);
- ptr=0;
- return(NULL);
- }
- ret=read(fd,buffer+ptr,PACKET_SIZE-ptr);
-
- if(ret<=0 || timeout)
- {
- if(timeout)
- {
-// fprintf(stderr,"%s: timeout\n",progname);
- }
- else
- {
- alarm(0);
- }
- ptr=0;
- return(NULL);
- }
- buffer[ptr+ret]=0;
- ptr=strlen(buffer);
- end=strchr(buffer,'\n');
- }
- alarm(0);timeout=0;
-
- end[0]=0;
- ptr=strlen(buffer)+1;
-//# ifdef DEBUG
-// printf("buffer: -%s-\n",buffer);
-//# endif
- return(buffer);
-}
-QStringList getRemotes(int fd)
-{
- const char write_buffer[] = "LIST\n";
- const char *readbuffer;
- int i, numlines;
- QStringList list;
-
- fd = socket(AF_UNIX, SOCK_STREAM, 0);
-
- 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("ConfigTab::GetRemotes");
- return NULL;
- }
-
- write(fd, write_buffer, strlen(write_buffer) );
-
- for(i=0; i<5; i++)
- {
- readbuffer = readPacket(int fd);
- }
-
- 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("ConfigTab::GetRemotes");
- return NULL;
- }
-
- std::close(fd);
- return list;
-}
-
-QStringList getButtons(int fd, 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(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("ConfigTab::GetRemotes");
- 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("ConfigTab::GetRemotes");
- return NULL;
- }
-
- std::close(fd);
- return list;
-}
diff --git a/noncore/tools/remote/remote.cpp b/noncore/tools/remote/remote.cpp
index 35d06bc..67fc57d 100644
--- a/noncore/tools/remote/remote.cpp
+++ b/noncore/tools/remote/remote.cpp
@@ -39,23 +39,2 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-/*void reconnect(int &fd)
-{
-// struct sockaddr_un addr;
-
- addr.sun_family=AF_UNIX;
- strcpy(addr.sun_path,"/dev/lircd");
- fd = socket(AF_UNIX, SOCK_STREAM, 0);
-
- if(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();
- }
-}
-*/
-
int main( int argc, char **argv )
@@ -64,42 +43,18 @@ int main( int argc, char **argv )
MainView w;
-
- int fd;
- // struct sockaddr_un addr;
- // char read_buffer[BUFFERSIZE+1];
- // char write_buffer[] = "LIST\n";
-
- // addr.sun_family=AF_UNIX;
- // strcpy(addr.sun_path,"/dev/lircd");
- // fd = socket(AF_UNIX, SOCK_STREAM, 0);
-
- // printf("fd1: %d\n", fd);
- /*
- if(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();
- }
- */
-
- // printf("%d\n", write(fd, write_buffer, sizeof(write_buffer) ) );
-
- // printf("%d\n", read(fd, read_buffer, BUFFERSIZE ) );
-
- // QMessageBox *mbtest = new QMessageBox("lirc test",
- // *new QString((const char *) read_buffer),
- // QMessageBox::NoIcon,
- // QMessageBox::Ok,
- // QMessageBox::NoButton,
- // QMessageBox::NoButton);
- // mbtest->exec();
-
a.setMainWidget( &w );
- w.setIRSocket(fd);
QPEApplication::showWidget( &w );
- return a.exec();
+
+ LircHandler lh;
+ if(!lh.isLircdRunning()) {
+ QMessageBox mb("Error!",
+ "Lircd is not running",
+ QMessageBox::NoIcon,
+ QMessageBox::Ok,
+ QMessageBox::NoButton,
+ QMessageBox::NoButton);
+ mb.exec();
+
+ }
+
+ return a.exec();
}
diff --git a/noncore/tools/remote/remote.pro b/noncore/tools/remote/remote.pro
index 880856c..59ea81b 100644
--- a/noncore/tools/remote/remote.pro
+++ b/noncore/tools/remote/remote.pro
@@ -3,4 +3,4 @@ CONFIG +=qt warn_on
DESTDIR =$(OPIEDIR)/bin
-HEADERS = remotetab.h learntab.h configtab.h topgroup.h dvdgroup.h channelgroup.h vcrgroup.h buttondialog.h topgroupconf.h dvdgroupconf.h channelgroupconf.h vcrgroupconf.h mainview.h recorddialog.h helptab.h
-SOURCES =remote.cpp remotetab.cpp learntab.cpp configtab.cpp topgroup.cpp dvdgroup.cpp channelgroup.cpp vcrgroup.cpp buttondialog.cpp topgroupconf.cpp dvdgroupconf.cpp channelgroupconf.cpp vcrgroupconf.cpp mainview.cpp recorddialog.cpp helptab.cpp
+HEADERS = remotetab.h learntab.h configtab.h topgroup.h dvdgroup.h channelgroup.h vcrgroup.h buttondialog.h topgroupconf.h dvdgroupconf.h channelgroupconf.h vcrgroupconf.h mainview.h recorddialog.h helptab.h lirchandler.h
+SOURCES =remote.cpp remotetab.cpp learntab.cpp configtab.cpp topgroup.cpp dvdgroup.cpp channelgroup.cpp vcrgroup.cpp buttondialog.cpp topgroupconf.cpp dvdgroupconf.cpp channelgroupconf.cpp vcrgroupconf.cpp mainview.cpp recorddialog.cpp helptab.cpp lirchandler.cpp
INCLUDEPATH +=$(OPIEDIR)/include
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
@@ -17,2 +17,3 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "remotetab.h"
+#include "lirchandler.h"
@@ -46,7 +47,2 @@ RemoteTab::RemoteTab(QWidget *parent, const char *name):QWidget(parent,name)
this->setMaximumWidth(240);
-
- timeout = 0;
-
- addr.sun_family=AF_UNIX;
- strcpy(addr.sun_path,"/dev/lircd");
}
@@ -58,115 +54,5 @@ int RemoteTab::sendIR()
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 0;
- }
-
-
- if(::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;
- }
- }
- ::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);
- end=strchr(buffer,'\n');
- }
- else
- {
- end=NULL;
- }
- alarm(TIMEOUT);
- while(end==NULL)
- {
- if(PACKET_SIZE<=ptr)
- {
-// fprintf(stderr,"%s: bad packet\n",progname);
- ptr=0;
- return(NULL);
- }
- ret=read(fd,buffer+ptr,PACKET_SIZE-ptr);
-
- if(ret<=0 || timeout)
- {
- if(timeout)
- {
-// fprintf(stderr,"%s: timeout\n",progname);
- }
- else
- {
- alarm(0);
- }
- ptr=0;
- return(NULL);
- }
- buffer[ptr+ret]=0;
- ptr=strlen(buffer);
- end=strchr(buffer,'\n');
- }
- alarm(0);timeout=0;
-
- end[0]=0;
- ptr=strlen(buffer)+1;
-//# ifdef DEBUG
-// printf("buffer: -%s-\n",buffer);
-//# endif
- return(buffer);
-}
-
-void RemoteTab::setIRSocket(int newfd)
-{
- fd = newfd;
+
+ LircHandler lh;
+ return lh.sendIR(string.latin1());
}
diff --git a/noncore/tools/remote/remotetab.h b/noncore/tools/remote/remotetab.h
index 38b58e9..da0a543 100644
--- a/noncore/tools/remote/remotetab.h
+++ b/noncore/tools/remote/remotetab.h
@@ -39,5 +39,2 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#define PACKET_SIZE 256
-#define TIMEOUT 3
-
class RemoteTab : public QWidget
@@ -47,3 +44,2 @@ public:
RemoteTab(QWidget *parent=0, const char *name=0);
- void setIRSocket(int newfd);
const char *readPacket();
@@ -55,5 +51,2 @@ public slots:
private:
- int fd;
- int timeout;
- struct sockaddr_un addr;
Config *cfg;