const int DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE = 12; ///< Default zoom level when GPS available
const qreal USER_MOVEMENT_MINIMUM_LONGITUDE_DIFFERENCE = 0.003;///< Min value for user move latitude
const qreal USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE = 0.001;///< Min value for user move longitude
+const int MIN_UPDATE_INTERVAL_MSECS = 5*60*1000;
SituareEngine::SituareEngine(QMainWindow *parent)
: QObject(parent),
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)
if (m_automaticUpdateIntervalTimer) {
if (enabled && m_gps->isRunning()) {
- m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
+ if (updateIntervalMsecs < MIN_UPDATE_INTERVAL_MSECS)
+ m_automaticUpdateIntervalTimer->setInterval(MIN_UPDATE_INTERVAL_MSECS);
+ else
+ m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
m_automaticUpdateIntervalTimer->start();
}
else
void SituareEngine::error(const QString &error)
{
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()));
this, SLOT(requestUpdateLocation(QString,bool)));
connect(m_ui, SIGNAL(enableAutomaticLocationUpdate(bool, int)),
- this, SLOT(enableAutomaticLocationUpdate(bool, int)));
+ this, SLOT(enableAutomaticLocationUpdate(bool, int)));
// signals from user info tab
connect(m_ui, SIGNAL(refreshUserData()),
this, SLOT(refreshUserData()));
+ connect (m_ui, SIGNAL(notificateUpdateFailing(QString)),
+ this, SLOT(error(QString)));
+
connect(m_ui, SIGNAL(findUser(QPointF)),
m_mapEngine, SLOT(setViewLocation(QPointF)));
connect(m_situareService, SIGNAL(updateWasSuccessful()),
this, SLOT(updateWasSuccessful()));
+
+ connect(m_situareService, SIGNAL(updateWasSuccessful()),
+ m_ui, SIGNAL(updateWasSuccessful()));
+
+ connect(m_situareService, SIGNAL(error(QString)),
+ m_ui, SIGNAL(messageSendingFailed(QString)));
}
void SituareEngine::updateWasSuccessful()
FacebookAuthentication::FacebookAuthentication(QObject *parent)
: QObject(parent),
- m_freshLogin(false),
- m_loginAttempts(0)
-
+ m_freshLogin(false)
{
qDebug() << __PRETTY_FUNCTION__;
}
else {
m_freshLogin = true;
-
- QStringList list;
- list.append(FACEBOOK_LOGINBASE);
- list.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
- list.append(INTERVAL1);
- list.append(SITUARE_LOGIN_SUCCESS);
- list.append(INTERVAL2);
- list.append(SITUARE_LOGIN_FAILURE);
- list.append(FACEBOOK_LOGIN_ENDING);
-
- emit newLoginRequest(list.join(EMPTY));
+ emit newLoginRequest();
}
}
else if ( callbackUrl.indexOf(LOGIN_FAILURE_REPLY) == 0){
qWarning() << "login failure" << endl;
qDebug() << callbackUrl;
- ++m_loginAttempts;
- /* emit loginFailure for every second login attemps, since webview loads login
- error page (loadingDone() signal is emitted) and we need to avoid that because
- at this point we don't have new login parameters */
- if(m_loginAttempts % 2) {
- clearAccountInformation(true);
- if(m_freshLogin) {
- emit error(LOGIN_FAILED);
- emit loginFailure();
- }
- else {
- m_freshLogin = true;
- emit error(SESSION_EXPIRED);
- }
+ clearAccountInformation(true);
+ if(m_freshLogin) {
+ emit error(LOGIN_FAILED);
+ emit loginFailure();
+ }
+ else {
+ m_freshLogin = true;
+ emit error(SESSION_EXPIRED);
}
}
else if(callbackUrl.indexOf(LOGIN_PAGE) == 0) {
/**
* @brief Signals when credentials are invalid new login is needed
*
- * @param url Login page url
*/
- void newLoginRequest(const QUrl &url);
+ void newLoginRequest();
/**
* @brief This signal is emitted when new cookies need to be saved.
bool m_freshLogin;
- int m_loginAttempts; ///< Indicates login attempts
-
/**
* @brief Dataclass that contains authorization to use facebook. Dataclass is composed of five
* QStrings and setters and getters.
qDebug() << "BytesAvailable: " << reply->bytesAvailable();
if (reply->error()) {
- emit error(reply->errorString());
+ emit error(reply->errorString());
+ qDebug() << "TMP MESSAGE VILLE";
} else {
qint64 max = reply->size();
QByteArray replyArray = reply->read(max);
QT += network \
webkit
-DEFINES += QT_NO_DEBUG_OUTPUT
+#DEFINES += QT_NO_DEBUG_OUTPUT
simulator {
SOURCES += network/networkhandlerprivatestub.cpp \
#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::automaticLocationUpdateEnabled(bool enabled)
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__;
connect(m_mapView, SIGNAL(viewResized(QSize)),
m_userPanel, SLOT(screenResized(QSize)));
+
+ connect(this, SIGNAL(updateWasSuccessful()),
+ m_userPanel, SIGNAL(updateWasSuccessful()));
+
+ connect(this, SIGNAL(messageSendingFailed(QString)),
+ m_userPanel, SIGNAL(messageSendingFailed(QString)));
+
+ connect(m_userPanel, SIGNAL(notificateUpdateFailing(QString)),
+ this, SIGNAL(notificateUpdateFailing(QString)));
}
void MainWindow::buildWebView()
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->emitAutomaticLocationUpdateSettings();
}
+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;
}
return false;
}
-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();
+
+ emit fetchUsernameFromSettings();
- loginDialog.clearTextFields();
+ loginDialog->clearTextFields();
if(!m_email.isEmpty())
- loginDialog.setEmailField(m_email);
-
- if(loginDialog.exec() != QDialog::Accepted) {
- // if login dialog was canceled we need to stop processing webview
- m_webView->stop();
+ 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;
void automaticLocationUpdateEnabled(bool enabled);
/**
+ * @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
*
*/
bool showEnableAutomaticUpdateLocationDialog();
/**
- * @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
******************************************************************************/
void maxZoomLevelReached();
/**
+ * @brief Signal that informs that user's message/location failed to update on Situare server
+ * This signal is originally sended from SituareService with name error
+ * Signal is renamed on MainWindow
+ */
+ void messageSendingFailed(const QString &error);
+
+ /**
* @brief Forwarding signal from MapEngine to MapView
*/
void minZoomLevelReached();
/**
+ * @brief Signal that used to inform user that his message/location update tp Situare server
+ * was failed.
+ * This signal is originally sended from UserInfo
+ */
+ void notificateUpdateFailing(const QString &message);
+
+ /**
* @brief Signal for refreshing user data.
*
*/
void updateCredentials(const QUrl &url);
/**
+ * @brief Signals when updateLocation request finished successfully
+ *
+ */
+ void updateWasSuccessful();
+
+ /**
* @brief MapView has finished zooming
*/
void viewZoomFinished();
******************************************************************************/
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
#include <QDebug>
#include "updatelocationdialog.h"
-UpdateLocationDialog::UpdateLocationDialog(QWidget *parent)
+UpdateLocationDialog::UpdateLocationDialog(const QString &userMessage, bool publishOnFacebook,
+ QWidget *parent)
: QDialog(parent)
{
qDebug() << __PRETTY_FUNCTION__;
QGroupBox *groupBox = new QGroupBox(scrollArea);
m_textEdit = new QTextEdit;
+ m_textEdit->setText(userMessage);
+
m_locationLabel = new QLabel;
m_locationLabel->setWordWrap(true);
+
m_checkBox = new QCheckBox(tr("Publish on Facebook"));
+ m_checkBox->setChecked(publishOnFacebook);
QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
QPushButton *sendButton = buttonBox->addButton(QDialogButtonBox::Ok);
connect(sendButton, SIGNAL(clicked()), this, SLOT(sendUpdate()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
- scrollArea->show();
-}
-
-UpdateLocationDialog::~UpdateLocationDialog()
-{
- qDebug() << __PRETTY_FUNCTION__;
+ scrollArea->show();
}
void UpdateLocationDialog::setAddress(const QString &address)
void UpdateLocationDialog::sendUpdate()
{
- qDebug() << __PRETTY_FUNCTION__;
+ qDebug() << __PRETTY_FUNCTION__;
// coordinates for this call will be get from somewhere, map etc...
- emit statusUpdate(m_textEdit->toPlainText(), m_checkBox->isChecked());
+ emit statusUpdate(m_textEdit->toPlainText(), m_checkBox->isChecked());
+ m_textEdit->clear();
- this->close();
+ close();
}
/**
* @brief Default constructor
*
+ * @param userMessage update location dialog message
+ * @param publishOnFacebook update location dialog Facebook publish policity
* @param parent
*/
- UpdateLocationDialog(QWidget *parent = 0);
- ~UpdateLocationDialog();
+ UpdateLocationDialog(const QString &userMessage = "", bool publishOnFacebook = false,
+ QWidget *parent = 0);
/*******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
signals:
-
/**
* @brief Signal Signal for requestLocationUpdate from SituareEngine via MainWindow class
*
******************************************************************************/
private:
-
- QCheckBox *m_checkBox; ///< Pointer to CheckBox
QLabel *m_locationLabel; ///< Pointer to locationLabel
+ QCheckBox *m_checkBox; ///< Pointer to CheckBox
QTextEdit *m_textEdit; ///< Pointer to TextEdit
};
Jussi Laitinen - jussi.laitinen@ixonos.com
Katri Kaikkonen - katri.kaikkonen@ixonos.com
Henri Lampela - henri.lampela@ixonos.com
+ Ville Tiensuu - ville.tiensuu@ixonos.com
Situare is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
USA.
*/
+#include "common.h"
#include "imagebutton.h"
#include "../user/user.h"
#include "userinfo.h"
const int BACKGROUND_WIDTH = 240; ///< Width for item
const int BACKGROUND_TOP_HEIGHT = 16; ///< Height for item top
const int BACKGROUND_BOTTOM_HEIGHT = 15; ///< Height for item bottom
-const QColor COLOR_GRAY = QColor(152, 152, 152); ///< Gray color
-const QFont NOKIA_FONT_NORMAL = QFont("Nokia Sans", 18, QFont::Normal); ///< Normal font
-const QFont NOKIA_FONT_SMALL = QFont("Nokia Sans", 13, QFont::Normal); ///< Small font
const int ICON_HEIGHT = 24; ///< Icon height
const int ICON_WIDTH = 24; ///< Icon width
-const int IMAGE_HEIGHT = 60; ///< Profile image height
-const int IMAGE_WIDTH = 60; ///< Profile image width
const int MARGIN = 5; ///< Icon margin
const int MOUSE_PRESS_AREA_WIDTH = 20; ///< Area width for item height toggling
const int MOUSE_PRESS_AREA_HEIGHT = 20; ///< Area height for item height toggling
+const QString USER_UNSEND_MESSAGE = "User_unsend_message_content";
+const QString USER_UNSEND_MESSAGE_PUBLISH_POLICITY = "User_unsend_message_publish";
/**
* @var LABEL_MAX_WIDTH
connect(updateStatusMessageButton,SIGNAL(clicked()),
this,SLOT(messageUpdate()));
+
connect(updateFriendsButton,SIGNAL(clicked()),
this, SIGNAL(refreshUserData()));
+
connect(m_findButton, SIGNAL(clicked()),
- this, SLOT(findButtonClicked()));
+ this, SLOT(findButtonClicked()));
setFixedWidth(BACKGROUND_WIDTH);
m_backgroundTopImage.load(":/res/images/user_info_item_top.png");
m_backgroundMiddleImage.load(":/res/images/user_info_item_middle.png");
m_backgroundBottomImage.load(":/res/images/user_info_item_bottom.png");
+
+ restoreUnsendMessage();
+}
+
+UserInfo::~UserInfo()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+
+ if (!m_backupMessage.isEmpty()) {
+ settings.setValue(USER_UNSEND_MESSAGE, m_backupMessage.toAscii());
+ settings.setValue(USER_UNSEND_MESSAGE_PUBLISH_POLICITY, m_backupFacebookPublishPolicity);
+ } else {
+ settings.remove(USER_UNSEND_MESSAGE);
+ settings.remove(USER_UNSEND_MESSAGE_PUBLISH_POLICITY);
+ }
}
void UserInfo::setAddress(const QString &address)
setText(false);
}
-QString UserInfo::shortenText(const QLabel *label, const QString &text, int textMaxWidth)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- QFontMetrics labelMetrics = label->fontMetrics();
-
- QString textParam = text;
- int index = textParam.indexOf('\n');
-
- if (index > 0) {
- textParam.truncate(index);
- textParam.append("...");
- }
-
- return labelMetrics.elidedText(textParam, Qt::ElideRight, textMaxWidth);
-}
-
void UserInfo::setText(bool expanded)
{
qDebug() << __PRETTY_FUNCTION__;
}
}
+void UserInfo::backupUpdateLocationDialogData(const QString &status, bool publish)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_backupMessage = status;
+ m_backupFacebookPublishPolicity = publish;
+
+ m_messageUpdateVerified = false;
+}
+
+void UserInfo::clearUpdateLocationDialogData()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_backupMessage.clear();
+ m_backupFacebookPublishPolicity = false;
+}
+
+void UserInfo::findButtonClicked()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ emit findUser(m_coordinates);
+}
+
void UserInfo::mouseReleaseEvent(QMouseEvent *event)
{
qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
}
}
+void UserInfo::mousePressEvent(QMouseEvent *event)
+{
+ qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
+
+ m_mousePosition = event->pos();
+}
+
+void UserInfo::messageUpdate()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ emit requestReverseGeo();
+
+ UpdateLocationDialog updateLocation(m_backupMessage, m_backupFacebookPublishPolicity, this);
+
+ connect(this, SIGNAL(reverseGeoReady(QString)),
+ &updateLocation, SLOT(setAddress(QString)));
+
+ connect(&updateLocation, SIGNAL(statusUpdate(QString,bool)),
+ this, SIGNAL(statusUpdate(QString,bool)));
+
+ connect(&updateLocation, SIGNAL(statusUpdate(QString,bool)),
+ this, SLOT(backupUpdateLocationDialogData(QString,bool)));
+
+ updateLocation.exec();
+
+ disconnect(this, SIGNAL(reverseGeoReady(QString)),
+ &updateLocation, SLOT(setAddress(QString)));
+
+ disconnect(&updateLocation, SIGNAL(statusUpdate(QString,bool)),
+ this, SIGNAL(statusUpdate(QString,bool)));
+
+ disconnect(&updateLocation, SIGNAL(statusUpdate(QString,bool)),
+ this, SLOT(backupUpdateLocationDialogData(QString,bool)));
+}
+
void UserInfo::paintEvent(QPaintEvent *aPaintEvent)
{
qDebug() << __PRETTY_FUNCTION__ << " " << aPaintEvent->rect();
painter.drawPixmap(bottomRect, m_backgroundBottomImage);
}
-void UserInfo::mousePressEvent(QMouseEvent *event)
+void UserInfo::restoreUnsendMessage()
{
- qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
+ qDebug() << __PRETTY_FUNCTION__;
- m_mousePosition = event->pos();
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+ m_backupMessage = settings.value(USER_UNSEND_MESSAGE, "").toString();
+ m_backupFacebookPublishPolicity =
+ settings.value(USER_UNSEND_MESSAGE_PUBLISH_POLICITY, false).toBool();
}
-void UserInfo::findButtonClicked()
+QString UserInfo::shortenText(const QLabel *label, const QString &text, int textMaxWidth)
{
qDebug() << __PRETTY_FUNCTION__;
- emit findUser(m_coordinates);
+ QFontMetrics labelMetrics = label->fontMetrics();
+
+ QString textParam = text;
+ int index = textParam.indexOf('\n');
+
+ if (index > 0) {
+ textParam.truncate(index);
+ textParam.append("...");
+ }
+
+ return labelMetrics.elidedText(textParam, Qt::ElideRight, textMaxWidth);
}
-void UserInfo::messageUpdate()
+void UserInfo::verifyMessageUpdateFailure(const QString &errorMessage)
{
qDebug() << __PRETTY_FUNCTION__;
- UpdateLocationDialog updateLocationDialog(this);
+ Q_UNUSED(errorMessage);
- emit requestReverseGeo();
+ if (!m_messageUpdateVerified) {
- connect(this, SIGNAL(reverseGeoReady(QString)),
- &updateLocationDialog, SLOT(setAddress(QString)));
- connect(&updateLocationDialog, SIGNAL(statusUpdate(QString, bool)),
- this, SIGNAL(statusUpdate(QString, bool)));
+ if (m_messageText != m_backupMessage && !m_backupMessage.isEmpty())
+ emit notificateUpdateFailing(tr("Location update failed\n\nYour message is saved to "
+ "textbox until sending will succeed"));
+ }
- updateLocationDialog.exec();
+ m_messageUpdateVerified = true;
}
-
Jussi Laitinen - jussi.laitinen@ixonos.com
Katri Kaikkonen - katri.kaikkonen@ixonos.com
Henri Lampela - henri.lampela@ixonos.com
+ Ville Tiensuu - ville.tiensuu@ixonos.com
Situare is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
*/
UserInfo(QWidget *parent=0);
+ /**
+ * @brief Desctructor
+ * saves unsend user message to settings
+ *
+ */
+ ~UserInfo();
+
/*******************************************************************************
* BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
*******************************************************************************/
*
* @param coordinates Reference to users current coordinates
*/
- void setCoordinates(const QPointF &coordinates);
-
- /**
- * @brief Sets the message text
- *
- * @param text Reference to user message
- */
- void setMessageText(const QString &text);
+ void setCoordinates(const QPointF &coordinates);
/**
* @brief Sets the user picture
*/
void setUserName(const QString &name);
+public slots:
+
+ /**
+ * @brief Clears backups of message and publish on Facebook setting
+ */
+ void clearUpdateLocationDialogData();
+
+ /**
+ * @brief Saves status message and Facebook publish setting
+ *
+ * @param status message that user sends. Message is stored to m_backupMessage data member
+ * @param publish setting that determines whether the user status message is published on
+ * Facebook. This value is stored to m_backupFacebookPublishPolicity data member.
+ */
+ void backupUpdateLocationDialogData(const QString &status, bool publish);
+
+ /**
+ * @brief Sets the message text
+ *
+ * @param text Reference to user message
+ */
+ void setMessageText(const QString &text);
+
+
+ /**
+ * @brief Emits signal to inform user about failed message/location update.
+ * Contains logic to send signal only after failed message/location update.
+ *
+ * @param errorMessage from Situare server. Message is not used in this function
+ */
+ void verifyMessageUpdateFailure(const QString &errorMessage);
+
private:
+
+ /**
+ * @brief reads Unsend message from settings at startup
+ *
+ */
+ void restoreUnsendMessage();
+
/**
* @brief Set shortened or full-length text to labels.
*
* @brief Slot function to forward messageUpdate launch signal
*
*/
- void messageUpdate();
+ void messageUpdate();
/******************************************************************************
* SIGNALS
void findUser(const QPointF &coordinates);
/**
+ * @brief Signal that informs that user's message/location failed to update on Situare server
+ * This signal is originally sended from SituareService with name error
+ * Signal is renamed on MainWindow
+ */
+ void messageSendingFailed(const QString &error);
+
+ /**
+ * @brief Signal that used to inform user that his message/location update tp Situare server
+ * was failed.
+ * This signal is originally sended from UserInfo
+ */
+ void notificateUpdateFailing(const QString &message);
+
+ /**
* @brief Signal for refreshing user data.
*
*/
* @param publish Publish on Facebook
*/
void statusUpdate(const QString &status, const bool &publish);
-
/******************************************************************************
* DATA MEMBERS
******************************************************************************/
private:
- bool m_expanded; ///< Item expanded state
+ bool m_backupFacebookPublishPolicity; ///< Backup of publish on Facebook checkbox value
+ bool m_expanded; ///< Item expanded state
+ bool m_messageUpdateVerified; ///< Place for message/location update check
QLabel *m_locationLabel; ///< Location label
QLabel *m_nameLabel; ///< Name label
QLabel *m_statusTextLabel; ///< Status text label
QPixmap m_backgroundTopImage; ///< Top background image
QPoint m_mousePosition; ///< Current mouse press position
QPointF m_coordinates; ///< User current coordinates
- QString m_address; ///< Address from where the new message was sent.
+ QString m_address; ///< Address from where the new message was sent
+ QString m_backupMessage; ///< Backup of users message
QString m_messageText; ///< User's message
QString m_time; ///< Time when the new message was sent
QString m_userName; ///< User's name
- ImageButton *m_findButton; ///< User find button
+ ImageButton *m_findButton; ///< User find button
};
#endif // USERINFO_H
connect(m_userInfo, SIGNAL(refreshUserData()),
this, SIGNAL(refreshUserData()));
+
+ connect(this, SIGNAL(updateWasSuccessful()),
+ m_userInfo, SLOT(clearUpdateLocationDialogData()));
+
+ connect(this, SIGNAL(messageSendingFailed(QString)),
+ m_userInfo, SIGNAL(messageSendingFailed(QString)));
+
+ connect (this, SIGNAL(messageSendingFailed(QString)),
+ m_userInfo, SLOT(verifyMessageUpdateFailure(QString)));
+
+ connect (m_userInfo, SIGNAL(notificateUpdateFailing(QString)),
+ this, SIGNAL(notificateUpdateFailing(QString)));
}
void UserInfoPanel::userDataReceived(User *user)
void findUser(const QPointF &coordinates);
/**
+ * @brief Signal that informs that user's message/location failed to update on Situare server
+ * This signal is originally sended from SituareService with name error
+ * Signal is renamed on MainWindow
+ */
+ void messageSendingFailed(const QString &error);
+
+ /**
+ * @brief Signal that used to inform user that his message/location update tp Situare server
+ * was failed.
+ * This signal is originally sended from UserInfo
+ */
+ void notificateUpdateFailing(const QString &message);
+
+ /**
* @brief Signal for refreshing user data.
*
*/
*/
void statusUpdate(const QString &status, const bool &publish);
+ /**
+ * @brief Signals when updateLocation request finished successfully
+ *
+ */
+ void updateWasSuccessful();
/*******************************************************************************
* DATA MEMBERS
******************************************************************************/