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