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"
36 MainWindow::MainWindow(): QMainWindow(0), menu_(0), themeLoader_(0), mainScreen_(0)
38 setWindowTitle(tr("jSpeed"));
41 QTimer::singleShot(500, this, SLOT(loadServices()));
44 MainWindow::~MainWindow()
49 void MainWindow::loadServices()
51 Odometer::instance().start();
52 QApplication::processEvents();
54 QApplication::processEvents();
55 PoiAlerts::instance().start();
56 QApplication::processEvents();
57 SpeedAlarm::instance().start();
58 QApplication::processEvents();
62 void MainWindow::addScreens()
64 stack_ = new MainWindowStack(this);
66 connect(stack_, SIGNAL(minimizePressed()), this, SLOT(minimize()));
67 connect(stack_, SIGNAL(settingsPressed()), this, SLOT(openMenu()));
68 connect(stack_, SIGNAL(closePressed()), this, SIGNAL(quit()));
70 mainScreen_ = new WidgetScreen(this);
71 WidgetScreen* detailScreen = new WidgetScreen(this);
73 themeLoader_ = new ThemeLoader(mainScreen_, detailScreen);
80 stack_->addScreen(mainScreen_);
81 stack_->addScreen(detailScreen);
83 connect(QApplication::desktop(), SIGNAL(resized(int)), stack_, SLOT(reArrange()));
85 setCentralWidget(stack_);
88 bool MainWindow::loadTheme()
90 if(!themeLoader_->load())
92 QMaemo5InformationBox::information(this, tr("Unable to load theme: %1").arg(themeLoader_->error()));
97 if(mainScreen_->orientationEnabled(WidgetScreen::LANDSCAPE) &&
98 mainScreen_->orientationEnabled(WidgetScreen::PORTRAIT))
100 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
102 else if(mainScreen_->orientationEnabled(WidgetScreen::PORTRAIT))
104 setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
108 setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
114 void MainWindow::minimize()
116 QDBusConnection connection = QDBusConnection::sessionBus();
117 QDBusMessage msg = QDBusMessage::createSignal("/",
118 "com.nokia.hildon_desktop",
120 connection.send(msg);
123 void MainWindow::openMenu()
127 menu_ = new MainMenu(this);
128 connect(menu_, SIGNAL(resetTrip()), &(Odometer::instance()), SLOT(resetTrip()));
129 connect(menu_, SIGNAL(resetAll()), &(Odometer::instance()), SLOT(resetAll()));
130 connect(menu_, SIGNAL(flip()), stack_, SLOT(flip()));
131 connect(menu_, SIGNAL(themeChanged()), this, SLOT(loadTheme()));
132 connect(menu_, SIGNAL(unitChanged()), &(Odometer::instance()), SLOT(updateUnit()));
138 void MainWindow::startBacklight()
140 QTimer* timer = new QTimer(this);
141 timer->setInterval(25000);
142 connect(timer, SIGNAL(timeout()), this, SLOT(keepBacklightOn()));
146 void MainWindow::keepBacklightOn()
148 QDBusConnection connection = QDBusConnection::systemBus();
149 QDBusMessage msg = QDBusMessage::createMethodCall("com.nokia.mce",
150 "/com/nokia/mce/request",
151 "com.nokia.mce.request",
152 "req_display_blanking_pause");
154 connection.call(msg);