First phase of userdata rewrite
authorlampehe-local <henri.lampela@ixonos.com>
Tue, 29 Jun 2010 07:31:26 +0000 (10:31 +0300)
committerlampehe-local <henri.lampela@ixonos.com>
Tue, 29 Jun 2010 07:31:26 +0000 (10:31 +0300)
15 files changed:
src/engine/engine.cpp
src/engine/engine.h
src/map/frienditemshandler.cpp
src/map/frienditemshandler.h
src/map/mapengine.cpp
src/map/mapengine.h
src/situareservice/situareservice.cpp
src/situareservice/situareservice.h
src/ui/friendlistitem.cpp
src/ui/friendlistitem.h
src/ui/friendlistpanel.cpp
src/ui/friendlistpanel.h
src/ui/mainwindow.cpp
src/ui/mainwindow.h
src/ui/userinfopanel.cpp

index 601ac66..289a578 100644 (file)
@@ -91,6 +91,12 @@ SituareEngine::SituareEngine(QMainWindow *parent)
     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
             m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
 
+    connect(this, SIGNAL(friendImageReady(User*)),
+            m_ui, SIGNAL(friendImageReady(User*)));
+
+    connect(this, SIGNAL(friendImageReady(User*)),
+            m_mapEngine, SIGNAL(friendImageReady(User*)));
+
     m_automaticUpdateIntervalTimer = new QTimer(this);
     connect(m_automaticUpdateIntervalTimer, SIGNAL(timeout()),
             this, SLOT(startAutomaticUpdate()));
@@ -328,6 +334,16 @@ void SituareEngine::fetchUsernameFromSettings()
     m_ui->setUsername(m_facebookAuthenticator->loadUsername());
 }
 
+void SituareEngine::imageReady(User *user)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if(user->type())
+        emit userLocationReady(user);
+    else
+        emit friendImageReady(user);
+}
+
 void SituareEngine::initializeGpsAndAutocentering()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -637,6 +653,9 @@ void SituareEngine::signalsFromSituareService()
     connect(m_situareService, SIGNAL(error(int, int)),
             this, SLOT(error(int, int)));
 
+    connect(m_situareService, SIGNAL(imageReady(User*)),
+            this, SLOT(imageReady(User*)));
+
     connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
             m_ui, SIGNAL(reverseGeoReady(QString)));
 
index 88c738c..763c69a 100644 (file)
@@ -223,6 +223,8 @@ private slots:
     */
     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
 
+    void imageReady(User *user);
+
     /**
     * @brief Requests automatic update.
     *
@@ -272,6 +274,8 @@ signals:
     */
     void friendsLocationsReady(QList<User *> &friendList);
 
+    void friendImageReady(User *user);
+
     /**
     * @brief Signals when new user data is ready
     *
index 954153a..6f81d35 100644 (file)
@@ -207,6 +207,18 @@ void FriendItemsHandler::dropOutOfGroupFriends()
     }
 }
 
+void FriendItemsHandler::friendImageReady(User *user)
+{
+   qDebug() << __PRETTY_FUNCTION__;
+
+   foreach (FriendLocationItem *friendItem, m_friendItems) {
+       if (user->userId() == friendItem->userId()) {
+           friendItem->setProfileImage(user->profileImage(), user->profileImageUrl());
+           break;
+       }
+   }
+}
+
 void FriendItemsHandler::friendListUpdated(QList<User *> &friendsList)
 {
     qDebug() << __PRETTY_FUNCTION__;
index 3a96a0e..ef84121 100644 (file)
@@ -187,6 +187,8 @@ private:
     void updateFriendLocationsAndImages(const QList<User *> &friendsList);
 
 private slots:
+
+    void friendImageReady(User *user);
     /**
     * @brief Slot for upgrading friend items and groups
     *
index 4d12982..5bd236b 100644 (file)
@@ -85,6 +85,9 @@ MapEngine::MapEngine(QObject *parent)
     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
             m_friendItemsHandler, SLOT(friendListUpdated(QList<User*>&)));
 
+    connect(this, SIGNAL(friendImageReady(User*)),
+            m_friendItemsHandler, SLOT(friendImageReady(User*)));
+
     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
             this, SLOT(friendsPositionsUpdated()));
 
index 816577a..60e3357 100644 (file)
@@ -392,6 +392,8 @@ signals:
      */
     void fetchImage(int zoomLevel, int x, int y);
 
