Added altitude display to detail screen. Added option to disable auto rotation.
[jspeed] / src / mainwindow.cpp
index d30e299..f8e9185 100644 (file)
 #include "widgetscreen.h"
 #include "poialerts.h"
 #include "speedalarm.h"
+#include "mediaplayer.h"
+#include "orientation.h"
+#include "settings.h"
+#include <QOrientationSensor>
+#include <QSensor>
 
-MainWindow::MainWindow(): QMainWindow(0), menu_(0), themeLoader_(0), mainScreen_(0)
+
+MainWindow::MainWindow(): QMainWindow(0), menu_(0), themeLoader_(0),
+mainScreen_(0), orientation_(0)
 {
     setWindowTitle(tr("jSpeed"));
     showFullScreen();
+    orientation_ = new Orientation(this);
+    orientation_->start();
     addScreens();
     QTimer::singleShot(500, this, SLOT(loadServices()));
 }
@@ -49,11 +58,13 @@ void MainWindow::loadServices()
 {
     Odometer::instance().start();
     QApplication::processEvents();
+    startBacklight();
+    QApplication::processEvents();
     PoiAlerts::instance().start();
     QApplication::processEvents();
     SpeedAlarm::instance().start();
     QApplication::processEvents();
-    startBacklight();
+    MediaPlayer::init();
 }
 
 void MainWindow::addScreens()
@@ -91,20 +102,21 @@ bool MainWindow::loadTheme()
         return false;
     }
 
-    if(mainScreen_->orientationEnabled(WidgetScreen::LANDSCAPE) &&
-       mainScreen_->orientationEnabled(WidgetScreen::PORTRAIT))
-    {
-        setAttribute(Qt::WA_Maemo5AutoOrientation, true);
-    }
-    else if(mainScreen_->orientationEnabled(WidgetScreen::PORTRAIT))
+    int orientations = 0;
+
+    if(mainScreen_->orientationEnabled(WidgetScreen::LANDSCAPE))
     {
-        setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
+        orientations |= Orientation::LANDSCAPE;
     }
-    else
+    if(mainScreen_->orientationEnabled(WidgetScreen::PORTRAIT))
     {
-        setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
+        orientations |= Orientation::PORTRAIT;
     }
 
+    orientation_->setSupportedOrientations(orientations);
+    onOrientationChanged();
+    orientation_->update();
+
     return true;
 }
 
@@ -127,6 +139,7 @@ void MainWindow::openMenu()
         connect(menu_, SIGNAL(flip()), stack_, SLOT(flip()));
         connect(menu_, SIGNAL(themeChanged()), this, SLOT(loadTheme()));
         connect(menu_, SIGNAL(unitChanged()), &(Odometer::instance()), SLOT(updateUnit()));
+        connect(menu_, SIGNAL(orientationChanged()), this, SLOT(onOrientationChanged()));
     }
 
     menu_->show();
@@ -150,3 +163,21 @@ void MainWindow::keepBacklightOn()
 
     connection.call(msg);
 }
+
+void MainWindow::onOrientationChanged()
+{
+    QString value = Settings::instance().value("orientation").toString();
+
+    if(value == "auto")
+    {
+        orientation_->setOrientationType(Orientation::TYPE_AUTO);
+    }
+    else if(value == "landscape")
+    {
+        orientation_->setOrientationType(Orientation::TYPE_LANDSCAPE);
+    }
+    else if(value == "portrait")
+    {
+        orientation_->setOrientationType(Orientation::TYPE_PORTRAIT);
+    }
+}