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