2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Henri Lampela - henri.lampela@ixonos.com
6 Kaj Wallin - kaj.wallin@ixonos.com
7 Jussi Laitinen - jussi.laitinen@ixonos.com
8 Sami Rämö - sami.ramo@ixonos.com
9 Ville Tiensuu - ville.tiensuu@ixonos.com
10 Katri Kaikkonen - katri.kaikkonen@ixonos.com
12 Situare is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 version 2 as published by the Free Software Foundation.
16 Situare is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with Situare; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
29 #include <QtAlgorithms>
31 #include "facebookservice/facebookauthentication.h"
32 #include "map/mapcommon.h"
33 #include "map/mapview.h"
36 #include "friendlistpanel.h"
37 #include "fullscreenbutton.h"
38 #include "logindialog.h"
40 #include "panelcommon.h"
41 #include "tabbedpanel.h"
42 #include "searchdialog.h"
43 #include "settingsdialog.h"
44 #include "userinfopanel.h"
45 #include "zoombuttonpanel.h"
46 #include "indicatorbuttonpanel.h"
48 #include "mainwindow.h"
50 // These MUST BE HERE, compiling for Maemo fails if moved
52 #include <QtMaemo5/QMaemo5InformationBox>
53 #include <QtGui/QX11Info>
54 #include <X11/Xatom.h>
56 #endif // Q_WS_MAEMO_5
58 MainWindow::MainWindow(QWidget *parent)
59 : QMainWindow(parent),
63 m_progressIndicatorCount(0),
64 m_ownLocationCrosshair(0),
68 m_fullScreenButton(0),
73 qDebug() << __PRETTY_FUNCTION__;
78 QHBoxLayout *layout = new QHBoxLayout;
79 layout->addWidget(m_mapView);
81 layout->setSpacing(0);
83 setCentralWidget(new QWidget());
84 centralWidget()->setLayout(layout);
89 setWindowTitle(tr("Situare"));
91 // set stacking order of widgets
92 m_zoomButtonPanel->stackUnder(m_tabbedPanel);
93 if(m_fullScreenButton) {
94 m_fullScreenButton->stackUnder(m_zoomButtonPanel);
95 m_osmLicense->stackUnder(m_fullScreenButton);
97 m_osmLicense->stackUnder(m_zoomButtonPanel);
99 m_ownLocationCrosshair->stackUnder(m_osmLicense);
100 m_indicatorButtonPanel->stackUnder(m_ownLocationCrosshair);
101 m_mapScale->stackUnder(m_indicatorButtonPanel);
102 m_mapView->stackUnder(m_mapScale);
106 // Set default screen size
107 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
109 setAttribute(Qt::WA_Maemo5StackedWindow);
113 MainWindow::~MainWindow()
115 qDebug() << __PRETTY_FUNCTION__;
122 qDeleteAll(m_queue.begin(), m_queue.end());
125 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
126 m_error_queue.clear();
129 void MainWindow::automaticUpdateDialogFinished(int result)
131 qDebug() << __PRETTY_FUNCTION__;
133 if (result == QMessageBox::Yes) {
134 readAutomaticLocationUpdateSettings();
136 QSettings settings(DIRECTORY_NAME, FILE_NAME);
137 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
138 readAutomaticLocationUpdateSettings();
141 m_automaticUpdateLocationDialog->deleteLater();
144 void MainWindow::buildFullScreenButton()
146 qDebug() << __PRETTY_FUNCTION__;
148 m_fullScreenButton = new FullScreenButton(this);
149 connect(m_fullScreenButton, SIGNAL(clicked()),
150 this, SLOT(toggleFullScreen()));
151 #endif // Q_WS_MAEMO_5
154 void MainWindow::buildFriendListPanel()
156 qDebug() << __PRETTY_FUNCTION__;
158 m_friendsListPanel = new FriendListPanel(this);
160 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
161 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
163 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
164 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
166 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
167 this, SIGNAL(findFriend(GeoCoordinate)));
169 connect(this, SIGNAL(friendImageReady(User*)),
170 m_friendsListPanel, SLOT(friendImageReady(User*)));
173 void MainWindow::buildIndicatorButtonPanel()
175 qDebug() << __PRETTY_FUNCTION__;
177 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
179 connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
180 this, SIGNAL(autoCenteringTriggered(bool)));
182 connect(m_mapView, SIGNAL(viewResized(QSize)),
183 m_indicatorButtonPanel, SLOT(screenResized(QSize)));
185 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
186 m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
188 connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
189 this, SIGNAL(draggingModeTriggered()));
192 void MainWindow::buildInformationBox(const QString &message, bool modal)
194 qDebug() << __PRETTY_FUNCTION__;
196 QString errorMessage = message;
200 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
203 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
204 // extra line changes are needed to make error notes broader
205 errorMessage.prepend("\n");
206 errorMessage.append("\n");
208 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
210 QLabel *label = new QLabel(msgBox);
211 label->setAlignment(Qt::AlignCenter);
212 label->setText(errorMessage);
213 msgBox->setWidget(label);
215 QMessageBox *msgBox = new QMessageBox(this);
216 msgBox->button(QMessageBox::Ok);
217 msgBox->setText(errorMessage);
218 msgBox->setModal(modal);
224 void MainWindow::buildManualLocationCrosshair()
226 qDebug() << __PRETTY_FUNCTION__;
228 m_ownLocationCrosshair = new QLabel(this);
229 QPixmap crosshairImage(":/res/images/sight.png");
230 m_ownLocationCrosshair->setPixmap(crosshairImage);
231 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
232 m_ownLocationCrosshair->hide();
233 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
235 connect(m_mapView, SIGNAL(viewResized(QSize)),
236 this, SLOT(drawOwnLocationCrosshair(QSize)));
239 void MainWindow::buildMap()
241 qDebug() << __PRETTY_FUNCTION__;
243 m_mapView = new MapView(this);
245 buildZoomButtonPanel();
247 buildManualLocationCrosshair();
248 buildFullScreenButton();
249 buildIndicatorButtonPanel();
252 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
253 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
255 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
256 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
258 connect(m_mapView, SIGNAL(viewResized(QSize)),
259 this, SIGNAL(mapViewResized(QSize)));
261 connect(m_mapView, SIGNAL(viewResized(QSize)),
262 this, SLOT(drawFullScreenButton(QSize)));
264 connect(m_mapView, SIGNAL(viewResized(QSize)),
265 this, SLOT(drawMapScale(QSize)));
267 connect(m_mapView, SIGNAL(viewResized(QSize)),
268 this, SLOT(setViewPortSize(QSize)));
270 connect(this, SIGNAL(zoomLevelChanged(int)),
271 m_mapView, SLOT(setZoomLevel(int)));
273 connect(m_mapView, SIGNAL(viewZoomFinished()),
274 this, SIGNAL(viewZoomFinished()));
276 connect(m_mapView, SIGNAL(zoomIn()),
277 this, SIGNAL(zoomIn()));
280 void MainWindow::buildMapScale()
282 m_mapScale = new MapScale(this);
283 connect(this, SIGNAL(newMapResolution(qreal)),
284 m_mapScale, SLOT(updateMapResolution(qreal)));
287 void MainWindow::buildOsmLicense()
289 qDebug() << __PRETTY_FUNCTION__;
291 m_osmLicense = new QLabel(this);
292 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
293 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
294 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
295 m_osmLicense->setFont(QFont("Nokia Sans", 9));
296 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
297 m_osmLicense->fontMetrics().height());
299 connect(m_mapView, SIGNAL(viewResized(QSize)),
300 this, SLOT(drawOsmLicense(QSize)));
303 void MainWindow::buildPanels()
305 qDebug() << __PRETTY_FUNCTION__;
307 buildUserInfoPanel();
308 buildFriendListPanel();
310 m_tabbedPanel = new TabbedPanel(this);
311 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png"));
312 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png"));
314 connect(m_tabbedPanel, SIGNAL(panelOpened()),
315 m_friendsListPanel, SLOT(clearFriendListFilter()));
317 connect(m_mapView, SIGNAL(viewResized(QSize)),
318 m_tabbedPanel, SLOT(resizePanel(QSize)));
321 void MainWindow::buildUserInfoPanel()
323 qDebug() << __PRETTY_FUNCTION__;
325 m_userInfoPanel = new UserInfoPanel(this);
327 connect(this, SIGNAL(userLocationReady(User*)),
328 m_userInfoPanel, SLOT(userDataReceived(User*)));
330 connect(this, SIGNAL(reverseGeoReady(QString)),
331 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
333 connect(this, SIGNAL(clearUpdateLocationDialogData()),
334 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
336 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
337 this, SIGNAL(findUser(GeoCoordinate)));
339 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
340 this, SIGNAL(requestReverseGeo()));
342 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
343 this, SIGNAL(statusUpdate(QString,bool)));
345 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
346 this, SIGNAL(refreshUserData()));
348 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
349 this, SLOT(buildInformationBox(QString, bool)));
352 void MainWindow::buildWebView()
354 qDebug() << __PRETTY_FUNCTION__;
357 m_webView = new QWebView;
360 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
362 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
364 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
365 this, SLOT(webViewRequestFinished(QNetworkReply*)));
366 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
367 this, SIGNAL(updateCredentials(QUrl)));
368 connect(m_webView, SIGNAL(loadFinished(bool)),
369 this, SLOT(loadDone(bool)));
375 void MainWindow::buildZoomButtonPanel()
377 qDebug() << __PRETTY_FUNCTION__;
379 m_zoomButtonPanel = new ZoomButtonPanel(this);
381 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
382 this, SIGNAL(zoomIn()));
384 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
385 this, SIGNAL(zoomOut()));
387 connect(this, SIGNAL(zoomLevelChanged(int)),
388 m_zoomButtonPanel, SLOT(resetButtons()));
390 connect(this, SIGNAL(maxZoomLevelReached()),
391 m_zoomButtonPanel, SLOT(disableZoomInButton()));
393 connect(this, SIGNAL(minZoomLevelReached()),
394 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
396 connect(m_mapView, SIGNAL(viewResized(QSize)),
397 m_zoomButtonPanel, SLOT(screenResized(QSize)));
399 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
400 this, SIGNAL(draggingModeTriggered()));
403 void MainWindow::clearCookieJar()
405 qDebug() << __PRETTY_FUNCTION__;
412 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
414 QList<QNetworkCookie> emptyList;
417 m_cookieJar->setAllCookies(emptyList);
418 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
421 void MainWindow::createMenus()
423 qDebug() << __PRETTY_FUNCTION__;
426 m_loginAct = new QAction(tr("Login"), this);
427 connect(m_loginAct, SIGNAL(triggered()),
428 this, SIGNAL(loginActionPressed()));
431 m_toSettingsAct = new QAction(tr("Settings"), this);
432 connect(m_toSettingsAct, SIGNAL(triggered()),
433 this, SLOT(openSettingsDialog()));
436 m_gpsToggleAct = new QAction(tr("GPS"), this);
437 m_gpsToggleAct->setCheckable(true);
439 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
440 this, SIGNAL(gpsTriggered(bool)));
442 /// @todo remove when not needed!
443 m_searchLocationAct = new QAction(tr("Location search"), this);
444 connect(m_searchLocationAct, SIGNAL(triggered()),
445 this, SLOT(startLocationSearch()));
447 // build the actual menu
448 m_viewMenu = menuBar()->addMenu(tr("Main"));
449 m_viewMenu->addAction(m_loginAct);
450 m_viewMenu->addAction(m_toSettingsAct);
451 m_viewMenu->addAction(m_gpsToggleAct);
452 m_viewMenu->addAction(m_searchLocationAct); /// @todo remove when not needed!
453 m_viewMenu->setObjectName(tr("Menu"));
456 void MainWindow::dialogFinished(int status)
458 qDebug() << __PRETTY_FUNCTION__;
460 QDialog *dialog = m_queue.takeFirst();
461 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
462 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
466 loginDialog->userInput(m_email, m_password);
468 QStringList urlParts;
469 urlParts.append(FACEBOOK_LOGINBASE);
470 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
471 urlParts.append(INTERVAL1);
472 urlParts.append(SITUARE_LOGIN_SUCCESS);
473 urlParts.append(INTERVAL2);
474 urlParts.append(SITUARE_LOGIN_FAILURE);
475 urlParts.append(FACEBOOK_LOGIN_ENDING);
477 emit saveUsername(m_email);
479 m_webView->load(QUrl(urlParts.join(EMPTY)));
480 toggleProgressIndicator(true);
482 emit cancelLoginProcess();
484 } else if(searchDialog) {
486 emit searchForLocation(searchDialog->input());
490 dialog->deleteLater();
492 if(!m_error_queue.isEmpty() && m_errorShown == false) {
493 showErrorInformationBox();
495 if(!m_queue.isEmpty()) {
496 showInformationBox();
501 void MainWindow::drawFullScreenButton(const QSize &size)
503 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
505 if(m_fullScreenButton)
506 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
507 size.height() - m_fullScreenButton->size().height());
510 void MainWindow::drawMapScale(const QSize &size)
512 qDebug() << __PRETTY_FUNCTION__;
514 const int LEFT_SCALE_MARGIN = 10;
515 const int BOTTOM_SCALE_MARGIN = 2;
516 // qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
518 m_mapScale->move(LEFT_SCALE_MARGIN,
519 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
522 void MainWindow::drawOsmLicense(const QSize &size)
524 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
526 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
528 size.height() - m_osmLicense->fontMetrics().height());
531 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
533 qDebug() << __PRETTY_FUNCTION__;
535 if (m_ownLocationCrosshair != 0) {
536 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
537 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
541 void MainWindow::errorDialogFinished(int status)
543 qDebug() << __PRETTY_FUNCTION__;
546 QDialog *dialog = m_error_queue.takeFirst();
548 dialog->deleteLater();
549 m_errorShown = false;
551 if(!m_error_queue.isEmpty())
552 showErrorInformationBox();
553 else if(!m_queue.isEmpty())
554 showInformationBox();
557 void MainWindow::gpsTimeout()
559 qDebug() << __PRETTY_FUNCTION__;
561 buildInformationBox(tr("GPS timeout"));
564 void MainWindow::grabZoomKeys(bool grab)
566 qDebug() << __PRETTY_FUNCTION__;
569 // Can't grab keys unless we have a window id
573 unsigned long val = (grab) ? 1 : 0;
574 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
578 XChangeProperty (QX11Info::display(),
584 reinterpret_cast<unsigned char *>(&val),
588 #endif // Q_WS_MAEMO_5
591 void MainWindow::keyPressEvent(QKeyEvent* event)
593 qDebug() << __PRETTY_FUNCTION__;
595 switch (event->key()) {
606 QWidget::keyPressEvent(event);
609 void MainWindow::loadCookies()
611 qDebug() << __PRETTY_FUNCTION__;
613 QSettings settings(DIRECTORY_NAME, FILE_NAME);
615 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
617 if(!list.isEmpty()) {
618 QList<QNetworkCookie> cookieList;
619 for(int i=0;i<list.count();i++) {
620 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
624 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
626 m_cookieJar->setAllCookies(cookieList);
627 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
631 void MainWindow::loadDone(bool done)
633 qDebug() << __PRETTY_FUNCTION__;
635 // for the first time the login page is opened, we need to refresh it to get cookies working
643 QWebFrame* frame = m_webView->page()->currentFrame();
647 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
649 foreach (QWebElement element, emailCollection) {
650 element.setAttribute("value", m_email.toAscii());
653 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
654 foreach (QWebElement element, passwordCollection) {
655 element.setAttribute("value", m_password.toAscii());
657 // find connect button
658 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
659 foreach (QWebElement element, buttonCollection)
661 QPoint pos(element.geometry().center());
663 // send a mouse click event to the web page
664 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
666 QApplication::sendEvent(m_webView->page(), &event0);
667 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
669 QApplication::sendEvent(m_webView->page(), &event1);
675 void MainWindow::loggedIn(bool logged)
677 qDebug() << __PRETTY_FUNCTION__;
682 m_loginAct->setText(tr("Logout"));
688 m_loginAct->setText(tr("Login"));
690 updateItemVisibility();
693 void MainWindow::loginFailed()
695 qDebug() << __PRETTY_FUNCTION__;
701 bool MainWindow::loginState()
703 qDebug() << __PRETTY_FUNCTION__;
708 void MainWindow::loginUsingCookies()
710 qDebug() << __PRETTY_FUNCTION__;
712 toggleProgressIndicator(true);
717 QStringList urlParts;
718 urlParts.append(FACEBOOK_LOGINBASE);
719 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
720 urlParts.append(INTERVAL1);
721 urlParts.append(SITUARE_LOGIN_SUCCESS);
722 urlParts.append(INTERVAL2);
723 urlParts.append(SITUARE_LOGIN_FAILURE);
724 urlParts.append(FACEBOOK_LOGIN_ENDING);
726 m_webView->load(QUrl(urlParts.join(EMPTY)));
730 void MainWindow::openSettingsDialog()
732 qDebug() << __PRETTY_FUNCTION__;
734 SettingsDialog *settingsDialog = new SettingsDialog(this);
735 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
736 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
738 settingsDialog->show();
741 void MainWindow::readAutomaticLocationUpdateSettings()
743 qDebug() << __PRETTY_FUNCTION__;
745 QSettings settings(DIRECTORY_NAME, FILE_NAME);
746 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
747 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
750 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
752 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
754 emit enableAutomaticLocationUpdate(false);
758 void MainWindow::queueDialog(QDialog *dialog)
760 qDebug() << __PRETTY_FUNCTION__;
762 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
763 if(dialog->isModal()) {
764 m_error_queue.append(dialog);
766 m_queue.append(dialog);
769 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
770 if(m_error_queue.count() == 1 && m_errorShown == false)
771 showErrorInformationBox();
772 else if(m_queue.count() == 1 && m_errorShown == false)
773 showInformationBox();
776 void MainWindow::saveCookies()
778 qDebug() << __PRETTY_FUNCTION__;
781 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
783 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
786 for(int i=0;i<cookieList.count();i++) {
787 QNetworkCookie cookie = cookieList.at(i);
788 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
789 list.append(QString(byteArray));
791 list.removeDuplicates();
793 QSettings settings(DIRECTORY_NAME, FILE_NAME);
794 settings.setValue(COOKIES, list);
797 void MainWindow::setGPSButtonEnabled(bool enabled)
799 qDebug() << __PRETTY_FUNCTION__;
801 m_gpsToggleAct->setChecked(enabled);
804 void MainWindow::setIndicatorButtonEnabled(bool enabled)
806 qDebug() << __PRETTY_FUNCTION__;
808 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
811 void MainWindow::setMapViewScene(QGraphicsScene *scene)
813 qDebug() << __PRETTY_FUNCTION__;
815 m_mapView->setScene(scene);
818 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
820 qDebug() << __PRETTY_FUNCTION__;
823 m_ownLocationCrosshair->show();
824 drawOwnLocationCrosshair(m_viewPortSize);
826 m_ownLocationCrosshair->hide();
830 void MainWindow::settingsDialogAccepted()
832 qDebug() << __PRETTY_FUNCTION__;
834 readAutomaticLocationUpdateSettings();
837 void MainWindow::setUsername(const QString &username)
839 qDebug() << __PRETTY_FUNCTION__;
844 void MainWindow::setViewPortSize(const QSize &size)
846 qDebug() << __PRETTY_FUNCTION__;
848 m_viewPortSize = size;
851 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
853 qDebug() << __PRETTY_FUNCTION__;
855 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
856 tr("Automatic location update"), text,
857 QMessageBox::Yes | QMessageBox::No |
858 QMessageBox::Cancel, this);
859 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
860 this, SLOT(automaticUpdateDialogFinished(int)));
862 m_automaticUpdateLocationDialog->show();
865 void MainWindow::toggleFullScreen()
867 qDebug() << __PRETTY_FUNCTION__;
869 if(windowState() == Qt::WindowNoState)
875 void MainWindow::showErrorInformationBox()
877 qDebug() << __PRETTY_FUNCTION__;
879 if(m_error_queue.count()) {
881 QDialog *dialog = m_error_queue.first();
882 connect(dialog, SIGNAL(finished(int)),
883 this, SLOT(errorDialogFinished(int)));
888 void MainWindow::showInformationBox()
890 qDebug() << __PRETTY_FUNCTION__;
892 if(m_queue.count()) {
893 QDialog *dialog = m_queue.first();
894 connect(dialog, SIGNAL(finished(int)),
895 this, SLOT(dialogFinished(int)));
900 void MainWindow::showPanels()
902 qDebug() << __PRETTY_FUNCTION__;
904 drawFullScreenButton(m_viewPortSize);
907 // if(!m_friendsListPanel->isVisible()) {
908 // m_friendsListPanel->show();
909 // m_friendsListPanelSidebar->show();
912 // if(!m_userPanel->isVisible()) {
913 // m_userPanel->show();
914 // m_userPanelSidebar->show();
919 void MainWindow::startLocationSearch()
921 qDebug() << __PRETTY_FUNCTION__;
923 SearchDialog *searchDialog = new SearchDialog();
924 queueDialog(searchDialog);
927 void MainWindow::startLoginProcess()
929 qDebug() << __PRETTY_FUNCTION__;
931 LoginDialog *loginDialog = new LoginDialog();
933 emit fetchUsernameFromSettings();
935 loginDialog->clearTextFields();
937 if(!m_email.isEmpty())
938 loginDialog->setEmailField(m_email);
940 queueDialog(loginDialog);
943 void MainWindow::toggleProgressIndicator(bool value)
945 qDebug() << __PRETTY_FUNCTION__;
949 m_progressIndicatorCount++;
950 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
952 if(m_progressIndicatorCount > 0)
953 m_progressIndicatorCount--;
955 if(m_progressIndicatorCount == 0)
956 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
960 #endif // Q_WS_MAEMO_5
963 void MainWindow::updateItemVisibility()
965 qDebug() << __PRETTY_FUNCTION__;
968 // m_friendsListPanel->closePanel();
969 // m_friendsListPanel->hide();
970 // m_friendsListPanelSidebar->hide();
972 // m_userPanel->closePanel();
973 // m_userPanel->hide();
974 // m_userPanelSidebar->hide();
978 const QString MainWindow::username()
980 qDebug() << __PRETTY_FUNCTION__;
985 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
987 qDebug() << __PRETTY_FUNCTION__;
989 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
990 // qwebview starts to load a new page while the current page loading is not finished
991 if(reply->error() != QNetworkReply::OperationCanceledError &&
992 reply->error() != QNetworkReply::NoError) {
993 emit error(ErrorContext::NETWORK, reply->error());