QTfrontend/ui/widget/teamselect.cpp
changeset 13694 27e5e311c7a3
parent 13235 d5a029299407
child 14534 db646b3c0b95
--- a/QTfrontend/ui/widget/teamselect.cpp	Tue Aug 21 23:56:49 2018 +0200
+++ b/QTfrontend/ui/widget/teamselect.cpp	Wed Aug 22 15:00:04 2018 +0200
@@ -74,6 +74,11 @@
     framePlaying->setInteractivity(interactive);
 }
 
+void TeamSelWidget::setUser(const QString& nickname)
+{
+    m_curUser = nickname;
+}
+
 void TeamSelWidget::hhNumChanged(const HWTeam& team)
 {
     QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
@@ -152,6 +157,37 @@
     emit setEnabledGameStart(curPlayingTeams.size()>1);
 }
 
+// Removes teams classified as net teams but which are owned by the local user.
+// Those teams don't make sense and might be leftovers from a finished game
+// after rejoining. See also: Bugzilla bug 597.
+void TeamSelWidget::cleanupFakeNetTeams()
+{
+    // m_curUser is not set for offline games. No cleanup is needed when offline.
+    if(m_curUser.isNull())
+        return;
+
+    QList<HWTeam>::iterator itPlay = curPlayingTeams.begin();
+    while(itPlay != curPlayingTeams.end())
+    {
+        if(itPlay->isNetTeam() && itPlay->owner() == m_curUser)
+        {
+            qDebug() << QString("cleanupFakeNetTeams: team '%1' removed").arg(itPlay->name());
+            QObject::disconnect(framePlaying->getTeamWidget(*itPlay), SIGNAL(teamStatusChanged(HWTeam)));
+            framePlaying->removeTeam(*itPlay);
+            itPlay = curPlayingTeams.erase(itPlay);
+        }
+        else
+            itPlay++;
+    }
+
+    // Show team notice if less than two teams.
+    if (curPlayingTeams.size() < 2)
+    {
+        numTeamNotice->show();
+    }
+    emit setEnabledGameStart(curPlayingTeams.size()>1);
+}
+
 void TeamSelWidget::changeTeamStatus(HWTeam team)
 {
     QList<HWTeam>::iterator itDontPlay=std::find(m_curNotPlayingTeams.begin(), m_curNotPlayingTeams.end(), team);