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 "meetpeoplepanel.h"
47 #include "messagepanel.h"
48 #include "panelcommon.h"
49 #include "routingpanel.h"
50 #include "searchdialog.h"
51 #include "settingsdialog.h"
52 #include "tabbedpanel.h"
53 #include "userinfopanel.h"
54 #include "zoombuttonpanel.h"
55 #include "messagedialog.h"
58 #include "mainwindow.h"
60 // These MUST BE HERE, compiling for Maemo fails if moved
62 #include <QtMaemo5/QMaemo5InformationBox>
63 #include <QtGui/QX11Info>
64 #include <X11/Xatom.h>
66 #endif // Q_WS_MAEMO_5
68 #if defined(Q_WS_MAEMO_5) & defined(ARMEL)
69 #include "ossoabookdialog.h"
72 MainWindow::MainWindow(QWidget *parent)
73 : QMainWindow(parent),
77 m_mapCenterHorizontalShifting(0),
78 m_progressIndicatorCount(0),
80 m_email(), ///< @todo WTF?!?!?!?
83 m_fullScreenButton(0),
84 m_indicatorButtonPanel(0),
88 qDebug() << __PRETTY_FUNCTION__;
92 // map view is the only widget which size & location is handled automatically by the system
93 // default functionality
94 setCentralWidget(m_mapView);
99 setWindowTitle(tr("Situare"));
101 // set stacking order of widgets (from top to bottom)
102 // m_tabbedPanel is the topmost one
103 if (m_fullScreenButton) {
104 m_fullScreenButton->stackUnder(m_tabbedPanel);
105 m_crosshair->stackUnder(m_fullScreenButton);
107 m_crosshair->stackUnder(m_tabbedPanel);
109 m_zoomButtonPanel->stackUnder(m_crosshair);
110 m_indicatorButtonPanel->stackUnder(m_zoomButtonPanel);
111 m_osmLicense->stackUnder(m_indicatorButtonPanel);
112 m_mapScale->stackUnder(m_osmLicense);
113 m_mapView->stackUnder(m_mapScale);
117 // Set default screen size
118 resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
120 setAttribute(Qt::WA_Maemo5StackedWindow);
124 MainWindow::~MainWindow()
126 qDebug() << __PRETTY_FUNCTION__;
133 qDeleteAll(m_queue.begin(), m_queue.end());
136 qDeleteAll(m_error_queue.begin(), m_error_queue.end());
137 m_error_queue.clear();
140 void MainWindow::automaticUpdateDialogFinished(int result)
142 qDebug() << __PRETTY_FUNCTION__;
144 if (result == QMessageBox::Yes) {
145 readAutomaticLocationUpdateSettings();
147 QSettings settings(DIRECTORY_NAME, FILE_NAME);
148 settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
149 readAutomaticLocationUpdateSettings();
152 m_automaticUpdateLocationDialog->deleteLater();
155 void MainWindow::buildCrosshair()
157 qDebug() << __PRETTY_FUNCTION__;
159 m_crosshair = new QLabel(this);
160 QPixmap crosshairImage(":/res/images/sight.png");
161 m_crosshair->setPixmap(crosshairImage);
162 m_crosshair->setFixedSize(crosshairImage.size());
164 m_crosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
166 connect(m_mapView, SIGNAL(viewResized(QSize)),
167 this, SLOT(moveCrosshair()));
169 connect(m_mapView, SIGNAL(horizontalShiftingChanged(int)),
170 this, SLOT(mapCenterHorizontalShiftingChanged(int)));
173 void MainWindow::buildFriendListPanel()
175 qDebug() << __PRETTY_FUNCTION__;
177 m_friendsListPanel = new FriendListPanel(this);
179 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
180 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
182 connect(this, SIGNAL(locationItemClicked(QList<QString>)),
183 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
185 connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
186 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
188 connect(this, SIGNAL(friendImageReady(QString,QPixmap)),
189 m_friendsListPanel, SLOT(friendImageReady(QString,QPixmap)));
191 connect(m_friendsListPanel, SIGNAL(routeToFriend(const GeoCoordinate&)),
192 this, SIGNAL(routeTo(const GeoCoordinate&)));
194 connect(m_friendsListPanel, SIGNAL(requestContactDialog(const QString &)),
195 this, SIGNAL(requestContactDialog(const QString &)));
198 void MainWindow::buildFullScreenButton()
200 qDebug() << __PRETTY_FUNCTION__;
203 m_fullScreenButton = new FullScreenButton(this);
205 if (m_fullScreenButton) {
206 connect(m_fullScreenButton, SIGNAL(clicked()),
207 this, SLOT(toggleFullScreen()));
209 connect(qApp, SIGNAL(showFullScreenButton()),
210 m_fullScreenButton, SLOT(invoke()));
212 #endif // Q_WS_MAEMO_5
215 void MainWindow::buildIndicatorButtonPanel()
217 qDebug() << __PRETTY_FUNCTION__;
219 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
221 connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
222 this, SIGNAL(autoCenteringTriggered(bool)));
224 connect(m_mapView, SIGNAL(viewResized(QSize)),
225 m_indicatorButtonPanel, SLOT(screenResized(QSize)));
227 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
228 m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
230 connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
231 this, SIGNAL(draggingModeTriggered()));
234 void MainWindow::buildInformationBox(const QString &message, bool modal)
236 qDebug() << __PRETTY_FUNCTION__;
238 QString errorMessage = message;
242 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
245 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
246 // extra line changes are needed to make error notes broader
247 errorMessage.prepend("\n");
248 errorMessage.append("\n");
250 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
252 QLabel *label = new QLabel(msgBox);
253 label->setAlignment(Qt::AlignCenter);
254 label->setText(errorMessage);
255 msgBox->setWidget(label);
257 QMessageBox *msgBox = new QMessageBox(this);
258 msgBox->button(QMessageBox::Ok);
259 msgBox->setText(errorMessage);
260 msgBox->setModal(modal);
266 void MainWindow::buildLocationSearchPanel()
268 qDebug() << __PRETTY_FUNCTION__;
270 m_locationSearchPanel = new LocationSearchPanel(this);
272 connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
273 m_locationSearchPanel, SLOT(populateLocationListView(const QList<Location>&)));
275 connect(m_locationSearchPanel, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
276 this, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
278 connect(m_locationSearchPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
279 this, SIGNAL(routeTo(const GeoCoordinate&)));
281 connect(m_locationSearchPanel, SIGNAL(requestSearchLocation()),
282 this, SLOT(startLocationSearch()));
284 connect(this, SIGNAL(searchForLocation(QString)),
285 m_locationSearchPanel, SLOT(prependSearchHistory(QString)));
287 connect(m_locationSearchPanel, SIGNAL(searchHistoryItemClicked(QString)),
288 this, SIGNAL(searchHistoryItemClicked(QString)));
291 void MainWindow::buildMap()
293 qDebug() << __PRETTY_FUNCTION__;
295 m_mapView = new MapView(this);
297 buildZoomButtonPanel();
300 buildFullScreenButton();
301 buildIndicatorButtonPanel();
304 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
305 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
307 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
308 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
310 connect(m_mapView, SIGNAL(viewResized(QSize)),
311 this, SIGNAL(mapViewResized(QSize)));
313 connect(m_mapView, SIGNAL(viewResized(QSize)),
314 this, SLOT(drawFullScreenButton(QSize)));
316 connect(m_mapView, SIGNAL(viewResized(QSize)),
317 this, SLOT(drawMapScale(QSize)));
319 connect(m_mapView, SIGNAL(viewResized(QSize)),
320 this, SLOT(moveCrosshair()));
322 connect(this, SIGNAL(zoomLevelChanged(int)),
323 m_mapView, SLOT(setZoomLevel(int)));
325 connect(m_mapView, SIGNAL(viewZoomFinished()),
326 this, SIGNAL(viewZoomFinished()));
328 connect(m_mapView, SIGNAL(zoomIn()),
329 this, SIGNAL(zoomIn()));
332 void MainWindow::buildMapScale()
334 m_mapScale = new MapScale(this);
335 connect(this, SIGNAL(newMapResolution(qreal)),
336 m_mapScale, SLOT(updateMapResolution(qreal)));
339 void MainWindow::buildMeetPeoplePanel()
341 qDebug() << __PRETTY_FUNCTION__;
343 m_meetPeoplePanel = new MeetPeoplePanel(this);
345 connect(this, SIGNAL(friendImageReady(QString,QPixmap)),
346 m_meetPeoplePanel, SLOT(setImage(QString,QPixmap)));
348 connect(this, SIGNAL(interestingPeopleReceived(QList<User>&)),
349 m_meetPeoplePanel, SLOT(populateInterestingPeopleListView(QList<User>&)));
351 connect(m_meetPeoplePanel, SIGNAL(requestInterestingPeople()),
352 this, SIGNAL(requestInterestingPeople()));
354 connect(m_meetPeoplePanel, SIGNAL(requestInterestingPeopleSearch()),
355 this, SLOT(startPeopleSearch()));
357 connect(m_meetPeoplePanel, SIGNAL(findPerson(GeoCoordinate)),
358 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
360 connect(m_meetPeoplePanel, SIGNAL(requestMessageDialog(QPair<QString, QString>)),
361 this, SIGNAL(requestMessageDialog(QPair<QString, QString>)));
364 void MainWindow::buildMessagePanel()
366 qDebug() << __PRETTY_FUNCTION__;
368 m_messsagePanel = new MessagePanel(this);
370 connect(this, SIGNAL(messagesReceived(QList<Message>&)),
371 m_messsagePanel, SLOT(populateMessageListView(QList<Message>&)));
373 connect(m_messsagePanel, SIGNAL(requestMessages()),
374 this, SIGNAL(requestMessages()));
376 connect(this, SIGNAL(friendImageReady(QString,QPixmap)),
377 m_messsagePanel, SLOT(setImage(QString,QPixmap)));
380 void MainWindow::buildOsmLicense()
382 qDebug() << __PRETTY_FUNCTION__;
384 m_osmLicense = new QLabel(this);
385 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
386 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
387 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
388 m_osmLicense->setFont(QFont("Nokia Sans", 9));
389 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
390 m_osmLicense->fontMetrics().height());
392 connect(m_mapView, SIGNAL(viewResized(QSize)),
393 this, SLOT(drawOsmLicense(QSize)));
396 void MainWindow::buildPanels()
398 qDebug() << __PRETTY_FUNCTION__;
400 buildUserInfoPanel();
401 buildFriendListPanel();
402 buildLocationSearchPanel();
404 buildMeetPeoplePanel();
407 m_tabbedPanel = new TabbedPanel(this);
409 //Save Situare related tab indexes so tabs can be enabled/disabled when logged in/out
410 m_situareTabsIndexes.append(
411 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png")));
412 m_situareTabsIndexes.append(
413 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png")));
415 // m_tabbedPanel->addTab(m_locationSearchPanel, QIcon(":/res/images/location_search.png"));
416 // m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
417 m_situareTabsIndexes.append(
418 m_tabbedPanel->addTab(m_meetPeoplePanel, QIcon(":/res/images/meet_people.png")));
419 m_situareTabsIndexes.append(
420 m_tabbedPanel->addTab(m_messsagePanel, QIcon(":/res/images/message.png")));
422 connect(m_mapView, SIGNAL(viewResized(QSize)),
423 m_tabbedPanel, SLOT(resizePanel(QSize)));
425 connect(m_friendsListPanel, SIGNAL(openPanelRequested(QWidget*)),
426 m_tabbedPanel, SLOT(openPanel(QWidget*)));
428 connect(m_routingPanel, SIGNAL(openPanelRequested(QWidget*)),
429 m_tabbedPanel, SLOT(openPanel(QWidget*)));
431 connect(m_tabbedPanel, SIGNAL(panelClosed()),
432 m_friendsListPanel, SLOT(anyPanelClosed()));
434 connect(m_tabbedPanel, SIGNAL(panelOpened()),
435 m_friendsListPanel, SLOT(anyPanelOpened()));
437 connect(m_tabbedPanel, SIGNAL(panelClosed()),
438 m_routingPanel, SLOT(clearListsSelections()));
440 connect(m_tabbedPanel, SIGNAL(panelClosed()),
441 m_mapView, SLOT(disableCenterShift()));
443 connect(m_tabbedPanel, SIGNAL(panelOpened()),
444 m_mapView, SLOT(enableCenterShift()));
446 connect(m_tabbedPanel, SIGNAL(panelClosed()),
447 m_userInfoPanel, SIGNAL(collapse()));
449 connect(m_tabbedPanel, SIGNAL(currentChanged(int)),
450 m_userInfoPanel, SIGNAL(collapse()));
452 connect(m_tabbedPanel, SIGNAL(panelClosed()),
453 m_meetPeoplePanel, SLOT(anyPanelClosed()));
455 connect(m_tabbedPanel, SIGNAL(panelClosed()),
456 m_messsagePanel, SLOT(anyPanelClosed()));
458 // signals for showing and hiding list item context buttons
459 connect(m_userInfoPanel, SIGNAL(listItemSelectionChanged(bool)),
460 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
462 connect(m_friendsListPanel, SIGNAL(listItemSelectionChanged(bool)),
463 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
465 connect(m_locationSearchPanel, SIGNAL(listItemSelectionChanged(bool)),
466 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
468 connect(m_routingPanel, SIGNAL(listItemSelectionChanged(bool)),
469 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
471 connect(m_meetPeoplePanel, SIGNAL(listItemSelectionChanged(bool)),
472 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
474 connect(m_messsagePanel, SIGNAL(listItemSelectionChanged(bool)),
475 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
478 void MainWindow::buildRoutingPanel()
480 qDebug() << __PRETTY_FUNCTION__;
482 m_routingPanel = new RoutingPanel(this);
484 connect(m_routingPanel, SIGNAL(routeToCursor()),
485 this, SIGNAL(routeToCursor()));
487 connect(this, SIGNAL(routeParsed(Route&)),
488 m_routingPanel, SLOT(setRoute(Route&)));
490 connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
491 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
493 connect(m_routingPanel, SIGNAL(clearRoute()),
494 this, SIGNAL(clearRoute()));
497 void MainWindow::buildUserInfoPanel()
499 qDebug() << __PRETTY_FUNCTION__;
501 m_userInfoPanel = new UserInfoPanel(this);
503 connect(this, SIGNAL(userLocationReady(User*)),
504 m_userInfoPanel, SLOT(userDataReceived(User*)));
506 connect(this, SIGNAL(reverseGeoReady(QString)),
507 m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
509 connect(this, SIGNAL(clearUpdateLocationDialogData()),
510 m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
512 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
513 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
515 connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
516 this, SIGNAL(requestReverseGeo()));
518 connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
519 this, SIGNAL(statusUpdate(QString,bool)));
521 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
522 this, SIGNAL(refreshUserData()));
524 connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
525 this, SLOT(buildInformationBox(QString, bool)));
527 connect(this, SIGNAL(userImageReady(QString,QPixmap)),
528 m_userInfoPanel, SLOT(setImage(QString,QPixmap)));
531 void MainWindow::buildWebView()
533 qDebug() << __PRETTY_FUNCTION__;
536 m_webView = new QWebView;
539 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
541 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
543 connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
544 this, SLOT(webViewRequestFinished(QNetworkReply*)));
545 connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
546 this, SIGNAL(updateCredentials(QUrl)));
547 connect(m_webView, SIGNAL(loadFinished(bool)),
548 this, SLOT(loadDone(bool)));
551 connect(m_webView->page()->networkAccessManager(), SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
552 this, SLOT(sslErrors(QNetworkReply*,QList<QSslError>)));
558 void MainWindow::buildZoomButtonPanel()
560 qDebug() << __PRETTY_FUNCTION__;
562 m_zoomButtonPanel = new ZoomButtonPanel(this);
564 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
565 this, SIGNAL(zoomIn()));
567 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
568 this, SIGNAL(zoomOut()));
570 connect(this, SIGNAL(zoomLevelChanged(int)),
571 m_zoomButtonPanel, SLOT(resetButtons()));
573 connect(this, SIGNAL(maxZoomLevelReached()),
574 m_zoomButtonPanel, SLOT(disableZoomInButton()));
576 connect(this, SIGNAL(minZoomLevelReached()),
577 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
579 connect(m_mapView, SIGNAL(viewResized(QSize)),
580 m_zoomButtonPanel, SLOT(screenResized(QSize)));
582 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
583 this, SIGNAL(draggingModeTriggered()));
586 void MainWindow::clearCookieJar()
588 qDebug() << __PRETTY_FUNCTION__;
595 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
597 QList<QNetworkCookie> emptyList;
600 m_cookieJar->setAllCookies(emptyList);
601 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
604 void MainWindow::createMenus()
606 qDebug() << __PRETTY_FUNCTION__;
609 m_loginAct = new QAction(tr("Login"), this);
610 connect(m_loginAct, SIGNAL(triggered()),
611 this, SIGNAL(loginActionPressed()));
614 m_toSettingsAct = new QAction(tr("Settings"), this);
615 connect(m_toSettingsAct, SIGNAL(triggered()),
616 this, SLOT(openSettingsDialog()));
619 m_gpsToggleAct = new QAction(tr("GPS"), this);
620 m_gpsToggleAct->setCheckable(true);
622 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
623 this, SIGNAL(gpsTriggered(bool)));
625 // build the actual menu
626 m_viewMenu = menuBar()->addMenu(tr("Main"));
627 m_viewMenu->addAction(m_loginAct);
628 m_viewMenu->addAction(m_toSettingsAct);
629 m_viewMenu->addAction(m_gpsToggleAct);
630 m_viewMenu->setObjectName(tr("Menu"));
633 void MainWindow::dialogFinished(int status)
635 qDebug() << __PRETTY_FUNCTION__;
637 QDialog *dialog = m_queue.takeFirst();
638 LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
639 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
640 MessageDialog *messageDialog = qobject_cast<MessageDialog *>(dialog);
644 loginDialog->userInput(m_email, m_password);
646 QStringList urlParts;
647 urlParts.append(FACEBOOK_LOGINBASE);
648 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
649 urlParts.append(INTERVAL1);
650 urlParts.append(SITUARE_LOGIN_SUCCESS);
651 urlParts.append(INTERVAL2);
652 urlParts.append(SITUARE_LOGIN_FAILURE);
653 urlParts.append(FACEBOOK_LOGIN_ENDING);
655 emit saveUsername(m_email);
657 m_webView->load(QUrl(urlParts.join(EMPTY)));
658 toggleProgressIndicator(true);
660 emit cancelLoginProcess();
662 } else if(searchDialog) {
664 emit searchForLocation(searchDialog->input());
667 else if (messageDialog) {
669 emit sendMessage(messageDialog->input().first, messageDialog->input().second);
672 dialog->deleteLater();
674 if(!m_error_queue.isEmpty() && m_errorShown == false) {
675 showErrorInformationBox();
677 if(!m_queue.isEmpty()) {
678 showInformationBox();
683 void MainWindow::drawFullScreenButton(const QSize &size)
685 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
687 if (m_fullScreenButton) {
688 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
689 size.height() - m_fullScreenButton->size().height());
693 void MainWindow::drawMapScale(const QSize &size)
695 qDebug() << __PRETTY_FUNCTION__;
697 const int LEFT_SCALE_MARGIN = 10;
698 const int BOTTOM_SCALE_MARGIN = 2;
700 m_mapScale->move(LEFT_SCALE_MARGIN,
701 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
704 void MainWindow::drawOsmLicense(const QSize &size)
706 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
708 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
710 size.height() - m_osmLicense->fontMetrics().height());
713 void MainWindow::errorDialogFinished(int status)
715 qDebug() << __PRETTY_FUNCTION__;
718 QDialog *dialog = m_error_queue.takeFirst();
720 dialog->deleteLater();
721 m_errorShown = false;
723 if(!m_error_queue.isEmpty())
724 showErrorInformationBox();
725 else if(!m_queue.isEmpty())
726 showInformationBox();
729 void MainWindow::gpsTimeout()
731 qDebug() << __PRETTY_FUNCTION__;
733 buildInformationBox(tr("GPS timeout"));
736 void MainWindow::grabZoomKeys(bool grab)
738 qDebug() << __PRETTY_FUNCTION__;
741 // Can't grab keys unless we have a window id
745 unsigned long val = (grab) ? 1 : 0;
746 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
750 XChangeProperty (QX11Info::display(),
756 reinterpret_cast<unsigned char *>(&val),
760 #endif // Q_WS_MAEMO_5
763 void MainWindow::keyPressEvent(QKeyEvent* event)
765 qDebug() << __PRETTY_FUNCTION__;
767 switch (event->key()) {
778 QWidget::keyPressEvent(event);
781 void MainWindow::loadCookies()
783 qDebug() << __PRETTY_FUNCTION__;
785 QSettings settings(DIRECTORY_NAME, FILE_NAME);
787 QStringList list = settings.value(COOKIES, EMPTY).toStringList();
789 if(!list.isEmpty()) {
790 QList<QNetworkCookie> cookieList;
791 for(int i=0;i<list.count();i++) {
792 cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
796 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
798 m_cookieJar->setAllCookies(cookieList);
799 m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
803 void MainWindow::loadDone(bool done)
805 qDebug() << __PRETTY_FUNCTION__;
807 // for the first time the login page is opened, we need to refresh it to get cookies working
815 QWebFrame* frame = m_webView->page()->currentFrame();
819 QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
821 foreach (QWebElement element, emailCollection) {
822 element.setAttribute("value", m_email.toAscii());
825 QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
826 foreach (QWebElement element, passwordCollection) {
827 element.setAttribute("value", m_password.toAscii());
829 // find connect button
830 QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
831 foreach (QWebElement element, buttonCollection)
833 QPoint pos(element.geometry().center());
835 // send a mouse click event to the web page
836 QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
838 QApplication::sendEvent(m_webView->page(), &event0);
839 QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
841 QApplication::sendEvent(m_webView->page(), &event1);
847 void MainWindow::loggedIn(bool logged)
849 qDebug() << __PRETTY_FUNCTION__;
854 m_loginAct->setText(tr("Logout"));
860 m_loginAct->setText(tr("Login"));
861 m_userInfoPanel->showUserInfo(false);
863 updateItemVisibility();
866 void MainWindow::loginFailed()
868 qDebug() << __PRETTY_FUNCTION__;
874 bool MainWindow::loginState()
876 qDebug() << __PRETTY_FUNCTION__;
881 void MainWindow::loginUsingCookies()
883 qDebug() << __PRETTY_FUNCTION__;
885 toggleProgressIndicator(true);
890 QStringList urlParts;
891 urlParts.append(FACEBOOK_LOGINBASE);
892 urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
893 urlParts.append(INTERVAL1);
894 urlParts.append(SITUARE_LOGIN_SUCCESS);
895 urlParts.append(INTERVAL2);
896 urlParts.append(SITUARE_LOGIN_FAILURE);
897 urlParts.append(FACEBOOK_LOGIN_ENDING);
899 m_webView->load(QUrl(urlParts.join(EMPTY)));
903 void MainWindow::mapCenterHorizontalShiftingChanged(int shifting)
905 m_mapCenterHorizontalShifting = shifting;
909 void MainWindow::moveCrosshair()
911 qDebug() << __PRETTY_FUNCTION__;
914 int mapHeight = m_mapView->size().height();
915 int mapWidth = m_mapView->size().width();
916 m_crosshair->move(mapWidth / 2 - m_crosshair->pixmap()->width() / 2
917 - m_mapCenterHorizontalShifting,
918 mapHeight / 2 - m_crosshair->pixmap()->height() / 2);
922 void MainWindow::openSettingsDialog()
924 qDebug() << __PRETTY_FUNCTION__;
926 SettingsDialog *settingsDialog = new SettingsDialog(this);
927 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
928 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
930 settingsDialog->show();
933 void MainWindow::queueDialog(QDialog *dialog)
935 qDebug() << __PRETTY_FUNCTION__;
937 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
938 if(dialog->isModal()) {
939 m_error_queue.append(dialog);
941 m_queue.append(dialog);
944 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
945 if(m_error_queue.count() == 1 && m_errorShown == false)
946 showErrorInformationBox();
947 else if(m_queue.count() == 1 && m_errorShown == false)
948 showInformationBox();
951 void MainWindow::readAutomaticLocationUpdateSettings()
953 qDebug() << __PRETTY_FUNCTION__;
955 QSettings settings(DIRECTORY_NAME, FILE_NAME);
956 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
957 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
960 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
962 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
964 emit enableAutomaticLocationUpdate(false);
968 void MainWindow::saveCookies()
970 qDebug() << __PRETTY_FUNCTION__;
973 m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
975 QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
978 for(int i=0;i<cookieList.count();i++) {
979 QNetworkCookie cookie = cookieList.at(i);
980 QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
981 list.append(QString(byteArray));
983 list.removeDuplicates();
985 QSettings settings(DIRECTORY_NAME, FILE_NAME);
986 settings.setValue(COOKIES, list);
989 void MainWindow::setCrosshairVisibility(bool visibility)
991 qDebug() << __PRETTY_FUNCTION__;
1001 void MainWindow::setGPSButtonEnabled(bool enabled)
1003 qDebug() << __PRETTY_FUNCTION__;
1005 m_gpsToggleAct->setChecked(enabled);
1008 void MainWindow::setIndicatorButtonEnabled(bool enabled)
1010 qDebug() << __PRETTY_FUNCTION__;
1012 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
1015 void MainWindow::setMapViewScene(QGraphicsScene *scene)
1017 qDebug() << __PRETTY_FUNCTION__;
1019 m_mapView->setScene(scene);
1022 void MainWindow::settingsDialogAccepted()
1024 qDebug() << __PRETTY_FUNCTION__;
1026 readAutomaticLocationUpdateSettings();
1029 void MainWindow::setUsername(const QString &username)
1031 qDebug() << __PRETTY_FUNCTION__;
1036 void MainWindow::showContactDialog(const QString &guid)
1038 qDebug() << __PRETTY_FUNCTION__;
1040 #if defined(Q_WS_MAEMO_5) & defined(ARMEL)
1041 OssoABookDialog::showContactDialog(guid);
1044 buildInformationBox(tr("Contact dialog works only on phone!"), true);
1048 void MainWindow::showMessageDialog(const QPair<QString, QString> &receiver)
1050 qDebug() << __PRETTY_FUNCTION__;
1052 MessageDialog *messageDialog = new MessageDialog(receiver.first, receiver.second);
1053 queueDialog(messageDialog);
1056 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
1058 qDebug() << __PRETTY_FUNCTION__;
1060 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
1061 tr("Automatic location update"), text,
1062 QMessageBox::Yes | QMessageBox::No |
1063 QMessageBox::Cancel, this);
1064 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
1065 this, SLOT(automaticUpdateDialogFinished(int)));
1067 m_automaticUpdateLocationDialog->show();
1070 void MainWindow::showErrorInformationBox()
1072 qDebug() << __PRETTY_FUNCTION__;
1074 if(m_error_queue.count()) {
1075 m_errorShown = true;
1076 QDialog *dialog = m_error_queue.first();
1077 connect(dialog, SIGNAL(finished(int)),
1078 this, SLOT(errorDialogFinished(int)));
1083 void MainWindow::showInformationBox()
1085 qDebug() << __PRETTY_FUNCTION__;
1087 if(m_queue.count()) {
1088 QDialog *dialog = m_queue.first();
1089 connect(dialog, SIGNAL(finished(int)),
1090 this, SLOT(dialogFinished(int)));
1095 void MainWindow::startLocationSearch()
1097 qDebug() << __PRETTY_FUNCTION__;
1099 SearchDialog *searchDialog = new SearchDialog(SearchDialog::Location);
1100 queueDialog(searchDialog);
1103 void MainWindow::startPeopleSearch()
1105 qDebug() << __PRETTY_FUNCTION__;
1107 SearchDialog *searchDialog = new SearchDialog(SearchDialog::People);
1108 queueDialog(searchDialog);
1111 void MainWindow::startLoginProcess()
1113 qDebug() << __PRETTY_FUNCTION__;
1115 LoginDialog *loginDialog = new LoginDialog();
1117 emit fetchUsernameFromSettings();
1119 loginDialog->clearTextFields();
1121 if(!m_email.isEmpty())
1122 loginDialog->setEmailField(m_email);
1124 queueDialog(loginDialog);
1127 void MainWindow::toggleFullScreen()
1129 qDebug() << __PRETTY_FUNCTION__;
1131 if(windowState() == Qt::WindowNoState)
1137 void MainWindow::toggleProgressIndicator(bool value)
1139 qDebug() << __PRETTY_FUNCTION__;
1143 m_progressIndicatorCount++;
1144 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
1146 if(m_progressIndicatorCount > 0)
1147 m_progressIndicatorCount--;
1149 if(m_progressIndicatorCount == 0)
1150 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
1154 #endif // Q_WS_MAEMO_5
1157 void MainWindow::updateItemVisibility()
1159 qDebug() << __PRETTY_FUNCTION__;
1161 m_tabbedPanel->setTabsEnabled(m_situareTabsIndexes, m_loggedIn);
1164 const QString MainWindow::username()
1166 qDebug() << __PRETTY_FUNCTION__;
1171 void MainWindow::webViewRequestFinished(QNetworkReply *reply)
1173 qDebug() << __PRETTY_FUNCTION__;
1175 // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
1176 // qwebview starts to load a new page while the current page loading is not finished
1177 if(reply->error() != QNetworkReply::OperationCanceledError &&
1178 reply->error() != QNetworkReply::NoError) {
1179 emit error(ErrorContext::NETWORK, reply->error());
1184 void MainWindow::sslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
1186 qWarning() << __PRETTY_FUNCTION__;
1188 reply->ignoreSslErrors();