Bug 117260 - Adding volume features in Asus Kmilo plugin
Summary: Adding volume features in Asus Kmilo plugin
Status: RESOLVED UNMAINTAINED
Alias: None
Product: kmilo
Classification: Miscellaneous
Component: Asus (show other bugs)
Version: unspecified
Platform: Ubuntu Linux
: NOR wishlist
Target Milestone: ---
Assignee: Unassigned bugs mailing-list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-29 07:30 UTC by Joel
Modified: 2011-09-15 18:51 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
asus.cpp in the ASUS plugin for Kmilo (7.41 KB, text/x-c++src)
2005-11-29 07:32 UTC, Joel
Details
asus.h in the ASUS plugin for Kmilo (2.24 KB, text/x-chdr)
2005-11-29 07:33 UTC, Joel
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Joel 2005-11-29 07:30:43 UTC
Version:            (using KDE KDE 3.4.3)
Installed from:    Ubuntu Packages
OS:                Linux

Hello,

I have modified the files to add volume features in the ASUS plugin. 

We assume that acpid daemon (acpid and acpi-support package with ubuntu distrib) already handles the setting the volume with scripts (scripts which are in /etc/acpi/*, corresponding to events in /etc/acpi/events/*).

For asus (acpi4asus project), somebody wrote the script named mute.pl to mute the sound and associated the commands "aumix -v +/-5" to adjust to volume).

So, the modifications in your plugin just allow the communication with kmix via dcop to retrieve volume and mute state (much code stolen from delli8k plugin).

Tell me what you think about it.

Joel

Diff between new version and old version (asus.cpp and asus.h) :

diff -urN asus/asus.cpp asus_new/asus.cpp
--- asus/asus.cpp       2005-11-28 14:03:28.000000000 +0530
+++ asus_new/asus.cpp   2005-11-28 14:53:23.000000000 +0530
@@ -22,6 +22,7 @@
 */

 #include <kgenericfactory.h>
+#include <ktoolinvocation.h>
 #include <kconfig.h>
 #include <krun.h>
 #include <kurl.h>
@@ -84,6 +85,13 @@
                {
                        return false;
                }
+
+        /* Volume support */
+        kmixClient = new DCOPRef( "kmix", "Mixer0" );
+        if (!readVolume(&asus_state))
+               {
+                       return false;
+               }
        }

        return true;
@@ -95,9 +103,31 @@
        // save last state and get new one
        memcpy(&last_asus_state, &asus_state, sizeof(asus_state_struct));
        readProc(&asus_state);
+    /* Volume support */
+    readVolume(&asus_state);

        Monitor::DisplayType pollResult = None;

+    /* Volume support */
+    if (last_asus_state.volume != asus_state.volume)
+    {
+        pollResult = Volume;
+        m_progress = asus_state.volume;
+    }
+
+    if (last_asus_state.mute != asus_state.mute)
+    {
+        pollResult = Mute;
+        if (asus_state.mute == true)
+               {
+                       _interface->displayText(i18n("Volume Off"));
+               }
+               else
+               {
+                       _interface->displayText(i18n("Volume On"));
+               }
+    }
+
        if (last_asus_state.brightness != asus_state.brightness)
        {
                pollResult = Brightness;
@@ -201,11 +231,91 @@
        return 0;
 }

+/* Volume support */
+bool AsusMonitor::readVolume(asus_state_struct* asus_state)
+{
+    asus_state->mute = retrieveMute();
+    asus_state->volume = retrieveVolume();
+
+    return true;
+}
+
+unsigned int AsusMonitor::retrieveVolume()
+{
+    bool kmix_error = false;
+
+    DCOPReply reply = kmixClient->call( "volume", 0 );
+
+    if( reply.isValid() )
+    {
+        return reply;
+    }
+    else
+    {
+        kmix_error = true;
+    }
+
+    if (kmix_error)
+    {
+        // maybe the error occurred because kmix wasn't running
+        if( KToolInvocation::startServiceByDesktopName( "kmix" ) == 0 )            // trying to start kmix
+        {
+            // trying again
+            reply = kmixClient->call( "volume", 0 );
+            if( reply.isValid() )
+            {
+                return reply;
+            }
+        }
+    }
+
+    kdError() << "KMilo: AsusMonitor could not access kmix/Mixer0 via dcop" << endl;
+
+    return 0;
+}
+
+unsigned int AsusMonitor::retrieveMute()
+{
+    bool kmix_error = false;
+
+    DCOPReply reply = kmixClient->call( "mute", 0 );
+
+    if( reply.isValid() )
+    {
+        return reply;
+    }
+    else
+    {
+        kmix_error = true;
+    }
+
+    if (kmix_error)
+    {
+        // maybe the error occurred because kmix wasn't running
+        if( KToolInvocation::startServiceByDesktopName( "kmix" ) == 0 )            // trying to start kmix
+        {
+            // trying again
+            reply = kmixClient->call( "mute", 0 );
+            if( reply.isValid() )
+            {
+                return reply;
+            }
+        }
+    }
+
+    kdError() << "KMilo: AsusMonitor could not access kmix/Mixer0 via dcop" << endl;
+
+    return false;
+}
+
 void AsusMonitor::clearStruct(asus_state_struct& asus_state)
 {
        asus_state.brightness = 0;
        asus_state.lcd = 0;
        asus_state.display = 0;
+    /* Volume support */
+    asus_state.volume = 0;
+    asus_state.mute = false;
 }

 }
diff -urN asus/asus.h asus_new/asus.h
--- asus/asus.h 2005-11-28 14:03:28.000000000 +0530
+++ asus_new/asus.h     2005-11-28 14:20:16.000000000 +0530
@@ -33,6 +33,9 @@
        unsigned int brightness;
        unsigned int lcd;
        unsigned int display;
+    /* Volume support */
+    unsigned int volume;
+    bool mute;
 } asus_state_struct;

 /**
@@ -72,6 +75,11 @@
                bool readProc(asus_state_struct* );
                int readProcEntry(const QString &);

+        /* Volume support with kmix */
+        DCOPRef *kmixClient;
+        unsigned int retrieveVolume();
+        bool retrieveMute();
+
                void clearStruct(asus_state_struct& asus_state);

 #ifdef Q_OS_FREEBSD
Comment 1 Joel 2005-11-29 07:32:47 UTC
Created attachment 13671 [details]
asus.cpp in the ASUS plugin for Kmilo
Comment 2 Joel 2005-11-29 07:33:31 UTC
Created attachment 13672 [details]
asus.h in the ASUS plugin for Kmilo
Comment 3 CHARY Corentin 2006-11-12 13:06:49 UTC
http://xf.iksaif.net/linux/kmilo_asus_dvi_and_sound.patch

It support sound without asus_acpid daemon =) and DVI !
Comment 4 Christoph Feck 2011-09-15 18:51:59 UTC
KMilo is no longer maintained, marking all bugs accordingly.