[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-multimedia
Subject:    [PATCH] Add mute option to KMix context menu
From:       Nadeem Hasan <nhasan () nadmm ! com>
Date:       2002-06-13 17:38:40
[Download RAW message or body]

On Thursday 13 June 2002 02:41 am, Nadeem Hasan wrote:
> Hi all,
>
> The following patch adds the mute option to the KMix tray icon context
> menu, allowing a user to mute the master volume with ease. It also displays
> a different icon and tooltip in the tray when muted to provide visual
> feedback. The patch also adds a new image file which is attached too.

Ok....found an unfinished thing with the earlier patch. Please use this one
instead. I am not subscribed to kde-mm.

Cheers,
--
Nadeem Hasan
nhasan@nadmm.com
http://www.nadmm.com/

[" " (text/x-diff)]

? .kmix.cpp.swp
? pics/.xvpics
Index: kmix.cpp
===================================================================
RCS file: /home/kde/kdemultimedia/kmix/kmix.cpp,v
retrieving revision 1.122
diff -u -r1.122 kmix.cpp
--- kmix.cpp	2002/05/21 21:54:03	1.122
+++ kmix.cpp	2002/06/13 06:53:06
@@ -141,9 +141,12 @@
     KStdAction::quit( this, SLOT(quit()), actionCollection());
 
     // settings menu
-    KAction *a = KStdAction::showMenubar( this, SLOT(toggleMenuBar()), actionCollection());
+    KStdAction::showMenubar( this, SLOT(toggleMenuBar()), actionCollection());
     KStdAction::preferences( this, SLOT(showSettings()), actionCollection());
 
+    ( void ) new KToggleAction( i18n( "M&ute" ), 0, this, SLOT( dockMute() ),
+            actionCollection(), "dock_mute" );
+
     createGUI( "kmixui.rc" );
 }
 
@@ -211,7 +214,7 @@
 
         // create dock widget
         m_dockWidget = new KMixDockWidget( m_mixers.first(), this );
-        m_dockWidget->setPixmap( BarIcon("kmixdocked") );
+        updateDockIcon();
 
         // create RMB menu
         QPopupMenu *menu = m_dockWidget->contextMenu();
@@ -219,19 +222,48 @@
         KAction *a = actionCollection()->action("options_configure");
         if (a) a->plug( menu );
 
-        menu->insertSeparator();
-
         a = actionCollection()->action("help_about_app");
         if (a) a->plug( menu );
 
         a = actionCollection()->action("help");
         if (a) a->plug( menu );
 
+        menu->insertSeparator();
+
+        a = actionCollection()->action( "dock_mute" );
+        if ( a ) a->plug( menu );
+
         m_dockWidget->show();
     }
 }
 
