2 * This file is part of jSpeed.
4 * jSpeed is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * jSpeed is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with jSpeed. If not, see <http://www.gnu.org/licenses/>.
19 #include <QtDBus/QDBusConnection>
20 #include <QtDBus/QDBusMessage>
21 #include <QtGui/QApplication>
22 #include <QtGui/QDesktopWidget>
23 #include <QtCore/QTimer>
24 #include <QtCore/QDebug>
25 #include <QMaemo5InformationBox>
26 #include "mainwindow.h"
27 #include "mainwindowstack.h"
28 #include "themeloader.h"
31 #include "widgetscreen.h"
32 #include "poialerts.h"
33 #include "speedalarm.h"
34 #include "mediaplayer.h"
35 #include "orientation.h"
36 #include <QOrientationSensor>
40 MainWindow::MainWindow(): QMainWindow(0), menu_(0), themeLoader_(0),
41 mainScreen_(0), orientation_(0)
43 setWindowTitle(tr("jSpeed"));
45 orientation_ = new Orientation(this);
46 orientation_->start();
48 QTimer::singleShot(500, this, SLOT(loadServices()));
51 MainWindow::~MainWindow()
56 void MainWindow::loadServices()
58 Odometer::instance().start();
59 QApplication::processEvents();
61 QApplication::processEvents();
62 PoiAlerts::instance().start();
63 QApplication::processEvents();
64 SpeedAlarm::instance().start();
65 QApplication::processEvents();
69 void MainWindow::addScreens()
71 stack_ = new MainWindowStack(this);
73 connect(stack_, SIGNAL(minimizePressed()), this, SLOT(minimize()));
74 connect(stack_, SIGNAL(settingsPressed()), this, SLOT(openMenu()));
75 connect(stack_, SIGNAL(closePressed()), this, SIGNAL(quit()));
77 mainScreen_ = new WidgetScreen(this);
78 WidgetScreen* detailScreen = new WidgetScreen(this);
80 themeLoader_ = new ThemeLoader(mainScreen_, detailScreen);
87 stack_->addScreen(mainScreen_);
88 stack_->addScreen(detailScreen);
90 connect(QApplication::desktop(), SIGNAL(resized(int)), stack_, SLOT(reArrange()));
92 setCentralWidget(stack_);
95 bool MainWindow::loadTheme()
97 if(!themeLoader_->load())
99 QMaemo5InformationBox::information(this, tr("Unable to load theme: %1").arg(themeLoader_->error()));
104 int orientations = 0;
106 if(mainScreen_->orientationEnabled(WidgetScreen::LANDSCAPE))
108 orientations |= Orientation::LANDSCAPE;
110 if(mainScreen_->orientationEnabled(WidgetScreen::PORTRAIT))
112 orientations |= Orientation::PORTRAIT;
115 orientation_->setSupportedOrientations(orientations);
116 orientation_->update();
121 void MainWindow::minimize()
123 QDBusConnection connection = QDBusConnection::sessionBus();
124 QDBusMessage msg = QDBusMessage::createSignal("/",
125 "com.nokia.hildon_desktop",
127 connection.send(msg);
130 void MainWindow::openMenu()
134 menu_ = new MainMenu(this);
135 connect(menu_, SIGNAL(resetTrip()), &(Odometer::instance()), SLOT(resetTrip()));
136 connect(menu_, SIGNAL(resetAll()), &(Odometer::instance()), SLOT(resetAll()));
137 connect(menu_, SIGNAL(flip()), stack_, SLOT(flip()));
138 connect(menu_, SIGNAL(themeChanged()), this, SLOT(loadTheme()));
139 connect(menu_, SIGNAL(unitChanged()), &(Odometer::instance()), SLOT(updateUnit()));
145 void MainWindow::startBacklight()
147 QTimer* timer = new QTimer(this);
148 timer->setInterval(25000);
149 connect(timer, SIGNAL(timeout()), this, SLOT(keepBacklightOn()));
153 void MainWindow::keepBacklightOn()
155 QDBusConnection connection = QDBusConnection::systemBus();
156 QDBusMessage msg = QDBusMessage::createMethodCall("com.nokia.mce",
157 "/com/nokia/mce/request",
158 "com.nokia.mce.request",
159 "req_display_blanking_pause");
161 connection.call(msg);