summaryrefslogtreecommitdiff
path: root/core/applets/vmemo/vmemo.cpp
Unidiff
Diffstat (limited to 'core/applets/vmemo/vmemo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/vmemo/vmemo.cpp73
1 files changed, 48 insertions, 25 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp
index 8ba1eb7..1a8f154 100644
--- a/core/applets/vmemo/vmemo.cpp
+++ b/core/applets/vmemo/vmemo.cpp
@@ -236,228 +236,251 @@ VMemo::VMemo( QWidget *parent, const char *_name )
236 else 236 else
237 usingIcon = false; 237 usingIcon = false;
238 if (!usingIcon) 238 if (!usingIcon)
239 hide(); 239 hide();
240 recording = false; 240 recording = false;
241} 241}
242 242
243VMemo::~VMemo() { 243VMemo::~VMemo() {
244} 244}
245 245
246int VMemo::position() 246int VMemo::position()
247{ 247{
248 return 1; 248 return 1;
249} 249}
250 250
251void VMemo::receive( const QCString &msg, const QByteArray &data ) { 251void VMemo::receive( const QCString &msg, const QByteArray &data ) {
252 QDataStream stream( data, IO_ReadOnly ); 252 QDataStream stream( data, IO_ReadOnly );
253 253
254 if (msg == "toggleRecord()") { 254 if (msg == "toggleRecord()") {
255 if (recording) { 255 if (recording) {
256 fromToggle = true; 256 fromToggle = true;
257 stopRecording(); 257 stopRecording();
258 } else { 258 } else {
259 fromToggle = true; 259 fromToggle = true;
260 startRecording(); 260 startRecording();
261 } 261 }
262 } 262 }
263} 263}
264 264
265void VMemo::paintEvent( QPaintEvent* ) { 265void VMemo::paintEvent( QPaintEvent* ) {
266 QPainter p(this); 266 QPainter p(this);
267 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); 267 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm );
268} 268}
269 269
270void VMemo::mousePressEvent( QMouseEvent * /*me*/) { 270void VMemo::mousePressEvent( QMouseEvent * /*me*/) {
271 271
272 if(!recording) { 272 if(!recording) {
273 if(!startRecording() ){ 273 if(!startRecording() ){
274 QMessageBox::critical(0, "vmemo", "Abort Recording", "Abort Recording"); 274 QMessageBox::critical(0, "vmemo", "Abort Recording", "Abort Recording");
275 } 275 }
276 } else { 276 } else {
277 stopRecording(); 277 stopRecording();
278 } 278 }
279} 279}
280 280
281void VMemo::mouseReleaseEvent( QMouseEvent * ) { 281void VMemo::mouseReleaseEvent( QMouseEvent * ) {
282} 282}
283 283
284bool VMemo::startRecording() { 284bool VMemo::startRecording() {
285 Config config( "Vmemo" ); 285 Config config( "Vmemo" );
286 config.setGroup( "System" ); 286 config.setGroup( "System" );
287 287
288 288
289 odebug << "Start recording engines" << oendl; 289 odebug << "Start recording engines" << oendl;
290 recording = true; 290 recording = true;
291 291
292 if (openDSP() == -1) { 292 if (openDSP() == -1) {
293 recording = false; 293 recording = false;
294 return false; 294 return false;
295 } 295 }
296 296
297 config.setGroup("Defaults"); 297 config.setGroup("Defaults");
298 298
299 date = TimeString::dateString( QDateTime::currentDateTime(),false,true); 299 date = TimeString::dateString( QDateTime::currentDateTime(),false,true);
300 date.replace(QRegExp("'"),""); 300 date.replace(QRegExp("'"),"");
301 date.replace(QRegExp(" "),"_"); 301 date.replace(QRegExp(" "),"_");
302 date.replace(QRegExp(":"),"-"); 302 date.replace(QRegExp(":"),"-");
303 date.replace(QRegExp(","),""); 303 date.replace(QRegExp(","),"");
304 304
305 QString fName; 305 QString fName;
306 config.setGroup( "System" ); 306 config.setGroup( "System" );
307 fName = QPEApplication::documentDir() ; 307 fName = QPEApplication::documentDir() ;
308 fileName = config.readEntry("RecLocation", fName); 308 fileName = config.readEntry("RecLocation", fName);
309 309
310 int s; 310 int s;
311 s=fileName.find(':'); 311 s=fileName.find(':');
312 if(s) 312 if(s)
313 fileName=fileName.right(fileName.length()-s-2); 313 fileName=fileName.right(fileName.length()-s-2);
314 odebug << "pathname will be "+fileName << oendl; 314 odebug << "pathname will be "+fileName << oendl;
315 315
316 if( fileName.left(1).find('/') == -1) 316 if( fileName.left(1).find('/') == -1)
317 fileName="/"+fileName; 317 fileName="/"+fileName;
318 if( fileName.right(1).find('/') == -1) 318 if( fileName.right(1).find('/') == -1)
319 fileName+="/"; 319 fileName+="/";
320 fName = "vm_"+ date + ".wav"; 320 fName = "vm_"+ date + ".wav";
321 321
322 fileName += fName; 322 fileName += fName;
323 odebug << "filename is " + fileName << oendl; 323 odebug << "filename is " + fileName << oendl;
324 324
325 useAlerts = config.readBoolEntry("Alert",1); 325 useAlerts = config.readBoolEntry("Alert",1);
326 if(useAlerts) { 326 if(useAlerts) {
327 msgLabel = new QLabel( 0, "alertLabel" ); 327 msgLabel = new QLabel( 0, "alertLabel" );
328 msgLabel->setText( tr("<B><P><font size=+2>VMemo-Recording</font></B><p>%1</p>").arg("vm_"+ date)); 328 msgLabel->setText( tr("<B><P><font size=+2>VMemo-Recording</font></B><p>%1</p>").arg("vm_"+ date));
329 msgLabel->show(); 329 msgLabel->show();
330 } 330 }
331 331
332// open tmp file here 332 // open tmp file here
333 char *pointer; 333 char *tmpFilePath = 0;
334 pointer=tmpnam(NULL); 334 char *tmpDir = getenv("TMPDIR");
335 odebug << "Opening tmp file " << pointer << "" << oendl; 335 if (tmpDir && *tmpDir != '\0') {
336 tmpFilePath = new char[strlen(tmpDir) + strlen("/vmemo-wav-XXXXXX") + 1];
337 strcpy(tmpFilePath, tmpDir);
338 free(tmpDir);
339 } else {
340 tmpFilePath = new char[strlen("/tmp/vmemo-wav-XXXXXX") + 1];
341 strcpy(tmpFilePath, "/tmp");
342 }
343 strcat(tmpFilePath, "/vmemo-wav-XXXXXX");
344 mode_t currUmask = umask(S_IRWXO | S_IRWXG);
345 int tmpFd = mkstemp(tmpFilePath);
346 umask(currUmask);
347 if (tmpFd == -1) {
348 owarn << "Could not open temp file with template " << tmpFilePath
349 << oendl;
350 delete [] tmpFilePath;
351 return false;
352 } else
353 odebug << "Opened temp file " << tmpFilePath << "" << oendl;
354
355 close(tmpFd);
336 356
337 if(openWAV(pointer ) == -1) { 357 if(openWAV(tmpFilePath ) == -1) {
338 358
339 QString err("Could not open the temp file\n"); 359 QString err("Could not open the temp file\n");
340 err += fileName; 360 err += fileName;
341 QMessageBox::critical(0, "vmemo", err, "Abort"); 361 QMessageBox::critical(0, "vmemo", err, "Abort");
342 ::close(dsp); 362 ::close(dsp);
343 return false; 363 return false;
344 } 364 }
345 if( record() ) { 365 if( record() ) {
346 366
347 QString cmd; 367 if( fileName.find(".wav",0,true) == -1)
348 if( fileName.find(".wav",0,true) == -1) 368 fileName += ".wav";
349 fileName += ".wav";
350 369
351 cmd.sprintf("mv %s "+fileName, pointer); 370 int retVal = rename(tmpFilePath, fileName.local8Bit());
352// move tmp file to regular file here 371 if (retVal == -1) {
353 372 owarn << "Could not move " << tmpFilePath << " to " << fileName
354 system(cmd.latin1()); 373 << oendl;
355 374 delete [] tmpFilePath;
356 QArray<int> cats(1); 375 return false;
357 cats[0] = config.readNumEntry("Category", 0); 376 }
358 377 delete [] tmpFilePath;
359 QString dlName("vm_"); 378
360 dlName += date; 379 QArray<int> cats(1);
361 DocLnk l; 380 cats[0] = config.readNumEntry("Category", 0);
362 l.setFile(fileName); 381
363 l.setName(dlName); 382 QString dlName("vm_");
364 l.setType("audio/x-wav"); 383 dlName += date;
365 l.setCategories(cats); 384 DocLnk l;
366 l.writeLink(); 385 l.setFile(fileName);
367 return true; 386 l.setName(dlName);
387 l.setType("audio/x-wav");
388 l.setCategories(cats);
389 l.writeLink();
390 return true;
368 } else 391 } else
369 return false; 392 return false;
370 393
371} 394}
372 395
373void VMemo::stopRecording() { 396void VMemo::stopRecording() {
374// show(); 397// show();
375 odebug << "Stopped recording" << oendl; 398 odebug << "Stopped recording" << oendl;
376 recording = false; 399 recording = false;
377 if(useAlerts) { 400 if(useAlerts) {
378 msgLabel->close(); 401 msgLabel->close();
379 msgLabel=0; 402 msgLabel=0;
380 delete msgLabel; 403 delete msgLabel;
381 } 404 }
382 t_timer->stop(); 405 t_timer->stop();
383 Config cfg("Vmemo"); 406 Config cfg("Vmemo");
384 cfg.setGroup("Defaults"); 407 cfg.setGroup("Defaults");
385// if( cfg.readNumEntry("hideIcon",0) == 1 ) 408// if( cfg.readNumEntry("hideIcon",0) == 1 )
386// hide(); 409// hide();
387} 410}
388 411
389int VMemo::openDSP() { 412int VMemo::openDSP() {
390 Config cfg("Vmemo"); 413 Config cfg("Vmemo");
391 cfg.setGroup("Record"); 414 cfg.setGroup("Record");
392 415
393 speed = cfg.readNumEntry("SampleRate", 22050); 416 speed = cfg.readNumEntry("SampleRate", 22050);
394 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) 417 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1)
395 if (cfg.readNumEntry("SixteenBit", 1)==1) { 418 if (cfg.readNumEntry("SixteenBit", 1)==1) {
396 format = AFMT_S16_LE; 419 format = AFMT_S16_LE;
397 resolution = 16; 420 resolution = 16;
398 } else { 421 } else {
399 format = AFMT_U8; 422 format = AFMT_U8;
400 resolution = 8; 423 resolution = 8;
401 } 424 }
402 425
403 odebug << "samplerate: " << speed << ", channels " << channels << ", resolution " << resolution << "" << oendl; 426 odebug << "samplerate: " << speed << ", channels " << channels << ", resolution " << resolution << "" << oendl;
404 427
405 if(systemZaurus) { 428 if(systemZaurus) {
406 dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 429 dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1
407 channels=1; //zaurus has one input channel 430 channels=1; //zaurus has one input channel
408 } else { 431 } else {
409#ifdef QT_QWS_DEVFS 432#ifdef QT_QWS_DEVFS
410 dsp = open("/dev/sound/dsp", O_RDONLY); 433 dsp = open("/dev/sound/dsp", O_RDONLY);
411#else 434#else
412 dsp = open("/dev/dsp", O_RDONLY); 435 dsp = open("/dev/dsp", O_RDONLY);
413#endif 436#endif
414 } 437 }
415 438
416 if (dsp == -1) { 439 if (dsp == -1) {
417 msgLabel->close(); 440 msgLabel->close();
418 msgLabel=0; 441 msgLabel=0;
419 delete msgLabel; 442 delete msgLabel;
420 443
421 perror("open(\"/dev/dsp\")"); 444 perror("open(\"/dev/dsp\")");
422 errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); 445 errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno);
423 QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); 446 QMessageBox::critical(0, "vmemo", errorMsg, "Abort");
424 return -1; 447 return -1;
425 } 448 }
426 449
427 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { 450 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) {
428 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 451 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
429// return -1; 452// return -1;
430 } 453 }
431 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { 454 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) {
432 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 455 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
433// return -1; 456// return -1;
434 } 457 }
435 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { 458 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) {
436 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 459 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
437// return -1; 460// return -1;
438 } 461 }
439 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { 462 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) {
440 perror("ioctl(\"SOUND_PCM_READ_RATE\")"); 463 perror("ioctl(\"SOUND_PCM_READ_RATE\")");
441// return -1; 464// return -1;
442 } 465 }
443 466
444 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false; //mute 467 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false; //mute
445 468
446 return 1; 469 return 1;
447} 470}
448 471
449int VMemo::openWAV(const char *filename) { 472int VMemo::openWAV(const char *filename) {
450 track.setName(filename); 473 track.setName(filename);
451 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { 474 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) {
452 errorMsg=filename; 475 errorMsg=filename;
453 return -1; 476 return -1;
454 } 477 }
455 478
456 wav=track.handle(); 479 wav=track.handle();
457 Config vmCfg("Vmemo"); 480 Config vmCfg("Vmemo");
458 vmCfg.setGroup("Defaults"); 481 vmCfg.setGroup("Defaults");
459 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); 482 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0);
460 483
461 WaveHeader wh; 484 WaveHeader wh;
462 485
463 wh.main_chunk = RIFF; 486 wh.main_chunk = RIFF;