+void KMixWindow::dockMute()
+{
+    Mixer *mixer = m_mixers.first();
+
+    MixDevice *masterDevice = ( *mixer )[ mixer->masterDevice() ];
+
+    masterDevice->setMuted( !masterDevice->isMuted() );
+    mixer->writeVolumeToHW( masterDevice->num(), masterDevice->getVolume() );
+
+    updateDockIcon();
+}
+
+void KMixWindow::updateDockIcon()
+{
+    Mixer *mixer = m_mixers.first();
+
+    MixDevice *masterDevice = ( *mixer )[ mixer->masterDevice() ];
 
+    // Required if muted from mixer widget
+    KToggleAction *a = static_cast<KToggleAction *>
+            ( actionCollection()->action(  "dock_mute" ) );
+    if ( a ) a->setChecked( masterDevice->isMuted() );
+
+    m_dockWidget->updatePixmap();
+    m_dockWidget->setVolumeTip( 0, masterDevice->getVolume() );
+}
+
 void KMixWindow::saveConfig()
 {
    KConfig *config = kapp->config();
@@ -349,7 +381,9 @@
    mw->setTicks( m_showTicks );
    mw->setLabels( m_showLabels );
    mw->show();
+
    connect( mw, SIGNAL(updateLayout()), this, SLOT(updateLayout()) );
+   connect( mw, SIGNAL( masterMuted( bool ) ), SLOT( updateDockIcon() ) );
 
    KAction *a = actionCollection()->action( "file_close_tab" );
    if ( a ) a->setEnabled( m_visibleTabs>1 );
Index: kmix.h
===================================================================
RCS file: /home/kde/kdemultimedia/kmix/kmix.h,v
retrieving revision 1.53
diff -u -r1.53 kmix.h
--- kmix.h	2002/05/18 11:50:17	1.53
+++ kmix.h	2002/06/13 06:53:06
@@ -91,6 +91,7 @@
    void loadVolumes();
    void saveVolumes();
    virtual void applyPrefs( KMixPrefDlg *prefDlg );
+   void updateDockIcon();
 
   private:
    KAccel *m_keyAccel;
@@ -120,6 +121,7 @@
    void insertMixerWidget( KMixerWidget *mw );
    void removeMixerWidget( KMixerWidget *mw );
    void updateLayout();
+   void dockMute();
 
    void toggleVisibility();
 };
Index: kmixdockwidget.cpp
===================================================================
RCS file: /home/kde/kdemultimedia/kmix/kmixdockwidget.cpp,v
retrieving revision 1.17
diff -u -r1.17 kmixdockwidget.cpp
--- kmixdockwidget.cpp	2002/03/18 21:24:05	1.17
+++ kmixdockwidget.cpp	2002/06/13 06:53:06
@@ -75,8 +75,23 @@
 
 void KMixDockWidget::setVolumeTip(int, Volume vol)
 {
+    MixDevice *masterDevice = ( *m_mixer )[ m_mixer->masterDevice() ];
+    QString tip = i18n("Volume at %1%").arg(vol.getVolume(0));
+    if ( masterDevice->isMuted() )
+        tip += i18n( " (Muted)" );
+
     QToolTip::remove(this);
-    QToolTip::add(this, i18n("Volume at %1%").arg(vol.getVolume(0)));
+    QToolTip::add(this, tip);
+}
+
+void KMixDockWidget::updatePixmap()
+{
+    MixDevice *masterDevice = ( *m_mixer )[ m_mixer->masterDevice() ];
+
+    if ( masterDevice->isMuted() )
+        setPixmap( BarIcon( "kmixdocked_mute" ) );
+    else
+        setPixmap( BarIcon( "kmixdocked" ) );
 }
 
 void KMixDockWidget::mousePressEvent(QMouseEvent *me)
@@ -131,8 +146,8 @@
         		QWidget::mouseReleaseEvent(me); // KSystemTray's shouldn't do the default action for this 
         		return;
     		default:
-        		masterVol->hide();
-        		KSystemTray::mouseReleaseEvent(me);
+        		//masterVol->hide();
+        		//KSystemTray::mouseReleaseEvent(me);
         		return;
         }
     }
Index: kmixdockwidget.h
===================================================================
RCS file: /home/kde/kdemultimedia/kmix/kmixdockwidget.h,v
retrieving revision 1.5
diff -u -r1.5 kmixdockwidget.h
--- kmixdockwidget.h	2001/08/11 21:08:17	1.5
+++ kmixdockwidget.h	2002/06/13 06:53:06
@@ -37,7 +37,9 @@
    KMixDockWidget(Mixer *, QWidget *parent=0, const char *name=0);
    ~KMixDockWidget();
 
- protected slots:  
+   void updatePixmap();
+
+ public slots:  
    void setVolumeTip(int, Volume);
 
  protected:
