X-Git-Url: http://git.maemo.org/git/?p=jspeed;a=blobdiff_plain;f=src%2Fmainwindow.cpp;h=f8e9185812074e9f573b209873a3bf7eb9bd1fc5;hp=f383234898e4fc73c17af489109bc88ab0625c71;hb=36d7905fbbcc49571fef5b7769707441f344d179;hpb=72650dd361fdc879b8295ef11a1e0c1cbc0cbd91 diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f383234..f8e9185 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -25,23 +25,46 @@ #include #include "mainwindow.h" #include "mainwindowstack.h" -#include "theme.h" -#include "detailwidget.h" -#include "detailscreen.h" +#include "themeloader.h" #include "mainmenu.h" #include "odometer.h" - -MainWindow::MainWindow(): QMainWindow(0), menu_(0), theme_(0) +#include "widgetscreen.h" +#include "poialerts.h" +#include "speedalarm.h" +#include "mediaplayer.h" +#include "orientation.h" +#include "settings.h" +#include +#include + + +MainWindow::MainWindow(): QMainWindow(0), menu_(0), themeLoader_(0), +mainScreen_(0), orientation_(0) { setWindowTitle(tr("jSpeed")); showFullScreen(); - Odometer::instance().start(); + orientation_ = new Orientation(this); + orientation_->start(); addScreens(); - startBacklight(); + QTimer::singleShot(500, this, SLOT(loadServices())); } MainWindow::~MainWindow() { + delete themeLoader_; +} + +void MainWindow::loadServices() +{ + Odometer::instance().start(); + QApplication::processEvents(); + startBacklight(); + QApplication::processEvents(); + PoiAlerts::instance().start(); + QApplication::processEvents(); + SpeedAlarm::instance().start(); + QApplication::processEvents(); + MediaPlayer::init(); } void MainWindow::addScreens() @@ -52,17 +75,18 @@ void MainWindow::addScreens() connect(stack_, SIGNAL(settingsPressed()), this, SLOT(openMenu())); connect(stack_, SIGNAL(closePressed()), this, SIGNAL(quit())); - DetailWidget* details = new DetailWidget(this); + mainScreen_ = new WidgetScreen(this); + WidgetScreen* detailScreen = new WidgetScreen(this); - theme_ = new Theme(details->getScreen()); + themeLoader_ = new ThemeLoader(mainScreen_, detailScreen); if(!loadTheme()) { return; } - stack_->addScreen(theme_); - stack_->addScreen(details); + stack_->addScreen(mainScreen_); + stack_->addScreen(detailScreen); connect(QApplication::desktop(), SIGNAL(resized(int)), stack_, SLOT(reArrange())); @@ -71,26 +95,28 @@ void MainWindow::addScreens() bool MainWindow::loadTheme() { - if(!theme_->load()) + if(!themeLoader_->load()) { - QMaemo5InformationBox::information(this, tr("Unable to load theme: %1").arg(theme_->error())); + QMaemo5InformationBox::information(this, tr("Unable to load theme: %1").arg(themeLoader_->error())); close(); return false; } - if(theme_->landscapeEnabled() && theme_->portraitEnabled()) - { - setAttribute(Qt::WA_Maemo5AutoOrientation, true); - } - else if(theme_->portraitEnabled()) + 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; } @@ -113,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(); @@ -136,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); + } +}