From 5ead31e633aaa8ff1078d8289b0dc5e11c598499 Mon Sep 17 00:00:00 2001 From: lampehe-local Date: Fri, 4 Jun 2010 13:44:06 +0300 Subject: [PATCH] Added queue for information notes --- src/engine/engine.cpp | 16 ++++----- src/notedata.cpp | 44 ++++++++++++++++++++++++ src/notedata.h | 43 ++++++++++++++++++++++++ src/src.pro | 8 +++-- src/ui/mainwindow.cpp | 89 +++++++++++++++++++++++++++++++++++-------------- src/ui/mainwindow.h | 32 +++++++++++++----- 6 files changed, 188 insertions(+), 44 deletions(-) create mode 100644 src/notedata.cpp create mode 100644 src/notedata.h diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 534a4c9..4e8ad90 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -84,13 +84,13 @@ SituareEngine::SituareEngine(QMainWindow *parent) connect(this, SIGNAL(friendsLocationsReady(QList&)), m_mapEngine, SIGNAL(friendsLocationsReady(QList&))); - initializeGpsAndAutocentering(); - // signals connected, now it's time to show the main window // but init the MapEngine before so starting location is set m_mapEngine->init(); m_ui->show(); + initializeGpsAndAutocentering(); + m_facebookAuthenticator->start(); m_automaticUpdateIntervalTimer = new QTimer(this); @@ -133,7 +133,7 @@ void SituareEngine::disableAutoCentering() qDebug() << __PRETTY_FUNCTION__; changeAutoCenteringSetting(false); - m_ui->showMaemoInformationBox(tr("Auto centering disabled")); + m_ui->queueInformationBox(tr("Auto centering disabled")); } void SituareEngine::enableAutoCentering(bool enabled) @@ -184,7 +184,7 @@ void SituareEngine::error(const QString &error) { qDebug() << __PRETTY_FUNCTION__; - m_ui->showMaemoInformationBox(error, true); + m_ui->queueInformationBox(error, true); if(error.compare(SESSION_EXPIRED) == 0) { m_facebookAuthenticator->clearAccountInformation(true); // keep username = true @@ -216,17 +216,17 @@ void SituareEngine::initializeGpsAndAutocentering() changeAutoCenteringSetting(true); enableGPS(true); - m_ui->showMaemoInformationBox(tr("GPS enabled")); - m_ui->showMaemoInformationBox(tr("Auto centering enabled")); + m_ui->queueInformationBox(tr("GPS enabled")); + m_ui->queueInformationBox(tr("Auto centering enabled")); } else { // Normal start changeAutoCenteringSetting(autoCenteringEnabled.toBool()); enableGPS(gpsEnabled.toBool()); if (gpsEnabled.toBool()) - m_ui->showMaemoInformationBox(tr("GPS enabled")); + m_ui->queueInformationBox(tr("GPS enabled")); if (gpsEnabled.toBool() && autoCenteringEnabled.toBool()) - m_ui->showMaemoInformationBox(tr("Auto centering enabled")); + m_ui->queueInformationBox(tr("Auto centering enabled")); } } diff --git a/src/notedata.cpp b/src/notedata.cpp new file mode 100644 index 0000000..61c471f --- /dev/null +++ b/src/notedata.cpp @@ -0,0 +1,44 @@ +/* + Situare - A location system for Facebook + Copyright (C) 2010 Ixonos Plc. Authors: + + Henri Lampela - henri.lampela@ixonos.com + + Situare is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2 as published by the Free Software Foundation. + + Situare is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Situare; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include +#include "notedata.h" + +NoteData::NoteData(const QString &message, bool modal) + : m_message(message), + m_modal(modal) +{ + qDebug() << __PRETTY_FUNCTION__; +} + +QString NoteData::message() const +{ + qDebug() << __PRETTY_FUNCTION__; + + return m_message; +} + +bool NoteData::modal() const +{ + qDebug() << __PRETTY_FUNCTION__; + + return m_modal; +} diff --git a/src/notedata.h b/src/notedata.h new file mode 100644 index 0000000..184a2f7 --- /dev/null +++ b/src/notedata.h @@ -0,0 +1,43 @@ +/* + Situare - A location system for Facebook + Copyright (C) 2010 Ixonos Plc. Authors: + + Henri Lampela - henri.lampela@ixonos.com + + Situare is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2 as published by the Free Software Foundation. + + Situare is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Situare; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef NOTEDATA_H +#define NOTEDATA_H + +#include + +class NoteData +{ +public: + NoteData(const QString &message, bool modal); + + QString message() const; + + bool modal() const; + +private: + + QString m_message; + bool m_modal; + +}; + +#endif // NOTEDATA_H diff --git a/src/src.pro b/src/src.pro index ceb28fe..3d881da 100644 --- a/src/src.pro +++ b/src/src.pro @@ -46,7 +46,8 @@ SOURCES += main.cpp \ network/networkaccessmanager.cpp \ network/networkhandler.cpp \ network/networkcookiejar.cpp \ - network/networkreply.cpp + network/networkreply.cpp \ + notedata.cpp HEADERS += ui/mainwindow.h \ map/mapengine.h \ map/mapview.h \ @@ -92,10 +93,11 @@ HEADERS += ui/mainwindow.h \ network/networkaccessmanager.h \ network/networkhandler.h \ network/networkcookiejar.h \ - network/networkreply.h + network/networkreply.h \ + notedata.h QT += network \ webkit -DEFINES += QT_NO_DEBUG_OUTPUT +#DEFINES += QT_NO_DEBUG_OUTPUT maemo5 | simulator { armel { diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 2ec3199..c52aa47 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -25,6 +25,7 @@ #include #include +#include #include "common.h" #include "facebookservice/facebookauthentication.h" @@ -109,6 +110,9 @@ MainWindow::~MainWindow() if(m_webView) delete m_webView; + + qDeleteAll(m_queue.begin(), m_queue.end()); + m_queue.clear(); } void MainWindow::buildFullScreenButton() @@ -372,7 +376,7 @@ void MainWindow::gpsTimeout() { qDebug() << __PRETTY_FUNCTION__; - showMaemoInformationBox(tr("GPS timeout")); + queueInformationBox(tr("GPS timeout")); } void MainWindow::grabZoomKeys(bool grab) @@ -495,8 +499,7 @@ void MainWindow::loggedIn(bool logged) if(logged) { m_loginAct->setText(tr("Logout")); - } - else { + } else { clearCookieJar(); m_email.clear(); m_password.clear(); @@ -526,6 +529,17 @@ void MainWindow::loginFailed() startLoginProcess(urlParts.join(EMPTY)); } +void MainWindow::noteFinished() +{ + qDebug() << __PRETTY_FUNCTION__; + + NoteData *data = m_queue.takeFirst(); + delete data; + + if(!m_queue.isEmpty()) + showInformationBox(); +} + void MainWindow::loginUsingCookies() { qDebug() << __PRETTY_FUNCTION__; @@ -554,6 +568,18 @@ void MainWindow::openSettingsDialog() m_settingsDialog->show(); } +void MainWindow::queueInformationBox(const QString &message, bool modal) +{ + qDebug() << __PRETTY_FUNCTION__; + + NoteData *data = new NoteData(message, modal); + + m_queue.append(data); + + if(m_queue.count() == 1) + showInformationBox(); +} + void MainWindow::saveCookies() { qDebug() << __PRETTY_FUNCTION__; @@ -609,8 +635,7 @@ void MainWindow::setOwnLocationCrosshairVisibility(bool visibility) m_ownLocationCrosshair->show(); m_drawOwnLocationCrosshair = true; drawOwnLocationCrosshair(m_viewPortWidth, m_viewPortHeight); - } - else { + } else { m_ownLocationCrosshair->hide(); m_drawOwnLocationCrosshair = false; } @@ -631,31 +656,47 @@ void MainWindow::setViewPortSize(int width, int height) m_viewPortHeight = height; } -void MainWindow::showMaemoInformationBox(const QString &message, bool modal) +void MainWindow::toggleFullScreen() +{ + qDebug() << __PRETTY_FUNCTION__; + + if(windowState() == Qt::WindowNoState) + showFullScreen(); + else + showNormal(); +} + +void MainWindow::showInformationBox() { qDebug() << __PRETTY_FUNCTION__; + NoteData *data = m_queue.takeFirst(); + #ifdef Q_WS_MAEMO_5 - if(modal) { - QMaemo5InformationBox::information(this, message, QMaemo5InformationBox::NoTimeout); - } - else { - QMaemo5InformationBox::information(this, message, QMaemo5InformationBox::DefaultTimeout); + QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this); + QLabel *label = new QLabel(msgBox); + label->setAlignment(Qt::AlignCenter); + label->setText(data->message()); + + if(data->modal()) { + msgBox->setTimeout(QMaemo5InformationBox::NoTimeout); + } else { + msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout); } #else - Q_UNUSED(modal); - QMessageBox::information(this, tr("Situare"), message, QMessageBox::Ok); + QMessageBox *msgBox = new QMessageBox(this); + msgBox->button(QMessageBox::Ok); + msgBox->setText(data->message()); + msgBox->setModal(data->modal()); #endif -} -void MainWindow::toggleFullScreen() -{ - qDebug() << __PRETTY_FUNCTION__; + connect(msgBox, SIGNAL(finished(int)), + this, SLOT(noteFinished())); + + msgBox->show(); + + m_queue.insert(0, data); - if(windowState() == Qt::WindowNoState) - showFullScreen(); - else - showNormal(); } void MainWindow::startLoginProcess(const QUrl &url) @@ -683,8 +724,7 @@ void MainWindow::startLoginProcess(const QUrl &url) m_webView->stop(); emit cancelLoginProcess(); - } - else { + } else { loginDialog.userInput(m_email, m_password); emit saveUsername(m_email); m_webView->load(url); @@ -719,8 +759,7 @@ void MainWindow::updateItemVisibility(bool show) setGPSButtonEnabled(false); emit gpsTriggered(false); } - } - else { + } else { m_friendsListPanel->closePanel(); m_friendsListPanel->hide(); m_friendsListPanelSidebar->hide(); diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index e4b78fe..bf4a250 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -29,6 +29,7 @@ #include "network/networkcookiejar.h" #include "panelsidebar.h" +#include "notedata.h" class QGraphicsScene; class QLabel; @@ -93,6 +94,14 @@ public: void loggedIn(bool logged); /** + * @brief Queues information box with message. + * + * @param message Information message + * @param modal Modal = true, non-modal false + */ + void queueInformationBox(const QString &message, bool modal=false); + + /** * @brief Enable / disable auto centering button. * * @param enabled true if shoud be enabled, false otherwise @@ -116,14 +125,6 @@ public: void setMapViewScene(QGraphicsScene *scene); /** - * @brief Show Maemo information box with message. - * - * @param message Information message - * @param modal Modal = true, non-modal false - */ - void showMaemoInformationBox(const QString &message, bool modal=false); - - /** * @brief Gets the username from member variable for saving purposes * * @return QString Username @@ -238,6 +239,13 @@ private: */ void setOwnLocationCrosshairVisibility(bool visible); + /** + * @brief Shows queued information box + * + * @fn showInformationBox + */ + void showInformationBox(); + private slots: /** * @brief Slot for drawing the fullscreen toggle button @@ -282,6 +290,12 @@ private slots: void loadDone(bool done); /** + * @brief Slot to intercept signal when information note is processed + * + */ + void noteFinished(); + + /** * @brief Slot to save cookies to settings * */ @@ -508,6 +522,8 @@ private: ZoomButtonPanel *m_zoomButtonPanel; ///< Instance of zoom button panel SettingsDialog *m_settingsDialog; ///< Settings dialog + + QList m_queue; ///< List type queue for information boxes }; #endif // MAINWINDOW_H -- 1.7.9.5