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 &)));
197 connect(m_friendsListPanel, SIGNAL(requestMessageDialog(QPair<QString, QString>)),
198 this, SIGNAL(requestMessageDialog(QPair<QString, QString>)));
201 void MainWindow::buildFullScreenButton()
203 qDebug() << __PRETTY_FUNCTION__;
206 m_fullScreenButton = new FullScreenButton(this);
208 if (m_fullScreenButton) {
209 connect(m_fullScreenButton, SIGNAL(clicked()),
210 this, SLOT(toggleFullScreen()));
212 connect(qApp, SIGNAL(showFullScreenButton()),
213 m_fullScreenButton, SLOT(invoke()));
215 #endif // Q_WS_MAEMO_5
218 void MainWindow::buildIndicatorButtonPanel()
220 qDebug() << __PRETTY_FUNCTION__;
222 m_indicatorButtonPanel = new IndicatorButtonPanel(this);
224 connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
225 this, SIGNAL(autoCenteringTriggered(bool)));
227 connect(m_mapView, SIGNAL(viewResized(QSize)),
228 m_indicatorButtonPanel, SLOT(screenResized(QSize)));
230 connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
231 m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
233 connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
234 this, SIGNAL(draggingModeTriggered()));
237 void MainWindow::buildInformationBox(const QString &message, bool modal)
239 qDebug() << __PRETTY_FUNCTION__;
241 QString errorMessage = message;
245 QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
248 msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
249 // extra line changes are needed to make error notes broader
250 errorMessage.prepend("\n");
251 errorMessage.append("\n");
253 msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
255 QLabel *label = new QLabel(msgBox);
256 label->setAlignment(Qt::AlignCenter);
257 label->setText(errorMessage);
258 msgBox->setWidget(label);
260 QMessageBox *msgBox = new QMessageBox(this);
261 msgBox->button(QMessageBox::Ok);
262 msgBox->setText(errorMessage);
263 msgBox->setModal(modal);
269 void MainWindow::buildLocationSearchPanel()
271 qDebug() << __PRETTY_FUNCTION__;
273 m_locationSearchPanel = new LocationSearchPanel(this);
275 connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
276 m_locationSearchPanel, SLOT(populateLocationListView(const QList<Location>&)));
278 connect(m_locationSearchPanel, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
279 this, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
281 connect(m_locationSearchPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
282 this, SIGNAL(routeTo(const GeoCoordinate&)));
284 connect(m_locationSearchPanel, SIGNAL(requestSearchLocation()),
285 this, SLOT(startLocationSearch()));
287 connect(this, SIGNAL(searchForLocation(QString)),
288 m_locationSearchPanel, SLOT(prependSearchHistory(QString)));
290 connect(m_locationSearchPanel, SIGNAL(searchHistoryItemClicked(QString)),
291 this, SIGNAL(searchHistoryItemClicked(QString)));
294 void MainWindow::buildLoginDialog(QWebView *browser)
296 qDebug() << __PRETTY_FUNCTION__;
298 if (!m_loginDialog) {
299 m_loginDialog = new QDialog(this);
301 m_loginDialog->setWindowTitle(tr("Login"));
302 m_loginDialog->setLayout(new QVBoxLayout());
303 m_loginDialog->layout()->addWidget(browser);
304 m_loginDialog->layout()->setContentsMargins(QMargins()); // zero margins
305 connect(m_loginDialog, SIGNAL(rejected()), this, SLOT(destroyLoginDialog()));
310 m_loginDialog->show();
313 void MainWindow::buildMap()
315 qDebug() << __PRETTY_FUNCTION__;
317 m_mapView = new MapView(this);
319 buildZoomButtonPanel();
322 buildFullScreenButton();
323 buildIndicatorButtonPanel();
326 connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
327 this, SIGNAL(mapViewScrolled(SceneCoordinate)));
329 connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
330 m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
332 connect(m_mapView, SIGNAL(viewResized(QSize)),
333 this, SIGNAL(mapViewResized(QSize)));
335 connect(m_mapView, SIGNAL(viewResized(QSize)),
336 this, SLOT(drawFullScreenButton(QSize)));
338 connect(m_mapView, SIGNAL(viewResized(QSize)),
339 this, SLOT(drawMapScale(QSize)));
341 connect(m_mapView, SIGNAL(viewResized(QSize)),
342 this, SLOT(moveCrosshair()));
344 connect(this, SIGNAL(zoomLevelChanged(int)),
345 m_mapView, SLOT(setZoomLevel(int)));
347 connect(m_mapView, SIGNAL(viewZoomFinished()),
348 this, SIGNAL(viewZoomFinished()));
350 connect(m_mapView, SIGNAL(zoomIn()),
351 this, SIGNAL(zoomIn()));
354 void MainWindow::buildMapScale()
356 m_mapScale = new MapScale(this);
357 connect(this, SIGNAL(newMapResolution(qreal)),
358 m_mapScale, SLOT(updateMapResolution(qreal)));
361 void MainWindow::buildMeetPeoplePanel()
363 qDebug() << __PRETTY_FUNCTION__;
365 m_meetPeoplePanel = new MeetPeoplePanel(this);
367 connect(this, SIGNAL(friendImageReady(QString,QPixmap)),
368 m_meetPeoplePanel, SLOT(setImage(QString,QPixmap)));
370 connect(this, SIGNAL(interestingPeopleReceived(QList<User>&,QList<User>&)),
371 m_meetPeoplePanel, SLOT(populateInterestingPeopleListView(QList<User>&,QList<User>&)));
373 connect(m_meetPeoplePanel, SIGNAL(requestInterestingPeople()),
374 this, SIGNAL(requestInterestingPeople()));
376 connect(m_meetPeoplePanel, SIGNAL(requestInterestingPeopleSearch()),
377 this, SLOT(startPeopleSearch()));
379 connect(m_meetPeoplePanel, SIGNAL(findPerson(GeoCoordinate)),
380 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
382 connect(m_meetPeoplePanel, SIGNAL(requestMessageDialog(QPair<QString, QString>)),
383 this, SIGNAL(requestMessageDialog(QPair<QString, QString>)));
385 connect(m_meetPeoplePanel, SIGNAL(requestShowFriend(QList<QString>)),
386 m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
389 void MainWindow::buildMessagePanel()
391 qDebug() << __PRETTY_FUNCTION__;
393 m_messagePanel = new MessagePanel(this);
395 connect(this, SIGNAL(messagesReceived(QList<Message>&, QList<Message>&)),
396 m_messagePanel, SLOT(populateMessageListView(QList<Message>&, QList<Message>&)));
398 connect(m_messagePanel, SIGNAL(requestMessages()),
399 this, SIGNAL(requestMessages()));
401 connect(this, SIGNAL(friendImageReady(QString,QPixmap)),
402 m_messagePanel, SLOT(setImage(QString,QPixmap)));
404 connect(m_messagePanel, SIGNAL(requestRemoveMessage(QString)),
405 this, SIGNAL(requestRemoveMessage(QString)));
407 connect(m_messagePanel, SIGNAL(findFriend(GeoCoordinate)),
408 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
410 connect(m_messagePanel, SIGNAL(requestMessageDialog(QPair<QString, QString>)),
411 this, SIGNAL(requestMessageDialog(QPair<QString, QString>)));
414 void MainWindow::buildOsmLicense()
416 qDebug() << __PRETTY_FUNCTION__;
418 m_osmLicense = new QLabel(this);
419 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
420 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
421 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
422 m_osmLicense->setFont(QFont("Nokia Sans", 9));
423 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
424 m_osmLicense->fontMetrics().height());
426 connect(m_mapView, SIGNAL(viewResized(QSize)),
427 this, SLOT(drawOsmLicense(QSize)));
430 void MainWindow::buildPanels()
432 qDebug() << __PRETTY_FUNCTION__;
434 buildUserInfoPanel();
435 buildFriendListPanel();
436 buildLocationSearchPanel();
438 buildMeetPeoplePanel();
441 m_tabbedPanel = new TabbedPanel(this);
443 //Save Situare related tab indexes so tabs can be enabled/disabled when logged in/out
444 m_situareTabsIndexes.append(
445 m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png")));
446 m_situareTabsIndexes.append(
447 m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png")));
449 // m_tabbedPanel->addTab(m_locationSearchPanel, QIcon(":/res/images/location_search.png"));
450 // m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
451 m_situareTabsIndexes.append(
452 m_tabbedPanel->addTab(m_meetPeoplePanel, QIcon(":/res/images/meet_people.png")));
453 m_situareTabsIndexes.append(
454 m_tabbedPanel->addTab(m_messagePanel, QIcon(":/res/images/message.png")));
456 connect(m_mapView, SIGNAL(viewResized(QSize)),
457 m_tabbedPanel, SLOT(resizePanel(QSize)));
459 connect(m_friendsListPanel, SIGNAL(openPanelRequested(QWidget*)),
460 m_tabbedPanel, SLOT(openPanel(QWidget*)));
462 connect(m_routingPanel, SIGNAL(openPanelRequested(QWidget*)),
463 m_tabbedPanel, SLOT(openPanel(QWidget*)));
465 connect(m_tabbedPanel, SIGNAL(panelClosed()),
466 m_friendsListPanel, SLOT(anyPanelClosed()));
468 connect(m_tabbedPanel, SIGNAL(panelOpened()),
469 m_friendsListPanel, SLOT(anyPanelOpened()));
471 connect(m_tabbedPanel, SIGNAL(panelClosed()),
472 m_routingPanel, SLOT(clearListsSelections()));
474 connect(m_tabbedPanel, SIGNAL(panelClosed()),
475 m_mapView, SLOT(disableCenterShift()));
477 connect(m_tabbedPanel, SIGNAL(panelOpened()),
478 m_mapView, SLOT(enableCenterShift()));
480 connect(m_tabbedPanel, SIGNAL(panelClosed()),
481 m_userInfoPanel, SIGNAL(collapse()));
483 connect(m_tabbedPanel, SIGNAL(currentChanged(int)),
484 m_userInfoPanel, SIGNAL(collapse()));
486 connect(m_tabbedPanel, SIGNAL(panelClosed()),
487 m_meetPeoplePanel, SLOT(anyPanelClosed()));
489 connect(m_tabbedPanel, SIGNAL(panelClosed()),
490 m_messagePanel, SLOT(anyPanelClosed()));
492 // signals for showing and hiding list item context buttons
493 connect(m_userInfoPanel, SIGNAL(listItemSelectionChanged(bool)),
494 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
496 connect(m_friendsListPanel, SIGNAL(listItemSelectionChanged(bool)),
497 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
499 connect(m_locationSearchPanel, SIGNAL(listItemSelectionChanged(bool)),
500 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
502 connect(m_routingPanel, SIGNAL(listItemSelectionChanged(bool)),
503 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
505 connect(m_meetPeoplePanel, SIGNAL(listItemSelectionChanged(bool)),
506 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
508 connect(m_messagePanel, SIGNAL(listItemSelectionChanged(bool)),
509 m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
512 void MainWindow::buildRoutingPanel()
514 qDebug() << __PRETTY_FUNCTION__;
516 m_routingPanel = new RoutingPanel(this);
518 connect(m_routingPanel, SIGNAL(routeToCursor()),
519 this, SIGNAL(routeToCursor()));
521 connect(this, SIGNAL(routeParsed(Route&)),
522 m_routingPanel, SLOT(setRoute(Route&)));
524 connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
525 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
527 connect(m_routingPanel, SIGNAL(clearRoute()),
528 this, SIGNAL(clearRoute()));
531 void MainWindow::buildUserInfoPanel()
533 qDebug() << __PRETTY_FUNCTION__;
535 m_userInfoPanel = new UserInfoPanel(this);
537 connect(this, SIGNAL(userLocationReady(User*)),
538 m_userInfoPanel, SLOT(userDataReceived(User*)));
540 connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
541 this, SIGNAL(centerToCoordinates(GeoCoordinate)));
543 connect(m_userInfoPanel, SIGNAL(refreshUserData()),
544 this, SIGNAL(refreshUserData()));
546 connect(m_userInfoPanel, SIGNAL(updateLocationMessageButtonClicked()),
547 this, SLOT(showUpdateLocationDialog()));
549 connect(this, SIGNAL(userImageReady(QString,QPixmap)),
550 m_userInfoPanel, SLOT(setImage(QString,QPixmap)));
552 connect(m_userInfoPanel, SIGNAL(addTags(QStringList)),
553 this, SIGNAL(addTags(QStringList)));
555 connect(m_userInfoPanel, SIGNAL(removeTags(QStringList)),
556 this, SIGNAL(removeTags(QStringList)));
558 connect(this, SIGNAL(popularTagsReceived(QHash<QString,QString>&)),
559 m_userInfoPanel, SLOT(populatePopularTags(QHash<QString,QString>&)));
561 connect(m_userInfoPanel, SIGNAL(requestPopularTags()),
562 this, SIGNAL(requestPopularTags()));
564 connect(this, SIGNAL(userTagsReceived(QHash<QString,QString>&)),
565 m_userInfoPanel, SLOT(userTagsReceived(QHash<QString,QString>&)));
568 void MainWindow::buildZoomButtonPanel()
570 qDebug() << __PRETTY_FUNCTION__;
572 m_zoomButtonPanel = new ZoomButtonPanel(this);
574 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
575 this, SIGNAL(zoomIn()));
577 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
578 this, SIGNAL(zoomOut()));
580 connect(this, SIGNAL(zoomLevelChanged(int)),
581 m_zoomButtonPanel, SLOT(resetButtons()));
583 connect(this, SIGNAL(maxZoomLevelReached()),
584 m_zoomButtonPanel, SLOT(disableZoomInButton()));
586 connect(this, SIGNAL(minZoomLevelReached()),
587 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
589 connect(m_mapView, SIGNAL(viewResized(QSize)),
590 m_zoomButtonPanel, SLOT(screenResized(QSize)));
592 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
593 this, SIGNAL(draggingModeTriggered()));
596 void MainWindow::createMenus()
598 qDebug() << __PRETTY_FUNCTION__;
601 m_loginAct = new QAction(tr("Login"), this);
602 connect(m_loginAct, SIGNAL(triggered()),
603 this, SIGNAL(loginActionPressed()));
606 m_toSettingsAct = new QAction(tr("Settings"), this);
607 connect(m_toSettingsAct, SIGNAL(triggered()),
608 this, SLOT(openSettingsDialog()));
611 m_gpsToggleAct = new QAction(tr("GPS"), this);
612 m_gpsToggleAct->setCheckable(true);
614 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
615 this, SIGNAL(gpsTriggered(bool)));
617 // build the actual menu
618 m_viewMenu = menuBar()->addMenu(tr("Main"));
619 m_viewMenu->addAction(m_loginAct);
620 m_viewMenu->addAction(m_toSettingsAct);
621 m_viewMenu->addAction(m_gpsToggleAct);
622 m_viewMenu->setObjectName(tr("Menu"));
625 void MainWindow::destroyLoginDialog()
627 qDebug() << __PRETTY_FUNCTION__;
630 m_loginDialog->hide();
631 m_loginDialog->deleteLater();
636 void MainWindow::dialogFinished(int status)
638 qDebug() << __PRETTY_FUNCTION__;
640 QDialog *dialog = m_queue.takeFirst();
641 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
642 MessageDialog *messageDialog = qobject_cast<MessageDialog *>(dialog);
644 if ((searchDialog) && (status != 0)) {
645 if (searchDialog->type() == SearchDialog::Location)
646 emit searchForLocation(searchDialog->input());
647 else if (searchDialog->type() == SearchDialog::PeopleTag)
648 emit requestSearchPeopleByTag(searchDialog->input());
649 } else if ((messageDialog) && (status != 0)) {
650 emit sendMessage(messageDialog->input().first, messageDialog->input().second,
651 messageDialog->isAddCoordinatesSelected());
654 dialog->deleteLater();
656 if(!m_error_queue.isEmpty() && m_errorShown == false) {
657 showErrorInformationBox();
659 if(!m_queue.isEmpty()) {
660 showInformationBox();
665 void MainWindow::drawFullScreenButton(const QSize &size)
667 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
669 if (m_fullScreenButton) {
670 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
671 size.height() - m_fullScreenButton->size().height());
675 void MainWindow::drawMapScale(const QSize &size)
677 qDebug() << __PRETTY_FUNCTION__;
679 const int LEFT_SCALE_MARGIN = 10;
680 const int BOTTOM_SCALE_MARGIN = 2;
682 m_mapScale->move(LEFT_SCALE_MARGIN,
683 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
686 void MainWindow::drawOsmLicense(const QSize &size)
688 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
690 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
692 size.height() - m_osmLicense->fontMetrics().height());
695 void MainWindow::errorDialogFinished(int status)
697 qDebug() << __PRETTY_FUNCTION__;
700 QDialog *dialog = m_error_queue.takeFirst();
702 dialog->deleteLater();
703 m_errorShown = false;
705 if(!m_error_queue.isEmpty())
706 showErrorInformationBox();
707 else if(!m_queue.isEmpty())
708 showInformationBox();
711 void MainWindow::gpsTimeout()
713 qDebug() << __PRETTY_FUNCTION__;
715 buildInformationBox(tr("GPS timeout"));
718 void MainWindow::grabZoomKeys(bool grab)
720 qDebug() << __PRETTY_FUNCTION__;
723 // Can't grab keys unless we have a window id
727 unsigned long val = (grab) ? 1 : 0;
728 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
732 XChangeProperty (QX11Info::display(),
738 reinterpret_cast<unsigned char *>(&val),
742 #endif // Q_WS_MAEMO_5
745 void MainWindow::keyPressEvent(QKeyEvent* event)
747 qDebug() << __PRETTY_FUNCTION__;
749 switch (event->key()) {
760 QWidget::keyPressEvent(event);
763 void MainWindow::loggedIn(bool logged)
765 qDebug() << __PRETTY_FUNCTION__;
770 m_loginAct->setText(tr("Logout"));
772 m_loginAct->setText(tr("Login"));
773 m_userInfoPanel->showUserInfo(false);
774 m_updateLocationController->clear();
776 updateItemVisibility(logged);
779 void MainWindow::mapCenterHorizontalShiftingChanged(int shifting)
781 m_mapCenterHorizontalShifting = shifting;
785 void MainWindow::moveCrosshair()
787 qDebug() << __PRETTY_FUNCTION__;
790 int mapHeight = m_mapView->size().height();
791 int mapWidth = m_mapView->size().width();
792 m_crosshair->move(mapWidth / 2 - m_crosshair->pixmap()->width() / 2
793 - m_mapCenterHorizontalShifting,
794 mapHeight / 2 - m_crosshair->pixmap()->height() / 2);
798 void MainWindow::openSettingsDialog()
800 qDebug() << __PRETTY_FUNCTION__;
802 SettingsDialog *settingsDialog = new SettingsDialog(this);
803 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
804 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
806 settingsDialog->show();
809 void MainWindow::queueDialog(QDialog *dialog)
811 qDebug() << __PRETTY_FUNCTION__;
813 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
814 if(dialog->isModal()) {
815 m_error_queue.append(dialog);
817 m_queue.append(dialog);
820 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
821 if(m_error_queue.count() == 1 && m_errorShown == false)
822 showErrorInformationBox();
823 else if(m_queue.count() == 1 && m_errorShown == false)
824 showInformationBox();
827 void MainWindow::readAutomaticLocationUpdateSettings()
829 qDebug() << __PRETTY_FUNCTION__;
831 QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
832 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
833 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
836 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
838 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
840 emit enableAutomaticLocationUpdate(false);
844 void MainWindow::setCrosshairVisibility(bool visibility)
846 qDebug() << __PRETTY_FUNCTION__;
856 void MainWindow::setGPSButtonEnabled(bool enabled)
858 qDebug() << __PRETTY_FUNCTION__;
860 m_gpsToggleAct->setChecked(enabled);
863 void MainWindow::setIndicatorButtonEnabled(bool enabled)
865 qDebug() << __PRETTY_FUNCTION__;
867 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
870 void MainWindow::setMapViewScene(QGraphicsScene *scene)
872 qDebug() << __PRETTY_FUNCTION__;
874 m_mapView->setScene(scene);
877 void MainWindow::settingsDialogAccepted()
879 qDebug() << __PRETTY_FUNCTION__;
881 readAutomaticLocationUpdateSettings();
884 void MainWindow::showContactDialog(const QString &guid)
886 qDebug() << __PRETTY_FUNCTION__;
888 #if defined(Q_WS_MAEMO_5) & defined(ARMEL)
889 OssoABookDialog::showContactDialog(guid);
892 buildInformationBox(tr("Contact dialog works only on phone!"), true);
896 void MainWindow::showMessageDialog(const QPair<QString, QString> &receiver)
898 qDebug() << __PRETTY_FUNCTION__;
900 MessageDialog *messageDialog = new MessageDialog(receiver.first, receiver.second);
901 queueDialog(messageDialog);
904 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
906 qDebug() << __PRETTY_FUNCTION__;
908 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
909 tr("Automatic location update"), text,
910 QMessageBox::Yes | QMessageBox::No |
911 QMessageBox::Cancel, this);
912 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
913 this, SLOT(automaticUpdateDialogFinished(int)));
915 m_automaticUpdateLocationDialog->show();
918 void MainWindow::showErrorInformationBox()
920 qDebug() << __PRETTY_FUNCTION__;
922 if(m_error_queue.count()) {
924 QDialog *dialog = m_error_queue.first();
925 connect(dialog, SIGNAL(finished(int)),
926 this, SLOT(errorDialogFinished(int)));
931 void MainWindow::showInformationBox()
933 qDebug() << __PRETTY_FUNCTION__;
935 if(m_queue.count()) {
936 QDialog *dialog = m_queue.first();
937 connect(dialog, SIGNAL(finished(int)),
938 this, SLOT(dialogFinished(int)));
943 void MainWindow::showUpdateLocationDialog()
945 qDebug() << __PRETTY_FUNCTION__;
947 UpdateLocationDialog *updateLocationDialog
948 = new UpdateLocationDialog(m_updateLocationController, this);
950 connect(this, SIGNAL(reverseGeoReady(QString)),
951 updateLocationDialog, SLOT(setAddress(QString)));
953 updateLocationDialog->show();
955 emit requestReverseGeo();
958 void MainWindow::startLocationSearch()
960 qDebug() << __PRETTY_FUNCTION__;
962 SearchDialog *searchDialog = new SearchDialog(SearchDialog::Location);
963 queueDialog(searchDialog);
966 void MainWindow::startPeopleSearch()
968 qDebug() << __PRETTY_FUNCTION__;
970 SearchDialog *searchDialog = new SearchDialog(SearchDialog::PeopleTag);
971 queueDialog(searchDialog);
974 void MainWindow::sslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
976 qDebug() << __PRETTY_FUNCTION__;
979 reply->ignoreSslErrors();
982 void MainWindow::toggleFullScreen()
984 qDebug() << __PRETTY_FUNCTION__;
986 if(windowState() == Qt::WindowNoState)
992 void MainWindow::toggleProgressIndicator(bool value)
994 qDebug() << __PRETTY_FUNCTION__;
998 m_progressIndicatorCount++;
999 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
1001 if(m_progressIndicatorCount > 0)
1002 m_progressIndicatorCount--;
1004 if(m_progressIndicatorCount == 0)
1005 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
1009 #endif // Q_WS_MAEMO_5
1012 void MainWindow::updateItemVisibility(bool loggedIn)
1014 qDebug() << __PRETTY_FUNCTION__;
1016 m_tabbedPanel->setTabsEnabled(m_situareTabsIndexes, loggedIn);