00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "volumeapplet.h"
00032
00033
00034 #include <opie2/odebug.h>
00035 #include <opie2/otaskbarapplet.h>
00036 #include <opie2/osoundsystem.h>
00037 #include <opie2/oledbox.h>
00038 #include <opie2/oresource.h>
00039
00040 #include <qpe/applnk.h>
00041 #include <qpe/qpeapplication.h>
00042
00043 using namespace Opie::Core;
00044 using namespace Opie::MM;
00045 using namespace Opie::Ui;
00046
00047
00048 #include <qpainter.h>
00049 #include <qlabel.h>
00050 #include <qlayout.h>
00051 #include <qslider.h>
00052
00053
00054 #include <assert.h>
00055
00056 Channel::Channel( OMixerInterface* mixer, QWidget* parent, const char* name )
00057 :QVBox( parent, name )
00058 {
00059 _name = new QLabel( name, this );
00060 _name->setFont( QFont( "Vera", 8 ) );
00061 _volume = new QSlider( 0, 100, 10, mixer->volume( name ) & 0xff, QSlider::Vertical, this );
00062 _volume->setTickmarks( QSlider::Both );
00063 _volume->setTickInterval( 20 );
00064 _mute = new OLedBox( green, this );
00065 _mute->setFocusPolicy( QWidget::NoFocus );
00066 _mute->setFixedSize( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
00067 _name->show();
00068 _volume->show();
00069 _mute->show();
00070 }
00071
00072
00073 Channel::~Channel()
00074 {
00075 }
00076
00077
00078 VolumeAppletControl::VolumeAppletControl( OTaskbarApplet* parent, const char* name )
00079 :QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), l(0)
00080 {
00081 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
00082 l = new QGridLayout( this );
00083 build();
00084 }
00085
00086
00087 void VolumeAppletControl::build()
00088 {
00089 OSoundSystem* sound = OSoundSystem::instance();
00090 OSoundSystem::CardIterator it = sound->iterator();
00091
00092
00093 mixer = new OMixerInterface( this, "/dev/mixer" );
00094
00095 QStringList channels = mixer->allChannels();
00096
00097 int x = 0;
00098
00099
00100 for ( QStringList::Iterator it = channels.begin(); it != channels.end(); ++it )
00101 {
00102 if((*it) == mixer->volume( "Vol")) {
00103 m_vol_percent=mixer->volume( *it ) >> 8;
00104 }
00105 owarn << "OSSDEMO: Mixer has channel " << *it << "" << oendl;
00106 owarn << "OSSDEMO: +--- volume " << ( mixer->volume( *it ) & 0xff )
00107 << " (left) | " << ( mixer->volume( *it ) >> 8 ) << " (right)" << oendl;
00108
00109 l->addWidget( new Channel( mixer, this, *it ), 0, x++, AlignCenter );
00110 }
00111
00112 }
00113
00114
00115 VolumeAppletControl::~VolumeAppletControl()
00116 {
00117 }
00118
00119 int VolumeAppletControl::volPercent ( ) const
00120 {
00121 return m_vol_percent;
00122 }
00123
00124 bool VolumeAppletControl::volMuted ( ) const
00125 {
00126 return m_vol_muted;
00127 }
00128
00129
00130 void VolumeAppletControl::showEvent( QShowEvent* e )
00131 {
00132 odebug << "showEvent" << oendl;
00133 QWidget::showEvent( e );
00134 }
00135
00136
00137 void VolumeAppletControl::hideEvent( QHideEvent* e )
00138 {
00139 odebug << "hideEvent" << oendl;
00140 QWidget::hideEvent( e );
00141 }
00142
00143
00144 QSize VolumeAppletControl::sizeHint() const
00145 {
00146 int wd = QPEApplication::desktop()->width();
00147 return QSize( wd, 200 );
00148 }
00149
00150
00151 VolumeApplet::VolumeApplet( QWidget *parent, const char *name )
00152 :OTaskbarApplet( parent, name )
00153 {
00154 setFixedHeight( AppLnk::smallIconSize() +4);
00155 setFixedWidth( AppLnk::smallIconSize() );
00156 _pixmap = Opie::Core::OResource::loadPixmap( "volume", Opie::Core::OResource::SmallIcon );
00157
00158 _control = new VolumeAppletControl( this, "control" );
00159 }
00160
00161
00162 VolumeApplet::~VolumeApplet()
00163 {
00164 }
00165
00166
00167 int VolumeApplet::position()
00168 {
00169 return 4;
00170 }
00171
00172
00173 void VolumeApplet::paintEvent( QPaintEvent* )
00174 {
00175 QPainter p(this);
00176 p.drawPixmap(0, 2, _pixmap );
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 }
00203
00204
00205 void VolumeApplet::mousePressEvent( QMouseEvent* )
00206 {
00207 if ( !_control->isVisible() )
00208 {
00209 popup( _control );
00210 }
00211 else
00212 {
00213 _control->hide();
00214 }
00215 }
00216
00217 EXPORT_OPIE_APPLET_v1( VolumeApplet )