author | schurig <schurig> | 2004-09-10 12:18:17 (UTC) |
---|---|---|
committer | schurig <schurig> | 2004-09-10 12:18:17 (UTC) |
commit | 9d0ccc1c5ca687bc017b2b515a9d3a47e98ce521 (patch) (side-by-side diff) | |
tree | 53927c6a19c69d54bb3d0e092ac57180bcb60222 | |
parent | ed70ec4945c7816ec6e899207ec8b99e20e10da5 (diff) | |
download | opie-9d0ccc1c5ca687bc017b2b515a9d3a47e98ce521.zip opie-9d0ccc1c5ca687bc017b2b515a9d3a47e98ce521.tar.gz opie-9d0ccc1c5ca687bc017b2b515a9d3a47e98ce521.tar.bz2 |
added support for DEVFS
-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 10 | ||||
-rw-r--r-- | core/applets/vtapplet/vt.cpp | 8 | ||||
-rw-r--r-- | libopie/odevice.cpp | 4 | ||||
-rw-r--r-- | libopie2/opiemm/osoundsystem.cpp | 5 | ||||
-rw-r--r-- | library/qpeapplication.cpp | 16 |
5 files changed, 40 insertions, 3 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index e747a19..07ef15c 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp @@ -350,140 +350,144 @@ bool VMemo::startRecording() { if( record() ) { QString cmd; if( fileName.find(".wav",0,TRUE) == -1) fileName += ".wav"; 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 += date; 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(); odebug << "Stopped recording" << oendl; 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; } odebug << "samplerate: " << speed << ", channels " << channels << ", resolution " << resolution << "" << oendl; if(systemZaurus) { dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 channels=1; //zaurus has one input channel } else { +#ifdef QT_QWS_DEVFS + dsp = open("/dev/sound/dsp", O_RDONLY); +#else dsp = open("/dev/dsp", O_RDONLY); +#endif } - if(dsp == -1) { + if (dsp == -1) { msgLabel->close(); msgLabel=0; delete msgLabel; perror("open(\"/dev/dsp\")"); errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); - QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); - return -1; + 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(); Config vmCfg("Vmemo"); vmCfg.setGroup("Defaults"); useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); WaveHeader wh; wh.main_chunk = RIFF; wh.length=0; wh.chunk_type = WAVE; wh.sub_chunk = FMT; wh.sc_len = 16; if(useADPCM) wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; else wh.format = PCM_CODE; wh.modus = channels; wh.sample_fq = speed; 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; // odebug << "Write header channels " << wh.modus << ", speed " << wh.sample_fq << ", b/s " // << wh.byte_p_sec << ", blockalign " << wh.byte_p_spl << ", bitrate " << wh.bit_p_spl << oendl; write (wav, &wh, sizeof(WaveHeader)); return 1; } bool VMemo::record() { length = 0; int bytesWritten = 0; diff --git a/core/applets/vtapplet/vt.cpp b/core/applets/vtapplet/vt.cpp index aec63c3..7832ee0 100644 --- a/core/applets/vtapplet/vt.cpp +++ b/core/applets/vtapplet/vt.cpp @@ -19,146 +19,154 @@ using namespace Opie::Core; /* QT */ #include <qpopupmenu.h> /* STD */ #include <fcntl.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <linux/vt.h> VTApplet::VTApplet ( ) : QObject ( 0, "VTApplet" ) { } VTApplet::~VTApplet ( ) { } int VTApplet::position ( ) const { return 2; } QString VTApplet::name ( ) const { return tr( "VT shortcut" ); } QString VTApplet::text ( ) const { return tr( "Terminal" ); } /* QString VTApplet::tr( const char* s ) const { return qApp->translate( "VTApplet", s, 0 ); } QString VTApplet::tr( const char* s, const char* p ) const { return qApp->translate( "VTApplet", s, p ); } */ QIconSet VTApplet::icon ( ) const { QPixmap pix; QImage img = Resource::loadImage ( "terminal" ); if ( !img. isNull ( )) pix. convertFromImage ( img. smoothScale ( 14, 14 )); return pix; } QPopupMenu *VTApplet::popup ( QWidget* parent ) const { odebug << "VTApplet::popup" << oendl; struct vt_stat vtstat; +#ifdef QT_QWS_DEVFS + int fd = ::open( "/dev/vc/0", O_RDWR ); +#else int fd = ::open( "/dev/tty0", O_RDWR ); +#endif if ( fd == -1 ) return 0; if ( ioctl( fd, VT_GETSTATE, &vtstat ) == -1 ) return 0; m_subMenu = new QPopupMenu( parent ); m_subMenu->setCheckable( true ); for ( int i = 1; i < 10; ++i ) { int id = m_subMenu->insertItem( QString::number( i ), 500+i ); m_subMenu->setItemChecked( id, id-500 == vtstat.v_active ); } ::close( fd ); connect( m_subMenu, SIGNAL( activated(int) ), this, SLOT( changeVT(int) ) ); connect( m_subMenu, SIGNAL( aboutToShow() ), this, SLOT( updateMenu() ) ); return m_subMenu; } void VTApplet::changeVT( int index ) { //odebug << "VTApplet::changeVT( " << index-500 << " )" << oendl; +#ifdef QT_QWS_DEVFS + int fd = ::open("/dev/vc/0", O_RDWR); +#else int fd = ::open("/dev/tty0", O_RDWR); +#endif if ( fd == -1 ) return; ioctl( fd, VT_ACTIVATE, index-500 ); } void VTApplet::updateMenu() { //odebug << "VTApplet::updateMenu()" << oendl; int fd = ::open( "/dev/console", O_RDONLY ); if ( fd == -1 ) return; for ( int i = 1; i < 10; ++i ) { int result = ioctl( fd, VT_DISALLOCATE, i ); /* if ( result == -1 ) odebug << "VT " << i << " disallocated == free" << oendl; else odebug << "VT " << i << " _not_ disallocated == busy" << oendl; */ m_subMenu->setItemEnabled( 500+i, result == -1 ); } ::close( fd ); } void VTApplet::activated() { odebug << "VTApplet::activated()" << oendl; } QRESULT VTApplet::queryInterface ( const QUuid &uuid, QUnknownInterface **iface ) { *iface = 0; if ( uuid == IID_QUnknown ) *iface = this; else if ( uuid == IID_MenuApplet ) *iface = this; else return QS_FALSE; if ( *iface ) (*iface)-> addRef ( ); return QS_OK; } Q_EXPORT_INTERFACE( ) { Q_CREATE_INSTANCE( VTApplet ) } diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index 21070bf..9d0bbbf 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp @@ -534,129 +534,133 @@ bool ODevice::setSoftSuspend ( bool /*soft*/ ) * This method will try to suspend the device * It only works if the user is the QWS Server and the apm application * is installed. * It tries to suspend and then waits some time cause some distributions * do have asynchronus apm implementations. * This method will either fail and return false or it'll suspend the * device and return once the device got woken up * * @return if the device got suspended */ bool ODevice::suspend ( ) { qDebug("ODevice::suspend"); if ( !isQWS( ) ) // only qwsserver is allowed to suspend return false; if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices return false; bool res = false; struct timeval tvs, tvn; ::gettimeofday ( &tvs, 0 ); ::sync ( ); // flush fs caches res = ( ::system ( "apm --suspend" ) == 0 ); // This is needed because the iPAQ apm implementation is asynchronous and we // can not be sure when exactly the device is really suspended // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. if ( res ) { do { // wait at most 1.5 sec: either suspend didn't work or the device resumed ::usleep ( 200 * 1000 ); ::gettimeofday ( &tvn, 0 ); } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); } return res; } //#include <linux/fb.h> better not rely on kernel headers in userspace ... #define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 /* VESA Blanking Levels */ #define VESA_NO_BLANKING 0 #define VESA_VSYNC_SUSPEND 1 #define VESA_HSYNC_SUSPEND 2 #define VESA_POWERDOWN 3 /** * This sets the display on or off */ bool ODevice::setDisplayStatus ( bool on ) { qDebug("ODevice::setDisplayStatus(%d)", on); if ( d-> m_model == Model_Unknown ) return false; bool res = false; int fd; +#ifdef QT_QWS_DEVFS + if (( fd = ::open ( "/dev/fb/0", O_RDWR )) >= 0 ) { +#else if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { +#endif res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); ::close ( fd ); } return res; } /** * This sets the display brightness * * @param p The brightness to be set on a scale from 0 to 255 * @return success or failure */ bool ODevice::setDisplayBrightness ( int p) { Q_UNUSED( p ) return false; } /** * @return returns the number of steppings on the brightness slider * in the Light-'n-Power settings. */ int ODevice::displayBrightnessResolution ( ) const { return 16; } /** * This sets the display contrast * @param p The contrast to be set on a scale from 0 to 255 * @return success or failure */ bool ODevice::setDisplayContrast ( int p) { Q_UNUSED( p ) return false; } /** * @return return the max value for the brightness settings slider * or 0 if the device doesn't support setting of a contrast */ int ODevice::displayContrastResolution ( ) const { return 0; } /** * This returns the vendor as string * @return Vendor as QString */ QString ODevice::vendorString ( ) const { return d-> m_vendorstr; } /** * This returns the vendor as one of the values of OVendor * @return OVendor */ OVendor ODevice::vendor ( ) const { return d-> m_vendor; } diff --git a/libopie2/opiemm/osoundsystem.cpp b/libopie2/opiemm/osoundsystem.cpp index 763ff65..17e5cb0 100644 --- a/libopie2/opiemm/osoundsystem.cpp +++ b/libopie2/opiemm/osoundsystem.cpp @@ -76,130 +76,135 @@ void OSoundSystem::synchronize() return; } QTextStream s( &f ); s.readLine(); s.readLine(); while ( !s.atEnd() ) { s >> str; str.truncate( str.find( ':' ) ); odebug << "OSoundSystem: found interface '" << str << "'" << oendl; OAudioInterface* iface; iface = new OAudioInterface( this, (const char*) str ); _interfaces.insert( str, iface ); s.readLine(); } */ } int OSoundSystem::count() const { return _interfaces.count(); } OSoundCard* OSoundSystem::card( const QString& iface ) const { return _interfaces[iface]; } OSoundSystem* OSoundSystem::instance() { if ( !_instance ) _instance = new OSoundSystem(); return _instance; } OSoundSystem::CardIterator OSoundSystem::iterator() const { return OSoundSystem::CardIterator( _interfaces ); } /*====================================================================================== * OSoundCard *======================================================================================*/ OSoundCard::OSoundCard( QObject* parent, const char* name ) :QObject( parent, name ), _audio( 0 ), _mixer( 0 ) { odebug << "OSoundCard::OSoundCard()" << oendl; init(); } OSoundCard::~OSoundCard() { } void OSoundCard::init() { +#ifdef QT_QWS_DEVFS + _audio = new OAudioInterface( this, "/dev/sound/dsp" ); + _mixer = new OMixerInterface( this, "/dev/sound/mixer" ); +#else _audio = new OAudioInterface( this, "/dev/dsp" ); _mixer = new OMixerInterface( this, "/dev/mixer" ); +#endif } /*====================================================================================== * OAudioInterface *======================================================================================*/ OAudioInterface::OAudioInterface( QObject* parent, const char* name ) :QObject( parent, name ), _sfd(0) { odebug << "OAudioInterface::OAudioInterface()" << oendl; init(); } OAudioInterface::~OAudioInterface() { } void OAudioInterface::init() { } /*====================================================================================== * OMixerInterface *======================================================================================*/ OMixerInterface::OMixerInterface( QObject* parent, const char* name ) :QObject( parent, name ) { odebug << "OMixerInterface::OMixerInterface()" << oendl; init(); } OMixerInterface::~OMixerInterface() { } void OMixerInterface::init() { // open the device _fd = ::open( name(), O_RDWR ); if ( _fd == -1 ) { owarn << "OMixerInterface::init(): Can't open mixer." << oendl; return; } // construct the device capabilities int devmask = 0; if ( ioctl( _fd, SOUND_MIXER_READ_DEVMASK, &devmask ) != -1 ) { if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "PlayVolume", SOUND_MIXER_VOLUME ); if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "PlayBass", SOUND_MIXER_BASS ); if ( devmask & ( 1 << SOUND_MIXER_TREBLE ) ) _channels.insert( "PlayTreble", SOUND_MIXER_TREBLE ); if ( devmask & ( 1 << SOUND_MIXER_SYNTH ) ) _channels.insert( "PlaySynth", SOUND_MIXER_SYNTH ); if ( devmask & ( 1 << SOUND_MIXER_PCM ) ) _channels.insert( "PlayPCM", SOUND_MIXER_PCM ); if ( devmask & ( 1 << SOUND_MIXER_SPEAKER ) ) _channels.insert( "PlaySpeaker", SOUND_MIXER_SPEAKER ); diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp index c6d9cfd..ca90427 100644 --- a/library/qpeapplication.cpp +++ b/library/qpeapplication.cpp @@ -504,200 +504,216 @@ static void qpe_show_dialog( QDialog* d, bool nomax ) }; class ResourceMimeFactory : public QMimeSourceFactory { public: ResourceMimeFactory() : resImage( 0 ) { setFilePath( Global::helpPath() ); setExtensionType( "html", "text/html;charset=UTF-8" ); } ~ResourceMimeFactory() { delete resImage; } const QMimeSource* data( const QString& abs_name ) const { const QMimeSource * r = QMimeSourceFactory::data( abs_name ); if ( !r ) { int sl = abs_name.length(); do { sl = abs_name.findRev( '/', sl - 1 ); QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; int dot = name.findRev( '.' ); if ( dot >= 0 ) name = name.left( dot ); QImage img = Resource::loadImage( name ); if ( !img.isNull() ) { delete resImage; resImage = new QImageDrag( img ); r = resImage; } } while ( !r && sl > 0 ); } return r; } private: mutable QImageDrag *resImage; }; static int& hack(int& i) { #if QT_VERSION <= 230 && defined(QT_NO_CODECS) // These should be created, but aren't in Qt 2.3.0 (void)new QUtf8Codec; (void)new QUtf16Codec; #endif return i; } static int muted = 0; static int micMuted = 0; static void setVolume( int t = 0, int percent = -1 ) { switch ( t ) { case 0: { Config cfg( "qpe" ); cfg.setGroup( "Volume" ); if ( percent < 0 ) percent = cfg.readNumEntry( "VolumePercent", 50 ); #ifndef QT_NO_SOUND int fd = 0; +#ifdef QT_QWS_DEVFS + if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { +#else if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { +#endif int vol = muted ? 0 : percent; // set both channels to same volume vol |= vol << 8; ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol ); ::close( fd ); } #endif } break; } } static void setMic( int t = 0, int percent = -1 ) { switch ( t ) { case 0: { Config cfg( "qpe" ); cfg.setGroup( "Volume" ); if ( percent < 0 ) percent = cfg.readNumEntry( "Mic", 50 ); #ifndef QT_NO_SOUND int fd = 0; int mic = micMuted ? 0 : percent; +#ifdef QT_QWS_DEVFS + if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { +#else if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { +#endif ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); ::close( fd ); } #endif } break; } } static void setBass( int t = 0, int percent = -1 ) { switch ( t ) { case 0: { Config cfg( "qpe" ); cfg.setGroup( "Volume" ); if ( percent < 0 ) percent = cfg.readNumEntry( "BassPercent", 50 ); #ifndef QT_NO_SOUND int fd = 0; int bass = percent; +#ifdef QT_QWS_DEVFS + if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { +#else if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { +#endif ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); ::close( fd ); } #endif } break; } } static void setTreble( int t = 0, int percent = -1 ) { switch ( t ) { case 0: { Config cfg( "qpe" ); cfg.setGroup( "Volume" ); if ( percent < 0 ) percent = cfg.readNumEntry( "TreblePercent", 50 ); #ifndef QT_NO_SOUND int fd = 0; int treble = percent; +#ifdef QT_QWS_DEVFS + if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { +#else if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { +#endif ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); ::close( fd ); } #endif } break; } } /** \class QPEApplication \brief The QPEApplication class implements various system services that are available to all Qtopia applications. Simply by using QPEApplication instead of QApplication, a standard Qt application becomes a Qtopia application. It automatically follows style changes, quits and raises, and in the case of \link docwidget.html document-oriented\endlink applications, changes the currently displayed document in response to the environment. To create a \link docwidget.html document-oriented\endlink application use showMainDocumentWidget(); to create a non-document-oriented application use showMainWidget(). The keepRunning() function indicates whether the application will continue running after it's processed the last \link qcop.html QCop\endlink message. This can be changed using setKeepRunning(). A variety of signals are emitted when certain events occur, for example, timeChanged(), clockChanged(), weekChanged(), dateFormatChanged() and volumeChanged(). If the application receives a \link qcop.html QCop\endlink message on the application's QPE/Application/\e{appname} channel, the appMessage() signal is emitted. There are also flush() and reload() signals, which are emitted when synching begins and ends respectively - upon these signals, the application should save and reload any data files that are involved in synching. Most of these signals will initially be received and unfiltered through the appMessage() signal. This class also provides a set of useful static functions. The qpeDir() and documentDir() functions return the respective paths. The grabKeyboard() and ungrabKeyboard() functions are used to control whether the application takes control of the device's physical buttons (e.g. application launch keys). The stylus' mode of operation is set with setStylusOperation() and retrieved with stylusOperation(). There are also setInputMethodHint() and inputMethodHint() functions. \ingroup qtopiaemb */ /*! \fn void QPEApplication::clientMoused() \internal */ /*! \fn void QPEApplication::timeChanged(); This signal is emitted when the time changes outside the normal passage of time, i.e. if the time is set backwards or forwards. */ /*! |