Added queue for information notes
[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::buildManualLocationCrosshair()
157 {
158     qDebug() << __PRETTY_FUNCTION__;
159
160     m_ownLocationCrosshair = new QLabel(this);
161     QPixmap crosshairImage(":/res/images/sight.png");
162     m_ownLocationCrosshair->setPixmap(crosshairImage);
163     m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
164     m_ownLocationCrosshair->hide();
165     m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
166
167     connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
168             this, SLOT(drawOwnLocationCrosshair(int, int)));
169 }
170
171 void MainWindow::buildMap()
172 {
173     qDebug() << __PRETTY_FUNCTION__;
174
175     m_mapView = new MapView(this);
176
177     buildZoomButtonPanel();
178     buildOsmLicense();
179     buildManualLocationCrosshair();
180     buildFullScreenButton();
181
182     connect(m_mapView, SIGNAL(viewScrolled(QPoint)),
183             this, SIGNAL(mapViewScrolled(QPoint)));
184
185     connect(this, SIGNAL(centerToSceneCoordinates(QPoint)),
186             m_mapView, SLOT(centerToSceneCoordinates(QPoint)));
187
188     connect(m_mapView, SIGNAL(viewResized(QSize)),
189             this, SIGNAL(mapViewResized(QSize)));
190
191     connect(m_mapView, SIGNAL(viewResized(QSize)),
192             this, SLOT(drawFullScreenButton(QSize)));
193
194     connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
195              this, SLOT(setViewPortSize(int, int)));
196
197     connect(this, SIGNAL(zoomLevelChanged(int)),
198             m_mapView, SLOT(setZoomLevel(int)));
199
200     connect(m_mapView, SIGNAL(viewZoomFinished()),
201             this, SIGNAL(viewZoomFinished()));
202 }
203
204 void MainWindow::buildOsmLicense()
205 {
206     qDebug() << __PRETTY_FUNCTION__;
207
208     m_osmLicense = new QLabel(this);
209     m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
210     m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
211     m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
212     m_osmLicense->setFont(QFont("Nokia Sans", 9));
213     m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
214                          m_osmLicense->fontMetrics().height());
215
216     connect(m_mapView, SIGNAL(viewResized(QSize)),
217             this, SLOT(drawOsmLicense(QSize)));
218 }
219
220 void MainWindow::buildUserInfoPanel()
221 {
222     qDebug() << __PRETTY_FUNCTION__;
223
224     m_userPanel = new UserInfoPanel(this);
225     m_userPanelSidebar = new PanelSideBar(this, LEFT);
226
227     m_userPanelSidebar->stackUnder(m_friendsListPanel);
228     m_userPanel->stackUnder(m_userPanelSidebar);
229
230     connect(m_userPanel, SIGNAL(findUser(QPointF)),
231             this, SIGNAL(findUser(QPointF)));
232
233     connect(this, SIGNAL(userLocationReady(User*)),
234             m_userPanel, SLOT(userDataReceived(User*)));
235
236     connect(m_userPanel, SIGNAL(requestReverseGeo()),
237             this, SIGNAL(requestReverseGeo()));
238
239     connect(this, SIGNAL(reverseGeoReady(QString)),
240             m_userPanel, SIGNAL(reverseGeoReady(QString)));
241
242     connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
243             this, SIGNAL(statusUpdate(QString,bool)));
244
245     connect(m_userPanel, SIGNAL(refreshUserData()),
246             this, SIGNAL(refreshUserData()));
247
248     connect(m_mapView, SIGNAL(viewResized(QSize)),
249             m_userPanel, SLOT(screenResized(QSize)));
250 }
251
252 void MainWindow::buildWebView()
253 {
254     qDebug() << __PRETTY_FUNCTION__;
255
256     if(!m_webView) {
257         m_webView = new QWebView;
258
259         connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
260                 this, SIGNAL(updateCredentials(QUrl)));
261         connect(m_webView, SIGNAL(loadFinished(bool)),
262                 this, SLOT(loadDone(bool)));
263
264         m_webView->hide();
265     }
266 }
267
268 void MainWindow::buildZoomButtonPanel()
269 {
270     qDebug() << __PRETTY_FUNCTION__;
271
272     m_zoomButtonPanel = new ZoomButtonPanel(this);
273
274     connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
275             this, SIGNAL(zoomIn()));
276
277     connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
278             this, SIGNAL(zoomOut()));
279
280     connect(this, SIGNAL(zoomLevelChanged(int)),
281             m_zoomButtonPanel, SLOT(resetButtons()));
282
283     connect(this, SIGNAL(maxZoomLevelReached()),
284             m_zoomButtonPanel, SLOT(disableZoomInButton()));
285
286     connect(this, SIGNAL(minZoomLevelReached()),
287             m_zoomButtonPanel, SLOT(disableZoomOutButton()));
288
289     connect(m_mapView, SIGNAL(viewResized(QSize)),
290             m_zoomButtonPanel, SLOT(screenResized(QSize)));
291 }
292
293 void MainWindow::clearCookieJar()
294 {
295     qDebug() << __PRETTY_FUNCTION__;
296
297     buildWebView();
298
299     if(!m_cookieJar) {
300         m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
301     }
302     QList<QNetworkCookie> emptyList;
303     emptyList.clear();
304
305     m_cookieJar->setAllCookies(emptyList);
306     m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
307 }
308
309 void MainWindow::createMenus()
310 {
311     qDebug() << __PRETTY_FUNCTION__;
312
313     // login/logout
314     m_loginAct = new QAction(tr("Login"), this);
315     connect(m_loginAct, SIGNAL(triggered()),
316             this, SIGNAL(loginActionPressed()));
317
318     // settings
319     m_toSettingsAct = new QAction(tr("Settings"), this);
320     connect(m_toSettingsAct, SIGNAL(triggered()),
321         this, SLOT(openSettingsDialog()));
322
323     // GPS
324     m_gpsToggleAct = new QAction(tr("GPS"), this);
325     m_gpsToggleAct->setCheckable(true);
326
327     connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
328             this, SIGNAL(gpsTriggered(bool)));
329
330     // automatic centering
331     m_autoCenteringAct = new QAction(tr("Auto centering"), this);
332     m_autoCenteringAct->setCheckable(true);
333     connect(m_autoCenteringAct, SIGNAL(triggered(bool)),
334         this, SIGNAL(autoCenteringTriggered(bool)));
335
336     // build the actual menu
337     m_viewMenu = menuBar()->addMenu(tr("Main"));
338     m_viewMenu->addAction(m_loginAct);
339     m_viewMenu->addAction(m_toSettingsAct);
340     m_viewMenu->addAction(m_gpsToggleAct);
341     m_viewMenu->addAction(m_autoCenteringAct);
342     m_viewMenu->setObjectName(tr("Menu"));
343 }
344
345 void MainWindow::drawFullScreenButton(const QSize &size)
346 {
347     qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
348
349     if(m_fullScreenButton) {
350         m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width()
351                                  - PANEL_PEEK_AMOUNT,
352                                  size.height() - m_fullScreenButton->size().height());
353     }
354 }
355
356 void MainWindow::drawOsmLicense(const QSize &size)
357 {
358     qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
359
360     m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
361                        - PANEL_PEEK_AMOUNT,
362                        size.height() - m_osmLicense->fontMetrics().height());
363 }
364
365 void MainWindow::drawOwnLocationCrosshair(int width, int height)
366 {
367     qDebug() << __PRETTY_FUNCTION__;
368
369     if (m_drawOwnLocationCrosshair && m_ownLocationCrosshair != 0) {
370         m_ownLocationCrosshair->move(width/2 - m_ownLocationCrosshair->pixmap()->width()/2,
371                             height/2 - m_ownLocationCrosshair->pixmap()->height()/2);
372     }
373 }
374
375 void MainWindow::gpsTimeout()
376 {
377     qDebug() << __PRETTY_FUNCTION__;
378
379     queueInformationBox(tr("GPS timeout"));
380 }
381
382 void MainWindow::grabZoomKeys(bool grab)
383 {
384     qDebug() << __PRETTY_FUNCTION__;
385
386 #ifdef Q_WS_MAEMO_5
387     // Can't grab keys unless we have a window id
388     if (!winId())
389         return;
390
391     unsigned long val = (grab) ? 1 : 0;
392     Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
393     if (!atom)
394         return;
395
396     XChangeProperty (QX11Info::display(),
397                      winId(),
398                      atom,
399                      XA_INTEGER,
400                      32,
401                      PropModeReplace,
402                      reinterpret_cast<unsigned char *>(&val),
403                      1);
404 #else
405     Q_UNUSED(grab);
406 #endif // Q_WS_MAEMO_5
407 }
408
409 void MainWindow::keyPressEvent(QKeyEvent* event)
410 {
411     qDebug() << __PRETTY_FUNCTION__;
412
413     switch (event->key()) {
414     case Qt::Key_F7:
415         event->accept();
416         emit zoomIn();
417         break;
418
419     case Qt::Key_F8:
420         event->accept();
421         emit zoomOut();
422         break;
423     }
424     QWidget::keyPressEvent(event);
425 }
426
427 void MainWindow::loadCookies()
428 {
429     qDebug() << __PRETTY_FUNCTION__;
430
431     QSettings settings(DIRECTORY_NAME, FILE_NAME);
432
433     QStringList list = settings.value(COOKIES, EMPTY).toStringList();
434
435     if(!list.isEmpty()) {
436         QList<QNetworkCookie> cookieList;
437         for(int i=0;i<list.count();i++) {
438             cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
439         }
440
441         if(!m_cookieJar)
442                m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
443
444         m_cookieJar->setAllCookies(cookieList);
445         m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
446
447     }
448 }
449
450 void MainWindow::loadDone(bool done)
451 {
452     qDebug() << __PRETTY_FUNCTION__;
453
454     // for the first time the login page is opened, we need to refresh it to get cookies working
455     if(m_refresh) {
456         m_webView->reload();
457         m_refresh = false;
458     }
459
460     if (done)
461     {
462         QWebFrame* frame = m_webView->page()->currentFrame();
463         if (frame!=NULL)
464         {
465             // set email box
466             QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
467
468             foreach (QWebElement element, emailCollection) {
469                 element.setAttribute("value", m_email.toAscii());
470             }
471             // set password box
472             QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
473             foreach (QWebElement element, passwordCollection) {
474                 element.setAttribute("value", m_password.toAscii());
475             }
476             // find connect button
477             QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
478             foreach (QWebElement element, buttonCollection)
479             {
480                 QPoint pos(element.geometry().center());
481
482                 // send a mouse click event to the web page
483                 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
484                                    Qt::NoModifier);
485                 QApplication::sendEvent(m_webView->page(), &event0);
486                 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
487                                    Qt::NoModifier);
488                 QApplication::sendEvent(m_webView->page(), &event1);
489             }
490         }
491     }
492 }
493
494 void MainWindow::loggedIn(bool logged)
495 {
496     qDebug() << __PRETTY_FUNCTION__;
497
498     m_loggedIn = logged;
499
500     if(logged) {
501         m_loginAct->setText(tr("Logout"));
502     } else {
503         clearCookieJar();
504         m_email.clear();
505         m_password.clear();
506
507         m_loginAct->setText(tr("Login"));
508     }
509     updateItemVisibility(m_loggedIn);
510 }
511
512 void MainWindow::loginFailed()
513 {
514     qDebug() << __PRETTY_FUNCTION__;
515
516     clearCookieJar();
517
518     toggleProgressIndicator(false);
519
520     QStringList urlParts;
521     urlParts.append(FACEBOOK_LOGINBASE);
522     urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
523     urlParts.append(INTERVAL1);
524     urlParts.append(SITUARE_LOGIN_SUCCESS);
525     urlParts.append(INTERVAL2);
526     urlParts.append(SITUARE_LOGIN_FAILURE);
527     urlParts.append(FACEBOOK_LOGIN_ENDING);
528
529     startLoginProcess(urlParts.join(EMPTY));
530 }
531
532 void MainWindow::noteFinished()
533 {
534     qDebug() << __PRETTY_FUNCTION__;
535
536     NoteData *data = m_queue.takeFirst();
537     delete data;
538
539     if(!m_queue.isEmpty())
540         showInformationBox();
541 }
542
543 void MainWindow::loginUsingCookies()
544 {
545     qDebug() << __PRETTY_FUNCTION__;
546
547     buildWebView();
548     loadCookies();
549     
550     QStringList urlParts;
551     urlParts.append(FACEBOOK_LOGINBASE);
552     urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
553     urlParts.append(INTERVAL1);
554     urlParts.append(SITUARE_LOGIN_SUCCESS);
555     urlParts.append(INTERVAL2);
556     urlParts.append(SITUARE_LOGIN_FAILURE);
557     urlParts.append(FACEBOOK_LOGIN_ENDING);
558
559     m_webView->load(QUrl(urlParts.join(EMPTY)));
560
561 }
562
563 void MainWindow::openSettingsDialog()
564 {
565     qDebug() << __PRETTY_FUNCTION__;
566
567     m_settingsDialog->enableSituareSettings(m_gpsToggleAct->isChecked() && m_loggedIn);
568     m_settingsDialog->show();
569 }
570
571 void MainWindow::queueInformationBox(const QString &message, bool modal)
572 {
573     qDebug() << __PRETTY_FUNCTION__;
574
575     NoteData *data = new NoteData(message, modal);
576
577     m_queue.append(data);
578
579     if(m_queue.count() == 1)
580         showInformationBox();
581 }
582
583 void MainWindow::saveCookies()
584 {
585     qDebug() << __PRETTY_FUNCTION__;
586
587     if(!m_cookieJar)
588         m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
589
590     QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
591     QStringList list;
592
593     for(int i=0;i<cookieList.count();i++) {
594         QNetworkCookie cookie = cookieList.at(i);
595         QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
596         list.append(QString(byteArray));
597     }
598     list.removeDuplicates();
599
600     QSettings settings(DIRECTORY_NAME, FILE_NAME);
601     settings.setValue(COOKIES, list);
602 }
603
604 void MainWindow::setAutoCenteringButtonEnabled(bool enabled)
605 {
606     qDebug() << __PRETTY_FUNCTION__;
607
608     m_autoCenteringAct->setChecked(enabled);
609 }
610
611 void MainWindow::setGPSButtonEnabled(bool enabled)
612 {
613     qDebug() << __PRETTY_FUNCTION__;
614
615     m_gpsToggleAct->setChecked(enabled);
616
617     if(m_loggedIn)
618         setOwnLocationCrosshairVisibility(!enabled);
619
620     m_autoCenteringAct->setVisible(enabled);
621 }
622
623 void MainWindow::setMapViewScene(QGraphicsScene *scene)
624 {
625     qDebug() << __PRETTY_FUNCTION__;
626
627     m_mapView->setScene(scene);
628 }
629
630 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
631 {
632     qDebug() << __PRETTY_FUNCTION__;
633
634     if (visibility) {
635         m_ownLocationCrosshair->show();
636         m_drawOwnLocationCrosshair = true;
637         drawOwnLocationCrosshair(m_viewPortWidth, m_viewPortHeight);
638     } else {
639         m_ownLocationCrosshair->hide();
640         m_drawOwnLocationCrosshair = false;
641     }
642 }
643
644 void MainWindow::setUsername(const QString &username)
645 {
646     qDebug() << __PRETTY_FUNCTION__;
647
648     m_email = username;
649 }
650
651 void MainWindow::setViewPortSize(int width, int height)
652 {
653     qDebug() << __PRETTY_FUNCTION__;
654
655     m_viewPortWidth = width;
656     m_viewPortHeight = height;
657 }
658
659 void MainWindow::toggleFullScreen()
660 {
661     qDebug() << __PRETTY_FUNCTION__;
662
663     if(windowState() == Qt::WindowNoState)
664         showFullScreen();
665     else
666         showNormal();
667 }
668
669 void MainWindow::showInformationBox()
670 {
671     qDebug() << __PRETTY_FUNCTION__;
672
673     NoteData *data = m_queue.takeFirst();
674
675 #ifdef Q_WS_MAEMO_5
676     QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
677     QLabel *label = new QLabel(msgBox);
678     label->setAlignment(Qt::AlignCenter);
679     label->setText(data->message());
680
681     if(data->modal()) {
682         msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
683     } else {
684         msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
685     }
686 #else
687     QMessageBox *msgBox = new QMessageBox(this);
688     msgBox->button(QMessageBox::Ok);
689     msgBox->setText(data->message());
690     msgBox->setModal(data->modal());
691 #endif
692
693     connect(msgBox, SIGNAL(finished(int)),
694             this, SLOT(noteFinished()));
695
696     msgBox->show();
697
698     m_queue.insert(0, data);
699
700 }
701
702 void MainWindow::startLoginProcess(const QUrl &url)
703 {
704     qDebug() << __PRETTY_FUNCTION__;
705
706     buildWebView();
707
708     LoginDialog loginDialog;
709
710     emit fetchUsernameFromSettings();
711
712     if(!m_cookieJar)
713         m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
714
715     m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
716
717     loginDialog.clearTextFields();
718
719     if(!m_email.isEmpty())
720         loginDialog.setEmailField(m_email);
721
722     if(loginDialog.exec() != QDialog::Accepted) {
723         // if login dialog was canceled we need to stop processing webview
724         m_webView->stop();
725
726         emit cancelLoginProcess();
727     } else {
728         loginDialog.userInput(m_email, m_password);
729         emit saveUsername(m_email);
730         m_webView->load(url);
731         toggleProgressIndicator(true);
732         m_refresh = true;
733     }
734 }
735
736 void MainWindow::toggleProgressIndicator(bool value)
737 {
738     qDebug() << __PRETTY_FUNCTION__;
739
740 #ifdef Q_WS_MAEMO_5
741     setAttribute(Qt::WA_Maemo5ShowProgressIndicator, value);
742 #else
743     Q_UNUSED(value);
744 #endif // Q_WS_MAEMO_5
745 }
746
747 void MainWindow::updateItemVisibility(bool show)
748 {
749     qDebug() << __PRETTY_FUNCTION__;
750     
751     if(show) {
752         m_friendsListPanel->show();
753         m_friendsListPanelSidebar->show();
754         m_userPanel->show();
755         m_userPanelSidebar->show();
756
757         if(m_drawOwnLocationCrosshair) {
758             m_ownLocationCrosshair->show();
759             setGPSButtonEnabled(false);
760             emit gpsTriggered(false);
761         }
762     } else {
763         m_friendsListPanel->closePanel();
764         m_friendsListPanel->hide();
765         m_friendsListPanelSidebar->hide();
766         m_userPanel->closePanel();
767         m_userPanel->hide();
768         m_userPanelSidebar->hide();
769         m_ownLocationCrosshair->hide();       
770     }
771 }
772
773 const QString MainWindow::username()
774 {
775     qDebug() << __PRETTY_FUNCTION__;
776     
777     return m_email;
778 }