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"
35 MainWindow::MainWindow(): QMainWindow(0), menu_(0), themeLoader_(0), mainScreen_(0)
37 setWindowTitle(tr("jSpeed"));
40 QTimer::singleShot(500, this, SLOT(loadServices()));
43 MainWindow::~MainWindow()
48 void MainWindow::loadServices()
50 Odometer::instance().start();
51 QApplication::processEvents();
52 PoiAlerts::instance().start();
53 QApplication::processEvents();
54 SpeedAlarm::instance().start();
55 QApplication::processEvents();
59 void MainWindow::addScreens()
61 stack_ = new MainWindowStack(this);
63 connect(stack_, SIGNAL(minimizePressed()), this, SLOT(minimize()));
64 connect(stack_, SIGNAL(settingsPressed()), this, SLOT(openMenu()));
65 connect(stack_, SIGNAL(closePressed()), this, SIGNAL(quit()));
67 mainScreen_ = new WidgetScreen(this);
68 WidgetScreen* detailScreen = new WidgetScreen(this);
70 themeLoader_ = new ThemeLoader(mainScreen_, detailScreen);
77 stack_->addScreen(mainScreen_);
78 stack_->addScreen(detailScreen);
80 connect(QApplication::desktop(), SIGNAL(resized(int)), stack_, SLOT(reArrange()));
82 setCentralWidget(stack_);
85 bool MainWindow::loadTheme()
87 if(!themeLoader_->load())
89 QMaemo5InformationBox::information(this, tr("Unable to load theme: %1").arg(themeLoader_->error()));
94 if(mainScreen_->orientationEnabled(WidgetScreen::LANDSCAPE) &&
95 mainScreen_->orientationEnabled(WidgetScreen::PORTRAIT))
97 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
99 else if(mainScreen_->orientationEnabled(WidgetScreen::PORTRAIT))
101 setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
105 setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
111 void MainWindow::minimize()
113 QDBusConnection connection = QDBusConnection::sessionBus();
114 QDBusMessage msg = QDBusMessage::createSignal("/",
115 "com.nokia.hildon_desktop",
117 connection.send(msg);
120 void MainWindow::openMenu()
124 menu_ = new MainMenu(this);
125 connect(menu_, SIGNAL(resetTrip()), &(Odometer::instance()), SLOT(resetTrip()));
126 connect(menu_, SIGNAL(resetAll()), &(Odometer::instance()), SLOT(resetAll()));
127 connect(menu_, SIGNAL(flip()), stack_, SLOT(flip()));
128 connect(menu_, SIGNAL(themeChanged()), this, SLOT(loadTheme()));
129 connect(menu_, SIGNAL(unitChanged()), &(Odometer::instance()), SLOT(updateUnit()));
135 void MainWindow::startBacklight()
137 QTimer* timer = new QTimer(this);
138 timer->setInterval(25000);
139 connect(timer, SIGNAL(timeout()), this, SLOT(keepBacklightOn()));
143 void MainWindow::keepBacklightOn()
145 QDBusConnection connection = QDBusConnection::systemBus();
146 QDBusMessage msg = QDBusMessage::createMethodCall("com.nokia.mce",
147 "/com/nokia/mce/request",
148 "com.nokia.mce.request",
149 "req_display_blanking_pause");
151 connection.call(msg);