2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Henri Lampela - henri.lampela@ixonos.com
6 Kaj Wallin - kaj.wallin@ixonos.com
7 Jussi Laitinen - jussi.laitinen@ixonos.com
8 Sami Rämö - sami.ramo@ixonos.com
9 Ville Tiensuu - ville.tiensuu@ixonos.com
10 Katri Kaikkonen - katri.kaikkonen@ixonos.com
12 Situare is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 version 2 as published by the Free Software Foundation.
16 Situare is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with Situare; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
28 #include <QApplication>
30 #include <QMessageBox>
31 #include <QtAlgorithms>
35 #include "facebookservice/facebookauthentication.h"
36 #include "map/mapcommon.h"
37 #include "map/mapview.h"
40 #include "friendlistpanel.h"
41 #include "fullscreenbutton.h"
42 #include "indicatorbuttonpanel.h"
43 #include "logindialog.h"
45 #include "panelcommon.h"
46 #include "tabbedpanel.h"
47 #include "searchdialog.h"
48 #include "settingsdialog.h"
49 #include "userinfopanel.h"
50 #include "zoombuttonpanel.h"
52 #include "mainwindow.h"
54 // These MUST BE HERE, compiling for Maemo fails if moved
56 #include <QtMaemo5/QMaemo5InformationBox>
57 #include <QtGui/QX11Info>
58 #include <X11/Xatom.h>
60 #endif // Q_WS_MAEMO_5
62 MainWindow::MainWindow(QWidget *parent)
63 : QMainWindow(parent),
67 m_progressIndicatorCount(0),
68 m_ownLocationCrosshair(0),
69 m_email(), ///< @todo WTF?!?!?!?
72 m_fullScreenButton(0),
73 m_indicatorButtonPanel(0),
77 qDebug() << __PRETTY_FUNCTION__;
82 QHBoxLayout *layout = new QHBoxLayout;
83 layout->addWidget(m_mapView);
85 layout->setSpacing(0);
87 setCentralWidget(new QWidget());
88 centralWidget()->setLayout(layout);
93 setWindowTitle(tr("Situare"));
95 // set stacking order of widgets
96 m_zoomButtonPanel->stackUnder(m_tabbedPanel);
97 if(m_fullScreenButton) {
98 m_fullScreenButton->stackUnder(m_zoomButtonPanel);
99 m_osmLicense->stackUnder(m_fullScreenButton);
101 m_osmLicense->stackUnder(m_zoomButtonPanel);
103 m_ownLocationCrosshair->stackUnder(m_osmLicense);
104 m_indicatorButtonPanel->stackUnder(m_ownLocationCrosshair);
105 m_mapScale->stackUnder(m_indicatorButtonPanel);
106 m_mapView->stackUnder(m_mapScale);
110 // Set default screen size
111 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
113 setAttribute(Qt::WA_Maemo5StackedWindow);
117 MainWindow::~MainWindow()
119 qDebug() << __PRETTY_FUNCTION__;
126 qDeleteAll(m_queue.begin(), m_queue.end());
129 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
130 m_error_queue.clear();
133 void MainWindow::automaticUpdateDialogFinished(int result)
135 qDebug() << __PRETTY_FUNCTION__;
137 if (result == QMessageBox::Yes) {
138 readAutomaticLocationUpdateSettings();
140 QSettings settings(DIRECTORY_NAME, FILE_NAME);
141 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
142 readAutomaticLocationUpdateSettings();
145 m_automaticUpdateLocationDialog->deleteLater();
148 void MainWindow::buildFullScreenButton()
150 qDebug() << __PRETTY_FUNCTION__;
153 m_fullScreenButton = new FullScreenButton(this);
155 if (m_fullScreenButton) {
156 connect(m_fullScreenButton, SIGNAL(clicked()),
157 this, SLOT(toggleFullScreen()));
159 connect(qApp, SIGNAL(showFullScreenButton()),
160 m_fullScreenButton, SLOT(invoke()));
162 #endif // Q_WS_MAEMO_5
165 void MainWindow::buildFriendListPanel()
167 qDebug() << __PRETTY_FUNCTION__;
169 m_friendsListPanel = new FriendListPanel(this);
171 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
172 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
174 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
175 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
177 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
178 this, SIGNAL(findFriend(GeoCoordinate)));
180 connect(this, SIGNAL(friendImageReady(User*)),
181 m_friendsListPanel, SLOT(friendImageReady(User*)));
184 void MainWindow::buildIndicatorButtonPanel()
186 qDebug() << __PRETTY_FUNCTION__;
188 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
190 connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
191 this, SIGNAL(autoCenteringTriggered(bool)));
193 connect(m_mapView, SIGNAL(viewResized(QSize)),
194 m_indicatorButtonPanel, SLOT(screenResized(QSize)));
196 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
197 m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
199 connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
200 this, SIGNAL(draggingModeTriggered()));
203 void MainWindow::buildInformationBox(const QString &message, bool modal)
205 qDebug() << __PRETTY_FUNCTION__;
207 QString errorMessage = message;
211 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
214 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
215 // extra line changes are needed to make error notes broader
216 errorMessage.prepend("\n");
217 errorMessage.append("\n");
219 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
221 QLabel *label = new QLabel(msgBox);
222 label->setAlignment(Qt::AlignCenter);
223 label->setText(errorMessage);
224 msgBox->setWidget(label);
226 QMessageBox *msgBox = new QMessageBox(this);
227 msgBox->button(QMessageBox::Ok);
228 msgBox->setText(errorMessage);
229 msgBox->setModal(modal);
235 void MainWindow::buildManualLocationCrosshair()
237 qDebug() << __PRETTY_FUNCTION__;
239 m_ownLocationCrosshair = new QLabel(this);
240 QPixmap crosshairImage(":/res/images/sight.png");
241 m_ownLocationCrosshair->setPixmap(crosshairImage);
242 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
243 m_ownLocationCrosshair->hide();
244 m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
246 connect(m_mapView, SIGNAL(viewResized(QSize)),
247 this, SLOT(drawOwnLocationCrosshair(QSize)));
250 void MainWindow::buildMap()
252 qDebug() << __PRETTY_FUNCTION__;
254 m_mapView = new MapView(this);
256 buildZoomButtonPanel();
258 buildManualLocationCrosshair();
259 buildFullScreenButton();
260 buildIndicatorButtonPanel();
263 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
264 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
266 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
267 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
269 connect(m_mapView, SIGNAL(viewResized(QSize)),
270 this, SIGNAL(mapViewResized(QSize)));
272 connect(m_mapView, SIGNAL(viewResized(QSize)),
273 this, SLOT(drawFullScreenButton(QSize)));
275 connect(m_mapView, SIGNAL(viewResized(QSize)),
276 this, SLOT(drawMapScale(QSize)));
278 connect(m_mapView, SIGNAL(viewResized(QSize)),
279 this, SLOT(setViewPortSize(QSize)));
281 connect(this, SIGNAL(zoomLevelChanged(int)),
282 m_mapView, SLOT(setZoomLevel(int)));
284 connect(m_mapView, SIGNAL(viewZoomFinished()),
285 this, SIGNAL(viewZoomFinished()));
287 connect(m_mapView, SIGNAL(zoomIn()),
288 this, SIGNAL(zoomIn()));
291 void MainWindow::buildMapScale()
293 m_mapScale = new MapScale(this);
294 connect(this, SIGNAL(newMapResolution(qreal)),
295 m_mapScale, SLOT(updateMapResolution(qreal)));
298 void MainWindow::buildOsmLicense()
300 qDebug() << __PRETTY_FUNCTION__;
302 m_osmLicense = new QLabel(this);
303 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
304 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
305 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
306 m_osmLicense->setFont(QFont("Nokia Sans", 9));
307 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
308 m_osmLicense->fontMetrics().height());
310 connect(m_mapView, SIGNAL(viewResized(QSize)),
311 this, SLOT(drawOsmLicense(QSize)));
314 void MainWindow::buildPanels()
316 qDebug() << __PRETTY_FUNCTION__;
318 buildUserInfoPanel();
319 buildFriendListPanel();
321 m_tabbedPanel = new TabbedPanel(this);
322 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png"));
323 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png"));
325 connect(m_tabbedPanel, SIGNAL(tabChanged()),
326 m_friendsListPanel, SLOT(clearFriendListFilter()));
328 connect(m_mapView, SIGNAL(viewResized(QSize)),
329 m_tabbedPanel, SLOT(resizePanel(QSize)));
332 void MainWindow::buildUserInfoPanel()
334 qDebug() << __PRETTY_FUNCTION__;
336 m_userInfoPanel = new UserInfoPanel(this);
338 connect(this, SIGNAL(userLocationReady(User*)),
339 m_userInfoPanel, SLOT(userDataReceived(User*)));
341 connect(this, SIGNAL(reverseGeoReady(QString)),
342 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
344 connect(this, SIGNAL(clearUpdateLocationDialogData()),
345 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
347 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
348 this, SIGNAL(findUser(GeoCoordinate)));
350 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
351 this, SIGNAL(requestReverseGeo()));
353 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
354 this, SIGNAL(statusUpdate(QString,bool)));
356 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
357 this, SIGNAL(refreshUserData()));
359 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
360 this, SLOT(buildInformationBox(QString, bool)));
363 void MainWindow::buildWebView()
365 qDebug() << __PRETTY_FUNCTION__;
368 m_webView = new QWebView;
371 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
373 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
375 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
376 this, SLOT(webViewRequestFinished(QNetworkReply*)));
377 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
378 this, SIGNAL(updateCredentials(QUrl)));
379 connect(m_webView, SIGNAL(loadFinished(bool)),
380 this, SLOT(loadDone(bool)));
386 void MainWindow::buildZoomButtonPanel()
388 qDebug() << __PRETTY_FUNCTION__;
390 m_zoomButtonPanel = new ZoomButtonPanel(this);
392 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
393 this, SIGNAL(zoomIn()));
395 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
396 this, SIGNAL(zoomOut()));
398 connect(this, SIGNAL(zoomLevelChanged(int)),
399 m_zoomButtonPanel, SLOT(resetButtons()));
401 connect(this, SIGNAL(maxZoomLevelReached()),
402 m_zoomButtonPanel, SLOT(disableZoomInButton()));
404 connect(this, SIGNAL(minZoomLevelReached()),
405 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
407 connect(m_mapView, SIGNAL(viewResized(QSize)),
408 m_zoomButtonPanel, SLOT(screenResized(QSize)));
410 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
411 this, SIGNAL(draggingModeTriggered()));
414 void MainWindow::clearCookieJar()
416 qDebug() << __PRETTY_FUNCTION__;
423 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
425 QList<QNetworkCookie> emptyList;
428 m_cookieJar->setAllCookies(emptyList);
429 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
432 void MainWindow::createMenus()
434 qDebug() << __PRETTY_FUNCTION__;
437 m_loginAct = new QAction(tr("Login"), this);
438 connect(m_loginAct, SIGNAL(triggered()),
439 this, SIGNAL(loginActionPressed()));
442 m_toSettingsAct = new QAction(tr("Settings"), this);
443 connect(m_toSettingsAct, SIGNAL(triggered()),
444 this, SLOT(openSettingsDialog()));
447 m_gpsToggleAct = new QAction(tr("GPS"), this);
448 m_gpsToggleAct->setCheckable(true);
450 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
451 this, SIGNAL(gpsTriggered(bool)));
453 /// @todo remove when not needed!
454 m_searchLocationAct = new QAction(tr("Location search"), this);
455 connect(m_searchLocationAct, SIGNAL(triggered()),
456 this, SLOT(startLocationSearch()));
458 // build the actual menu
459 m_viewMenu = menuBar()->addMenu(tr("Main"));
460 m_viewMenu->addAction(m_loginAct);
461 m_viewMenu->addAction(m_toSettingsAct);
462 m_viewMenu->addAction(m_gpsToggleAct);
463 m_viewMenu->addAction(m_searchLocationAct); /// @todo remove when not needed!
464 m_viewMenu->setObjectName(tr("Menu"));
467 void MainWindow::dialogFinished(int status)
469 qDebug() << __PRETTY_FUNCTION__;
471 QDialog *dialog = m_queue.takeFirst();
472 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
473 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
477 loginDialog->userInput(m_email, m_password);
479 QStringList urlParts;
480 urlParts.append(FACEBOOK_LOGINBASE);
481 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
482 urlParts.append(INTERVAL1);
483 urlParts.append(SITUARE_LOGIN_SUCCESS);
484 urlParts.append(INTERVAL2);
485 urlParts.append(SITUARE_LOGIN_FAILURE);
486 urlParts.append(FACEBOOK_LOGIN_ENDING);
488 emit saveUsername(m_email);
490 m_webView->load(QUrl(urlParts.join(EMPTY)));
491 toggleProgressIndicator(true);
493 emit cancelLoginProcess();
495 } else if(searchDialog) {
497 emit searchForLocation(searchDialog->input());
501 dialog->deleteLater();
503 if(!m_error_queue.isEmpty() && m_errorShown == false) {
504 showErrorInformationBox();
506 if(!m_queue.isEmpty()) {
507 showInformationBox();
512 void MainWindow::drawFullScreenButton(const QSize &size)
514 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
516 if (m_fullScreenButton) {
517 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
518 size.height() - m_fullScreenButton->size().height());
522 void MainWindow::drawMapScale(const QSize &size)
524 qDebug() << __PRETTY_FUNCTION__;
526 const int LEFT_SCALE_MARGIN = 10;
527 const int BOTTOM_SCALE_MARGIN = 2;
529 m_mapScale->move(LEFT_SCALE_MARGIN,
530 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
533 void MainWindow::drawOsmLicense(const QSize &size)
535 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
537 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
539 size.height() - m_osmLicense->fontMetrics().height());
542 void MainWindow::drawOwnLocationCrosshair(const QSize &size)
544 qDebug() << __PRETTY_FUNCTION__;
546 if (m_ownLocationCrosshair != 0) {
547 m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
548 size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
552 void MainWindow::errorDialogFinished(int status)
554 qDebug() << __PRETTY_FUNCTION__;
557 QDialog *dialog = m_error_queue.takeFirst();
559 dialog->deleteLater();
560 m_errorShown = false;
562 if(!m_error_queue.isEmpty())
563 showErrorInformationBox();
564 else if(!m_queue.isEmpty())
565 showInformationBox();
568 void MainWindow::gpsTimeout()
570 qDebug() << __PRETTY_FUNCTION__;
572 buildInformationBox(tr("GPS timeout"));
575 void MainWindow::grabZoomKeys(bool grab)
577 qDebug() << __PRETTY_FUNCTION__;
580 // Can't grab keys unless we have a window id
584 unsigned long val = (grab) ? 1 : 0;
585 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
589 XChangeProperty (QX11Info::display(),
595 reinterpret_cast<unsigned char *>(&val),
599 #endif // Q_WS_MAEMO_5
602 void MainWindow::keyPressEvent(QKeyEvent* event)
604 qDebug() << __PRETTY_FUNCTION__;
606 switch (event->key()) {
617 QWidget::keyPressEvent(event);
620 void MainWindow::loadCookies()
622 qDebug() << __PRETTY_FUNCTION__;
624 QSettings settings(DIRECTORY_NAME, FILE_NAME);
626 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
628 if(!list.isEmpty()) {
629 QList<QNetworkCookie> cookieList;
630 for(int i=0;i<list.count();i++) {
631 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
635 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
637 m_cookieJar->setAllCookies(cookieList);
638 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
642 void MainWindow::loadDone(bool done)
644 qDebug() << __PRETTY_FUNCTION__;
646 // for the first time the login page is opened, we need to refresh it to get cookies working
654 QWebFrame* frame = m_webView->page()->currentFrame();
658 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
660 foreach (QWebElement element, emailCollection) {
661 element.setAttribute("value", m_email.toAscii());
664 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
665 foreach (QWebElement element, passwordCollection) {
666 element.setAttribute("value", m_password.toAscii());
668 // find connect button
669 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
670 foreach (QWebElement element, buttonCollection)
672 QPoint pos(element.geometry().center());
674 // send a mouse click event to the web page
675 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
677 QApplication::sendEvent(m_webView->page(), &event0);
678 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
680 QApplication::sendEvent(m_webView->page(), &event1);
686 void MainWindow::loggedIn(bool logged)
688 qDebug() << __PRETTY_FUNCTION__;
693 m_loginAct->setText(tr("Logout"));
699 m_loginAct->setText(tr("Login"));
701 updateItemVisibility();
704 void MainWindow::loginFailed()
706 qDebug() << __PRETTY_FUNCTION__;
712 bool MainWindow::loginState()
714 qDebug() << __PRETTY_FUNCTION__;
719 void MainWindow::loginUsingCookies()
721 qDebug() << __PRETTY_FUNCTION__;
723 toggleProgressIndicator(true);
728 QStringList urlParts;
729 urlParts.append(FACEBOOK_LOGINBASE);
730 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
731 urlParts.append(INTERVAL1);
732 urlParts.append(SITUARE_LOGIN_SUCCESS);
733 urlParts.append(INTERVAL2);
734 urlParts.append(SITUARE_LOGIN_FAILURE);
735 urlParts.append(FACEBOOK_LOGIN_ENDING);
737 m_webView->load(QUrl(urlParts.join(EMPTY)));
741 void MainWindow::openSettingsDialog()
743 qDebug() << __PRETTY_FUNCTION__;
745 SettingsDialog *settingsDialog = new SettingsDialog(this);
746 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
747 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
749 settingsDialog->show();
752 void MainWindow::readAutomaticLocationUpdateSettings()
754 qDebug() << __PRETTY_FUNCTION__;
756 QSettings settings(DIRECTORY_NAME, FILE_NAME);
757 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
758 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
761 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
763 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
765 emit enableAutomaticLocationUpdate(false);
769 void MainWindow::queueDialog(QDialog *dialog)
771 qDebug() << __PRETTY_FUNCTION__;
773 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
774 if(dialog->isModal()) {
775 m_error_queue.append(dialog);
777 m_queue.append(dialog);
780 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
781 if(m_error_queue.count() == 1 && m_errorShown == false)
782 showErrorInformationBox();
783 else if(m_queue.count() == 1 && m_errorShown == false)
784 showInformationBox();
787 void MainWindow::saveCookies()
789 qDebug() << __PRETTY_FUNCTION__;
792 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
794 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
797 for(int i=0;i<cookieList.count();i++) {
798 QNetworkCookie cookie = cookieList.at(i);
799 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
800 list.append(QString(byteArray));
802 list.removeDuplicates();
804 QSettings settings(DIRECTORY_NAME, FILE_NAME);
805 settings.setValue(COOKIES, list);
808 void MainWindow::setGPSButtonEnabled(bool enabled)
810 qDebug() << __PRETTY_FUNCTION__;
812 m_gpsToggleAct->setChecked(enabled);
815 void MainWindow::setIndicatorButtonEnabled(bool enabled)
817 qDebug() << __PRETTY_FUNCTION__;
819 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
822 void MainWindow::setMapViewScene(QGraphicsScene *scene)
824 qDebug() << __PRETTY_FUNCTION__;
826 m_mapView->setScene(scene);
829 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
831 qDebug() << __PRETTY_FUNCTION__;
834 m_ownLocationCrosshair->show();
835 drawOwnLocationCrosshair(m_viewPortSize);
837 m_ownLocationCrosshair->hide();
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 ///< @todo check how this is called and can this method be removed
917 drawFullScreenButton(m_viewPortSize);
920 // if(!m_friendsListPanel->isVisible()) {
921 // m_friendsListPanel->show();
922 // m_friendsListPanelSidebar->show();
925 // if(!m_userPanel->isVisible()) {
926 // m_userPanel->show();
927 // m_userPanelSidebar->show();
932 void MainWindow::startLocationSearch()
934 qDebug() << __PRETTY_FUNCTION__;
936 SearchDialog *searchDialog = new SearchDialog();
937 queueDialog(searchDialog);
940 void MainWindow::startLoginProcess()
942 qDebug() << __PRETTY_FUNCTION__;
944 LoginDialog *loginDialog = new LoginDialog();
946 emit fetchUsernameFromSettings();
948 loginDialog->clearTextFields();
950 if(!m_email.isEmpty())
951 loginDialog->setEmailField(m_email);
953 queueDialog(loginDialog);
956 void MainWindow::toggleProgressIndicator(bool value)
958 qDebug() << __PRETTY_FUNCTION__;
962 m_progressIndicatorCount++;
963 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
965 if(m_progressIndicatorCount > 0)
966 m_progressIndicatorCount--;
968 if(m_progressIndicatorCount == 0)
969 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
973 #endif // Q_WS_MAEMO_5
976 void MainWindow::updateItemVisibility()
978 qDebug() << __PRETTY_FUNCTION__;
980 ///< @todo can this be removed?
983 // m_friendsListPanel->closePanel();
984 // m_friendsListPanel->hide();
985 // m_friendsListPanelSidebar->hide();
987 // m_userPanel->closePanel();
988 // m_userPanel->hide();
989 // m_userPanelSidebar->hide();
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());