-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 @@ -161,293 +161,319 @@ static char * vmemo_xpm[] = { "S c #6E6E74", "T c #95959C", "U c #74747A", "V c #1D1D1E", "W c #91929A", "X c #42444A", "Y c #22282E", "Z c #B0B2BC", "` c #898A90", " . c #65656A", ".. c #999AA2", "+. c #52535A", "@. c #151B21", "#. c #515257", "$. c #B5B5BE", "%. c #616167", "&. c #1A1D22", "*. c #000713", "=. c #1F1F21", " ", " . + @ # ", " $ % & * = - ", " ; > , ' ) ! ~ ", " { ] ^ / ( _ : ", " < [ } | 1 2 3 ", " 4 5 6 7 8 9 0 a b c ", " d e f g h i j 3 k l m n ", " o p q r s t u v w n ", " o x y z A B C D E n ", " F G H I J K L M N O ", " P Q R S T U V W X ", " Y Z ` b ...+. ", " @.#.$.%.&. ", " *.B =. ", " n n n n n n n n n "}; VMemo::VMemo( QWidget *parent, const char *_name ) : QWidget( parent, _name ) { setFixedHeight( 18 ); setFixedWidth( 14 ); recording = FALSE; t_timer = new QTimer( this ); connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) ); struct utsname name; /* check for embedix kernel running on the zaurus*/ if (uname(&name) != -1) { QString release=name.release; Config vmCfg("Vmemo"); vmCfg.setGroup("Defaults"); int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); qDebug("toggleKey %d", toggleKey); if(release.find("embedix",0,TRUE) !=-1) systemZaurus=TRUE; else systemZaurus=FALSE; myChannel = new QCopChannel( "QPE/VMemo", this ); connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); if( toggleKey != -1 ) { // QPEApplication::grabKeyboard(); QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); // e << 4096; // Key_Escape // e << Key_F5; //4148 e << toggleKey; e << QString("QPE/VMemo"); e << QString("toggleRecord()"); } if(toggleKey == 1) usingIcon=TRUE; else 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; - stopRecording(); + 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 * ) +void VMemo::mousePressEvent( QMouseEvent * me) { - if(!recording) + // just to be safe + if (recording) { + recording = FALSE; + return; + } + /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions + mousePressEvent and mouseReleaseEvent with a NULL parameter. */ + if ( me->button() != LeftButton) + + // if (!systemZaurus && me != NULL) + return; + + if(!recording) startRecording(); else stopRecording(); } void VMemo::mouseReleaseEvent( QMouseEvent * ) { // if(usingIcon && !recording) // stopRecording(); } bool VMemo::startRecording() { if ( recording) return FALSE; Config config( "Vmemo" ); config.setGroup( "System" ); useAlerts = config.readBoolEntry("Alert",1); if(useAlerts) { msgLabel = new QLabel( 0, "alertLabel" ); msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); msgLabel->show(); } // if(useAlerts) // QMessageBox::message("VMemo","Really Record?");//) ==1) // return; // } else { // if (!systemZaurus ) // QSound::play(Resource::findSound("vmemob")); // } qDebug("Start recording engines"); recording = TRUE; if (openDSP() == -1) { // QMessageBox::critical(0, "vmemo", "Could not open dsp device.\n"+errorMsg, "Abort"); // delete msgLabel; recording = FALSE; msgLabel=0; delete msgLabel; return FALSE; } config.setGroup("Defaults"); QDateTime dt = QDateTime::currentDateTime(); QString fName; config.setGroup( "System" ); fName = QPEApplication::documentDir() ; fileName = config.readEntry("RecLocation", fName); int s; 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(","),""); - if(openWAV(fileName.latin1()) == -1) { - // QString err("Could not open the output file\n"); - // err += fileName; - // QMessageBox::critical(0, "vmemo", err, "Abort"); - close(dsp); +// 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; } - + 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(); record(); return TRUE; } void VMemo::stopRecording() { show(); qDebug("Stopped recording"); recording = FALSE; if(useAlerts) { msgLabel->close(); msgLabel=0; delete msgLabel; } t_timer->stop(); Config cfg("Vmemo"); cfg.setGroup("Defaults"); if( cfg.readNumEntry("hideIcon",0) == 1 ) hide(); } int VMemo::openDSP() { Config cfg("Vmemo"); cfg.setGroup("Record"); speed = cfg.readNumEntry("SampleRate", 22050); channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) if (cfg.readNumEntry("SixteenBit", 1)==1) { format = AFMT_S16_LE; resolution = 16; } else { format = AFMT_U8; resolution = 8; } qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); if(systemZaurus) { dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 channels=1; //zaurus has one input channel } else { dsp = open("/dev/dsp", O_RDONLY); } if(dsp == -1) { perror("open(\"/dev/dsp\")"); errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); return -1; } if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); return -1; } if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); return -1; } if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { perror("ioctl(\"SNDCTL_DSP_SPEED\")"); return -1; } if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { perror("ioctl(\"SOUND_PCM_READ_RATE\")"); return -1; } QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute return 1; } int VMemo::openWAV(const char *filename) { track.setName(filename); if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { errorMsg=filename; return -1; } wav=track.handle(); @@ -554,98 +580,98 @@ void VMemo::record(void) signed short sound[1024];//, monoBuffer[512]; while(recording) { result = read(dsp, sound, 1024); // 8192 write(wav, sound, result); length += result; if(length<0) { recording=false; perror("dev/dsp's is a lookin' messy"); QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); } // 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 } //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// value = length+36; lseek(wav, 4, SEEK_SET); write(wav, &value, 4); lseek(wav, 40, SEEK_SET); write(wav, &length, 4); track.close(); qDebug("Track closed"); if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) perror("ioctl(\"SNDCTL_DSP_RESET\")"); ::close(dsp); 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 } int VMemo::setToggleButton(int tog) { for( int i=0; i < 10;i++) { switch (tog) { case 0: return -1; break; case 1: return 0; break; case 2: return Key_Escape; break; case 3: return Key_Space; break; case 4: return Key_F12; break; case 5: return Key_F9; break; case 6: return Key_F10; break; case 7: return Key_F11; break; case 8: return Key_F13; break; }; } return -1; } void VMemo::timerBreak() { //stop stopRecording(); - QMessageBox::message("Vmemo","Vmemo recording has \ntimed out"); + QMessageBox::message("Vmemo","Vmemo recording has ended"); } |