Added initial harmattan packaging.
[gpsdata] / src / satelliteviewwindow.cpp
1 /*
2  *  GPSData for Maemo.
3  *  Copyright (C) 2011 Roman Moravcik
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #include <QtGui>
21
22 #include "satelliteviewwindow.h"
23
24 SatelliteViewWindow::SatelliteViewWindow(QWidget *parent) : QMainWindow(parent)
25 {
26     m_screenLocked = false;
27
28     createUi();
29
30     connect(parent, SIGNAL(screenLocked(bool)), this, SLOT(onScreenLocked(bool)));
31 }
32
33 void SatelliteViewWindow::createUi()
34 {
35 #if defined(Q_OS_SYMBIAN)
36     setAttribute(Qt::WA_DeleteOnClose);
37 #elif defined(Q_WS_MAEMO_5)
38     setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
39     setWindowFlags(Qt::Dialog);
40 #endif
41
42     setWindowTitle(tr("Satellite view"));
43
44     m_satelliteView = new SatelliteView();
45 #ifdef Q_WS_MAEMO_5
46     m_satelliteView->setMinimumSize(480, 480);
47 #endif
48     setCentralWidget(m_satelliteView);
49
50 #ifdef Q_OS_SYMBIAN
51     QAction* backSoftkey = new QAction(tr("Back"), this);
52     backSoftkey->setSoftKeyRole(QAction::NegativeSoftKey);
53     connect(backSoftkey, SIGNAL(triggered()), this, SLOT(close()));
54     addAction(backSoftkey);
55 #endif
56 }
57
58 void SatelliteViewWindow::onScreenLocked(bool locked)
59 {
60     m_screenLocked = locked;
61 }
62
63 void SatelliteViewWindow::onSatellitesInViewUpdated(const QList<QGeoSatelliteInfo> &satellites)
64 {
65     if (m_screenLocked)
66         return;
67
68     m_satelliteView->updateWidget(satellites, false);
69 }
70
71 void SatelliteViewWindow::onSatellitesInUseUpdated(const QList<QGeoSatelliteInfo> &satellites)
72 {
73     if (m_screenLocked)
74         return;
75
76     m_satelliteView->updateWidget(satellites, true);
77 }
78
79 void SatelliteViewWindow::setSatelliteInfoSource(QGeoSatelliteInfoSource *satelliteInfoSource)
80 {
81     m_satellite = satelliteInfoSource;
82     if (m_satellite) {
83         connect(m_satellite, SIGNAL(satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &)), this,
84                 SLOT(onSatellitesInViewUpdated(const QList<QGeoSatelliteInfo> &)));
85         connect(m_satellite, SIGNAL(satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &)), this,
86                 SLOT(onSatellitesInUseUpdated(const QList<QGeoSatelliteInfo> &)));
87
88         m_satellite->requestUpdate();
89     }
90 }