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*)));
181 void MainWindow::buildIndicatorButton()
183 qDebug() << __PRETTY_FUNCTION__;
185 m_indicatorButton = new IndicatorButton(this);
187 connect(m_indicatorButton, SIGNAL(autoCenteringTriggered(bool)),
188 this, SIGNAL(autoCenteringTriggered(bool)));
190 connect(m_mapView, SIGNAL(viewResized(QSize)),
191 m_indicatorButton, SLOT(screenResized(QSize)));
193 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
194 m_indicatorButton, SLOT(updateValues(qreal, qreal, bool)));
197 void MainWindow::buildInformationBox(const QString &message, bool modal)
199 qDebug() << __PRETTY_FUNCTION__;
201 QString errorMessage = message;
205 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
208 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
209 // extra line changes are needed to make error notes broader
210 errorMessage.prepend("\n");
211 errorMessage.append("\n");
213 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
215 QLabel *label = new QLabel(msgBox);
216 label->setAlignment(Qt::AlignCenter);
217 label->setText(errorMessage);
218 msgBox->setWidget(label);
220 QMessageBox *msgBox = new QMessageBox(this);
221 msgBox->button(QMessageBox::Ok);
222 msgBox->setText(errorMessage);
223 msgBox->setModal(modal);
229 void MainWindow::buildManualLocationCrosshair()
231 qDebug() << __PRETTY_FUNCTION__;
233 m_ownLocationCrosshair = new QLabel(this);
234 QPixmap crosshairImage(":/res/images/sight.png");
235 m_ownLocationCrosshair->setPixmap(crosshairImage);
236 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
237 m_ownLocationCrosshair->hide();
238 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
240 connect(m_mapView, SIGNAL(viewResized(QSize)),
241 this, SLOT(drawOwnLocationCrosshair(QSize)));
244 void MainWindow::buildMap()
246 qDebug() << __PRETTY_FUNCTION__;
248 m_mapView = new MapView(this);
250 buildZoomButtonPanel();
252 buildManualLocationCrosshair();
253 buildFullScreenButton();
254 buildIndicatorButton();
257 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
258 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
260 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
261 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
263 connect(m_mapView, SIGNAL(viewResized(QSize)),
264 this, SIGNAL(mapViewResized(QSize)));
266 connect(m_mapView, SIGNAL(viewResized(QSize)),
267 this, SLOT(drawFullScreenButton(QSize)));
269 connect(m_mapView, SIGNAL(viewResized(QSize)),
270 this, SLOT(drawMapScale(QSize)));
272 connect(m_mapView, SIGNAL(viewResized(QSize)),
273 this, SLOT(setViewPortSize(QSize)));
275 connect(this, SIGNAL(zoomLevelChanged(int)),
276 m_mapView, SLOT(setZoomLevel(int)));
278 connect(m_mapView, SIGNAL(viewZoomFinished()),
279 this, SIGNAL(viewZoomFinished()));
281 connect(m_mapView, SIGNAL(zoomIn()),
282 this, SIGNAL(zoomIn()));
285 void MainWindow::buildMapScale()
287 m_mapScale = new MapScale(this);
288 connect(this, SIGNAL(newMapResolution(qreal)),
289 m_mapScale, SLOT(updateMapResolution(qreal)));
292 void MainWindow::buildOsmLicense()
294 qDebug() << __PRETTY_FUNCTION__;
296 m_osmLicense = new QLabel(this);
297 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
298 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
299 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
300 m_osmLicense->setFont(QFont("Nokia Sans", 9));
301 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
302 m_osmLicense->fontMetrics().height());
304 connect(m_mapView, SIGNAL(viewResized(QSize)),
305 this, SLOT(drawOsmLicense(QSize)));
308 void MainWindow::buildUserInfoPanel()
310 qDebug() << __PRETTY_FUNCTION__;
312 m_userPanel = new UserInfoPanel(this);
314 m_userPanelSidebar = new PanelSideBar(this, LEFT);
316 m_userPanelSidebar->stackUnder(m_friendsListPanel);
317 m_userPanel->stackUnder(m_userPanelSidebar);
319 connect(this, SIGNAL(userLocationReady(User*)),
320 m_userPanel, SLOT(userDataReceived(User*)));
322 connect(this, SIGNAL(reverseGeoReady(QString)),
323 m_userPanel, SIGNAL(reverseGeoReady(QString)));
325 connect(this, SIGNAL(clearUpdateLocationDialogData()),
326 m_userPanel, SIGNAL(clearUpdateLocationDialogData()));
328 connect(m_mapView, SIGNAL(viewResized(QSize)),
329 m_userPanel, SLOT(resizePanel(QSize)));
331 connect(m_mapView, SIGNAL(viewResized(QSize)),
332 m_userPanelSidebar, SLOT(resizeSideBar(QSize)));
334 connect(m_userPanel, SIGNAL(findUser(GeoCoordinate)),
335 this, SIGNAL(findUser(GeoCoordinate)));
337 connect(m_userPanel, SIGNAL(requestReverseGeo()),
338 this, SIGNAL(requestReverseGeo()));
340 connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
341 this, SIGNAL(statusUpdate(QString,bool)));
343 connect(m_userPanel, SIGNAL(refreshUserData()),
344 this, SIGNAL(refreshUserData()));
346 connect(m_userPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
347 this, SLOT(buildInformationBox(QString, bool)));
350 void MainWindow::buildWebView()
352 qDebug() << __PRETTY_FUNCTION__;
355 m_webView = new QWebView;
358 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
360 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
362 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
363 this, SLOT(webViewRequestFinished(QNetworkReply*)));
364 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
365 this, SIGNAL(updateCredentials(QUrl)));
366 connect(m_webView, SIGNAL(loadFinished(bool)),
367 this, SLOT(loadDone(bool)));
373 void MainWindow::buildZoomButtonPanel()
375 qDebug() << __PRETTY_FUNCTION__;
377 m_zoomButtonPanel = new ZoomButtonPanel(this);
379 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
380 this, SIGNAL(zoomIn()));
382 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
383 this, SIGNAL(zoomOut()));
385 connect(this, SIGNAL(zoomLevelChanged(int)),
386 m_zoomButtonPanel, SLOT(resetButtons()));
388 connect(this, SIGNAL(maxZoomLevelReached()),
389 m_zoomButtonPanel, SLOT(disableZoomInButton()));
391 connect(this, SIGNAL(minZoomLevelReached()),
392 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
394 connect(m_mapView, SIGNAL(viewResized(QSize)),
395 m_zoomButtonPanel, SLOT(screenResized(QSize)));
399 void MainWindow::clearCookieJar()
401 qDebug() << __PRETTY_FUNCTION__;
408 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
410 QList<QNetworkCookie> emptyList;
413 m_cookieJar->setAllCookies(emptyList);
414 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
417 void MainWindow::createMenus()
419 qDebug() << __PRETTY_FUNCTION__;
422 m_loginAct = new QAction(tr("Login"), this);
423 connect(m_loginAct, SIGNAL(triggered()),
424 this, SIGNAL(loginActionPressed()));
427 m_toSettingsAct = new QAction(tr("Settings"), this);
428 connect(m_toSettingsAct, SIGNAL(triggered()),
429 this, SLOT(openSettingsDialog()));
432 m_gpsToggleAct = new QAction(tr("GPS"), this);
433 m_gpsToggleAct->setCheckable(true);
435 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
436 this, SIGNAL(gpsTriggered(bool)));
438 /// @todo remove when not needed!
439 m_searchLocationAct = new QAction(tr("Location search"), this);
440 connect(m_searchLocationAct, SIGNAL(triggered()),
441 this, SLOT(startLocationSearch()));
443 // build the actual menu
444 m_viewMenu = menuBar()->addMenu(tr("Main"));
445 m_viewMenu->addAction(m_loginAct);
446 m_viewMenu->addAction(m_toSettingsAct);
447 m_viewMenu->addAction(m_gpsToggleAct);
448 m_viewMenu->addAction(m_searchLocationAct); /// @todo remove when not needed!
449 m_viewMenu->setObjectName(tr("Menu"));
452 void MainWindow::dialogFinished(int status)
454 qDebug() << __PRETTY_FUNCTION__;
456 QDialog *dialog = m_queue.takeFirst();
457 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
458 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
462 loginDialog->userInput(m_email, m_password);
464 QStringList urlParts;
465 urlParts.append(FACEBOOK_LOGINBASE);
466 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
467 urlParts.append(INTERVAL1);
468 urlParts.append(SITUARE_LOGIN_SUCCESS);
469 urlParts.append(INTERVAL2);
470 urlParts.append(SITUARE_LOGIN_FAILURE);
471 urlParts.append(FACEBOOK_LOGIN_ENDING);
473 emit saveUsername(m_email);
475 m_webView->load(QUrl(urlParts.join(EMPTY)));
476 toggleProgressIndicator(true);
478 emit cancelLoginProcess();
480 } else if(searchDialog) {
482 emit searchForLocation(searchDialog->input());
486 dialog->deleteLater();
488 if(!m_error_queue.isEmpty() && m_errorShown == false) {
489 showErrorInformationBox();
491 if(!m_queue.isEmpty()) {
492 showInformationBox();
497 void MainWindow::drawFullScreenButton(const QSize &size)
499 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
501 if(m_fullScreenButton) {
503 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width()
505 size.height() - m_fullScreenButton->size().height());
507 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
508 size.height() - m_fullScreenButton->size().height());
513 void MainWindow::drawMapScale(const QSize &size)
515 qDebug() << __PRETTY_FUNCTION__;
517 const int LEFT_SCALE_MARGIN = 10;
518 const int BOTTOM_SCALE_MARGIN = 2;
519 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
521 m_mapScale->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
522 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
525 void MainWindow::drawOsmLicense(const QSize &size)
527 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
529 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
531 size.height() - m_osmLicense->fontMetrics().height());
534 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
536 qDebug() << __PRETTY_FUNCTION__;
538 if (m_drawOwnLocationCrosshair && m_ownLocationCrosshair != 0) {
539 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
540 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
544 void MainWindow::errorDialogFinished(int status)
546 qDebug() << __PRETTY_FUNCTION__;
549 QDialog *dialog = m_error_queue.takeFirst();
551 dialog->deleteLater();
552 m_errorShown = false;
554 if(!m_error_queue.isEmpty())
555 showErrorInformationBox();
556 else if(!m_queue.isEmpty())
557 showInformationBox();
560 void MainWindow::gpsTimeout()
562 qDebug() << __PRETTY_FUNCTION__;
564 buildInformationBox(tr("GPS timeout"));
567 void MainWindow::grabZoomKeys(bool grab)
569 qDebug() << __PRETTY_FUNCTION__;
572 // Can't grab keys unless we have a window id
576 unsigned long val = (grab) ? 1 : 0;
577 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
581 XChangeProperty (QX11Info::display(),
587 reinterpret_cast<unsigned char *>(&val),
591 #endif // Q_WS_MAEMO_5
594 void MainWindow::keyPressEvent(QKeyEvent* event)
596 qDebug() << __PRETTY_FUNCTION__;
598 switch (event->key()) {
609 QWidget::keyPressEvent(event);
612 void MainWindow::loadCookies()
614 qDebug() << __PRETTY_FUNCTION__;
616 QSettings settings(DIRECTORY_NAME, FILE_NAME);
618 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
620 if(!list.isEmpty()) {
621 QList<QNetworkCookie> cookieList;
622 for(int i=0;i<list.count();i++) {
623 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
627 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
629 m_cookieJar->setAllCookies(cookieList);
630 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
634 void MainWindow::loadDone(bool done)
636 qDebug() << __PRETTY_FUNCTION__;
638 // for the first time the login page is opened, we need to refresh it to get cookies working
646 QWebFrame* frame = m_webView->page()->currentFrame();
650 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
652 foreach (QWebElement element, emailCollection) {
653 element.setAttribute("value", m_email.toAscii());
656 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
657 foreach (QWebElement element, passwordCollection) {
658 element.setAttribute("value", m_password.toAscii());
660 // find connect button
661 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
662 foreach (QWebElement element, buttonCollection)
664 QPoint pos(element.geometry().center());
666 // send a mouse click event to the web page
667 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
669 QApplication::sendEvent(m_webView->page(), &event0);
670 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
672 QApplication::sendEvent(m_webView->page(), &event1);
678 void MainWindow::loggedIn(bool logged)
680 qDebug() << __PRETTY_FUNCTION__;
685 m_loginAct->setText(tr("Logout"));
691 m_loginAct->setText(tr("Login"));
693 updateItemVisibility();
696 void MainWindow::loginFailed()
698 qDebug() << __PRETTY_FUNCTION__;
704 bool MainWindow::loginState()
706 qDebug() << __PRETTY_FUNCTION__;
711 void MainWindow::loginUsingCookies()
713 qDebug() << __PRETTY_FUNCTION__;
715 toggleProgressIndicator(true);
720 QStringList urlParts;
721 urlParts.append(FACEBOOK_LOGINBASE);
722 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
723 urlParts.append(INTERVAL1);
724 urlParts.append(SITUARE_LOGIN_SUCCESS);
725 urlParts.append(INTERVAL2);
726 urlParts.append(SITUARE_LOGIN_FAILURE);
727 urlParts.append(FACEBOOK_LOGIN_ENDING);
729 m_webView->load(QUrl(urlParts.join(EMPTY)));
733 void MainWindow::openSettingsDialog()
735 qDebug() << __PRETTY_FUNCTION__;
737 SettingsDialog *settingsDialog = new SettingsDialog(this);
738 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
739 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
741 settingsDialog->show();
744 void MainWindow::readAutomaticLocationUpdateSettings()
746 qDebug() << __PRETTY_FUNCTION__;
748 QSettings settings(DIRECTORY_NAME, FILE_NAME);
749 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
750 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
753 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
755 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
757 emit enableAutomaticLocationUpdate(false);
761 void MainWindow::queueDialog(QDialog *dialog)
763 qDebug() << __PRETTY_FUNCTION__;
765 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
766 if(dialog->isModal()) {
767 m_error_queue.append(dialog);
769 m_queue.append(dialog);
772 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
773 if(m_error_queue.count() == 1 && m_errorShown == false)
774 showErrorInformationBox();
775 else if(m_queue.count() == 1 && m_errorShown == false)
776 showInformationBox();
779 void MainWindow::saveCookies()
781 qDebug() << __PRETTY_FUNCTION__;
784 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
786 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
789 for(int i=0;i<cookieList.count();i++) {
790 QNetworkCookie cookie = cookieList.at(i);
791 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
792 list.append(QString(byteArray));
794 list.removeDuplicates();
796 QSettings settings(DIRECTORY_NAME, FILE_NAME);
797 settings.setValue(COOKIES, list);
800 void MainWindow::setGPSButtonEnabled(bool enabled)
802 qDebug() << __PRETTY_FUNCTION__;
804 m_gpsToggleAct->setChecked(enabled);
806 setOwnLocationCrosshairVisibility(!enabled);
809 void MainWindow::setIndicatorButtonEnabled(bool enabled)
811 qDebug() << __PRETTY_FUNCTION__;
813 m_indicatorButton->setChecked(enabled);
817 void MainWindow::setMapViewScene(QGraphicsScene *scene)
819 qDebug() << __PRETTY_FUNCTION__;
821 m_mapView->setScene(scene);
824 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
826 qDebug() << __PRETTY_FUNCTION__;
828 if (visibility && m_loggedIn) {
829 m_ownLocationCrosshair->show();
830 m_drawOwnLocationCrosshair = true;
831 drawOwnLocationCrosshair(m_viewPortSize);
833 m_ownLocationCrosshair->hide();
834 m_drawOwnLocationCrosshair = false;
838 void MainWindow::settingsDialogAccepted()
840 qDebug() << __PRETTY_FUNCTION__;
842 readAutomaticLocationUpdateSettings();
845 void MainWindow::setUsername(const QString &username)
847 qDebug() << __PRETTY_FUNCTION__;
852 void MainWindow::setViewPortSize(const QSize &size)
854 qDebug() << __PRETTY_FUNCTION__;
856 m_viewPortSize = size;
859 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
861 qDebug() << __PRETTY_FUNCTION__;
863 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
864 tr("Automatic location update"), text,
865 QMessageBox::Yes | QMessageBox::No |
866 QMessageBox::Cancel, this);
867 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
868 this, SLOT(automaticUpdateDialogFinished(int)));
870 m_automaticUpdateLocationDialog->show();
873 void MainWindow::toggleFullScreen()
875 qDebug() << __PRETTY_FUNCTION__;
877 if(windowState() == Qt::WindowNoState)
883 void MainWindow::showErrorInformationBox()
885 qDebug() << __PRETTY_FUNCTION__;
887 if(m_error_queue.count()) {
889 QDialog *dialog = m_error_queue.first();
890 connect(dialog, SIGNAL(finished(int)),
891 this, SLOT(errorDialogFinished(int)));
896 void MainWindow::showInformationBox()
898 qDebug() << __PRETTY_FUNCTION__;
900 if(m_queue.count()) {
901 QDialog *dialog = m_queue.first();
902 connect(dialog, SIGNAL(finished(int)),
903 this, SLOT(dialogFinished(int)));
908 void MainWindow::showPanels()
910 qDebug() << __PRETTY_FUNCTION__;
912 drawFullScreenButton(m_viewPortSize);
915 if(!m_friendsListPanel->isVisible()) {
916 m_friendsListPanel->show();
917 m_friendsListPanelSidebar->show();
920 if(!m_userPanel->isVisible()) {
922 m_userPanelSidebar->show();
927 void MainWindow::startLocationSearch()
929 qDebug() << __PRETTY_FUNCTION__;
931 SearchDialog *searchDialog = new SearchDialog();
932 queueDialog(searchDialog);
935 void MainWindow::startLoginProcess()
937 qDebug() << __PRETTY_FUNCTION__;
939 LoginDialog *loginDialog = new LoginDialog();
941 emit fetchUsernameFromSettings();
943 loginDialog->clearTextFields();
945 if(!m_email.isEmpty())
946 loginDialog->setEmailField(m_email);
948 queueDialog(loginDialog);
951 void MainWindow::toggleProgressIndicator(bool value)
953 qDebug() << __PRETTY_FUNCTION__;
957 m_progressIndicatorCount++;
958 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
960 if(m_progressIndicatorCount > 0)
961 m_progressIndicatorCount--;
963 if(m_progressIndicatorCount == 0)
964 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
968 #endif // Q_WS_MAEMO_5
971 void MainWindow::updateItemVisibility()
973 qDebug() << __PRETTY_FUNCTION__;
977 if(!m_gpsToggleAct->isChecked())
978 setOwnLocationCrosshairVisibility(true);
980 m_friendsListPanel->closePanel();
981 m_friendsListPanel->hide();
982 m_friendsListPanelSidebar->hide();
983 m_userPanel->closePanel();
985 m_userPanelSidebar->hide();
986 setOwnLocationCrosshairVisibility(false);
990 const QString MainWindow::username()
992 qDebug() << __PRETTY_FUNCTION__;
997 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
999 qDebug() << __PRETTY_FUNCTION__;
1001 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1002 // qwebview starts to load a new page while the current page loading is not finished
1003 if(reply->error() != QNetworkReply::OperationCanceledError &&
1004 reply->error() != QNetworkReply::NoError) {
1005 emit error(ErrorContext::NETWORK, reply->error());