-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 2c3edf1..b77e3b8 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -193,229 +193,255 @@ static char * vmemo_xpm[] = { | |||
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 | ||
198 | VMemo::VMemo( QWidget *parent, const char *_name ) | 198 | VMemo::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 | if(toggleKey == 1) | 237 | if(toggleKey == 1) |
238 | usingIcon=TRUE; | 238 | usingIcon=TRUE; |
239 | else | 239 | else |
240 | usingIcon=FALSE; | 240 | usingIcon=FALSE; |
241 | if( vmCfg.readNumEntry("hideIcon",0) == 1) | 241 | if( vmCfg.readNumEntry("hideIcon",0) == 1) |
242 | hide(); | 242 | hide(); |
243 | } | 243 | } |
244 | } | 244 | } |
245 | 245 | ||
246 | VMemo::~VMemo() | 246 | VMemo::~VMemo() |
247 | { | 247 | { |
248 | } | 248 | } |
249 | 249 | ||
250 | void VMemo::receive( const QCString &msg, const QByteArray &data ) | 250 | void VMemo::receive( const QCString &msg, const QByteArray &data ) |
251 | { | 251 | { |
252 | qDebug("receive"); | 252 | qDebug("receive"); |
253 | QDataStream stream( data, IO_ReadOnly ); | 253 | QDataStream stream( data, IO_ReadOnly ); |
254 | if (msg == "toggleRecord()") { | 254 | if (msg == "toggleRecord()") { |
255 | if (recording) { | 255 | if (recording) { |
256 | fromToggle = TRUE; | 256 | fromToggle = TRUE; |
257 | stopRecording(); | 257 | mouseReleaseEvent(NULL); |
258 | // stopRecording(); | ||
258 | } else { | 259 | } else { |
259 | fromToggle = TRUE; | 260 | fromToggle = TRUE; |
261 | // mousePressEvent(NULL); | ||
260 | startRecording(); | 262 | startRecording(); |
261 | } | 263 | } |
262 | } | 264 | } |
263 | } | 265 | } |
264 | 266 | ||
265 | void VMemo::paintEvent( QPaintEvent* ) | 267 | void VMemo::paintEvent( QPaintEvent* ) |
266 | { | 268 | { |
267 | QPainter p(this); | 269 | QPainter p(this); |
268 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); | 270 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); |
269 | } | 271 | } |
270 | 272 | ||
271 | void VMemo::mousePressEvent( QMouseEvent * ) | 273 | void VMemo::mousePressEvent( QMouseEvent * me) |
272 | { | 274 | { |
273 | if(!recording) | 275 | // just to be safe |
276 | if (recording) { | ||
277 | recording = FALSE; | ||
278 | return; | ||
279 | } | ||
280 | /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions | ||
281 | mousePressEvent and mouseReleaseEvent with a NULL parameter. */ | ||
282 | if ( me->button() != LeftButton) | ||
283 | |||
284 | // if (!systemZaurus && me != NULL) | ||
285 | return; | ||
286 | |||
287 | if(!recording) | ||
274 | startRecording(); | 288 | startRecording(); |
275 | else | 289 | else |
276 | stopRecording(); | 290 | stopRecording(); |
277 | } | 291 | } |
278 | 292 | ||
279 | void VMemo::mouseReleaseEvent( QMouseEvent * ) | 293 | void VMemo::mouseReleaseEvent( QMouseEvent * ) |
280 | { | 294 | { |
281 | // if(usingIcon && !recording) | 295 | // if(usingIcon && !recording) |
282 | // stopRecording(); | 296 | // stopRecording(); |
283 | } | 297 | } |
284 | 298 | ||
285 | bool VMemo::startRecording() { | 299 | bool VMemo::startRecording() { |
286 | 300 | ||
287 | if ( recording) | 301 | if ( recording) |
288 | return FALSE; | 302 | return FALSE; |
289 | 303 | ||
290 | Config config( "Vmemo" ); | 304 | Config config( "Vmemo" ); |
291 | config.setGroup( "System" ); | 305 | config.setGroup( "System" ); |
292 | 306 | ||
293 | useAlerts = config.readBoolEntry("Alert",1); | 307 | useAlerts = config.readBoolEntry("Alert",1); |
294 | if(useAlerts) { | 308 | if(useAlerts) { |
295 | 309 | ||
296 | msgLabel = new QLabel( 0, "alertLabel" ); | 310 | msgLabel = new QLabel( 0, "alertLabel" ); |
297 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); | 311 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); |
298 | msgLabel->show(); | 312 | msgLabel->show(); |
299 | } | 313 | } |
300 | 314 | ||
301 | // if(useAlerts) | 315 | // if(useAlerts) |
302 | // QMessageBox::message("VMemo","Really Record?");//) ==1) | 316 | // QMessageBox::message("VMemo","Really Record?");//) ==1) |
303 | // return; | 317 | // return; |
304 | // } else { | 318 | // } else { |
305 | // if (!systemZaurus ) | 319 | // if (!systemZaurus ) |
306 | // QSound::play(Resource::findSound("vmemob")); | 320 | // QSound::play(Resource::findSound("vmemob")); |
307 | // } | 321 | // } |
308 | qDebug("Start recording engines"); | 322 | qDebug("Start recording engines"); |
309 | recording = TRUE; | 323 | recording = TRUE; |
310 | 324 | ||
311 | if (openDSP() == -1) { | 325 | if (openDSP() == -1) { |
312 | // QMessageBox::critical(0, "vmemo", "Could not open dsp device.\n"+errorMsg, "Abort"); | 326 | // QMessageBox::critical(0, "vmemo", "Could not open dsp device.\n"+errorMsg, "Abort"); |
313 | // delete msgLabel; | 327 | // delete msgLabel; |
314 | recording = FALSE; | 328 | recording = FALSE; |
315 | msgLabel=0; | 329 | msgLabel=0; |
316 | delete msgLabel; | 330 | delete msgLabel; |
317 | 331 | ||
318 | return FALSE; | 332 | return FALSE; |
319 | } | 333 | } |
320 | 334 | ||
321 | config.setGroup("Defaults"); | 335 | config.setGroup("Defaults"); |
322 | 336 | ||
323 | QDateTime dt = QDateTime::currentDateTime(); | 337 | QDateTime dt = QDateTime::currentDateTime(); |
324 | 338 | ||
325 | QString fName; | 339 | QString fName; |
326 | config.setGroup( "System" ); | 340 | config.setGroup( "System" ); |
327 | fName = QPEApplication::documentDir() ; | 341 | fName = QPEApplication::documentDir() ; |
328 | fileName = config.readEntry("RecLocation", fName); | 342 | fileName = config.readEntry("RecLocation", fName); |
329 | 343 | ||
330 | int s; | 344 | int s; |
331 | s=fileName.find(':'); | 345 | s=fileName.find(':'); |
332 | if(s) | 346 | if(s) |
333 | fileName=fileName.right(fileName.length()-s-2); | 347 | fileName=fileName.right(fileName.length()-s-2); |
334 | qDebug("pathname will be "+fileName); | 348 | qDebug("pathname will be "+fileName); |
335 | 349 | ||
336 | if( fileName.left(1).find('/') == -1) | 350 | if( fileName.left(1).find('/') == -1) |
337 | fileName="/"+fileName; | 351 | fileName="/"+fileName; |
338 | if( fileName.right(1).find('/') == -1) | 352 | if( fileName.right(1).find('/') == -1) |
339 | fileName+="/"; | 353 | fileName+="/"; |
340 | fName = "vm_"+ dt.toString()+ ".wav"; | 354 | fName = "vm_"+ dt.toString()+ ".wav"; |
341 | 355 | ||
342 | fileName+=fName; | 356 | fileName+=fName; |
343 | qDebug("filename is "+fileName); | 357 | qDebug("filename is "+fileName); |
344 | // No spaces in the filename | 358 | // No spaces in the filename |
345 | fileName.replace(QRegExp("'"),""); | 359 | fileName.replace(QRegExp("'"),""); |
346 | fileName.replace(QRegExp(" "),"_"); | 360 | fileName.replace(QRegExp(" "),"_"); |
347 | fileName.replace(QRegExp(":"),"."); | 361 | fileName.replace(QRegExp(":"),"."); |
348 | fileName.replace(QRegExp(","),""); | 362 | fileName.replace(QRegExp(","),""); |
349 | 363 | ||
350 | if(openWAV(fileName.latin1()) == -1) { | 364 | // open tmp file here |
351 | // QString err("Could not open the output file\n"); | 365 | char *pointer; |
352 | // err += fileName; | 366 | pointer=tmpnam(NULL); |
353 | // QMessageBox::critical(0, "vmemo", err, "Abort"); | 367 | qDebug("Opening tmp file %s",pointer); |
354 | close(dsp); | 368 | |
369 | if(openWAV(pointer ) == -1) { | ||
370 | |||
371 | // if(openWAV(fileName.latin1()) == -1) { | ||
372 | QString err("Could not open the temp file\n"); | ||
373 | err += fileName; | ||
374 | QMessageBox::critical(0, "vmemo", err, "Abort"); | ||
375 | ::close(dsp); | ||
355 | return FALSE; | 376 | return FALSE; |
356 | } | 377 | } |
357 | 378 | QString cmd; | |
379 | cmd.sprintf("mv %s "+fileName,pointer); | ||
380 | |||
381 | // move tmp file to regular file here | ||
382 | system(cmd.latin1()); | ||
383 | |||
358 | QArray<int> cats(1); | 384 | QArray<int> cats(1); |
359 | cats[0] = config.readNumEntry("Category", 0); | 385 | cats[0] = config.readNumEntry("Category", 0); |
360 | 386 | ||
361 | QString dlName("vm_"); | 387 | QString dlName("vm_"); |
362 | dlName += dt.toString(); | 388 | dlName += dt.toString(); |
363 | DocLnk l; | 389 | DocLnk l; |
364 | l.setFile(fileName); | 390 | l.setFile(fileName); |
365 | l.setName(dlName); | 391 | l.setName(dlName); |
366 | l.setType("audio/x-wav"); | 392 | l.setType("audio/x-wav"); |
367 | l.setCategories(cats); | 393 | l.setCategories(cats); |
368 | l.writeLink(); | 394 | l.writeLink(); |
369 | 395 | ||
370 | record(); | 396 | record(); |
371 | 397 | ||
372 | return TRUE; | 398 | return TRUE; |
373 | } | 399 | } |
374 | 400 | ||
375 | void VMemo::stopRecording() { | 401 | void VMemo::stopRecording() { |
376 | show(); | 402 | show(); |
377 | qDebug("Stopped recording"); | 403 | qDebug("Stopped recording"); |
378 | recording = FALSE; | 404 | recording = FALSE; |
379 | if(useAlerts) { | 405 | if(useAlerts) { |
380 | msgLabel->close(); | 406 | msgLabel->close(); |
381 | msgLabel=0; | 407 | msgLabel=0; |
382 | delete msgLabel; | 408 | delete msgLabel; |
383 | } | 409 | } |
384 | t_timer->stop(); | 410 | t_timer->stop(); |
385 | Config cfg("Vmemo"); | 411 | Config cfg("Vmemo"); |
386 | cfg.setGroup("Defaults"); | 412 | cfg.setGroup("Defaults"); |
387 | if( cfg.readNumEntry("hideIcon",0) == 1 ) | 413 | if( cfg.readNumEntry("hideIcon",0) == 1 ) |
388 | hide(); | 414 | hide(); |
389 | } | 415 | } |
390 | 416 | ||
391 | int VMemo::openDSP() | 417 | int VMemo::openDSP() |
392 | { | 418 | { |
393 | Config cfg("Vmemo"); | 419 | Config cfg("Vmemo"); |
394 | cfg.setGroup("Record"); | 420 | cfg.setGroup("Record"); |
395 | 421 | ||
396 | speed = cfg.readNumEntry("SampleRate", 22050); | 422 | speed = cfg.readNumEntry("SampleRate", 22050); |
397 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 423 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
398 | if (cfg.readNumEntry("SixteenBit", 1)==1) { | 424 | if (cfg.readNumEntry("SixteenBit", 1)==1) { |
399 | format = AFMT_S16_LE; | 425 | format = AFMT_S16_LE; |
400 | resolution = 16; | 426 | resolution = 16; |
401 | } else { | 427 | } else { |
402 | format = AFMT_U8; | 428 | format = AFMT_U8; |
403 | resolution = 8; | 429 | resolution = 8; |
404 | } | 430 | } |
405 | 431 | ||
406 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); | 432 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); |
407 | 433 | ||
408 | if(systemZaurus) { | 434 | if(systemZaurus) { |
409 | dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 | 435 | dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 |
410 | channels=1; //zaurus has one input channel | 436 | channels=1; //zaurus has one input channel |
411 | } else { | 437 | } else { |
412 | dsp = open("/dev/dsp", O_RDONLY); | 438 | dsp = open("/dev/dsp", O_RDONLY); |
413 | } | 439 | } |
414 | 440 | ||
415 | if(dsp == -1) { | 441 | if(dsp == -1) { |
416 | perror("open(\"/dev/dsp\")"); | 442 | perror("open(\"/dev/dsp\")"); |
417 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); | 443 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); |
418 | QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); | 444 | QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); |
419 | return -1; | 445 | return -1; |
420 | } | 446 | } |
421 | 447 | ||
@@ -586,66 +612,66 @@ void VMemo::record(void) | |||
586 | 612 | ||
587 | write(wav, &length, 4); | 613 | write(wav, &length, 4); |
588 | 614 | ||
589 | track.close(); | 615 | track.close(); |
590 | qDebug("Track closed"); | 616 | qDebug("Track closed"); |
591 | 617 | ||
592 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 618 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
593 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 619 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
594 | 620 | ||
595 | ::close(dsp); | 621 | ::close(dsp); |
596 | fileName = fileName.left(fileName.length()-4); | 622 | fileName = fileName.left(fileName.length()-4); |
597 | // if(useAlerts) | 623 | // if(useAlerts) |
598 | // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); | 624 | // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); |
599 | qDebug("done recording "+fileName); | 625 | qDebug("done recording "+fileName); |
600 | 626 | ||
601 | // QSound::play(Resource::findSound("vmemoe")); | 627 | // QSound::play(Resource::findSound("vmemoe")); |
602 | 628 | ||
603 | Config cfg("qpe"); | 629 | Config cfg("qpe"); |
604 | cfg.setGroup("Volume"); | 630 | cfg.setGroup("Volume"); |
605 | QString foo = cfg.readEntry("Mute","TRUE"); | 631 | QString foo = cfg.readEntry("Mute","TRUE"); |
606 | if(foo.find("TRUE",0,TRUE) != -1) | 632 | if(foo.find("TRUE",0,TRUE) != -1) |
607 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute | 633 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute |
608 | 634 | ||
609 | } | 635 | } |
610 | 636 | ||
611 | int VMemo::setToggleButton(int tog) { | 637 | int VMemo::setToggleButton(int tog) { |
612 | 638 | ||
613 | for( int i=0; i < 10;i++) { | 639 | for( int i=0; i < 10;i++) { |
614 | switch (tog) { | 640 | switch (tog) { |
615 | case 0: | 641 | case 0: |
616 | return -1; | 642 | return -1; |
617 | break; | 643 | break; |
618 | case 1: | 644 | case 1: |
619 | return 0; | 645 | return 0; |
620 | break; | 646 | break; |
621 | case 2: | 647 | case 2: |
622 | return Key_Escape; | 648 | return Key_Escape; |
623 | break; | 649 | break; |
624 | case 3: | 650 | case 3: |
625 | return Key_Space; | 651 | return Key_Space; |
626 | break; | 652 | break; |
627 | case 4: | 653 | case 4: |
628 | return Key_F12; | 654 | return Key_F12; |
629 | break; | 655 | break; |
630 | case 5: | 656 | case 5: |
631 | return Key_F9; | 657 | return Key_F9; |
632 | break; | 658 | break; |
633 | case 6: | 659 | case 6: |
634 | return Key_F10; | 660 | return Key_F10; |
635 | break; | 661 | break; |
636 | case 7: | 662 | case 7: |
637 | return Key_F11; | 663 | return Key_F11; |
638 | break; | 664 | break; |
639 | case 8: | 665 | case 8: |
640 | return Key_F13; | 666 | return Key_F13; |
641 | break; | 667 | break; |
642 | }; | 668 | }; |
643 | } | 669 | } |
644 | return -1; | 670 | return -1; |
645 | } | 671 | } |
646 | 672 | ||
647 | void VMemo::timerBreak() { | 673 | void VMemo::timerBreak() { |
648 | //stop | 674 | //stop |
649 | stopRecording(); | 675 | stopRecording(); |
650 | QMessageBox::message("Vmemo","Vmemo recording has \ntimed out"); | 676 | QMessageBox::message("Vmemo","Vmemo recording has ended"); |
651 | } | 677 | } |