|
|
|
@ -42,40 +42,16 @@
|
|
|
|
|
|
|
|
|
|
using namespace KMilo;
|
|
|
|
|
|
|
|
|
|
GenericMonitor::GenericMonitor(TQObject *parent, const char *name, const TQStringList& args)
|
|
|
|
|
: Monitor(parent, name, args), kmixClient(NULL), kmixWindow(NULL), tdepowersave(NULL)
|
|
|
|
|
// now the key data (from kkeyserver_x11.h and $TQTDIR/include/tqnamespace.h)
|
|
|
|
|
struct ShortcutInfo
|
|
|
|
|
{
|
|
|
|
|
_poll = false;
|
|
|
|
|
m_displayType = Monitor::None;
|
|
|
|
|
|
|
|
|
|
m_mute = false;
|
|
|
|
|
m_progress = 0;
|
|
|
|
|
m_minVolume = 0;
|
|
|
|
|
m_maxVolume = 100;
|
|
|
|
|
m_volume = 50;
|
|
|
|
|
}
|
|
|
|
|
const char* name;
|
|
|
|
|
int symbol;
|
|
|
|
|
const char *slot;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GenericMonitor::~GenericMonitor()
|
|
|
|
|
static const ShortcutInfo shortcuts[] =
|
|
|
|
|
{
|
|
|
|
|
if(ga) {
|
|
|
|
|
ga->remove("FastVolumeUp");
|
|
|
|
|
ga->remove("FastVolumeDown");
|
|
|
|
|
ga->remove("SlowVolumeUp");
|
|
|
|
|
ga->remove("SlowVolumeDown");
|
|
|
|
|
ga->remove("Mute");
|
|
|
|
|
delete ga;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GenericMonitor::init()
|
|
|
|
|
{
|
|
|
|
|
config = new TDEConfig(CONFIG_FILE);
|
|
|
|
|
reconfigure(config);
|
|
|
|
|
|
|
|
|
|
if(!m_enabled)
|
|
|
|
|
return false; // exit early if we are not supposed to run
|
|
|
|
|
|
|
|
|
|
static const ShortcutInfo shortcuts[] = {
|
|
|
|
|
{ "Search", TDEShortcut("XF86Search"), TQT_SLOT(launchSearch()) },
|
|
|
|
|
{ "Home Folder", TDEShortcut("XF86MyComputer"), TQT_SLOT(launchHomeFolder()) },
|
|
|
|
|
{ "Mail", TDEShortcut("XF86Mail"), TQT_SLOT(launchMail()) },
|
|
|
|
@ -92,10 +68,40 @@ bool GenericMonitor::init()
|
|
|
|
|
{ "FastVolumeDown", TQt::Key_VolumeDown, TQT_SLOT(fastVolumeDown()) },
|
|
|
|
|
{ "SlowVolumeUp", TQt::CTRL+TQt::Key_VolumeUp, TQT_SLOT(slowVolumeUp()) },
|
|
|
|
|
{ "SlowVolumeDown", TQt::CTRL+TQt::Key_VolumeDown, TQT_SLOT(slowVolumeDown()) },
|
|
|
|
|
{ "Mute", TDEShortcut("XF86AudioMute"), TQT_SLOT(mute()) },
|
|
|
|
|
{ "Mute", TDEShortcut("XF86AudioMute"), TQT_SLOT(toggleMute()) },
|
|
|
|
|
{ "BrightnessUp", TDEShortcut("XF86MonBrightnessUp"), TQT_SLOT(brightnessUp()) },
|
|
|
|
|
{ "BrightnessDown", TDEShortcut("XF86MonBrightnessDown"), TQT_SLOT(brightnessDown()) }
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GenericMonitor::GenericMonitor(TQObject *parent, const char *name, const TQStringList& args)
|
|
|
|
|
: Monitor(parent, name, args), kmixClient(NULL), kmixWindow(NULL), tdepowersave(NULL),
|
|
|
|
|
m_progress(0), m_displayType(Monitor::None)
|
|
|
|
|
{
|
|
|
|
|
_poll = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GenericMonitor::~GenericMonitor()
|
|
|
|
|
{
|
|
|
|
|
if (ga)
|
|
|
|
|
{
|
|
|
|
|
int len = (int)sizeof(shortcuts)/sizeof(ShortcutInfo);
|
|
|
|
|
for (int i = 0; i < len; i++)
|
|
|
|
|
{
|
|
|
|
|
ga->remove(shortcuts[i].name);
|
|
|
|
|
}
|
|
|
|
|
ga->updateConnections();
|
|
|
|
|
delete ga;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GenericMonitor::init()
|
|
|
|
|
{
|
|
|
|
|
config = new TDEConfig(CONFIG_FILE);
|
|
|
|
|
reconfigure(config);
|
|
|
|
|
|
|
|
|
|
if(!m_enabled)
|
|
|
|
|
return false; // exit early if we are not supposed to run
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ga = new TDEGlobalAccel(this, "miloGenericAccel");
|
|
|
|
|
|
|
|
|
@ -113,7 +119,7 @@ bool GenericMonitor::init()
|
|
|
|
|
ga->readSettings();
|
|
|
|
|
ga->updateConnections();
|
|
|
|
|
|
|
|
|
|
kmixClient = new DCOPRef("kmix", "Mixer0");
|
|
|
|
|
kmixClient = new DCOPRef("kmix", "kmix");
|
|
|
|
|
kmixWindow = new DCOPRef("kmix", "kmix-mainwindow#1");
|
|
|
|
|
tdepowersave = new DCOPRef("tdepowersave", "tdepowersaveIface");
|
|
|
|
|
|
|
|
|
@ -123,114 +129,72 @@ bool GenericMonitor::init()
|
|
|
|
|
void GenericMonitor::reconfigure(TDEConfig *config)
|
|
|
|
|
{
|
|
|
|
|
config->setGroup("generic monitor");
|
|
|
|
|
|
|
|
|
|
m_volumeDeviceIdx = config->readNumEntry("volumeDeviceIdx", -1);
|
|
|
|
|
m_muteDeviceIdx = config->readNumEntry("muteDeviceIdx", m_volumeDeviceIdx);
|
|
|
|
|
m_extraDeviceIdx = config->readNumEntry("extraDeviceIdx", -1);
|
|
|
|
|
m_volumeStepFast = config->readNumEntry("volumeStepFast", 10);
|
|
|
|
|
m_volumeStepSlow = config->readNumEntry("volumeStepSlow", 1);
|
|
|
|
|
m_enabled = config->readBoolEntry("enabled", true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GenericMonitor::retrieveKmixDevices()
|
|
|
|
|
bool GenericMonitor::retrieveVolume(int &volume)
|
|
|
|
|
{
|
|
|
|
|
if(m_volumeDeviceIdx != -1 && m_muteDeviceIdx != -1)
|
|
|
|
|
return true; // both indexes already set
|
|
|
|
|
DCOPReply reply = kmixClient->call("volume");
|
|
|
|
|
if (reply.isValid())
|
|
|
|
|
{
|
|
|
|
|
volume = reply;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DCOPReply reply = kmixClient->call("masterDeviceIndex");
|
|
|
|
|
if (!reply.isValid())
|
|
|
|
|
{ // maybe the error occurred because kmix wasn't running
|
|
|
|
|
// maybe the error occurred because kmix wasn't running. Try to start it
|
|
|
|
|
_interface->displayText(i18n("Starting KMix..."));
|
|
|
|
|
if (kapp->startServiceByDesktopName("kmix")==0) // trying to start kmix
|
|
|
|
|
if (kapp->startServiceByDesktopName("kmix") == 0)
|
|
|
|
|
{
|
|
|
|
|
reply = kmixClient->call("masterDeviceIndex");
|
|
|
|
|
// trying again
|
|
|
|
|
reply = kmixClient->call("volume");
|
|
|
|
|
if (reply.isValid())
|
|
|
|
|
{
|
|
|
|
|
volume = reply;
|
|
|
|
|
kmixWindow->send("hide");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!reply.isValid())
|
|
|
|
|
{
|
|
|
|
|
kdDebug() << "KMilo: GenericMonitor could not access kmix/Mixer0 via dcop"
|
|
|
|
|
<< endl;
|
|
|
|
|
kdDebug() << "KMilo: GenericMonitor could not access kmix via dcop" << endl;
|
|
|
|
|
_interface->displayText(i18n("It seems that KMix is not running."));
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
if (m_volumeDeviceIdx == -1)
|
|
|
|
|
m_volumeDeviceIdx = reply;
|
|
|
|
|
if (m_muteDeviceIdx == -1)
|
|
|
|
|
m_muteDeviceIdx = m_volumeDeviceIdx; // this is the behaviour documented in README
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GenericMonitor::retrieveVolume()
|
|
|
|
|
void GenericMonitor::volumeChange(int direction, int percentage)
|
|
|
|
|
{
|
|
|
|
|
bool kmix_error = false;
|
|
|
|
|
|
|
|
|
|
if(!retrieveKmixDevices())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
DCOPReply reply = kmixClient->call("absoluteVolume", m_volumeDeviceIdx);
|
|
|
|
|
if (reply.isValid())
|
|
|
|
|
m_volume = reply;
|
|
|
|
|
else
|
|
|
|
|
kmix_error = true;
|
|
|
|
|
|
|
|
|
|
if (kmix_error) // maybe the error occurred because kmix wasn't running
|
|
|
|
|
int volume;
|
|
|
|
|
if (!direction || !retrieveVolume(volume))
|
|
|
|
|
{
|
|
|
|
|
_interface->displayText(i18n("Starting KMix..."));
|
|
|
|
|
if (kapp->startServiceByDesktopName("kmix")==0) // trying to start kmix
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (direction > 0)
|
|
|
|
|
{
|
|
|
|
|
// trying again
|
|
|
|
|
reply = kmixClient->call("absoluteVolume", m_volumeDeviceIdx);
|
|
|
|
|
if (reply.isValid())
|
|
|
|
|
volume += percentage;
|
|
|
|
|
if (volume > 100)
|
|
|
|
|
{
|
|
|
|
|
m_volume = reply;
|
|
|
|
|
kmix_error = false;
|
|
|
|
|
kmixWindow->send("hide");
|
|
|
|
|
}
|
|
|
|
|
volume = 100;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (kmix_error)
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
kdDebug() << "KMilo: GenericMonitor could not access kmix/Mixer0 via dcop"
|
|
|
|
|
<< endl;
|
|
|
|
|
_interface->displayText(i18n("It seems that KMix is not running."));
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
reply = kmixClient->call("absoluteVolumeMax", m_volumeDeviceIdx);
|
|
|
|
|
m_maxVolume = reply;
|
|
|
|
|
reply = kmixClient->call("absoluteVolumeMin", m_volumeDeviceIdx);
|
|
|
|
|
m_minVolume = reply;
|
|
|
|
|
return true;
|
|
|
|
|
volume -= percentage;
|
|
|
|
|
if (volume < 0)
|
|
|
|
|
{
|
|
|
|
|
volume = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GenericMonitor::volumeChange(int direction, int step)
|
|
|
|
|
{
|
|
|
|
|
if (!retrieveVolume())
|
|
|
|
|
return;
|
|
|
|
|
_interface->displayProgress(i18n("Volume"), volume);
|
|
|
|
|
kmixClient->send("setVolume", volume);
|
|
|
|
|
|
|
|
|
|
/* Following snippet of code may seem to be overcomplicated, but it works for both devices with
|
|
|
|
|
* volume grain < 100 (32 tested) and devices with volume grain > 100 (256 tested) while preserving
|
|
|
|
|
* accuracy for devices with fine grain and preserving usability for devices with rough grain. */
|
|
|
|
|
int userVisibleVolume = tqRound(m_volume * 100.0 / (m_maxVolume - m_minVolume));
|
|
|
|
|
userVisibleVolume += direction * step; // add requested volume step
|
|
|
|
|
long previousVolume = m_volume;
|
|
|
|
|
m_volume = tqRound(m_minVolume + userVisibleVolume * (m_maxVolume - m_minVolume) / 100.0);
|
|
|
|
|
if (m_volume == previousVolume) // if the change was rounded to zero
|
|
|
|
|
m_volume += direction;
|
|
|
|
|
|
|
|
|
|
if (m_volume > m_maxVolume)
|
|
|
|
|
m_volume = m_maxVolume;
|
|
|
|
|
if (m_volume < m_minVolume)
|
|
|
|
|
m_volume = m_minVolume;
|
|
|
|
|
|
|
|
|
|
displayVolume();
|
|
|
|
|
// if mute then unmute
|
|
|
|
|
bool muted = false;
|
|
|
|
|
if (retrieveMute(muted) && muted)
|
|
|
|
|
{
|
|
|
|
|
kmixClient->send("setMute", false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GenericMonitor::slowVolumeUp() { volumeChange( 1, m_volumeStepSlow); }
|
|
|
|
@ -238,90 +202,53 @@ void GenericMonitor::slowVolumeDown() { volumeChange(-1, m_volumeStepSlow); }
|
|
|
|
|
void GenericMonitor::fastVolumeUp() { volumeChange( 1, m_volumeStepFast); }
|
|
|
|
|
void GenericMonitor::fastVolumeDown() { volumeChange(-1, m_volumeStepFast); }
|
|
|
|
|
|
|
|
|
|
void GenericMonitor::displayVolume()
|
|
|
|
|
bool GenericMonitor::retrieveMute(bool &muted)
|
|
|
|
|
{
|
|
|
|
|
_interface->displayProgress(i18n("Volume"), tqRound(m_volume * 100.0 / (m_maxVolume - m_minVolume)));
|
|
|
|
|
|
|
|
|
|
// If we got this far, the DCOP communication with kmix works,
|
|
|
|
|
// so we don't have to test the result.
|
|
|
|
|
// Also, device indexes are set to their proper values.
|
|
|
|
|
kmixClient->send("setAbsoluteVolume", m_volumeDeviceIdx, m_volume);
|
|
|
|
|
if(m_extraDeviceIdx != -1)
|
|
|
|
|
// for simplicity, use relative volume rather that absolute (extra precision is not needed here)
|
|
|
|
|
kmixClient->send("setVolume", m_extraDeviceIdx, tqRound(m_volume * 100.0 / (m_maxVolume - m_minVolume)));
|
|
|
|
|
|
|
|
|
|
// if mute then unmute
|
|
|
|
|
if (m_mute)
|
|
|
|
|
DCOPReply reply = kmixClient->call("mute");
|
|
|
|
|
if (reply.isValid())
|
|
|
|
|
{
|
|
|
|
|
m_mute = false;
|
|
|
|
|
kmixClient->send("setMute", m_muteDeviceIdx, m_mute);
|
|
|
|
|
muted = reply;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GenericMonitor::retrieveMute()
|
|
|
|
|
{
|
|
|
|
|
bool kmix_error = false;
|
|
|
|
|
|
|
|
|
|
if(!retrieveKmixDevices())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
DCOPReply reply = kmixClient->call("mute", m_muteDeviceIdx);
|
|
|
|
|
if (reply.isValid())
|
|
|
|
|
m_mute = reply;
|
|
|
|
|
else
|
|
|
|
|
kmix_error = true;
|
|
|
|
|
|
|
|
|
|
if (kmix_error)
|
|
|
|
|
{
|
|
|
|
|
// maybe the error occurred because kmix wasn't running
|
|
|
|
|
// maybe the error occurred because kmix wasn't running. Try to start it
|
|
|
|
|
_interface->displayText(i18n("Starting KMix..."));
|
|
|
|
|
if (kapp->startServiceByDesktopName("kmix")==0) // trying to start kmix
|
|
|
|
|
if (kapp->startServiceByDesktopName("kmix") == 0)
|
|
|
|
|
{
|
|
|
|
|
// trying again
|
|
|
|
|
reply = kmixClient->call("mute", m_muteDeviceIdx);
|
|
|
|
|
reply = kmixClient->call("mute");
|
|
|
|
|
if (reply.isValid())
|
|
|
|
|
{
|
|
|
|
|
m_mute = reply;
|
|
|
|
|
kmix_error = false;
|
|
|
|
|
kmixWindow->send("hide");
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
muted = reply;
|
|
|
|
|
kmixWindow->send("hide");
|
|
|
|
|
kmix_error = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (kmix_error)
|
|
|
|
|
{
|
|
|
|
|
kdDebug() << "KMilo: GenericMonitor could not access kmix/Mixer0 via dcop"
|
|
|
|
|
<< endl;
|
|
|
|
|
kdDebug() << "KMilo: GenericMonitor could not access kmix via dcop" << endl;
|
|
|
|
|
_interface->displayText(i18n("It seems that KMix is not running."));
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GenericMonitor::mute()
|
|
|
|
|
void GenericMonitor::toggleMute()
|
|
|
|
|
{
|
|
|
|
|
if (!retrieveMute())
|
|
|
|
|
bool muted = false;
|
|
|
|
|
if (!retrieveMute(muted))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_mute = !m_mute;
|
|
|
|
|
muted = !muted;
|
|
|
|
|
TQString muteText;
|
|
|
|
|
if (m_mute)
|
|
|
|
|
if (muted)
|
|
|
|
|
{
|
|
|
|
|
muteText = i18n("Mute on");
|
|
|
|
|
} else {
|
|
|
|
|
muteText = i18n("Mute off");
|
|
|
|
|
muteText = i18n("System muted");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
muteText = i18n("System unmuted");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kmixClient->send("setMute", m_muteDeviceIdx, m_mute);
|
|
|
|
|
if(m_extraDeviceIdx != -1)
|
|
|
|
|
kmixClient->send("setMute", m_extraDeviceIdx, m_mute);
|
|
|
|
|
|
|
|
|
|
kmixClient->send("setMute", muted);
|
|
|
|
|
_interface->displayText(muteText);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|