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>
36 #include "engine/updatelocation.h"
38 #include "friendlistpanel.h"
39 #include "fullscreenbutton.h"
40 #include "indicatorbuttonpanel.h"
41 #include "locationsearchpanel.h"
42 #include "map/mapcommon.h"
43 #include "map/mapview.h"
45 #include "meetpeoplepanel.h"
46 #include "messagedialog.h"
47 #include "messagepanel.h"
48 #include "panelcommon.h"
49 #include "routingpanel.h"
50 #include "searchdialog.h"
51 #include "settingsdialog.h"
52 #include "situareservice/situarecommon.h"
53 #include "tabbedpanel.h"
54 #include "updatelocation/updatelocationdialog.h"
55 #include "userinfopanel.h"
56 #include "zoombuttonpanel.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),
81 m_fullScreenButton(0),
82 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);
120 m_updateLocationController = new UpdateLocation(this);
122 connect(this, SIGNAL(updateWasSuccessful()), m_updateLocationController, SLOT(clear()));
123 connect(m_updateLocationController, SIGNAL(locationUpdate(QString,bool)),
124 this, SIGNAL(locationUpdate(QString,bool)));
127 MainWindow::~MainWindow()
129 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(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_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::buildLoginDialog(QWebView *browser)
293 qDebug() << __PRETTY_FUNCTION__;
295 if (!m_loginDialog) {
296 m_loginDialog = new QDialog(this);
298 m_loginDialog->setWindowTitle(tr("Login"));
299 m_loginDialog->setLayout(new QVBoxLayout());
300 m_loginDialog->layout()->addWidget(browser);
301 m_loginDialog->layout()->setContentsMargins(QMargins()); // zero margins
302 connect(m_loginDialog, SIGNAL(rejected()), this, SLOT(destroyLoginDialog()));
307 m_loginDialog->show();
310 void MainWindow::buildMap()
312 qDebug() << __PRETTY_FUNCTION__;
314 m_mapView = new MapView(this);
316 buildZoomButtonPanel();
319 buildFullScreenButton();
320 buildIndicatorButtonPanel();
323 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
324 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
326 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
327 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
329 connect(m_mapView, SIGNAL(viewResized(QSize)),
330 this, SIGNAL(mapViewResized(QSize)));
332 connect(m_mapView, SIGNAL(viewResized(QSize)),
333 this, SLOT(drawFullScreenButton(QSize)));
335 connect(m_mapView, SIGNAL(viewResized(QSize)),
336 this, SLOT(drawMapScale(QSize)));
338 connect(m_mapView, SIGNAL(viewResized(QSize)),
339 this, SLOT(moveCrosshair()));
341 connect(this, SIGNAL(zoomLevelChanged(int)),
342 m_mapView, SLOT(setZoomLevel(int)));
344 connect(m_mapView, SIGNAL(viewZoomFinished()),
345 this, SIGNAL(viewZoomFinished()));
347 connect(m_mapView, SIGNAL(zoomIn()),
348 this, SIGNAL(zoomIn()));
351 void MainWindow::buildMapScale()
353 m_mapScale = new MapScale(this);
354 connect(this, SIGNAL(newMapResolution(qreal)),
355 m_mapScale, SLOT(updateMapResolution(qreal)));
358 void MainWindow::buildMeetPeoplePanel()
360 qDebug() << __PRETTY_FUNCTION__;
362 m_meetPeoplePanel = new MeetPeoplePanel(this);
364 connect(this, SIGNAL(friendImageReady(QString,QPixmap)),
365 m_meetPeoplePanel, SLOT(setImage(QString,QPixmap)));
367 connect(this, SIGNAL(interestingPeopleReceived(QList<User>&,QList<User>&)),
368 m_meetPeoplePanel, SLOT(populateInterestingPeopleListView(QList<User>&,QList<User>&)));
370 connect(m_meetPeoplePanel, SIGNAL(requestInterestingPeople()),
371 this, SIGNAL(requestInterestingPeople()));
373 connect(m_meetPeoplePanel, SIGNAL(requestInterestingPeopleSearch()),
374 this, SLOT(startPeopleSearch()));
376 connect(m_meetPeoplePanel, SIGNAL(findPerson(GeoCoordinate)),
377 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
379 connect(m_meetPeoplePanel, SIGNAL(requestMessageDialog(QPair<QString, QString>)),
380 this, SIGNAL(requestMessageDialog(QPair<QString, QString>)));
382 connect(m_meetPeoplePanel, SIGNAL(requestShowFriend(QList<QString>)),
383 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
386 void MainWindow::buildMessagePanel()
388 qDebug() << __PRETTY_FUNCTION__;
390 m_messagePanel = new MessagePanel(this);
392 connect(this, SIGNAL(messagesReceived(QList<Message>&, QList<Message>&)),
393 m_messagePanel, SLOT(populateMessageListView(QList<Message>&, QList<Message>&)));
395 connect(m_messagePanel, SIGNAL(requestMessages()),
396 this, SIGNAL(requestMessages()));
398 connect(this, SIGNAL(friendImageReady(QString,QPixmap)),
399 m_messagePanel, SLOT(setImage(QString,QPixmap)));
401 connect(m_messagePanel, SIGNAL(requestRemoveMessage(QString)),
402 this, SIGNAL(requestRemoveMessage(QString)));
404 connect(m_messagePanel, SIGNAL(findFriend(GeoCoordinate)),
405 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
407 connect(m_messagePanel, SIGNAL(requestMessageDialog(QPair<QString, QString>)),
408 this, SIGNAL(requestMessageDialog(QPair<QString, QString>)));
411 void MainWindow::buildOsmLicense()
413 qDebug() << __PRETTY_FUNCTION__;
415 m_osmLicense = new QLabel(this);
416 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
417 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
418 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
419 m_osmLicense->setFont(QFont("Nokia Sans", 9));
420 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
421 m_osmLicense->fontMetrics().height());
423 connect(m_mapView, SIGNAL(viewResized(QSize)),
424 this, SLOT(drawOsmLicense(QSize)));
427 void MainWindow::buildPanels()
429 qDebug() << __PRETTY_FUNCTION__;
431 buildUserInfoPanel();
432 buildFriendListPanel();
433 buildLocationSearchPanel();
435 buildMeetPeoplePanel();
438 m_tabbedPanel = new TabbedPanel(this);
440 //Save Situare related tab indexes so tabs can be enabled/disabled when logged in/out
441 m_situareTabsIndexes.append(
442 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png")));
443 m_situareTabsIndexes.append(
444 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png")));
446 // m_tabbedPanel->addTab(m_locationSearchPanel, QIcon(":/res/images/location_search.png"));
447 // m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
448 m_situareTabsIndexes.append(
449 m_tabbedPanel->addTab(m_meetPeoplePanel, QIcon(":/res/images/meet_people.png")));
450 m_situareTabsIndexes.append(
451 m_tabbedPanel->addTab(m_messagePanel, QIcon(":/res/images/message.png")));
453 connect(m_mapView, SIGNAL(viewResized(QSize)),
454 m_tabbedPanel, SLOT(resizePanel(QSize)));
456 connect(m_friendsListPanel, SIGNAL(openPanelRequested(QWidget*)),
457 m_tabbedPanel, SLOT(openPanel(QWidget*)));
459 connect(m_routingPanel, SIGNAL(openPanelRequested(QWidget*)),
460 m_tabbedPanel, SLOT(openPanel(QWidget*)));
462 connect(m_tabbedPanel, SIGNAL(panelClosed()),
463 m_friendsListPanel, SLOT(anyPanelClosed()));
465 connect(m_tabbedPanel, SIGNAL(panelOpened()),
466 m_friendsListPanel, SLOT(anyPanelOpened()));
468 connect(m_tabbedPanel, SIGNAL(panelClosed()),
469 m_routingPanel, SLOT(clearListsSelections()));
471 connect(m_tabbedPanel, SIGNAL(panelClosed()),
472 m_mapView, SLOT(disableCenterShift()));
474 connect(m_tabbedPanel, SIGNAL(panelOpened()),
475 m_mapView, SLOT(enableCenterShift()));
477 connect(m_tabbedPanel, SIGNAL(panelClosed()),
478 m_userInfoPanel, SIGNAL(collapse()));
480 connect(m_tabbedPanel, SIGNAL(currentChanged(int)),
481 m_userInfoPanel, SIGNAL(collapse()));
483 connect(m_tabbedPanel, SIGNAL(panelClosed()),
484 m_meetPeoplePanel, SLOT(anyPanelClosed()));
486 connect(m_tabbedPanel, SIGNAL(panelClosed()),
487 m_messagePanel, SLOT(anyPanelClosed()));
489 // signals for showing and hiding list item context buttons
490 connect(m_userInfoPanel, SIGNAL(listItemSelectionChanged(bool)),
491 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
493 connect(m_friendsListPanel, SIGNAL(listItemSelectionChanged(bool)),
494 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
496 connect(m_locationSearchPanel, SIGNAL(listItemSelectionChanged(bool)),
497 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
499 connect(m_routingPanel, SIGNAL(listItemSelectionChanged(bool)),
500 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
502 connect(m_meetPeoplePanel, SIGNAL(listItemSelectionChanged(bool)),
503 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
505 connect(m_messagePanel, SIGNAL(listItemSelectionChanged(bool)),
506 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
509 void MainWindow::buildRoutingPanel()
511 qDebug() << __PRETTY_FUNCTION__;
513 m_routingPanel = new RoutingPanel(this);
515 connect(m_routingPanel, SIGNAL(routeToCursor()),
516 this, SIGNAL(routeToCursor()));
518 connect(this, SIGNAL(routeParsed(Route&)),
519 m_routingPanel, SLOT(setRoute(Route&)));
521 connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
522 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
524 connect(m_routingPanel, SIGNAL(clearRoute()),
525 this, SIGNAL(clearRoute()));
528 void MainWindow::buildUserInfoPanel()
530 qDebug() << __PRETTY_FUNCTION__;
532 m_userInfoPanel = new UserInfoPanel(this);
534 connect(this, SIGNAL(userLocationReady(User*)),
535 m_userInfoPanel, SLOT(userDataReceived(User*)));
537 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
538 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
540 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
541 this, SIGNAL(refreshUserData()));
543 connect(this, SIGNAL(userImageReady(QString,QPixmap)),
544 m_userInfoPanel, SLOT(setImage(QString,QPixmap)));
546 connect(m_userInfoPanel, SIGNAL(addTags(QStringList)),
547 this, SIGNAL(addTags(QStringList)));
549 connect(m_userInfoPanel, SIGNAL(removeTags(QStringList)),
550 this, SIGNAL(removeTags(QStringList)));
552 connect(this, SIGNAL(popularTagsReceived(QHash<QString,QString>&)),
553 m_userInfoPanel, SLOT(populatePopularTags(QHash<QString,QString>&)));
555 connect(m_userInfoPanel, SIGNAL(requestPopularTags()),
556 this, SIGNAL(requestPopularTags()));
559 void MainWindow::buildZoomButtonPanel()
561 qDebug() << __PRETTY_FUNCTION__;
563 m_zoomButtonPanel = new ZoomButtonPanel(this);
565 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
566 this, SIGNAL(zoomIn()));
568 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
569 this, SIGNAL(zoomOut()));
571 connect(this, SIGNAL(zoomLevelChanged(int)),
572 m_zoomButtonPanel, SLOT(resetButtons()));
574 connect(this, SIGNAL(maxZoomLevelReached()),
575 m_zoomButtonPanel, SLOT(disableZoomInButton()));
577 connect(this, SIGNAL(minZoomLevelReached()),
578 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
580 connect(m_mapView, SIGNAL(viewResized(QSize)),
581 m_zoomButtonPanel, SLOT(screenResized(QSize)));
583 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
584 this, SIGNAL(draggingModeTriggered()));
587 void MainWindow::createMenus()
589 qDebug() << __PRETTY_FUNCTION__;
592 m_loginAct = new QAction(tr("Login"), this);
593 connect(m_loginAct, SIGNAL(triggered()),
594 this, SIGNAL(loginActionPressed()));
597 m_toSettingsAct = new QAction(tr("Settings"), this);
598 connect(m_toSettingsAct, SIGNAL(triggered()),
599 this, SLOT(openSettingsDialog()));
602 m_gpsToggleAct = new QAction(tr("GPS"), this);
603 m_gpsToggleAct->setCheckable(true);
605 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
606 this, SIGNAL(gpsTriggered(bool)));
608 // build the actual menu
609 m_viewMenu = menuBar()->addMenu(tr("Main"));
610 m_viewMenu->addAction(m_loginAct);
611 m_viewMenu->addAction(m_toSettingsAct);
612 m_viewMenu->addAction(m_gpsToggleAct);
613 m_viewMenu->setObjectName(tr("Menu"));
616 void MainWindow::destroyLoginDialog()
618 qDebug() << __PRETTY_FUNCTION__;
621 m_loginDialog->hide();
622 m_loginDialog->deleteLater();
627 void MainWindow::dialogFinished(int status)
629 qDebug() << __PRETTY_FUNCTION__;
631 QDialog *dialog = m_queue.takeFirst();
632 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
633 MessageDialog *messageDialog = qobject_cast<MessageDialog *>(dialog);
635 if ((searchDialog) && (status != 0)) {
636 if (searchDialog->type() == SearchDialog::Location)
637 emit searchForLocation(searchDialog->input());
638 else if (searchDialog->type() == SearchDialog::PeopleTag)
639 emit requestSearchPeopleByTag(searchDialog->input());
640 } else if ((messageDialog) && (status != 0)) {
641 emit sendMessage(messageDialog->input().first, messageDialog->input().second,
642 messageDialog->isAddCoordinatesSelected());
645 dialog->deleteLater();
647 if(!m_error_queue.isEmpty() && m_errorShown == false) {
648 showErrorInformationBox();
650 if(!m_queue.isEmpty()) {
651 showInformationBox();
656 void MainWindow::drawFullScreenButton(const QSize &size)
658 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
660 if (m_fullScreenButton) {
661 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
662 size.height() - m_fullScreenButton->size().height());
666 void MainWindow::drawMapScale(const QSize &size)
668 qDebug() << __PRETTY_FUNCTION__;
670 const int LEFT_SCALE_MARGIN = 10;
671 const int BOTTOM_SCALE_MARGIN = 2;
673 m_mapScale->move(LEFT_SCALE_MARGIN,
674 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
677 void MainWindow::drawOsmLicense(const QSize &size)
679 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
681 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
683 size.height() - m_osmLicense->fontMetrics().height());
686 void MainWindow::errorDialogFinished(int status)
688 qDebug() << __PRETTY_FUNCTION__;
691 QDialog *dialog = m_error_queue.takeFirst();
693 dialog->deleteLater();
694 m_errorShown = false;
696 if(!m_error_queue.isEmpty())
697 showErrorInformationBox();
698 else if(!m_queue.isEmpty())
699 showInformationBox();
702 void MainWindow::gpsTimeout()
704 qDebug() << __PRETTY_FUNCTION__;
706 buildInformationBox(tr("GPS timeout"));
709 void MainWindow::grabZoomKeys(bool grab)
711 qDebug() << __PRETTY_FUNCTION__;
714 // Can't grab keys unless we have a window id
718 unsigned long val = (grab) ? 1 : 0;
719 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
723 XChangeProperty (QX11Info::display(),
729 reinterpret_cast<unsigned char *>(&val),
733 #endif // Q_WS_MAEMO_5
736 void MainWindow::keyPressEvent(QKeyEvent* event)
738 qDebug() << __PRETTY_FUNCTION__;
740 switch (event->key()) {
751 QWidget::keyPressEvent(event);
754 void MainWindow::loggedIn(bool logged)
756 qDebug() << __PRETTY_FUNCTION__;
761 m_loginAct->setText(tr("Logout"));
763 m_loginAct->setText(tr("Login"));
764 m_userInfoPanel->showUserInfo(false);
765 m_updateLocationController->clear();
767 updateItemVisibility(logged);
770 void MainWindow::mapCenterHorizontalShiftingChanged(int shifting)
772 m_mapCenterHorizontalShifting = shifting;
776 void MainWindow::moveCrosshair()
778 qDebug() << __PRETTY_FUNCTION__;
781 int mapHeight = m_mapView->size().height();
782 int mapWidth = m_mapView->size().width();
783 m_crosshair->move(mapWidth / 2 - m_crosshair->pixmap()->width() / 2
784 - m_mapCenterHorizontalShifting,
785 mapHeight / 2 - m_crosshair->pixmap()->height() / 2);
789 void MainWindow::openSettingsDialog()
791 qDebug() << __PRETTY_FUNCTION__;
793 SettingsDialog *settingsDialog = new SettingsDialog(this);
794 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
795 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
797 settingsDialog->show();
800 void MainWindow::queueDialog(QDialog *dialog)
802 qDebug() << __PRETTY_FUNCTION__;
804 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
805 if(dialog->isModal()) {
806 m_error_queue.append(dialog);
808 m_queue.append(dialog);
811 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
812 if(m_error_queue.count() == 1 && m_errorShown == false)
813 showErrorInformationBox();
814 else if(m_queue.count() == 1 && m_errorShown == false)
815 showInformationBox();
818 void MainWindow::readAutomaticLocationUpdateSettings()
820 qDebug() << __PRETTY_FUNCTION__;
822 QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
823 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
824 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
827 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
829 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
831 emit enableAutomaticLocationUpdate(false);
835 void MainWindow::setCrosshairVisibility(bool visibility)
837 qDebug() << __PRETTY_FUNCTION__;
847 void MainWindow::setGPSButtonEnabled(bool enabled)
849 qDebug() << __PRETTY_FUNCTION__;
851 m_gpsToggleAct->setChecked(enabled);
854 void MainWindow::setIndicatorButtonEnabled(bool enabled)
856 qDebug() << __PRETTY_FUNCTION__;
858 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
861 void MainWindow::setMapViewScene(QGraphicsScene *scene)
863 qDebug() << __PRETTY_FUNCTION__;
865 m_mapView->setScene(scene);
868 void MainWindow::settingsDialogAccepted()
870 qDebug() << __PRETTY_FUNCTION__;
872 readAutomaticLocationUpdateSettings();
875 void MainWindow::showContactDialog(const QString &guid)
877 qDebug() << __PRETTY_FUNCTION__;
879 #if defined(Q_WS_MAEMO_5) & defined(ARMEL)
880 OssoABookDialog::showContactDialog(guid);
883 buildInformationBox(tr("Contact dialog works only on phone!"), true);
887 void MainWindow::showMessageDialog(const QPair<QString, QString> &receiver)
889 qDebug() << __PRETTY_FUNCTION__;
891 MessageDialog *messageDialog = new MessageDialog(receiver.first, receiver.second);
892 queueDialog(messageDialog);
895 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
897 qDebug() << __PRETTY_FUNCTION__;
899 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
900 tr("Automatic location update"), text,
901 QMessageBox::Yes | QMessageBox::No |
902 QMessageBox::Cancel, this);
903 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
904 this, SLOT(automaticUpdateDialogFinished(int)));
906 m_automaticUpdateLocationDialog->show();
909 void MainWindow::showErrorInformationBox()
911 qDebug() << __PRETTY_FUNCTION__;
913 if(m_error_queue.count()) {
915 QDialog *dialog = m_error_queue.first();
916 connect(dialog, SIGNAL(finished(int)),
917 this, SLOT(errorDialogFinished(int)));
922 void MainWindow::showInformationBox()
924 qDebug() << __PRETTY_FUNCTION__;
926 if(m_queue.count()) {
927 QDialog *dialog = m_queue.first();
928 connect(dialog, SIGNAL(finished(int)),
929 this, SLOT(dialogFinished(int)));
934 void MainWindow::showUpdateLocationDialog()
936 qDebug() << __PRETTY_FUNCTION__;
938 UpdateLocationDialog *updateLocationDialog
939 = new UpdateLocationDialog(m_updateLocationController, this);
941 connect(this, SIGNAL(reverseGeoReady(QString)),
942 updateLocationDialog, SLOT(setAddress(QString)));
944 updateLocationDialog->show();
946 emit requestReverseGeo();
949 void MainWindow::startLocationSearch()
951 qDebug() << __PRETTY_FUNCTION__;
953 SearchDialog *searchDialog = new SearchDialog(SearchDialog::Location);
954 queueDialog(searchDialog);
957 void MainWindow::startPeopleSearch()
959 qDebug() << __PRETTY_FUNCTION__;
961 SearchDialog *searchDialog = new SearchDialog(SearchDialog::PeopleTag);
962 queueDialog(searchDialog);
965 void MainWindow::sslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
967 qDebug() << __PRETTY_FUNCTION__;
970 reply->ignoreSslErrors();
973 void MainWindow::toggleFullScreen()
975 qDebug() << __PRETTY_FUNCTION__;
977 if(windowState() == Qt::WindowNoState)
983 void MainWindow::toggleProgressIndicator(bool value)
985 qDebug() << __PRETTY_FUNCTION__;
989 m_progressIndicatorCount++;
990 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
992 if(m_progressIndicatorCount > 0)
993 m_progressIndicatorCount--;
995 if(m_progressIndicatorCount == 0)
996 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
1000 #endif // Q_WS_MAEMO_5
1003 void MainWindow::updateItemVisibility(bool loggedIn)
1005 qDebug() << __PRETTY_FUNCTION__;
1007 m_tabbedPanel->setTabsEnabled(m_situareTabsIndexes, loggedIn);