Room players list
authorunc0rr
Mon, 08 Oct 2012 23:57:17 +0400
changeset 7731 262228c64f15
parent 7730 2013733f9ca9
child 7732 fad3408fdcc1
Room players list
QTfrontend/model/playerslistmodel.cpp
QTfrontend/model/playerslistmodel.h
QTfrontend/net/newnetclient.cpp
--- a/QTfrontend/model/playerslistmodel.cpp	Mon Oct 08 13:27:46 2012 -0400
+++ b/QTfrontend/model/playerslistmodel.cpp	Mon Oct 08 23:57:17 2012 +0400
@@ -102,6 +102,24 @@
 }
 
 
+void PlayersListModel::playerJoinedRoom(const QString & nickname)
+{
+    QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname);
+
+    if(mil.size())
+        setData(mil[0], "1", RoomFilterRole);
+}
+
+
+void PlayersListModel::playerLeftRoom(const QString & nickname)
+{
+    QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname);
+
+    if(mil.size())
+        setData(mil[0], "0", RoomFilterRole);
+}
+
+
 void PlayersListModel::setFlag(const QString &nickname, StateFlag flagType, bool isSet)
 {
     QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname);
@@ -119,6 +137,21 @@
 }
 
 
+void PlayersListModel::resetRoomFlags()
+{
+    for(int i = rowCount() - 1; i >= 0; --i)
+    {
+        QModelIndex mi = index(i);
+
+        if(mi.data(RoomFilterRole).toString() == "1")
+        {
+            setData(mi, "0", RoomFilterRole);
+            setData(mi, false, RoomAdmin);
+            setData(mi, false, Ready);
+        }
+    }
+}
+
 void PlayersListModel::updateIcon(const QModelIndex & index)
 {
     quint32 iconNum = 0;
--- a/QTfrontend/model/playerslistmodel.h	Mon Oct 08 13:27:46 2012 -0400
+++ b/QTfrontend/model/playerslistmodel.h	Mon Oct 08 23:57:17 2012 +0400
@@ -21,7 +21,8 @@
     };
 
     enum SpecialRoles {
-        SortRole = Qt::UserRole + 100
+        SortRole       = Qt::UserRole + 100,
+        RoomFilterRole = Qt::UserRole + 101
     };
 
     explicit PlayersListModel(QObject *parent = 0);
@@ -38,7 +39,10 @@
 public slots:
     void addPlayer(const QString & nickname);
     void removePlayer(const QString & nickname);
+    void playerJoinedRoom(const QString & nickname);
+    void playerLeftRoom(const QString & nickname);
     void setFlag(const QString & nickname, StateFlag flagType, bool isSet);
+    void resetRoomFlags();
 
 private:
     QHash<quint32, QIcon> & m_icons();
--- a/QTfrontend/net/newnetclient.cpp	Mon Oct 08 13:27:46 2012 -0400
+++ b/QTfrontend/net/newnetclient.cpp	Mon Oct 08 23:57:17 2012 +0400
@@ -52,6 +52,8 @@
     m_roomPlayersModel->setSortRole(PlayersListModel::SortRole);
     m_roomPlayersModel->setDynamicSortFilter(true);
     m_roomPlayersModel->sort(0);
+    m_roomPlayersModel->setFilterRole(PlayersListModel::RoomFilterRole);
+    m_roomPlayersModel->setFilterFixedString("1");
 
     // socket stuff
     connect(&NetSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
@@ -592,6 +594,7 @@
 
             emit nickAdded(lst[i], isChief && (lst[i] != mynick));
             emit chatStringFromNet(tr("%1 *** %2 has joined the room").arg('\x03').arg(lst[i]));
+            m_playersModel->playerJoinedRoom(lst[i]);
         }
         return;
     }
@@ -718,6 +721,7 @@
             {
                 emit nickAdded(lst[i], isChief && (lst[i] != mynick));
                 emit chatStringFromNet(tr("%1 *** %2 has joined the room").arg('\x03').arg(lst[i]));
+                m_playersModel->playerJoinedRoom(lst[i]);
             }
             return;
         }
@@ -734,6 +738,7 @@
                 emit chatStringFromNet(tr("%1 *** %2 has left").arg('\x03').arg(lst[1]));
             else
                 emit chatStringFromNet(tr("%1 *** %2 has left (%3)").arg('\x03').arg(lst[1], lst[2]));
+            m_playersModel->playerLeftRoom(lst[1]);
             return;
         }