-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 | |||
@@ -225,81 +225,95 @@ VMemo::VMemo( QWidget *parent, const char *_name ) | |||
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 ) |
@@ -318,72 +332,84 @@ bool VMemo::startRecording() { | |||
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 | } |
@@ -618,34 +644,34 @@ int VMemo::setToggleButton(int tog) { | |||
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 | } |