#include <QtCore/QCoreApplication>
+#ifdef Q_WS_MAEMO_5
+#include <mce/dbus-names.h>
+#include <mce/mode-names.h>
+#endif
+
#include "mainwindow.h"
#include "asettings.h"
#include "about.h"
int data_rate = 0;
+#ifdef Q_WS_MAEMO_5
+static QDBusConnection dBusConnection = QDBusConnection::systemBus();
+#endif
+
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
accelerometer->addFilter(awidget);
accelerometer->setDataRate(data_rate);
accelerometer->start();
-
+
+#ifdef Q_WS_MAEMO_5
+ dBusInterface = new QDBusInterface(MCE_SERVICE, MCE_REQUEST_PATH,
+ MCE_REQUEST_IF, dBusConnection, this);
+
+ dBusConnection.connect(MCE_SERVICE, MCE_SIGNAL_PATH, MCE_SIGNAL_IF,
+ MCE_DISPLAY_SIG, this, SLOT(screenChange(const QDBusMessage &)));
+#endif
}
MainWindow::~MainWindow()
{
SettingsDialog dialog(this);
QSettings settings("igorinov", "ameter", this);
+ int code;
- if (dialog.exec() != QDialog::Accepted)
+ accelerometer->stop();
+ code = dialog.exec();
+ accelerometer->start();
+ if (code != QDialog::Accepted)
{
return;
}
settings.setValue("rate", data_rate);
awidget->setGravity(g_n);
- accelerometer->stop();
accelerometer->setDataRate(data_rate);
- accelerometer->start();
}
void MainWindow::setOrientation(ScreenOrientation orientation)
{
-#if defined(Q_OS_SYMBIAN)
- // If the version of Qt on the device is < 4.7.2, that attribute won't work
- if (orientation != ScreenOrientationAuto) {
- const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
- if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
- qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
- return;
- }
- }
-#endif // Q_OS_SYMBIAN
-
Qt::WidgetAttribute attribute;
switch (orientation) {
#if QT_VERSION < 0x040702
#endif
}
+#ifdef Q_WS_MAEMO_5
+void MainWindow::screenChange(const QDBusMessage &message)
+{
+ QString state = message.arguments().at(0).toString();
+ if (!state.isEmpty()) {
+ if (state == MCE_DISPLAY_OFF_STRING)
+ accelerometer->stop();
+ if (state == MCE_DISPLAY_ON_STRING)
+ accelerometer->start();
+ }
+}
+#endif
+