Merge branch 'master' of https://vcs.maemo.org/git/situare
[situare] / src / ui / userinfo.cpp
index a609dd9..42a0c01 100644 (file)
 #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 int ICON_HEIGHT = 24; ///< Icon height
-const int ICON_WIDTH = 24;  ///< Icon 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
@@ -144,10 +143,10 @@ UserInfo::~UserInfo()
 
     if (!m_backupMessage.isEmpty()) {        
         settings.setValue(USER_UNSEND_MESSAGE, m_backupMessage.toAscii());
-        settings.setValue(USER_UNSEND_MESSAGE_PUBLISH_POLICITY, m_backupFacebookPublishPolicity);
+        settings.setValue(USER_UNSEND_MESSAGE_PUBLISH, m_backupFacebookPublishPolicity);
     } else {
         settings.remove(USER_UNSEND_MESSAGE);
-        settings.remove(USER_UNSEND_MESSAGE_PUBLISH_POLICITY);
+        settings.remove(USER_UNSEND_MESSAGE_PUBLISH);
     }
 }
 
@@ -170,6 +169,19 @@ void UserInfo::setMessageText(const QString &text)
     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);
 }
 
@@ -200,8 +212,7 @@ 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));
@@ -263,8 +274,6 @@ void UserInfo::messageUpdate()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    emit requestReverseGeo();
-
     delete m_updateLocation;
     m_updateLocation = new UpdateLocationDialog(m_backupMessage, m_backupFacebookPublishPolicity,
                                                 this);
@@ -282,6 +291,8 @@ void UserInfo::messageUpdate()
             this, SLOT(updateLocationDialogFinished(int)));
 
     m_updateLocation->show();
+
+    emit requestReverseGeo();
 }
 
 void UserInfo::paintEvent(QPaintEvent *aPaintEvent)
@@ -306,9 +317,9 @@ void UserInfo::restoreUnsendMessage()
     qDebug() << __PRETTY_FUNCTION__;
 
     QSettings settings(DIRECTORY_NAME, FILE_NAME);
-    m_backupMessage = settings.value(USER_UNSEND_MESSAGE, "").toString();
+    m_backupMessage = settings.value(USER_UNSEND_MESSAGE, EMPTY).toString();
     m_backupFacebookPublishPolicity =
-            settings.value(USER_UNSEND_MESSAGE_PUBLISH_POLICITY, false).toBool();
+            settings.value(USER_UNSEND_MESSAGE_PUBLISH, false).toBool();
 }
 
 QString UserInfo::shortenText(const QLabel *label, const QString &text, int textMaxWidth)
@@ -316,14 +327,16 @@ QString UserInfo::shortenText(const QLabel *label, const QString &text, int text
     qDebug() << __PRETTY_FUNCTION__;
 
     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 (index > 0) {
+            textParam.truncate(index);
+            textParam.append("...");
+        }
+            if (textWidth > 150)
+                textParam.insert(LINE_LENGTH, QString("\n"));
 
    return labelMetrics.elidedText(textParam, Qt::ElideRight, textMaxWidth);
 }
@@ -337,8 +350,7 @@ void UserInfo::verifyMessageUpdateFailure(const int error)
     if (!m_messageUpdateVerified) {
 
         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"), true);
+            emit notificateUpdateFailing(tr("Location update failed, please try again"), false);
     }
 
     m_messageUpdateVerified = true;