-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 36 |
1 files changed, 3 insertions, 33 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index c5d0a5b..4c07b3a 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -198,155 +198,129 @@ static char * vmemo_xpm[] = { | |||
198 | " d e f g h i j 3 k l m n ", | 198 | " d e f g h i j 3 k l m n ", |
199 | " o p q r s t u v w n ", | 199 | " o p q r s t u v w n ", |
200 | " o x y z A B C D E n ", | 200 | " o x y z A B C D E n ", |
201 | " F G H I J K L M N O ", | 201 | " F G H I J K L M N O ", |
202 | " P Q R S T U V W X ", | 202 | " P Q R S T U V W X ", |
203 | " Y Z ` b ...+. ", | 203 | " Y Z ` b ...+. ", |
204 | " @.#.$.%.&. ", | 204 | " @.#.$.%.&. ", |
205 | " *.B =. ", | 205 | " *.B =. ", |
206 | " n n n n n n n n n "}; | 206 | " n n n n n n n n n "}; |
207 | 207 | ||
208 | 208 | ||
209 | VMemo::VMemo( QWidget *parent, const char *_name ) | 209 | VMemo::VMemo( QWidget *parent, const char *_name ) |
210 | : QWidget( parent, _name ) { | 210 | : QWidget( parent, _name ) { |
211 | setFixedHeight( 18 ); | 211 | setFixedHeight( 18 ); |
212 | setFixedWidth( 14 ); | 212 | setFixedWidth( 14 ); |
213 | 213 | ||
214 | recording = FALSE; | ||
215 | |||
216 | t_timer = new QTimer( this ); | 214 | t_timer = new QTimer( this ); |
217 | connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) ); | 215 | connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) ); |
218 | 216 | ||
219 | struct utsname name; /* check for embedix kernel running on the zaurus*/ | 217 | struct utsname name; /* check for embedix kernel running on the zaurus*/ |
220 | if (uname(&name) != -1) { | 218 | if (uname(&name) != -1) { |
221 | QString release=name.release; | 219 | QString release=name.release; |
222 | 220 | ||
223 | Config vmCfg("Vmemo"); | 221 | Config vmCfg("Vmemo"); |
224 | vmCfg.setGroup("Defaults"); | 222 | vmCfg.setGroup("Defaults"); |
225 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); | 223 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); |
226 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | 224 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); |
227 | 225 | ||
228 | qDebug("toggleKey %d", toggleKey); | 226 | qDebug("toggleKey %d", toggleKey); |
229 | 227 | ||
230 | if(release.find("embedix",0,TRUE) !=-1) | 228 | if(release.find("embedix",0,TRUE) !=-1) |
231 | systemZaurus=TRUE; | 229 | systemZaurus=TRUE; |
232 | else | 230 | else |
233 | systemZaurus=FALSE; | 231 | systemZaurus=FALSE; |
234 | 232 | ||
235 | myChannel = new QCopChannel( "QPE/VMemo", this ); | 233 | myChannel = new QCopChannel( "QPE/VMemo", this ); |
236 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), | 234 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), |
237 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 235 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
238 | 236 | ||
239 | if( toggleKey != -1 ) { | 237 | if( toggleKey != -1 ) { |
240 | // QPEApplication::grabKeyboard(); | ||
241 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); | 238 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); |
242 | // e << 4096; // Key_Escape | 239 | // e << 4096; // Key_Escape |
243 | // e << Key_F5; //4148 | 240 | // e << Key_F5; //4148 |
244 | e << toggleKey; | 241 | e << toggleKey; |
245 | e << QString("QPE/VMemo"); | 242 | e << QString("QPE/VMemo"); |
246 | e << QString("toggleRecord()"); | 243 | e << QString("toggleRecord()"); |
247 | } | 244 | } |
248 | if(toggleKey == 1) | 245 | if(toggleKey == 1) |
249 | usingIcon=TRUE; | 246 | usingIcon=TRUE; |
250 | else | 247 | else |
251 | usingIcon=FALSE; | 248 | usingIcon=FALSE; |
252 | if( vmCfg.readNumEntry("hideIcon",0) == 1) | 249 | if( vmCfg.readNumEntry("hideIcon",0) == 1) |
253 | hide(); | 250 | hide(); |
251 | recording = FALSE; | ||
254 | } | 252 | } |
255 | } | 253 | } |
256 | 254 | ||
257 | VMemo::~VMemo() { | 255 | VMemo::~VMemo() { |
258 | } | 256 | } |
259 | 257 | ||
260 | void VMemo::receive( const QCString &msg, const QByteArray &data ) { | 258 | void VMemo::receive( const QCString &msg, const QByteArray &data ) { |
261 | qDebug("receive"); | 259 | qDebug("receive"); |
262 | QDataStream stream( data, IO_ReadOnly ); | 260 | QDataStream stream( data, IO_ReadOnly ); |
263 | 261 | ||
264 | if (msg == "toggleRecord()") { | 262 | if (msg == "toggleRecord()") { |
265 | |||
266 | if (recording) { | 263 | if (recording) { |
267 | fromToggle = TRUE; | 264 | fromToggle = TRUE; |
268 | mouseReleaseEvent(NULL); | ||
269 | stopRecording(); | 265 | stopRecording(); |
270 | } else { | 266 | } else { |
271 | fromToggle = TRUE; | 267 | fromToggle = TRUE; |
272 | // mousePressEvent(NULL); | ||
273 | startRecording(); | 268 | startRecording(); |
274 | } | 269 | } |
275 | } | 270 | } |
276 | } | 271 | } |
277 | 272 | ||
278 | void VMemo::paintEvent( QPaintEvent* ) { | 273 | void VMemo::paintEvent( QPaintEvent* ) { |
279 | QPainter p(this); | 274 | QPainter p(this); |
280 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); | 275 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); |
281 | } | 276 | } |
282 | 277 | ||
283 | void VMemo::mousePressEvent( QMouseEvent * me) { | 278 | void VMemo::mousePressEvent( QMouseEvent * me) { |
284 | // just to be safe | ||
285 | // if (recording) { | ||
286 | // recording = FALSE; | ||
287 | // return; | ||
288 | // } | ||
289 | /* 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 |
290 | mousePressEvent and mouseReleaseEvent with a NULL parameter. */ | 280 | mousePressEvent and mouseReleaseEvent with a NULL parameter. */ |
291 | // if ( me->button() != LeftButton && me != NULL /*&& !systemZaurus*/) { | ||
292 | 281 | ||
293 | // if (!systemZaurus && me != NULL) | 282 | // if (!systemZaurus && me != NULL) |
294 | // return; | 283 | // return; |
295 | // } | 284 | // } |
296 | 285 | ||
297 | if(!recording) | 286 | if(!recording) |
298 | startRecording(); | 287 | startRecording(); |
299 | else | 288 | else |
300 | stopRecording(); | 289 | stopRecording(); |
301 | } | 290 | } |
302 | 291 | ||
303 | void VMemo::mouseReleaseEvent( QMouseEvent * ) { | 292 | void VMemo::mouseReleaseEvent( QMouseEvent * ) { |
304 | // if(usingIcon && !recording) | ||
305 | // stopRecording(); | ||
306 | } | 293 | } |
307 | 294 | ||
308 | bool VMemo::startRecording() { | 295 | bool VMemo::startRecording() { |
309 | |||
310 | if ( recording) | ||
311 | return FALSE; | ||
312 | |||
313 | Config config( "Vmemo" ); | 296 | Config config( "Vmemo" ); |
314 | config.setGroup( "System" ); | 297 | config.setGroup( "System" ); |
315 | 298 | ||
316 | useAlerts = config.readBoolEntry("Alert",1); | 299 | useAlerts = config.readBoolEntry("Alert",1); |
317 | if(useAlerts) { | 300 | if(useAlerts) { |
318 | 301 | ||
319 | msgLabel = new QLabel( 0, "alertLabel" ); | 302 | msgLabel = new QLabel( 0, "alertLabel" ); |
320 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); | 303 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); |
321 | msgLabel->show(); | 304 | msgLabel->show(); |
322 | } | 305 | } |
323 | 306 | ||
324 | // if(useAlerts) | ||
325 | // QMessageBox::message("VMemo","Really Record?");//) ==1) | ||
326 | // return; | ||
327 | // } else { | ||
328 | // if (!systemZaurus ) | ||
329 | // QSound::play(Resource::findSound("vmemob")); | ||
330 | // } | ||
331 | qDebug("Start recording engines"); | 307 | qDebug("Start recording engines"); |
332 | recording = TRUE; | 308 | recording = TRUE; |
333 | 309 | ||
334 | if (openDSP() == -1) { | 310 | if (openDSP() == -1) { |
335 | // QMessageBox::critical(0, "vmemo", "Could not open dsp device.\n"+errorMsg, "Abort"); | ||
336 | // delete msgLabel; | ||
337 | recording = FALSE; | 311 | recording = FALSE; |
338 | msgLabel=0; | 312 | msgLabel=0; |
339 | delete msgLabel; | 313 | delete msgLabel; |
340 | 314 | ||
341 | return FALSE; | 315 | return FALSE; |
342 | } | 316 | } |
343 | 317 | ||
344 | config.setGroup("Defaults"); | 318 | config.setGroup("Defaults"); |
345 | 319 | ||
346 | QDateTime dt = QDateTime::currentDateTime(); | 320 | QDateTime dt = QDateTime::currentDateTime(); |
347 | 321 | ||
348 | QString fName; | 322 | QString fName; |
349 | config.setGroup( "System" ); | 323 | config.setGroup( "System" ); |
350 | fName = QPEApplication::documentDir() ; | 324 | fName = QPEApplication::documentDir() ; |
351 | fileName = config.readEntry("RecLocation", fName); | 325 | fileName = config.readEntry("RecLocation", fName); |
352 | 326 | ||
@@ -563,68 +537,64 @@ bool VMemo::record() { | |||
563 | if(useADPCM) { | 537 | if(useADPCM) { |
564 | adpcm_coder( sbuf, abuf, result/2, &encoder_state); | 538 | adpcm_coder( sbuf, abuf, result/2, &encoder_state); |
565 | bytesWritten = ::write(wav, abuf, result/4); | 539 | bytesWritten = ::write(wav, abuf, result/4); |
566 | 540 | ||
567 | } else { | 541 | } else { |
568 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 542 | for (int i = 0; i < result; i++) { //since Z is mono do normally |
569 | monoBuffer[i] = sound[i]; | 543 | monoBuffer[i] = sound[i]; |
570 | } | 544 | } |
571 | 545 | ||
572 | length+=write(wav, monoBuffer, result); | 546 | length+=write(wav, monoBuffer, result); |
573 | } | 547 | } |
574 | length +=bytesWritten; | 548 | length +=bytesWritten; |
575 | 549 | ||
576 | if(length<0) { | 550 | if(length<0) { |
577 | recording=false; | 551 | recording=false; |
578 | perror("dev/dsp's is a lookin' messy"); | 552 | perror("dev/dsp's is a lookin' messy"); |
579 | QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); | 553 | QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); |
580 | break; | 554 | break; |
581 | return FALSE; | 555 | return FALSE; |
582 | } | 556 | } |
583 | // printf("%d\r",length); | 557 | // printf("%d\r",length); |
584 | // fflush(stdout); | 558 | // fflush(stdout); |
585 | qApp->processEvents(); | 559 | qApp->processEvents(); |
586 | } | 560 | } |
587 | // qDebug("file has length of %d lasting %d seconds", | 561 | // qDebug("file has length of %d lasting %d seconds", |
588 | // length, (( length / speed) / channels) / 2 ); | 562 | // length, (( length / speed) / channels) / 2 ); |
589 | // } | 563 | // } |
590 | 564 | ||
591 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// | 565 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// |
592 | 566 | ||
593 | value = length+36; | 567 | value = length+36; |
594 | 568 | ||
595 | lseek(wav, 4, SEEK_SET); | 569 | lseek(wav, 4, SEEK_SET); |
596 | write(wav, &value, 4); | 570 | write(wav, &value, 4); |
597 | lseek(wav, 40, SEEK_SET); | 571 | lseek(wav, 40, SEEK_SET); |
598 | 572 | ||
599 | write(wav, &length, 4); | 573 | write(wav, &length, 4); |
600 | 574 | ||
601 | track.close(); | 575 | track.close(); |
602 | qDebug("Track closed"); | 576 | qDebug("Track closed"); |
603 | 577 | ||
604 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 578 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
605 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 579 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
606 | 580 | ||
607 | ::close(dsp); | 581 | ::close(dsp); |
608 | 582 | ||
609 | // if(useAlerts) | ||
610 | // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); | ||
611 | qDebug("done recording "+fileName); | 583 | qDebug("done recording "+fileName); |
612 | 584 | ||
613 | // QSound::play(Resource::findSound("vmemoe")); | ||
614 | |||
615 | Config cfg("qpe"); | 585 | Config cfg("qpe"); |
616 | cfg.setGroup("Volume"); | 586 | cfg.setGroup("Volume"); |
617 | QString foo = cfg.readEntry("Mute","TRUE"); | 587 | QString foo = cfg.readEntry("Mute","TRUE"); |
618 | if(foo.find("TRUE",0,TRUE) != -1) | 588 | if(foo.find("TRUE",0,TRUE) != -1) |
619 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute | 589 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute |
620 | return TRUE; | 590 | return TRUE; |
621 | } | 591 | } |
622 | 592 | ||
623 | int VMemo::setToggleButton(int tog) { | 593 | int VMemo::setToggleButton(int tog) { |
624 | 594 | ||
625 | for( int i=0; i < 10;i++) { | 595 | for( int i=0; i < 10;i++) { |
626 | switch (tog) { | 596 | switch (tog) { |
627 | case 0: | 597 | case 0: |
628 | return -1; | 598 | return -1; |
629 | break; | 599 | break; |
630 | case 1: | 600 | case 1: |