-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 84d53e0..2d694d2 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -204,16 +204,17 @@ VMemo::VMemo( QWidget *parent, const char *_name ) | |||
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 | Config vmCfg("Vmemo"); | 213 | Config vmCfg("Vmemo"); |
213 | vmCfg.setGroup("Defaults"); | 214 | vmCfg.setGroup("Defaults"); |
214 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); | 215 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); |
215 | 216 | ||
216 | qDebug("toggleKey %d", toggleKey); | 217 | qDebug("toggleKey %d", toggleKey); |
217 | 218 | ||
218 | if(release.find("embedix",0,TRUE) !=-1) | 219 | if(release.find("embedix",0,TRUE) !=-1) |
219 | systemZaurus=TRUE; | 220 | systemZaurus=TRUE; |
@@ -228,27 +229,29 @@ VMemo::VMemo( QWidget *parent, const char *_name ) | |||
228 | // QPEApplication::grabKeyboard(); | 229 | // QPEApplication::grabKeyboard(); |
229 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); | 230 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); |
230 | // e << 4096; // Key_Escape | 231 | // e << 4096; // Key_Escape |
231 | // e << Key_F5; //4148 | 232 | // e << Key_F5; //4148 |
232 | e << toggleKey; | 233 | e << toggleKey; |
233 | e << QString("QPE/VMemo"); | 234 | e << QString("QPE/VMemo"); |
234 | e << QString("toggleRecord()"); | 235 | e << QString("toggleRecord()"); |
235 | } | 236 | } |
236 | if( vmCfg.readNumEntry("hideIcon",0) == 1 || toggleKey > 0) | 237 | |
238 | if( vmCfg.readNumEntry("hideIcon",0) == 1) | ||
237 | hide(); | 239 | hide(); |
238 | } | 240 | } |
239 | } | 241 | } |
240 | 242 | ||
241 | VMemo::~VMemo() | 243 | VMemo::~VMemo() |
242 | { | 244 | { |
243 | } | 245 | } |
244 | 246 | ||
245 | void VMemo::receive( const QCString &msg, const QByteArray &data ) | 247 | void VMemo::receive( const QCString &msg, const QByteArray &data ) |
246 | { | 248 | { |
249 | qDebug("receive"); | ||
247 | QDataStream stream( data, IO_ReadOnly ); | 250 | QDataStream stream( data, IO_ReadOnly ); |
248 | if (msg == "toggleRecord()") { | 251 | if (msg == "toggleRecord()") { |
249 | if (recording) { | 252 | if (recording) { |
250 | fromToggle = TRUE; | 253 | fromToggle = TRUE; |
251 | stopRecording(); | 254 | stopRecording(); |
252 | } else { | 255 | } else { |
253 | fromToggle = TRUE; | 256 | fromToggle = TRUE; |
254 | startRecording(); | 257 | startRecording(); |
@@ -270,17 +273,17 @@ void VMemo::mousePressEvent( QMouseEvent * ) | |||
270 | void VMemo::mouseReleaseEvent( QMouseEvent * ) | 273 | void VMemo::mouseReleaseEvent( QMouseEvent * ) |
271 | { | 274 | { |
272 | stopRecording(); | 275 | stopRecording(); |
273 | } | 276 | } |
274 | 277 | ||
275 | bool VMemo::startRecording() { | 278 | bool VMemo::startRecording() { |
276 | 279 | ||
277 | if ( recording) | 280 | if ( recording) |
278 | return FALSE;; | 281 | return FALSE; |
279 | 282 | ||
280 | Config config( "Vmemo" ); | 283 | Config config( "Vmemo" ); |
281 | config.setGroup( "System" ); | 284 | config.setGroup( "System" ); |
282 | 285 | ||
283 | useAlerts = config.readBoolEntry("Alert"); | 286 | useAlerts = config.readBoolEntry("Alert"); |
284 | if(useAlerts) { | 287 | if(useAlerts) { |
285 | 288 | ||
286 | msgLabel = new QLabel( 0, "alertLabel" ); | 289 | msgLabel = new QLabel( 0, "alertLabel" ); |
@@ -313,33 +316,34 @@ bool VMemo::startRecording() { | |||
313 | config.setGroup( "System" ); | 316 | config.setGroup( "System" ); |
314 | fName = QPEApplication::documentDir() ; | 317 | fName = QPEApplication::documentDir() ; |
315 | fileName = config.readEntry("RecLocation", fName); | 318 | fileName = config.readEntry("RecLocation", fName); |
316 | 319 | ||
317 | int s; | 320 | int s; |
318 | s=fileName.find(':'); | 321 | s=fileName.find(':'); |
319 | if(s) | 322 | if(s) |
320 | fileName=fileName.right(fileName.length()-s-2); | 323 | fileName=fileName.right(fileName.length()-s-2); |
321 | qDebug("filename will be "+fileName); | 324 | qDebug("pathname will be "+fileName); |
325 | |||
322 | if( fileName.left(1).find('/') == -1) | 326 | if( fileName.left(1).find('/') == -1) |
323 | fileName="/"+fileName; | 327 | fileName="/"+fileName; |
324 | if( fileName.right(1).find('/') == -1) | 328 | if( fileName.right(1).find('/') == -1) |
325 | fileName+="/"; | 329 | fileName+="/"; |
326 | fName = "vm_"+ dt.toString()+ ".wav"; | 330 | fName = "vm_"+ dt.toString()+ ".wav"; |
327 | 331 | ||
328 | fileName+=fName; | 332 | fileName+=fName; |
329 | qDebug("filename is "+fileName); | 333 | qDebug("filename is "+fileName); |
330 | // No spaces in the filename | 334 | // No spaces in the filename |
331 | fileName.replace(QRegExp("'"),""); | 335 | fileName.replace(QRegExp("'"),""); |
332 | fileName.replace(QRegExp(" "),"_"); | 336 | fileName.replace(QRegExp(" "),"_"); |
333 | fileName.replace(QRegExp(":"),"."); | 337 | fileName.replace(QRegExp(":"),"."); |
334 | fileName.replace(QRegExp(","),""); | 338 | fileName.replace(QRegExp(","),""); |
335 | 339 | ||
336 | if(openWAV(fileName.latin1()) == -1) { | 340 | if(openWAV(fileName.latin1()) == -1) { |
337 | // QString err("Could not open the output file\n"); | 341 | // QString err("Could not open the output file\n"); |
338 | // err += fileName; | 342 | // err += fileName; |
339 | // QMessageBox::critical(0, "vmemo", err, "Abort"); | 343 | // QMessageBox::critical(0, "vmemo", err, "Abort"); |
340 | close(dsp); | 344 | close(dsp); |
341 | return FALSE; | 345 | return FALSE; |
342 | } | 346 | } |
343 | 347 | ||
344 | QArray<int> cats(1); | 348 | QArray<int> cats(1); |
345 | cats[0] = config.readNumEntry("Category", 0); | 349 | cats[0] = config.readNumEntry("Category", 0); |
@@ -355,20 +359,26 @@ bool VMemo::startRecording() { | |||
355 | 359 | ||
356 | 360 | ||
357 | record(); | 361 | record(); |
358 | // delete msgLabel; | 362 | // delete msgLabel; |
359 | return TRUE; | 363 | return TRUE; |
360 | } | 364 | } |
361 | 365 | ||
362 | void VMemo::stopRecording() { | 366 | void VMemo::stopRecording() { |
367 | show(); | ||
368 | qDebug("Stopped recording"); | ||
363 | recording = FALSE; | 369 | recording = FALSE; |
364 | if(useAlerts) | 370 | if(useAlerts) |
365 | if( msgLabel) delete msgLabel; | 371 | if( msgLabel) delete msgLabel; |
366 | t_timer->stop(); | 372 | t_timer->stop(); |
373 | Config cfg("Vmemo"); | ||
374 | cfg.setGroup("Defaults"); | ||
375 | if( cfg.readNumEntry("hideIcon",0) == 1 ) | ||
376 | hide(); | ||
367 | } | 377 | } |
368 | 378 | ||
369 | int VMemo::openDSP() | 379 | int VMemo::openDSP() |
370 | { | 380 | { |
371 | Config cfg("Vmemo"); | 381 | Config cfg("Vmemo"); |
372 | cfg.setGroup("Record"); | 382 | cfg.setGroup("Record"); |
373 | 383 | ||
374 | speed = cfg.readNumEntry("SampleRate", 22050); | 384 | speed = cfg.readNumEntry("SampleRate", 22050); |
@@ -379,20 +389,20 @@ int VMemo::openDSP() | |||
379 | } else { | 389 | } else { |
380 | format = AFMT_U8; | 390 | format = AFMT_U8; |
381 | resolution = 8; | 391 | resolution = 8; |
382 | } | 392 | } |
383 | 393 | ||
384 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); | 394 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); |
385 | 395 | ||
386 | if(systemZaurus) { | 396 | if(systemZaurus) { |
387 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 | 397 | dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 |
388 | channels=1; //zaurus has one input channel | 398 | channels=1; //zaurus has one input channel |
389 | } else { | 399 | } else { |
390 | dsp = open("/dev/dsp", O_RDWR); | 400 | dsp = open("/dev/dsp", O_RDONLY); |
391 | } | 401 | } |
392 | 402 | ||
393 | if(dsp == -1) { | 403 | if(dsp == -1) { |
394 | perror("open(\"/dev/dsp\")"); | 404 | perror("open(\"/dev/dsp\")"); |
395 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); | 405 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); |
396 | QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); | 406 | QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); |
397 | return -1; | 407 | return -1; |
398 | } | 408 | } |
@@ -560,26 +570,27 @@ void VMemo::record(void) | |||
560 | 570 | ||
561 | lseek(wav, 4, SEEK_SET); | 571 | lseek(wav, 4, SEEK_SET); |
562 | write(wav, &value, 4); | 572 | write(wav, &value, 4); |
563 | lseek(wav, 40, SEEK_SET); | 573 | lseek(wav, 40, SEEK_SET); |
564 | 574 | ||
565 | write(wav, &length, 4); | 575 | write(wav, &length, 4); |
566 | 576 | ||
567 | track.close(); | 577 | track.close(); |
568 | qDebug("Tracvk closed"); | 578 | qDebug("Track closed"); |
569 | 579 | ||
570 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 580 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
571 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 581 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
572 | 582 | ||
573 | ::close(dsp); | 583 | ::close(dsp); |
574 | fileName = fileName.left(fileName.length()-4); | 584 | fileName = fileName.left(fileName.length()-4); |
575 | // if(useAlerts) | 585 | // if(useAlerts) |
576 | // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); | 586 | // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); |
577 | qDebug("done recording "+fileName); | 587 | qDebug("done recording "+fileName); |
588 | |||
578 | QSound::play(Resource::findSound("vmemoe")); | 589 | QSound::play(Resource::findSound("vmemoe")); |
579 | 590 | ||
580 | Config cfg("qpe"); | 591 | Config cfg("qpe"); |
581 | cfg.setGroup("Volume"); | 592 | cfg.setGroup("Volume"); |
582 | QString foo = cfg.readEntry("Mute","TRUE"); | 593 | QString foo = cfg.readEntry("Mute","TRUE"); |
583 | if(foo.find("TRUE",0,TRUE) != -1) | 594 | if(foo.find("TRUE",0,TRUE) != -1) |
584 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute | 595 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute |
585 | 596 | ||