Index: kmixerwidget.cpp
===================================================================
RCS file: /home/kde/kdemultimedia/kmix/kmixerwidget.cpp,v
retrieving revision 1.24
diff -u -r1.24 kmixerwidget.cpp
--- kmixerwidget.cpp	2002/05/19 09:50:04	1.24
+++ kmixerwidget.cpp	2002/06/13 06:53:07
@@ -119,6 +119,9 @@
          new MixDeviceWidget( m_mixer, mixDevice, !m_small, !m_small, m_small,
                               m_direction, this, mixDevice->name().latin1() );
 
+      connect( mdw, SIGNAL( masterMuted( bool ) ),
+                  SIGNAL( masterMuted( bool ) ) );
+
       connect( mdw, SIGNAL(updateLayout()), this, SLOT(updateSize()));
       m_devLayout->addWidget( mdw, 0 );
 
Index: kmixerwidget.h
===================================================================
RCS file: /home/kde/kdemultimedia/kmix/kmixerwidget.h,v
retrieving revision 1.8
diff -u -r1.8 kmixerwidget.h
--- kmixerwidget.h	2001/10/25 22:47:25	1.8
+++ kmixerwidget.h	2002/06/13 06:53:07
@@ -63,6 +63,7 @@
 
   signals:
    void updateLayout();
+   void masterMuted( bool );
 
   public slots:     
    void setTicks( bool on );
Index: mixdevicewidget.cpp
===================================================================
RCS file: /home/kde/kdemultimedia/kmix/mixdevicewidget.cpp,v
retrieving revision 1.29
diff -u -r1.29 mixdevicewidget.cpp
--- mixdevicewidget.cpp	2002/05/10 05:52:58	1.29
+++ mixdevicewidget.cpp	2002/06/13 06:53:07
@@ -310,6 +310,9 @@
    m_mixdevice->setMuted( value );
    update();
    emit newVolume( m_mixdevice->num(), m_mixdevice->getVolume() );
+
+   if ( m_mixdevice->num()==m_mixer->masterDevice() )
+       emit masterMuted( value );
 }
 
 void MixDeviceWidget::toggleMuted()
Index: mixdevicewidget.h
===================================================================
RCS file: /home/kde/kdemultimedia/kmix/mixdevicewidget.h,v
retrieving revision 1.7
diff -u -r1.7 mixdevicewidget.h
--- mixdevicewidget.h	2001/10/25 22:47:25	1.7
+++ mixdevicewidget.h	2002/06/13 06:53:07
@@ -83,6 +83,7 @@
       void defineKeys();
    signals:
       void newVolume( int num, Volume volume );
+      void masterMuted( bool );
       void newRecsrc( int num, bool on );
       void updateLayout();
       void rightMouseClick();
Index: pics/Makefile.am
===================================================================
RCS file: /home/kde/kdemultimedia/kmix/pics/Makefile.am,v
retrieving revision 1.14
diff -u -r1.14 Makefile.am
--- pics/Makefile.am	2001/05/13 02:12:24	1.14
+++ pics/Makefile.am	2002/06/13 06:53:07
@@ -2,7 +2,8 @@
 picsdir = $(kde_datadir)/kmix/pics
 pics_DATA = mix_audio.png mix_bass.png mix_cd.png mix_ext.png \
 	mix_microphone.png mix_midi.png	mix_recmon.png mix_treble.png \
-	mix_unknown.png mix_volume.png mix_surround.png mix_video.png kmixdocked.png
+	mix_unknown.png mix_volume.png mix_surround.png mix_video.png \
+    kmixdocked.png kmixdocked_mute.png
 
 EXTRA_DIST = $(pics_DATA) 
 
Index: pics/kmixdocked_mute.png
===================================================================
RCS file: kmixdocked_mute.png
diff -N kmixdocked_mute.png
Binary files /dev/null and kmixdocked_mute.png differ

["kmixdocked_mute.png" (image/png)]
_______________________________________________
kde-multimedia mailing list
kde-multimedia@mail.kde.org
http://mail.kde.org/mailman/listinfo/kde-multimedia

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic