X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fmainwindow.cpp;h=ae3ae67f48b9cbde1584336f961332db196b9bad;hb=31b8d1a1c494219efd0b18f7c0bee5fb6d80e187;hp=56c4b6962fbddf6ed1c97429d11978e2fe7d3027;hpb=5f02fb58a131038e91fa1250ae4865e27bcb94a2;p=qcpufreq diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 56c4b69..ae3ae67 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #if defined(Q_WS_MAEMO_5) #include @@ -30,35 +29,62 @@ #define APPNAME "QCPUFreq" -#define APPVERSION "0.2" +#define APPVERSION "0.3" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { + //this is a stacked window on Maemo 5 + #if defined(Q_WS_MAEMO_5) + setAttribute(Qt::WA_Maemo5StackedWindow); + #endif + ui->setupUi(this); refresh(); // enable auto rotation - setAutoRotaion(); + setAutoRotation(); //create a QGraphicsScene for the little chip icon scene = new QGraphicsScene(); orientationChanged(); + //create the refresh timer + refreshTimer = new QTimer(); + //refresh UI every 10 seconds + refreshTimer->start( 10000 ); + + //create helper process + helperProcess = new QProcess; + + //create a new, stackable help window + helpWindow = new HelpWindow( this ); + #if defined(Q_WS_MAEMO_5) + helpWindow->setAttribute(Qt::WA_Maemo5StackedWindow); + #endif + helpWindow->setWindowFlags( windowFlags() | Qt::Window ); + + //show errors about the sudo setup only once + showSudoError = true; + //connect signals and slots + connect(ui->actionHelp, SIGNAL(triggered()), this, SLOT(showHelp())); 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(ui->sr_box, SIGNAL(clicked()), this, SLOT(setSmartReflex())); + connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh())); } MainWindow::~MainWindow() { - delete ui; + delete helpWindow; + delete refreshTimer; delete scene; + delete ui; } @@ -96,10 +122,7 @@ void MainWindow::adjustFreq() */ 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 @@ -111,9 +134,15 @@ int MainWindow::callHelper(QString action, QString param) arguments.append( action ); arguments.append( param ); - helper.execute( "sudo", arguments ); + helperProcess->start( "sudo", arguments, QIODevice::NotOpen ); + + if ( showSudoError && !helperProcess->waitForFinished( 400 )) { + //do not show this error again + showSudoError = false; + QMessageBox::critical(this, tr("QCPUFreq"), tr("There seems to be a problem with your sudo setup!")); + } - return helper.exitCode(); + return helperProcess->exitCode(); } @@ -123,7 +152,23 @@ int MainWindow::callHelper(QString action, QString param) QString MainWindow::getCPUTemp() { #if defined(Q_WS_MAEMO_5) - return readSysFile( "devices/platform/omap34xx_temp/temp1_input_raw" ); + QFile file( "/sys/class/power_supply/bq27200-0/temp" ); + + //check if we can read a more accurate temperature (only for power kernel) + if (file.exists()) + return QString( readSysFile( "class/power_supply/bq27200-0/temp" ) + " " + QString::fromUtf8("\302\260") + "C" ); + else { + //read the current system temperature + QString tstring = readSysFile( "devices/platform/omap34xx_temp/temp1_input_raw" ); + if (tstring == "0") + return tr( "Unknown" ); + + //convert it to an integer and calculate the approx. temperature from the raw value + int tint = tstring.toInt(); + tint = ( 0.65 * tint ); + tstring.setNum(tint); + return QString( tstring + " " + QString::fromUtf8("\302\260") + "C" ); + } #endif return tr( "Unknown" ); } @@ -219,6 +264,9 @@ int MainWindow::getSmartReflexState() else return 0; #else + //disable UI checkbox + ui->sr_box->setDisabled( true ); + return 0; #endif } @@ -236,14 +284,17 @@ QString MainWindow::readSysFile(QString sys_file) //open the file if ( !file.exists() || !file.open( QIODevice::ReadOnly ) ) { - QMessageBox::critical(this, tr("QCPUFreq"), tr("Could not get information from /sys!")); - return ""; + QMessageBox::critical(this, tr("QCPUFreq"), tr("Could not get information from /sys!")); + return ""; } //read the file QTextStream in( &file ); QString txt = in.readLine(); + //close the file + file.close(); + return txt; } @@ -274,9 +325,9 @@ void MainWindow::refresh() //smart reflex button if ( getSmartReflexState() == 1 ) - ui->sr_btn->setText( tr( "Enabled" ) ); + ui->sr_box->setCheckState( Qt::Checked ); else - ui->sr_btn->setText( tr( "Disabled" ) ); + ui->sr_box->setCheckState( Qt::Unchecked ); //display frequency slider @@ -321,7 +372,7 @@ void MainWindow::orientationChanged() /** * Enables the auto-rotation feature of Maemo5 devices */ -void MainWindow::setAutoRotaion() +void MainWindow::setAutoRotation() { #if defined(Q_WS_MAEMO_5) setAttribute(Qt::WA_Maemo5AutoOrientation, true); @@ -350,6 +401,15 @@ void MainWindow::setSmartReflex() /** + * SLOT: display the help window + */ +void MainWindow::showHelp() +{ + helpWindow->show(); +} + + +/** * Returns true when the device is in portrait mode */ bool MainWindow::usePortrait()