reviewed and iterated with Marko Niemelä
authorVille Tiensuu <ville.tiensuu@ixonos.com>
Tue, 8 Jun 2010 07:44:11 +0000 (10:44 +0300)
committerVille Tiensuu <ville.tiensuu@ixonos.com>
Tue, 8 Jun 2010 07:44:11 +0000 (10:44 +0300)
src/ui/updatelocation/updatelocationdialog.cpp
src/ui/updatelocation/updatelocationdialog.h
src/ui/userinfo.cpp
src/ui/userinfo.h

index c7c9231..cbf79cb 100755 (executable)
@@ -23,7 +23,8 @@
 #include <QDebug>
 #include "updatelocationdialog.h"
 
-UpdateLocationDialog::UpdateLocationDialog(QWidget *parent)
+UpdateLocationDialog::UpdateLocationDialog(const QString &userMessage, bool publishOnFacebook,
+                                           QWidget *parent)
     : QDialog(parent)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -34,9 +35,13 @@ UpdateLocationDialog::UpdateLocationDialog(QWidget *parent)
     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);
@@ -74,8 +79,8 @@ void UpdateLocationDialog::sendUpdate()
     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->hide();
+    close();
 }
index 9454787..af57d5b 100755 (executable)
@@ -53,9 +53,12 @@ public:
     /**
     * @brief Default constructor
     *
+    * @param userMessage update location dialog message
+    * @param publishOnFacebook update location dialog Facebook publish policity
     * @param parent
     */
-    UpdateLocationDialog(QWidget *parent = 0);    
+    UpdateLocationDialog(const QString &userMessage = "", bool publishOnFacebook = false,
+                         QWidget *parent = 0);
 
 /*******************************************************************************
  * MEMBER FUNCTIONS AND SLOTS
@@ -96,9 +99,7 @@ signals:
  ******************************************************************************/
 
 private:
-
     QLabel *m_locationLabel; ///< Pointer to locationLabel
-public:
     QCheckBox *m_checkBox; ///< Pointer to CheckBox
     QTextEdit *m_textEdit; ///< Pointer to TextEdit
 };
index a43f053..a97f499 100644 (file)
@@ -90,10 +90,6 @@ UserInfo::UserInfo(QWidget *parent)
     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",
@@ -118,16 +114,7 @@ UserInfo::UserInfo(QWidget *parent)
             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)));
+        this, SLOT(findButtonClicked()));    
 
     setFixedWidth(BACKGROUND_WIDTH);
 
@@ -151,12 +138,15 @@ UserInfo::~UserInfo()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (!m_backupMessage.isEmpty()) {
-        QSettings settings(DIRECTORY_NAME, FILE_NAME);
+    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)
@@ -218,7 +208,7 @@ void UserInfo::setText(bool expanded)
     }
 }
 
-void UserInfo::backupUpdateLocationDialogData(const QString &status, const bool &publish)
+void UserInfo::backupUpdateLocationDialogData(const QString &status, bool publish)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -232,9 +222,7 @@ void UserInfo::clearUpdateLocationDialogData()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    qDebug() << "Message Before Clearing: " << m_backupMessage;
     m_backupMessage.clear();
-    qDebug() << "Message After Clearing: " << m_backupMessage;
     m_backupFacebookPublishPolicity = false;
 }
 
@@ -245,17 +233,6 @@ void UserInfo::findButtonClicked()
     emit findUser(m_coordinates);
 }
 
-void UserInfo::restoreUnsendMessage()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    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::mouseReleaseEvent(QMouseEvent *event)
 {
     qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
@@ -286,12 +263,27 @@ void UserInfo::messageUpdate()
 
     emit requestReverseGeo();
 
-    m_messageDialog->show();
-    m_messageDialog->m_textEdit->setPlainText(m_backupMessage);
-    m_messageDialog->m_checkBox->setCheckState(Qt::Unchecked);
+    UpdateLocationDialog updateLocation(m_backupMessage, m_backupFacebookPublishPolicity, this);
 
-    if (m_backupFacebookPublishPolicity == true)
-        m_messageDialog->m_checkBox->setCheckState(Qt::Checked);
+    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)
@@ -311,6 +303,16 @@ void UserInfo::paintEvent(QPaintEvent *aPaintEvent)
     painter.drawPixmap(bottomRect, m_backgroundBottomImage);
 }
 
+void UserInfo::restoreUnsendMessage()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    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();
+}
+
 QString UserInfo::shortenText(const QLabel *label, const QString &text, int textMaxWidth)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -335,14 +337,10 @@ void UserInfo::verifyMessageUpdateFailure(const QString &errorMessage)
     Q_UNUSED(errorMessage);
 
     if (!m_messageUpdateVerified) {
-        QString message = QObject::tr("Status update failed\n\nYour message is saved to textbox "
-                                      "until sending will succeed");
-
-        qDebug() << "m_messageText: " << m_messageText;
-        qDebug() << "m_backupMessage: " << m_backupMessage;
 
         if (m_messageText != m_backupMessage && !m_backupMessage.isEmpty())
-            emit notificateUpdateFailing(message);
+            emit notificateUpdateFailing(tr("Location update failed\n\nYour message is saved to "
+                                            "textbox until sending will succeed"));
     }
 
     m_messageUpdateVerified = true;
index 069b77c..c404217 100644 (file)
@@ -133,7 +133,7 @@ public slots:
     * @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, const bool &publish);
+    void backupUpdateLocationDialogData(const QString &status, bool publish);
 
     /**
     * @brief Sets the message text
@@ -257,8 +257,7 @@ private:
     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
-    UpdateLocationDialog *m_messageDialog;  ///< Dialog for sending message and location
+    ImageButton *m_findButton;          ///< User find button   
 };
 
 #endif // USERINFO_H