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,
28 #include <QApplication>
30 #include <QMessageBox>
31 #include <QtAlgorithms>
34 #include "facebookservice/facebookauthentication.h"
35 #include "map/mapcommon.h"
36 #include "map/mapview.h"
39 #include "friendlistpanel.h"
40 #include "fullscreenbutton.h"
41 #include "logindialog.h"
43 #include "searchdialog.h"
44 #include "settingsdialog.h"
45 #include "userinfopanel.h"
46 #include "zoombuttonpanel.h"
47 #include "indicatorbuttonpanel.h"
49 #include "mainwindow.h"
51 // These MUST BE HERE, compiling for Maemo fails if moved
53 #include <QtMaemo5/QMaemo5InformationBox>
54 #include <QtGui/QX11Info>
55 #include <X11/Xatom.h>
57 #endif // Q_WS_MAEMO_5
59 MainWindow::MainWindow(QWidget *parent)
60 : QMainWindow(parent),
64 m_progressIndicatorCount(0),
65 m_ownLocationCrosshair(0),
69 m_fullScreenButton(0),
70 m_indicatorButtonPanel(0),
74 qDebug() << __PRETTY_FUNCTION__;
79 QHBoxLayout *layout = new QHBoxLayout;
80 layout->addWidget(m_mapView);
82 layout->setSpacing(0);
84 setCentralWidget(new QWidget());
85 centralWidget()->setLayout(layout);
87 buildFriendListPanel();
91 setWindowTitle(tr("Situare"));
93 // set stacking order of widgets
94 m_zoomButtonPanel->stackUnder(m_userPanel);
95 if(m_fullScreenButton) {
96 m_fullScreenButton->stackUnder(m_zoomButtonPanel);
97 m_osmLicense->stackUnder(m_fullScreenButton);
99 m_osmLicense->stackUnder(m_zoomButtonPanel);
101 m_ownLocationCrosshair->stackUnder(m_osmLicense);
102 m_indicatorButtonPanel->stackUnder(m_ownLocationCrosshair);
103 m_mapScale->stackUnder(m_indicatorButtonPanel);
104 m_mapView->stackUnder(m_mapScale);
108 // Set default screen size
109 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
111 setAttribute(Qt::WA_Maemo5StackedWindow);
115 MainWindow::~MainWindow()
117 qDebug() << __PRETTY_FUNCTION__;
124 qDeleteAll(m_queue.begin(), m_queue.end());
127 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
128 m_error_queue.clear();
131 void MainWindow::automaticUpdateDialogFinished(int result)
133 qDebug() << __PRETTY_FUNCTION__;
135 if (result == QMessageBox::Yes) {
136 readAutomaticLocationUpdateSettings();
138 QSettings settings(DIRECTORY_NAME, FILE_NAME);
139 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
140 readAutomaticLocationUpdateSettings();
143 m_automaticUpdateLocationDialog->deleteLater();
146 void MainWindow::buildFullScreenButton()
148 qDebug() << __PRETTY_FUNCTION__;
151 m_fullScreenButton = new FullScreenButton(this);
153 if (m_fullScreenButton) {
154 connect(m_fullScreenButton, SIGNAL(clicked()),
155 this, SLOT(toggleFullScreen()));
157 connect(qApp, SIGNAL(showFullScreenButton()),
158 m_fullScreenButton, SLOT(invoke()));
160 #endif // Q_WS_MAEMO_5
163 void MainWindow::buildFriendListPanel()
165 qDebug() << __PRETTY_FUNCTION__;
167 m_friendsListPanel = new FriendListPanel(this);
169 m_friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
171 m_friendsListPanel->stackUnder(m_friendsListPanelSidebar);
173 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
174 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
176 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
177 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
179 connect(m_mapView, SIGNAL(viewResized(QSize)),
180 m_friendsListPanel, SLOT(resizePanel(QSize)));
182 connect(m_mapView, SIGNAL(viewResized(QSize)),
183 m_friendsListPanelSidebar, SLOT(resizeSideBar(QSize)));
185 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
186 this, SIGNAL(findFriend(GeoCoordinate)));
188 connect(this, SIGNAL(friendImageReady(User*)),
189 m_friendsListPanel, SLOT(friendImageReady(User*)));
192 void MainWindow::buildIndicatorButtonPanel()
194 qDebug() << __PRETTY_FUNCTION__;
196 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
198 connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
199 this, SIGNAL(autoCenteringTriggered(bool)));
201 connect(m_mapView, SIGNAL(viewResized(QSize)),
202 m_indicatorButtonPanel, SLOT(screenResized(QSize)));
204 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
205 m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
207 connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
208 this, SIGNAL(draggingModeTriggered()));
211 void MainWindow::buildInformationBox(const QString &message, bool modal)
213 qDebug() << __PRETTY_FUNCTION__;
215 QString errorMessage = message;
219 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
222 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
223 // extra line changes are needed to make error notes broader
224 errorMessage.prepend("\n");
225 errorMessage.append("\n");
227 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
229 QLabel *label = new QLabel(msgBox);
230 label->setAlignment(Qt::AlignCenter);
231 label->setText(errorMessage);
232 msgBox->setWidget(label);
234 QMessageBox *msgBox = new QMessageBox(this);
235 msgBox->button(QMessageBox::Ok);
236 msgBox->setText(errorMessage);
237 msgBox->setModal(modal);
243 void MainWindow::buildManualLocationCrosshair()
245 qDebug() << __PRETTY_FUNCTION__;
247 m_ownLocationCrosshair = new QLabel(this);
248 QPixmap crosshairImage(":/res/images/sight.png");
249 m_ownLocationCrosshair->setPixmap(crosshairImage);
250 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
251 m_ownLocationCrosshair->hide();
252 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
254 connect(m_mapView, SIGNAL(viewResized(QSize)),
255 this, SLOT(drawOwnLocationCrosshair(QSize)));
258 void MainWindow::buildMap()
260 qDebug() << __PRETTY_FUNCTION__;
262 m_mapView = new MapView(this);
264 buildZoomButtonPanel();
266 buildManualLocationCrosshair();
267 buildFullScreenButton();
268 buildIndicatorButtonPanel();
271 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
272 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
274 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
275 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
277 connect(m_mapView, SIGNAL(viewResized(QSize)),
278 this, SIGNAL(mapViewResized(QSize)));
280 connect(m_mapView, SIGNAL(viewResized(QSize)),
281 this, SLOT(drawFullScreenButton(QSize)));
283 connect(m_mapView, SIGNAL(viewResized(QSize)),
284 this, SLOT(drawMapScale(QSize)));
286 connect(m_mapView, SIGNAL(viewResized(QSize)),
287 this, SLOT(setViewPortSize(QSize)));
289 connect(this, SIGNAL(zoomLevelChanged(int)),
290 m_mapView, SLOT(setZoomLevel(int)));
292 connect(m_mapView, SIGNAL(viewZoomFinished()),
293 this, SIGNAL(viewZoomFinished()));
295 connect(m_mapView, SIGNAL(zoomIn()),
296 this, SIGNAL(zoomIn()));
299 void MainWindow::buildMapScale()
301 m_mapScale = new MapScale(this);
302 connect(this, SIGNAL(newMapResolution(qreal)),
303 m_mapScale, SLOT(updateMapResolution(qreal)));
306 void MainWindow::buildOsmLicense()
308 qDebug() << __PRETTY_FUNCTION__;
310 m_osmLicense = new QLabel(this);
311 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
312 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
313 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
314 m_osmLicense->setFont(QFont("Nokia Sans", 9));
315 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
316 m_osmLicense->fontMetrics().height());
318 connect(m_mapView, SIGNAL(viewResized(QSize)),
319 this, SLOT(drawOsmLicense(QSize)));
322 void MainWindow::buildUserInfoPanel()
324 qDebug() << __PRETTY_FUNCTION__;
326 m_userPanel = new UserInfoPanel(this);
328 m_userPanelSidebar = new PanelSideBar(this, LEFT);
330 m_userPanelSidebar->stackUnder(m_friendsListPanel);
331 m_userPanel->stackUnder(m_userPanelSidebar);
333 connect(this, SIGNAL(userLocationReady(User*)),
334 m_userPanel, SLOT(userDataReceived(User*)));
336 connect(this, SIGNAL(reverseGeoReady(QString)),
337 m_userPanel, SIGNAL(reverseGeoReady(QString)));
339 connect(this, SIGNAL(clearUpdateLocationDialogData()),
340 m_userPanel, SIGNAL(clearUpdateLocationDialogData()));
342 connect(m_mapView, SIGNAL(viewResized(QSize)),
343 m_userPanel, SLOT(resizePanel(QSize)));
345 connect(m_mapView, SIGNAL(viewResized(QSize)),
346 m_userPanelSidebar, SLOT(resizeSideBar(QSize)));
348 connect(m_userPanel, SIGNAL(findUser(GeoCoordinate)),
349 this, SIGNAL(findUser(GeoCoordinate)));
351 connect(m_userPanel, SIGNAL(requestReverseGeo()),
352 this, SIGNAL(requestReverseGeo()));
354 connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
355 this, SIGNAL(statusUpdate(QString,bool)));
357 connect(m_userPanel, SIGNAL(refreshUserData()),
358 this, SIGNAL(refreshUserData()));
360 connect(m_userPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
361 this, SLOT(buildInformationBox(QString, bool)));
364 void MainWindow::buildWebView()
366 qDebug() << __PRETTY_FUNCTION__;
369 m_webView = new QWebView;
372 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
374 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
376 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
377 this, SLOT(webViewRequestFinished(QNetworkReply*)));
378 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
379 this, SIGNAL(updateCredentials(QUrl)));
380 connect(m_webView, SIGNAL(loadFinished(bool)),
381 this, SLOT(loadDone(bool)));
387 void MainWindow::buildZoomButtonPanel()
389 qDebug() << __PRETTY_FUNCTION__;
391 m_zoomButtonPanel = new ZoomButtonPanel(this);
393 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
394 this, SIGNAL(zoomIn()));
396 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
397 this, SIGNAL(zoomOut()));
399 connect(this, SIGNAL(zoomLevelChanged(int)),
400 m_zoomButtonPanel, SLOT(resetButtons()));
402 connect(this, SIGNAL(maxZoomLevelReached()),
403 m_zoomButtonPanel, SLOT(disableZoomInButton()));
405 connect(this, SIGNAL(minZoomLevelReached()),
406 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
408 connect(m_mapView, SIGNAL(viewResized(QSize)),
409 m_zoomButtonPanel, SLOT(screenResized(QSize)));
411 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
412 this, SIGNAL(draggingModeTriggered()));
415 void MainWindow::clearCookieJar()
417 qDebug() << __PRETTY_FUNCTION__;
424 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
426 QList<QNetworkCookie> emptyList;
429 m_cookieJar->setAllCookies(emptyList);
430 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
433 void MainWindow::createMenus()
435 qDebug() << __PRETTY_FUNCTION__;
438 m_loginAct = new QAction(tr("Login"), this);
439 connect(m_loginAct, SIGNAL(triggered()),
440 this, SIGNAL(loginActionPressed()));
443 m_toSettingsAct = new QAction(tr("Settings"), this);
444 connect(m_toSettingsAct, SIGNAL(triggered()),
445 this, SLOT(openSettingsDialog()));
448 m_gpsToggleAct = new QAction(tr("GPS"), this);
449 m_gpsToggleAct->setCheckable(true);
451 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
452 this, SIGNAL(gpsTriggered(bool)));
454 /// @todo remove when not needed!
455 m_searchLocationAct = new QAction(tr("Location search"), this);
456 connect(m_searchLocationAct, SIGNAL(triggered()),
457 this, SLOT(startLocationSearch()));
459 // build the actual menu
460 m_viewMenu = menuBar()->addMenu(tr("Main"));
461 m_viewMenu->addAction(m_loginAct);
462 m_viewMenu->addAction(m_toSettingsAct);
463 m_viewMenu->addAction(m_gpsToggleAct);
464 m_viewMenu->addAction(m_searchLocationAct); /// @todo remove when not needed!
465 m_viewMenu->setObjectName(tr("Menu"));
468 void MainWindow::dialogFinished(int status)
470 qDebug() << __PRETTY_FUNCTION__;
472 QDialog *dialog = m_queue.takeFirst();
473 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
474 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
478 loginDialog->userInput(m_email, m_password);
480 QStringList urlParts;
481 urlParts.append(FACEBOOK_LOGINBASE);
482 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
483 urlParts.append(INTERVAL1);
484 urlParts.append(SITUARE_LOGIN_SUCCESS);
485 urlParts.append(INTERVAL2);
486 urlParts.append(SITUARE_LOGIN_FAILURE);
487 urlParts.append(FACEBOOK_LOGIN_ENDING);
489 emit saveUsername(m_email);
491 m_webView->load(QUrl(urlParts.join(EMPTY)));
492 toggleProgressIndicator(true);
494 emit cancelLoginProcess();
496 } else if(searchDialog) {
498 emit searchForLocation(searchDialog->input());
502 dialog->deleteLater();
504 if(!m_error_queue.isEmpty() && m_errorShown == false) {
505 showErrorInformationBox();
507 if(!m_queue.isEmpty()) {
508 showInformationBox();
513 void MainWindow::drawFullScreenButton(const QSize &size)
515 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
517 if(m_fullScreenButton) {
519 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width()
521 size.height() - m_fullScreenButton->size().height());
523 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
524 size.height() - m_fullScreenButton->size().height());
529 void MainWindow::drawMapScale(const QSize &size)
531 qDebug() << __PRETTY_FUNCTION__;
533 const int LEFT_SCALE_MARGIN = 10;
534 const int BOTTOM_SCALE_MARGIN = 2;
535 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
537 m_mapScale->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
538 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
541 void MainWindow::drawOsmLicense(const QSize &size)
543 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
545 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
547 size.height() - m_osmLicense->fontMetrics().height());
550 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
552 qDebug() << __PRETTY_FUNCTION__;
554 if (m_ownLocationCrosshair != 0) {
555 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
556 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
560 void MainWindow::errorDialogFinished(int status)
562 qDebug() << __PRETTY_FUNCTION__;
565 QDialog *dialog = m_error_queue.takeFirst();
567 dialog->deleteLater();
568 m_errorShown = false;
570 if(!m_error_queue.isEmpty())
571 showErrorInformationBox();
572 else if(!m_queue.isEmpty())
573 showInformationBox();
576 void MainWindow::gpsTimeout()
578 qDebug() << __PRETTY_FUNCTION__;
580 buildInformationBox(tr("GPS timeout"));
583 void MainWindow::grabZoomKeys(bool grab)
585 qDebug() << __PRETTY_FUNCTION__;
588 // Can't grab keys unless we have a window id
592 unsigned long val = (grab) ? 1 : 0;
593 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
597 XChangeProperty (QX11Info::display(),
603 reinterpret_cast<unsigned char *>(&val),
607 #endif // Q_WS_MAEMO_5
610 void MainWindow::keyPressEvent(QKeyEvent* event)
612 qDebug() << __PRETTY_FUNCTION__;
614 switch (event->key()) {
625 QWidget::keyPressEvent(event);
628 void MainWindow::loadCookies()
630 qDebug() << __PRETTY_FUNCTION__;
632 QSettings settings(DIRECTORY_NAME, FILE_NAME);
634 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
636 if(!list.isEmpty()) {
637 QList<QNetworkCookie> cookieList;
638 for(int i=0;i<list.count();i++) {
639 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
643 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
645 m_cookieJar->setAllCookies(cookieList);
646 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
650 void MainWindow::loadDone(bool done)
652 qDebug() << __PRETTY_FUNCTION__;
654 // for the first time the login page is opened, we need to refresh it to get cookies working
662 QWebFrame* frame = m_webView->page()->currentFrame();
666 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
668 foreach (QWebElement element, emailCollection) {
669 element.setAttribute("value", m_email.toAscii());
672 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
673 foreach (QWebElement element, passwordCollection) {
674 element.setAttribute("value", m_password.toAscii());
676 // find connect button
677 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
678 foreach (QWebElement element, buttonCollection)
680 QPoint pos(element.geometry().center());
682 // send a mouse click event to the web page
683 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
685 QApplication::sendEvent(m_webView->page(), &event0);
686 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
688 QApplication::sendEvent(m_webView->page(), &event1);
694 void MainWindow::loggedIn(bool logged)
696 qDebug() << __PRETTY_FUNCTION__;
701 m_loginAct->setText(tr("Logout"));
707 m_loginAct->setText(tr("Login"));
709 updateItemVisibility();
712 void MainWindow::loginFailed()
714 qDebug() << __PRETTY_FUNCTION__;
720 bool MainWindow::loginState()
722 qDebug() << __PRETTY_FUNCTION__;
727 void MainWindow::loginUsingCookies()
729 qDebug() << __PRETTY_FUNCTION__;
731 toggleProgressIndicator(true);
736 QStringList urlParts;
737 urlParts.append(FACEBOOK_LOGINBASE);
738 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
739 urlParts.append(INTERVAL1);
740 urlParts.append(SITUARE_LOGIN_SUCCESS);
741 urlParts.append(INTERVAL2);
742 urlParts.append(SITUARE_LOGIN_FAILURE);
743 urlParts.append(FACEBOOK_LOGIN_ENDING);
745 m_webView->load(QUrl(urlParts.join(EMPTY)));
749 void MainWindow::openSettingsDialog()
751 qDebug() << __PRETTY_FUNCTION__;
753 SettingsDialog *settingsDialog = new SettingsDialog(this);
754 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
755 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
757 settingsDialog->show();
760 void MainWindow::readAutomaticLocationUpdateSettings()
762 qDebug() << __PRETTY_FUNCTION__;
764 QSettings settings(DIRECTORY_NAME, FILE_NAME);
765 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
766 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
769 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
771 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
773 emit enableAutomaticLocationUpdate(false);
777 void MainWindow::queueDialog(QDialog *dialog)
779 qDebug() << __PRETTY_FUNCTION__;
781 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
782 if(dialog->isModal()) {
783 m_error_queue.append(dialog);
785 m_queue.append(dialog);
788 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
789 if(m_error_queue.count() == 1 && m_errorShown == false)
790 showErrorInformationBox();
791 else if(m_queue.count() == 1 && m_errorShown == false)
792 showInformationBox();
795 void MainWindow::saveCookies()
797 qDebug() << __PRETTY_FUNCTION__;
800 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
802 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
805 for(int i=0;i<cookieList.count();i++) {
806 QNetworkCookie cookie = cookieList.at(i);
807 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
808 list.append(QString(byteArray));
810 list.removeDuplicates();
812 QSettings settings(DIRECTORY_NAME, FILE_NAME);
813 settings.setValue(COOKIES, list);
816 void MainWindow::setGPSButtonEnabled(bool enabled)
818 qDebug() << __PRETTY_FUNCTION__;
820 m_gpsToggleAct->setChecked(enabled);
823 void MainWindow::setIndicatorButtonEnabled(bool enabled)
825 qDebug() << __PRETTY_FUNCTION__;
827 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
830 void MainWindow::setMapViewScene(QGraphicsScene *scene)
832 qDebug() << __PRETTY_FUNCTION__;
834 m_mapView->setScene(scene);
837 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
839 qDebug() << __PRETTY_FUNCTION__;
842 m_ownLocationCrosshair->show();
843 drawOwnLocationCrosshair(m_viewPortSize);
845 m_ownLocationCrosshair->hide();
849 void MainWindow::settingsDialogAccepted()
851 qDebug() << __PRETTY_FUNCTION__;
853 readAutomaticLocationUpdateSettings();
856 void MainWindow::setUsername(const QString &username)
858 qDebug() << __PRETTY_FUNCTION__;
863 void MainWindow::setViewPortSize(const QSize &size)
865 qDebug() << __PRETTY_FUNCTION__;
867 m_viewPortSize = size;
870 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
872 qDebug() << __PRETTY_FUNCTION__;
874 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
875 tr("Automatic location update"), text,
876 QMessageBox::Yes | QMessageBox::No |
877 QMessageBox::Cancel, this);
878 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
879 this, SLOT(automaticUpdateDialogFinished(int)));
881 m_automaticUpdateLocationDialog->show();
884 void MainWindow::toggleFullScreen()
886 qDebug() << __PRETTY_FUNCTION__;
888 if(windowState() == Qt::WindowNoState)
894 void MainWindow::showErrorInformationBox()
896 qDebug() << __PRETTY_FUNCTION__;
898 if(m_error_queue.count()) {
900 QDialog *dialog = m_error_queue.first();
901 connect(dialog, SIGNAL(finished(int)),
902 this, SLOT(errorDialogFinished(int)));
907 void MainWindow::showInformationBox()
909 qDebug() << __PRETTY_FUNCTION__;
911 if(m_queue.count()) {
912 QDialog *dialog = m_queue.first();
913 connect(dialog, SIGNAL(finished(int)),
914 this, SLOT(dialogFinished(int)));
919 void MainWindow::showPanels()
921 qDebug() << __PRETTY_FUNCTION__;
923 drawFullScreenButton(m_viewPortSize);
926 if(!m_friendsListPanel->isVisible()) {
927 m_friendsListPanel->show();
928 m_friendsListPanelSidebar->show();
931 if(!m_userPanel->isVisible()) {
933 m_userPanelSidebar->show();
938 void MainWindow::startLocationSearch()
940 qDebug() << __PRETTY_FUNCTION__;
942 SearchDialog *searchDialog = new SearchDialog();
943 queueDialog(searchDialog);
946 void MainWindow::startLoginProcess()
948 qDebug() << __PRETTY_FUNCTION__;
950 LoginDialog *loginDialog = new LoginDialog();
952 emit fetchUsernameFromSettings();
954 loginDialog->clearTextFields();
956 if(!m_email.isEmpty())
957 loginDialog->setEmailField(m_email);
959 queueDialog(loginDialog);
962 void MainWindow::toggleProgressIndicator(bool value)
964 qDebug() << __PRETTY_FUNCTION__;
968 m_progressIndicatorCount++;
969 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
971 if(m_progressIndicatorCount > 0)
972 m_progressIndicatorCount--;
974 if(m_progressIndicatorCount == 0)
975 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
979 #endif // Q_WS_MAEMO_5
982 void MainWindow::updateItemVisibility()
984 qDebug() << __PRETTY_FUNCTION__;
987 m_friendsListPanel->closePanel();
988 m_friendsListPanel->hide();
989 m_friendsListPanelSidebar->hide();
990 m_userPanel->closePanel();
992 m_userPanelSidebar->hide();
996 const QString MainWindow::username()
998 qDebug() << __PRETTY_FUNCTION__;
1003 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1005 qDebug() << __PRETTY_FUNCTION__;
1007 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1008 // qwebview starts to load a new page while the current page loading is not finished
1009 if(reply->error() != QNetworkReply::OperationCanceledError &&
1010 reply->error() != QNetworkReply::NoError) {
1011 emit error(ErrorContext::NETWORK, reply->error());