X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fmainwindow.cpp;h=b2f34b298c716891a22480c11daf033a42739aa0;hb=9971ca04e3017c9cdc16031e2321aefdbbe7e97c;hp=f75e4abf2c1f665fdd519fdf7d44867f939437e7;hpb=6fb8064a307b0cc7086a666a5443db48267d75bc;p=qcpufreq diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f75e4ab..b2f34b2 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -30,13 +30,14 @@ #define APPNAME "QCPUFreq" -#define APPVERSION "0.1" +#define APPVERSION "0.2" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); + refresh(); // enable auto rotation @@ -46,17 +47,24 @@ MainWindow::MainWindow(QWidget *parent) : scene = new QGraphicsScene(); orientationChanged(); + //create the refresh timer + refreshTimer = new QTimer(); + //refresh UI every 10 seconds + refreshTimer->start( 10000 ); + //connect signals and slots connect( ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()) ); connect( ui->freq_adjust, SIGNAL(valueChanged(int)), this, SLOT(adjustFreq()) ); connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(orientationChanged())); connect( ui->sr_btn, SIGNAL(clicked()), this, SLOT(setSmartReflex()) ); + connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh())); } MainWindow::~MainWindow() { delete ui; + delete refreshTimer; delete scene; } @@ -79,24 +87,44 @@ void MainWindow::adjustFreq() int newmax = getScalingFreq( ui->freq_adjust->sliderPosition() ); QString max; max.setNum( newmax ); - QStringList arguments; -#if defined(Q_WS_MAEMO_5) - //on Maemo5 the set_scalingmaxfreq-Script is not in $PATH - arguments.append( "/opt/usr/bin/set_scalingmaxfreq" ); -#else - arguments.append( "set_scalingmaxfreq" ); -#endif - arguments.append( max ); - //execute the scaling script - QProcess script; - script.execute( "sudo", arguments ); + callHelper( "set_maxfreq", max ); refresh(); } /** + * Calls the QCPUFreq helper script with "sudo action param" + * + * @param action : the action of the helper script + * @param param : the parameter for the action + * @return exit code + */ +int MainWindow::callHelper(QString action, QString param) +{ + QProcess helper; + QStringList arguments; + //run sudo in non-interactive mode + arguments.append( "-n" ); + + #if defined(Q_WS_MAEMO_5) + //On Maemo 5 the helper script resides in /opt/usr/bin, which us usually not in $PATH + arguments.append( "/opt/usr/bin/QCPUFreq.helper" ); + #else + arguments.append( "QCPUFreq.helper" ); + #endif + + arguments.append( action ); + arguments.append( param ); + + helper.execute( "sudo", arguments ); + + return helper.exitCode(); +} + + +/** * Returns the current CPU temperature */ QString MainWindow::getCPUTemp() @@ -252,13 +280,10 @@ void MainWindow::refresh() ui->cpu_temp->setText( getCPUTemp() ); //smart reflex button - if ( getSmartReflexState() == 1 ) { - ui->sr_btn->setDown( true ); + if ( getSmartReflexState() == 1 ) ui->sr_btn->setText( tr( "Enabled" ) ); - } else { - ui->sr_btn->setDown( false ); + else ui->sr_btn->setText( tr( "Disabled" ) ); - } //display frequency slider @@ -266,6 +291,8 @@ void MainWindow::refresh() ui->freq_adjust->setMaximum( getScalingSteps() ); ui->freq_adjust->setInvertedAppearance( true ); ui->freq_adjust->setSliderPosition( getScalingStep(getMaxFreq()) ); + + //ui->retranslateUi(this); } @@ -314,22 +341,15 @@ void MainWindow::setAutoRotaion() */ void MainWindow::setSmartReflex() { -//SmartReflex is only supprted on Maemo5 +//SmartReflex is only supported on Maemo5 #if defined(Q_WS_MAEMO_5) - QStringList arguments; - arguments.append( "/opt/usr/bin/set_sr" ); - if ( getSmartReflexState() == 1 ) - arguments.append( "off" ); + callHelper( "set_sr", "off"); else { QMaemo5InformationBox::information(this, tr( "SmartReflex support is known to be unstable on some devices and may cause random reboots." ), QMaemo5InformationBox::DefaultTimeout); - arguments.append( "on" ); + callHelper( "set_sr", "on"); } - //execute the sr script script - QProcess script; - script.execute( "sudo", arguments ); - #endif //refresh the UI refresh();