connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
- 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_facebookAuthenticator->start();
+ initializeGpsAndAutocentering();
+
m_automaticUpdateIntervalTimer = new QTimer(this);
connect(m_automaticUpdateIntervalTimer, SIGNAL(timeout()),
this, SLOT(automaticUpdateIntervalTimerTimeout()));
qDebug() << __PRETTY_FUNCTION__;
changeAutoCenteringSetting(false);
- m_ui->showMaemoInformationBox(tr("Auto centering disabled"));
+ m_ui->buildInformationBox(tr("Auto centering disabled"));
}
void SituareEngine::enableAutoCentering(bool enabled)
qDebug() << __PRETTY_FUNCTION__;
qDebug() << "ERROR MESSAGE: " << error;
- m_ui->showMaemoInformationBox(error, true);
+ m_ui->buildInformationBox(error, true);
if(error.compare(SESSION_EXPIRED) == 0) {
m_facebookAuthenticator->clearAccountInformation(true); // keep username = true
changeAutoCenteringSetting(true);
enableGPS(true);
- m_ui->showMaemoInformationBox(tr("GPS enabled"));
- m_ui->showMaemoInformationBox(tr("Auto centering enabled"));
+ m_ui->buildInformationBox(tr("GPS enabled"));
+ m_ui->buildInformationBox(tr("Auto centering enabled"));
+
} else { // Normal start
changeAutoCenteringSetting(autoCenteringEnabled.toBool());
enableGPS(gpsEnabled.toBool());
if (gpsEnabled.toBool())
- m_ui->showMaemoInformationBox(tr("GPS enabled"));
+ m_ui->buildInformationBox(tr("GPS enabled"));
if (gpsEnabled.toBool() && autoCenteringEnabled.toBool())
- m_ui->showMaemoInformationBox(tr("Auto centering enabled"));
- }
+ m_ui->buildInformationBox(tr("Auto centering enabled"));
+ }
}
bool SituareEngine::isUserMoved()
connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
this, SLOT(loginOk()));
- connect(m_facebookAuthenticator, SIGNAL(newLoginRequest(QUrl)),
- m_ui, SLOT(startLoginProcess(QUrl)));
+ connect(m_facebookAuthenticator, SIGNAL(newLoginRequest()),
+ m_ui, SLOT(startLoginProcess()));
connect(m_facebookAuthenticator, SIGNAL(loginFailure()),
m_ui, SLOT(loginFailed()));
#include <QtGui>
#include <QtWebKit>
+#include <QtAlgorithms>
#include "common.h"
#include "facebookservice/facebookauthentication.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),
m_drawOwnLocationCrosshair(false),
+ m_errorShown(false),
m_loggedIn(false),
m_refresh(false),
m_ownLocationCrosshair(0),
if(m_webView)
delete m_webView;
+
+ qDeleteAll(m_queue.begin(), m_queue.end());
+ m_queue.clear();
+
+ qDeleteAll(m_error_queue.begin(), m_error_queue.end());
+ m_error_queue.clear();
}
void MainWindow::buildFullScreenButton()
m_friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
}
+void MainWindow::buildInformationBox(const QString &message, bool modal)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+#ifdef Q_WS_MAEMO_5
+ QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
+ QLabel *label = new QLabel(msgBox);
+ label->setAlignment(Qt::AlignCenter);
+ label->setText(message);
+ msgBox->setWidget(label);
+
+ if(modal) {
+ msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
+ } else {
+ msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
+ }
+#else
+ QMessageBox *msgBox = new QMessageBox(this);
+ msgBox->button(QMessageBox::Ok);
+ msgBox->setText(message);
+ msgBox->setModal(modal);
+#endif
+
+ queueDialog(msgBox);
+}
+
void MainWindow::buildManualLocationCrosshair()
{
qDebug() << __PRETTY_FUNCTION__;
if(!m_webView) {
m_webView = new QWebView;
+ if(!m_cookieJar)
+ m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
+
+ m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
+
+ connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
+ this, SLOT(webViewRequestFinished(QNetworkReply*)));
connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
this, SIGNAL(updateCredentials(QUrl)));
connect(m_webView, SIGNAL(loadFinished(bool)),
m_viewMenu->setObjectName(tr("Menu"));
}
+void MainWindow::dialogFinished(int status)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QDialog *dialog = m_queue.takeFirst();
+ LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
+ if(loginDialog) {
+ if(status != 0) {
+ buildWebView();
+ loginDialog->userInput(m_email, m_password);
+
+ QStringList urlParts;
+ urlParts.append(FACEBOOK_LOGINBASE);
+ urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
+ urlParts.append(INTERVAL1);
+ urlParts.append(SITUARE_LOGIN_SUCCESS);
+ urlParts.append(INTERVAL2);
+ urlParts.append(SITUARE_LOGIN_FAILURE);
+ urlParts.append(FACEBOOK_LOGIN_ENDING);
+
+ emit saveUsername(m_email);
+ m_refresh = true;
+ m_webView->load(QUrl(urlParts.join(EMPTY)));
+ toggleProgressIndicator(true);
+ } else {
+ emit cancelLoginProcess();
+ }
+ }
+
+ dialog->deleteLater();
+
+ if(!m_error_queue.isEmpty() && m_errorShown == false) {
+ showErrorInformationBox();
+ } else {
+ if(!m_queue.isEmpty()) {
+ showInformationBox();
+ }
+ }
+}
+
void MainWindow::drawFullScreenButton(const QSize &size)
{
qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
}
}
+void MainWindow::errorDialogFinished(int status)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ qDebug() << status;
+ QDialog *dialog = m_error_queue.takeFirst();
+
+ dialog->deleteLater();
+ m_errorShown = false;
+
+ if(!m_error_queue.isEmpty()) {
+ showErrorInformationBox();
+ }
+}
+
void MainWindow::gpsTimeout()
{
qDebug() << __PRETTY_FUNCTION__;
- showMaemoInformationBox(tr("GPS timeout"));
+ buildInformationBox(tr("GPS timeout"));
}
void MainWindow::grabZoomKeys(bool grab)
if(logged) {
m_loginAct->setText(tr("Logout"));
- }
- else {
+ } else {
clearCookieJar();
m_email.clear();
m_password.clear();
toggleProgressIndicator(false);
- QStringList urlParts;
- urlParts.append(FACEBOOK_LOGINBASE);
- urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
- urlParts.append(INTERVAL1);
- urlParts.append(SITUARE_LOGIN_SUCCESS);
- urlParts.append(INTERVAL2);
- urlParts.append(SITUARE_LOGIN_FAILURE);
- urlParts.append(FACEBOOK_LOGIN_ENDING);
-
- startLoginProcess(urlParts.join(EMPTY));
+ startLoginProcess();
}
void MainWindow::loginUsingCookies()
m_settingsDialog->show();
}
+void MainWindow::queueDialog(QDialog *dialog)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
+ if(dialog->isModal()) {
+ m_error_queue.append(dialog);
+ } else {
+ m_queue.append(dialog);
+ }
+
+ // show error dialog if there is only one error dialog in the queue and no error dialog is shown
+ if(m_error_queue.count() == 1 && m_errorShown == false)
+ showErrorInformationBox();
+ else if(m_queue.count() == 1 && m_errorShown == false)
+ showInformationBox();
+}
+
void MainWindow::saveCookies()
{
qDebug() << __PRETTY_FUNCTION__;
m_ownLocationCrosshair->show();
m_drawOwnLocationCrosshair = true;
drawOwnLocationCrosshair(m_viewPortWidth, m_viewPortHeight);
- }
- else {
+ } else {
m_ownLocationCrosshair->hide();
m_drawOwnLocationCrosshair = false;
}
m_viewPortHeight = height;
}
-void MainWindow::showMaemoInformationBox(const QString &message, bool modal)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
-#ifdef Q_WS_MAEMO_5
- if(modal) {
- QMaemo5InformationBox::information(this, message, QMaemo5InformationBox::NoTimeout);
- }
- else {
- QMaemo5InformationBox::information(this, message, QMaemo5InformationBox::DefaultTimeout);
- }
-#else
- Q_UNUSED(modal);
- QMessageBox::information(this, tr("Situare"), message, QMessageBox::Ok);
-#endif
-}
-
void MainWindow::toggleFullScreen()
{
qDebug() << __PRETTY_FUNCTION__;
showNormal();
}
-void MainWindow::startLoginProcess(const QUrl &url)
+void MainWindow::showErrorInformationBox()
{
qDebug() << __PRETTY_FUNCTION__;
- buildWebView();
+ if(m_error_queue.count()) {
+ m_errorShown = true;
+ QDialog *dialog = m_error_queue.first();
+ connect(dialog, SIGNAL(finished(int)),
+ this, SLOT(errorDialogFinished(int)));
+ dialog->show();
+ }
+}
- LoginDialog loginDialog;
+void MainWindow::showInformationBox()
+{
+ qDebug() << __PRETTY_FUNCTION__;
- emit fetchUsernameFromSettings();
+ if(m_queue.count()) {
+ QDialog *dialog = m_queue.first();
+ connect(dialog, SIGNAL(finished(int)),
+ this, SLOT(dialogFinished(int)));
+ dialog->show();
+ }
+}
- if(!m_cookieJar)
- m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
+void MainWindow::startLoginProcess()
+{
+ qDebug() << __PRETTY_FUNCTION__;
- m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
+ LoginDialog *loginDialog = new LoginDialog();
- loginDialog.clearTextFields();
+ emit fetchUsernameFromSettings();
- if(!m_email.isEmpty())
- loginDialog.setEmailField(m_email);
+ loginDialog->clearTextFields();
- if(loginDialog.exec() != QDialog::Accepted) {
- // if login dialog was canceled we need to stop processing webview
- m_webView->stop();
+ if(!m_email.isEmpty())
+ loginDialog->setEmailField(m_email);
- emit cancelLoginProcess();
- }
- else {
- loginDialog.userInput(m_email, m_password);
- emit saveUsername(m_email);
- m_webView->load(url);
- toggleProgressIndicator(true);
- m_refresh = true;
- }
+ queueDialog(loginDialog);
}
void MainWindow::toggleProgressIndicator(bool value)
setGPSButtonEnabled(false);
emit gpsTriggered(false);
}
- }
- else {
+ } else {
m_friendsListPanel->closePanel();
m_friendsListPanel->hide();
m_friendsListPanelSidebar->hide();
return m_email;
}
+
+void MainWindow::webViewRequestFinished(QNetworkReply *reply)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if(reply->error()) {
+ qDebug() << reply->error() << reply->errorString();
+ toggleProgressIndicator(false);
+ }
+}
+
class QGraphicsScene;
class QLabel;
class QWebView;
+class QNetworkReply;
class FacebookAuthentication;
class FriendListPanel;
******************************************************************************/
public:
/**
+ * @brief Builds information box with message.
+ *
+ * @param message Information message
+ * @param modal Modal = true, non-modal false
+ */
+ void buildInformationBox(const QString &message, bool modal=false);
+
+ /**
* @brief Clears cookie jar
*
*/
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
* @brief Public slot to intercept signal when old cerdentials are invalid or credentials
* doesn't exist yet
*
- * @param url Login page url
*/
- void startLoginProcess(const QUrl &url);
+ void startLoginProcess();
/**
* @brief Toggle progress indicator.
void grabZoomKeys(bool grab);
/**
+ * @brief Queues dialog/information box
+ *
+ * @param dialog Dialog to be added into queue
+ */
+ void queueDialog(QDialog *dialog);
+
+ /**
* @brief Set own location crosshair visibility
*
* @param visible
*/
void setOwnLocationCrosshairVisibility(bool visible);
+ /**
+ * @brief Shows queued error information box
+ *
+ */
+ void showErrorInformationBox();
+
+ /**
+ * @brief Shows queued information box
+ *
+ * @fn showInformationBox
+ */
+ void showInformationBox();
+
private slots:
/**
+ * @brief Slot to intercept signal when dialog/information note is processed
+ *
+ * @param status Status of the dialog
+ */
+ void dialogFinished(int status);
+
+ /**
* @brief Slot for drawing the fullscreen toggle button
*
* @param size Size of the screen
void drawOwnLocationCrosshair(int width, int height);
/**
+ * @brief Slot to intercept signal when error dialog/information note is processed
+ *
+ * @param status Status of the dialog
+ */
+ void errorDialogFinished(int status);
+
+ /**
* @brief Slot for gps timeout.
*
* Called when request timeout occurs.
*/
void toggleFullScreen();
+ /**
+ * @brief Slot to intercept signal from webview's networkaccessmanager
+ *
+ * @param reply Network reply (contains errors)
+ */
+ void webViewRequestFinished(QNetworkReply* reply);
+
/*******************************************************************************
* SIGNALS
******************************************************************************/
******************************************************************************/
private:
bool m_drawOwnLocationCrosshair; ///< Flag for making ownLocationCrosshair visible or not
+ bool m_errorShown; ///< Indicates if error dialog/note is shown
bool m_loggedIn; ///< Indicates login state
bool m_refresh; ///< Indicates when webpage is refreshed
QLabel *m_osmLicense; ///< Label for Open Street Map license
QLabel *m_ownLocationCrosshair; ///< Label that show ownLocationCrosshair
+ QList<QDialog *> m_error_queue; ///< QList type error dialog queue
+ QList<QDialog *> m_queue; ///< QList type dialog queue
+
QMenu *m_viewMenu; ///< Object that hold the view menu items
QString m_email; ///< Placeholder for email
ZoomButtonPanel *m_zoomButtonPanel; ///< Instance of zoom button panel
SettingsDialog *m_settingsDialog; ///< Settings dialog
+
};
#endif // MAINWINDOW_H