summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-07-02 17:11:46 (UTC)
committer llornkcor <llornkcor>2002-07-02 17:11:46 (UTC)
commitc418781fac36feb2f392e0642ed50065bb4ef99c (patch) (unidiff)
tree1a841245d0fc5e2b09231b73378e220947db9410
parent78172d2d23543992605e273770692b5a0a84ed32 (diff)
downloadopie-c418781fac36feb2f392e0642ed50065bb4ef99c.zip
opie-c418781fac36feb2f392e0642ed50065bb4ef99c.tar.gz
opie-c418781fac36feb2f392e0642ed50065bb4ef99c.tar.bz2
changed default icon action from hold to tap to record
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/vmemo/vmemo.cpp58
-rw-r--r--core/applets/vmemo/vmemo.h2
2 files changed, 34 insertions, 26 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp
index cb3e45e..2c3edf1 100644
--- a/core/applets/vmemo/vmemo.cpp
+++ b/core/applets/vmemo/vmemo.cpp
@@ -1,643 +1,651 @@
1/************************************************************************************ 1/************************************************************************************
2 ** 2 **
3 ** This file may be distributed and/or modified under the terms of the 3 ** This file may be distributed and/or modified under the terms of the
4 ** GNU General Public License version 2 as published by the Free Software 4 ** GNU General Public License version 2 as published by the Free Software
5 ** Foundation and appearing in the file LICENSE.GPL included in the 5 ** Foundation and appearing in the file LICENSE.GPL included in the
6 ** packaging of this file. 6 ** packaging of this file.
7 ** 7 **
8 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 8 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
9 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 9 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
10 ** 10 **
11 ************************************************************************************/ 11 ************************************************************************************/
12// copyright 2002 Jeremy Cowgar <jc@cowgar.com> 12// copyright 2002 Jeremy Cowgar <jc@cowgar.com>
13/* 13/*
14 * $Id$ 14 * $Id$
15 */ 15 */
16// Sun 03-17-2002 L.J.Potter <ljp@llornkcor.com> 16// Sun 03-17-2002 L.J.Potter <ljp@llornkcor.com>
17#include <sys/utsname.h> 17#include <sys/utsname.h>
18#include <sys/time.h> 18#include <sys/time.h>
19#include <sys/types.h> 19#include <sys/types.h>
20#include <unistd.h> 20#include <unistd.h>
21#include <stdio.h> 21#include <stdio.h>
22#include <sys/stat.h> 22#include <sys/stat.h>
23#include <fcntl.h> 23#include <fcntl.h>
24#include <sys/ioctl.h> 24#include <sys/ioctl.h>
25#include <linux/soundcard.h> 25#include <linux/soundcard.h>
26 26
27#include <string.h> 27#include <string.h>
28#include <stdlib.h> 28#include <stdlib.h>
29#include <errno.h> 29#include <errno.h>
30#include <qtimer.h> 30#include <qtimer.h>
31 31
32typedef struct _waveheader { 32typedef struct _waveheader {
33 u_long main_chunk; /* 'RIFF' */ 33 u_long main_chunk; /* 'RIFF' */
34 u_long length; /* filelen */ 34 u_long length; /* filelen */
35 u_long chunk_type; /* 'WAVE' */ 35 u_long chunk_type; /* 'WAVE' */
36 u_long sub_chunk; /* 'fmt ' */ 36 u_long sub_chunk; /* 'fmt ' */
37 u_long sc_len; /* length of sub_chunk, =16 37 u_long sc_len; /* length of sub_chunk, =16
38 (chunckSize) format len */ 38 (chunckSize) format len */
39 u_short format; /* should be 1 for PCM-code (formatTag) */ 39 u_short format; /* should be 1 for PCM-code (formatTag) */
40 40
41 u_short modus; /* 1 Mono, 2 Stereo (channels) */ 41 u_short modus; /* 1 Mono, 2 Stereo (channels) */
42 u_long sample_fq; /* samples per second (samplesPerSecond) */ 42 u_long sample_fq; /* samples per second (samplesPerSecond) */
43 u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ 43 u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */
44 u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ 44 u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */
45 u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ 45 u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */
46 46
47 u_long data_chunk; /* 'data' */ 47 u_long data_chunk; /* 'data' */
48 48
49 u_long data_length;/* samplecount */ 49 u_long data_length;/* samplecount */
50} WaveHeader; 50} WaveHeader;
51 51
52#define RIFF 0x46464952 52#define RIFF 0x46464952
53#define WAVE 0x45564157 53#define WAVE 0x45564157
54#define FMT 0x20746D66 54#define FMT 0x20746D66
55#define DATA 0x61746164 55#define DATA 0x61746164
56#define PCM_CODE 1 56#define PCM_CODE 1
57#define WAVE_MONO 1 57#define WAVE_MONO 1
58#define WAVE_STEREO 2 58#define WAVE_STEREO 2
59 59
60#include "vmemo.h" 60#include "vmemo.h"
61 61
62#include <qpe/qpeapplication.h> 62#include <qpe/qpeapplication.h>
63#include <qpe/resource.h> 63#include <qpe/resource.h>
64#include <qpe/config.h> 64#include <qpe/config.h>
65 65
66#include <qpainter.h> 66#include <qpainter.h>
67#include <qdatetime.h> 67#include <qdatetime.h>
68#include <qregexp.h> 68#include <qregexp.h>
69#include <qsound.h> 69#include <qsound.h>
70#include <qfile.h> 70#include <qfile.h>
71#include <qmessagebox.h> 71#include <qmessagebox.h>
72 72
73int seq = 0; 73int seq = 0;
74 74
75/* XPM */ 75/* XPM */
76static char * vmemo_xpm[] = { 76static char * vmemo_xpm[] = {
77 "16 16 102 2", 77 "16 16 102 2",
78 " c None", 78 " c None",
79 ". c #60636A", 79 ". c #60636A",
80 "+ c #6E6E72", 80 "+ c #6E6E72",
81 "@ c #68696E", 81 "@ c #68696E",
82 "# c #4D525C", 82 "# c #4D525C",
83 "$ c #6B6C70", 83 "$ c #6B6C70",
84 "% c #E3E3E8", 84 "% c #E3E3E8",
85 "& c #EEEEF2", 85 "& c #EEEEF2",
86 "* c #EAEAEF", 86 "* c #EAEAEF",
87 "= c #CACAD0", 87 "= c #CACAD0",
88 "- c #474A51", 88 "- c #474A51",
89 "; c #171819", 89 "; c #171819",
90 "> c #9B9B9F", 90 "> c #9B9B9F",
91 ", c #EBEBF0", 91 ", c #EBEBF0",
92 "' c #F4F4F7", 92 "' c #F4F4F7",
93 ") c #F1F1F5", 93 ") c #F1F1F5",
94 "! c #DEDEE4", 94 "! c #DEDEE4",
95 "~ c #57575C", 95 "~ c #57575C",
96 "{ c #010101", 96 "{ c #010101",
97 "] c #A2A2A6", 97 "] c #A2A2A6",
98 "^ c #747477", 98 "^ c #747477",
99 "/ c #B5B5B8", 99 "/ c #B5B5B8",
100 "( c #AEAEB2", 100 "( c #AEAEB2",
101 "_ c #69696D", 101 "_ c #69696D",
102 ": c #525256", 102 ": c #525256",
103 "< c #181C24", 103 "< c #181C24",
104 "[ c #97979B", 104 "[ c #97979B",
105 "} c #A7A7AC", 105 "} c #A7A7AC",
106 "| c #B0B0B4", 106 "| c #B0B0B4",
107 "1 c #C8C8D1", 107 "1 c #C8C8D1",
108 "2 c #75757B", 108 "2 c #75757B",
109 "3 c #46464A", 109 "3 c #46464A",
110 "4 c #494A4F", 110 "4 c #494A4F",
111 "5 c #323234", 111 "5 c #323234",
112 "6 c #909095", 112 "6 c #909095",
113 "7 c #39393B", 113 "7 c #39393B",
114 "8 c #757578", 114 "8 c #757578",
115 "9 c #87878E", 115 "9 c #87878E",
116 "0 c #222224", 116 "0 c #222224",
117 "a c #414144", 117 "a c #414144",
118 "b c #6A6A6E", 118 "b c #6A6A6E",
119 "c c #020C16", 119 "c c #020C16",
120 "d c #6B6B6F", 120 "d c #6B6B6F",
121 "e c #68686D", 121 "e c #68686D",
122 "f c #5B5B60", 122 "f c #5B5B60",
123 "g c #8A8A8F", 123 "g c #8A8A8F",
124 "h c #6B6B6E", 124 "h c #6B6B6E",
125 "i c #ADADB2", 125 "i c #ADADB2",
126 "j c #828289", 126 "j c #828289",
127 "k c #3E3E41", 127 "k c #3E3E41",
128 "l c #CFCFD7", 128 "l c #CFCFD7",
129 "m c #4C4C50", 129 "m c #4C4C50",
130 "n c #000000", 130 "n c #000000",
131 "o c #66666A", 131 "o c #66666A",
132 "p c #505054", 132 "p c #505054",
133 "q c #838388", 133 "q c #838388",
134 "r c #A1A1A7", 134 "r c #A1A1A7",
135 "s c #A9A9AE", 135 "s c #A9A9AE",
136 "t c #A8A8B0", 136 "t c #A8A8B0",
137 "u c #5E5E63", 137 "u c #5E5E63",
138 "v c #3A3A3E", 138 "v c #3A3A3E",
139 "w c #BDBDC6", 139 "w c #BDBDC6",
140 "x c #59595E", 140 "x c #59595E",
141 "y c #76767C", 141 "y c #76767C",
142 "z c #373738", 142 "z c #373738",
143 "A c #717174", 143 "A c #717174",
144 "B c #727278", 144 "B c #727278",
145 "C c #1C1C1E", 145 "C c #1C1C1E",
146 "D c #3C3C3F", 146 "D c #3C3C3F",
147 "E c #ADADB6", 147 "E c #ADADB6",
148 "F c #54555A", 148 "F c #54555A",
149 "G c #8B8C94", 149 "G c #8B8C94",
150 "H c #5A5A5F", 150 "H c #5A5A5F",
151 "I c #BBBBC3", 151 "I c #BBBBC3",
152 "J c #C4C4CB", 152 "J c #C4C4CB",
153 "K c #909098", 153 "K c #909098",
154 "L c #737379", 154 "L c #737379",
155 "M c #343437", 155 "M c #343437",
156 "N c #8F8F98", 156 "N c #8F8F98",
157 "O c #000407", 157 "O c #000407",
158 "P c #2D3137", 158 "P c #2D3137",
159 "Q c #B0B1BC", 159 "Q c #B0B1BC",
160 "R c #3B3C40", 160 "R c #3B3C40",
161 "S c #6E6E74", 161 "S c #6E6E74",
162 "T c #95959C", 162 "T c #95959C",
163 "U c #74747A", 163 "U c #74747A",
164 "V c #1D1D1E", 164 "V c #1D1D1E",
165 "W c #91929A", 165 "W c #91929A",
166 "X c #42444A", 166 "X c #42444A",
167 "Y c #22282E", 167 "Y c #22282E",
168 "Z c #B0B2BC", 168 "Z c #B0B2BC",
169 "` c #898A90", 169 "` c #898A90",
170 " . c #65656A", 170 " . c #65656A",
171 ".. c #999AA2", 171 ".. c #999AA2",
172 "+. c #52535A", 172 "+. c #52535A",
173 "@. c #151B21", 173 "@. c #151B21",
174 "#. c #515257", 174 "#. c #515257",
175 "$. c #B5B5BE", 175 "$. c #B5B5BE",
176 "%. c #616167", 176 "%. c #616167",
177 "&. c #1A1D22", 177 "&. c #1A1D22",
178 "*. c #000713", 178 "*. c #000713",
179 "=. c #1F1F21", 179 "=. c #1F1F21",
180 " ", 180 " ",
181 " . + @ # ", 181 " . + @ # ",
182 " $ % & * = - ", 182 " $ % & * = - ",
183 " ; > , ' ) ! ~ ", 183 " ; > , ' ) ! ~ ",
184 " { ] ^ / ( _ : ", 184 " { ] ^ / ( _ : ",
185 " < [ } | 1 2 3 ", 185 " < [ } | 1 2 3 ",
186 " 4 5 6 7 8 9 0 a b c ", 186 " 4 5 6 7 8 9 0 a b c ",
187 " d e f g h i j 3 k l m n ", 187 " d e f g h i j 3 k l m n ",
188 " o p q r s t u v w n ", 188 " o p q r s t u v w n ",
189 " o x y z A B C D E n ", 189 " o x y z A B C D E n ",
190 " F G H I J K L M N O ", 190 " F G H I J K L M N O ",
191 " P Q R S T U V W X ", 191 " P Q R S T U V W X ",
192 " Y Z ` b ...+. ", 192 " Y Z ` b ...+. ",
193 " @.#.$.%.&. ", 193 " @.#.$.%.&. ",
194 " *.B =. ", 194 " *.B =. ",
195 " n n n n n n n n n "}; 195 " n n n n n n n n n "};
196 196
197 197
198VMemo::VMemo( QWidget *parent, const char *_name ) 198VMemo::VMemo( QWidget *parent, const char *_name )
199 : QWidget( parent, _name ) 199 : QWidget( parent, _name )
200{ 200{
201 setFixedHeight( 18 ); 201 setFixedHeight( 18 );
202 setFixedWidth( 14 ); 202 setFixedWidth( 14 );
203 203
204 recording = FALSE; 204 recording = FALSE;
205 205
206 t_timer = new QTimer( this ); 206 t_timer = new QTimer( this );
207 connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) ); 207 connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) );
208 208
209 struct utsname name; /* check for embedix kernel running on the zaurus*/ 209 struct utsname name; /* check for embedix kernel running on the zaurus*/
210 if (uname(&name) != -1) { 210 if (uname(&name) != -1) {
211 QString release=name.release; 211 QString release=name.release;
212 212
213 Config vmCfg("Vmemo"); 213 Config vmCfg("Vmemo");
214 vmCfg.setGroup("Defaults"); 214 vmCfg.setGroup("Defaults");
215 int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); 215 int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1));
216 216
217 qDebug("toggleKey %d", toggleKey); 217 qDebug("toggleKey %d", toggleKey);
218 218
219 if(release.find("embedix",0,TRUE) !=-1) 219 if(release.find("embedix",0,TRUE) !=-1)
220 systemZaurus=TRUE; 220 systemZaurus=TRUE;
221 else 221 else
222 systemZaurus=FALSE; 222 systemZaurus=FALSE;
223 223
224 myChannel = new QCopChannel( "QPE/VMemo", this ); 224 myChannel = new QCopChannel( "QPE/VMemo", this );
225 connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), 225 connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)),
226 this, SLOT(receive(const QCString&, const QByteArray&)) ); 226 this, SLOT(receive(const QCString&, const QByteArray&)) );
227 227
228 if( toggleKey != -1 ) { 228 if( toggleKey != -1 ) {
229 // QPEApplication::grabKeyboard(); 229 // QPEApplication::grabKeyboard();
230 QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); 230 QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)");
231 // e << 4096; // Key_Escape 231 // e << 4096; // Key_Escape
232 // e << Key_F5; //4148 232 // e << Key_F5; //4148
233 e << toggleKey; 233 e << toggleKey;
234 e << QString("QPE/VMemo"); 234 e << QString("QPE/VMemo");
235 e << QString("toggleRecord()"); 235 e << QString("toggleRecord()");
236 } 236 }
237 237 if(toggleKey == 1)
238 usingIcon=TRUE;
239 else
240 usingIcon=FALSE;
238 if( vmCfg.readNumEntry("hideIcon",0) == 1) 241 if( vmCfg.readNumEntry("hideIcon",0) == 1)
239 hide(); 242 hide();
240 } 243 }
241} 244}
242 245
243VMemo::~VMemo() 246VMemo::~VMemo()
244{ 247{
245} 248}
246 249
247void VMemo::receive( const QCString &msg, const QByteArray &data ) 250void VMemo::receive( const QCString &msg, const QByteArray &data )
248{ 251{
249 qDebug("receive"); 252 qDebug("receive");
250 QDataStream stream( data, IO_ReadOnly ); 253 QDataStream stream( data, IO_ReadOnly );
251 if (msg == "toggleRecord()") { 254 if (msg == "toggleRecord()") {
252 if (recording) { 255 if (recording) {
253 fromToggle = TRUE; 256 fromToggle = TRUE;
254 stopRecording(); 257 stopRecording();
255 } else { 258 } else {
256 fromToggle = TRUE; 259 fromToggle = TRUE;
257 startRecording(); 260 startRecording();
258 } 261 }
259 } 262 }
260} 263}
261 264
262void VMemo::paintEvent( QPaintEvent* ) 265void VMemo::paintEvent( QPaintEvent* )
263{ 266{
264 QPainter p(this); 267 QPainter p(this);
265 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); 268 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm );
266} 269}
267 270
268void VMemo::mousePressEvent( QMouseEvent * ) 271void VMemo::mousePressEvent( QMouseEvent * )
269{ 272{
270 startRecording(); 273 if(!recording)
274 startRecording();
275 else
276 stopRecording();
271} 277}
272 278
273void VMemo::mouseReleaseEvent( QMouseEvent * ) 279void VMemo::mouseReleaseEvent( QMouseEvent * )
274{ 280{
275 stopRecording(); 281// if(usingIcon && !recording)
282// stopRecording();
276} 283}
277 284
278bool VMemo::startRecording() { 285bool VMemo::startRecording() {
279 286
280 if ( recording) 287 if ( recording)
281 return FALSE; 288 return FALSE;
282 289
283 Config config( "Vmemo" ); 290 Config config( "Vmemo" );
284 config.setGroup( "System" ); 291 config.setGroup( "System" );
285 292
286 useAlerts = config.readBoolEntry("Alert",1); 293 useAlerts = config.readBoolEntry("Alert",1);
287 if(useAlerts) { 294 if(useAlerts) {
288 295
289 msgLabel = new QLabel( 0, "alertLabel" ); 296 msgLabel = new QLabel( 0, "alertLabel" );
290 msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); 297 msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>");
291 msgLabel->show(); 298 msgLabel->show();
292 } 299 }
293 300
294 // if(useAlerts) 301 // if(useAlerts)
295 // QMessageBox::message("VMemo","Really Record?");//) ==1) 302 // QMessageBox::message("VMemo","Really Record?");//) ==1)
296 // return; 303 // return;
297 // } else { 304 // } else {
298 // if (!systemZaurus ) 305 // if (!systemZaurus )
299 // QSound::play(Resource::findSound("vmemob")); 306 // QSound::play(Resource::findSound("vmemob"));
300 // } 307 // }
301 qDebug("Start recording engines"); 308 qDebug("Start recording engines");
302 recording = TRUE; 309 recording = TRUE;
303 310
304 if (openDSP() == -1) { 311 if (openDSP() == -1) {
305 // QMessageBox::critical(0, "vmemo", "Could not open dsp device.\n"+errorMsg, "Abort"); 312 // QMessageBox::critical(0, "vmemo", "Could not open dsp device.\n"+errorMsg, "Abort");
306 // delete msgLabel; 313 // delete msgLabel;
307 recording = FALSE; 314 recording = FALSE;
308 msgLabel=0; 315 msgLabel=0;
309 delete msgLabel; 316 delete msgLabel;
310 317
311 return FALSE; 318 return FALSE;
312 } 319 }
313 320
314 config.setGroup("Defaults"); 321 config.setGroup("Defaults");
315 322
316 QDateTime dt = QDateTime::currentDateTime(); 323 QDateTime dt = QDateTime::currentDateTime();
317 324
318 QString fName; 325 QString fName;
319 config.setGroup( "System" ); 326 config.setGroup( "System" );
320 fName = QPEApplication::documentDir() ; 327 fName = QPEApplication::documentDir() ;
321 fileName = config.readEntry("RecLocation", fName); 328 fileName = config.readEntry("RecLocation", fName);
322 329
323 int s; 330 int s;
324 s=fileName.find(':'); 331 s=fileName.find(':');
325 if(s) 332 if(s)
326 fileName=fileName.right(fileName.length()-s-2); 333 fileName=fileName.right(fileName.length()-s-2);
327 qDebug("pathname will be "+fileName); 334 qDebug("pathname will be "+fileName);
328 335
329 if( fileName.left(1).find('/') == -1) 336 if( fileName.left(1).find('/') == -1)
330 fileName="/"+fileName; 337 fileName="/"+fileName;
331 if( fileName.right(1).find('/') == -1) 338 if( fileName.right(1).find('/') == -1)
332 fileName+="/"; 339 fileName+="/";
333 fName = "vm_"+ dt.toString()+ ".wav"; 340 fName = "vm_"+ dt.toString()+ ".wav";
334 341
335 fileName+=fName; 342 fileName+=fName;
336 qDebug("filename is "+fileName); 343 qDebug("filename is "+fileName);
337 // No spaces in the filename 344 // No spaces in the filename
338 fileName.replace(QRegExp("'"),""); 345 fileName.replace(QRegExp("'"),"");
339 fileName.replace(QRegExp(" "),"_"); 346 fileName.replace(QRegExp(" "),"_");
340 fileName.replace(QRegExp(":"),"."); 347 fileName.replace(QRegExp(":"),".");
341 fileName.replace(QRegExp(","),""); 348 fileName.replace(QRegExp(","),"");
342 349
343 if(openWAV(fileName.latin1()) == -1) { 350 if(openWAV(fileName.latin1()) == -1) {
344 // QString err("Could not open the output file\n"); 351 // QString err("Could not open the output file\n");
345 // err += fileName; 352 // err += fileName;
346 // QMessageBox::critical(0, "vmemo", err, "Abort"); 353 // QMessageBox::critical(0, "vmemo", err, "Abort");
347 close(dsp); 354 close(dsp);
348 return FALSE; 355 return FALSE;
349 } 356 }
350 357
351 QArray<int> cats(1); 358 QArray<int> cats(1);
352 cats[0] = config.readNumEntry("Category", 0); 359 cats[0] = config.readNumEntry("Category", 0);
353 360
354 QString dlName("vm_"); 361 QString dlName("vm_");
355 dlName += dt.toString(); 362 dlName += dt.toString();
356 DocLnk l; 363 DocLnk l;
357 l.setFile(fileName); 364 l.setFile(fileName);
358 l.setName(dlName); 365 l.setName(dlName);
359 l.setType("audio/x-wav"); 366 l.setType("audio/x-wav");
360 l.setCategories(cats); 367 l.setCategories(cats);
361 l.writeLink(); 368 l.writeLink();
362
363 369
364 record(); 370 record();
365 // delete msgLabel; 371
366 return TRUE; 372 return TRUE;
367} 373}
368 374
369void VMemo::stopRecording() { 375void VMemo::stopRecording() {
370show(); 376 show();
371 qDebug("Stopped recording"); 377 qDebug("Stopped recording");
372 recording = FALSE; 378 recording = FALSE;
373 if(useAlerts) 379 if(useAlerts) {
374 if( msgLabel) delete msgLabel; 380 msgLabel->close();
375 t_timer->stop(); 381 msgLabel=0;
376 Config cfg("Vmemo"); 382 delete msgLabel;
377 cfg.setGroup("Defaults"); 383 }
384 t_timer->stop();
385 Config cfg("Vmemo");
386 cfg.setGroup("Defaults");
378 if( cfg.readNumEntry("hideIcon",0) == 1 ) 387 if( cfg.readNumEntry("hideIcon",0) == 1 )
379 hide(); 388 hide();
380} 389}
381 390
382int VMemo::openDSP() 391int VMemo::openDSP()
383{ 392{
384 Config cfg("Vmemo"); 393 Config cfg("Vmemo");
385 cfg.setGroup("Record"); 394 cfg.setGroup("Record");
386 395
387 speed = cfg.readNumEntry("SampleRate", 22050); 396 speed = cfg.readNumEntry("SampleRate", 22050);
388 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) 397 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1)
389 if (cfg.readNumEntry("SixteenBit", 1)==1) { 398 if (cfg.readNumEntry("SixteenBit", 1)==1) {
390 format = AFMT_S16_LE; 399 format = AFMT_S16_LE;
391 resolution = 16; 400 resolution = 16;
392 } else { 401 } else {
393 format = AFMT_U8; 402 format = AFMT_U8;
394 resolution = 8; 403 resolution = 8;
395 } 404 }
396 405
397 qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); 406 qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution);
398 407
399 if(systemZaurus) { 408 if(systemZaurus) {
400 dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 409 dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1
401 channels=1; //zaurus has one input channel 410 channels=1; //zaurus has one input channel
402 } else { 411 } else {
403 dsp = open("/dev/dsp", O_RDONLY); 412 dsp = open("/dev/dsp", O_RDONLY);
404 } 413 }
405 414
406 if(dsp == -1) { 415 if(dsp == -1) {
407 perror("open(\"/dev/dsp\")"); 416 perror("open(\"/dev/dsp\")");
408 errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); 417 errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno);
409 QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); 418 QMessageBox::critical(0, "vmemo", errorMsg, "Abort");
410 return -1; 419 return -1;
411 } 420 }
412 421
413 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { 422 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) {
414 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 423 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
415 return -1; 424 return -1;
416 } 425 }
417 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { 426 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) {
418 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 427 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
419 return -1; 428 return -1;
420 } 429 }
421 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { 430 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) {
422 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 431 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
423 return -1; 432 return -1;
424 } 433 }
425 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { 434 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) {
426 perror("ioctl(\"SOUND_PCM_READ_RATE\")"); 435 perror("ioctl(\"SOUND_PCM_READ_RATE\")");
427 return -1; 436 return -1;
428 } 437 }
429 438
430 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute 439 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute
431 440
432 return 1; 441 return 1;
433} 442}
434 443
435int VMemo::openWAV(const char *filename) 444int VMemo::openWAV(const char *filename)
436{ 445{
437 track.setName(filename); 446 track.setName(filename);
438 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { 447 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) {
439 errorMsg=filename; 448 errorMsg=filename;
440 return -1; 449 return -1;
441 } 450 }
442 451
443 wav=track.handle(); 452 wav=track.handle();
444 453
445 WaveHeader wh; 454 WaveHeader wh;
446 455
447 wh.main_chunk = RIFF; 456 wh.main_chunk = RIFF;
448 wh.length=0; 457 wh.length=0;
449 wh.chunk_type = WAVE; 458 wh.chunk_type = WAVE;
450 wh.sub_chunk = FMT; 459 wh.sub_chunk = FMT;
451 wh.sc_len = 16; 460 wh.sc_len = 16;
452 wh.format = PCM_CODE; 461 wh.format = PCM_CODE;
453 wh.modus = channels; 462 wh.modus = channels;
454 wh.sample_fq = speed; 463 wh.sample_fq = speed;
455 wh.byte_p_sec = speed * channels * resolution/8; 464 wh.byte_p_sec = speed * channels * resolution/8;
456 wh.byte_p_spl = channels * (resolution / 8); 465 wh.byte_p_spl = channels * (resolution / 8);
457 wh.bit_p_spl = resolution; 466 wh.bit_p_spl = resolution;
458 wh.data_chunk = DATA; 467 wh.data_chunk = DATA;
459 wh.data_length= 0; 468 wh.data_length= 0;
460 // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" 469 // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d"
461 // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); 470 // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl );
462 write (wav, &wh, sizeof(WaveHeader)); 471 write (wav, &wh, sizeof(WaveHeader));
463 472
464 return 1; 473 return 1;
465} 474}
466 475
467void VMemo::record(void) 476void VMemo::record(void)
468{ 477{
469 int length=0, result, value; 478 int length=0, result, value;
470 QString msg; 479 QString msg;
471 msg.sprintf("Recording format %d", format); 480 msg.sprintf("Recording format %d", format);
472 qDebug(msg); 481 qDebug(msg);
473 Config config("Vmemo"); 482 Config config("Vmemo");
474 config.setGroup("Record"); 483 config.setGroup("Record");
475 int sRate=config.readNumEntry("SizeLimit", 30); 484 int sRate=config.readNumEntry("SizeLimit", 30);
476 485
477 t_timer->start( sRate * 1000+1000, TRUE); 486 t_timer->start( sRate * 1000+1000, TRUE);
478 487
479 if(systemZaurus) { 488 if(systemZaurus) {
480 489
481 msg.sprintf("Recording format zaurus"); 490 msg.sprintf("Recording format zaurus");
482 qDebug(msg); 491 qDebug(msg);
483 signed short sound[512], monoBuffer[512]; 492 signed short sound[1024], monoBuffer[1024];
484 493
485 if(format==AFMT_S16_LE) { 494 if(format==AFMT_S16_LE) {
486 495
487 496
488 497
489 while(recording) { 498 while(recording) {
490 499
491 result = read(dsp, sound, 512); // 8192 500 result = read(dsp, sound, 1024); // 8192
492 // int j=0; 501 // int j=0;
493 502
494 for (int i = 0; i < result; i++) { //since Z is mono do normally 503 for (int i = 0; i < result; i++) { //since Z is mono do normally
495 monoBuffer[i] = sound[i]; 504 monoBuffer[i] = sound[i];
496 } 505 }
497 506
498 length+=write(wav, monoBuffer, result); 507 length+=write(wav, monoBuffer, result);
499 if(length<0) 508 if(length<0)
500 recording=false; 509 recording=false;
501 510 // for (int i = 0; i < result; i+=2) {
502 // for (int i = 0; i < result; i+=2) {
503 // monoBuffer[j] = sound[i]; 511 // monoBuffer[j] = sound[i];
504 // // monoBuffer[j] = (sound[i]+sound[i+1])/2; 512 // // monoBuffer[j] = (sound[i]+sound[i+1])/2;
505 513
506 // j++; 514 // j++;
507 // } 515 // }
508 qApp->processEvents(); 516 qApp->processEvents();
509 // printf("%d\r",length); 517 // printf("%d\r",length);
510 // fflush(stdout); 518 // fflush(stdout);
511 } 519 }
512 520
513 } else { //AFMT_U8 521 } else { //AFMT_U8
514 // 8bit unsigned 522 // 8bit unsigned
515 unsigned short sound[512], monoBuffer[512]; 523 unsigned short sound[1024], monoBuffer[1024];
516 while(recording) { 524 while(recording) {
517 result = read(dsp, sound, 512); // 8192 525 result = read(dsp, sound, 1024); // 8192
518 // int j=0; 526 // int j=0;
519 527
520 // if(systemZaurus) { 528 // if(systemZaurus) {
521 529
522 for (int i = 0; i < result; i++) { //since Z is mono do normally 530 for (int i = 0; i < result; i++) { //since Z is mono do normally
523 monoBuffer[i] = sound[i]; 531 monoBuffer[i] = sound[i];
524 } 532 }
525 533
526 length+=write(wav, monoBuffer, result); 534 length+=write(wav, monoBuffer, result);
527 535
528 // for (int i = 0; i < result; i+=2) { 536 // for (int i = 0; i < result; i+=2) {
529 // monoBuffer[j] = (sound[i]+sound[i+1])/2; 537 // monoBuffer[j] = (sound[i]+sound[i+1])/2;
530 // j++; 538 // j++;
531 // } 539 // }
532 // length+=write(wav, monoBuffer, result/2); 540 // length+=write(wav, monoBuffer, result/2);
533 length += result; 541 length += result;
534 // printf("%d\r",length); 542 // printf("%d\r",length);
535 // fflush(stdout); 543 // fflush(stdout);
536 } 544 }
537 545
538 qApp->processEvents(); 546 qApp->processEvents();
539 } 547 }
540 548
541 } else { // 16 bit only capabilities 549 } else { // 16 bit only capabilities
542 550
543 551
544 msg.sprintf("Recording format other"); 552 msg.sprintf("Recording format other");
545 qDebug(msg); 553 qDebug(msg);
546 554
547 signed short sound[512];//, monoBuffer[512]; 555 signed short sound[1024];//, monoBuffer[512];
548 556
549 while(recording) { 557 while(recording) {
550 558
551 result = read(dsp, sound, 512); // 8192 559 result = read(dsp, sound, 1024); // 8192
552 560
553 write(wav, sound, result); 561 write(wav, sound, result);
554 length += result; 562 length += result;
563
555 if(length<0) { 564 if(length<0) {
556 565
557 recording=false; 566 recording=false;
558 perror("dev/dsp's is a lookin' messy"); 567 perror("dev/dsp's is a lookin' messy");
559 QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); 568 QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName);
560 } 569 }
561 // printf("%d\r",length); 570 // printf("%d\r",length);
562 // fflush(stdout); 571 // fflush(stdout);
563 qApp->processEvents(); 572 qApp->processEvents();
564 } 573 }
565 // qDebug("file has length of %d lasting %d seconds", 574 // qDebug("file has length of %d lasting %d seconds",
566 // length, (( length / speed) / channels) / 2 ); 575 // length, (( length / speed) / channels) / 2 );
567 // medialplayer states wrong length in secs 576 // medialplayer states wrong length in secs
568 } 577 }
569 578
570 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// 579 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<//
571 580
572 value = length+36; 581 value = length+36;
573 582
574 lseek(wav, 4, SEEK_SET); 583 lseek(wav, 4, SEEK_SET);
575 write(wav, &value, 4); 584 write(wav, &value, 4);
576 lseek(wav, 40, SEEK_SET); 585 lseek(wav, 40, SEEK_SET);
577 586
578 write(wav, &length, 4); 587 write(wav, &length, 4);
579 588
580 track.close(); 589 track.close();
581 qDebug("Track closed"); 590 qDebug("Track closed");
582 591
583 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) 592 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1)
584 perror("ioctl(\"SNDCTL_DSP_RESET\")"); 593 perror("ioctl(\"SNDCTL_DSP_RESET\")");
585 594
586 ::close(dsp); 595 ::close(dsp);
587 fileName = fileName.left(fileName.length()-4); 596 fileName = fileName.left(fileName.length()-4);
588 // if(useAlerts) 597 // if(useAlerts)
589 // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); 598 // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName);
590 qDebug("done recording "+fileName); 599 qDebug("done recording "+fileName);
591 600
592 QSound::play(Resource::findSound("vmemoe")); 601// QSound::play(Resource::findSound("vmemoe"));
593 602
594 Config cfg("qpe"); 603 Config cfg("qpe");
595 cfg.setGroup("Volume"); 604 cfg.setGroup("Volume");
596 QString foo = cfg.readEntry("Mute","TRUE"); 605 QString foo = cfg.readEntry("Mute","TRUE");
597 if(foo.find("TRUE",0,TRUE) != -1) 606 if(foo.find("TRUE",0,TRUE) != -1)
598 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute 607 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute
599 608
600} 609}
601 610
602int VMemo::setToggleButton(int tog) { 611int VMemo::setToggleButton(int tog) {
603 612
604 for( int i=0; i < 10;i++) { 613 for( int i=0; i < 10;i++) {
605 switch (tog) { 614 switch (tog) {
606 case 0: 615 case 0:
607 return -1; 616 return -1;
608 break; 617 break;
609 case 1: 618 case 1:
610 return 0; 619 return 0;
611 break; 620 break;
612 case 2: 621 case 2:
613 return Key_Escape; 622 return Key_Escape;
614 break; 623 break;
615 case 3: 624 case 3:
616 return Key_Space; 625 return Key_Space;
617 break; 626 break;
618 case 4: 627 case 4:
619 return Key_F12; 628 return Key_F12;
620 break; 629 break;
621 case 5: 630 case 5:
622 return Key_F9; 631 return Key_F9;
623 break; 632 break;
624 case 6: 633 case 6:
625 return Key_F10; 634 return Key_F10;
626 break; 635 break;
627 case 7: 636 case 7:
628 return Key_F11; 637 return Key_F11;
629 break; 638 break;
630 case 8: 639 case 8:
631 return Key_F13; 640 return Key_F13;
632 break; 641 break;
633 }; 642 };
634 } 643 }
635 return -1; 644 return -1;
636} 645}
637 646
638void VMemo::timerBreak() { 647void VMemo::timerBreak() {
639 //stop 648 //stop
640 recording=false; 649 stopRecording();
641
642 QMessageBox::message("Vmemo","Vmemo recording has \ntimed out"); 650 QMessageBox::message("Vmemo","Vmemo recording has \ntimed out");
643} 651}
diff --git a/core/applets/vmemo/vmemo.h b/core/applets/vmemo/vmemo.h
index 51ace35..823c7b8 100644
--- a/core/applets/vmemo/vmemo.h
+++ b/core/applets/vmemo/vmemo.h
@@ -1,63 +1,63 @@
1/**************************************************************************************94x78** 1/**************************************************************************************94x78**
2** 2**
3** This file may be distributed and/or modified under the terms of the 3** This file may be distributed and/or modified under the terms of the
4** GNU General Public License version 2 as published by the Free Software 4** GNU General Public License version 2 as published by the Free Software
5** Foundation and appearing in the file LICENSE.GPL included in the 5** Foundation and appearing in the file LICENSE.GPL included in the
6** packaging of this file. 6** packaging of this file.
7** 7**
8** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 8** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
9** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 9** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
10** 10**
11*********************************************************************************************/ 11*********************************************************************************************/
12 12
13/* 13/*
14 * $Id$ 14 * $Id$
15 */ 15 */
16 16
17#ifndef __VMEMO_H__ 17#ifndef __VMEMO_H__
18#define __VMEMO_H__ 18#define __VMEMO_H__
19 19
20 20
21#include <qwidget.h> 21#include <qwidget.h>
22#include <qpixmap.h> 22#include <qpixmap.h>
23#include <qpe/applnk.h> 23#include <qpe/applnk.h>
24#include <qfile.h> 24#include <qfile.h>
25#include <qpe/qcopenvelope_qws.h> 25#include <qpe/qcopenvelope_qws.h>
26#include <qlabel.h> 26#include <qlabel.h>
27#include <qtimer.h> 27#include <qtimer.h>
28 28
29class VMemo : public QWidget 29class VMemo : public QWidget
30{ 30{
31 Q_OBJECT 31 Q_OBJECT
32public: 32public:
33 VMemo( QWidget *parent, const char *name = NULL); 33 VMemo( QWidget *parent, const char *name = NULL);
34 ~VMemo(); 34 ~VMemo();
35 QFile track; 35 QFile track;
36 QString fileName, errorMsg; 36 QString fileName, errorMsg;
37 QLabel* msgLabel; 37 QLabel* msgLabel;
38 QTimer *t_timer; 38 QTimer *t_timer;
39 39bool usingIcon;
40public slots: 40public slots:
41 void record(); 41 void record();
42 void mousePressEvent( QMouseEvent * ); 42 void mousePressEvent( QMouseEvent * );
43 void mouseReleaseEvent( QMouseEvent * ); 43 void mouseReleaseEvent( QMouseEvent * );
44 void receive( const QCString &msg, const QByteArray &data ); 44 void receive( const QCString &msg, const QByteArray &data );
45 bool startRecording(); 45 bool startRecording();
46 void stopRecording(); 46 void stopRecording();
47 void timerBreak(); 47 void timerBreak();
48private: 48private:
49 bool useAlerts; 49 bool useAlerts;
50 void paintEvent( QPaintEvent* ); 50 void paintEvent( QPaintEvent* );
51 int setToggleButton(int); 51 int setToggleButton(int);
52 int openDSP(); 52 int openDSP();
53 int openWAV(const char *filename); 53 int openWAV(const char *filename);
54 bool fromToggle; 54 bool fromToggle;
55 QPixmap vmemoPixmap; 55 QPixmap vmemoPixmap;
56 QCopChannel *myChannel; 56 QCopChannel *myChannel;
57 bool systemZaurus; 57 bool systemZaurus;
58 int dsp, wav, rate, speed, channels, format, resolution; 58 int dsp, wav, rate, speed, channels, format, resolution;
59 bool recording; 59 bool recording;
60}; 60};
61 61
62#endif // __VMEMO_H__ 62#endif // __VMEMO_H__
63 63