summaryrefslogtreecommitdiff
path: root/noncore/tools/remote/learntab.cpp
authorspiralman <spiralman>2002-07-23 22:34:51 (UTC)
committer spiralman <spiralman>2002-07-23 22:34:51 (UTC)
commit7b69ef59464072521adb20148d49f9c654c066ee (patch) (unidiff)
tree449ef1dbfeac19f18b1ded20b4865353fa71452c /noncore/tools/remote/learntab.cpp
parentc344a4f4d0a614cfeb75d1d935e1f519d473c068 (diff)
downloadopie-7b69ef59464072521adb20148d49f9c654c066ee.zip
opie-7b69ef59464072521adb20148d49f9c654c066ee.tar.gz
opie-7b69ef59464072521adb20148d49f9c654c066ee.tar.bz2
Added code for irrecord frontend, doesnt work yet.
Diffstat (limited to 'noncore/tools/remote/learntab.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/remote/learntab.cpp171
1 files changed, 168 insertions, 3 deletions
diff --git a/noncore/tools/remote/learntab.cpp b/noncore/tools/remote/learntab.cpp
index 998f449..1c746c5 100644
--- a/noncore/tools/remote/learntab.cpp
+++ b/noncore/tools/remote/learntab.cpp
@@ -19,8 +19,173 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19LearnTab::LearnTab(QWidget *parent, const char *name):QWidget(parent,name) 19LearnTab::LearnTab(QWidget *parent, const char *name):QWidget(parent,name)
20{ 20{
21 QVBoxLayout *layout = new QVBoxLayout(this); 21 QVBoxLayout *layout = new QVBoxLayout(this);
22 QString *string = new QString("<qt><h1>Opie-Remote Usage Instructions</h1><p>First, some definitions. A Remote is a remote entry in an lircd.conf file, it represents one remote you want to emulate. A Remote Layout is one entry in your ~/Settings/Remote.conf file. It represents the buttons that you see on your screen. Each button on a Remote Layout can be mapped to any button in a Remote. This way you can have, for example, a vcr remote layout, in which all the play/pause/etc buttons are mapped to the buttons on your vcr's remote. However, most VCR's don't have volume controls, so the volume buttons can be mapped to the volume buttons on your TV.</p><p>The first things you need the lirc and lirc-modules ipkgs. If you installed this from an ipkg, they should already be there, thanks to the wonderful world of dependencies. If not, get them. The next thing you need is an lircd.conf file. you can get these at <a href=http://www.lirc.org/>http://www.lirc.org/</a>. Read the documentation there to figure out how to make your own, if one for your remote doesn't exist, or how to have multiple remotes in one lircd.conf file. Once you have a good lircd.conf file, put it in /etc, kill the lircd daemon (if its running) and do a modprobe lirc_sir. Then, run lircd again.</p><p>The next thing you want to do is to create a remote layout. Go to the config tab, and enter a name for your remote layout in the pulldown menu. Dont use the name Remotes, as that could confuse the app. Hopefully, that will be fixed soon. after entering the name you want to use, press New, and then select the name again from the pulldown menu (another oddity that i hope to fix). Then, press each button that you want to map, and a dialog should appear. Select the remote and button that you want to use, and click OK. Once you are done, go to the Remote tab, and select the new remote from the dropdown menu. It should works fine. If at any time you want to change a remote layout, go to the Config tab, select the layout from the dropdown menu, and change the buttons you want to change.</p><p>This is program is written and maintaned by Thomas (spiralman) Stephens. <a href=mailto:spiralman@softhome.net>spiralman@softhome.net</a>. Or, look for me on #opie or #handhelds.org on irc.openprojects.net.</p></qt>"); 22 QHBoxLayout *bottomLayout = new QHBoxLayout(this);
23 23
24 QTextView *textView = new QTextView(*string, 0, this); 24 layout->insertSpacing(0,5);
25 layout->addWidget(textView); 25 remotesBox = new QListBox(this, "remotesBox");
26 layout->insertWidget(0, remotesBox, 1);
27 remotesBox->insertStringList(getRemotes());
28
29 layout->insertSpacing(-1,5);
30 layout->insertLayout(-1, bottomLayout);
31 layout->insertSpacing(-1,5);
32
33 QPushButton *add = new QPushButton("Add", this, "add");
34 bottomLayout->insertSpacing(-1, 5);
35 bottomLayout->insertWidget(-1, add);
36 bottomLayout->insertSpacing(-1, 5);
37 QPushButton *edit = new QPushButton("Edit", this, "edit");
38 bottomLayout->insertWidget(-1, edit);
39 bottomLayout->insertSpacing(-1, 5);
40 QPushButton *del = new QPushButton("Delete", this, "delete");
41 bottomLayout->insertWidget(-1, del);
42 bottomLayout->insertSpacing(-1, 5);
43
44 connect(add, SIGNAL(clicked()), this, SLOT(add()) );
45 connect(edit, SIGNAL(clicked()), this, SLOT(edit()) );
46 connect(del, SIGNAL(clicked()), this, SLOT(del()) );
26} 47}
48
49void LearnTab::add()
50{
51 printf("LearnTab::add: add pressed\n");
52 RecordDialog *dialog = new RecordDialog(this);
53 dialog->showMaximized();
54}
55
56void LearnTab::edit()
57{
58}
59
60void LearnTab::del()
61{
62}
63
64QStringList LearnTab::getRemotes()
65{
66 const char write_buffer[] = "LIST\n";
67 const char *readbuffer;
68 int i, numlines;
69 QStringList list;
70
71 addr.sun_family=AF_UNIX;
72 strcpy(addr.sun_path,"/dev/lircd");
73
74 fd = socket(AF_UNIX, SOCK_STREAM, 0);
75 if(fd == -1)
76 {
77 QMessageBox *mb = new QMessageBox("Error!",
78 "couldnt connect to socket",
79 QMessageBox::NoIcon,
80 QMessageBox::Ok,
81 QMessageBox::NoButton,
82 QMessageBox::NoButton);
83 mb->exec();
84 perror("ButtonDialog::GetRemotes");
85 return NULL;
86 }
87
88 if(::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1)
89 {
90 QMessageBox *mb = new QMessageBox("Error!",
91 "couldnt connect to socket",
92 QMessageBox::NoIcon,
93 QMessageBox::Ok,
94 QMessageBox::NoButton,
95 QMessageBox::NoButton);
96 mb->exec();
97 perror("ButtonDialog::GetRemotes");
98 return NULL;
99 }
100
101 write(fd, write_buffer, strlen(write_buffer));
102
103 for(i=0; i<5; i++)
104 {
105 printf("%d\n", i);
106 readbuffer = readPacket();
107 printf("%s", readbuffer);
108 printf("%d\n", i);
109 }
110
111 numlines = atoi(readbuffer);
112
113 for(i=0; i<numlines; i++)
114 {
115 list+=readPacket();
116 }
117
118 if(strcasecmp(readPacket(), "END") != 0)
119 {
120 QMessageBox *mb = new QMessageBox("Error!",
121 "bad packet",
122 QMessageBox::NoIcon,
123 QMessageBox::Ok,
124 QMessageBox::NoButton,
125 QMessageBox::NoButton);
126 mb->exec();
127 perror("ButtonDialog::GetRemotes");
128 return NULL;
129 }
130
131 ::close(fd);
132 return list;
133}
134
135//this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html
136const char *LearnTab::readPacket()
137{
138 static char buffer[PACKET_SIZE+1]="";
139 char *end;
140 static int ptr=0,end_len=0;
141 ssize_t ret;
142 timeout = 0;
143
144 if(ptr>0)
145 {
146 memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1);
147 ptr=strlen(buffer);
148 end=strchr(buffer,'\n');
149 }
150 else
151 {
152 end=NULL;
153 }
154 alarm(TIMEOUT);
155 while(end==NULL)
156 {
157 if(PACKET_SIZE<=ptr)
158 {
159 fprintf(stderr,"bad packet\n");
160 ptr=0;
161 return(NULL);
162 }
163 ret=read(fd,buffer+ptr,PACKET_SIZE-ptr);
164
165 if(ret<=0 || timeout)
166 {
167 if(timeout)
168 {
169 fprintf(stderr,"timeout\n");
170 }
171 else
172 {
173 alarm(0);
174 }
175 ptr=0;
176 return(NULL);
177 }
178 buffer[ptr+ret]=0;
179 ptr=strlen(buffer);
180 end=strchr(buffer,'\n');
181 }
182 alarm(0);timeout=0;
183
184 end[0]=0;
185 ptr=strlen(buffer)+1;
186//# ifdef DEBUG
187 //printf("buffer: -%s-\n",buffer);
188//# endif
189 return(buffer);
190}
191