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
#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";
+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 int ICON_HEIGHT = 24; ///< Icon height
+const int ICON_WIDTH = 24; ///< Icon width
+const int MARGIN = 5; ///< Icon margin
+const int LINE_LENGTH = 17; ///< Line length
+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
/**
* @var LABEL_MAX_WIDTH
UserInfo::UserInfo(QWidget *parent)
: QWidget(parent),
- m_expanded(false)
+ m_expanded(false),
+ m_messageUpdateVerified(false),
+ m_updateLocation(0)
{
qDebug() << __PRETTY_FUNCTION__;
m_updatedLabel = new QLabel();
m_updatedLabel->setWordWrap(true);
- m_messageDialog = new UpdateLocationDialog(this);
- m_messageDialog->hide();
- m_messageDialog->setWindowModality(Qt::NonModal);
-
ImageButton *updateFriendsButton = new ImageButton(this, ":/res/images/refresh.png",
":/res/images/refresh_s.png");
ImageButton *updateStatusMessageButton = new ImageButton(this, ":/res/images/send_position.png",
this, SIGNAL(refreshUserData()));
connect(m_findButton, SIGNAL(clicked()),
- this, SLOT(findButtonClicked()));
-
- connect(this, SIGNAL(reverseGeoReady(QString)),
- m_messageDialog, SLOT(setAddress(QString)));
-
- connect(m_messageDialog, SIGNAL(statusUpdate(QString,bool)),
- this, SIGNAL(statusUpdate(QString,bool)));
-
- connect(m_messageDialog, SIGNAL(statusUpdate(QString,bool)),
- this, SLOT(backupUpdateLocationDialogData(QString,bool)));
-
- connect(this, SIGNAL(messageUpdatedToSituare()),
- this, SLOT(clearUpdateLocationDialogData()));
+ this, SLOT(findButtonClicked()));
setFixedWidth(BACKGROUND_WIDTH);
{
qDebug() << __PRETTY_FUNCTION__;
- if (!m_backupMessage.isEmpty()) {
- QSettings settings(DIRECTORY_NAME, FILE_NAME);
- settings.setValue(USER_UNSEND_MESSAGE, m_backupMessage.toAscii());
- settings.setValue(USER_UNSEND_MESSAGE_PUBLISH_POLICITY, m_backupFacebookPublishPolicity);
- }
-
-}
-
-void UserInfo::backupUpdateLocationDialogData(const QString &status, const bool &publish)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_backupMessage = status;
- m_backupFacebookPublishPolicity = publish;
-
- m_messageUpdateVerified = false;
-}
-
-void UserInfo::clearUpdateLocationDialogData()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- qDebug() << "Message Before Clearing: " << m_backupMessage;
- m_backupMessage.clear();
- qDebug() << "Message After Clearing: " << m_backupMessage;
- m_backupFacebookPublishPolicity = false;
-}
-
-void UserInfo::restoreUnsendMessage()
-{
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();
+ if (!m_backupMessage.isEmpty()) {
+ settings.setValue(USER_UNSEND_MESSAGE, m_backupMessage.toAscii());
+ settings.setValue(USER_UNSEND_MESSAGE_PUBLISH, m_backupFacebookPublishPolicity);
+ } else {
+ settings.remove(USER_UNSEND_MESSAGE);
+ settings.remove(USER_UNSEND_MESSAGE_PUBLISH);
+ }
}
void UserInfo::setAddress(const QString &address)
qDebug() << __PRETTY_FUNCTION__;
m_messageText = text;
+ m_expandedMessageText.clear();
+ QString temp = "";
+ for(int i=0;i < text.length();i++) {
+ if(fontMetrics().width(temp.append(text.at(i))) > 170) {
+ temp.append("\n");
+ if(temp.startsWith(QString(" ")))
+ temp.remove(0, 1);
+
+ m_expandedMessageText.append(temp);
+ temp.clear();
+ }
+ }
+ m_expandedMessageText.append(temp);
setText(false);
}
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__;
if (expanded) {
- m_nameLabel->setText(m_userName);
- m_statusTextLabel->setText(m_messageText);
+ m_statusTextLabel->setText(m_expandedMessageText);
}
else {
m_nameLabel->setText(shortenText(m_nameLabel, m_userName, LABEL_MAX_WIDTH));
}
}
-void UserInfo::verifyMessageUpdateToServer(QString errorMessage)
+void UserInfo::backupUpdateLocationDialogData(const QString &status, bool publish)
{
qDebug() << __PRETTY_FUNCTION__;
- Q_UNUSED(errorMessage);
+ m_backupMessage = status;
+ m_backupFacebookPublishPolicity = publish;
- if (!m_messageUpdateVerified) {
- QString message = QObject::tr("Status update failed\n\nYour message is saved to textbox "
- "until sending will succeed");
+ m_messageUpdateVerified = false;
+}
- qDebug() << "m_messageText: " << m_messageText;
- qDebug() << "m_backupMessage: " << m_backupMessage;
+void UserInfo::clearUpdateLocationDialogData()
+{
+ qDebug() << __PRETTY_FUNCTION__;
- if (m_messageText != m_backupMessage && !m_backupMessage.isEmpty())
- emit notificateUpdateFailing(message);
- }
+ m_backupMessage.clear();
+ m_backupFacebookPublishPolicity = false;
+}
- m_messageUpdateVerified = true;
+void UserInfo::findButtonClicked()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ emit findUser(m_coordinates);
}
void UserInfo::mouseReleaseEvent(QMouseEvent *event)
}
}
+void UserInfo::mousePressEvent(QMouseEvent *event)
+{
+ qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
+
+ m_mousePosition = event->pos();
+}
+
+void UserInfo::messageUpdate()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ delete m_updateLocation;
+ m_updateLocation = new UpdateLocationDialog(m_backupMessage, m_backupFacebookPublishPolicity,
+ this);
+
+ connect(this, SIGNAL(reverseGeoReady(QString)),
+ m_updateLocation, SLOT(setAddress(QString)));
+
+ connect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
+ this, SIGNAL(statusUpdate(QString,bool)));
+
+ connect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
+ this, SLOT(backupUpdateLocationDialogData(QString,bool)));
+
+ connect(m_updateLocation, SIGNAL(finished(int)),
+ this, SLOT(updateLocationDialogFinished(int)));
+
+ m_updateLocation->show();
+
+ emit requestReverseGeo();
+}
+
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, EMPTY).toString();
+ m_backupFacebookPublishPolicity =
+ settings.value(USER_UNSEND_MESSAGE_PUBLISH, 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');
+ int textWidth = fontMetrics().width(textParam);
+
+ if (index > 0) {
+ textParam.truncate(index);
+ textParam.append("...");
+ }
+ if (textWidth > 150)
+ textParam.insert(LINE_LENGTH, QString("\n"));
+
+ return labelMetrics.elidedText(textParam, Qt::ElideRight, textMaxWidth);
}
-void UserInfo::messageUpdate()
+void UserInfo::verifyMessageUpdateFailure(const int error)
{
qDebug() << __PRETTY_FUNCTION__;
- emit requestReverseGeo();
+ Q_UNUSED(error);
- m_messageDialog->show();
- m_messageDialog->m_textEdit->setPlainText(m_backupMessage);
- m_messageDialog->m_checkBox->setCheckState(Qt::Unchecked);
+ if (!m_messageUpdateVerified) {
+
+ if (m_messageText != m_backupMessage && !m_backupMessage.isEmpty())
+ emit notificateUpdateFailing(tr("Location update failed, please try again"), false);
+ }
+
+ m_messageUpdateVerified = true;
+}
+
+void UserInfo::updateLocationDialogFinished(int reason)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ Q_UNUSED(reason);
+
+ if (m_updateLocation) {
+ disconnect(this, SIGNAL(reverseGeoReady(QString)),
+ m_updateLocation, SLOT(setAddress(QString)));
- if (m_backupFacebookPublishPolicity == true)
- m_messageDialog->m_checkBox->setCheckState(Qt::Checked);
+ disconnect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
+ this, SIGNAL(statusUpdate(QString,bool)));
+
+ disconnect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
+ this, SLOT(backupUpdateLocationDialogData(QString,bool)));
+
+ disconnect(m_updateLocation, SIGNAL(finished(int)),
+ this, SLOT(updateLocationDialogFinished(int)));
+
+ m_updateLocation->deleteLater();
+ m_updateLocation = 0;
+ }
- m_messageDialog->exec();
}