--- /dev/null
+#include "helpwindow.h"
+#include "ui_helpwindow.h"
+
+#include <QFile>
+#include <QLocale>
+#include <QTextStream>
+#include <QMessageBox>
+
+HelpWindow::HelpWindow(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::HelpWindow)
+{
+ //this is a stacked window on Maemo 5
+ #if defined(Q_WS_MAEMO_5)
+ //setAttribute(Qt::WA_Maemo5StackedWindow);
+ #endif
+ ui->setupUi(this);
+
+ setHelpText();
+
+}
+
+HelpWindow::~HelpWindow()
+{
+ delete ui;
+}
+
+
+/**
+ * Assigns the help text to the QTextEdit
+ */
+void HelpWindow::setHelpText()
+{
+ //get the current locale name for lacalized help messages
+ QString locale = QLocale::system().name();
+
+ //open help text
+ QFile help( ":/txt/help_" + locale );
+
+ //open the file
+ if ( !help.exists() || !help.open( QIODevice::ReadOnly ) ) {
+ //try to open the file in english language instead
+ help.setFileName(":/txt/help_en");
+ if ( !help.exists() || !help.open( QIODevice::ReadOnly ) ) {
+ QMessageBox::critical(this, tr("QCPUFreq"), tr("Cannot open help file!"));
+ return;
+ }
+ }
+
+ //read the file
+ QTextStream in( &help );
+ QString txt;
+ do {
+ txt += in.readLine();
+ txt += "\n";
+ } while ( !in.atEnd() );
+
+ ui->textEdit->setText( txt );
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>HelpWindow</class>
+ <widget class="QWidget" name="HelpWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>530</width>
+ <height>415</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Help</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QTextEdit" name="textEdit">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="styleSheet">
+ <string notr="true">background: transparent;</string>
+ </property>
+ <property name="frameShape">
+ <enum>QFrame::NoFrame</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Plain</enum>
+ </property>
+ <property name="horizontalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOff</enum>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
#include <QFile>
#include <QMessageBox>
#include <QTextStream>
-#include <QProcess>
#include <QDesktopWidget>
#if defined(Q_WS_MAEMO_5)
#include <QMaemo5InformationBox>
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();
//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;
}
*/
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( action );
arguments.append( param );
- helper.execute( "sudo", arguments );
+ helperProcess->start( "sudo", arguments, QIODevice::NotOpen );
+
+ if ( showSudoError && !helperProcess->waitForFinished( 200 )) {
+ //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();
}
else
return 0;
#else
+ //disable UI checkbox
+ ui->sr_box->setDisabled( true );
+
return 0;
#endif
}
//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
//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
/**
* 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);
/**
+ * SLOT: display the help window
+ */
+void MainWindow::showHelp()
+{
+ helpWindow->show();
+}
+
+
+/**
* Returns true when the device is in portrait mode
*/
bool MainWindow::usePortrait()
</widget>
</item>
<item row="4" column="1">
- <widget class="QPushButton" name="sr_btn">
+ <widget class="QCheckBox" name="sr_box">
<property name="sizePolicy">
- <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
- <string>Disabled</string>
+ <string>Enable SR</string>
</property>
</widget>
</item>
<property name="title">
<string>File</string>
</property>
+ <addaction name="actionHelp"/>
<addaction name="actionAbout"/>
</widget>
<addaction name="menuFile"/>
<string>About</string>
</property>
</action>
+ <action name="actionHelp">
+ <property name="text">
+ <string>Help</string>
+ </property>
+ </action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>