2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
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 Katri Kaikkonen - katri.kaikkonen@ixonos.com
12 Situare is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 version 2 as published by the Free Software Foundation.
16 Situare is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with Situare; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
29 #include <QtAlgorithms>
31 #include "facebookservice/facebookauthentication.h"
32 #include "map/mapcommon.h"
33 #include "map/mapview.h"
36 #include "friendlistpanel.h"
37 #include "fullscreenbutton.h"
38 #include "logindialog.h"
40 #include "searchdialog.h"
41 #include "settingsdialog.h"
42 #include "userinfopanel.h"
43 #include "zoombuttonpanel.h"
44 #include "indicatorbuttonpanel.h"
46 #include "mainwindow.h"
48 // These MUST BE HERE, compiling for Maemo fails if moved
50 #include <QtMaemo5/QMaemo5InformationBox>
51 #include <QtGui/QX11Info>
52 #include <X11/Xatom.h>
54 #endif // Q_WS_MAEMO_5
56 MainWindow::MainWindow(QWidget *parent)
57 : QMainWindow(parent),
61 m_progressIndicatorCount(0),
62 m_ownLocationCrosshair(0),
66 m_fullScreenButton(0),
67 m_indicatorButtonPanel(0),
71 qDebug() << __PRETTY_FUNCTION__;
76 QHBoxLayout *layout = new QHBoxLayout;
77 layout->addWidget(m_mapView);
79 layout->setSpacing(0);
81 setCentralWidget(new QWidget());
82 centralWidget()->setLayout(layout);
84 buildFriendListPanel();
88 setWindowTitle(tr("Situare"));
90 // set stacking order of widgets
91 m_zoomButtonPanel->stackUnder(m_userPanel);
92 if(m_fullScreenButton) {
93 m_fullScreenButton->stackUnder(m_zoomButtonPanel);
94 m_osmLicense->stackUnder(m_fullScreenButton);
96 m_osmLicense->stackUnder(m_zoomButtonPanel);
98 m_ownLocationCrosshair->stackUnder(m_osmLicense);
99 m_indicatorButtonPanel->stackUnder(m_ownLocationCrosshair);
100 m_mapScale->stackUnder(m_indicatorButtonPanel);
101 m_mapView->stackUnder(m_mapScale);
105 // Set default screen size
106 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
108 setAttribute(Qt::WA_Maemo5StackedWindow);
112 MainWindow::~MainWindow()
114 qDebug() << __PRETTY_FUNCTION__;
121 qDeleteAll(m_queue.begin(), m_queue.end());
124 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
125 m_error_queue.clear();
128 void MainWindow::automaticUpdateDialogFinished(int result)
130 qDebug() << __PRETTY_FUNCTION__;
132 if (result == QMessageBox::Yes) {
133 readAutomaticLocationUpdateSettings();
135 QSettings settings(DIRECTORY_NAME, FILE_NAME);
136 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
137 readAutomaticLocationUpdateSettings();
140 m_automaticUpdateLocationDialog->deleteLater();
143 void MainWindow::buildFullScreenButton()
145 qDebug() << __PRETTY_FUNCTION__;
148 m_fullScreenButton = new FullScreenButton(this);
150 if (m_fullScreenButton) {
151 connect(m_fullScreenButton, SIGNAL(clicked()),
152 this, SLOT(toggleFullScreen()));
154 connect(qApp, SIGNAL(showFullScreenButton()),
155 m_fullScreenButton, SLOT(invoke()));
157 #endif // Q_WS_MAEMO_5
160 void MainWindow::buildFriendListPanel()
162 qDebug() << __PRETTY_FUNCTION__;
164 m_friendsListPanel = new FriendListPanel(this);
166 m_friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
168 m_friendsListPanel->stackUnder(m_friendsListPanelSidebar);
170 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
171 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
173 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
174 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
176 connect(m_mapView, SIGNAL(viewResized(QSize)),
177 m_friendsListPanel, SLOT(resizePanel(QSize)));
179 connect(m_mapView, SIGNAL(viewResized(QSize)),
180 m_friendsListPanelSidebar, SLOT(resizeSideBar(QSize)));
182 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
183 this, SIGNAL(findFriend(GeoCoordinate)));
185 connect(this, SIGNAL(friendImageReady(User*)),
186 m_friendsListPanel, SLOT(friendImageReady(User*)));
189 void MainWindow::buildIndicatorButtonPanel()
191 qDebug() << __PRETTY_FUNCTION__;
193 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
195 connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
196 this, SIGNAL(autoCenteringTriggered(bool)));
198 connect(m_mapView, SIGNAL(viewResized(QSize)),
199 m_indicatorButtonPanel, SLOT(screenResized(QSize)));
201 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
202 m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
204 connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
205 this, SIGNAL(draggingModeTriggered()));
208 void MainWindow::buildInformationBox(const QString &message, bool modal)
210 qDebug() << __PRETTY_FUNCTION__;
212 QString errorMessage = message;
216 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
219 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
220 // extra line changes are needed to make error notes broader
221 errorMessage.prepend("\n");
222 errorMessage.append("\n");
224 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
226 QLabel *label = new QLabel(msgBox);
227 label->setAlignment(Qt::AlignCenter);
228 label->setText(errorMessage);
229 msgBox->setWidget(label);
231 QMessageBox *msgBox = new QMessageBox(this);
232 msgBox->button(QMessageBox::Ok);
233 msgBox->setText(errorMessage);
234 msgBox->setModal(modal);
240 void MainWindow::buildManualLocationCrosshair()
242 qDebug() << __PRETTY_FUNCTION__;
244 m_ownLocationCrosshair = new QLabel(this);
245 QPixmap crosshairImage(":/res/images/sight.png");
246 m_ownLocationCrosshair->setPixmap(crosshairImage);
247 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
248 m_ownLocationCrosshair->hide();
249 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
251 connect(m_mapView, SIGNAL(viewResized(QSize)),
252 this, SLOT(drawOwnLocationCrosshair(QSize)));
255 void MainWindow::buildMap()
257 qDebug() << __PRETTY_FUNCTION__;
259 m_mapView = new MapView(this);
261 buildZoomButtonPanel();
263 buildManualLocationCrosshair();
264 buildFullScreenButton();
265 buildIndicatorButtonPanel();
268 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
269 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
271 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
272 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
274 connect(m_mapView, SIGNAL(viewResized(QSize)),
275 this, SIGNAL(mapViewResized(QSize)));
277 connect(m_mapView, SIGNAL(viewResized(QSize)),
278 this, SLOT(drawFullScreenButton(QSize)));
280 connect(m_mapView, SIGNAL(viewResized(QSize)),
281 this, SLOT(drawMapScale(QSize)));
283 connect(m_mapView, SIGNAL(viewResized(QSize)),
284 this, SLOT(setViewPortSize(QSize)));
286 connect(this, SIGNAL(zoomLevelChanged(int)),
287 m_mapView, SLOT(setZoomLevel(int)));
289 connect(m_mapView, SIGNAL(viewZoomFinished()),
290 this, SIGNAL(viewZoomFinished()));
292 connect(m_mapView, SIGNAL(zoomIn()),
293 this, SIGNAL(zoomIn()));
296 void MainWindow::buildMapScale()
298 m_mapScale = new MapScale(this);
299 connect(this, SIGNAL(newMapResolution(qreal)),
300 m_mapScale, SLOT(updateMapResolution(qreal)));
303 void MainWindow::buildOsmLicense()
305 qDebug() << __PRETTY_FUNCTION__;
307 m_osmLicense = new QLabel(this);
308 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
309 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
310 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
311 m_osmLicense->setFont(QFont("Nokia Sans", 9));
312 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
313 m_osmLicense->fontMetrics().height());
315 connect(m_mapView, SIGNAL(viewResized(QSize)),
316 this, SLOT(drawOsmLicense(QSize)));
319 void MainWindow::buildUserInfoPanel()
321 qDebug() << __PRETTY_FUNCTION__;
323 m_userPanel = new UserInfoPanel(this);
325 m_userPanelSidebar = new PanelSideBar(this, LEFT);
327 m_userPanelSidebar->stackUnder(m_friendsListPanel);
328 m_userPanel->stackUnder(m_userPanelSidebar);
330 connect(this, SIGNAL(userLocationReady(User*)),
331 m_userPanel, SLOT(userDataReceived(User*)));
333 connect(this, SIGNAL(reverseGeoReady(QString)),
334 m_userPanel, SIGNAL(reverseGeoReady(QString)));
336 connect(this, SIGNAL(clearUpdateLocationDialogData()),
337 m_userPanel, SIGNAL(clearUpdateLocationDialogData()));
339 connect(m_mapView, SIGNAL(viewResized(QSize)),
340 m_userPanel, SLOT(resizePanel(QSize)));
342 connect(m_mapView, SIGNAL(viewResized(QSize)),
343 m_userPanelSidebar, SLOT(resizeSideBar(QSize)));
345 connect(m_userPanel, SIGNAL(findUser(GeoCoordinate)),
346 this, SIGNAL(findUser(GeoCoordinate)));
348 connect(m_userPanel, SIGNAL(requestReverseGeo()),
349 this, SIGNAL(requestReverseGeo()));
351 connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
352 this, SIGNAL(statusUpdate(QString,bool)));
354 connect(m_userPanel, SIGNAL(refreshUserData()),
355 this, SIGNAL(refreshUserData()));
357 connect(m_userPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
358 this, SLOT(buildInformationBox(QString, bool)));
361 void MainWindow::buildWebView()
363 qDebug() << __PRETTY_FUNCTION__;
366 m_webView = new QWebView;
369 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
371 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
373 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
374 this, SLOT(webViewRequestFinished(QNetworkReply*)));
375 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
376 this, SIGNAL(updateCredentials(QUrl)));
377 connect(m_webView, SIGNAL(loadFinished(bool)),
378 this, SLOT(loadDone(bool)));
384 void MainWindow::buildZoomButtonPanel()
386 qDebug() << __PRETTY_FUNCTION__;
388 m_zoomButtonPanel = new ZoomButtonPanel(this);
390 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
391 this, SIGNAL(zoomIn()));
393 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
394 this, SIGNAL(zoomOut()));
396 connect(this, SIGNAL(zoomLevelChanged(int)),
397 m_zoomButtonPanel, SLOT(resetButtons()));
399 connect(this, SIGNAL(maxZoomLevelReached()),
400 m_zoomButtonPanel, SLOT(disableZoomInButton()));
402 connect(this, SIGNAL(minZoomLevelReached()),
403 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
405 connect(m_mapView, SIGNAL(viewResized(QSize)),
406 m_zoomButtonPanel, SLOT(screenResized(QSize)));
408 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
409 this, SIGNAL(draggingModeTriggered()));
412 void MainWindow::clearCookieJar()
414 qDebug() << __PRETTY_FUNCTION__;
421 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
423 QList<QNetworkCookie> emptyList;
426 m_cookieJar->setAllCookies(emptyList);
427 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
430 void MainWindow::createMenus()
432 qDebug() << __PRETTY_FUNCTION__;
435 m_loginAct = new QAction(tr("Login"), this);
436 connect(m_loginAct, SIGNAL(triggered()),
437 this, SIGNAL(loginActionPressed()));
440 m_toSettingsAct = new QAction(tr("Settings"), this);
441 connect(m_toSettingsAct, SIGNAL(triggered()),
442 this, SLOT(openSettingsDialog()));
445 m_gpsToggleAct = new QAction(tr("GPS"), this);
446 m_gpsToggleAct->setCheckable(true);
448 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
449 this, SIGNAL(gpsTriggered(bool)));
451 /// @todo remove when not needed!
452 m_searchLocationAct = new QAction(tr("Location search"), this);
453 connect(m_searchLocationAct, SIGNAL(triggered()),
454 this, SLOT(startLocationSearch()));
456 // build the actual menu
457 m_viewMenu = menuBar()->addMenu(tr("Main"));
458 m_viewMenu->addAction(m_loginAct);
459 m_viewMenu->addAction(m_toSettingsAct);
460 m_viewMenu->addAction(m_gpsToggleAct);
461 m_viewMenu->addAction(m_searchLocationAct); /// @todo remove when not needed!
462 m_viewMenu->setObjectName(tr("Menu"));
465 void MainWindow::dialogFinished(int status)
467 qDebug() << __PRETTY_FUNCTION__;
469 QDialog *dialog = m_queue.takeFirst();
470 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
471 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
475 loginDialog->userInput(m_email, m_password);
477 QStringList urlParts;
478 urlParts.append(FACEBOOK_LOGINBASE);
479 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
480 urlParts.append(INTERVAL1);
481 urlParts.append(SITUARE_LOGIN_SUCCESS);
482 urlParts.append(INTERVAL2);
483 urlParts.append(SITUARE_LOGIN_FAILURE);
484 urlParts.append(FACEBOOK_LOGIN_ENDING);
486 emit saveUsername(m_email);
488 m_webView->load(QUrl(urlParts.join(EMPTY)));
489 toggleProgressIndicator(true);
491 emit cancelLoginProcess();
493 } else if(searchDialog) {
495 emit searchForLocation(searchDialog->input());
499 dialog->deleteLater();
501 if(!m_error_queue.isEmpty() && m_errorShown == false) {
502 showErrorInformationBox();
504 if(!m_queue.isEmpty()) {
505 showInformationBox();
510 void MainWindow::drawFullScreenButton(const QSize &size)
512 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
514 if(m_fullScreenButton) {
516 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width()
518 size.height() - m_fullScreenButton->size().height());
520 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
521 size.height() - m_fullScreenButton->size().height());
526 void MainWindow::drawMapScale(const QSize &size)
528 qDebug() << __PRETTY_FUNCTION__;
530 const int LEFT_SCALE_MARGIN = 10;
531 const int BOTTOM_SCALE_MARGIN = 2;
532 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
534 m_mapScale->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
535 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
538 void MainWindow::drawOsmLicense(const QSize &size)
540 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
542 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
544 size.height() - m_osmLicense->fontMetrics().height());
547 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
549 qDebug() << __PRETTY_FUNCTION__;
551 if (m_ownLocationCrosshair != 0) {
552 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
553 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
557 void MainWindow::errorDialogFinished(int status)
559 qDebug() << __PRETTY_FUNCTION__;
562 QDialog *dialog = m_error_queue.takeFirst();
564 dialog->deleteLater();
565 m_errorShown = false;
567 if(!m_error_queue.isEmpty())
568 showErrorInformationBox();
569 else if(!m_queue.isEmpty())
570 showInformationBox();
573 void MainWindow::gpsTimeout()
575 qDebug() << __PRETTY_FUNCTION__;
577 buildInformationBox(tr("GPS timeout"));
580 void MainWindow::grabZoomKeys(bool grab)
582 qDebug() << __PRETTY_FUNCTION__;
585 // Can't grab keys unless we have a window id
589 unsigned long val = (grab) ? 1 : 0;
590 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
594 XChangeProperty (QX11Info::display(),
600 reinterpret_cast<unsigned char *>(&val),
604 #endif // Q_WS_MAEMO_5
607 void MainWindow::keyPressEvent(QKeyEvent* event)
609 qDebug() << __PRETTY_FUNCTION__;
611 switch (event->key()) {
622 QWidget::keyPressEvent(event);
625 void MainWindow::loadCookies()
627 qDebug() << __PRETTY_FUNCTION__;
629 QSettings settings(DIRECTORY_NAME, FILE_NAME);
631 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
633 if(!list.isEmpty()) {
634 QList<QNetworkCookie> cookieList;
635 for(int i=0;i<list.count();i++) {
636 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
640 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
642 m_cookieJar->setAllCookies(cookieList);
643 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
647 void MainWindow::loadDone(bool done)
649 qDebug() << __PRETTY_FUNCTION__;
651 // for the first time the login page is opened, we need to refresh it to get cookies working
659 QWebFrame* frame = m_webView->page()->currentFrame();
663 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
665 foreach (QWebElement element, emailCollection) {
666 element.setAttribute("value", m_email.toAscii());
669 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
670 foreach (QWebElement element, passwordCollection) {
671 element.setAttribute("value", m_password.toAscii());
673 // find connect button
674 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
675 foreach (QWebElement element, buttonCollection)
677 QPoint pos(element.geometry().center());
679 // send a mouse click event to the web page
680 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
682 QApplication::sendEvent(m_webView->page(), &event0);
683 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
685 QApplication::sendEvent(m_webView->page(), &event1);
691 void MainWindow::loggedIn(bool logged)
693 qDebug() << __PRETTY_FUNCTION__;
698 m_loginAct->setText(tr("Logout"));
704 m_loginAct->setText(tr("Login"));
706 updateItemVisibility();
709 void MainWindow::loginFailed()
711 qDebug() << __PRETTY_FUNCTION__;
717 bool MainWindow::loginState()
719 qDebug() << __PRETTY_FUNCTION__;
724 void MainWindow::loginUsingCookies()
726 qDebug() << __PRETTY_FUNCTION__;
728 toggleProgressIndicator(true);
733 QStringList urlParts;
734 urlParts.append(FACEBOOK_LOGINBASE);
735 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
736 urlParts.append(INTERVAL1);
737 urlParts.append(SITUARE_LOGIN_SUCCESS);
738 urlParts.append(INTERVAL2);
739 urlParts.append(SITUARE_LOGIN_FAILURE);
740 urlParts.append(FACEBOOK_LOGIN_ENDING);
742 m_webView->load(QUrl(urlParts.join(EMPTY)));
746 void MainWindow::openSettingsDialog()
748 qDebug() << __PRETTY_FUNCTION__;
750 SettingsDialog *settingsDialog = new SettingsDialog(this);
751 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
752 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
754 settingsDialog->show();
757 void MainWindow::readAutomaticLocationUpdateSettings()
759 qDebug() << __PRETTY_FUNCTION__;
761 QSettings settings(DIRECTORY_NAME, FILE_NAME);
762 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
763 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
766 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
768 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
770 emit enableAutomaticLocationUpdate(false);
774 void MainWindow::queueDialog(QDialog *dialog)
776 qDebug() << __PRETTY_FUNCTION__;
778 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
779 if(dialog->isModal()) {
780 m_error_queue.append(dialog);
782 m_queue.append(dialog);
785 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
786 if(m_error_queue.count() == 1 && m_errorShown == false)
787 showErrorInformationBox();
788 else if(m_queue.count() == 1 && m_errorShown == false)
789 showInformationBox();
792 void MainWindow::saveCookies()
794 qDebug() << __PRETTY_FUNCTION__;
797 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
799 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
802 for(int i=0;i<cookieList.count();i++) {
803 QNetworkCookie cookie = cookieList.at(i);
804 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
805 list.append(QString(byteArray));
807 list.removeDuplicates();
809 QSettings settings(DIRECTORY_NAME, FILE_NAME);
810 settings.setValue(COOKIES, list);
813 void MainWindow::setGPSButtonEnabled(bool enabled)
815 qDebug() << __PRETTY_FUNCTION__;
817 m_gpsToggleAct->setChecked(enabled);
820 void MainWindow::setIndicatorButtonEnabled(bool enabled)
822 qDebug() << __PRETTY_FUNCTION__;
824 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
827 void MainWindow::setMapViewScene(QGraphicsScene *scene)
829 qDebug() << __PRETTY_FUNCTION__;
831 m_mapView->setScene(scene);
834 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
836 qDebug() << __PRETTY_FUNCTION__;
839 m_ownLocationCrosshair->show();
840 drawOwnLocationCrosshair(m_viewPortSize);
842 m_ownLocationCrosshair->hide();
846 void MainWindow::settingsDialogAccepted()
848 qDebug() << __PRETTY_FUNCTION__;
850 readAutomaticLocationUpdateSettings();
853 void MainWindow::setUsername(const QString &username)
855 qDebug() << __PRETTY_FUNCTION__;
860 void MainWindow::setViewPortSize(const QSize &size)
862 qDebug() << __PRETTY_FUNCTION__;
864 m_viewPortSize = size;
867 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
869 qDebug() << __PRETTY_FUNCTION__;
871 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
872 tr("Automatic location update"), text,
873 QMessageBox::Yes | QMessageBox::No |
874 QMessageBox::Cancel, this);
875 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
876 this, SLOT(automaticUpdateDialogFinished(int)));
878 m_automaticUpdateLocationDialog->show();
881 void MainWindow::toggleFullScreen()
883 qDebug() << __PRETTY_FUNCTION__;
885 if(windowState() == Qt::WindowNoState)
891 void MainWindow::showErrorInformationBox()
893 qDebug() << __PRETTY_FUNCTION__;
895 if(m_error_queue.count()) {
897 QDialog *dialog = m_error_queue.first();
898 connect(dialog, SIGNAL(finished(int)),
899 this, SLOT(errorDialogFinished(int)));
904 void MainWindow::showInformationBox()
906 qDebug() << __PRETTY_FUNCTION__;
908 if(m_queue.count()) {
909 QDialog *dialog = m_queue.first();
910 connect(dialog, SIGNAL(finished(int)),
911 this, SLOT(dialogFinished(int)));
916 void MainWindow::showPanels()
918 qDebug() << __PRETTY_FUNCTION__;
920 drawFullScreenButton(m_viewPortSize);
923 if(!m_friendsListPanel->isVisible()) {
924 m_friendsListPanel->show();
925 m_friendsListPanelSidebar->show();
928 if(!m_userPanel->isVisible()) {
930 m_userPanelSidebar->show();
935 void MainWindow::startLocationSearch()
937 qDebug() << __PRETTY_FUNCTION__;
939 SearchDialog *searchDialog = new SearchDialog();
940 queueDialog(searchDialog);
943 void MainWindow::startLoginProcess()
945 qDebug() << __PRETTY_FUNCTION__;
947 LoginDialog *loginDialog = new LoginDialog();
949 emit fetchUsernameFromSettings();
951 loginDialog->clearTextFields();
953 if(!m_email.isEmpty())
954 loginDialog->setEmailField(m_email);
956 queueDialog(loginDialog);
959 void MainWindow::toggleProgressIndicator(bool value)
961 qDebug() << __PRETTY_FUNCTION__;
965 m_progressIndicatorCount++;
966 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
968 if(m_progressIndicatorCount > 0)
969 m_progressIndicatorCount--;
971 if(m_progressIndicatorCount == 0)
972 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
976 #endif // Q_WS_MAEMO_5
979 void MainWindow::updateItemVisibility()
981 qDebug() << __PRETTY_FUNCTION__;
984 m_friendsListPanel->closePanel();
985 m_friendsListPanel->hide();
986 m_friendsListPanelSidebar->hide();
987 m_userPanel->closePanel();
989 m_userPanelSidebar->hide();
993 const QString MainWindow::username()
995 qDebug() << __PRETTY_FUNCTION__;
1000 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1002 qDebug() << __PRETTY_FUNCTION__;
1004 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1005 // qwebview starts to load a new page while the current page loading is not finished
1006 if(reply->error() != QNetworkReply::OperationCanceledError &&
1007 reply->error() != QNetworkReply::NoError) {
1008 emit error(ErrorContext::NETWORK, reply->error());