summaryrefslogtreecommitdiffstats
path: root/examples/sysinfo/dialog.cpp
diff options
context:
space:
mode:
authorLorn Potter <lorn.potter@nokia.com>2011-03-29 20:30:44 +1000
committerLorn Potter <lorn.potter@nokia.com>2011-03-29 20:30:44 +1000
commit87adf45b194543687e97ff582d78cb30fe127858 (patch)
tree06d8f3e28ab39c6f23ac55e49b62fb6d1eb5afa1 /examples/sysinfo/dialog.cpp
parentfd2c80e1b12daa72ee701307f71b330c97cc927f (diff)
add alignedtimer to sysinfo example
Diffstat (limited to 'examples/sysinfo/dialog.cpp')
-rw-r--r--examples/sysinfo/dialog.cpp182
1 files changed, 176 insertions, 6 deletions
diff --git a/examples/sysinfo/dialog.cpp b/examples/sysinfo/dialog.cpp
index cf6c60af05..820de28aab 100644
--- a/examples/sysinfo/dialog.cpp
+++ b/examples/sysinfo/dialog.cpp
@@ -42,6 +42,8 @@
#include <QMessageBox>
#include <QTimer>
#include <math.h>
+#include <QDateTime>
+
#ifndef Q_CC_MINGW
#ifdef Q_OS_WIN
// silly MS
@@ -52,7 +54,8 @@ inline float round(float x) {
#endif
Dialog::Dialog() :
QWidget(),
- saver(NULL), systemInfo(NULL), di(NULL), ni(NULL),sti(NULL),bi(NULL),dis(NULL)
+ saver(NULL), systemInfo(NULL), di(NULL), ni(NULL),sti(NULL),bi(NULL),dis(NULL),
+ alt1(0),alt2(0),alt3(0)
{
setupUi(this);
setupGeneral();
@@ -60,10 +63,6 @@ Dialog::Dialog() :
connect(comboBox,SIGNAL(activated(int)),this,SLOT(tabChanged(int)));
connect(versionComboBox,SIGNAL(activated(int)), this,SLOT(getVersion(int)));
connect(featureComboBox,SIGNAL(activated(int)), this,SLOT(getFeature(int)));
- updateDeviceLockedState();
- QTimer *timer = new QTimer(this);
- connect(timer, SIGNAL(timeout()), this, SLOT(updateDeviceLockedState()));
- timer->start(1000);
}
Dialog::~Dialog()
@@ -74,6 +73,18 @@ Dialog::~Dialog()
delete dis;
}
+void Dialog::parseArguments()
+{
+ bool ok;
+ int tab = qApp->arguments().at(1).toInt(&ok);
+ if (ok) {
+ comboBox->setCurrentIndex(tab);
+ stackedWidget->setCurrentIndex(tab);
+ tabChanged(tab);
+ }
+}
+
+
void Dialog::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
@@ -124,6 +135,9 @@ void Dialog::tabChanged(int index)
case 10:
setupSaver();
break;
+ case 11:
+ setupAlignedTimers();
+ break;
};
}
@@ -214,7 +228,10 @@ void Dialog::setupDevice()
connect(di,SIGNAL(lockStatusChanged(QSystemDeviceInfo::LockTypeFlags)),
this,SLOT(lockStatusChanged(QSystemDeviceInfo::LockTypeFlags)),Qt::UniqueConnection);
-
+ updateDeviceLockedState();
+ QTimer *timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), this, SLOT(updateDeviceLockedState()));
+ timer->start(1000);
}
void Dialog::updateKeyboard(QSystemDeviceInfo::KeyboardTypeFlags type)
@@ -1245,3 +1262,156 @@ void Dialog::cellIdChanged(int id)
cellIdLabel->setText(QString::number(id));
}
+void Dialog::setupAlignedTimer()
+{
+ connect(startButton,SIGNAL(clicked()),this,SLOT(startAlignedTimers()));
+}
+
+void Dialog::setupAlignedTimers()
+{
+ QSystemAlignedTimer alignedtimer;
+ if(alignedtimer.lastError() == QSystemAlignedTimer::AlignedTimerNotSupported) {
+ min1spinBox->setEnabled(false);
+ max1spinBox->setEnabled(false);
+
+ min2spinBox->setEnabled(false);
+ max2spinBox->setEnabled(false);
+
+ min3spinBox->setEnabled(false);
+ max3spinBox->setEnabled(false);
+
+ startButton->setEnabled(false);
+
+ checkBox_1->setEnabled(false);
+ checkBox_2->setEnabled(false);
+ checkBox_3->setEnabled(false);
+
+ timeLabel->setText("Aligned Timer is not supported on this platform");
+ return;
+ }
+
+ if (!alt1) {
+ alt1 = new QSystemAlignedTimer(this);
+
+ connect(alt1,SIGNAL(error(QSystemAlignedTimer::AlignedTimerError)),
+ this,SLOT(timerError(QSystemAlignedTimer::AlignedTimerError)));
+ connect(alt1,SIGNAL(timeout()),this,SLOT(timeout1()));
+ }
+ if (!alt2) {
+ alt2 = new QSystemAlignedTimer(this);
+
+ connect(alt2,SIGNAL(error(QSystemAlignedTimer::AlignedTimerError)),
+ this,SLOT(timerError(QSystemAlignedTimer::AlignedTimerError)));
+ connect(alt2,SIGNAL(timeout()),this,SLOT(timeout2()));
+ }
+ if (!alt3) {
+ alt3 = new QSystemAlignedTimer(this);
+
+ connect(alt3,SIGNAL(error(QSystemAlignedTimer::AlignedTimerError)),
+ this,SLOT(timerError(QSystemAlignedTimer::AlignedTimerError)));
+ connect(alt3,SIGNAL(timeout()),this,SLOT(timeout3()));
+ }
+
+ connect(startButton,SIGNAL(clicked()),this,SLOT(startAlignedTimers()),Qt::UniqueConnection);
+ connect(stopButton,SIGNAL(clicked()),this,SLOT(stopAlignedTimers()),Qt::UniqueConnection);
+
+ connect(startButton_2,SIGNAL(clicked()),this,SLOT(startAlignedTimers()),Qt::UniqueConnection);
+ connect(stopButton_2,SIGNAL(clicked()),this,SLOT(stopAlignedTimers()),Qt::UniqueConnection);
+
+ connect(startButton_3,SIGNAL(clicked()),this,SLOT(startAlignedTimers()),Qt::UniqueConnection);
+ connect(stopButton_3,SIGNAL(clicked()),this,SLOT(stopAlignedTimers()),Qt::UniqueConnection);
+}
+
+void Dialog::startAlignedTimers()
+{
+ QPushButton *button = qobject_cast<QPushButton*>(sender());
+
+ if (button == startButton) {
+ if (checkBox_1->isChecked()) {
+ QSystemAlignedTimer::singleShot(min1spinBox->value(),max1spinBox->value(),
+ this,SLOT(timeout1()));
+ } else {
+ alt1->setMinimumInterval(min1spinBox->value());
+ alt1->setMaximumInterval(max1spinBox->value());
+ alt1->start();
+ }
+ if(alt1->lastError() == QSystemAlignedTimer::NoError)
+ textEdit->append("<b>Timer 1: Start: </b>" + QDateTime::currentDateTime().toString("yyyy MMM ddd hh:mm:ss"));
+ } else if (button == startButton_2) {
+ if (checkBox_2->isChecked()) {
+ QSystemAlignedTimer::singleShot(min2spinBox->value(),max2spinBox->value(),
+ this,SLOT(timeout2()));
+ } else {
+ alt2->start(min2spinBox->value(),max2spinBox->value());
+ }
+ if(alt2->lastError() == QSystemAlignedTimer::NoError)
+ textEdit->append("<b>Timer 2: Start: </b>" + QDateTime::currentDateTime().toString("yyyy MMM ddd hh:mm:ss"));
+ } else if (button == startButton_3) {
+ if (checkBox_3->isChecked()) {
+ QSystemAlignedTimer::singleShot(min3spinBox->value(),max3spinBox->value(),
+ this,SLOT(timeout3()));
+ } else {
+ if(alt3->lastError() == QSystemAlignedTimer::NoError)
+ alt3->start(min3spinBox->value(),max3spinBox->value());
+ }
+ textEdit->append("<b>Timer 3: Start: </b>" + QDateTime::currentDateTime().toString("yyyy MMM ddd hh:mm:ss"));
+ }
+}
+
+void Dialog::timeout1()
+{
+ textEdit->append("<b>Timer 1: </b>" + QDateTime::currentDateTime().toString("yyyy MMM ddd hh:mm:ss"));
+}
+
+void Dialog::timeout2()
+{
+ textEdit->append("<b>Timer 2: </b>" + QDateTime::currentDateTime().toString("yyyy MMM ddd hh:mm:ss"));
+}
+
+void Dialog::timeout3()
+{
+ textEdit->append("<b>Timer 3: </b>" + QDateTime::currentDateTime().toString("yyyy MMM ddd hh:mm:ss"));
+}
+
+void Dialog::stopAlignedTimers()
+{
+ QPushButton *button = qobject_cast<QPushButton*>(sender());
+ if(button->objectName() == stopButton->objectName()) {
+ alt1->stop();
+ textEdit->append("<b>Timer 1: Stop: </b>" + QDateTime::currentDateTime().toString("yyyy MMM ddd hh:mm:ss"));
+ } else if(button == stopButton_2) {
+ alt2->stop();
+ textEdit->append("<b>Timer 2: Stop: </b>" + QDateTime::currentDateTime().toString("yyyy MMM ddd hh:mm:ss"));
+ } else if(button == stopButton_3) {
+ alt3->stop();
+ textEdit->append("<b>Timer 3: Stop: </b>" + QDateTime::currentDateTime().toString("yyyy MMM ddd hh:mm:ss"));
+ }
+}
+
+void Dialog::timerError(QSystemAlignedTimer::AlignedTimerError error)
+{
+ QString errorStr;
+ QSystemAlignedTimer *timer = qobject_cast<QSystemAlignedTimer*>(sender());
+ if (timer == alt1) {
+ errorStr = "<b>Timer 1: </b> ";
+ } if (timer == alt2) {
+ errorStr = "<b>Timer 2: </b> ";
+ } if (timer == alt3) {
+ errorStr = "<b>Timer 3: </b> ";
+ }
+ switch( error) {
+ case QSystemAlignedTimer::AlignedTimerNotSupported:
+ errorStr += "Timer Not Supported";
+ break;
+ case QSystemAlignedTimer::InvalidArgument:
+ errorStr += "Invalid Argument";
+ break;
+ case QSystemAlignedTimer::TimerFailed:
+ errorStr += "Timer Failed";
+ break;
+ case QSystemAlignedTimer::InternalError:
+ errorStr += "Internal Error";
+ break;
+ };
+ textEdit->append(errorStr);
+}