summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/vmemo/vmemo.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp
index 4c07b3a..226f058 100644
--- a/core/applets/vmemo/vmemo.cpp
+++ b/core/applets/vmemo/vmemo.cpp
@@ -264,99 +264,96 @@ void VMemo::receive( const QCString &msg, const QByteArray &data ) {
264 fromToggle = TRUE; 264 fromToggle = TRUE;
265 stopRecording(); 265 stopRecording();
266 } else { 266 } else {
267 fromToggle = TRUE; 267 fromToggle = TRUE;
268 startRecording(); 268 startRecording();
269 } 269 }
270 } 270 }
271} 271}
272 272
273void VMemo::paintEvent( QPaintEvent* ) { 273void VMemo::paintEvent( QPaintEvent* ) {
274 QPainter p(this); 274 QPainter p(this);
275 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); 275 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm );
276} 276}
277 277
278void VMemo::mousePressEvent( QMouseEvent * me) { 278void VMemo::mousePressEvent( QMouseEvent * me) {
279 /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions 279 /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions
280 mousePressEvent and mouseReleaseEvent with a NULL parameter. */ 280 mousePressEvent and mouseReleaseEvent with a NULL parameter. */
281 281
282// if (!systemZaurus && me != NULL) 282// if (!systemZaurus && me != NULL)
283// return; 283// return;
284// } 284// }
285 285
286 if(!recording) 286 if(!recording)
287 startRecording(); 287 startRecording();
288 else 288 else
289 stopRecording(); 289 stopRecording();
290} 290}
291 291
292void VMemo::mouseReleaseEvent( QMouseEvent * ) { 292void VMemo::mouseReleaseEvent( QMouseEvent * ) {
293} 293}
294 294
295bool VMemo::startRecording() { 295bool VMemo::startRecording() {
296 Config config( "Vmemo" ); 296 Config config( "Vmemo" );
297 config.setGroup( "System" ); 297 config.setGroup( "System" );
298 298
299 useAlerts = config.readBoolEntry("Alert",1); 299 useAlerts = config.readBoolEntry("Alert",1);
300 if(useAlerts) { 300 if(useAlerts) {
301 301
302 msgLabel = new QLabel( 0, "alertLabel" ); 302 msgLabel = new QLabel( 0, "alertLabel" );
303 msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); 303 msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>");
304 msgLabel->show(); 304 msgLabel->show();
305 } 305 }
306 306
307 qDebug("Start recording engines"); 307 qDebug("Start recording engines");
308 recording = TRUE; 308 recording = TRUE;
309 309
310 if (openDSP() == -1) { 310 if (openDSP() == -1) {
311 recording = FALSE; 311 recording = FALSE;
312 msgLabel=0;
313 delete msgLabel;
314
315 return FALSE; 312 return FALSE;
316 } 313 }
317 314
318 config.setGroup("Defaults"); 315 config.setGroup("Defaults");
319 316
320 QDateTime dt = QDateTime::currentDateTime(); 317 QDateTime dt = QDateTime::currentDateTime();
321 318
322 QString fName; 319 QString fName;
323 config.setGroup( "System" ); 320 config.setGroup( "System" );
324 fName = QPEApplication::documentDir() ; 321 fName = QPEApplication::documentDir() ;
325 fileName = config.readEntry("RecLocation", fName); 322 fileName = config.readEntry("RecLocation", fName);
326 323
327 int s; 324 int s;
328 s=fileName.find(':'); 325 s=fileName.find(':');
329 if(s) 326 if(s)
330 fileName=fileName.right(fileName.length()-s-2); 327 fileName=fileName.right(fileName.length()-s-2);
331 qDebug("pathname will be "+fileName); 328 qDebug("pathname will be "+fileName);
332 329
333 if( fileName.left(1).find('/') == -1) 330 if( fileName.left(1).find('/') == -1)
334 fileName="/"+fileName; 331 fileName="/"+fileName;
335 if( fileName.right(1).find('/') == -1) 332 if( fileName.right(1).find('/') == -1)
336 fileName+="/"; 333 fileName+="/";
337 fName = "vm_"+ dt.toString()+ ".wav"; 334 fName = "vm_"+ dt.toString()+ ".wav";
338 335
339 fileName+=fName; 336 fileName+=fName;
340 // No spaces in the filename 337 // No spaces in the filename
341 fileName.replace(QRegExp("'"),""); 338 fileName.replace(QRegExp("'"),"");
342 fileName.replace(QRegExp(" "),"_"); 339 fileName.replace(QRegExp(" "),"_");
343 fileName.replace(QRegExp(":"),"."); 340 fileName.replace(QRegExp(":"),".");
344 fileName.replace(QRegExp(","),""); 341 fileName.replace(QRegExp(","),"");
345 342
346 343
347 qDebug("filename is "+fileName); 344 qDebug("filename is "+fileName);
348// open tmp file here 345// open tmp file here
349 char *pointer; 346 char *pointer;
350 pointer=tmpnam(NULL); 347 pointer=tmpnam(NULL);
351 qDebug("Opening tmp file %s",pointer); 348 qDebug("Opening tmp file %s",pointer);
352 349
353 if(openWAV(pointer ) == -1) { 350 if(openWAV(pointer ) == -1) {
354 351
355// if(openWAV(fileName.latin1()) == -1) { 352// if(openWAV(fileName.latin1()) == -1) {
356 QString err("Could not open the temp file\n"); 353 QString err("Could not open the temp file\n");
357 err += fileName; 354 err += fileName;
358 QMessageBox::critical(0, "vmemo", err, "Abort"); 355 QMessageBox::critical(0, "vmemo", err, "Abort");
359 ::close(dsp); 356 ::close(dsp);
360 return FALSE; 357 return FALSE;
361 } 358 }
362 if( record() ) { 359 if( record() ) {
@@ -382,98 +379,102 @@ bool VMemo::startRecording() {
382 l.setCategories(cats); 379 l.setCategories(cats);
383 l.writeLink(); 380 l.writeLink();
384 return TRUE; 381 return TRUE;
385 } else 382 } else
386 return FALSE; 383 return FALSE;
387 384
388} 385}
389 386
390void VMemo::stopRecording() { 387void VMemo::stopRecording() {
391 show(); 388 show();
392 qDebug("Stopped recording"); 389 qDebug("Stopped recording");
393 recording = FALSE; 390 recording = FALSE;
394 if(useAlerts) { 391 if(useAlerts) {
395 msgLabel->close(); 392 msgLabel->close();
396 msgLabel=0; 393 msgLabel=0;
397 delete msgLabel; 394 delete msgLabel;
398 } 395 }
399 t_timer->stop(); 396 t_timer->stop();
400 Config cfg("Vmemo"); 397 Config cfg("Vmemo");
401 cfg.setGroup("Defaults"); 398 cfg.setGroup("Defaults");
402 if( cfg.readNumEntry("hideIcon",0) == 1 ) 399 if( cfg.readNumEntry("hideIcon",0) == 1 )
403 hide(); 400 hide();
404} 401}
405 402
406int VMemo::openDSP() { 403int VMemo::openDSP() {
407 Config cfg("Vmemo"); 404 Config cfg("Vmemo");
408 cfg.setGroup("Record"); 405 cfg.setGroup("Record");
409 406
410 speed = cfg.readNumEntry("SampleRate", 22050); 407 speed = cfg.readNumEntry("SampleRate", 22050);
411 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) 408 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1)
412 if (cfg.readNumEntry("SixteenBit", 1)==1) { 409 if (cfg.readNumEntry("SixteenBit", 1)==1) {
413 format = AFMT_S16_LE; 410 format = AFMT_S16_LE;
414 resolution = 16; 411 resolution = 16;
415 } else { 412 } else {
416 format = AFMT_U8; 413 format = AFMT_U8;
417 resolution = 8; 414 resolution = 8;
418 } 415 }
419 416
420 qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); 417 qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution);
421 418
422 if(systemZaurus) { 419 if(systemZaurus) {
423 dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 420 dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1
424 channels=1; //zaurus has one input channel 421 channels=1; //zaurus has one input channel
425 } else { 422 } else {
426 dsp = open("/dev/dsp", O_RDONLY); 423 dsp = open("/dev/dsp", O_RDONLY);
427 } 424 }
428 425
429 if(dsp == -1) { 426 if(dsp == -1) {
430 perror("open(\"/dev/dsp\")"); 427 msgLabel->close();
431 errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); 428 msgLabel=0;
429 delete msgLabel;
430
431 perror("open(\"/dev/dsp\")");
432 errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno);
432 QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); 433 QMessageBox::critical(0, "vmemo", errorMsg, "Abort");
433 return -1; 434 return -1;
434 } 435 }
435 436
436 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { 437 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) {
437 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 438 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
438 return -1; 439 return -1;
439 } 440 }
440 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { 441 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) {
441 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 442 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
442 return -1; 443 return -1;
443 } 444 }
444 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { 445 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) {
445 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 446 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
446 return -1; 447 return -1;
447 } 448 }
448 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { 449 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) {
449 perror("ioctl(\"SOUND_PCM_READ_RATE\")"); 450 perror("ioctl(\"SOUND_PCM_READ_RATE\")");
450 return -1; 451 return -1;
451 } 452 }
452 453
453 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute 454 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute
454 455
455 return 1; 456 return 1;
456} 457}
457 458
458int VMemo::openWAV(const char *filename) { 459int VMemo::openWAV(const char *filename) {
459 track.setName(filename); 460 track.setName(filename);
460 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { 461 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) {
461 errorMsg=filename; 462 errorMsg=filename;
462 return -1; 463 return -1;
463 } 464 }
464 465
465 wav=track.handle(); 466 wav=track.handle();
466 Config vmCfg("Vmemo"); 467 Config vmCfg("Vmemo");
467 vmCfg.setGroup("Defaults"); 468 vmCfg.setGroup("Defaults");
468 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); 469 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0);
469 470
470 WaveHeader wh; 471 WaveHeader wh;
471 472
472 wh.main_chunk = RIFF; 473 wh.main_chunk = RIFF;
473 wh.length=0; 474 wh.length=0;
474 wh.chunk_type = WAVE; 475 wh.chunk_type = WAVE;
475 wh.sub_chunk = FMT; 476 wh.sub_chunk = FMT;
476 wh.sc_len = 16; 477 wh.sc_len = 16;
477 if(useADPCM) 478 if(useADPCM)
478 wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; 479 wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE;
479 else 480 else