[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdemultimedia/kmix
From: Christian Esken <esken () kde ! org>
Date: 2008-10-26 22:40:41
Message-ID: 1225060841.145339.22961.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 876262 by esken:
Refactor increase/decrease volume.
Resolve 2 TODO items (missing functionaity on capture volumes).
Add OSD, as discussed on kcd.
Fix one more show-window-on-start issue.
Bugfix: Let KMix only show GLOBAL shortcuts for the volume actions.
M +6 -0 ChangeLog
M +8 -4 KMixApp.cpp
M +83 -3 kmix.cpp
M +10 -1 kmix.h
M +2 -0 main.cpp
M +2 -0 mdwslider.h
M +7 -1 mixdevicewidget.cpp
M +2 -0 mixdevicewidget.h
M +26 -17 mixer.cpp
M +11 -0 volume.cpp
M +3 -0 volume.h
--- trunk/KDE/kdemultimedia/kmix/ChangeLog #876261:876262
@@ -8,3 +8,9 @@
in the panel applet to show only important devices initally.
- Much nicer "New Mixer Tab..." dialog
+v3.0
+- KDE 4 version
+
+
+TODO:
+ Reenable OSD (osd.cpp, cpp.h)
--- trunk/KDE/kdemultimedia/kmix/KMixApp.cpp #876261:876262
@@ -48,21 +48,24 @@
int
KMixApp::newInstance()
{
+ // There are 3 cases for a new instance
+
//kDebug(67100) << "KMixApp::newInstance() isRestored()=" << isRestored() << \
"_keepVisibility=" << _keepVisibility; if ( m_kmix )
{ // There already exists an instance/window
kDebug(67100) << "KMixApp::newInstance() Instance exists";
if ( ! _keepVisibility && !isSessionRestored() ) {
- //kDebug(67100) << "KMixApp::newInstance() _keepVisibility=false";
- // Default case: If KMix is running and the *USER*
+ kDebug(67100) << "KMixApp::newInstance() SHOW WINDOW (_keepVisibility=" << \
_keepVisibility << ", isSessionRestored=" << isSessionRestored(); + // CASE 1: If \
KMix is running AND the *USER*
// starts it again, the KMix main window will be shown.
// If KMix is restored by SM or the --keepvisibilty is used, KMix will NOT
// explicitly be shown.
m_kmix->show();
}
else {
- //kDebug(67100) << "KMixApp::newInstance() _keepVisibility=true || \
isRestored()=true"; + // CASE 2: If KMix is running, AND ( \
session gets restored OR keepvisibilty command line switch ) + kDebug(67100) << \
"KMixApp::newInstance() REGULAR_START _keepVisibility=" << _keepVisibility; // \
Special case: Command line arg --keepVisibility was used: // We don't want to change \
the visibiliy, thus we don't call show() here. //
@@ -74,8 +77,9 @@
}
else
{
+ // CASE 3: KMix was not running yet => instanciate a new one
//kDebug(67100) << "KMixApp::newInstance() !m_kmix";
- m_kmix = new KMixWindow;
+ m_kmix = new KMixWindow(_keepVisibility);
//connect(this, SIGNAL(stopUpdatesOnVisibility()), m_kmix, \
SLOT(stopVisibilityUpdates())); if ( isSessionRestored() && \
KMainWindow::canBeRestored(0) ) {
--- trunk/KDE/kdemultimedia/kmix/kmix.cpp #876261:876262
@@ -25,6 +25,7 @@
// include files for QT
#include <QCheckBox>
#include <QLabel>
+#include <QDesktopWidget>
#include <qradiobutton.h>
#include <KTabWidget>
@@ -62,7 +63,7 @@
/* KMixWindow
* Constructs a mixer window (KMix main window)
*/
-KMixWindow::KMixWindow()
+KMixWindow::KMixWindow(bool invisible)
: KXmlGuiWindow(0),
m_showTicks( true ),
m_showMenubar(true),
@@ -87,7 +88,7 @@
theKMixDeviceManager->initHotplug();
connect(theKMixDeviceManager, SIGNAL( plugged( const char*, const QString&, \
QString&)), SLOT (plugged( const char*, const QString&, QString&) ) ); \
connect(theKMixDeviceManager, SIGNAL( unplugged( const QString&)), SLOT (unplugged( \
const QString&) ) );
- if ( m_startVisible )
+ if ( m_startVisible && ! invisible)
show(); // Started visible: We don't do "m_isVisible = true;", as the \
showEvent() already does it
connect( kapp, SIGNAL( aboutToQuit()), SLOT( saveConfig()) );
@@ -122,6 +123,32 @@
action = actionCollection()->addAction("toggle_channels_currentview");
action->setText(i18n("Configure &Channels..."));
connect(action, SIGNAL(triggered(bool) ), SLOT(slotConfigureCurrentView()));
+
+ KAction* globalAction = actionCollection()->addAction("increase_volume");
+ globalAction->setText(i18n("Increase Volume"));
+ globalAction->setGlobalShortcut(KShortcut(Qt::Key_VolumeUp));
+ connect(globalAction, SIGNAL(triggered(bool) ), SLOT(slotIncreaseVolume()));
+
+ globalAction = actionCollection()->addAction("decrease_volume");
+ globalAction->setText(i18n("Decrease Volume"));
+ globalAction->setGlobalShortcut(KShortcut(Qt::Key_VolumeDown));
+ connect(globalAction, SIGNAL(triggered(bool) ), SLOT(slotDecreaseVolume()));
+
+ globalAction = actionCollection()->addAction("mute");
+ globalAction->setText(i18n("Mute"));
+ globalAction->setGlobalShortcut(KShortcut(Qt::Key_VolumeMute));
+ connect(globalAction, SIGNAL(triggered(bool) ), SLOT(slotMute()));
+
+ volumeDisplay = new QProgressBar();
+ volumeDisplay->setWindowFlags(Qt::X11BypassWindowManagerHint);
+ QDesktopWidget* desktop = KApplication::kApplication()->desktop();
+ QRect rect = desktop->screenGeometry();
+ int width = (rect.width()/2) - (volumeDisplay->width()/2);
+ int height = (rect.height()/2) - (volumeDisplay->height()/2);
+ volumeDisplay->move(width, height);
+ volumeDisplayTimer = new QTimer(this);
+ connect(volumeDisplayTimer, SIGNAL(timeout()), this, \
SLOT(slotHideVolumeDisplay())); +
createGUI( "kmixui.rc" );
}
@@ -552,7 +579,9 @@
return false;
}
else {
- // Accept the close in all situations, when the user has disabled docking
+ // Accept the close, if:
+ // The user has disabled docking
+ // or SessionSaving() is running
// kDebug(67100) << "close";
return true;
}
@@ -570,6 +599,57 @@
}
}
+void KMixWindow::slotIncreaseVolume()
+{
+ Mixer* mixer = Mixer::getGlobalMasterMixer(); // only needed for the awkward \
construct below + MixDevice *md = Mixer::getGlobalMasterMD();
+ md->setMuted(false);
+ mixer->increaseVolume(md->id()); // this is awkward. Better move the \
increaseVolume impl to the Volume class. + // md->playbackVolume().increase(); // \
not yet implemented + showVolumeDisplay();
+}
+
+void KMixWindow::slotDecreaseVolume()
+{
+ Mixer* mixer = Mixer::getGlobalMasterMixer();
+ mixer->setMute("Master:0", false);
+ mixer->decreaseVolume("PCM:0");
+ showVolumeDisplay();
+}
+
+void KMixWindow::showVolumeDisplay()
+{
+ Mixer* mixer = Mixer::getGlobalMasterMixer();
+ int currentVolume = mixer->masterVolume();
+ volumeDisplay->setValue(currentVolume);
+ if (mixer->mute("Master:0")) {
+ volumeDisplay->setValue(0);
+ }
+ volumeDisplay->show();
+
+ //FIXME, how to get this to work before it is displayed for the first time?
+ QDesktopWidget* desktop = KApplication::kApplication()->desktop();
+ QRect rect = desktop->screenGeometry();
+ int width = (rect.width()/2) - (volumeDisplay->width()/2);
+ int height = (rect.height()/2) - (volumeDisplay->height()/2);
+ volumeDisplay->move(width, height);
+
+ volumeDisplayTimer->setInterval(2000);
+ volumeDisplayTimer->start();
+}
+
+void KMixWindow::slotHideVolumeDisplay()
+{
+ volumeDisplay->hide();
+}
+
+void KMixWindow::slotMute()
+{
+ Mixer* mixer = Mixer::getGlobalMasterMixer();
+ mixer->toggleMute("Master:0");
+ showVolumeDisplay();
+}
+
void KMixWindow::quit()
{
// kDebug(67100) << "quit";
--- trunk/KDE/kdemultimedia/kmix/kmix.h #876261:876262
@@ -29,6 +29,8 @@
class QLabel;
#include <qlist.h>
#include <QVBoxLayout>
+#include <QProgressBar>
+#include <QTimer>
class KTabWidget;
// KDE
@@ -51,7 +53,7 @@
Q_OBJECT
public:
- KMixWindow();
+ KMixWindow(bool invisible);
~KMixWindow();
bool updateDocking();
@@ -115,6 +117,9 @@
QLabel *m_errorLabel;
ViewDockAreaPopup *_dockAreaPopup;
unsigned int m_configVersion;
+ QProgressBar* volumeDisplay;
+ QTimer* volumeDisplayTimer;
+ void showVolumeDisplay();
private slots:
void saveConfig();
@@ -124,6 +129,10 @@
void plugged( const char* driverName, const QString& udi, QString& dev);
void unplugged( const QString& udi);
void hideOrClose();
+ void slotIncreaseVolume();
+ void slotDecreaseVolume();
+ void slotHideVolumeDisplay();
+ void slotMute();
};
#endif // KMIX_H
--- trunk/KDE/kdemultimedia/kmix/main.cpp #876261:876262
@@ -21,6 +21,7 @@
#include <kcmdlineargs.h>
#include <kaboutdata.h>
+#include <kdebug.h>
#include <klocale.h>
#include <kglobal.h>
#include <kstandarddirs.h>
@@ -60,6 +61,7 @@
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
bool hasArgKeepvisibility = args->isSet("keepvisibility");
+ kDebug(67100) << "hasArgKeepvisibility=" << hasArgKeepvisibility;
KMixApp::keepVisibility(hasArgKeepvisibility);
if (!KMixApp::start())
--- trunk/KDE/kdemultimedia/kmix/mdwslider.h #876261:876262
@@ -37,6 +37,7 @@
class KLed;
class KLedButton;
class KAction;
+#include <kshortcut.h>
class MixDevice;
class VerticalText;
@@ -142,6 +143,7 @@
QCheckBox* m_captureLED;
QLabel* m_captureText;
QWidget *m_captureSpacer;
+// static KShortcut dummyShortcut;
QList<QWidget *> m_slidersPlayback;
--- trunk/KDE/kdemultimedia/kmix/mixdevicewidget.cpp #876261:876262
@@ -58,6 +58,7 @@
QWidget* parent, ViewBase* mw) :
QWidget( parent ), m_mixdevice( md ), m_view( mw ),
m_disabled( false ), _orientation( orientation ), m_small( small )
+ , m_shortcutsDialog(0)
{
_mdwActions = new KActionCollection( this );
_mdwPopupActions = new KActionCollection( this );
@@ -79,7 +80,12 @@
void MixDeviceWidget::defineKeys()
{
- KShortcutsDialog::configure(_mdwPopupActions ); // , \
KShortcutsEditor::LetterShortcutsAllowed, this); + // Dialog for *global* shortcuts \
of this MDW + if ( m_shortcutsDialog == 0 ) {
+ m_shortcutsDialog = new KShortcutsDialog( KShortcutsEditor::GlobalAction );
+ m_shortcutsDialog->addCollection(_mdwPopupActions);
+ }
+ m_shortcutsDialog->configure();
}
void MixDeviceWidget::volumeChange( int ) { /* is virtual */ }
--- trunk/KDE/kdemultimedia/kmix/mixdevicewidget.h #876261:876262
@@ -33,6 +33,7 @@
class KLed;
class KAction;
class KActionCollection;
+class KShortcutsDialog;
class MixDevice;
class Mixer;
@@ -83,6 +84,7 @@
bool m_disabled;
Qt::Orientation _orientation;
bool m_small;
+ KShortcutsDialog* m_shortcutsDialog;
private:
void mousePressEvent( QMouseEvent *e );
--- trunk/KDE/kdemultimedia/kmix/mixer.cpp #876261:876262
@@ -573,16 +573,20 @@
{
MixDevice *md= getMixdeviceById( mixdeviceID );
if (md != 0) {
- Volume& volP=md->playbackVolume(); // @todo Is hardcoded to PlaybackVolume
+ Volume& volP=md->playbackVolume();
+ if ( volP.hasVolume() ) {
+ double step = (volP.maxVolume()-volP.minVolume()+1) / 20;
+ if ( step < 1 ) step = 1;
+ volP.changeAllVolumes(step);
+ }
+
Volume& volC=md->captureVolume();
- double fivePercent = (volP.maxVolume()-volP.minVolume()+1) / 20;
- for (unsigned int i=Volume::CHIDMIN; i <= Volume::CHIDMAX; i++)
- {
- int volToChange = volP.getVolume((Volume::ChannelID)i);
- if ( fivePercent < 1 ) fivePercent = 1;
- volToChange += (int)fivePercent;
- volP.setVolume((Volume::ChannelID)i, volToChange);
+ if ( volC.hasVolume() ) {
+ double step = (volC.maxVolume()-volC.minVolume()+1) / 20;
+ if ( step < 1 ) step = 1;
+ volC.changeAllVolumes(step);
}
+
_mixerBackend->writeVolumeToHW(mixdeviceID, md);
}
@@ -597,18 +601,23 @@
{
MixDevice *md= getMixdeviceById( mixdeviceID );
if (md != 0) {
- Volume& volP=md->playbackVolume(); // @todo Is hardcoded to PlaybackVolume
+ Volume& volP=md->playbackVolume();
+ if ( volP.hasVolume() ) {
+ double step = (volP.maxVolume()-volP.minVolume()+1) / 20;
+ if ( step < 1 ) step = 1;
+ volP.changeAllVolumes(-step);
+ }
+
Volume& volC=md->captureVolume();
- double fivePercent = (volP.maxVolume()-volP.minVolume()+1) / 20;
- for (unsigned int i=Volume::CHIDMIN; i <= Volume::CHIDMAX; i++) {
- int volToChange = volP.getVolume((Volume::ChannelID)i);
- if ( fivePercent < 1 ) fivePercent = 1;
- volToChange -= (int)fivePercent;
- volP.setVolume((Volume::ChannelID)i, volToChange);
- } // for
- _mixerBackend->writeVolumeToHW(mixdeviceID, md);
+ if ( volC.hasVolume() ) {
+ double step = (volC.maxVolume()-volC.minVolume()+1) / 20;
+ if ( step < 1 ) step = 1;
+ volC.changeAllVolumes(-step);
+ }
}
+ _mixerBackend->writeVolumeToHW(mixdeviceID, md);
+
/************************************************************
It is important, not to implement this method like this:
int vol=volume(mixdeviceID);
--- trunk/KDE/kdemultimedia/kmix/volume.cpp #876261:876262
@@ -97,6 +97,17 @@
}
}
+void Volume::changeAllVolumes( long step )
+{
+ for (unsigned int i=Volume::CHIDMIN; i <= Volume::CHIDMAX; i++)
+ {
+ int volToChange = getVolume((Volume::ChannelID)i);
+ volToChange += (int)step;
+ setVolume((Volume::ChannelID)i, volToChange);
+ }
+}
+
+
// @ compatibility
void Volume::setVolume( ChannelID chid, long vol)
{
--- trunk/KDE/kdemultimedia/kmix/volume.h #876261:876262
@@ -83,6 +83,9 @@
// Set volumes as specified by the channel mask
void setVolume( const Volume &vol, ChannelMask chmask);
void setVolume( ChannelID chid, long volume);
+
+ // Increase or decrease all volumes by step
+ void changeAllVolumes( long step );
long getVolume(ChannelID chid);
long getAvgVolume(ChannelMask chmask);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic