author | llornkcor <llornkcor> | 2002-06-28 23:37:17 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-06-28 23:37:17 (UTC) |
commit | 0552cd7f5762939ccdf05b9bf4fdae9b3e79b0a5 (patch) (unidiff) | |
tree | f1414fe0a921700e616b52c01ff84ea250e168b4 | |
parent | 05a76394214a0066325c71f91eb44ed7412df67c (diff) | |
download | opie-0552cd7f5762939ccdf05b9bf4fdae9b3e79b0a5.zip opie-0552cd7f5762939ccdf05b9bf4fdae9b3e79b0a5.tar.gz opie-0552cd7f5762939ccdf05b9bf4fdae9b3e79b0a5.tar.bz2 |
changed O_RDWR to O_RDONLY
-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 | |||
@@ -200,59 +200,62 @@ VMemo::VMemo( QWidget *parent, const char *_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 | 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; |
220 | else | 221 | else |
221 | systemZaurus=FALSE; | 222 | systemZaurus=FALSE; |
222 | 223 | ||
223 | myChannel = new QCopChannel( "QPE/VMemo", this ); | 224 | myChannel = new QCopChannel( "QPE/VMemo", this ); |
224 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), | 225 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), |
225 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 226 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
226 | 227 | ||
227 | if( toggleKey != -1 ) { | 228 | if( toggleKey != -1 ) { |
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(); |
255 | } | 258 | } |
256 | } | 259 | } |
257 | } | 260 | } |
258 | 261 | ||
@@ -266,25 +269,25 @@ void VMemo::mousePressEvent( QMouseEvent * ) | |||
266 | { | 269 | { |
267 | startRecording(); | 270 | startRecording(); |
268 | } | 271 | } |
269 | 272 | ||
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" ); |
287 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); | 290 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); |
288 | msgLabel->show(); | 291 | msgLabel->show(); |
289 | } | 292 | } |
290 | 293 | ||
@@ -309,41 +312,42 @@ bool VMemo::startRecording() { | |||
309 | 312 | ||
310 | QDateTime dt = QDateTime::currentDateTime(); | 313 | QDateTime dt = QDateTime::currentDateTime(); |
311 | 314 | ||
312 | QString fName; | 315 | QString fName; |
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); |
346 | 350 | ||
347 | QString dlName("vm_"); | 351 | QString dlName("vm_"); |
348 | dlName += dt.toString(); | 352 | dlName += dt.toString(); |
349 | DocLnk l; | 353 | DocLnk l; |
@@ -351,52 +355,58 @@ bool VMemo::startRecording() { | |||
351 | l.setName(dlName); | 355 | l.setName(dlName); |
352 | l.setType("audio/x-wav"); | 356 | l.setType("audio/x-wav"); |
353 | l.setCategories(cats); | 357 | l.setCategories(cats); |
354 | l.writeLink(); | 358 | l.writeLink(); |
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); |
375 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 385 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
376 | if (cfg.readNumEntry("SixteenBit", 1)==1) { | 386 | if (cfg.readNumEntry("SixteenBit", 1)==1) { |
377 | format = AFMT_S16_LE; | 387 | format = AFMT_S16_LE; |
378 | resolution = 16; | 388 | resolution = 16; |
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 | } |
399 | 409 | ||
400 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { | 410 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { |
401 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 411 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
402 | return -1; | 412 | return -1; |
@@ -556,34 +566,35 @@ void VMemo::record(void) | |||
556 | 566 | ||
557 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// | 567 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// |
558 | 568 | ||
559 | value = length+36; | 569 | value = length+36; |
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 | ||
586 | } | 597 | } |
587 | 598 | ||
588 | int VMemo::setToggleButton(int tog) { | 599 | int VMemo::setToggleButton(int tog) { |
589 | 600 | ||