author | zecke <zecke> | 2004-08-25 21:51:13 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-08-25 21:51:13 (UTC) |
commit | df3e4c8b13c16aeb96e70dbaa2d409f83eed988e (patch) (side-by-side diff) | |
tree | 59b12028c6e8a53b99f1686278b6e9fdc57ab18e | |
parent | e4811064703ad34f42f15c3044cd8f63c0e7583c (diff) | |
download | opie-df3e4c8b13c16aeb96e70dbaa2d409f83eed988e.zip opie-df3e4c8b13c16aeb96e70dbaa2d409f83eed988e.tar.gz opie-df3e4c8b13c16aeb96e70dbaa2d409f83eed988e.tar.bz2 |
-Have a common implementation for reading the config value
and setting the Mixer. The mixer, sound and path
is configurable
-Restore the Opie HEADER (who is guilty? probably me)
-Fix warnings
-Port Zaurus,Simpad,Ipaq to configure the mixer
-rw-r--r-- | libopie2/opiecore/device/odevice.cpp | 57 | ||||
-rw-r--r-- | libopie2/opiecore/device/odevice.h | 55 | ||||
-rw-r--r-- | libopie2/opiecore/device/odevice_ipaq.cpp | 71 | ||||
-rw-r--r-- | libopie2/opiecore/device/odevice_simpad.cpp | 47 | ||||
-rw-r--r-- | libopie2/opiecore/device/odevice_simpad.h | 2 | ||||
-rw-r--r-- | libopie2/opiecore/device/odevice_yopy.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiecore/device/odevice_zaurus.cpp | 99 |
7 files changed, 158 insertions, 175 deletions
diff --git a/libopie2/opiecore/device/odevice.cpp b/libopie2/opiecore/device/odevice.cpp index b58f9eb..26c6dca 100644 --- a/libopie2/opiecore/device/odevice.cpp +++ b/libopie2/opiecore/device/odevice.cpp @@ -44,8 +44,9 @@ #include <qpe/config.h> #include <qpe/resource.h> #include <qpe/sound.h> #include <qpe/qcopenvelope_qws.h> +#include <qpe/sound.h> #include <opie2/okeyfilter.h> /* STD */ #include <fcntl.h> @@ -170,8 +171,12 @@ ODevice::ODevice() d->m_holdtime = 1000; // 1000ms d->m_buttons = 0; d->m_cpu_frequencies = new QStrList; + + /* mixer */ + d->m_sound = d->m_vol = d->m_mixer = -1; + // New distribution detection code first checks for legacy distributions, // identified by /etc/familiar-version or /etc/oz_version. // Then check for OpenEmbedded and lastly, read /etc/issue @@ -704,25 +709,77 @@ void ODevice::remapHeldAction ( int button, const OQCopMessage &action ) void ODevice::virtual_hook(int, void* ){ } +/** + * Sends a QCOP message to channel QPE/System + * with the message "aboutToSuspend()" if this + * is the windowing server + */ void ODevice::sendSuspendmsg() { if ( isQWS() ) return; QCopEnvelope ( "QPE/System", "aboutToSuspend()" ); } +/** + * \brief Prepend the QWSServer::KeyboardFilter to the list of installed KeyFilters + * + * Prepend a QWSServer::KeyboardFilter to the List of Keyboard + * Filters. This function is the only way to prepend a KeyFilter. + * + * @param aFilter The KeyFilter to be prepended to the list of filters + * + * @see Opie::Core::OKeyFilter + * @see Opie::Core::OKeyFilter::inst() + */ void ODevice::addPreHandler(QWSServer::KeyboardFilter*aFilter) { Opie::Core::OKeyFilter::inst()->addPreHandler(aFilter); } +/** + * \brief Remove the QWSServer::KeyboardFilter in the param from the list + * + * Remove the QWSServer::KeyboardFilter \par aFilter from the List + * of Keyfilters. Call this when you delete the KeyFilter! + * + * @param aFilter The filter to be removed from the Opie::Core::OKeyFilter + * @see Opie::Core::ODevice::addPreHandler + */ void ODevice::remPreHandler(QWSServer::KeyboardFilter*aFilter) { Opie::Core::OKeyFilter::inst()->remPreHandler(aFilter); } +void ODevice::playingStopped() { + const_cast<QObject*>(sender())->disconnect( this ); + if ( d->m_sound >= 0 ) { + ::ioctl ( d->m_sound, MIXER_WRITE( d->m_mixer ), &d->m_vol ); + ::close ( d->m_sound ); + } +} + +void ODevice::changeMixerForAlarm( int mixer, const char* file, Sound *snd ) { + if (( d->m_sound = ::open ( file, O_RDWR )) >= 0 ) { + if ( ::ioctl ( d->m_sound, MIXER_READ( mixer ), &d->m_vol ) >= 0 ) { + Config cfg ( "qpe" ); + cfg. setGroup ( "Volume" ); + + int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); + if ( volalarm < 0 ) + volalarm = 0; + else if ( volalarm > 100 ) + volalarm = 100; + volalarm |= ( volalarm << 8 ); + + if ( ::ioctl ( d->m_sound, MIXER_WRITE( mixer ), &volalarm ) >= 0 ) + register_qpe_sound_finished(snd, this, SLOT(playingStopped())); + } + d->m_mixer = mixer; + } +} } } diff --git a/libopie2/opiecore/device/odevice.h b/libopie2/opiecore/device/odevice.h index cb7a83f..f4b3e0e 100644 --- a/libopie2/opiecore/device/odevice.h +++ b/libopie2/opiecore/device/odevice.h @@ -1,28 +1,28 @@ /* - This file is part of the Opie Project - Copyright (C) The Opie Team <opie-devel@handhelds.org> + This file is part of the Opie Project + Copyright (C) The Opie Team <opie-devel@handhelds.org> =. .=l. - .>+-= -_;:, .> :=|. This program is free software; you can -.> <`_, > . <= redistribute it and/or modify it under -:`=1 )Y*s>-.-- : the terms of the GNU Library General Public -.="- .-=="i, .._ License as published by the Free Software -- . .-<_> .<> Foundation; either version 2 of the License, - ._= =} : or (at your option) any later version. - .%`+i> _;_. - .i_,=:_. -<s. This program is distributed in the hope that - + . -:. = it will be useful, but WITHOUT ANY WARRANTY; - : .. .:, . . . without even the implied warranty of - =_ + =;=|` MERCHANTABILITY or FITNESS FOR A - _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU -..}^=.= = ; Library General Public License for more -++= -. .` .: details. -: = ...= . :.=- --. .:....=;==+<; You should have received a copy of the GNU - -_. . . )=. = Library General Public License along with - -- :-=` this library; see the file COPYING.LIB. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ @@ -37,15 +37,20 @@ _;:, .> :=|. This program is free software; you can /* QT */ #include <qnamespace.h> #include <qobject.h> #include <qstring.h> + + #include <qstrlist.h> #include <qwindowsystem_qws.h> + +class Sound; + namespace Opie{ namespace Core{ - class ODeviceData; +class ODeviceData; /** * The available devices */ enum OModel { @@ -318,13 +323,16 @@ signals: void buttonMappingChanged(); private slots: void systemMessage ( const QCString &, const QByteArray & ); + void playingStopped(); protected: void addPreHandler(QWSServer::KeyboardFilter*aFilter); void remPreHandler(QWSServer::KeyboardFilter*aFilter); void reloadButtonMapping(); + void changeMixerForAlarm( int mixer, const char* file, Sound *snd); + /* ugly virtual hook */ virtual void virtual_hook( int id, void* data ); }; @@ -347,8 +355,11 @@ class ODeviceData { QValueList <ODeviceButton> *m_buttons; uint m_holdtime; QStrList *m_cpu_frequencies; + + /* values for changeMixerForAlarm */ + int m_sound, m_vol, m_mixer; }; extern bool isQWS(); extern QCString makeChannel ( const char *str ); diff --git a/libopie2/opiecore/device/odevice_ipaq.cpp b/libopie2/opiecore/device/odevice_ipaq.cpp index 21fed99..7f5aa7b 100644 --- a/libopie2/opiecore/device/odevice_ipaq.cpp +++ b/libopie2/opiecore/device/odevice_ipaq.cpp @@ -1,28 +1,28 @@ /* - This file is part of the Opie Project - Copyright (C) The Opie Team <opie-devel@handhelds.org> + This file is part of the Opie Project + Copyright (C) 2002,2003,2004 The Opie Team <opie-devel@handhelds.org> =. .=l. - .>+-= -_;:, .> :=|. This program is free software; you can -.> <`_, > . <= redistribute it and/or modify it under -:`=1 )Y*s>-.-- : the terms of the GNU Library General Public -.="- .-=="i, .._ License as published by the Free Software -- . .-<_> .<> Foundation; either version 2 of the License, - ._= =} : or (at your option) any later version. - .%`+i> _;_. - .i_,=:_. -<s. This program is distributed in the hope that - + . -:. = it will be useful, but WITHOUT ANY WARRANTY; - : .. .:, . . . without even the implied warranty of - =_ + =;=|` MERCHANTABILITY or FITNESS FOR A - _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU -..}^=.= = ; Library General Public License for more -++= -. .` .: details. -: = ...= . :.=- --. .:....=;==+<; You should have received a copy of the GNU - -_. . . )=. = Library General Public License along with - -- :-=` this library; see the file COPYING.LIB. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ @@ -330,38 +330,11 @@ void iPAQ::timerEvent ( QTimerEvent * ) void iPAQ::playAlarmSound() { #ifndef QT_NO_SOUND static Sound snd ( "alarm" ); - int fd; - int vol; - bool vol_reset = false; - - if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { - if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { - Config cfg ( "qpe" ); - cfg. setGroup ( "Volume" ); - - int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); - if ( volalarm < 0 ) - volalarm = 0; - else if ( volalarm > 100 ) - volalarm = 100; - volalarm |= ( volalarm << 8 ); - - if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) - vol_reset = true; - } - } + changeMixerForAlarm(0, "/dev/sound/mixer", &snd ); snd. play(); - while ( !snd. isFinished()) - qApp->processEvents(); - - if ( fd >= 0 ) { - if ( vol_reset ) - ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); - ::close ( fd ); - } #endif } diff --git a/libopie2/opiecore/device/odevice_simpad.cpp b/libopie2/opiecore/device/odevice_simpad.cpp index c6de614..2d0160d 100644 --- a/libopie2/opiecore/device/odevice_simpad.cpp +++ b/libopie2/opiecore/device/odevice_simpad.cpp @@ -237,18 +237,19 @@ bool SIMpad::setLedState ( OLed l, OLedState st ) && with SIMPAD_LED2_ON write to cs3 */ m_leds [0] = st; return true; - } - } - } - + // } +// } +#else + Q_UNUSED( l ) + Q_UNUSED( st ) #endif return false; } -bool SIMpad::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) +bool SIMpad::filter ( int /*unicode*/, int /*keycode*/, int /*modifiers*/, bool /*isPress*/, bool /*autoRepeat*/ ) { //TODO return false; } @@ -265,38 +266,12 @@ void SIMpad::timerEvent ( QTimerEvent * ) void SIMpad::playAlarmSound() { #ifndef QT_NO_SOUND static Sound snd ( "alarm" ); - int fd; - int vol; - bool vol_reset = false; - - if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { - if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { - Config cfg ( "qpe" ); - cfg. setGroup ( "Volume" ); - - int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); - if ( volalarm < 0 ) - volalarm = 0; - else if ( volalarm > 100 ) - volalarm = 100; - volalarm |= ( volalarm << 8 ); - - if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) - vol_reset = true; - } - } + /* save as the Sound is static! */ + changeMixerForAlarm( 0, "/dev/sound/mixer" , &snd); snd. play(); - while ( !snd. isFinished()) - qApp->processEvents(); - - if ( fd >= 0 ) { - if ( vol_reset ) - ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); - ::close ( fd ); - } #endif } @@ -334,16 +309,12 @@ bool SIMpad::setSoftSuspend ( bool soft ) bool SIMpad::setDisplayStatus ( bool on ) { qDebug( "ODevice for SIMpad: setDisplayStatus(%s)", on? "on" : "off" ); - bool res = false; - int fd; QString cmdline = QString().sprintf( "echo %s > /proc/cs3", on ? "0xd41a" : "0xd40a" ); //TODO make better :) - res = ( ::system( (const char*) cmdline ) == 0 ); - - return res; + return ( ::system( (const char*) cmdline ) == 0 ); } bool SIMpad::setDisplayBrightness ( int bright ) diff --git a/libopie2/opiecore/device/odevice_simpad.h b/libopie2/opiecore/device/odevice_simpad.h index d9ae5a5..6c42be7 100644 --- a/libopie2/opiecore/device/odevice_simpad.h +++ b/libopie2/opiecore/device/odevice_simpad.h @@ -1,7 +1,7 @@ /* This file is part of the Opie Project - Copyright (C) The Opie Team <opie-devel@handhelds.org> + Copyright (C) 2003, 2004 The Opie Team <opie-devel@handhelds.org> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can diff --git a/libopie2/opiecore/device/odevice_yopy.cpp b/libopie2/opiecore/device/odevice_yopy.cpp index 223aa76..a06d7ec 100644 --- a/libopie2/opiecore/device/odevice_yopy.cpp +++ b/libopie2/opiecore/device/odevice_yopy.cpp @@ -142,8 +142,10 @@ bool Yopy::setDisplayBrightness( int bright ) ::close( fd ); return true; } } +#else + Q_UNUSED( bright ) #endif return false; } diff --git a/libopie2/opiecore/device/odevice_zaurus.cpp b/libopie2/opiecore/device/odevice_zaurus.cpp index 47682bb..127fee9 100644 --- a/libopie2/opiecore/device/odevice_zaurus.cpp +++ b/libopie2/opiecore/device/odevice_zaurus.cpp @@ -1,28 +1,28 @@ /* - This file is part of the Opie Project - Copyright (C) The Opie Team <opie-devel@handhelds.org> + This file is part of the Opie Project + Copyright (C) The Opie Team <opie-devel@handhelds.org> =. .=l. - .>+-= -_;:, .> :=|. This program is free software; you can -.> <`_, > . <= redistribute it and/or modify it under -:`=1 )Y*s>-.-- : the terms of the GNU Library General Public -.="- .-=="i, .._ License as published by the Free Software -- . .-<_> .<> Foundation; either version 2 of the License, - ._= =} : or (at your option) any later version. - .%`+i> _;_. - .i_,=:_. -<s. This program is distributed in the hope that - + . -:. = it will be useful, but WITHOUT ANY WARRANTY; - : .. .:, . . . without even the implied warranty of - =_ + =;=|` MERCHANTABILITY or FITNESS FOR A - _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU -..}^=.= = ; Library General Public License for more -++= -. .` .: details. -: = ...= . :.=- --. .:....=;==+<; You should have received a copy of the GNU - -_. . . )=. = Library General Public License along with - -- :-=` this library; see the file COPYING.LIB. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ @@ -182,10 +182,8 @@ void Zaurus::init(const QString& cpu_info) d->m_modelstr = "Unkown Zaurus"; } // set initial rotation - - bool flipstate = false; switch ( d->m_model ) { case Model_Zaurus_SL6000: case Model_Zaurus_SLA300: d->m_rotation = Rot0; @@ -317,66 +315,37 @@ int status; /* set new led status if you call SHARP_LED_SETSTATUS */ void Zaurus::buzzer ( int sound ) { #ifndef QT_NO_SOUND - QString soundname; + Sound *snd = 0; // Not all devices have real sound if ( d->m_model == Model_Zaurus_SLC7x0 || d->m_model == Model_Zaurus_SLB600 ){ switch ( sound ){ - case SHARP_BUZ_SCHEDULE_ALARM: - soundname = "alarm"; - break; case SHARP_BUZ_TOUCHSOUND: - soundname = "touchsound"; + static Sound touch_sound("touchsound"); + snd = &touch_sound; break; case SHARP_BUZ_KEYSOUND: - soundname = "keysound"; + static Sound key_sound( "keysound" ); + snd = &key_sound; break; + case SHARP_BUZ_SCHEDULE_ALARM: default: - soundname = "alarm"; - + static Sound alarm_sound("alarm"); + snd = &alarm_sound; + break; } } // If a soundname is defined, we expect that this device has // sound capabilities.. Otherwise we expect to have the buzzer // device.. - if ( !soundname.isEmpty() ){ - int fd; - int vol; - bool vol_reset = false; - - Sound snd ( soundname ); - - if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { - if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { - Config cfg ( "qpe" ); - cfg. setGroup ( "Volume" ); - - int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); - if ( volalarm < 0 ) - volalarm = 0; - else if ( volalarm > 100 ) - volalarm = 100; - volalarm |= ( volalarm << 8 ); - - if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) - vol_reset = true; - } - } - - snd. play(); - while ( !snd. isFinished()) - qApp->processEvents(); - - if ( fd >= 0 ) { - if ( vol_reset ) - ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); - ::close ( fd ); - } + if ( snd ){ + changeMixerForAlarm( 0, "/dev/sound/mixer", snd ); + snd-> play(); } else { int fd = ::open ( "/dev/sharp_buz", O_WRONLY|O_NONBLOCK ); if ( fd >= 0 ) { @@ -513,9 +482,9 @@ bool Zaurus::setDisplayBrightness ( int bright ) //qDebug( "using special treatment for devices with the corgi backlight interface" ); // special treatment for devices with the corgi backlight interface if (( fd = ::open ( "/proc/driver/fl/corgi-bl", O_WRONLY )) >= 0 ) { - int value = ( bright == 1 ) ? 1 : bright * ( 17.0 / 255.0 ); + int value = ( bright == 1 ) ? 1 : static_cast<int>( bright * ( 17.0 / 255.0 ) ); char writeCommand[100]; const int count = sprintf( writeCommand, "0x%x\n", value ); res = ( ::write ( fd, writeCommand, count ) != -1 ); ::close ( fd ); |