+    void friendImageReady(User *user);
+
     /**
      * @brief Signal when friend list locations are fetched
      *
index 4565ba0..fa1af86 100644 (file)
@@ -294,8 +294,6 @@ void SituareService::parseUserData(const QByteArray &jsonReply)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_visited = 0;
-    m_nbrOfImages = 0;
     m_defaultImage = false;
 
     QJson::Parser parser;
@@ -377,6 +375,7 @@ void SituareService::parseUserData(const QByteArray &jsonReply)
 
               m_friendsList.append(user);
             }
+            emit userDataChanged(m_user, m_friendsList);
             addProfileImages();
         } else {
             QVariant address = result.value("address");
@@ -403,31 +402,28 @@ void SituareService::imageReceived(const QUrl &url, const QPixmap &image)
     if(url == QUrl(SILHOUETTE_URL)) {
         if(m_user->profileImageUrl().isEmpty()) {
             m_user->setProfileImage(AvatarImage::create(image, AvatarImage::Large));
+            emit imageReady(m_user);
         }
         for(int i=0;i < m_friendsList.count();i++) {
             if(m_friendsList.at(i)->profileImageUrl().isEmpty()) {
                 m_friendsList.at(i)->setProfileImage(AvatarImage::create(image,
                                                                          AvatarImage::Small));
+                emit imageReady(m_friendsList.at(i));
             }
         }
     }
 
     if (m_user->profileImageUrl() == url) {
         m_user->setProfileImage(AvatarImage::create(image, AvatarImage::Large));
+        emit imageReady(m_user);
     }
 
     for(int i=0;i<m_friendsList.count();i++) {
         if(m_friendsList.at(i)->profileImageUrl() == url) {
             m_friendsList.at(i)->setProfileImage(AvatarImage::create(image, AvatarImage::Small));
-            m_nbrOfImages++; // indicates how many friend profile images has been downloaded
+            emit imageReady(m_friendsList.at(i));
         }
     }
-
-    if(m_nbrOfImages == m_visited) {
-        qDebug() << "m_nbrOfImages: " << m_nbrOfImages << " m_visited: " << m_visited;
-        qDebug() << "emit userDataChanged";
-        emit userDataChanged(m_user, m_friendsList);
-    }
 }
 
 void SituareService::addProfileImages()
@@ -445,8 +441,7 @@ void SituareService::addProfileImages()
     for(int i=0;i<m_friendsList.count();i++) {
         if(!m_friendsList.at(i)->profileImageUrl().isEmpty() &&
            m_friendsList.at(i)->profileImageUrl().isValid()) {
-            m_visited++; // indicates how many friends that have profile image
-            emit fetchImage(m_friendsList.at(i)->profileImageUrl());
+           emit fetchImage(m_friendsList.at(i)->profileImageUrl());
         }
     }
 }
index 362f72a..11ab781 100644 (file)
@@ -201,6 +201,8 @@ signals:
     */
     void fetchImage(const QUrl &url);
 
+    void imageReady(User *user);
+
     /**
     * @brief Signals when address data is retrieved
     *
@@ -228,9 +230,6 @@ signals:
 
 private:
 
-    int m_nbrOfImages;      ///< Indicates number of friends whose images has been downloaded
-    int m_visited;          ///< Indicates number of friends with images
-
     bool m_defaultImage;    ///< Indicates if some of the friends/user doesn't have a image
 
     QList<QNetworkReply *> m_currentRequests;   ///< List of current http requests
@@ -241,9 +240,6 @@ private:
     FacebookCredentials m_credentials;          ///< handle for FacebookCredentials
     ImageFetcher *m_imageFetcher;               ///< Instance of the image fetcher
     User *m_user;                               ///< Pointer to User
-
-
-
 };
 
 #endif // SITUARESERVICE_H
index 24e6dd5..6a999db 100644 (file)
@@ -184,6 +184,14 @@ void FriendListItem::setData(User *user)
     }
 }
 
+void FriendListItem::setAvatarImage(const QPixmap &image)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if(!image.isNull())
+        m_findButton->setButtonIcon(image);
+}
+
 void FriendListItem::setDistanceIcon(double value, const QString &unit)
 {
     QPixmap distanceImage;
index 46b228c..9121bec 100644 (file)
@@ -87,6 +87,8 @@ public:
     */
     void setData(User *user);
 
+    void setAvatarImage(const QPixmap &image);
+
 private:
     /**
     * @brief Set distance icon.
index 4c62607..4831fce 100644 (file)
@@ -65,6 +65,14 @@ FriendListPanel::FriendListPanel(QWidget *parent)
             this, SLOT(clearFriendListFilter()));
 }
 
+void FriendListPanel::friendImageReady(User *user)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    FriendListItem *item = m_friendListView->widget(user->userId());
+    item->setAvatarImage(user->profileImage());
+}
+
 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
 {
     qDebug() << __PRETTY_FUNCTION__;
index 1d81a02..e780eed 100644 (file)
@@ -60,6 +60,8 @@ public slots:
     */
     void friendInfoReceived(QList<User *> &friendList);
 
+    void friendImageReady(User *user);
+
 private slots:
     /**
     * @brief Slot to clear friend list filter.
index 1d0a247..16d0b35 100644 (file)
@@ -169,6 +169,9 @@ void MainWindow::buildFriendListPanel()
 
     connect(m_friendsListPanel, SIGNAL(findFriend(QPointF)),
             this, SIGNAL(findFriend(QPointF)));
+
+    connect(this, SIGNAL(friendImageReady(User*)),
+            m_friendsListPanel, SLOT(friendImageReady(User*)));
 }
 
 void MainWindow::buildInformationBox(const QString &message, bool modal)
index fe93387..c2ba90b 100644 (file)
@@ -443,6 +443,8 @@ signals:
     */
     void findUser(const QPointF &coordinates);
 
+    void friendImageReady(User *user);
+
     /**
     * @brief GPS setting changed
     *
index d09932f..59ddfa8 100644 (file)
@@ -69,7 +69,7 @@ UserInfoPanel::UserInfoPanel(QWidget *parent)
     connect(this, SIGNAL(clearUpdateLocationDialogData()),
             m_userInfo, SLOT(clearUpdateLocationDialogData()));
 
-    connect (m_userInfo, SIGNAL(notificateUpdateFailing(QString, bool)),
+    connect(m_userInfo, SIGNAL(notificateUpdateFailing(QString, bool)),
              this, SIGNAL(notificateUpdateFailing(QString, bool)));
 }