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
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.
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.
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,
28 #include <QtAlgorithms>
30 #include "facebookservice/facebookauthentication.h"
31 #include "map/mapcommon.h"
32 #include "map/mapview.h"
34 #include "friendlistpanel.h"
35 #include "fullscreenbutton.h"
36 #include "indicatorbutton.h"
37 #include "logindialog.h"
39 #include "searchdialog.h"
40 #include "settingsdialog.h"
41 #include "userinfopanel.h"
42 #include "zoombuttonpanel.h"
44 #include "mainwindow.h"
46 // These MUST BE HERE, compiling for Maemo fails if moved
48 #include <QtMaemo5/QMaemo5InformationBox>
49 #include <QtGui/QX11Info>
50 #include <X11/Xatom.h>
52 #endif // Q_WS_MAEMO_5
54 MainWindow::MainWindow(QWidget *parent)
55 : QMainWindow(parent),
56 m_drawOwnLocationCrosshair(false),
60 m_progressIndicatorCount(0),
61 m_ownLocationCrosshair(0),
65 m_fullScreenButton(0),
70 qDebug() << __PRETTY_FUNCTION__;
75 QHBoxLayout *layout = new QHBoxLayout;
76 layout->addWidget(m_mapView);
78 layout->setSpacing(0);
80 setCentralWidget(new QWidget());
81 centralWidget()->setLayout(layout);
83 buildFriendListPanel();
87 setWindowTitle(tr("Situare"));
89 // set stacking order of widgets
90 m_zoomButtonPanel->stackUnder(m_userPanel);
91 if(m_fullScreenButton) {
92 m_fullScreenButton->stackUnder(m_zoomButtonPanel);
93 m_osmLicense->stackUnder(m_fullScreenButton);
95 m_osmLicense->stackUnder(m_zoomButtonPanel);
97 m_ownLocationCrosshair->stackUnder(m_osmLicense);
98 m_indicatorButton->stackUnder(m_ownLocationCrosshair);
99 m_mapScale->stackUnder(m_indicatorButton);
100 m_mapView->stackUnder(m_mapScale);
104 // Set default screen size
105 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
107 setAttribute(Qt::WA_Maemo5StackedWindow);
111 MainWindow::~MainWindow()
113 qDebug() << __PRETTY_FUNCTION__;
120 qDeleteAll(m_queue.begin(), m_queue.end());
123 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
124 m_error_queue.clear();
127 void MainWindow::automaticUpdateDialogFinished(int result)
129 qDebug() << __PRETTY_FUNCTION__;
131 if (result == QMessageBox::Yes) {
132 readAutomaticLocationUpdateSettings();
134 QSettings settings(DIRECTORY_NAME, FILE_NAME);
135 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
136 readAutomaticLocationUpdateSettings();
139 m_automaticUpdateLocationDialog->deleteLater();
142 void MainWindow::buildFullScreenButton()
144 qDebug() << __PRETTY_FUNCTION__;
146 m_fullScreenButton = new FullScreenButton(this);
147 connect(m_fullScreenButton, SIGNAL(clicked()),
148 this, SLOT(toggleFullScreen()));
149 #endif // Q_WS_MAEMO_5
152 void MainWindow::buildFriendListPanel()
154 qDebug() << __PRETTY_FUNCTION__;
156 m_friendsListPanel = new FriendListPanel(this);
158 m_friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
160 m_friendsListPanel->stackUnder(m_friendsListPanelSidebar);
162 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
163 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
165 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
166 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
168 connect(m_mapView, SIGNAL(viewResized(QSize)),
169 m_friendsListPanel, SLOT(resizePanel(QSize)));
171 connect(m_mapView, SIGNAL(viewResized(QSize)),
172 m_friendsListPanelSidebar, SLOT(resizeSideBar(QSize)));
174 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
175 this, SIGNAL(findFriend(GeoCoordinate)));
177 connect(this, SIGNAL(friendImageReady(User*)),
178 m_friendsListPanel, SLOT(friendImageReady(User*)));
180 connect(this, SIGNAL(locationDataParsed(QList<Location>&)),
181 m_friendsListPanel, SLOT(locationDataReady(QList<Location>&)));
183 connect(m_friendsListPanel, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)),
184 this, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)));
187 void MainWindow::buildIndicatorButton()
189 qDebug() << __PRETTY_FUNCTION__;
191 m_indicatorButton = new IndicatorButton(this);
193 connect(m_indicatorButton, SIGNAL(autoCenteringTriggered(bool)),
194 this, SIGNAL(autoCenteringTriggered(bool)));
196 connect(m_mapView, SIGNAL(viewResized(QSize)),
197 m_indicatorButton, SLOT(screenResized(QSize)));
200 void MainWindow::buildInformationBox(const QString &message, bool modal)
202 qDebug() << __PRETTY_FUNCTION__;
204 QString errorMessage = message;
208 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
211 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
212 // extra line changes are needed to make error notes broader
213 errorMessage.prepend("\n");
214 errorMessage.append("\n");
216 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
218 QLabel *label = new QLabel(msgBox);
219 label->setAlignment(Qt::AlignCenter);
220 label->setText(errorMessage);
221 msgBox->setWidget(label);
223 QMessageBox *msgBox = new QMessageBox(this);
224 msgBox->button(QMessageBox::Ok);
225 msgBox->setText(errorMessage);
226 msgBox->setModal(modal);
232 void MainWindow::buildManualLocationCrosshair()
234 qDebug() << __PRETTY_FUNCTION__;
236 m_ownLocationCrosshair = new QLabel(this);
237 QPixmap crosshairImage(":/res/images/sight.png");
238 m_ownLocationCrosshair->setPixmap(crosshairImage);
239 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
240 m_ownLocationCrosshair->hide();
241 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
243 connect(m_mapView, SIGNAL(viewResized(QSize)),
244 this, SLOT(drawOwnLocationCrosshair(QSize)));
247 void MainWindow::buildMap()
249 qDebug() << __PRETTY_FUNCTION__;
251 m_mapView = new MapView(this);
253 buildZoomButtonPanel();
255 buildManualLocationCrosshair();
256 buildFullScreenButton();
257 buildIndicatorButton();
260 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
261 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
263 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
264 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
266 connect(m_mapView, SIGNAL(viewResized(QSize)),
267 this, SIGNAL(mapViewResized(QSize)));
269 connect(m_mapView, SIGNAL(viewResized(QSize)),
270 this, SLOT(drawFullScreenButton(QSize)));
272 connect(m_mapView, SIGNAL(viewResized(QSize)),
273 this, SLOT(drawMapScale(QSize)));
275 connect(m_mapView, SIGNAL(viewResized(QSize)),
276 this, SLOT(setViewPortSize(QSize)));
278 connect(this, SIGNAL(zoomLevelChanged(int)),
279 m_mapView, SLOT(setZoomLevel(int)));
281 connect(m_mapView, SIGNAL(viewZoomFinished()),
282 this, SIGNAL(viewZoomFinished()));
284 connect(m_mapView, SIGNAL(zoomIn()),
285 this, SIGNAL(zoomIn()));
288 void MainWindow::buildMapScale()
290 m_mapScale = new MapScale(this);
291 connect(this, SIGNAL(newMapResolution(qreal)),
292 m_mapScale, SLOT(updateMapResolution(qreal)));
295 void MainWindow::buildOsmLicense()
297 qDebug() << __PRETTY_FUNCTION__;
299 m_osmLicense = new QLabel(this);
300 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
301 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
302 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
303 m_osmLicense->setFont(QFont("Nokia Sans", 9));
304 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
305 m_osmLicense->fontMetrics().height());
307 connect(m_mapView, SIGNAL(viewResized(QSize)),
308 this, SLOT(drawOsmLicense(QSize)));
311 void MainWindow::buildUserInfoPanel()
313 qDebug() << __PRETTY_FUNCTION__;
315 m_userPanel = new UserInfoPanel(this);
317 m_userPanelSidebar = new PanelSideBar(this, LEFT);
319 m_userPanelSidebar->stackUnder(m_friendsListPanel);
320 m_userPanel->stackUnder(m_userPanelSidebar);
322 connect(this, SIGNAL(userLocationReady(User*)),
323 m_userPanel, SLOT(userDataReceived(User*)));
325 connect(this, SIGNAL(reverseGeoReady(QString)),
326 m_userPanel, SIGNAL(reverseGeoReady(QString)));
328 connect(this, SIGNAL(clearUpdateLocationDialogData()),
329 m_userPanel, SIGNAL(clearUpdateLocationDialogData()));
331 connect(m_mapView, SIGNAL(viewResized(QSize)),
332 m_userPanel, SLOT(resizePanel(QSize)));
334 connect(m_mapView, SIGNAL(viewResized(QSize)),
335 m_userPanelSidebar, SLOT(resizeSideBar(QSize)));
337 connect(m_userPanel, SIGNAL(findUser(GeoCoordinate)),
338 this, SIGNAL(findUser(GeoCoordinate)));
340 connect(m_userPanel, SIGNAL(requestReverseGeo()),
341 this, SIGNAL(requestReverseGeo()));
343 connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
344 this, SIGNAL(statusUpdate(QString,bool)));
346 connect(m_userPanel, SIGNAL(refreshUserData()),
347 this, SIGNAL(refreshUserData()));
349 connect(m_userPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
350 this, SLOT(buildInformationBox(QString, bool)));
353 void MainWindow::buildWebView()
355 qDebug() << __PRETTY_FUNCTION__;
358 m_webView = new QWebView;
361 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
363 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
365 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
366 this, SLOT(webViewRequestFinished(QNetworkReply*)));
367 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
368 this, SIGNAL(updateCredentials(QUrl)));
369 connect(m_webView, SIGNAL(loadFinished(bool)),
370 this, SLOT(loadDone(bool)));
376 void MainWindow::buildZoomButtonPanel()
378 qDebug() << __PRETTY_FUNCTION__;
380 m_zoomButtonPanel = new ZoomButtonPanel(this);
382 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
383 this, SIGNAL(zoomIn()));
385 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
386 this, SIGNAL(zoomOut()));
388 connect(this, SIGNAL(zoomLevelChanged(int)),
389 m_zoomButtonPanel, SLOT(resetButtons()));
391 connect(this, SIGNAL(maxZoomLevelReached()),
392 m_zoomButtonPanel, SLOT(disableZoomInButton()));
394 connect(this, SIGNAL(minZoomLevelReached()),
395 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
397 connect(m_mapView, SIGNAL(viewResized(QSize)),
398 m_zoomButtonPanel, SLOT(screenResized(QSize)));
402 void MainWindow::clearCookieJar()
404 qDebug() << __PRETTY_FUNCTION__;
411 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
413 QList<QNetworkCookie> emptyList;
416 m_cookieJar->setAllCookies(emptyList);
417 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
420 void MainWindow::createMenus()
422 qDebug() << __PRETTY_FUNCTION__;
425 m_loginAct = new QAction(tr("Login"), this);
426 connect(m_loginAct, SIGNAL(triggered()),
427 this, SIGNAL(loginActionPressed()));
430 m_toSettingsAct = new QAction(tr("Settings"), this);
431 connect(m_toSettingsAct, SIGNAL(triggered()),
432 this, SLOT(openSettingsDialog()));
435 m_gpsToggleAct = new QAction(tr("GPS"), this);
436 m_gpsToggleAct->setCheckable(true);
438 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
439 this, SIGNAL(gpsTriggered(bool)));
441 /// @todo remove when not needed!
442 m_searchLocationAct = new QAction(tr("Location search"), this);
443 connect(m_searchLocationAct, SIGNAL(triggered()),
444 this, SLOT(startLocationSearch()));
446 // build the actual menu
447 m_viewMenu = menuBar()->addMenu(tr("Main"));
448 m_viewMenu->addAction(m_loginAct);
449 m_viewMenu->addAction(m_toSettingsAct);
450 m_viewMenu->addAction(m_gpsToggleAct);
451 m_viewMenu->addAction(m_searchLocationAct); /// @todo remove when not needed!
452 m_viewMenu->setObjectName(tr("Menu"));
455 void MainWindow::dialogFinished(int status)
457 qDebug() << __PRETTY_FUNCTION__;
459 QDialog *dialog = m_queue.takeFirst();
460 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
461 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
465 loginDialog->userInput(m_email, m_password);
467 QStringList urlParts;
468 urlParts.append(FACEBOOK_LOGINBASE);
469 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
470 urlParts.append(INTERVAL1);
471 urlParts.append(SITUARE_LOGIN_SUCCESS);
472 urlParts.append(INTERVAL2);
473 urlParts.append(SITUARE_LOGIN_FAILURE);
474 urlParts.append(FACEBOOK_LOGIN_ENDING);
476 emit saveUsername(m_email);
478 m_webView->load(QUrl(urlParts.join(EMPTY)));
479 toggleProgressIndicator(true);
481 emit cancelLoginProcess();
483 } else if(searchDialog) {
485 emit searchForLocation(searchDialog->input());
489 dialog->deleteLater();
491 if(!m_error_queue.isEmpty() && m_errorShown == false) {
492 showErrorInformationBox();
494 if(!m_queue.isEmpty()) {
495 showInformationBox();
500 void MainWindow::drawFullScreenButton(const QSize &size)
502 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
504 if(m_fullScreenButton) {
506 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width()
508 size.height() - m_fullScreenButton->size().height());
510 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
511 size.height() - m_fullScreenButton->size().height());
516 void MainWindow::drawMapScale(const QSize &size)
518 qDebug() << __PRETTY_FUNCTION__;
520 const int LEFT_SCALE_MARGIN = 10;
521 const int BOTTOM_SCALE_MARGIN = 2;
522 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
524 m_mapScale->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
525 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
528 void MainWindow::drawOsmLicense(const QSize &size)
530 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
532 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
534 size.height() - m_osmLicense->fontMetrics().height());
537 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
539 qDebug() << __PRETTY_FUNCTION__;
541 if (m_drawOwnLocationCrosshair && m_ownLocationCrosshair != 0) {
542 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
543 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
547 void MainWindow::errorDialogFinished(int status)
549 qDebug() << __PRETTY_FUNCTION__;
552 QDialog *dialog = m_error_queue.takeFirst();
554 dialog->deleteLater();
555 m_errorShown = false;
557 if(!m_error_queue.isEmpty())
558 showErrorInformationBox();
559 else if(!m_queue.isEmpty())
560 showInformationBox();
563 void MainWindow::gpsTimeout()
565 qDebug() << __PRETTY_FUNCTION__;
567 buildInformationBox(tr("GPS timeout"));
570 void MainWindow::grabZoomKeys(bool grab)
572 qDebug() << __PRETTY_FUNCTION__;
575 // Can't grab keys unless we have a window id
579 unsigned long val = (grab) ? 1 : 0;
580 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
584 XChangeProperty (QX11Info::display(),
590 reinterpret_cast<unsigned char *>(&val),
594 #endif // Q_WS_MAEMO_5
597 void MainWindow::keyPressEvent(QKeyEvent* event)
599 qDebug() << __PRETTY_FUNCTION__;
601 switch (event->key()) {
612 QWidget::keyPressEvent(event);
615 void MainWindow::loadCookies()
617 qDebug() << __PRETTY_FUNCTION__;
619 QSettings settings(DIRECTORY_NAME, FILE_NAME);
621 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
623 if(!list.isEmpty()) {
624 QList<QNetworkCookie> cookieList;
625 for(int i=0;i<list.count();i++) {
626 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
630 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
632 m_cookieJar->setAllCookies(cookieList);
633 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
637 void MainWindow::loadDone(bool done)
639 qDebug() << __PRETTY_FUNCTION__;
641 // for the first time the login page is opened, we need to refresh it to get cookies working
649 QWebFrame* frame = m_webView->page()->currentFrame();
653 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
655 foreach (QWebElement element, emailCollection) {
656 element.setAttribute("value", m_email.toAscii());
659 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
660 foreach (QWebElement element, passwordCollection) {
661 element.setAttribute("value", m_password.toAscii());
663 // find connect button
664 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
665 foreach (QWebElement element, buttonCollection)
667 QPoint pos(element.geometry().center());
669 // send a mouse click event to the web page
670 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
672 QApplication::sendEvent(m_webView->page(), &event0);
673 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
675 QApplication::sendEvent(m_webView->page(), &event1);
681 void MainWindow::loggedIn(bool logged)
683 qDebug() << __PRETTY_FUNCTION__;
688 m_loginAct->setText(tr("Logout"));
694 m_loginAct->setText(tr("Login"));
696 updateItemVisibility();
699 void MainWindow::loginFailed()
701 qDebug() << __PRETTY_FUNCTION__;
707 bool MainWindow::loginState()
709 qDebug() << __PRETTY_FUNCTION__;
714 void MainWindow::loginUsingCookies()
716 qDebug() << __PRETTY_FUNCTION__;
718 toggleProgressIndicator(true);
723 QStringList urlParts;
724 urlParts.append(FACEBOOK_LOGINBASE);
725 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
726 urlParts.append(INTERVAL1);
727 urlParts.append(SITUARE_LOGIN_SUCCESS);
728 urlParts.append(INTERVAL2);
729 urlParts.append(SITUARE_LOGIN_FAILURE);
730 urlParts.append(FACEBOOK_LOGIN_ENDING);
732 m_webView->load(QUrl(urlParts.join(EMPTY)));
736 void MainWindow::openSettingsDialog()
738 qDebug() << __PRETTY_FUNCTION__;
740 SettingsDialog *settingsDialog = new SettingsDialog(this);
741 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
742 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
744 settingsDialog->show();
747 void MainWindow::readAutomaticLocationUpdateSettings()
749 qDebug() << __PRETTY_FUNCTION__;
751 QSettings settings(DIRECTORY_NAME, FILE_NAME);
752 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
753 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
756 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
758 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
760 emit enableAutomaticLocationUpdate(false);
764 void MainWindow::queueDialog(QDialog *dialog)
766 qDebug() << __PRETTY_FUNCTION__;
768 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
769 if(dialog->isModal()) {
770 m_error_queue.append(dialog);
772 m_queue.append(dialog);
775 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
776 if(m_error_queue.count() == 1 && m_errorShown == false)
777 showErrorInformationBox();
778 else if(m_queue.count() == 1 && m_errorShown == false)
779 showInformationBox();
782 void MainWindow::saveCookies()
784 qDebug() << __PRETTY_FUNCTION__;
787 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
789 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
792 for(int i=0;i<cookieList.count();i++) {
793 QNetworkCookie cookie = cookieList.at(i);
794 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
795 list.append(QString(byteArray));
797 list.removeDuplicates();
799 QSettings settings(DIRECTORY_NAME, FILE_NAME);
800 settings.setValue(COOKIES, list);
803 void MainWindow::setGPSButtonEnabled(bool enabled)
805 qDebug() << __PRETTY_FUNCTION__;
807 m_gpsToggleAct->setChecked(enabled);
809 setOwnLocationCrosshairVisibility(!enabled);
812 void MainWindow::setIndicatorButtonEnabled(bool enabled)
814 qDebug() << __PRETTY_FUNCTION__;
816 m_indicatorButton->setChecked(enabled);
820 void MainWindow::setMapViewScene(QGraphicsScene *scene)
822 qDebug() << __PRETTY_FUNCTION__;
824 m_mapView->setScene(scene);
827 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
829 qDebug() << __PRETTY_FUNCTION__;
831 if (visibility && m_loggedIn) {
832 m_ownLocationCrosshair->show();
833 m_drawOwnLocationCrosshair = true;
834 drawOwnLocationCrosshair(m_viewPortSize);
836 m_ownLocationCrosshair->hide();
837 m_drawOwnLocationCrosshair = false;
841 void MainWindow::settingsDialogAccepted()
843 qDebug() << __PRETTY_FUNCTION__;
845 readAutomaticLocationUpdateSettings();
848 void MainWindow::setUsername(const QString &username)
850 qDebug() << __PRETTY_FUNCTION__;
855 void MainWindow::setViewPortSize(const QSize &size)
857 qDebug() << __PRETTY_FUNCTION__;
859 m_viewPortSize = size;
862 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
864 qDebug() << __PRETTY_FUNCTION__;
866 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
867 tr("Automatic location update"), text,
868 QMessageBox::Yes | QMessageBox::No |
869 QMessageBox::Cancel, this);
870 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
871 this, SLOT(automaticUpdateDialogFinished(int)));
873 m_automaticUpdateLocationDialog->show();
876 void MainWindow::toggleFullScreen()
878 qDebug() << __PRETTY_FUNCTION__;
880 if(windowState() == Qt::WindowNoState)
886 void MainWindow::showErrorInformationBox()
888 qDebug() << __PRETTY_FUNCTION__;
890 if(m_error_queue.count()) {
892 QDialog *dialog = m_error_queue.first();
893 connect(dialog, SIGNAL(finished(int)),
894 this, SLOT(errorDialogFinished(int)));
899 void MainWindow::showInformationBox()
901 qDebug() << __PRETTY_FUNCTION__;
903 if(m_queue.count()) {
904 QDialog *dialog = m_queue.first();
905 connect(dialog, SIGNAL(finished(int)),
906 this, SLOT(dialogFinished(int)));
911 void MainWindow::showPanels()
913 qDebug() << __PRETTY_FUNCTION__;
915 drawFullScreenButton(m_viewPortSize);
918 if(!m_friendsListPanel->isVisible()) {
919 m_friendsListPanel->show();
920 m_friendsListPanelSidebar->show();
923 if(!m_userPanel->isVisible()) {
925 m_userPanelSidebar->show();
930 void MainWindow::startLocationSearch()
932 qDebug() << __PRETTY_FUNCTION__;
934 SearchDialog *searchDialog = new SearchDialog();
935 queueDialog(searchDialog);
938 void MainWindow::startLoginProcess()
940 qDebug() << __PRETTY_FUNCTION__;
942 LoginDialog *loginDialog = new LoginDialog();
944 emit fetchUsernameFromSettings();
946 loginDialog->clearTextFields();
948 if(!m_email.isEmpty())
949 loginDialog->setEmailField(m_email);
951 queueDialog(loginDialog);
954 void MainWindow::toggleProgressIndicator(bool value)
956 qDebug() << __PRETTY_FUNCTION__;
960 m_progressIndicatorCount++;
961 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
963 if(m_progressIndicatorCount > 0)
964 m_progressIndicatorCount--;
966 if(m_progressIndicatorCount == 0)
967 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
971 #endif // Q_WS_MAEMO_5
974 void MainWindow::updateItemVisibility()
976 qDebug() << __PRETTY_FUNCTION__;
980 if(!m_gpsToggleAct->isChecked())
981 setOwnLocationCrosshairVisibility(true);
983 m_friendsListPanel->closePanel();
984 m_friendsListPanel->hide();
985 m_friendsListPanelSidebar->hide();
986 m_userPanel->closePanel();
988 m_userPanelSidebar->hide();
989 setOwnLocationCrosshairVisibility(false);
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());