-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 44 | ||||
-rw-r--r-- | core/applets/vmemo/vmemo.h | 2 |
2 files changed, 27 insertions, 19 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index b5239eb..035965e 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp @@ -251,34 +251,36 @@ VMemo::VMemo( QWidget *parent, const char *_name ) usingIcon=FALSE; if( vmCfg.readNumEntry("hideIcon",0) == 1) hide(); } } VMemo::~VMemo() { } void VMemo::receive( const QCString &msg, const QByteArray &data ) { qDebug("receive"); QDataStream stream( data, IO_ReadOnly ); + if (msg == "toggleRecord()") { - if (recording) { - fromToggle = TRUE; - mouseReleaseEvent(NULL); -// stopRecording(); - } else { - fromToggle = TRUE; - // mousePressEvent(NULL); - startRecording(); - } + + if (recording) { + fromToggle = TRUE; + mouseReleaseEvent(NULL); + stopRecording(); + } else { + fromToggle = TRUE; + // mousePressEvent(NULL); + startRecording(); + } } } void VMemo::paintEvent( QPaintEvent* ) { QPainter p(this); p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); } void VMemo::mousePressEvent( QMouseEvent * me) { // just to be safe if (recording) { recording = FALSE; @@ -350,65 +352,67 @@ bool VMemo::startRecording() { s=fileName.find(':'); if(s) fileName=fileName.right(fileName.length()-s-2); qDebug("pathname will be "+fileName); if( fileName.left(1).find('/') == -1) fileName="/"+fileName; if( fileName.right(1).find('/') == -1) fileName+="/"; fName = "vm_"+ dt.toString()+ ".wav"; fileName+=fName; - qDebug("filename is "+fileName); // No spaces in the filename fileName.replace(QRegExp("'"),""); fileName.replace(QRegExp(" "),"_"); fileName.replace(QRegExp(":"),"."); fileName.replace(QRegExp(","),""); + qDebug("filename is "+fileName); // open tmp file here char *pointer; pointer=tmpnam(NULL); qDebug("Opening tmp file %s",pointer); if(openWAV(pointer ) == -1) { // if(openWAV(fileName.latin1()) == -1) { QString err("Could not open the temp file\n"); err += fileName; QMessageBox::critical(0, "vmemo", err, "Abort"); ::close(dsp); return FALSE; } - record(); + if( record() ) { QString cmd; cmd.sprintf("mv %s "+fileName, pointer); // move tmp file to regular file here system(cmd.latin1()); QArray<int> cats(1); cats[0] = config.readNumEntry("Category", 0); QString dlName("vm_"); dlName += dt.toString(); DocLnk l; l.setFile(fileName); l.setName(dlName); l.setType("audio/x-wav"); l.setCategories(cats); l.writeLink(); - return TRUE; + } else + return FALSE; + } void VMemo::stopRecording() { show(); qDebug("Stopped recording"); recording = FALSE; if(useAlerts) { msgLabel->close(); msgLabel=0; delete msgLabel; } t_timer->stop(); @@ -495,78 +499,82 @@ int VMemo::openWAV(const char *filename) { wh.byte_p_sec = speed * channels * resolution/8; wh.byte_p_spl = channels * (resolution / 8); wh.bit_p_spl = resolution; wh.data_chunk = DATA; wh.data_length= 0; // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); write (wav, &wh, sizeof(WaveHeader)); return 1; } -void VMemo::record(void) { - int length=0, result, value; +bool VMemo::record() { + + int length=0, result, value; QString msg; msg.sprintf("Recording format %d", format); qDebug(msg); Config config("Vmemo"); config.setGroup("Record"); int sRate=config.readNumEntry("SizeLimit", 30); - - t_timer->start( sRate * 1000+1000, TRUE); + if(sRate > 0) + t_timer->start( sRate * 1000+1000, TRUE); // if(systemZaurus) { // } else { // 16 bit only capabilities msg.sprintf("Recording format other"); qDebug(msg); int bufsize=1024; int bytesWritten=0; signed short sound[1024], monoBuffer[1024]; char abuf[bufsize/2]; short sbuf[bufsize]; while(recording) { if(useADPCM) result = read( dsp, sbuf, bufsize); // 8192 else result = read(dsp, sound, 1024); // 8192 if( result <= 0) { perror("recording error "); // qDebug(currentFileName); QMessageBox::message(tr("Note"),tr("error recording")); - recording=FALSE;; + recording=FALSE; break; + return FALSE; } if(useADPCM) { adpcm_coder( sbuf, abuf, result/2, &encoder_state); bytesWritten = ::write(wav, abuf, result/4); } else { for (int i = 0; i < result; i++) { //since Z is mono do normally monoBuffer[i] = sound[i]; } length+=write(wav, monoBuffer, result); } length +=bytesWritten; if(length<0) { recording=false; perror("dev/dsp's is a lookin' messy"); QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); + break; + return FALSE; } // printf("%d\r",length); // fflush(stdout); qApp->processEvents(); } // qDebug("file has length of %d lasting %d seconds", // length, (( length / speed) / channels) / 2 ); // medialplayer states wrong length in secs // } //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// @@ -588,25 +596,25 @@ void VMemo::record(void) { fileName = fileName.left(fileName.length()-4); // if(useAlerts) // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); qDebug("done recording "+fileName); // QSound::play(Resource::findSound("vmemoe")); Config cfg("qpe"); cfg.setGroup("Volume"); QString foo = cfg.readEntry("Mute","TRUE"); if(foo.find("TRUE",0,TRUE) != -1) QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute - +return TRUE; } int VMemo::setToggleButton(int tog) { for( int i=0; i < 10;i++) { switch (tog) { case 0: return -1; break; case 1: return 0; break; diff --git a/core/applets/vmemo/vmemo.h b/core/applets/vmemo/vmemo.h index 167af2a..9ee08ff 100644 --- a/core/applets/vmemo/vmemo.h +++ b/core/applets/vmemo/vmemo.h @@ -29,25 +29,25 @@ class VMemo : public QWidget { Q_OBJECT public: VMemo( QWidget *parent, const char *name = NULL); ~VMemo(); QFile track; QString fileName, errorMsg; QLabel* msgLabel; QTimer *t_timer; bool usingIcon, useADPCM; public slots: - void record(); + bool record(); void mousePressEvent( QMouseEvent * ); void mouseReleaseEvent( QMouseEvent * ); void receive( const QCString &msg, const QByteArray &data ); bool startRecording(); void stopRecording(); void timerBreak(); private: bool useAlerts; void paintEvent( QPaintEvent* ); int setToggleButton(int); int openDSP(); int openWAV(const char *filename); |