Diffstat (limited to 'core/applets/vmemo/vmemo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 73 |
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 | |||
@@ -300,100 +300,123 @@ bool VMemo::startRecording() { | |||
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 | ||
373 | void VMemo::stopRecording() { | 396 | void 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 | ||
389 | int VMemo::openDSP() { | 412 | int 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; |