Ejemplo n.º 1
0
LightSettings::LightSettings( QWidget* parent,  Qt::WFlags fl )
    : QDialog( parent, fl), isStatusView( false )
{
    setWindowTitle(tr("Power Management"));
    QVBoxLayout * baseLayout = new QVBoxLayout( this );
    baseLayout->setMargin( 0 );

    QWidget * container = new QWidget();

    QScrollArea *sView = new QScrollArea;
    sView->setFocusPolicy(Qt::NoFocus);
    sView->setFrameStyle(QFrame::NoFrame);
    sView->setWidget( container );
    sView->setWidgetResizable( true );
    sView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    QVBoxLayout *lightLayout = new QVBoxLayout(container);
    lightLayout->setMargin( 0 );
    b = new LightSettingsContainer();
    QtopiaApplication::setInputMethodHint( b->interval_dim, QtopiaApplication::AlwaysOff );
    QtopiaApplication::setInputMethodHint( b->interval_lightoff, QtopiaApplication::AlwaysOff );
    QtopiaApplication::setInputMethodHint( b->interval_suspend, QtopiaApplication::AlwaysOff );

    lightLayout->addWidget(b);

    baseLayout->addWidget(sView);

    // add context menu to push its status to Profiles
    contextMenu = QSoftMenuBar::menuFor( this );
    QAction* actionCapture = new QAction( QIcon( ":icon/Note" ), tr( "Add to current profile" ), this );
    contextMenu->addAction( actionCapture );
    connect( actionCapture, SIGNAL(triggered()), this, SLOT(pushSettingStatus()) );
    connect( qApp, SIGNAL(appMessage(QString,QByteArray)),
        this, SLOT(receive(QString,QByteArray)) );

    connect( b->interval_dim, SIGNAL(valueChanged(int)), this, SLOT(updateLightOffMinValue(int)) );
    connect( b->interval_dim, SIGNAL(valueChanged(int)), this, SLOT(updateSuspendMinValue(int)) );
    connect( b->interval_lightoff, SIGNAL(valueChanged(int)), this, SLOT(updateSuspendMinValue(int)) );

    b->officon->setPixmap(QPixmap(":image/off").scaled(24, 24, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
    b->brighticon->setPixmap(QPixmap(":image/Light").scaled(24, 24, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));

    QSettings hwConfig("Trolltech", "Hardware");
    hwConfig.beginGroup("PowerManagement");
    lockMode.canSuspend = hwConfig.value("CanSuspendLock", false).toBool();    
    batteryMode.canSuspend = hwConfig.value("CanSuspend", false).toBool();
    externalMode.canSuspend = hwConfig.value("CanSuspendAC", false).toBool();
    hwConfig.endGroup();

    b->notnetworkedsuspend->hide();

    if (batteryMode.canSuspend || externalMode.canSuspend || lockMode.canSuspend) {
        b->interval_suspend->setEnabled(true);
    } else {
        b->interval_suspend->hide();
        b->label_suspend->hide();
    }

    QSettings config("Trolltech","qpe");
    
    config.beginGroup("LockPower");
    lockMode.intervalDim = config.value( "Interval_Dim", 20 ).toInt();
    lockMode.intervalLightOff = config.value("Interval_LightOff", 30).toInt();
    lockMode.intervalSuspend = config.value("Interval", 60).toInt();
    lockMode.brightness = config.value("Brightness", 255).toInt();
    lockMode.brightness = qMax(1,lockMode.brightness * qpe_sysBrightnessSteps() / 255);
    lockMode.initBrightness = lockMode.brightness;
    lockMode.dim = config.value("Dim", true).toBool();
    lockMode.lightoff = config.value("LightOff", false).toBool();
    lockMode.suspend = config.value("Suspend", true).toBool();
    lockMode.networkedsuspend = config.value("NetworkedSuspend", true).toBool();
    config.endGroup();

    config.beginGroup("BatteryPower");
    batteryMode.intervalDim = config.value( "Interval_Dim", 20 ).toInt();
    batteryMode.intervalLightOff = config.value("Interval_LightOff", 30).toInt();
    batteryMode.intervalSuspend = config.value("Interval", 60).toInt();
    batteryMode.brightness = config.value("Brightness", 255).toInt();
    batteryMode.brightness = qMax(1,batteryMode.brightness * qpe_sysBrightnessSteps() / 255);
    batteryMode.initBrightness = batteryMode.brightness;
    batteryMode.dim = config.value("Dim", true).toBool();
    batteryMode.lightoff = config.value("LightOff", false).toBool();
    batteryMode.suspend = config.value("Suspend", true).toBool();
    batteryMode.networkedsuspend = config.value("NetworkedSuspend", true).toBool();
    config.endGroup();

    config.beginGroup("ExternalPower");
    externalMode.intervalDim = config.value( "Interval_Dim", 20 ).toInt();
    externalMode.intervalLightOff = config.value("Interval_LightOff", 30).toInt();
    externalMode.intervalSuspend = config.value("Interval", 240).toInt();
    externalMode.brightness = config.value("Brightness", 255).toInt();
    externalMode.brightness = qMax(1,externalMode.brightness * qpe_sysBrightnessSteps() / 255);
    externalMode.initBrightness = externalMode.brightness;
    externalMode.dim = config.value("Dim", true).toBool();
    externalMode.lightoff = config.value("LightOff", false).toBool();   //default to leave on
    externalMode.suspend = config.value("Suspend", true).toBool();
    externalMode.networkedsuspend = config.value("NetworkedSuspend",false).toBool();
    config.endGroup();

    //must set min > 0 the screen will become completely black
    int maxbright = qpe_sysBrightnessSteps();
    b->brightness->setMaximum( maxbright );
    b->brightness->setMinimum( 1 );
    b->brightness->setTickInterval( qMax(1,maxbright/16) );
    b->brightness->setSingleStep( qMax(1,maxbright/16) );
    b->brightness->setPageStep( qMax(1,maxbright/16) );

    currentMode = &batteryMode;
    applyMode();

    connect(b->powerSource, SIGNAL(currentIndexChanged(int)),
            this, SLOT(powerTypeChanged(int)));
    if ( powerStatus.wallStatus() == QPowerStatus::Available ) {
        b->powerSource->setCurrentIndex(1);
    }

    connect(b->brightness, SIGNAL(valueChanged(int)), this, SLOT(applyBrightness()));

    QtopiaChannel *channel = new QtopiaChannel("Qtopia/PowerStatus", this);
    connect(channel, SIGNAL(received(QString,QByteArray)),
            this, SLOT(sysMessage(QString,QByteArray)));
}
Ejemplo n.º 2
0
/*  Apply light/power settings for current power source */
static void applyLightSettings(QPowerStatus *p)
{
    int initbright;
    int intervalDim;
    int intervalLightOff;
    int intervalSuspend;
    bool dim;
    bool lightoff;
    bool suspend;

    bool canSuspend;

    QSettings config("Trolltech","qpe");

    QSettings hwConfig("Trolltech", "Hardware");
    hwConfig.beginGroup("PowerManagement");
    if (p->wallStatus() == QPowerStatus::Available) {
        config.beginGroup("ExternalPower");
        canSuspend = hwConfig.value("CanSuspendAC", false).toBool();
    } else {
        config.beginGroup("BatteryPower");
        canSuspend = hwConfig.value("CanSuspend", false).toBool();
    }

    intervalDim = config.value("Interval_Dim", 20).toInt();
    config.setValue("Interval_Dim", intervalDim);
    intervalLightOff = config.value("Interval_LightOff", 30).toInt();
    config.setValue("Interval_LightOff", intervalLightOff);
    if (canSuspend) {
        if (p->wallStatus() == QPowerStatus::Available) {
            intervalSuspend = config.value("Interval", 240).toInt();
            config.setValue("Interval", intervalSuspend);
        } else {
            intervalSuspend = config.value("Interval", 60).toInt();
            config.setValue("Interval", intervalSuspend);
        }
        suspend = config.value("Suspend", true).toBool();
        config.setValue("Suspend", suspend);
    } else {
        intervalSuspend = 0;
        config.setValue("Interval", intervalSuspend);
        suspend = false;
        config.setValue("Suspend", suspend);
    }

    initbright = config.value("Brightness",  qpe_sysBrightnessSteps()).toInt();
    config.setValue("Brightness", initbright);

    dim = config.value("Dim", true).toBool();
    config.setValue("Dim", dim);
    lightoff = config.value("LightOff", false).toBool();
    config.setValue("LightOff", lightoff);

    config.sync(); //write out for syncronisation with light app

    int i_dim =      (dim ? intervalDim : 0);
    int i_lightoff = (lightoff ? intervalLightOff : 0);
    int i_suspend = (suspend ? intervalSuspend : 0);

    QtopiaServiceRequest eB("QtopiaPowerManager", "setBacklight(int)" );
    eB << -3; //forced on
    eB.send();

    QtopiaServiceRequest e("QtopiaPowerManager", "setIntervals(int,int,int)" );
    e << i_dim << i_lightoff << i_suspend;
    e.send();
}