#include "VBrightness.h" // Qt #include // Project #include "Logger.h" using namespace View; using namespace Gui; using namespace Storage; VBrightness::VBrightness(QObject *parent) : QObject(parent) { initConnections(); init(); } /*! * \brief VBrightness::init * Applies the user specified brightness level on start * Defaults to the maximum brightness level if the level is not set */ void VBrightness::init() { doSetBrightness(getBrightness()); } /*! * \brief VDeviceInformation::initConnections * Makes the necessary connections. Called inside VIEW_DEF_CLASS */ void VBrightness::initConnections() { connect(&_processSetBrightness, SIGNAL(finished(int)), this, SLOT(onProcessSetBrightnessFinished(int))); } /*! * \brief VBrightness::doSetBrightness * Called when the user tries to set the current brightness * \param vBrightness (quint32) the brightness level */ void VBrightness::doSetBrightness(const quint32 &vBrightness) { if (_processSetBrightness.state() != QProcess::NotRunning) return; brightness(vBrightness); _processSetBrightness.start(Brightness_Set, QStringList() << QString("%0").arg(vBrightness)); } /*! * \brief VBrightness::onProcessSetBrightnessFinished * Called when the process to set the brightness has finished * \param vExitCode (int) the exit code */ void VBrightness::onProcessSetBrightnessFinished(const int &vExitCode) { if (vExitCode != 0) { status(tr("Failed to set brightness")); } } /*! * \brief VBrightness::doGetBrightness * Gets the current brightness level */ void VBrightness::doGetBrightness() { brightness(getBrightness()); } /*! * \brief VBrightness::getBrightness * Gets the current brightness level from settings * \return (quint32) the current brightness level */ quint32 VBrightness::getBrightness() const { bool ok = false; QVariant currentLevel = BrightnessSettings.value(Brightness_Level, brightnessMaximum()); quint32 level = currentLevel.toInt(&ok); if (ok) return level; return brightnessMaximum(); } /*! * \brief VBrightness::doSaveBrightness * Saves the brightness level to the settings file */ void VBrightness::doSaveBrightness() { // update settings BrightnessSettings.setValue(Brightness_Level, brightness()); }