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()));
565 void MainWindow::buildZoomButtonPanel()
567 qDebug() << __PRETTY_FUNCTION__;
569 m_zoomButtonPanel = new ZoomButtonPanel(this);
571 connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
572 this, SIGNAL(zoomIn()));
574 connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
575 this, SIGNAL(zoomOut()));
577 connect(this, SIGNAL(zoomLevelChanged(int)),
578 m_zoomButtonPanel, SLOT(resetButtons()));
580 connect(this, SIGNAL(maxZoomLevelReached()),
581 m_zoomButtonPanel, SLOT(disableZoomInButton()));
583 connect(this, SIGNAL(minZoomLevelReached()),
584 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
586 connect(m_mapView, SIGNAL(viewResized(QSize)),
587 m_zoomButtonPanel, SLOT(screenResized(QSize)));
589 connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
590 this, SIGNAL(draggingModeTriggered()));
593 void MainWindow::createMenus()
595 qDebug() << __PRETTY_FUNCTION__;
598 m_loginAct = new QAction(tr("Login"), this);
599 connect(m_loginAct, SIGNAL(triggered()),
600 this, SIGNAL(loginActionPressed()));
603 m_toSettingsAct = new QAction(tr("Settings"), this);
604 connect(m_toSettingsAct, SIGNAL(triggered()),
605 this, SLOT(openSettingsDialog()));
608 m_gpsToggleAct = new QAction(tr("GPS"), this);
609 m_gpsToggleAct->setCheckable(true);
611 connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
612 this, SIGNAL(gpsTriggered(bool)));
614 // build the actual menu
615 m_viewMenu = menuBar()->addMenu(tr("Main"));
616 m_viewMenu->addAction(m_loginAct);
617 m_viewMenu->addAction(m_toSettingsAct);
618 m_viewMenu->addAction(m_gpsToggleAct);
619 m_viewMenu->setObjectName(tr("Menu"));
622 void MainWindow::destroyLoginDialog()
624 qDebug() << __PRETTY_FUNCTION__;
627 m_loginDialog->hide();
628 m_loginDialog->deleteLater();
633 void MainWindow::dialogFinished(int status)
635 qDebug() << __PRETTY_FUNCTION__;
637 QDialog *dialog = m_queue.takeFirst();
638 SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
639 MessageDialog *messageDialog = qobject_cast<MessageDialog *>(dialog);
641 if ((searchDialog) && (status != 0)) {
642 if (searchDialog->type() == SearchDialog::Location)
643 emit searchForLocation(searchDialog->input());
644 else if (searchDialog->type() == SearchDialog::PeopleTag)
645 emit requestSearchPeopleByTag(searchDialog->input());
646 } else if ((messageDialog) && (status != 0)) {
647 emit sendMessage(messageDialog->input().first, messageDialog->input().second,
648 messageDialog->isAddCoordinatesSelected());
651 dialog->deleteLater();
653 if(!m_error_queue.isEmpty() && m_errorShown == false) {
654 showErrorInformationBox();
656 if(!m_queue.isEmpty()) {
657 showInformationBox();
662 void MainWindow::drawFullScreenButton(const QSize &size)
664 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
666 if (m_fullScreenButton) {
667 m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
668 size.height() - m_fullScreenButton->size().height());
672 void MainWindow::drawMapScale(const QSize &size)
674 qDebug() << __PRETTY_FUNCTION__;
676 const int LEFT_SCALE_MARGIN = 10;
677 const int BOTTOM_SCALE_MARGIN = 2;
679 m_mapScale->move(LEFT_SCALE_MARGIN,
680 size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
683 void MainWindow::drawOsmLicense(const QSize &size)
685 qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
687 m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
689 size.height() - m_osmLicense->fontMetrics().height());
692 void MainWindow::errorDialogFinished(int status)
694 qDebug() << __PRETTY_FUNCTION__;
697 QDialog *dialog = m_error_queue.takeFirst();
699 dialog->deleteLater();
700 m_errorShown = false;
702 if(!m_error_queue.isEmpty())
703 showErrorInformationBox();
704 else if(!m_queue.isEmpty())
705 showInformationBox();
708 void MainWindow::gpsTimeout()
710 qDebug() << __PRETTY_FUNCTION__;
712 buildInformationBox(tr("GPS timeout"));
715 void MainWindow::grabZoomKeys(bool grab)
717 qDebug() << __PRETTY_FUNCTION__;
720 // Can't grab keys unless we have a window id
724 unsigned long val = (grab) ? 1 : 0;
725 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
729 XChangeProperty (QX11Info::display(),
735 reinterpret_cast<unsigned char *>(&val),
739 #endif // Q_WS_MAEMO_5
742 void MainWindow::keyPressEvent(QKeyEvent* event)
744 qDebug() << __PRETTY_FUNCTION__;
746 switch (event->key()) {
757 QWidget::keyPressEvent(event);
760 void MainWindow::loggedIn(bool logged)
762 qDebug() << __PRETTY_FUNCTION__;
767 m_loginAct->setText(tr("Logout"));
769 m_loginAct->setText(tr("Login"));
770 m_userInfoPanel->showUserInfo(false);
771 m_updateLocationController->clear();
773 updateItemVisibility(logged);
776 void MainWindow::mapCenterHorizontalShiftingChanged(int shifting)
778 m_mapCenterHorizontalShifting = shifting;
782 void MainWindow::moveCrosshair()
784 qDebug() << __PRETTY_FUNCTION__;
787 int mapHeight = m_mapView->size().height();
788 int mapWidth = m_mapView->size().width();
789 m_crosshair->move(mapWidth / 2 - m_crosshair->pixmap()->width() / 2
790 - m_mapCenterHorizontalShifting,
791 mapHeight / 2 - m_crosshair->pixmap()->height() / 2);
795 void MainWindow::openSettingsDialog()
797 qDebug() << __PRETTY_FUNCTION__;
799 SettingsDialog *settingsDialog = new SettingsDialog(this);
800 settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
801 connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
803 settingsDialog->show();
806 void MainWindow::queueDialog(QDialog *dialog)
808 qDebug() << __PRETTY_FUNCTION__;
810 // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
811 if(dialog->isModal()) {
812 m_error_queue.append(dialog);
814 m_queue.append(dialog);
817 // show error dialog if there is only one error dialog in the queue and no error dialog is shown
818 if(m_error_queue.count() == 1 && m_errorShown == false)
819 showErrorInformationBox();
820 else if(m_queue.count() == 1 && m_errorShown == false)
821 showInformationBox();
824 void MainWindow::readAutomaticLocationUpdateSettings()
826 qDebug() << __PRETTY_FUNCTION__;
828 QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
829 bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
830 QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
833 if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
835 emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
837 emit enableAutomaticLocationUpdate(false);
841 void MainWindow::setCrosshairVisibility(bool visibility)
843 qDebug() << __PRETTY_FUNCTION__;
853 void MainWindow::setGPSButtonEnabled(bool enabled)
855 qDebug() << __PRETTY_FUNCTION__;
857 m_gpsToggleAct->setChecked(enabled);
860 void MainWindow::setIndicatorButtonEnabled(bool enabled)
862 qDebug() << __PRETTY_FUNCTION__;
864 m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
867 void MainWindow::setMapViewScene(QGraphicsScene *scene)
869 qDebug() << __PRETTY_FUNCTION__;
871 m_mapView->setScene(scene);
874 void MainWindow::settingsDialogAccepted()
876 qDebug() << __PRETTY_FUNCTION__;
878 readAutomaticLocationUpdateSettings();
881 void MainWindow::showContactDialog(const QString &guid)
883 qDebug() << __PRETTY_FUNCTION__;
885 #if defined(Q_WS_MAEMO_5) & defined(ARMEL)
886 OssoABookDialog::showContactDialog(guid);
889 buildInformationBox(tr("Contact dialog works only on phone!"), true);
893 void MainWindow::showMessageDialog(const QPair<QString, QString> &receiver)
895 qDebug() << __PRETTY_FUNCTION__;
897 MessageDialog *messageDialog = new MessageDialog(receiver.first, receiver.second);
898 queueDialog(messageDialog);
901 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
903 qDebug() << __PRETTY_FUNCTION__;
905 m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
906 tr("Automatic location update"), text,
907 QMessageBox::Yes | QMessageBox::No |
908 QMessageBox::Cancel, this);
909 connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
910 this, SLOT(automaticUpdateDialogFinished(int)));
912 m_automaticUpdateLocationDialog->show();
915 void MainWindow::showErrorInformationBox()
917 qDebug() << __PRETTY_FUNCTION__;
919 if(m_error_queue.count()) {
921 QDialog *dialog = m_error_queue.first();
922 connect(dialog, SIGNAL(finished(int)),
923 this, SLOT(errorDialogFinished(int)));
928 void MainWindow::showInformationBox()
930 qDebug() << __PRETTY_FUNCTION__;
932 if(m_queue.count()) {
933 QDialog *dialog = m_queue.first();
934 connect(dialog, SIGNAL(finished(int)),
935 this, SLOT(dialogFinished(int)));
940 void MainWindow::showUpdateLocationDialog()
942 qDebug() << __PRETTY_FUNCTION__;
944 UpdateLocationDialog *updateLocationDialog
945 = new UpdateLocationDialog(m_updateLocationController, this);
947 connect(this, SIGNAL(reverseGeoReady(QString)),
948 updateLocationDialog, SLOT(setAddress(QString)));
950 updateLocationDialog->show();
952 emit requestReverseGeo();
955 void MainWindow::startLocationSearch()
957 qDebug() << __PRETTY_FUNCTION__;
959 SearchDialog *searchDialog = new SearchDialog(SearchDialog::Location);
960 queueDialog(searchDialog);
963 void MainWindow::startPeopleSearch()
965 qDebug() << __PRETTY_FUNCTION__;
967 SearchDialog *searchDialog = new SearchDialog(SearchDialog::PeopleTag);
968 queueDialog(searchDialog);
971 void MainWindow::sslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
973 qDebug() << __PRETTY_FUNCTION__;
976 reply->ignoreSslErrors();
979 void MainWindow::toggleFullScreen()
981 qDebug() << __PRETTY_FUNCTION__;
983 if(windowState() == Qt::WindowNoState)
989 void MainWindow::toggleProgressIndicator(bool value)
991 qDebug() << __PRETTY_FUNCTION__;
995 m_progressIndicatorCount++;
996 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
998 if(m_progressIndicatorCount > 0)
999 m_progressIndicatorCount--;
1001 if(m_progressIndicatorCount == 0)
1002 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
1006 #endif // Q_WS_MAEMO_5
1009 void MainWindow::updateItemVisibility(bool loggedIn)
1011 qDebug() << __PRETTY_FUNCTION__;
1013 m_tabbedPanel->setTabsEnabled(m_situareTabsIndexes, loggedIn);