Integrated friendlistview with dev.
[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 "settingsdialog.h"
28 #include "facebookservice/facebookauthentication.h"
29 #include "situareservice/situareservice.h"
30
31 MainWindow::MainWindow(QWidget *parent)
32     : QMainWindow(parent)
33 {
34     qDebug() << __PRETTY_FUNCTION__;
35
36     createViews();
37     setCentralWidget(m_situareViews);
38     createMenus();
39     setWindowTitle(tr("List view"));
40     this->hide();
41
42     m_locationDialog = new UpdateLocationDialog(this);
43     connect(m_listViewScreen->m_personalInfo,SIGNAL(launchMessageUpdate()),
44             this,SLOT(openLocationUpdateDialog()));
45
46     connect(this, SIGNAL(reverseGeoReady(QString)), m_locationDialog, SLOT(setAddress(QString)));
47     connect(m_locationDialog, SIGNAL(statusUpdate(QString,bool)), this,
48             SIGNAL(statusUpdate(QString,bool)));
49
50     connect(this, SIGNAL(userDataChanged(User*,QList<User*>&)), m_listViewScreen,
51             SLOT(userDataChanged(User*,QList<User*>&)));
52
53     connect(m_listViewScreen->m_personalInfo, SIGNAL(launchUpdateFriendsStatus()),
54             this, SIGNAL(refreshUserData()));
55 }
56
57 MainWindow::~MainWindow()
58 {
59     qDebug() << __PRETTY_FUNCTION__;
60     delete m_toListViewAct;
61     delete m_toMapViewAct;
62     delete m_toSettingsAct;
63     delete m_situareViews;
64 }
65
66 void MainWindow::createMenus()
67 {
68     qDebug() << __PRETTY_FUNCTION__;
69     m_toListViewAct = new QAction(tr("List"), this);
70     m_toListViewAct->setObjectName(tr("List"));
71     connect(m_toListViewAct, SIGNAL(triggered()), this, SLOT(toListView()));
72     m_toMapViewAct = new QAction(tr("Map"), this);
73     m_toMapViewAct->setObjectName(tr("Map"));
74     connect(m_toMapViewAct, SIGNAL(triggered()), this, SLOT(toMapView()));
75     m_toSettingsAct = new QAction(tr("Settings"), this);
76     m_toSettingsAct->setObjectName(tr("Settings"));
77     connect(m_toSettingsAct, SIGNAL(triggered()), this, SLOT(openSettingsDialog()));
78     m_viewMenu = menuBar()->addMenu(tr("View"));
79     m_viewMenu->addAction(m_toListViewAct);
80     m_viewMenu->addAction(m_toMapViewAct);
81     m_viewMenu->addAction(m_toSettingsAct);
82     m_viewMenu->setObjectName(tr("View Menu"));
83 }
84
85 void MainWindow::createViews()
86 {
87     qDebug() << __PRETTY_FUNCTION__;
88     m_listViewScreen = new ListViewScreen(this);
89     m_mapViewScreen = new MapViewScreen(this);
90
91     m_situareViews = new QStackedWidget;
92     m_situareViews->addWidget(m_listViewScreen);
93     m_situareViews->addWidget(m_mapViewScreen);
94 }
95
96 void MainWindow::toListView()
97 {
98     qDebug() << __PRETTY_FUNCTION__;
99     switchView(0);
100 }
101
102 void MainWindow::toMapView()
103 {
104     qDebug() << __PRETTY_FUNCTION__;
105     switchView(1);
106 }
107
108 void MainWindow::switchView(int nextIndex)
109 {
110     qDebug() << __PRETTY_FUNCTION__ << ":" << nextIndex;
111     if (nextIndex < 0 || nextIndex > 1) {
112         qDebug() << "Illegal parameter value in MainWindow::switchView";
113         return;
114     }
115     m_situareViews->setCurrentIndex(nextIndex);
116     switch (m_situareViews->currentIndex()) {
117         case 0:
118             setWindowTitle(tr("List view"));
119             break;
120         case 1:
121             setWindowTitle(tr("Map view"));
122             break;
123         default:
124             qDebug() << "Illegal switch value in MainWindow::switchView";
125             break;
126     }
127 }
128
129 void MainWindow::openLocationUpdateDialog()
130 {
131     qDebug() << __PRETTY_FUNCTION__;
132
133     emit requestReverseGeo();
134     m_locationDialog->exec();
135 }
136
137 void MainWindow::openSettingsDialog()
138 {
139     qDebug() << __PRETTY_FUNCTION__;
140     SettingsDialog *dialog = new SettingsDialog(this);
141     dialog->show();
142 }