Integrated updateLocation, it currently uses hardcoded coordinates.
[situare] / src / ui / mainwindow.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5       Henri Lampela - henri.lampela@ixonos.com
6       Kaj Wallin - kaj.wallin@ixonos.com
7
8    Situare is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License
10    version 2 as published by the Free Software Foundation.
11
12    Situare is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with Situare; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
20    USA.
21 */
22
23 #include <QtGui>
24 #include "mainwindow.h"
25 #include "listviewscreen.h"
26 #include "mapviewscreen.h"
27 #include "facebookservice/facebookauthentication.h"
28 #include "situareservice/situareservice.h"
29
30 MainWindow::MainWindow(QWidget *parent)
31     : QMainWindow(parent)
32 {
33     qDebug() << __PRETTY_FUNCTION__;
34
35     createViews();
36     setCentralWidget(m_situareViews);
37     createMenus();
38     setWindowTitle(tr("List view"));
39     this->hide();
40
41     m_locationDialog = new UpdateLocationDialog(this);
42     connect(m_listViewScreen->m_personalInfo,SIGNAL(launchMessageUpdate()),
43             this,SLOT(openLocationUpdateDialog()));
44
45     connect(this, SIGNAL(reverseGeoReady(QString)), m_locationDialog, SLOT(setAddress(QString)));
46     connect(m_locationDialog, SIGNAL(statusUpdate(QString,bool)), this,
47             SIGNAL(statusUpdate(QString,bool)));
48 }
49
50 MainWindow::~MainWindow()
51 {
52     qDebug() << __PRETTY_FUNCTION__;
53     delete m_toListViewAct;
54     delete m_toMapViewAct;
55     delete m_situareViews;
56 }
57
58 void MainWindow::createMenus()
59 {
60     qDebug() << __PRETTY_FUNCTION__;
61     m_toListViewAct = new QAction(tr("List"), this);
62     m_toListViewAct->setObjectName(tr("List"));
63     connect(m_toListViewAct, SIGNAL(triggered()), this, SLOT(toListView()));
64     m_toMapViewAct = new QAction(tr("Map"), this);
65     m_toMapViewAct->setObjectName(tr("Map"));
66     connect(m_toMapViewAct, SIGNAL(triggered()), this, SLOT(toMapView()));
67     m_viewMenu = menuBar()->addMenu(tr("View"));
68     m_viewMenu->addAction(m_toListViewAct);
69     m_viewMenu->addAction(m_toMapViewAct);
70     m_viewMenu->setObjectName(tr("View Menu"));
71 }
72
73 void MainWindow::createViews()
74 {
75     qDebug() << __PRETTY_FUNCTION__;
76     m_listViewScreen = new ListViewScreen(this);
77     m_mapViewScreen = new MapViewScreen(this);
78
79     m_situareViews = new QStackedWidget;
80     m_situareViews->addWidget(m_listViewScreen);
81     m_situareViews->addWidget(m_mapViewScreen);
82 }
83
84 void MainWindow::toListView()
85 {
86     qDebug() << __PRETTY_FUNCTION__;
87     switchView(0);
88 }
89
90 void MainWindow::toMapView()
91 {
92     qDebug() << __PRETTY_FUNCTION__;
93     switchView(1);
94 }
95
96 void MainWindow::switchView(int nextIndex)
97 {
98     qDebug() << __PRETTY_FUNCTION__ << ":" << nextIndex;
99     if (nextIndex < 0 || nextIndex > 1) {
100         qDebug() << "Illegal parameter value in MainWindow::switchView";
101         return;
102     }
103     m_situareViews->setCurrentIndex(nextIndex);
104     switch (m_situareViews->currentIndex()) {
105         case 0:
106             setWindowTitle(tr("List view"));
107             break;
108         case 1:
109             setWindowTitle(tr("Map view"));
110             break;
111         default:
112             qDebug() << "Illegal switch value in MainWindow::switchView";
113             break;
114     }
115 }
116 void MainWindow::openLocationUpdateDialog()
117 {
118     qDebug() << __PRETTY_FUNCTION__;
119
120     emit requestReverseGeo();
121     m_locationDialog->exec();
122 }