diff -ur kdeutils-3.5.2-orig/kmilo/asus/asus.cpp kdeutils-3.5.2/kmilo/asus/asus.cpp --- kdeutils-3.5.2-orig/kmilo/asus/asus.cpp 2006-01-19 17:49:13.000000000 +0100 +++ kdeutils-3.5.2/kmilo/asus/asus.cpp 2006-11-12 11:07:07.000000000 +0100 @@ -31,8 +31,12 @@ #include "kmilointerface.h" +#include "asus.moc" #include "asus.h" +#include +#include + #ifdef Q_OS_FREEBSD #include #include @@ -40,14 +44,23 @@ #define ROUND(x) (int(x + 0.5)) +#define ACPID_SOCKET "/var/run/acpid.socket" + namespace KMilo { AsusMonitor::AsusMonitor(QObject* parent, const char* name, const QStringList& args): Monitor(parent, name, args) { + acpid = NULL; + m_volume = 50; + m_mute = 0; + m_volumeMaster = 1; } AsusMonitor::~AsusMonitor() { + delete kmixClient; + delete kmixWindow; + closeAcpidSocket(); } bool AsusMonitor::init() @@ -75,6 +88,10 @@ kdDebug() << "/proc/acpi/asus doesn't exist, check that the asus_acpi module is loaded" << endl; return false; } + if(!initAcpidSocket()) + { + kdDebug() << ACPID_SOCKET " doesn't exist, check that acpid is running" << endl; + } #endif else { @@ -84,6 +101,10 @@ { return false; } + kmixClient = new DCOPRef("kmix", "Mixer0"); + kmixWindow = new DCOPRef("kmix", "kmix-mainwindow#1"); + retrieveVolume(); + retrieveMute(); } return true; @@ -105,20 +126,14 @@ m_progress = ROUND(value * 100); } - if (last_asus_state.lcd != asus_state.lcd) - { - if (asus_state.lcd == 0) - { - _interface->displayText(i18n("Display changed: LCD off")); - } - else - { - _interface->displayText(i18n("Display changed: LCD on")); - } + + // determine the state of wireless lan + if (asus_state.lcd != last_asus_state.lcd) { + showToggleMessage(i18n("Display changed: LCD on"), i18n("Display changed: LCD off"), asus_state.lcd == 1); } if (last_asus_state.display != asus_state.display) - { + { switch (asus_state.display) { case 0: @@ -145,12 +160,64 @@ case 7: _interface->displayText(i18n("Display changed: LCD, CRT and TV out on")); break; + case 8: + _interface->displayText(i18n("Display changed: DVI on")); + break; + case 9: + _interface->displayText(i18n("Display changed: DVI and LCD on")); + break; + case 10: + _interface->displayText(i18n("Display changed: DVI and CRT on")); + break; + case 11: + _interface->displayText(i18n("Display changed: DVI, LCD and CRT on")); + break; + case 12: + _interface->displayText(i18n("Display changed: DVI and TV out on")); + break; + case 13: + _interface->displayText(i18n("Display changed: DVI, LCD and TV out on")); + break; + case 14: + _interface->displayText(i18n("Display changed: DVI, CRT and TV out on")); + break; + case 15: + _interface->displayText(i18n("Display changed: DVI, LCD, CRT and TV out on")); + break; + } } + if (last_asus_state.mled != asus_state.mled) + { + if (asus_state.mled == 1) + { + _interface->displayText(i18n("New mails")); + } + } + // determine the state of wireless lan + if (asus_state.wled != last_asus_state.wled) { + showToggleMessage(i18n("Wireless LAN is enabled"), i18n("Wireless LAN is disabled"), asus_state.wled == 1); + } + + // determine the state of bluetooth + if (asus_state.bluetooth != last_asus_state.bluetooth) { + showToggleMessage(i18n("Bluetooth is enabled"), i18n("Bluetooth is disabled"), asus_state.bluetooth == 1); + } + return pollResult; } +void AsusMonitor::showToggleMessage(QString onMessage, QString offMessage, bool state) { + QString message; + if (state) { + message = onMessage; + } else { + message = offMessage; + } + _interface->displayText(message); +} + int AsusMonitor::progress() const { @@ -174,9 +241,11 @@ #else asus_state->brightness = readProcEntry(QString("brn")); asus_state->lcd = readProcEntry(QString("lcd")); - //disabled because it does not yet work on my S5200N (asus_acpi bug) - //asus_state->display = readProcEntry(QString("disp")); - //FIXME + asus_state->display = readProcEntry(QString("disp")); + asus_state->bluetooth = readProcEntry(QString("bluetooth")); + asus_state->mled = readProcEntry(QString("mled")); + asus_state->wled = readProcEntry(QString("wled")); + asus_state->tled = readProcEntry(QString("tled")); #endif return true; } @@ -201,11 +270,186 @@ return 0; } +bool AsusMonitor::initAcpidSocket() +{ + acpid = new KSocket(ACPID_SOCKET); + if (acpid->socket() >= 0) { + fcntl(acpid->socket(), F_SETFL, O_NONBLOCK); + acpid->enableRead(true); + acpid->enableWrite(false); + } + else + { + return false; + } + + connect(acpid, SIGNAL(readEvent (KSocket *)), this, SLOT(readAcpidEvent())); + connect(acpid, SIGNAL(closeEvent(KSocket *)), this, SLOT(closeAcpidEvent())); + return true; +} + +void AsusMonitor::closeAcpidSocket() +{ + delete acpid; +} + +void AsusMonitor::closeAcpidEvent() +{ + closeAcpidSocket(); +} + +bool AsusMonitor::readAcpidEvent() +{ + char buffer; + QString rxBuffer = ""; + + do { + if ( recv( acpid->socket(), &buffer, 1, 0) < 1) + { + if (errno != EWOULDBLOCK) + return false; + } + else + rxBuffer += buffer; + + } while (buffer != '\n'); + + /* + * remove \r\n from the string and don't transmit empty lines + */ + + if ( rxBuffer.length() > 2 ) + { + rxBuffer.truncate(rxBuffer.length()-2); + handleAcpidEvent(rxBuffer); + return true; + } + else + return false; +} + +bool AsusMonitor::handleAcpidEvent(QString event) +{ + //kdDebug() << "handle event" << event << endl; + if (event.contains("hotkey ATKD 00000030")) + { + increaseVolume(); + displayVolume(); + } + else if (event.contains("hotkey ATKD 00000031")) + { + decreaseVolume(); + displayVolume(); + } + else if (event.contains("hotkey ATKD 00000032")) + { + kmixClient->send("toggleMute", m_volumeMaster); + displayMute(); + } + else + { + return false; + } + + return true; +} + +bool AsusMonitor::retrieveVolume() { + bool kmix_error = false; + + + DCOPReply reply = kmixClient->call("volume", m_volumeMaster); + if (reply.isValid()) { + m_volume = reply; + } else { + kmix_error = true; + } + + if (kmix_error) { // maybe the error occurred because kmix wasn't running + if (kapp->startServiceByDesktopName("kmix") == 0) { // trying to start kmix + // trying again + reply = kmixClient->call("volume", m_volumeMaster); + if (reply.isValid()) { + m_volume = reply; + kmix_error = false; + kmixWindow->send("minimize"); + } + } + } + + if (kmix_error) { + kdError() << "KMilo: AsusMonitor could not access kmix/Mixer0 via dcop" << endl; + return false; + } else { + return true; + } +} + +bool AsusMonitor::retrieveMute() { + bool kmix_error = false; + + + DCOPReply reply = kmixClient->call("mute", m_volumeMaster); + if (reply.isValid()) { + m_mute = reply; + } else { + kmix_error = true; + } + + if (kmix_error) { // maybe the error occurred because kmix wasn't running + if (kapp->startServiceByDesktopName("kmix") == 0) { // trying to start kmix + // trying again + reply = kmixClient->call("mute", m_volumeMaster); + if (reply.isValid()) { + m_mute = reply; + kmix_error = false; + kmixWindow->send("minimize"); + } + } + } + + if (kmix_error) { + kdError() << "KMilo: AsusMonitor could not access kmix/Mixer0 via dcop" << endl; + return false; + } else { + return true; + } +} + +void AsusMonitor::increaseVolume() { + kmixClient->send("increaseVolume", m_volumeMaster); + + if(retrieveVolume()) + m_progress = m_volume; +} + +void AsusMonitor::decreaseVolume() { + kmixClient->send("decreaseVolume", m_volumeMaster); + + if(retrieveVolume()) + m_progress = m_volume; +} + +void AsusMonitor::displayVolume() +{ + _interface->displayProgress(i18n("Volume"), m_volume); +} + +void AsusMonitor::displayMute() +{ + retrieveMute(); + showToggleMessage(i18n("Mute on"), i18n("Mute off"), m_mute); +} + void AsusMonitor::clearStruct(asus_state_struct& asus_state) { asus_state.brightness = 0; asus_state.lcd = 0; asus_state.display = 0; + asus_state.bluetooth = 0; + asus_state.mled = 0; + asus_state.wled = 0; + asus_state.tled = 0; } } Seulement dans kdeutils-3.5.2/kmilo/asus/: asus.cpp~ diff -ur kdeutils-3.5.2-orig/kmilo/asus/asus.h kdeutils-3.5.2/kmilo/asus/asus.h --- kdeutils-3.5.2-orig/kmilo/asus/asus.h 2006-01-19 17:49:13.000000000 +0100 +++ kdeutils-3.5.2/kmilo/asus/asus.h 2006-11-12 11:04:21.000000000 +0100 @@ -25,6 +25,7 @@ #include #include +#include #include "monitor.h" @@ -32,15 +33,23 @@ typedef struct { + /* Display */ unsigned int brightness; unsigned int lcd; unsigned int display; + + /* Leds */ + unsigned int bluetooth; + unsigned int mled; /* Mail */ + unsigned int wled; /* Wlan */ + unsigned int tled; /* Touchpad */ } asus_state_struct; /** * KMilo plugin for Asus Laptops */ class AsusMonitor: public Monitor { + Q_OBJECT public: AsusMonitor(QObject *parent, const char *name, const QStringList&); virtual ~AsusMonitor(); @@ -71,11 +80,44 @@ asus_state_struct last_asus_state; asus_state_struct asus_state; + KSocket *acpid; + + void showToggleMessage(QString , QString , bool ); + + /** + * Some informations are in /proc/acpi/asus ... + */ bool readProc(asus_state_struct* ); int readProcEntry(const QString &); + /** + * But we need acpid for hotkeys + */ + bool initAcpidSocket(); + void closeAcpidSocket(); + bool handleAcpidEvent(QString ); + private slots: + bool readAcpidEvent(); + void closeAcpidEvent(); + + private: void clearStruct(asus_state_struct& asus_state); + /** + * Volume + */ + void increaseVolume(); + void decreaseVolume(); + DCOPRef* kmixClient; + DCOPRef* kmixWindow; + bool retrieveKmixValue(QCString , int, int &); + bool retrieveVolume(); + bool retrieveMute(); + void displayVolume(); + void displayMute(); + int m_volume, m_volumeMaster; + bool m_mute; + #ifdef Q_OS_FREEBSD int brightness_mib[4]; int backlight_mib[4]; Seulement dans kdeutils-3.5.2/kmilo/asus/: asus.h~ Seulement dans kdeutils-3.5.2/kmilo/asus/: asus.moc diff -ur kdeutils-3.5.2-orig/kmilo/asus/Makefile.in kdeutils-3.5.2/kmilo/asus/Makefile.in --- kdeutils-3.5.2-orig/kmilo/asus/Makefile.in 2006-03-18 15:00:00.000000000 +0100 +++ kdeutils-3.5.2/kmilo/asus/Makefile.in 2006-11-11 19:54:39.000000000 +0100 @@ -121,6 +121,7 @@ #>+ 1 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) $(KDE_DIST) ACLOCAL = @ACLOCAL@ +MOC = @MOC@ AMDEP_FALSE = @AMDEP_FALSE@ AMDEP_TRUE = @AMDEP_TRUE@ AMTAR = @AMTAR@ @@ -435,7 +436,7 @@ kde_module_LTLIBRARIES = kmilo_asus.la kmilo_asus_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) kmilo_asus_la_LIBADD = ../kmilod/libkmilo.la $(LIB_KIO) -kmilo_asus_la_SOURCES = asus.cpp +kmilo_asus_la_SOURCES = asus.cpp asus.moc #>- METASOURCES = AUTO noinst_HEADERS = asus.h services_DATA = kmilo_asus.desktop @@ -693,6 +694,10 @@ clean-am: clean-closures clean-bcheck clean-generic clean-kde_moduleLTLIBRARIES clean-libtool \ mostlyclean-am +#>+ 3 +clean-metasources: + -rm -f asus.moc + distclean: distclean-am -rm -rf ./$(DEPDIR) -rm -f Makefile @@ -843,5 +848,13 @@ -rm -f *.rpo #>+ 3 +asus.moc: $(srcdir)/asus.h + $(MOC) $(srcdir)/asus.h -o asus.moc + +asus.o: asus.moc +#>+ 2 +mocs: asus.moc + +#>+ 3 nmcheck: nmcheck-am: nmcheck Seulement dans kdeutils-3.5.2/kmilo/asus/: Makefile.in~