QTfrontend/model/playerslistmodel.cpp
changeset 7737 ff63da8a3202
parent 7732 fad3408fdcc1
child 7744 75e1d0c0ba72
equal deleted inserted replaced
7736:1cf84a84ef43 7737:ff63da8a3202
   133 
   133 
   134         if(flagType == Friend || flagType == ServerAdmin
   134         if(flagType == Friend || flagType == ServerAdmin
   135                 || flagType == Ignore || flagType == RoomAdmin)
   135                 || flagType == Ignore || flagType == RoomAdmin)
   136             updateSortData(mil[0]);
   136             updateSortData(mil[0]);
   137 
   137 
       
   138         if(flagType == Friend)
       
   139         {
       
   140             if(isSet)
       
   141                 m_friendsSet.insert(nickname.toLower());
       
   142             else
       
   143                 m_friendsSet.remove(nickname.toLower());
       
   144 
       
   145             saveSet(m_friendsSet, "friends");
       
   146         }
       
   147 
       
   148         if(flagType == Ignore)
       
   149         {
       
   150             if(isSet)
       
   151                 m_ignoredSet.insert(nickname.toLower());
       
   152             else
       
   153                 m_ignoredSet.remove(nickname.toLower());
       
   154 
       
   155             saveSet(m_ignoredSet, "ignore");
       
   156         }
       
   157 
   138         updateIcon(mil[0]);
   158         updateIcon(mil[0]);
   139     }
   159     }
   140 }
   160 }
   141 
   161 
       
   162 
       
   163 bool PlayersListModel::isFlagSet(const QString & nickname, StateFlag flagType)
       
   164 {
       
   165     QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname);
       
   166 
       
   167     if(mil.size())
       
   168         return mil[0].data(flagType).toBool();
       
   169     else
       
   170         return false;
       
   171 }
   142 
   172 
   143 void PlayersListModel::resetRoomFlags()
   173 void PlayersListModel::resetRoomFlags()
   144 {
   174 {
   145     for(int i = rowCount() - 1; i >= 0; --i)
   175     for(int i = rowCount() - 1; i >= 0; --i)
   146     {
   176     {
   149         if(mi.data(RoomFilterRole).toString() == "1")
   179         if(mi.data(RoomFilterRole).toString() == "1")
   150         {
   180         {
   151             setData(mi, "0", RoomFilterRole);
   181             setData(mi, "0", RoomFilterRole);
   152             setData(mi, false, RoomAdmin);
   182             setData(mi, false, RoomAdmin);
   153             setData(mi, false, Ready);
   183             setData(mi, false, Ready);
       
   184 
       
   185             updateSortData(mi);
       
   186             updateIcon(mi);
   154         }
   187         }
   155     }
   188     }
   156 }
   189 }
   157 
   190 
   158 void PlayersListModel::updateIcon(const QModelIndex & index)
   191 void PlayersListModel::updateIcon(const QModelIndex & index)
   292     txt.close();
   325     txt.close();
   293 }
   326 }
   294 
   327 
   295 void PlayersListModel::saveSet(const QSet<QString> & set, const QString & suffix)
   328 void PlayersListModel::saveSet(const QSet<QString> & set, const QString & suffix)
   296 {
   329 {
       
   330     qDebug("saving set");
       
   331 
   297     QString fileName = QString("%1/%2_%3.txt").arg(cfgdir->absolutePath(), m_nickname.toLower(), suffix);
   332     QString fileName = QString("%1/%2_%3.txt").arg(cfgdir->absolutePath(), m_nickname.toLower(), suffix);
   298 
   333 
   299     QFile txt(fileName);
   334     QFile txt(fileName);
   300 
   335 
   301     // list empty? => rather have no file for the list than an empty one
   336     // list empty? => rather have no file for the list than an empty one