summaryrefslogtreecommitdiff
path: root/core/applets/volumeapplet
Unidiff
Diffstat (limited to 'core/applets/volumeapplet') (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/volumeapplet/.cvsignore3
-rw-r--r--core/applets/volumeapplet/Makefile.in115
-rw-r--r--core/applets/volumeapplet/qpe-volumeapplet.control9
-rwxr-xr-xcore/applets/volumeapplet/qpe-volumeapplet.postinst2
-rwxr-xr-xcore/applets/volumeapplet/qpe-volumeapplet.postrm2
-rw-r--r--core/applets/volumeapplet/volume.cpp199
-rw-r--r--core/applets/volumeapplet/volume.h75
-rw-r--r--core/applets/volumeapplet/volumeapplet.pro12
-rw-r--r--core/applets/volumeapplet/volumeappletimpl.cpp64
-rw-r--r--core/applets/volumeapplet/volumeappletimpl.h44
10 files changed, 525 insertions, 0 deletions
diff --git a/core/applets/volumeapplet/.cvsignore b/core/applets/volumeapplet/.cvsignore
new file mode 100644
index 0000000..edfa921
--- a/dev/null
+++ b/core/applets/volumeapplet/.cvsignore
@@ -0,0 +1,3 @@
1moc_*
2*.moc
3Makefile
diff --git a/core/applets/volumeapplet/Makefile.in b/core/applets/volumeapplet/Makefile.in
new file mode 100644
index 0000000..7020cb7
--- a/dev/null
+++ b/core/applets/volumeapplet/Makefile.in
@@ -0,0 +1,115 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS) $(SYSCONF_CXXFLAGS_LIB)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS) $(SYSCONF_CFLAGS_LIB)
9 INCPATH =-I$(QPEDIR)/include
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = ../../plugins/applets/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= volumeapplet
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =volume.h \
27 volumeappletimpl.h
28 SOURCES =volume.cpp \
29 volumeappletimpl.cpp
30 OBJECTS =volume.o \
31 volumeappletimpl.o
32INTERFACES =
33UICDECLS =
34UICIMPLS =
35 SRCMOC =moc_volume.cpp
36 OBJMOC =moc_volume.o
37
38
39####### Implicit rules
40
41.SUFFIXES: .cpp .cxx .cc .C .c
42
43.cpp.o:
44 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
45
46.cxx.o:
47 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
48
49.cc.o:
50 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
51
52.C.o:
53 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
54
55.c.o:
56 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
57
58####### Build rules
59
60
61all: $(DESTDIR)$(SYSCONF_LINK_TARGET)
62
63$(DESTDIR)$(SYSCONF_LINK_TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
64 $(SYSCONF_LINK_LIB)
65
66moc: $(SRCMOC)
67
68tmake:
69 tmake volumeapplet.pro
70
71clean:
72 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
73 -rm -f *~ core
74 -rm -f allmoc.cpp
75
76####### Extension Modules
77
78listpromodules:
79 @echo
80
81listallmodules:
82 @echo
83
84listaddonpromodules:
85 @echo
86
87listaddonentmodules:
88 @echo
89
90
91REQUIRES=
92
93####### Sub-libraries
94
95
96###### Combined headers
97
98
99
100####### Compile
101
102volume.o: volume.cpp \
103 volume.h
104
105volumeappletimpl.o: volumeappletimpl.cpp \
106 volume.h \
107 volumeappletimpl.h
108
109moc_volume.o: moc_volume.cpp \
110 volume.h
111
112moc_volume.cpp: volume.h
113 $(MOC) volume.h -o moc_volume.cpp
114
115
diff --git a/core/applets/volumeapplet/qpe-volumeapplet.control b/core/applets/volumeapplet/qpe-volumeapplet.control
new file mode 100644
index 0000000..a80262a
--- a/dev/null
+++ b/core/applets/volumeapplet/qpe-volumeapplet.control
@@ -0,0 +1,9 @@
1Files: plugins/applets/libvolumeapplet.so*
2Priority: optional
3Section: qpe/taskbar
4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm
6Version: $QPE_VERSION-3
7Depends: qpe-base ($QPE_VERSION)
8Description: Volume applet
9 Volume applet for the Qtopia environment taskbar.
diff --git a/core/applets/volumeapplet/qpe-volumeapplet.postinst b/core/applets/volumeapplet/qpe-volumeapplet.postinst
new file mode 100755
index 0000000..ba76ffa
--- a/dev/null
+++ b/core/applets/volumeapplet/qpe-volumeapplet.postinst
@@ -0,0 +1,2 @@
1#!/bin/sh
2/opt/QtPalmtop/bin/qcop QPE/TaskBar "reloadApplets()"
diff --git a/core/applets/volumeapplet/qpe-volumeapplet.postrm b/core/applets/volumeapplet/qpe-volumeapplet.postrm
new file mode 100755
index 0000000..ba76ffa
--- a/dev/null
+++ b/core/applets/volumeapplet/qpe-volumeapplet.postrm
@@ -0,0 +1,2 @@
1#!/bin/sh
2/opt/QtPalmtop/bin/qcop QPE/TaskBar "reloadApplets()"
diff --git a/core/applets/volumeapplet/volume.cpp b/core/applets/volumeapplet/volume.cpp
new file mode 100644
index 0000000..35dbf22
--- a/dev/null
+++ b/core/applets/volumeapplet/volume.cpp
@@ -0,0 +1,199 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "volume.h"
22
23#include <qpe/resource.h>
24#include <qpe/qpeapplication.h>
25#include <qpe/config.h>
26#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
27#include <qpe/qcopenvelope_qws.h>
28#endif
29
30#include <qpainter.h>
31#include <qcheckbox.h>
32#include <qslider.h>
33#include <qlayout.h>
34#include <qframe.h>
35#include <qpixmap.h>
36
37
38VolumeControl::VolumeControl( QWidget *parent, const char *name )
39 : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup )
40{
41 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
42
43 QVBoxLayout *vbox = new QVBoxLayout( this );
44 slider = new QSlider( this );
45 muteBox = new QCheckBox( tr("Mute"), this );
46 slider->setRange( 0, 100 );
47 slider->setTickmarks( QSlider::Both );
48 slider->setTickInterval( 20 );
49 slider->setFocusPolicy( QWidget::NoFocus );
50 muteBox->setFocusPolicy( QWidget::NoFocus );
51 vbox->setMargin( 6 );
52 vbox->setSpacing( 3 );
53 vbox->addWidget( slider, 0, Qt::AlignVCenter | Qt::AlignHCenter );
54 vbox->addWidget( muteBox );
55 setFixedHeight( 100 );
56 setFixedWidth( sizeHint().width() );
57 setFocusPolicy(QWidget::NoFocus);
58}
59
60void VolumeControl::keyPressEvent( QKeyEvent *e)
61{
62 switch(e->key()) {
63 case Key_Up:
64 slider->subtractStep();
65 break;
66 case Key_Down:
67 slider->addStep();
68 break;
69 case Key_Space:
70 muteBox->toggle();
71 break;
72 case Key_Escape:
73 close();
74 break;
75 }
76}
77
78//===========================================================================
79
80VolumeApplet::VolumeApplet( QWidget *parent, const char *name )
81 : QWidget( parent, name )
82{
83 setFixedHeight( 18 );
84 setFixedWidth( 14 );
85 volumePixmap = Resource::loadPixmap( "volume" );
86 muted = FALSE; // ### read from pref
87 volumePercent = 50; // ### read from pref
88 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) );
89 writeSystemVolume();
90}
91
92VolumeApplet::~VolumeApplet()
93{
94}
95
96void VolumeApplet::mousePressEvent( QMouseEvent *)
97{
98 // Create a small volume control window to adjust the volume with
99 VolumeControl *vc = new VolumeControl;
100 vc->slider->setValue( 100 - volumePercent );
101 vc->muteBox->setChecked( muted );
102 connect( vc->slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderMoved( int ) ) );
103 connect( vc->muteBox, SIGNAL( toggled( bool ) ), this, SLOT( mute( bool ) ) );
104 QPoint curPos = mapToGlobal( rect().topLeft() );
105 vc->move( curPos.x()-(vc->sizeHint().width()-width())/2, curPos.y() - 100 );
106 vc->show();
107}
108
109void VolumeApplet::volumeChanged( bool nowMuted )
110{
111 int previousVolume = volumePercent;
112
113 if ( !nowMuted )
114 readSystemVolume();
115
116 // Handle case where muting it toggled
117 if ( muted != nowMuted ) {
118 muted = nowMuted;
119 repaint( TRUE );
120 return;
121 }
122
123 // Avoid over repainting
124 if ( previousVolume != volumePercent )
125 repaint( 2, height() - 3, width() - 4, 2, FALSE );
126}
127
128
129void VolumeApplet::mute( bool toggled )
130{
131 muted = toggled;
132 // clear if removing mute
133 repaint( !toggled );
134 writeSystemVolume();
135}
136
137
138void VolumeApplet::sliderMoved( int percent )
139{
140 setVolume( 100 - percent );
141}
142
143
144void VolumeApplet::readSystemVolume()
145{
146 Config cfg("Sound");
147 cfg.setGroup("System");
148 volumePercent = cfg.readNumEntry("Volume");
149}
150
151
152void VolumeApplet::setVolume( int percent )
153{
154 // clamp volume percent to be between 0 and 100
155 volumePercent = (percent < 0) ? 0 : ((percent > 100) ? 100 : percent);
156 // repaint just the little volume rectangle
157 repaint( 2, height() - 3, width() - 4, 2, FALSE );
158 writeSystemVolume();
159}
160
161
162void VolumeApplet::writeSystemVolume()
163{
164 {
165 Config cfg("Sound");
166 cfg.setGroup("System");
167 cfg.writeEntry("Volume",volumePercent);
168 }
169#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
170 // Send notification that the volume has changed
171 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted;
172#endif
173}
174
175
176void VolumeApplet::paintEvent( QPaintEvent* )
177{
178 QPainter p(this);
179
180 if (volumePixmap.isNull())
181 volumePixmap = Resource::loadPixmap( "volume" );
182 p.drawPixmap( 0, 1, volumePixmap );
183 p.setPen( darkGray );
184 p.drawRect( 1, height() - 4, width() - 2, 4 );
185
186 int pixelsWide = volumePercent * (width() - 4) / 100;
187 p.fillRect( 2, height() - 3, pixelsWide, 2, red );
188 p.fillRect( pixelsWide + 2, height() - 3, width() - 4 - pixelsWide, 2, lightGray );
189
190 if ( muted ) {
191 p.setPen( red );
192 p.drawLine( 1, 2, width() - 2, height() - 5 );
193 p.drawLine( 1, 3, width() - 2, height() - 4 );
194 p.drawLine( width() - 2, 2, 1, height() - 5 );
195 p.drawLine( width() - 2, 3, 1, height() - 4 );
196 }
197}
198
199
diff --git a/core/applets/volumeapplet/volume.h b/core/applets/volumeapplet/volume.h
new file mode 100644
index 0000000..5704cad
--- a/dev/null
+++ b/core/applets/volumeapplet/volume.h
@@ -0,0 +1,75 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef __VOLUME_APPLET_H__
21#define __VOLUME_APPLET_H__
22
23
24#include <qwidget.h>
25#include <qframe.h>
26#include <qpixmap.h>
27#include <qguardedptr.h>
28
29class QSlider;
30class QCheckBox;
31
32class VolumeControl : public QFrame
33{
34 Q_OBJECT
35public:
36 VolumeControl( QWidget *parent=0, const char *name=0 );
37
38public:
39 QSlider *slider;
40 QCheckBox *muteBox;
41
42private:
43 void keyPressEvent( QKeyEvent * );
44};
45
46class VolumeApplet : public QWidget
47{
48 Q_OBJECT
49public:
50 VolumeApplet( QWidget *parent = 0, const char *name=0 );
51 ~VolumeApplet();
52 bool isMute( ) { return muted; }
53 int percent( ) { return volumePercent; }
54
55public slots:
56 void volumeChanged( bool muted );
57 void setVolume( int percent );
58 void sliderMoved( int percent );
59 void mute( bool );
60
61private:
62 void readSystemVolume();
63 void writeSystemVolume();
64 void mousePressEvent( QMouseEvent * );
65 void paintEvent( QPaintEvent* );
66
67private:
68 int volumePercent;
69 bool muted;
70 QPixmap volumePixmap;
71};
72
73
74#endif // __VOLUME_APPLET_H__
75
diff --git a/core/applets/volumeapplet/volumeapplet.pro b/core/applets/volumeapplet/volumeapplet.pro
new file mode 100644
index 0000000..a33cf81
--- a/dev/null
+++ b/core/applets/volumeapplet/volumeapplet.pro
@@ -0,0 +1,12 @@
1 TEMPLATE= lib
2 CONFIG += qt warn_on release
3 HEADERS= volume.h volumeappletimpl.h
4 SOURCES= volume.cpp volumeappletimpl.cpp
5 TARGET = volumeapplet
6 DESTDIR = ../../plugins/applets
7INCLUDEPATH += $(QPEDIR)/include
8DEPENDPATH += ../$(QPEDIR)/include
9LIBS += -lqpe
10 VERSION = 1.0.0
11
12TRANSLATIONS += ../../i18n/de/libvolumeapplet.ts
diff --git a/core/applets/volumeapplet/volumeappletimpl.cpp b/core/applets/volumeapplet/volumeappletimpl.cpp
new file mode 100644
index 0000000..676ab61
--- a/dev/null
+++ b/core/applets/volumeapplet/volumeappletimpl.cpp
@@ -0,0 +1,64 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "volume.h"
21#include "volumeappletimpl.h"
22
23
24VolumeAppletImpl::VolumeAppletImpl()
25 : volume(0), ref(0)
26{
27}
28
29VolumeAppletImpl::~VolumeAppletImpl()
30{
31 delete volume;
32}
33
34QWidget *VolumeAppletImpl::applet( QWidget *parent )
35{
36 if ( !volume )
37 volume = new VolumeApplet( parent );
38 return volume;
39}
40
41int VolumeAppletImpl::position() const
42{
43 return 6;
44}
45
46QRESULT VolumeAppletImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
47{
48 *iface = 0;
49 if ( uuid == IID_QUnknown )
50 *iface = this;
51 else if ( uuid == IID_TaskbarApplet )
52 *iface = this;
53
54 if ( *iface )
55 (*iface)->addRef();
56 return QS_OK;
57}
58
59Q_EXPORT_INTERFACE()
60{
61 Q_CREATE_INSTANCE( VolumeAppletImpl )
62}
63
64
diff --git a/core/applets/volumeapplet/volumeappletimpl.h b/core/applets/volumeapplet/volumeappletimpl.h
new file mode 100644
index 0000000..9b2952a
--- a/dev/null
+++ b/core/applets/volumeapplet/volumeappletimpl.h
@@ -0,0 +1,44 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef VOLUMEAPPLETIMPL_H
21#define VOLUMEAPPLETIMPL_H
22
23#include <qpe/taskbarappletinterface.h>
24
25class VolumeApplet;
26
27class VolumeAppletImpl : public TaskbarAppletInterface
28{
29public:
30 VolumeAppletImpl();
31 virtual ~VolumeAppletImpl();
32
33 QRESULT queryInterface( const QUuid&, QUnknownInterface** );
34 Q_REFCOUNT
35
36 virtual QWidget *applet( QWidget *parent );
37 virtual int position() const;
38
39private:
40 VolumeApplet *volume;
41 ulong ref;
42};
43
44#endif