BatteryWatcher::BatteryWatcher(QObject *parent) :
    Watcher(parent),
    mBatteryInfo(),
    mBattery(),
    mTrayIcon(0),
    mSettings()
{
    qDebug() << "Starting BatteryWatcher";
    if (!mBattery.haveBattery())
    {
        LxQt::Notification::notify(tr("No battery!"),
                                  tr("LXQt could not find data about any battery - monitoring disabled"),
                                  "lxqt-powermanagement");
    }



    connect(&mBattery, SIGNAL(batteryChanged()), this, SLOT(batteryChanged()));
    connect(&mSettings, SIGNAL(settingsChanged()), this, SLOT(settingsChanged()));
    connect(LxQt::Settings::globalSettings(), SIGNAL(iconThemeChanged()), this, SLOT(settingsChanged()));
    settingsChanged();
    batteryChanged();
}
Пример #2
0
TrayIcon::TrayIcon(Battery* battery, QObject *parent) :
    QSystemTrayIcon(parent),
    mBattery(battery),
    mSettings("razor-autosuspend")
{
    setUpstatusIcons();

    connect(battery, SIGNAL(batteryChanged()), this, SLOT(update()));
    connect(RazorSettings::globalSettings(), SIGNAL(iconThemeChanged()), this, SLOT(iconThemeChanged()));
    connect(&mSettings, SIGNAL(settingsChanged()), this, SLOT(settingsChanged()));
    connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(showStatus(QSystemTrayIcon::ActivationReason)));

    checkThemeStatusIcons();
    update();
    setVisible(mSettings.value(SHOWTRAYICON_KEY, true).toBool());
}
Пример #3
0
void
PSMoveQt::onTimeout()
{
    int ax, ay, az, gx, gy, gz, mx, my, mz, buttons, battery;

    while (psmove_poll(_move)) {
        setTrigger(psmove_get_trigger(_move));
        psmove_get_gyroscope(_move, &gx, &gy, &gz);
        if (gx != _gx || gy != _gy || gz != _gz) {
            _gx = gx;
            _gy = gy;
            _gz = gz;
            emit gyroChanged();
        }
        psmove_get_accelerometer(_move, &ax, &ay, &az);
        if (ax != _ax || ay != _ay || az != _az) {
            _ax = ax;
            _ay = ay;
            _az = az;
            emit accelerometerChanged();
        }

        psmove_get_magnetometer(_move, &mx, &my, &mz);
        if (mx != _mx || my != _my || mz != _mz) {
            _mx = mx;
            _my = my;
            _mz = mz;
            emit magnetometerChanged();
        }

        buttons = psmove_get_buttons(_move);
        if (buttons != _buttons) {
            unsigned int pressed, released;
            psmove_get_button_events(_move, &pressed, &released);

            for (int i=1; i<=PSMoveQt::T; i <<= 1) {
                if (pressed & i) {
                    emit buttonPressed(i);
                } else if (released & i) {
                    emit buttonReleased(i);
                }
            }

            _buttons = buttons;
        }

        battery = psmove_get_battery(_move);
        if (battery != _battery) {
            bool charging = (battery == Batt_CHARGING ||
                    _battery == Batt_CHARGING);

            _battery = battery;

            if (charging) {
                emit chargingChanged();
            } else if (_battery != Batt_CHARGING) {
                emit batteryChanged(_battery);
            }
        }
    }
}
Пример #4
0
//1
void MavSerialPort::sys_status_handler(){
    mavlink_msg_sys_status_decode(&message, &sys_status);
    emit batteryChanged(sys_status.voltage_battery);
}
Пример #5
0
//1
void MavSerialPort::sys_status_handler(){
  //  qDebug() << "MAVLINK_MSG_ID_SYS_STATUS\n";
    mavlink_msg_sys_status_decode(&message, &sys_status);

    emit batteryChanged();
}
void BatteryWatcher::batteryChanged()
{
    static QTime actionTime;
    static LxQt::Notification *notification = 0;

    qDebug() <<  "BatteryChanged"
             <<  "discharging:"  << mBattery.discharging()
             << "chargeLevel:" << mBattery.chargeLevel()
             << "powerlow:"    << mBattery.powerLow()
             << "actionTime:"  << actionTime;


    if (mBattery.powerLow() && mSettings.getPowerLowAction() > 0)
    {
        if (actionTime.isNull())
        {
            actionTime = QTime::currentTime().addMSecs(mSettings.getPowerLowWarningTime()*1000);
        }

        if (notification == 0)
        {
            notification = new LxQt::Notification(tr("Power low!"), this);
            notification->setTimeout(2000);
        }

        int milliSecondsToAction = QTime::currentTime().msecsTo(actionTime);

        if (milliSecondsToAction > 0)
        {
            int secondsToAction = milliSecondsToAction/1000;
            switch (mSettings.getPowerLowAction())
            {
            case LxQt::Power::PowerSuspend:
                notification->setBody(tr("Suspending in %1 seconds").arg(secondsToAction));
                break;
            case LxQt::Power::PowerHibernate:
                notification->setBody(tr("Hibernating in %1 seconds").arg(secondsToAction));
                break;
            case LxQt::Power::PowerShutdown:
                notification->setBody(tr("Shutting down in %1 seconds").arg(secondsToAction));
                break;
            }

            notification->update();

            QTimer::singleShot(200, this, SLOT(batteryChanged()));
        }
        else
        {
            doAction(mSettings.getPowerLowAction());
        }
    }
    else
    {
        if (!actionTime.isNull())
        {
            actionTime = QTime();
        }

        if (notification)
        {
            delete notification;
            notification = 0;
        }
    }

    mBatteryInfo.updateInfo(&mBattery);

    if (mSettings.isShowIcon())
        mTrayIcon->update(mBattery.discharging(), mBattery.chargeLevel(), mSettings.getPowerLowLevel());
}