Changed implementation
[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       Jussi Laitinen jussi.laitinen@ixonos.com
8       Sami Rämö - sami.ramo@ixonos.com
9       Ville Tiensuu - ville.tiensuu@ixonos.com
10
11    Situare is free software; you can redistribute it and/or
12    modify it under the terms of the GNU General Public License
13    version 2 as published by the Free Software Foundation.
14
15    Situare is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with Situare; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
23    USA.
24 */
25
26 #include <QtGui>
27 #include <QtWebKit>
28 #include <QtAlgorithms>
29
30 #include "common.h"
31 #include "facebookservice/facebookauthentication.h"
32 #include "friendlistpanel.h"
33 #include "logindialog.h"
34 #include "map/mapview.h"
35 #include "settingsdialog.h"
36 #include "userinfopanel.h"
37 #include "zoombuttonpanel.h"
38
39 #include "mainwindow.h"
40
41 // These MUST BE HERE, compiling for Maemo fails if moved
42 #ifdef Q_WS_MAEMO_5
43 #include <QtMaemo5/QMaemo5InformationBox>
44 #include <QtGui/QX11Info>
45 #include <X11/Xatom.h>
46 #include <X11/Xlib.h>
47 #endif // Q_WS_MAEMO_5
48
49 // values for setting screen size in desktop matching N900 screen size
50 const int N900_APP_WIDTH = 800;
51 const int N900_APP_HEIGHT = 449;
52
53 MainWindow::MainWindow(QWidget *parent)
54     : QMainWindow(parent),
55     m_drawOwnLocationCrosshair(false),
56     m_loggedIn(false),
57     m_refresh(false),
58     m_ownLocationCrosshair(0),
59     m_email(),    
60     m_password(),
61     m_fullScreenButton(0),
62     m_webView(0),
63     m_cookieJar(0)
64 {
65     qDebug() << __PRETTY_FUNCTION__;
66
67     buildMap();
68
69     // build main layout
70     QHBoxLayout *layout = new QHBoxLayout;
71     layout->addWidget(m_mapView);
72     layout->setMargin(0);
73     setCentralWidget(new QWidget());
74     centralWidget()->setLayout(layout);
75
76     buildFriendListPanel();
77     buildUserInfoPanel();
78
79     m_settingsDialog = new SettingsDialog(this);
80     m_settingsDialog->hide();
81     connect(m_settingsDialog, SIGNAL(enableAutomaticLocationUpdate(bool,int)),
82             this, SIGNAL(enableAutomaticLocationUpdate(bool,int)));
83
84     createMenus();
85     setWindowTitle(tr("Situare"));
86
87     // set stacking order of widgets
88     m_zoomButtonPanel->stackUnder(m_userPanel);
89     if(m_fullScreenButton) {
90         m_fullScreenButton->stackUnder(m_zoomButtonPanel);
91         m_osmLicense->stackUnder(m_fullScreenButton);
92     } else
93         m_osmLicense->stackUnder(m_zoomButtonPanel);
94     m_ownLocationCrosshair->stackUnder(m_osmLicense);
95     m_mapView->stackUnder(m_ownLocationCrosshair);
96
97     this->toggleProgressIndicator(true);
98
99     grabZoomKeys(true);
100
101     // set screen size in desktop matching N900 screen size
102     resize(N900_APP_WIDTH, N900_APP_HEIGHT);
103 }
104
105 MainWindow::~MainWindow()
106 {
107     qDebug() << __PRETTY_FUNCTION__;
108
109     grabZoomKeys(false);
110
111     if(m_webView)
112         delete m_webView;
113
114     qDeleteAll(m_queue.begin(), m_queue.end());
115     m_queue.clear();
116 }
117
118 void MainWindow::buildFullScreenButton()
119 {
120     qDebug() << __PRETTY_FUNCTION__;
121 #ifdef Q_WS_MAEMO_5
122     m_fullScreenButton = new QToolButton(this);
123     m_fullScreenButton->setIcon(QIcon::fromTheme(QLatin1String("general_fullsize")));
124     m_fullScreenButton->setFixedSize(m_fullScreenButton->sizeHint());
125     connect(m_fullScreenButton, SIGNAL(clicked()),
126             this, SLOT(toggleFullScreen()));
127 #endif // Q_WS_MAEMO_5
128
129 }
130
131 void MainWindow::buildFriendListPanel()
132 {
133     qDebug() << __PRETTY_FUNCTION__;
134
135     m_friendsListPanel = new FriendListPanel(this);
136     m_friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
137
138     m_friendsListPanel->stackUnder(m_friendsListPanelSidebar);
139
140     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
141             m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
142
143     connect(m_friendsListPanel, SIGNAL(findFriend(QPointF)),
144             this, SIGNAL(findFriend(QPointF)));
145
146     connect(m_mapView, SIGNAL(viewResized(QSize)),
147             m_friendsListPanel, SLOT(screenResized(QSize)));
148
149     connect(this, SIGNAL(locationItemClicked(QList<QString>)),
150             m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
151
152     connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
153             m_friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
154 }
155
156 void MainWindow::buildInformationBox(const QString &message, bool modal)
157 {
158     qDebug() << __PRETTY_FUNCTION__;
159
160 #ifdef Q_WS_MAEMO_5
161     QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
162     QLabel *label = new QLabel(msgBox);
163     label->setAlignment(Qt::AlignCenter);
164     label->setText(message);
165     msgBox->setWidget(label);
166
167     if(modal) {
168         msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
169     } else {
170         msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
171     }
172 #else
173     QMessageBox *msgBox = new QMessageBox(this);
174     msgBox->button(QMessageBox::Ok);
175     msgBox->setText(message);
176     msgBox->setModal(modal);
177 #endif
178
179     queueDialog(msgBox);
180 }
181
182 void MainWindow::buildManualLocationCrosshair()
183 {
184     qDebug() << __PRETTY_FUNCTION__;
185
186     m_ownLocationCrosshair = new QLabel(this);
187     QPixmap crosshairImage(":/res/images/sight.png");
188     m_ownLocationCrosshair->setPixmap(crosshairImage);
189     m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
190     m_ownLocationCrosshair->hide();
191     m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
192
193     connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
194             this, SLOT(drawOwnLocationCrosshair(int, int)));
195 }
196
197 void MainWindow::buildMap()
198 {
199     qDebug() << __PRETTY_FUNCTION__;
200
201     m_mapView = new MapView(this);
202
203     buildZoomButtonPanel();
204     buildOsmLicense();
205     buildManualLocationCrosshair();
206     buildFullScreenButton();
207
208     connect(m_mapView, SIGNAL(viewScrolled(QPoint)),
209             this, SIGNAL(mapViewScrolled(QPoint)));
210
211     connect(this, SIGNAL(centerToSceneCoordinates(QPoint)),
212             m_mapView, SLOT(centerToSceneCoordinates(QPoint)));
213
214     connect(m_mapView, SIGNAL(viewResized(QSize)),
215             this, SIGNAL(mapViewResized(QSize)));
216
217     connect(m_mapView, SIGNAL(viewResized(QSize)),
218             this, SLOT(drawFullScreenButton(QSize)));
219
220     connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
221              this, SLOT(setViewPortSize(int, int)));
222
223     connect(this, SIGNAL(zoomLevelChanged(int)),
224             m_mapView, SLOT(setZoomLevel(int)));
225
226     connect(m_mapView, SIGNAL(viewZoomFinished()),
227             this, SIGNAL(viewZoomFinished()));
228 }
229
230 void MainWindow::buildOsmLicense()
231 {
232     qDebug() << __PRETTY_FUNCTION__;
233
234     m_osmLicense = new QLabel(this);
235     m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
236     m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
237     m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
238     m_osmLicense->setFont(QFont("Nokia Sans", 9));
239     m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
240                          m_osmLicense->fontMetrics().height());
241
242     connect(m_mapView, SIGNAL(viewResized(QSize)),
243             this, SLOT(drawOsmLicense(QSize)));
244 }
245
246 void MainWindow::buildUserInfoPanel()
247 {
248     qDebug() << __PRETTY_FUNCTION__;
249
250     m_userPanel = new UserInfoPanel(this);
251     m_userPanelSidebar = new PanelSideBar(this, LEFT);
252
253     m_userPanelSidebar->stackUnder(m_friendsListPanel);
254     m_userPanel->stackUnder(m_userPanelSidebar);
255
256     connect(m_userPanel, SIGNAL(findUser(QPointF)),
257             this, SIGNAL(findUser(QPointF)));
258
259     connect(this, SIGNAL(userLocationReady(User*)),
260             m_userPanel, SLOT(userDataReceived(User*)));
261
262     connect(m_userPanel, SIGNAL(requestReverseGeo()),
263             this, SIGNAL(requestReverseGeo()));
264
265     connect(this, SIGNAL(reverseGeoReady(QString)),
266             m_userPanel, SIGNAL(reverseGeoReady(QString)));
267
268     connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
269             this, SIGNAL(statusUpdate(QString,bool)));
270
271     connect(m_userPanel, SIGNAL(refreshUserData()),
272             this, SIGNAL(refreshUserData()));
273
274     connect(m_mapView, SIGNAL(viewResized(QSize)),
275             m_userPanel, SLOT(screenResized(QSize)));
276 }
277
278 void MainWindow::buildWebView()
279 {
280     qDebug() << __PRETTY_FUNCTION__;
281
282     if(!m_webView) {
283         m_webView = new QWebView;
284
285         connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
286                 this, SIGNAL(updateCredentials(QUrl)));
287         connect(m_webView, SIGNAL(loadFinished(bool)),
288                 this, SLOT(loadDone(bool)));
289
290         m_webView->hide();
291     }
292 }
293
294 void MainWindow::buildZoomButtonPanel()
295 {
296     qDebug() << __PRETTY_FUNCTION__;
297
298     m_zoomButtonPanel = new ZoomButtonPanel(this);
299
300     connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
301             this, SIGNAL(zoomIn()));
302
303     connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
304             this, SIGNAL(zoomOut()));
305
306     connect(this, SIGNAL(zoomLevelChanged(int)),
307             m_zoomButtonPanel, SLOT(resetButtons()));
308
309     connect(this, SIGNAL(maxZoomLevelReached()),
310             m_zoomButtonPanel, SLOT(disableZoomInButton()));
311
312     connect(this, SIGNAL(minZoomLevelReached()),
313             m_zoomButtonPanel, SLOT(disableZoomOutButton()));
314
315     connect(m_mapView, SIGNAL(viewResized(QSize)),
316             m_zoomButtonPanel, SLOT(screenResized(QSize)));
317 }
318
319 void MainWindow::clearCookieJar()
320 {
321     qDebug() << __PRETTY_FUNCTION__;
322
323     buildWebView();
324
325     if(!m_cookieJar) {
326         m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
327     }
328     QList<QNetworkCookie> emptyList;
329     emptyList.clear();
330
331     m_cookieJar->setAllCookies(emptyList);
332     m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
333 }
334
335 void MainWindow::createMenus()
336 {
337     qDebug() << __PRETTY_FUNCTION__;
338
339     // login/logout
340     m_loginAct = new QAction(tr("Login"), this);
341     connect(m_loginAct, SIGNAL(triggered()),
342             this, SIGNAL(loginActionPressed()));
343
344     // settings
345     m_toSettingsAct = new QAction(tr("Settings"), this);
346     connect(m_toSettingsAct, SIGNAL(triggered()),
347         this, SLOT(openSettingsDialog()));
348
349     // GPS
350     m_gpsToggleAct = new QAction(tr("GPS"), this);
351     m_gpsToggleAct->setCheckable(true);
352
353     connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
354             this, SIGNAL(gpsTriggered(bool)));
355
356     // automatic centering
357     m_autoCenteringAct = new QAction(tr("Auto centering"), this);
358     m_autoCenteringAct->setCheckable(true);
359     connect(m_autoCenteringAct, SIGNAL(triggered(bool)),
360         this, SIGNAL(autoCenteringTriggered(bool)));
361
362     // build the actual menu
363     m_viewMenu = menuBar()->addMenu(tr("Main"));
364     m_viewMenu->addAction(m_loginAct);
365     m_viewMenu->addAction(m_toSettingsAct);
366     m_viewMenu->addAction(m_gpsToggleAct);
367     m_viewMenu->addAction(m_autoCenteringAct);
368     m_viewMenu->setObjectName(tr("Menu"));
369 }
370
371 void MainWindow::dialogFinished(int status)
372 {
373     qDebug() << __PRETTY_FUNCTION__;
374     qDebug() << status;
375     QDialog *dialog = m_queue.takeFirst();
376     if(!dialog->objectName().isEmpty()) {
377         buildWebView();
378         if(status != 0) {
379             static_cast<LoginDialog *>(dialog)->userInput(m_email, m_password);
380
381             if(!m_cookieJar)
382                 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
383
384             m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
385
386             QStringList urlParts;
387             urlParts.append(FACEBOOK_LOGINBASE);
388             urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
389             urlParts.append(INTERVAL1);
390             urlParts.append(SITUARE_LOGIN_SUCCESS);
391             urlParts.append(INTERVAL2);
392             urlParts.append(SITUARE_LOGIN_FAILURE);
393             urlParts.append(FACEBOOK_LOGIN_ENDING);
394
395             emit saveUsername(m_email);
396             m_webView->load(QUrl(urlParts.join(EMPTY)));
397             toggleProgressIndicator(true);
398             m_refresh = true;
399         } else {
400             m_webView->stop();
401             emit cancelLoginProcess();
402         }
403     }
404
405     dialog->deleteLater();
406
407     if(!m_queue.isEmpty())
408         showInformationBox();
409 }
410
411 void MainWindow::drawFullScreenButton(const QSize &size)
412 {
413     qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
414
415     if(m_fullScreenButton) {
416         m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width()
417                                  - PANEL_PEEK_AMOUNT,
418                                  size.height() - m_fullScreenButton->size().height());
419     }
420 }
421
422 void MainWindow::drawOsmLicense(const QSize &size)
423 {
424     qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
425
426     m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
427                        - PANEL_PEEK_AMOUNT,
428                        size.height() - m_osmLicense->fontMetrics().height());
429 }
430
431 void MainWindow::drawOwnLocationCrosshair(int width, int height)
432 {
433     qDebug() << __PRETTY_FUNCTION__;
434
435     if (m_drawOwnLocationCrosshair && m_ownLocationCrosshair != 0) {
436         m_ownLocationCrosshair->move(width/2 - m_ownLocationCrosshair->pixmap()->width()/2,
437                             height/2 - m_ownLocationCrosshair->pixmap()->height()/2);
438     }
439 }
440
441 void MainWindow::gpsTimeout()
442 {
443     qDebug() << __PRETTY_FUNCTION__;
444
445     buildInformationBox(tr("GPS timeout"));
446 }
447
448 void MainWindow::grabZoomKeys(bool grab)
449 {
450     qDebug() << __PRETTY_FUNCTION__;
451
452 #ifdef Q_WS_MAEMO_5
453     // Can't grab keys unless we have a window id
454     if (!winId())
455         return;
456
457     unsigned long val = (grab) ? 1 : 0;
458     Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
459     if (!atom)
460         return;
461
462     XChangeProperty (QX11Info::display(),
463                      winId(),
464                      atom,
465                      XA_INTEGER,
466                      32,
467                      PropModeReplace,
468                      reinterpret_cast<unsigned char *>(&val),
469                      1);
470 #else
471     Q_UNUSED(grab);
472 #endif // Q_WS_MAEMO_5
473 }
474
475 void MainWindow::keyPressEvent(QKeyEvent* event)
476 {
477     qDebug() << __PRETTY_FUNCTION__;
478
479     switch (event->key()) {
480     case Qt::Key_F7:
481         event->accept();
482         emit zoomIn();
483         break;
484
485     case Qt::Key_F8:
486         event->accept();
487         emit zoomOut();
488         break;
489     }
490     QWidget::keyPressEvent(event);
491 }
492
493 void MainWindow::loadCookies()
494 {
495     qDebug() << __PRETTY_FUNCTION__;
496
497     QSettings settings(DIRECTORY_NAME, FILE_NAME);
498
499     QStringList list = settings.value(COOKIES, EMPTY).toStringList();
500
501     if(!list.isEmpty()) {
502         QList<QNetworkCookie> cookieList;
503         for(int i=0;i<list.count();i++) {
504             cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
505         }
506
507         if(!m_cookieJar)
508                m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
509
510         m_cookieJar->setAllCookies(cookieList);
511         m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
512
513     }
514 }
515
516 void MainWindow::loadDone(bool done)
517 {
518     qDebug() << __PRETTY_FUNCTION__;
519
520     // for the first time the login page is opened, we need to refresh it to get cookies working
521     if(m_refresh) {
522         m_webView->reload();
523         m_refresh = false;
524     }
525
526     if (done)
527     {
528         QWebFrame* frame = m_webView->page()->currentFrame();
529         if (frame!=NULL)
530         {
531             // set email box
532             QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
533
534             foreach (QWebElement element, emailCollection) {
535                 element.setAttribute("value", m_email.toAscii());
536             }
537             // set password box
538             QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
539             foreach (QWebElement element, passwordCollection) {
540                 element.setAttribute("value", m_password.toAscii());
541             }
542             // find connect button
543             QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
544             foreach (QWebElement element, buttonCollection)
545             {
546                 QPoint pos(element.geometry().center());
547
548                 // send a mouse click event to the web page
549                 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
550                                    Qt::NoModifier);
551                 QApplication::sendEvent(m_webView->page(), &event0);
552                 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
553                                    Qt::NoModifier);
554                 QApplication::sendEvent(m_webView->page(), &event1);
555             }
556         }
557     }
558 }
559
560 void MainWindow::loggedIn(bool logged)
561 {
562     qDebug() << __PRETTY_FUNCTION__;
563
564     m_loggedIn = logged;
565
566     if(logged) {
567         m_loginAct->setText(tr("Logout"));
568     } else {
569         clearCookieJar();
570         m_email.clear();
571         m_password.clear();
572
573         m_loginAct->setText(tr("Login"));
574     }
575     updateItemVisibility(m_loggedIn);
576 }
577
578 void MainWindow::loginFailed()
579 {
580     qDebug() << __PRETTY_FUNCTION__;
581
582     clearCookieJar();
583
584     toggleProgressIndicator(false);
585
586     startLoginProcess();
587 }
588
589 void MainWindow::loginUsingCookies()
590 {
591     qDebug() << __PRETTY_FUNCTION__;
592
593     buildWebView();
594     loadCookies();
595     
596     QStringList urlParts;
597     urlParts.append(FACEBOOK_LOGINBASE);
598     urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
599     urlParts.append(INTERVAL1);
600     urlParts.append(SITUARE_LOGIN_SUCCESS);
601     urlParts.append(INTERVAL2);
602     urlParts.append(SITUARE_LOGIN_FAILURE);
603     urlParts.append(FACEBOOK_LOGIN_ENDING);
604
605     m_webView->load(QUrl(urlParts.join(EMPTY)));
606
607 }
608
609 void MainWindow::openSettingsDialog()
610 {
611     qDebug() << __PRETTY_FUNCTION__;
612
613     m_settingsDialog->enableSituareSettings(m_gpsToggleAct->isChecked() && m_loggedIn);
614     m_settingsDialog->show();
615 }
616
617 void MainWindow::queueDialog(QDialog *dialog)
618 {
619     qDebug() << __PRETTY_FUNCTION__;
620
621     if(dialog->isModal()) {
622         m_queue.insert(0, dialog);
623     } else {
624         m_queue.append(dialog);
625     }
626
627     if(m_queue.count() == 1)
628         this->showInformationBox();
629 }
630
631 void MainWindow::saveCookies()
632 {
633     qDebug() << __PRETTY_FUNCTION__;
634
635     if(!m_cookieJar)
636         m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
637
638     QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
639     QStringList list;
640
641     for(int i=0;i<cookieList.count();i++) {
642         QNetworkCookie cookie = cookieList.at(i);
643         QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
644         list.append(QString(byteArray));
645     }
646     list.removeDuplicates();
647
648     QSettings settings(DIRECTORY_NAME, FILE_NAME);
649     settings.setValue(COOKIES, list);
650 }
651
652 void MainWindow::setAutoCenteringButtonEnabled(bool enabled)
653 {
654     qDebug() << __PRETTY_FUNCTION__;
655
656     m_autoCenteringAct->setChecked(enabled);
657 }
658
659 void MainWindow::setGPSButtonEnabled(bool enabled)
660 {
661     qDebug() << __PRETTY_FUNCTION__;
662
663     m_gpsToggleAct->setChecked(enabled);
664
665     if(m_loggedIn)
666         setOwnLocationCrosshairVisibility(!enabled);
667
668     m_autoCenteringAct->setVisible(enabled);
669 }
670
671 void MainWindow::setMapViewScene(QGraphicsScene *scene)
672 {
673     qDebug() << __PRETTY_FUNCTION__;
674
675     m_mapView->setScene(scene);
676 }
677
678 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
679 {
680     qDebug() << __PRETTY_FUNCTION__;
681
682     if (visibility) {
683         m_ownLocationCrosshair->show();
684         m_drawOwnLocationCrosshair = true;
685         drawOwnLocationCrosshair(m_viewPortWidth, m_viewPortHeight);
686     } else {
687         m_ownLocationCrosshair->hide();
688         m_drawOwnLocationCrosshair = false;
689     }
690 }
691
692 void MainWindow::setUsername(const QString &username)
693 {
694     qDebug() << __PRETTY_FUNCTION__;
695
696     m_email = username;
697 }
698
699 void MainWindow::setViewPortSize(int width, int height)
700 {
701     qDebug() << __PRETTY_FUNCTION__;
702
703     m_viewPortWidth = width;
704     m_viewPortHeight = height;
705 }
706
707 void MainWindow::toggleFullScreen()
708 {
709     qDebug() << __PRETTY_FUNCTION__;
710
711     if(windowState() == Qt::WindowNoState)
712         showFullScreen();
713     else
714         showNormal();
715 }
716
717 void MainWindow::showInformationBox()
718 {
719     qDebug() << __PRETTY_FUNCTION__;
720
721     QDialog *dialog = m_queue.takeFirst();
722     connect(dialog, SIGNAL(finished(int)),
723             this, SLOT(dialogFinished(int)));
724     dialog->show();
725     m_queue.insert(0, dialog);
726 }
727
728 void MainWindow::startLoginProcess()
729 {
730     qDebug() << __PRETTY_FUNCTION__;
731
732     LoginDialog *loginDialog = new LoginDialog();
733
734     loginDialog->setObjectName(QString("loginDialog"));
735
736     emit fetchUsernameFromSettings();
737
738     loginDialog->clearTextFields();
739
740     if(!m_email.isEmpty())
741         loginDialog->setEmailField(m_email);
742
743     queueDialog(loginDialog);
744 }
745
746 void MainWindow::toggleProgressIndicator(bool value)
747 {
748     qDebug() << __PRETTY_FUNCTION__;
749
750 #ifdef Q_WS_MAEMO_5
751     setAttribute(Qt::WA_Maemo5ShowProgressIndicator, value);
752 #else
753     Q_UNUSED(value);
754 #endif // Q_WS_MAEMO_5
755 }
756
757 void MainWindow::updateItemVisibility(bool show)
758 {
759     qDebug() << __PRETTY_FUNCTION__;
760     
761     if(show) {
762         m_friendsListPanel->show();
763         m_friendsListPanelSidebar->show();
764         m_userPanel->show();
765         m_userPanelSidebar->show();
766
767         if(m_drawOwnLocationCrosshair) {
768             m_ownLocationCrosshair->show();
769             setGPSButtonEnabled(false);
770             emit gpsTriggered(false);
771         }
772     } else {
773         m_friendsListPanel->closePanel();
774         m_friendsListPanel->hide();
775         m_friendsListPanelSidebar->hide();
776         m_userPanel->closePanel();
777         m_userPanel->hide();
778         m_userPanelSidebar->hide();
779         m_ownLocationCrosshair->hide();       
780     }
781 }
782
783 const QString MainWindow::username()
784 {
785     qDebug() << __PRETTY_FUNCTION__;
786     
787     return m_email;
788 }