#include <QMaemo5InformationBox>
#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 <QOrientationSensor>
+#include <QSensor>
+
+
+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()
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()));
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;
}
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();
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);
+ }
+}