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),
59 m_progressIndicatorCount(0),
60 m_ownLocationCrosshair(0),
64 m_fullScreenButton(0),
69 qDebug() << __PRETTY_FUNCTION__;
74 QHBoxLayout *layout = new QHBoxLayout;
75 layout->addWidget(m_mapView);
77 layout->setSpacing(0);
79 setCentralWidget(new QWidget());
80 centralWidget()->setLayout(layout);
82 buildFriendListPanel();
86 setWindowTitle(tr("Situare"));
88 // set stacking order of widgets
89 m_zoomButtonPanel->stackUnder(m_userPanel);
90 if(m_fullScreenButton) {
91 m_fullScreenButton->stackUnder(m_zoomButtonPanel);
92 m_osmLicense->stackUnder(m_fullScreenButton);
94 m_osmLicense->stackUnder(m_zoomButtonPanel);
96 m_ownLocationCrosshair->stackUnder(m_osmLicense);
97 m_indicatorButton->stackUnder(m_ownLocationCrosshair);
98 m_mapScale->stackUnder(m_indicatorButton);
99 m_mapView->stackUnder(m_mapScale);
103 // Set default screen size
104 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
106 setAttribute(Qt::WA_Maemo5StackedWindow);
110 MainWindow::~MainWindow()
112 qDebug() << __PRETTY_FUNCTION__;
119 qDeleteAll(m_queue.begin(), m_queue.end());
122 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
123 m_error_queue.clear();
126 void MainWindow::automaticUpdateDialogFinished(int result)
128 qDebug() << __PRETTY_FUNCTION__;
130 if (result == QMessageBox::Yes) {
131 readAutomaticLocationUpdateSettings();
133 QSettings settings(DIRECTORY_NAME, FILE_NAME);
134 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
135 readAutomaticLocationUpdateSettings();
138 m_automaticUpdateLocationDialog->deleteLater();
141 void MainWindow::buildFullScreenButton()
143 qDebug() << __PRETTY_FUNCTION__;
145 m_fullScreenButton = new FullScreenButton(this);
146 connect(m_fullScreenButton, SIGNAL(clicked()),
147 this, SLOT(toggleFullScreen()));
148 #endif // Q_WS_MAEMO_5
151 void MainWindow::buildFriendListPanel()
153 qDebug() << __PRETTY_FUNCTION__;
155 m_friendsListPanel = new FriendListPanel(this);
157 m_friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
159 m_friendsListPanel->stackUnder(m_friendsListPanelSidebar);
161 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
162 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
164 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
165 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
167 connect(m_mapView, SIGNAL(viewResized(QSize)),
168 m_friendsListPanel, SLOT(resizePanel(QSize)));
170 connect(m_mapView, SIGNAL(viewResized(QSize)),
171 m_friendsListPanelSidebar, SLOT(resizeSideBar(QSize)));
173 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
174 this, SIGNAL(findFriend(GeoCoordinate)));
176 connect(this, SIGNAL(friendImageReady(User*)),
177 m_friendsListPanel, SLOT(friendImageReady(User*)));
180 void MainWindow::buildIndicatorButton()
182 qDebug() << __PRETTY_FUNCTION__;
184 m_indicatorButton = new IndicatorButton(this);
186 connect(m_indicatorButton, SIGNAL(autoCenteringTriggered(bool)),
187 this, SIGNAL(autoCenteringTriggered(bool)));
189 connect(m_mapView, SIGNAL(viewResized(QSize)),
190 m_indicatorButton, SLOT(screenResized(QSize)));
192 connect(m_indicatorButton, SIGNAL(draggingModeTriggered()),
193 this, SIGNAL(draggingModeTriggered()));
196 void MainWindow::buildInformationBox(const QString &message, bool modal)
198 qDebug() << __PRETTY_FUNCTION__;
200 QString errorMessage = message;
204 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
207 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
208 // extra line changes are needed to make error notes broader
209 errorMessage.prepend("\n");
210 errorMessage.append("\n");
212 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
214 QLabel *label = new QLabel(msgBox);
215 label->setAlignment(Qt::AlignCenter);
216 label->setText(errorMessage);
217 msgBox->setWidget(label);
219 QMessageBox *msgBox = new QMessageBox(this);
220 msgBox->button(QMessageBox::Ok);
221 msgBox->setText(errorMessage);
222 msgBox->setModal(modal);
228 void MainWindow::buildManualLocationCrosshair()
230 qDebug() << __PRETTY_FUNCTION__;
232 m_ownLocationCrosshair = new QLabel(this);
233 QPixmap crosshairImage(":/res/images/sight.png");
234 m_ownLocationCrosshair->setPixmap(crosshairImage);
235 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
236 m_ownLocationCrosshair->hide();
237 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
239 connect(m_mapView, SIGNAL(viewResized(QSize)),
240 this, SLOT(drawOwnLocationCrosshair(QSize)));
243 void MainWindow::buildMap()
245 qDebug() << __PRETTY_FUNCTION__;
247 m_mapView = new MapView(this);
249 buildZoomButtonPanel();
251 buildManualLocationCrosshair();
252 buildFullScreenButton();
253 buildIndicatorButton();
256 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
257 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
259 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
260 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
262 connect(m_mapView, SIGNAL(viewResized(QSize)),
263 this, SIGNAL(mapViewResized(QSize)));
265 connect(m_mapView, SIGNAL(viewResized(QSize)),
266 this, SLOT(drawFullScreenButton(QSize)));
268 connect(m_mapView, SIGNAL(viewResized(QSize)),
269 this, SLOT(drawMapScale(QSize)));
271 connect(m_mapView, SIGNAL(viewResized(QSize)),
272 this, SLOT(setViewPortSize(QSize)));
274 connect(this, SIGNAL(zoomLevelChanged(int)),
275 m_mapView, SLOT(setZoomLevel(int)));
277 connect(m_mapView, SIGNAL(viewZoomFinished()),
278 this, SIGNAL(viewZoomFinished()));
280 connect(m_mapView, SIGNAL(zoomIn()),
281 this, SIGNAL(zoomIn()));
284 void MainWindow::buildMapScale()
286 m_mapScale = new MapScale(this);
287 connect(this, SIGNAL(newMapResolution(qreal)),
288 m_mapScale, SLOT(updateMapResolution(qreal)));
291 void MainWindow::buildOsmLicense()
293 qDebug() << __PRETTY_FUNCTION__;
295 m_osmLicense = new QLabel(this);
296 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
297 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
298 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
299 m_osmLicense->setFont(QFont("Nokia Sans", 9));
300 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
301 m_osmLicense->fontMetrics().height());
303 connect(m_mapView, SIGNAL(viewResized(QSize)),
304 this, SLOT(drawOsmLicense(QSize)));
307 void MainWindow::buildUserInfoPanel()
309 qDebug() << __PRETTY_FUNCTION__;
311 m_userPanel = new UserInfoPanel(this);
313 m_userPanelSidebar = new PanelSideBar(this, LEFT);
315 m_userPanelSidebar->stackUnder(m_friendsListPanel);
316 m_userPanel->stackUnder(m_userPanelSidebar);
318 connect(this, SIGNAL(userLocationReady(User*)),
319 m_userPanel, SLOT(userDataReceived(User*)));
321 connect(this, SIGNAL(reverseGeoReady(QString)),
322 m_userPanel, SIGNAL(reverseGeoReady(QString)));
324 connect(this, SIGNAL(clearUpdateLocationDialogData()),
325 m_userPanel, SIGNAL(clearUpdateLocationDialogData()));
327 connect(m_mapView, SIGNAL(viewResized(QSize)),
328 m_userPanel, SLOT(resizePanel(QSize)));
330 connect(m_mapView, SIGNAL(viewResized(QSize)),
331 m_userPanelSidebar, SLOT(resizeSideBar(QSize)));
333 connect(m_userPanel, SIGNAL(findUser(GeoCoordinate)),
334 this, SIGNAL(findUser(GeoCoordinate)));
336 connect(m_userPanel, SIGNAL(requestReverseGeo()),
337 this, SIGNAL(requestReverseGeo()));
339 connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
340 this, SIGNAL(statusUpdate(QString,bool)));
342 connect(m_userPanel, SIGNAL(refreshUserData()),
343 this, SIGNAL(refreshUserData()));
345 connect(m_userPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
346 this, SLOT(buildInformationBox(QString, bool)));
349 void MainWindow::buildWebView()
351 qDebug() << __PRETTY_FUNCTION__;
354 m_webView = new QWebView;
357 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
359 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
361 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
362 this, SLOT(webViewRequestFinished(QNetworkReply*)));
363 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
364 this, SIGNAL(updateCredentials(QUrl)));
365 connect(m_webView, SIGNAL(loadFinished(bool)),
366 this, SLOT(loadDone(bool)));
372 void MainWindow::buildZoomButtonPanel()
374 qDebug() << __PRETTY_FUNCTION__;
376 m_zoomButtonPanel = new ZoomButtonPanel(this);
378 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
379 this, SIGNAL(zoomIn()));
381 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
382 this, SIGNAL(zoomOut()));
384 connect(this, SIGNAL(zoomLevelChanged(int)),
385 m_zoomButtonPanel, SLOT(resetButtons()));
387 connect(this, SIGNAL(maxZoomLevelReached()),
388 m_zoomButtonPanel, SLOT(disableZoomInButton()));
390 connect(this, SIGNAL(minZoomLevelReached()),
391 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
393 connect(m_mapView, SIGNAL(viewResized(QSize)),
394 m_zoomButtonPanel, SLOT(screenResized(QSize)));
396 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
397 this, SIGNAL(draggingModeTriggered()));
400 void MainWindow::clearCookieJar()
402 qDebug() << __PRETTY_FUNCTION__;
409 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
411 QList<QNetworkCookie> emptyList;
414 m_cookieJar->setAllCookies(emptyList);
415 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
418 void MainWindow::createMenus()
420 qDebug() << __PRETTY_FUNCTION__;
423 m_loginAct = new QAction(tr("Login"), this);
424 connect(m_loginAct, SIGNAL(triggered()),
425 this, SIGNAL(loginActionPressed()));
428 m_toSettingsAct = new QAction(tr("Settings"), this);
429 connect(m_toSettingsAct, SIGNAL(triggered()),
430 this, SLOT(openSettingsDialog()));
433 m_gpsToggleAct = new QAction(tr("GPS"), this);
434 m_gpsToggleAct->setCheckable(true);
436 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
437 this, SIGNAL(gpsTriggered(bool)));
439 /// @todo remove when not needed!
440 m_searchLocationAct = new QAction(tr("Location search"), this);
441 connect(m_searchLocationAct, SIGNAL(triggered()),
442 this, SLOT(startLocationSearch()));
444 // build the actual menu
445 m_viewMenu = menuBar()->addMenu(tr("Main"));
446 m_viewMenu->addAction(m_loginAct);
447 m_viewMenu->addAction(m_toSettingsAct);
448 m_viewMenu->addAction(m_gpsToggleAct);
449 m_viewMenu->addAction(m_searchLocationAct); /// @todo remove when not needed!
450 m_viewMenu->setObjectName(tr("Menu"));
453 void MainWindow::dialogFinished(int status)
455 qDebug() << __PRETTY_FUNCTION__;
457 QDialog *dialog = m_queue.takeFirst();
458 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
459 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
463 loginDialog->userInput(m_email, m_password);
465 QStringList urlParts;
466 urlParts.append(FACEBOOK_LOGINBASE);
467 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
468 urlParts.append(INTERVAL1);
469 urlParts.append(SITUARE_LOGIN_SUCCESS);
470 urlParts.append(INTERVAL2);
471 urlParts.append(SITUARE_LOGIN_FAILURE);
472 urlParts.append(FACEBOOK_LOGIN_ENDING);
474 emit saveUsername(m_email);
476 m_webView->load(QUrl(urlParts.join(EMPTY)));
477 toggleProgressIndicator(true);
479 emit cancelLoginProcess();
481 } else if(searchDialog) {
483 emit searchForLocation(searchDialog->input());
487 dialog->deleteLater();
489 if(!m_error_queue.isEmpty() && m_errorShown == false) {
490 showErrorInformationBox();
492 if(!m_queue.isEmpty()) {
493 showInformationBox();
498 void MainWindow::drawFullScreenButton(const QSize &size)
500 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
502 if(m_fullScreenButton) {
504 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width()
506 size.height() - m_fullScreenButton->size().height());
508 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
509 size.height() - m_fullScreenButton->size().height());
514 void MainWindow::drawMapScale(const QSize &size)
516 qDebug() << __PRETTY_FUNCTION__;
518 const int LEFT_SCALE_MARGIN = 10;
519 const int BOTTOM_SCALE_MARGIN = 2;
520 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
522 m_mapScale->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
523 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
526 void MainWindow::drawOsmLicense(const QSize &size)
528 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
530 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
532 size.height() - m_osmLicense->fontMetrics().height());
535 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
537 qDebug() << __PRETTY_FUNCTION__;
539 if (m_ownLocationCrosshair != 0) {
540 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
541 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
545 void MainWindow::errorDialogFinished(int status)
547 qDebug() << __PRETTY_FUNCTION__;
550 QDialog *dialog = m_error_queue.takeFirst();
552 dialog->deleteLater();
553 m_errorShown = false;
555 if(!m_error_queue.isEmpty())
556 showErrorInformationBox();
557 else if(!m_queue.isEmpty())
558 showInformationBox();
561 void MainWindow::gpsTimeout()
563 qDebug() << __PRETTY_FUNCTION__;
565 buildInformationBox(tr("GPS timeout"));
568 void MainWindow::grabZoomKeys(bool grab)
570 qDebug() << __PRETTY_FUNCTION__;
573 // Can't grab keys unless we have a window id
577 unsigned long val = (grab) ? 1 : 0;
578 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
582 XChangeProperty (QX11Info::display(),
588 reinterpret_cast<unsigned char *>(&val),
592 #endif // Q_WS_MAEMO_5
595 void MainWindow::keyPressEvent(QKeyEvent* event)
597 qDebug() << __PRETTY_FUNCTION__;
599 switch (event->key()) {
610 QWidget::keyPressEvent(event);
613 void MainWindow::loadCookies()
615 qDebug() << __PRETTY_FUNCTION__;
617 QSettings settings(DIRECTORY_NAME, FILE_NAME);
619 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
621 if(!list.isEmpty()) {
622 QList<QNetworkCookie> cookieList;
623 for(int i=0;i<list.count();i++) {
624 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
628 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
630 m_cookieJar->setAllCookies(cookieList);
631 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
635 void MainWindow::loadDone(bool done)
637 qDebug() << __PRETTY_FUNCTION__;
639 // for the first time the login page is opened, we need to refresh it to get cookies working
647 QWebFrame* frame = m_webView->page()->currentFrame();
651 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
653 foreach (QWebElement element, emailCollection) {
654 element.setAttribute("value", m_email.toAscii());
657 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
658 foreach (QWebElement element, passwordCollection) {
659 element.setAttribute("value", m_password.toAscii());
661 // find connect button
662 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
663 foreach (QWebElement element, buttonCollection)
665 QPoint pos(element.geometry().center());
667 // send a mouse click event to the web page
668 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
670 QApplication::sendEvent(m_webView->page(), &event0);
671 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
673 QApplication::sendEvent(m_webView->page(), &event1);
679 void MainWindow::loggedIn(bool logged)
681 qDebug() << __PRETTY_FUNCTION__;
686 m_loginAct->setText(tr("Logout"));
692 m_loginAct->setText(tr("Login"));
694 updateItemVisibility();
697 void MainWindow::loginFailed()
699 qDebug() << __PRETTY_FUNCTION__;
705 bool MainWindow::loginState()
707 qDebug() << __PRETTY_FUNCTION__;
712 void MainWindow::loginUsingCookies()
714 qDebug() << __PRETTY_FUNCTION__;
716 toggleProgressIndicator(true);
721 QStringList urlParts;
722 urlParts.append(FACEBOOK_LOGINBASE);
723 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
724 urlParts.append(INTERVAL1);
725 urlParts.append(SITUARE_LOGIN_SUCCESS);
726 urlParts.append(INTERVAL2);
727 urlParts.append(SITUARE_LOGIN_FAILURE);
728 urlParts.append(FACEBOOK_LOGIN_ENDING);
730 m_webView->load(QUrl(urlParts.join(EMPTY)));
734 void MainWindow::openSettingsDialog()
736 qDebug() << __PRETTY_FUNCTION__;
738 SettingsDialog *settingsDialog = new SettingsDialog(this);
739 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
740 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
742 settingsDialog->show();
745 void MainWindow::readAutomaticLocationUpdateSettings()
747 qDebug() << __PRETTY_FUNCTION__;
749 QSettings settings(DIRECTORY_NAME, FILE_NAME);
750 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
751 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
754 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
756 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
758 emit enableAutomaticLocationUpdate(false);
762 void MainWindow::queueDialog(QDialog *dialog)
764 qDebug() << __PRETTY_FUNCTION__;
766 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
767 if(dialog->isModal()) {
768 m_error_queue.append(dialog);
770 m_queue.append(dialog);
773 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
774 if(m_error_queue.count() == 1 && m_errorShown == false)
775 showErrorInformationBox();
776 else if(m_queue.count() == 1 && m_errorShown == false)
777 showInformationBox();
780 void MainWindow::saveCookies()
782 qDebug() << __PRETTY_FUNCTION__;
785 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
787 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
790 for(int i=0;i<cookieList.count();i++) {
791 QNetworkCookie cookie = cookieList.at(i);
792 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
793 list.append(QString(byteArray));
795 list.removeDuplicates();
797 QSettings settings(DIRECTORY_NAME, FILE_NAME);
798 settings.setValue(COOKIES, list);
801 void MainWindow::setGPSButtonEnabled(bool enabled)
803 qDebug() << __PRETTY_FUNCTION__;
805 m_gpsToggleAct->setChecked(enabled);
808 void MainWindow::setIndicatorButtonEnabled(bool enabled)
810 qDebug() << __PRETTY_FUNCTION__;
812 m_indicatorButton->setChecked(enabled);
816 void MainWindow::setMapViewScene(QGraphicsScene *scene)
818 qDebug() << __PRETTY_FUNCTION__;
820 m_mapView->setScene(scene);
823 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
825 qDebug() << __PRETTY_FUNCTION__;
828 m_ownLocationCrosshair->show();
829 drawOwnLocationCrosshair(m_viewPortSize);
831 m_ownLocationCrosshair->hide();
835 void MainWindow::settingsDialogAccepted()
837 qDebug() << __PRETTY_FUNCTION__;
839 readAutomaticLocationUpdateSettings();
842 void MainWindow::setUsername(const QString &username)
844 qDebug() << __PRETTY_FUNCTION__;
849 void MainWindow::setViewPortSize(const QSize &size)
851 qDebug() << __PRETTY_FUNCTION__;
853 m_viewPortSize = size;
856 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
858 qDebug() << __PRETTY_FUNCTION__;
860 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
861 tr("Automatic location update"), text,
862 QMessageBox::Yes | QMessageBox::No |
863 QMessageBox::Cancel, this);
864 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
865 this, SLOT(automaticUpdateDialogFinished(int)));
867 m_automaticUpdateLocationDialog->show();
870 void MainWindow::toggleFullScreen()
872 qDebug() << __PRETTY_FUNCTION__;
874 if(windowState() == Qt::WindowNoState)
880 void MainWindow::showErrorInformationBox()
882 qDebug() << __PRETTY_FUNCTION__;
884 if(m_error_queue.count()) {
886 QDialog *dialog = m_error_queue.first();
887 connect(dialog, SIGNAL(finished(int)),
888 this, SLOT(errorDialogFinished(int)));
893 void MainWindow::showInformationBox()
895 qDebug() << __PRETTY_FUNCTION__;
897 if(m_queue.count()) {
898 QDialog *dialog = m_queue.first();
899 connect(dialog, SIGNAL(finished(int)),
900 this, SLOT(dialogFinished(int)));
905 void MainWindow::showPanels()
907 qDebug() << __PRETTY_FUNCTION__;
909 drawFullScreenButton(m_viewPortSize);
912 if(!m_friendsListPanel->isVisible()) {
913 m_friendsListPanel->show();
914 m_friendsListPanelSidebar->show();
917 if(!m_userPanel->isVisible()) {
919 m_userPanelSidebar->show();
924 void MainWindow::startLocationSearch()
926 qDebug() << __PRETTY_FUNCTION__;
928 SearchDialog *searchDialog = new SearchDialog();
929 queueDialog(searchDialog);
932 void MainWindow::startLoginProcess()
934 qDebug() << __PRETTY_FUNCTION__;
936 LoginDialog *loginDialog = new LoginDialog();
938 emit fetchUsernameFromSettings();
940 loginDialog->clearTextFields();
942 if(!m_email.isEmpty())
943 loginDialog->setEmailField(m_email);
945 queueDialog(loginDialog);
948 void MainWindow::toggleProgressIndicator(bool value)
950 qDebug() << __PRETTY_FUNCTION__;
954 m_progressIndicatorCount++;
955 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
957 if(m_progressIndicatorCount > 0)
958 m_progressIndicatorCount--;
960 if(m_progressIndicatorCount == 0)
961 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
965 #endif // Q_WS_MAEMO_5
968 void MainWindow::updateItemVisibility()
970 qDebug() << __PRETTY_FUNCTION__;
973 m_friendsListPanel->closePanel();
974 m_friendsListPanel->hide();
975 m_friendsListPanelSidebar->hide();
976 m_userPanel->closePanel();
978 m_userPanelSidebar->hide();
982 const QString MainWindow::username()
984 qDebug() << __PRETTY_FUNCTION__;
989 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
991 qDebug() << __PRETTY_FUNCTION__;
993 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
994 // qwebview starts to load a new page while the current page loading is not finished
995 if(reply->error() != QNetworkReply::OperationCanceledError &&
996 reply->error() != QNetworkReply::NoError) {
997 emit error(ErrorContext::NETWORK, reply->error());