39076b7e3e608eca64be0b3dcfe805549c48d060
[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
29 MainWindow::MainWindow(QWidget *parent)
30     : QMainWindow(parent)
31 {
32     qDebug() << __PRETTY_FUNCTION__;
33     loggedIn = false;
34     createViews();
35     setCentralWidget(situareViews);
36     createMenus();
37     setWindowTitle(tr("List view"));
38     //this->show();
39 /*
40     connect(this,SIGNAL(testLoginClosed()), this, SLOT(loginScreenClosed()));
41 */
42 }
43
44 MainWindow::~MainWindow()
45 {
46     qDebug() << __PRETTY_FUNCTION__;
47     delete toListViewAct;
48     delete toMapViewAct;
49     delete situareViews;
50 }
51
52 void MainWindow::createMenus()
53 {
54     qDebug() << __PRETTY_FUNCTION__;
55     toListViewAct = new QAction(tr("List"), this);
56     toListViewAct->setObjectName(tr("List"));
57     connect(toListViewAct, SIGNAL(triggered()), this, SLOT(toListView()));
58     toMapViewAct = new QAction(tr("Map"), this);
59     toMapViewAct->setObjectName(tr("Map"));
60     connect(toMapViewAct, SIGNAL(triggered()), this, SLOT(toMapView()));
61     viewMenu = menuBar()->addMenu(tr("View"));
62     viewMenu->addAction(toListViewAct);
63     viewMenu->addAction(toMapViewAct);
64     viewMenu->setObjectName(tr("View Menu"));
65 /*
66     FBAuth = new FacebookAuthentication(this);
67     FBAuth->show();
68     FBAuth->start();
69
70     connect(FBAuth, SIGNAL(credentialsReady()), this, SLOT(loginOK()));
71     connect(FBAuth, SIGNAL(userExit()), this, SLOT(loginScreenClosed()));
72 */
73 }
74
75 void MainWindow::createViews()
76 {
77     qDebug() << __PRETTY_FUNCTION__;
78     situareViews = new QStackedWidget;
79     situareViews->addWidget(new ListViewScreen);
80     situareViews->addWidget(new MapViewScreen);
81 }
82
83 void MainWindow::toListView()
84 {
85     qDebug() << __PRETTY_FUNCTION__;
86     switchView(0);
87 }
88
89 void MainWindow::toMapView()
90 {
91     qDebug() << __PRETTY_FUNCTION__;
92     switchView(1);
93 }
94
95 void MainWindow::switchView(int nextIndex)
96 {
97     qDebug() << __PRETTY_FUNCTION__ << ":" << nextIndex;
98     if (nextIndex < 0 || nextIndex > 1) {
99         qDebug() << tr("Illegal parameter value in MainWindow::switchView");
100         return;
101     }
102     situareViews->setCurrentIndex(nextIndex);
103     switch (situareViews->currentIndex()) {
104         case 0:
105             setWindowTitle(tr("List view"));
106             break;
107         case 1:
108             setWindowTitle(tr("Map view"));
109             break;
110         default:
111             qDebug() << tr("Illegal switch value in MainWindow::switchView");
112             break;
113     }
114 }
115
116 void MainWindow::loginScreenClosed()
117 {
118     qDebug() << __PRETTY_FUNCTION__ << loggedIn;
119     if (loggedIn) {
120         //this->show();
121         return;
122     }
123     else {
124         this->close();
125     }
126 }
127
128 void MainWindow::loginOK()
129 {
130     qDebug() << __PRETTY_FUNCTION__ << loggedIn;
131     loggedIn = true;
132 }