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 "meetpeoplepanel.h"
46 #include "panelcommon.h"
47 #include "routingpanel.h"
48 #include "tabbedpanel.h"
49 #include "searchdialog.h"
50 #include "settingsdialog.h"
51 #include "userinfopanel.h"
52 #include "zoombuttonpanel.h"
55 #include "mainwindow.h"
57 // These MUST BE HERE, compiling for Maemo fails if moved
59 #include <QtMaemo5/QMaemo5InformationBox>
60 #include <QtGui/QX11Info>
61 #include <X11/Xatom.h>
63 #endif // Q_WS_MAEMO_5
65 #if defined(Q_WS_MAEMO_5) & defined(ARMEL)
66 #include "ossoabookdialog.h"
69 MainWindow::MainWindow(QWidget *parent)
70 : QMainWindow(parent),
74 m_mapCenterHorizontalShifting(0),
75 m_progressIndicatorCount(0),
77 m_email(), ///< @todo WTF?!?!?!?
80 m_fullScreenButton(0),
81 m_indicatorButtonPanel(0),
85 qDebug() << __PRETTY_FUNCTION__;
89 // map view is the only widget which size & location is handled automatically by the system
90 // default functionality
91 setCentralWidget(m_mapView);
96 setWindowTitle(tr("Situare"));
98 // set stacking order of widgets (from top to bottom)
99 // m_tabbedPanel is the topmost one
100 if (m_fullScreenButton) {
101 m_fullScreenButton->stackUnder(m_tabbedPanel);
102 m_crosshair->stackUnder(m_fullScreenButton);
104 m_crosshair->stackUnder(m_tabbedPanel);
106 m_zoomButtonPanel->stackUnder(m_crosshair);
107 m_indicatorButtonPanel->stackUnder(m_zoomButtonPanel);
108 m_osmLicense->stackUnder(m_indicatorButtonPanel);
109 m_mapScale->stackUnder(m_osmLicense);
110 m_mapView->stackUnder(m_mapScale);
114 // Set default screen size
115 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
117 setAttribute(Qt::WA_Maemo5StackedWindow);
121 MainWindow::~MainWindow()
123 qDebug() << __PRETTY_FUNCTION__;
130 qDeleteAll(m_queue.begin(), m_queue.end());
133 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
134 m_error_queue.clear();
137 void MainWindow::automaticUpdateDialogFinished(int result)
139 qDebug() << __PRETTY_FUNCTION__;
141 if (result == QMessageBox::Yes) {
142 readAutomaticLocationUpdateSettings();
144 QSettings settings(DIRECTORY_NAME, FILE_NAME);
145 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
146 readAutomaticLocationUpdateSettings();
149 m_automaticUpdateLocationDialog->deleteLater();
152 void MainWindow::buildCrosshair()
154 qDebug() << __PRETTY_FUNCTION__;
156 m_crosshair = new QLabel(this);
157 QPixmap crosshairImage(":/res/images/sight.png");
158 m_crosshair->setPixmap(crosshairImage);
159 m_crosshair->setFixedSize(crosshairImage.size());
161 m_crosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
163 connect(m_mapView, SIGNAL(viewResized(QSize)),
164 this, SLOT(moveCrosshair()));
166 connect(m_mapView, SIGNAL(horizontalShiftingChanged(int)),
167 this, SLOT(mapCenterHorizontalShiftingChanged(int)));
170 void MainWindow::buildFriendListPanel()
172 qDebug() << __PRETTY_FUNCTION__;
174 m_friendsListPanel = new FriendListPanel(this);
176 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
177 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
179 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
180 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
182 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
183 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
185 connect(this, SIGNAL(friendImageReady(User*)),
186 m_friendsListPanel, SLOT(friendImageReady(User*)));
188 connect(m_friendsListPanel, SIGNAL(routeToFriend(const GeoCoordinate&)),
189 this, SIGNAL(routeTo(const GeoCoordinate&)));
191 connect(m_friendsListPanel, SIGNAL(requestContactDialog(const QString &)),
192 this, SIGNAL(requestContactDialog(const QString &)));
195 void MainWindow::buildFullScreenButton()
197 qDebug() << __PRETTY_FUNCTION__;
200 m_fullScreenButton = new FullScreenButton(this);
202 if (m_fullScreenButton) {
203 connect(m_fullScreenButton, SIGNAL(clicked()),
204 this, SLOT(toggleFullScreen()));
206 connect(qApp, SIGNAL(showFullScreenButton()),
207 m_fullScreenButton, SLOT(invoke()));
209 #endif // Q_WS_MAEMO_5
212 void MainWindow::buildIndicatorButtonPanel()
214 qDebug() << __PRETTY_FUNCTION__;
216 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
218 connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
219 this, SIGNAL(autoCenteringTriggered(bool)));
221 connect(m_mapView, SIGNAL(viewResized(QSize)),
222 m_indicatorButtonPanel, SLOT(screenResized(QSize)));
224 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
225 m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
227 connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
228 this, SIGNAL(draggingModeTriggered()));
231 void MainWindow::buildInformationBox(const QString &message, bool modal)
233 qDebug() << __PRETTY_FUNCTION__;
235 QString errorMessage = message;
239 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
242 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
243 // extra line changes are needed to make error notes broader
244 errorMessage.prepend("\n");
245 errorMessage.append("\n");
247 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
249 QLabel *label = new QLabel(msgBox);
250 label->setAlignment(Qt::AlignCenter);
251 label->setText(errorMessage);
252 msgBox->setWidget(label);
254 QMessageBox *msgBox = new QMessageBox(this);
255 msgBox->button(QMessageBox::Ok);
256 msgBox->setText(errorMessage);
257 msgBox->setModal(modal);
263 void MainWindow::buildMap()
265 qDebug() << __PRETTY_FUNCTION__;
267 m_mapView = new MapView(this);
269 buildZoomButtonPanel();
272 buildFullScreenButton();
273 buildIndicatorButtonPanel();
276 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
277 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
279 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
280 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
282 connect(m_mapView, SIGNAL(viewResized(QSize)),
283 this, SIGNAL(mapViewResized(QSize)));
285 connect(m_mapView, SIGNAL(viewResized(QSize)),
286 this, SLOT(drawFullScreenButton(QSize)));
288 connect(m_mapView, SIGNAL(viewResized(QSize)),
289 this, SLOT(drawMapScale(QSize)));
291 connect(m_mapView, SIGNAL(viewResized(QSize)),
292 this, SLOT(moveCrosshair()));
294 connect(this, SIGNAL(zoomLevelChanged(int)),
295 m_mapView, SLOT(setZoomLevel(int)));
297 connect(m_mapView, SIGNAL(viewZoomFinished()),
298 this, SIGNAL(viewZoomFinished()));
300 connect(m_mapView, SIGNAL(zoomIn()),
301 this, SIGNAL(zoomIn()));
304 void MainWindow::buildMapScale()
306 m_mapScale = new MapScale(this);
307 connect(this, SIGNAL(newMapResolution(qreal)),
308 m_mapScale, SLOT(updateMapResolution(qreal)));
311 void MainWindow::buildMeetPeoplePanel()
313 m_meetPeoplePanel = new MeetPeoplePanel(this);
315 connect(this, SIGNAL(friendImageReady(User*)),
316 m_meetPeoplePanel, SLOT(friendImageReady(User*)));
318 connect(this, SIGNAL(interestingPeopleReceived(QList<User*>&)),
319 m_meetPeoplePanel, SLOT(populateInterestingPeopleListView(QList<User*>&)));
322 void MainWindow::buildOsmLicense()
324 qDebug() << __PRETTY_FUNCTION__;
326 m_osmLicense = new QLabel(this);
327 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
328 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
329 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
330 m_osmLicense->setFont(QFont("Nokia Sans", 9));
331 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
332 m_osmLicense->fontMetrics().height());
334 connect(m_mapView, SIGNAL(viewResized(QSize)),
335 this, SLOT(drawOsmLicense(QSize)));
338 void MainWindow::buildPanels()
340 qDebug() << __PRETTY_FUNCTION__;
342 buildUserInfoPanel();
343 buildFriendListPanel();
345 buildMeetPeoplePanel();
347 m_tabbedPanel = new TabbedPanel(this);
348 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png"));
349 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png"));
350 m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
351 m_tabbedPanel->addTab(m_meetPeoplePanel, QIcon(":/res/images/meet_people.png"));
353 connect(m_mapView, SIGNAL(viewResized(QSize)),
354 m_tabbedPanel, SLOT(resizePanel(QSize)));
356 connect(m_friendsListPanel, SIGNAL(showPanelRequested(QWidget*)),
357 m_tabbedPanel, SLOT(showPanel(QWidget*)));
359 connect(m_routingPanel, SIGNAL(showPanelRequested(QWidget*)),
360 m_tabbedPanel, SLOT(showPanel(QWidget*)));
362 connect(m_tabbedPanel, SIGNAL(panelClosed()),
363 m_friendsListPanel, SLOT(anyPanelClosed()));
365 connect(m_tabbedPanel, SIGNAL(panelOpened()),
366 m_friendsListPanel, SLOT(anyPanelOpened()));
368 connect(m_tabbedPanel, SIGNAL(panelClosed()),
369 m_routingPanel, SLOT(clearListsSelections()));
371 connect(m_tabbedPanel, SIGNAL(panelClosed()),
372 m_mapView, SLOT(disableCenterShift()));
374 connect(m_tabbedPanel, SIGNAL(panelOpened()),
375 m_mapView, SLOT(enableCenterShift()));
378 void MainWindow::buildRoutingPanel()
380 qDebug() << __PRETTY_FUNCTION__;
382 m_routingPanel = new RoutingPanel(this);
384 connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
385 m_routingPanel, SLOT(populateLocationListView(const QList<Location>&)));
387 connect(m_routingPanel, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
388 this, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
390 connect(m_routingPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
391 this, SIGNAL(routeTo(const GeoCoordinate&)));
393 connect(this, SIGNAL(routeParsed(Route&)),
394 m_routingPanel, SLOT(setRoute(Route&)));
396 connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
397 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
399 connect(m_routingPanel, SIGNAL(requestSearchLocation()),
400 this, SLOT(startLocationSearch()));
402 connect(m_routingPanel, SIGNAL(clearRoute()),
403 this, SIGNAL(clearRoute()));
406 void MainWindow::buildUserInfoPanel()
408 qDebug() << __PRETTY_FUNCTION__;
410 m_userInfoPanel = new UserInfoPanel(this);
412 connect(this, SIGNAL(userLocationReady(User*)),
413 m_userInfoPanel, SLOT(userDataReceived(User*)));
415 connect(this, SIGNAL(reverseGeoReady(QString)),
416 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
418 connect(this, SIGNAL(clearUpdateLocationDialogData()),
419 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
421 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
422 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
424 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
425 this, SIGNAL(requestReverseGeo()));
427 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
428 this, SIGNAL(statusUpdate(QString,bool)));
430 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
431 this, SIGNAL(refreshUserData()));
433 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
434 this, SLOT(buildInformationBox(QString, bool)));
437 void MainWindow::buildWebView()
439 qDebug() << __PRETTY_FUNCTION__;
442 m_webView = new QWebView;
445 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
447 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
449 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
450 this, SLOT(webViewRequestFinished(QNetworkReply*)));
451 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
452 this, SIGNAL(updateCredentials(QUrl)));
453 connect(m_webView, SIGNAL(loadFinished(bool)),
454 this, SLOT(loadDone(bool)));
460 void MainWindow::buildZoomButtonPanel()
462 qDebug() << __PRETTY_FUNCTION__;
464 m_zoomButtonPanel = new ZoomButtonPanel(this);
466 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
467 this, SIGNAL(zoomIn()));
469 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
470 this, SIGNAL(zoomOut()));
472 connect(this, SIGNAL(zoomLevelChanged(int)),
473 m_zoomButtonPanel, SLOT(resetButtons()));
475 connect(this, SIGNAL(maxZoomLevelReached()),
476 m_zoomButtonPanel, SLOT(disableZoomInButton()));
478 connect(this, SIGNAL(minZoomLevelReached()),
479 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
481 connect(m_mapView, SIGNAL(viewResized(QSize)),
482 m_zoomButtonPanel, SLOT(screenResized(QSize)));
484 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
485 this, SIGNAL(draggingModeTriggered()));
488 void MainWindow::clearCookieJar()
490 qDebug() << __PRETTY_FUNCTION__;
497 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
499 QList<QNetworkCookie> emptyList;
502 m_cookieJar->setAllCookies(emptyList);
503 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
506 void MainWindow::createMenus()
508 qDebug() << __PRETTY_FUNCTION__;
511 m_loginAct = new QAction(tr("Login"), this);
512 connect(m_loginAct, SIGNAL(triggered()),
513 this, SIGNAL(loginActionPressed()));
516 m_toSettingsAct = new QAction(tr("Settings"), this);
517 connect(m_toSettingsAct, SIGNAL(triggered()),
518 this, SLOT(openSettingsDialog()));
521 m_gpsToggleAct = new QAction(tr("GPS"), this);
522 m_gpsToggleAct->setCheckable(true);
524 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
525 this, SIGNAL(gpsTriggered(bool)));
527 // build the actual menu
528 m_viewMenu = menuBar()->addMenu(tr("Main"));
529 m_viewMenu->addAction(m_loginAct);
530 m_viewMenu->addAction(m_toSettingsAct);
531 m_viewMenu->addAction(m_gpsToggleAct);
532 m_viewMenu->setObjectName(tr("Menu"));
535 void MainWindow::dialogFinished(int status)
537 qDebug() << __PRETTY_FUNCTION__;
539 QDialog *dialog = m_queue.takeFirst();
540 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
541 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
545 loginDialog->userInput(m_email, m_password);
547 QStringList urlParts;
548 urlParts.append(FACEBOOK_LOGINBASE);
549 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
550 urlParts.append(INTERVAL1);
551 urlParts.append(SITUARE_LOGIN_SUCCESS);
552 urlParts.append(INTERVAL2);
553 urlParts.append(SITUARE_LOGIN_FAILURE);
554 urlParts.append(FACEBOOK_LOGIN_ENDING);
556 emit saveUsername(m_email);
558 m_webView->load(QUrl(urlParts.join(EMPTY)));
559 toggleProgressIndicator(true);
561 emit cancelLoginProcess();
563 } else if(searchDialog) {
565 emit searchForLocation(searchDialog->input());
569 dialog->deleteLater();
571 if(!m_error_queue.isEmpty() && m_errorShown == false) {
572 showErrorInformationBox();
574 if(!m_queue.isEmpty()) {
575 showInformationBox();
580 void MainWindow::drawFullScreenButton(const QSize &size)
582 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
584 if (m_fullScreenButton) {
585 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
586 size.height() - m_fullScreenButton->size().height());
590 void MainWindow::drawMapScale(const QSize &size)
592 qDebug() << __PRETTY_FUNCTION__;
594 const int LEFT_SCALE_MARGIN = 10;
595 const int BOTTOM_SCALE_MARGIN = 2;
597 m_mapScale->move(LEFT_SCALE_MARGIN,
598 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
601 void MainWindow::drawOsmLicense(const QSize &size)
603 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
605 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
607 size.height() - m_osmLicense->fontMetrics().height());
610 void MainWindow::errorDialogFinished(int status)
612 qDebug() << __PRETTY_FUNCTION__;
615 QDialog *dialog = m_error_queue.takeFirst();
617 dialog->deleteLater();
618 m_errorShown = false;
620 if(!m_error_queue.isEmpty())
621 showErrorInformationBox();
622 else if(!m_queue.isEmpty())
623 showInformationBox();
626 void MainWindow::gpsTimeout()
628 qDebug() << __PRETTY_FUNCTION__;
630 buildInformationBox(tr("GPS timeout"));
633 void MainWindow::grabZoomKeys(bool grab)
635 qDebug() << __PRETTY_FUNCTION__;
638 // Can't grab keys unless we have a window id
642 unsigned long val = (grab) ? 1 : 0;
643 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
647 XChangeProperty (QX11Info::display(),
653 reinterpret_cast<unsigned char *>(&val),
657 #endif // Q_WS_MAEMO_5
660 void MainWindow::keyPressEvent(QKeyEvent* event)
662 qDebug() << __PRETTY_FUNCTION__;
664 switch (event->key()) {
675 QWidget::keyPressEvent(event);
678 void MainWindow::loadCookies()
680 qDebug() << __PRETTY_FUNCTION__;
682 QSettings settings(DIRECTORY_NAME, FILE_NAME);
684 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
686 if(!list.isEmpty()) {
687 QList<QNetworkCookie> cookieList;
688 for(int i=0;i<list.count();i++) {
689 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
693 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
695 m_cookieJar->setAllCookies(cookieList);
696 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
700 void MainWindow::loadDone(bool done)
702 qDebug() << __PRETTY_FUNCTION__;
704 // for the first time the login page is opened, we need to refresh it to get cookies working
712 QWebFrame* frame = m_webView->page()->currentFrame();
716 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
718 foreach (QWebElement element, emailCollection) {
719 element.setAttribute("value", m_email.toAscii());
722 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
723 foreach (QWebElement element, passwordCollection) {
724 element.setAttribute("value", m_password.toAscii());
726 // find connect button
727 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
728 foreach (QWebElement element, buttonCollection)
730 QPoint pos(element.geometry().center());
732 // send a mouse click event to the web page
733 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
735 QApplication::sendEvent(m_webView->page(), &event0);
736 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
738 QApplication::sendEvent(m_webView->page(), &event1);
744 void MainWindow::loggedIn(bool logged)
746 qDebug() << __PRETTY_FUNCTION__;
751 m_loginAct->setText(tr("Logout"));
757 m_loginAct->setText(tr("Login"));
759 updateItemVisibility();
762 void MainWindow::loginFailed()
764 qDebug() << __PRETTY_FUNCTION__;
770 bool MainWindow::loginState()
772 qDebug() << __PRETTY_FUNCTION__;
777 void MainWindow::loginUsingCookies()
779 qDebug() << __PRETTY_FUNCTION__;
781 toggleProgressIndicator(true);
786 QStringList urlParts;
787 urlParts.append(FACEBOOK_LOGINBASE);
788 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
789 urlParts.append(INTERVAL1);
790 urlParts.append(SITUARE_LOGIN_SUCCESS);
791 urlParts.append(INTERVAL2);
792 urlParts.append(SITUARE_LOGIN_FAILURE);
793 urlParts.append(FACEBOOK_LOGIN_ENDING);
795 m_webView->load(QUrl(urlParts.join(EMPTY)));
799 void MainWindow::mapCenterHorizontalShiftingChanged(int shifting)
801 m_mapCenterHorizontalShifting = shifting;
805 void MainWindow::moveCrosshair()
807 qDebug() << __PRETTY_FUNCTION__;
810 int mapHeight = m_mapView->size().height();
811 int mapWidth = m_mapView->size().width();
812 m_crosshair->move(mapWidth / 2 - m_crosshair->pixmap()->width() / 2
813 - m_mapCenterHorizontalShifting,
814 mapHeight / 2 - m_crosshair->pixmap()->height() / 2);
818 void MainWindow::openSettingsDialog()
820 qDebug() << __PRETTY_FUNCTION__;
822 SettingsDialog *settingsDialog = new SettingsDialog(this);
823 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
824 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
826 settingsDialog->show();
829 void MainWindow::queueDialog(QDialog *dialog)
831 qDebug() << __PRETTY_FUNCTION__;
833 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
834 if(dialog->isModal()) {
835 m_error_queue.append(dialog);
837 m_queue.append(dialog);
840 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
841 if(m_error_queue.count() == 1 && m_errorShown == false)
842 showErrorInformationBox();
843 else if(m_queue.count() == 1 && m_errorShown == false)
844 showInformationBox();
847 void MainWindow::readAutomaticLocationUpdateSettings()
849 qDebug() << __PRETTY_FUNCTION__;
851 QSettings settings(DIRECTORY_NAME, FILE_NAME);
852 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
853 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
856 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
858 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
860 emit enableAutomaticLocationUpdate(false);
864 void MainWindow::saveCookies()
866 qDebug() << __PRETTY_FUNCTION__;
869 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
871 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
874 for(int i=0;i<cookieList.count();i++) {
875 QNetworkCookie cookie = cookieList.at(i);
876 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
877 list.append(QString(byteArray));
879 list.removeDuplicates();
881 QSettings settings(DIRECTORY_NAME, FILE_NAME);
882 settings.setValue(COOKIES, list);
885 void MainWindow::setCrosshairVisibility(bool visibility)
887 qDebug() << __PRETTY_FUNCTION__;
897 void MainWindow::setGPSButtonEnabled(bool enabled)
899 qDebug() << __PRETTY_FUNCTION__;
901 m_gpsToggleAct->setChecked(enabled);
904 void MainWindow::setIndicatorButtonEnabled(bool enabled)
906 qDebug() << __PRETTY_FUNCTION__;
908 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
911 void MainWindow::setMapViewScene(QGraphicsScene *scene)
913 qDebug() << __PRETTY_FUNCTION__;
915 m_mapView->setScene(scene);
918 void MainWindow::settingsDialogAccepted()
920 qDebug() << __PRETTY_FUNCTION__;
922 readAutomaticLocationUpdateSettings();
925 void MainWindow::setUsername(const QString &username)
927 qDebug() << __PRETTY_FUNCTION__;
932 void MainWindow::showContactDialog(const QString &guid)
934 qDebug() << __PRETTY_FUNCTION__ << guid;
936 #if defined(Q_WS_MAEMO_5) & defined(ARMEL)
937 OssoABookDialog::showContactDialog(guid);
941 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
943 qDebug() << __PRETTY_FUNCTION__;
945 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
946 tr("Automatic location update"), text,
947 QMessageBox::Yes | QMessageBox::No |
948 QMessageBox::Cancel, this);
949 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
950 this, SLOT(automaticUpdateDialogFinished(int)));
952 m_automaticUpdateLocationDialog->show();
955 void MainWindow::showErrorInformationBox()
957 qDebug() << __PRETTY_FUNCTION__;
959 if(m_error_queue.count()) {
961 QDialog *dialog = m_error_queue.first();
962 connect(dialog, SIGNAL(finished(int)),
963 this, SLOT(errorDialogFinished(int)));
968 void MainWindow::showInformationBox()
970 qDebug() << __PRETTY_FUNCTION__;
972 if(m_queue.count()) {
973 QDialog *dialog = m_queue.first();
974 connect(dialog, SIGNAL(finished(int)),
975 this, SLOT(dialogFinished(int)));
980 void MainWindow::showPanels()
982 qDebug() << __PRETTY_FUNCTION__;
984 ///< @todo check how this is called and can this method be removed
987 // if(!m_friendsListPanel->isVisible()) {
988 // m_friendsListPanel->show();
989 // m_friendsListPanelSidebar->show();
992 // if(!m_userPanel->isVisible()) {
993 // m_userPanel->show();
994 // m_userPanelSidebar->show();
999 void MainWindow::startLocationSearch()
1001 qDebug() << __PRETTY_FUNCTION__;
1003 SearchDialog *searchDialog = new SearchDialog();
1004 queueDialog(searchDialog);
1007 void MainWindow::startLoginProcess()
1009 qDebug() << __PRETTY_FUNCTION__;
1011 LoginDialog *loginDialog = new LoginDialog();
1013 emit fetchUsernameFromSettings();
1015 loginDialog->clearTextFields();
1017 if(!m_email.isEmpty())
1018 loginDialog->setEmailField(m_email);
1020 queueDialog(loginDialog);
1023 void MainWindow::toggleFullScreen()
1025 qDebug() << __PRETTY_FUNCTION__;
1027 if(windowState() == Qt::WindowNoState)
1033 void MainWindow::toggleProgressIndicator(bool value)
1035 qDebug() << __PRETTY_FUNCTION__;
1039 m_progressIndicatorCount++;
1040 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
1042 if(m_progressIndicatorCount > 0)
1043 m_progressIndicatorCount--;
1045 if(m_progressIndicatorCount == 0)
1046 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
1050 #endif // Q_WS_MAEMO_5
1053 void MainWindow::updateItemVisibility()
1055 qDebug() << __PRETTY_FUNCTION__;
1057 ///< @todo can this be removed?
1059 // if(!m_loggedIn) {
1060 // m_friendsListPanel->closePanel();
1061 // m_friendsListPanel->hide();
1062 // m_friendsListPanelSidebar->hide();
1064 // m_userPanel->closePanel();
1065 // m_userPanel->hide();
1066 // m_userPanelSidebar->hide();
1070 const QString MainWindow::username()
1072 qDebug() << __PRETTY_FUNCTION__;
1077 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1079 qDebug() << __PRETTY_FUNCTION__;
1081 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1082 // qwebview starts to load a new page while the current page loading is not finished
1083 if(reply->error() != QNetworkReply::OperationCanceledError &&
1084 reply->error() != QNetworkReply::NoError) {
1085 emit error(ErrorContext::NETWORK, reply->error());