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,
27 #include <QtAlgorithms>
31 #include <QApplication>
33 #include <QMessageBox>
37 #include "facebookservice/facebookauthentication.h"
38 #include "friendlistpanel.h"
39 #include "fullscreenbutton.h"
40 #include "indicatorbuttonpanel.h"
41 #include "locationsearchpanel.h"
42 #include "logindialog.h"
43 #include "map/mapcommon.h"
44 #include "map/mapview.h"
46 #include "panelcommon.h"
47 #include "routingpanel.h"
48 #include "searchdialog.h"
49 #include "settingsdialog.h"
50 #include "tabbedpanel.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::buildLocationSearchPanel()
265 qDebug() << __PRETTY_FUNCTION__;
267 m_locationSearchPanel = new LocationSearchPanel(this);
269 connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
270 m_locationSearchPanel, SLOT(populateLocationListView(const QList<Location>&)));
272 connect(m_locationSearchPanel, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
273 this, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
275 connect(m_locationSearchPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
276 this, SIGNAL(routeTo(const GeoCoordinate&)));
278 connect(m_locationSearchPanel, SIGNAL(requestSearchLocation()),
279 this, SLOT(startLocationSearch()));
281 connect(this, SIGNAL(searchForLocation(QString)),
282 m_locationSearchPanel, SLOT(prependSearchHistory(QString)));
284 connect(m_locationSearchPanel, SIGNAL(searchHistoryItemClicked(QString)),
285 this, SIGNAL(searchHistoryItemClicked(QString)));
288 void MainWindow::buildMap()
290 qDebug() << __PRETTY_FUNCTION__;
292 m_mapView = new MapView(this);
294 buildZoomButtonPanel();
297 buildFullScreenButton();
298 buildIndicatorButtonPanel();
301 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
302 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
304 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
305 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
307 connect(m_mapView, SIGNAL(viewResized(QSize)),
308 this, SIGNAL(mapViewResized(QSize)));
310 connect(m_mapView, SIGNAL(viewResized(QSize)),
311 this, SLOT(drawFullScreenButton(QSize)));
313 connect(m_mapView, SIGNAL(viewResized(QSize)),
314 this, SLOT(drawMapScale(QSize)));
316 connect(m_mapView, SIGNAL(viewResized(QSize)),
317 this, SLOT(moveCrosshair()));
319 connect(this, SIGNAL(zoomLevelChanged(int)),
320 m_mapView, SLOT(setZoomLevel(int)));
322 connect(m_mapView, SIGNAL(viewZoomFinished()),
323 this, SIGNAL(viewZoomFinished()));
325 connect(m_mapView, SIGNAL(zoomIn()),
326 this, SIGNAL(zoomIn()));
329 void MainWindow::buildMapScale()
331 m_mapScale = new MapScale(this);
332 connect(this, SIGNAL(newMapResolution(qreal)),
333 m_mapScale, SLOT(updateMapResolution(qreal)));
336 void MainWindow::buildOsmLicense()
338 qDebug() << __PRETTY_FUNCTION__;
340 m_osmLicense = new QLabel(this);
341 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
342 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
343 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
344 m_osmLicense->setFont(QFont("Nokia Sans", 9));
345 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
346 m_osmLicense->fontMetrics().height());
348 connect(m_mapView, SIGNAL(viewResized(QSize)),
349 this, SLOT(drawOsmLicense(QSize)));
352 void MainWindow::buildPanels()
354 qDebug() << __PRETTY_FUNCTION__;
356 buildUserInfoPanel();
357 buildFriendListPanel();
358 buildLocationSearchPanel();
361 m_tabbedPanel = new TabbedPanel(this);
363 //Save Situare related tab indexes so tabs can be enabled/disabled when logged in/out
364 m_situareTabsIndexes.append(
365 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png")));
366 m_situareTabsIndexes.append(
367 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png")));
369 m_tabbedPanel->addTab(m_locationSearchPanel, QIcon(":/res/images/location_search.png"));
370 m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
372 connect(m_mapView, SIGNAL(viewResized(QSize)),
373 m_tabbedPanel, SLOT(resizePanel(QSize)));
375 connect(m_friendsListPanel, SIGNAL(openPanelRequested(QWidget*)),
376 m_tabbedPanel, SLOT(openPanel(QWidget*)));
378 connect(m_routingPanel, SIGNAL(openPanelRequested(QWidget*)),
379 m_tabbedPanel, SLOT(openPanel(QWidget*)));
381 connect(m_tabbedPanel, SIGNAL(panelClosed()),
382 m_friendsListPanel, SLOT(anyPanelClosed()));
384 connect(m_tabbedPanel, SIGNAL(panelOpened()),
385 m_friendsListPanel, SLOT(anyPanelOpened()));
387 connect(m_tabbedPanel, SIGNAL(panelClosed()),
388 m_routingPanel, SLOT(clearListsSelections()));
390 connect(m_tabbedPanel, SIGNAL(panelClosed()),
391 m_mapView, SLOT(disableCenterShift()));
393 connect(m_tabbedPanel, SIGNAL(panelOpened()),
394 m_mapView, SLOT(enableCenterShift()));
396 connect(m_tabbedPanel, SIGNAL(panelClosed()),
397 m_userInfoPanel, SIGNAL(collapse()));
399 connect(m_tabbedPanel, SIGNAL(currentChanged(int)),
400 m_userInfoPanel, SIGNAL(collapse()));
402 // signals for showing and hiding list item context buttons
403 connect(m_friendsListPanel, SIGNAL(listItemSelectionChanged(bool)),
404 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
406 connect(m_locationSearchPanel, SIGNAL(listItemSelectionChanged(bool)),
407 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
409 connect(m_routingPanel, SIGNAL(listItemSelectionChanged(bool)),
410 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
413 void MainWindow::buildRoutingPanel()
415 qDebug() << __PRETTY_FUNCTION__;
417 m_routingPanel = new RoutingPanel(this);
419 connect(m_routingPanel, SIGNAL(routeToCursor()),
420 this, SIGNAL(routeToCursor()));
422 connect(this, SIGNAL(routeParsed(Route&)),
423 m_routingPanel, SLOT(setRoute(Route&)));
425 connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
426 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
428 connect(m_routingPanel, SIGNAL(clearRoute()),
429 this, SIGNAL(clearRoute()));
432 void MainWindow::buildUserInfoPanel()
434 qDebug() << __PRETTY_FUNCTION__;
436 m_userInfoPanel = new UserInfoPanel(this);
438 connect(this, SIGNAL(userLocationReady(User*)),
439 m_userInfoPanel, SLOT(userDataReceived(User*)));
441 connect(this, SIGNAL(reverseGeoReady(QString)),
442 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
444 connect(this, SIGNAL(clearUpdateLocationDialogData()),
445 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
447 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
448 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
450 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
451 this, SIGNAL(requestReverseGeo()));
453 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
454 this, SIGNAL(statusUpdate(QString,bool)));
456 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
457 this, SIGNAL(refreshUserData()));
459 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
460 this, SLOT(buildInformationBox(QString, bool)));
463 void MainWindow::buildWebView()
465 qDebug() << __PRETTY_FUNCTION__;
468 m_webView = new QWebView;
471 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
473 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
475 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
476 this, SLOT(webViewRequestFinished(QNetworkReply*)));
477 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
478 this, SIGNAL(updateCredentials(QUrl)));
479 connect(m_webView, SIGNAL(loadFinished(bool)),
480 this, SLOT(loadDone(bool)));
486 void MainWindow::buildZoomButtonPanel()
488 qDebug() << __PRETTY_FUNCTION__;
490 m_zoomButtonPanel = new ZoomButtonPanel(this);
492 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
493 this, SIGNAL(zoomIn()));
495 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
496 this, SIGNAL(zoomOut()));
498 connect(this, SIGNAL(zoomLevelChanged(int)),
499 m_zoomButtonPanel, SLOT(resetButtons()));
501 connect(this, SIGNAL(maxZoomLevelReached()),
502 m_zoomButtonPanel, SLOT(disableZoomInButton()));
504 connect(this, SIGNAL(minZoomLevelReached()),
505 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
507 connect(m_mapView, SIGNAL(viewResized(QSize)),
508 m_zoomButtonPanel, SLOT(screenResized(QSize)));
510 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
511 this, SIGNAL(draggingModeTriggered()));
514 void MainWindow::clearCookieJar()
516 qDebug() << __PRETTY_FUNCTION__;
523 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
525 QList<QNetworkCookie> emptyList;
528 m_cookieJar->setAllCookies(emptyList);
529 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
532 void MainWindow::createMenus()
534 qDebug() << __PRETTY_FUNCTION__;
537 m_loginAct = new QAction(tr("Login"), this);
538 connect(m_loginAct, SIGNAL(triggered()),
539 this, SIGNAL(loginActionPressed()));
542 m_toSettingsAct = new QAction(tr("Settings"), this);
543 connect(m_toSettingsAct, SIGNAL(triggered()),
544 this, SLOT(openSettingsDialog()));
547 m_gpsToggleAct = new QAction(tr("GPS"), this);
548 m_gpsToggleAct->setCheckable(true);
550 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
551 this, SIGNAL(gpsTriggered(bool)));
553 // build the actual menu
554 m_viewMenu = menuBar()->addMenu(tr("Main"));
555 m_viewMenu->addAction(m_loginAct);
556 m_viewMenu->addAction(m_toSettingsAct);
557 m_viewMenu->addAction(m_gpsToggleAct);
558 m_viewMenu->setObjectName(tr("Menu"));
561 void MainWindow::dialogFinished(int status)
563 qDebug() << __PRETTY_FUNCTION__;
565 QDialog *dialog = m_queue.takeFirst();
566 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
567 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
571 loginDialog->userInput(m_email, m_password);
573 QStringList urlParts;
574 urlParts.append(FACEBOOK_LOGINBASE);
575 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
576 urlParts.append(INTERVAL1);
577 urlParts.append(SITUARE_LOGIN_SUCCESS);
578 urlParts.append(INTERVAL2);
579 urlParts.append(SITUARE_LOGIN_FAILURE);
580 urlParts.append(FACEBOOK_LOGIN_ENDING);
582 emit saveUsername(m_email);
584 m_webView->load(QUrl(urlParts.join(EMPTY)));
585 toggleProgressIndicator(true);
587 emit cancelLoginProcess();
589 } else if(searchDialog) {
591 emit searchForLocation(searchDialog->input());
595 dialog->deleteLater();
597 if(!m_error_queue.isEmpty() && m_errorShown == false) {
598 showErrorInformationBox();
600 if(!m_queue.isEmpty()) {
601 showInformationBox();
606 void MainWindow::drawFullScreenButton(const QSize &size)
608 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
610 if (m_fullScreenButton) {
611 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
612 size.height() - m_fullScreenButton->size().height());
616 void MainWindow::drawMapScale(const QSize &size)
618 qDebug() << __PRETTY_FUNCTION__;
620 const int LEFT_SCALE_MARGIN = 10;
621 const int BOTTOM_SCALE_MARGIN = 2;
623 m_mapScale->move(LEFT_SCALE_MARGIN,
624 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
627 void MainWindow::drawOsmLicense(const QSize &size)
629 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
631 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
633 size.height() - m_osmLicense->fontMetrics().height());
636 void MainWindow::errorDialogFinished(int status)
638 qDebug() << __PRETTY_FUNCTION__;
641 QDialog *dialog = m_error_queue.takeFirst();
643 dialog->deleteLater();
644 m_errorShown = false;
646 if(!m_error_queue.isEmpty())
647 showErrorInformationBox();
648 else if(!m_queue.isEmpty())
649 showInformationBox();
652 void MainWindow::gpsTimeout()
654 qDebug() << __PRETTY_FUNCTION__;
656 buildInformationBox(tr("GPS timeout"));
659 void MainWindow::grabZoomKeys(bool grab)
661 qDebug() << __PRETTY_FUNCTION__;
664 // Can't grab keys unless we have a window id
668 unsigned long val = (grab) ? 1 : 0;
669 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
673 XChangeProperty (QX11Info::display(),
679 reinterpret_cast<unsigned char *>(&val),
683 #endif // Q_WS_MAEMO_5
686 void MainWindow::keyPressEvent(QKeyEvent* event)
688 qDebug() << __PRETTY_FUNCTION__;
690 switch (event->key()) {
701 QWidget::keyPressEvent(event);
704 void MainWindow::loadCookies()
706 qDebug() << __PRETTY_FUNCTION__;
708 QSettings settings(DIRECTORY_NAME, FILE_NAME);
710 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
712 if(!list.isEmpty()) {
713 QList<QNetworkCookie> cookieList;
714 for(int i=0;i<list.count();i++) {
715 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
719 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
721 m_cookieJar->setAllCookies(cookieList);
722 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
726 void MainWindow::loadDone(bool done)
728 qDebug() << __PRETTY_FUNCTION__;
730 // for the first time the login page is opened, we need to refresh it to get cookies working
738 QWebFrame* frame = m_webView->page()->currentFrame();
742 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
744 foreach (QWebElement element, emailCollection) {
745 element.setAttribute("value", m_email.toAscii());
748 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
749 foreach (QWebElement element, passwordCollection) {
750 element.setAttribute("value", m_password.toAscii());
752 // find connect button
753 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
754 foreach (QWebElement element, buttonCollection)
756 QPoint pos(element.geometry().center());
758 // send a mouse click event to the web page
759 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
761 QApplication::sendEvent(m_webView->page(), &event0);
762 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
764 QApplication::sendEvent(m_webView->page(), &event1);
770 void MainWindow::loggedIn(bool logged)
772 qDebug() << __PRETTY_FUNCTION__;
777 m_loginAct->setText(tr("Logout"));
783 m_loginAct->setText(tr("Login"));
784 m_userInfoPanel->showUserInfo(false);
786 updateItemVisibility();
789 void MainWindow::loginFailed()
791 qDebug() << __PRETTY_FUNCTION__;
797 bool MainWindow::loginState()
799 qDebug() << __PRETTY_FUNCTION__;
804 void MainWindow::loginUsingCookies()
806 qDebug() << __PRETTY_FUNCTION__;
808 toggleProgressIndicator(true);
813 QStringList urlParts;
814 urlParts.append(FACEBOOK_LOGINBASE);
815 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
816 urlParts.append(INTERVAL1);
817 urlParts.append(SITUARE_LOGIN_SUCCESS);
818 urlParts.append(INTERVAL2);
819 urlParts.append(SITUARE_LOGIN_FAILURE);
820 urlParts.append(FACEBOOK_LOGIN_ENDING);
822 m_webView->load(QUrl(urlParts.join(EMPTY)));
826 void MainWindow::mapCenterHorizontalShiftingChanged(int shifting)
828 m_mapCenterHorizontalShifting = shifting;
832 void MainWindow::moveCrosshair()
834 qDebug() << __PRETTY_FUNCTION__;
837 int mapHeight = m_mapView->size().height();
838 int mapWidth = m_mapView->size().width();
839 m_crosshair->move(mapWidth / 2 - m_crosshair->pixmap()->width() / 2
840 - m_mapCenterHorizontalShifting,
841 mapHeight / 2 - m_crosshair->pixmap()->height() / 2);
845 void MainWindow::openSettingsDialog()
847 qDebug() << __PRETTY_FUNCTION__;
849 SettingsDialog *settingsDialog = new SettingsDialog(this);
850 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
851 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
853 settingsDialog->show();
856 void MainWindow::queueDialog(QDialog *dialog)
858 qDebug() << __PRETTY_FUNCTION__;
860 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
861 if(dialog->isModal()) {
862 m_error_queue.append(dialog);
864 m_queue.append(dialog);
867 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
868 if(m_error_queue.count() == 1 && m_errorShown == false)
869 showErrorInformationBox();
870 else if(m_queue.count() == 1 && m_errorShown == false)
871 showInformationBox();
874 void MainWindow::readAutomaticLocationUpdateSettings()
876 qDebug() << __PRETTY_FUNCTION__;
878 QSettings settings(DIRECTORY_NAME, FILE_NAME);
879 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
880 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
883 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
885 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
887 emit enableAutomaticLocationUpdate(false);
891 void MainWindow::saveCookies()
893 qDebug() << __PRETTY_FUNCTION__;
896 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
898 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
901 for(int i=0;i<cookieList.count();i++) {
902 QNetworkCookie cookie = cookieList.at(i);
903 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
904 list.append(QString(byteArray));
906 list.removeDuplicates();
908 QSettings settings(DIRECTORY_NAME, FILE_NAME);
909 settings.setValue(COOKIES, list);
912 void MainWindow::setCrosshairVisibility(bool visibility)
914 qDebug() << __PRETTY_FUNCTION__;
924 void MainWindow::setGPSButtonEnabled(bool enabled)
926 qDebug() << __PRETTY_FUNCTION__;
928 m_gpsToggleAct->setChecked(enabled);
931 void MainWindow::setIndicatorButtonEnabled(bool enabled)
933 qDebug() << __PRETTY_FUNCTION__;
935 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
938 void MainWindow::setMapViewScene(QGraphicsScene *scene)
940 qDebug() << __PRETTY_FUNCTION__;
942 m_mapView->setScene(scene);
945 void MainWindow::settingsDialogAccepted()
947 qDebug() << __PRETTY_FUNCTION__;
949 readAutomaticLocationUpdateSettings();
952 void MainWindow::setUsername(const QString &username)
954 qDebug() << __PRETTY_FUNCTION__;
959 void MainWindow::showContactDialog(const QString &guid)
961 qDebug() << __PRETTY_FUNCTION__;
963 #if defined(Q_WS_MAEMO_5) & defined(ARMEL)
964 OssoABookDialog::showContactDialog(guid);
967 buildInformationBox(tr("Contact dialog works only on phone!"), true);
971 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
973 qDebug() << __PRETTY_FUNCTION__;
975 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
976 tr("Automatic location update"), text,
977 QMessageBox::Yes | QMessageBox::No |
978 QMessageBox::Cancel, this);
979 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
980 this, SLOT(automaticUpdateDialogFinished(int)));
982 m_automaticUpdateLocationDialog->show();
985 void MainWindow::showErrorInformationBox()
987 qDebug() << __PRETTY_FUNCTION__;
989 if(m_error_queue.count()) {
991 QDialog *dialog = m_error_queue.first();
992 connect(dialog, SIGNAL(finished(int)),
993 this, SLOT(errorDialogFinished(int)));
998 void MainWindow::showInformationBox()
1000 qDebug() << __PRETTY_FUNCTION__;
1002 if(m_queue.count()) {
1003 QDialog *dialog = m_queue.first();
1004 connect(dialog, SIGNAL(finished(int)),
1005 this, SLOT(dialogFinished(int)));
1010 void MainWindow::startLocationSearch()
1012 qDebug() << __PRETTY_FUNCTION__;
1014 SearchDialog *searchDialog = new SearchDialog();
1015 queueDialog(searchDialog);
1018 void MainWindow::startLoginProcess()
1020 qDebug() << __PRETTY_FUNCTION__;
1022 LoginDialog *loginDialog = new LoginDialog();
1024 emit fetchUsernameFromSettings();
1026 loginDialog->clearTextFields();
1028 if(!m_email.isEmpty())
1029 loginDialog->setEmailField(m_email);
1031 queueDialog(loginDialog);
1034 void MainWindow::toggleFullScreen()
1036 qDebug() << __PRETTY_FUNCTION__;
1038 if(windowState() == Qt::WindowNoState)
1044 void MainWindow::toggleProgressIndicator(bool value)
1046 qDebug() << __PRETTY_FUNCTION__;
1050 m_progressIndicatorCount++;
1051 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
1053 if(m_progressIndicatorCount > 0)
1054 m_progressIndicatorCount--;
1056 if(m_progressIndicatorCount == 0)
1057 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
1061 #endif // Q_WS_MAEMO_5
1064 void MainWindow::updateItemVisibility()
1066 qDebug() << __PRETTY_FUNCTION__;
1068 m_tabbedPanel->setTabsEnabled(m_situareTabsIndexes, m_loggedIn);
1071 const QString MainWindow::username()
1073 qDebug() << __PRETTY_FUNCTION__;
1078 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1080 qDebug() << __PRETTY_FUNCTION__;
1082 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1083 // qwebview starts to load a new page while the current page loading is not finished
1084 if(reply->error() != QNetworkReply::OperationCanceledError &&
1085 reply->error() != QNetworkReply::NoError) {
1086 emit error(ErrorContext::NETWORK, reply->error());