Ejemplo n.º 1
0
void UserContextMenu::gamesOfUserReceived(const Response &resp, const CommandContainer &commandContainer)
{
    const Response_GetGamesOfUser &response = resp.GetExtension(Response_GetGamesOfUser::ext);
    const Command_GetGamesOfUser &cmd = commandContainer.session_command(0).GetExtension(Command_GetGamesOfUser::ext);

    QMap<int, GameTypeMap> gameTypeMap;
    QMap<int, QString> roomMap;
    const int roomListSize = response.room_list_size();
    for (int i = 0; i < roomListSize; ++i) {
        const ServerInfo_Room &roomInfo = response.room_list(i);
        roomMap.insert(roomInfo.room_id(), QString::fromStdString(roomInfo.name()));
        GameTypeMap tempMap;
        const int gameTypeListSize = roomInfo.gametype_list_size();
        for (int j = 0; j < gameTypeListSize; ++j) {
            const ServerInfo_GameType &gameTypeInfo = roomInfo.gametype_list(j);
            tempMap.insert(gameTypeInfo.game_type_id(), QString::fromStdString(gameTypeInfo.description()));
        }
        gameTypeMap.insert(roomInfo.room_id(), tempMap);
    }

    GameSelector *selector = new GameSelector(client, tabSupervisor, 0, roomMap, gameTypeMap, false, false);
    const int gameListSize = response.game_list_size();
    for (int i = 0; i < gameListSize; ++i)
        selector->processGameInfo(response.game_list(i));

    selector->setWindowTitle(tr("%1's games").arg(QString::fromStdString(cmd.user_name())));
    selector->setMinimumWidth(800);
    selector->setAttribute(Qt::WA_DeleteOnClose);
    selector->show();
}
Ejemplo n.º 2
0
QVariant GamesModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();
    if (role == Qt::UserRole)
        return index.row();
    if (role != Qt::DisplayRole && role != SORT_ROLE)
        return QVariant();
    if ((index.row() >= gameList.size()) || (index.column() >= columnCount()))
        return QVariant();

    const ServerInfo_Game &g = gameList[index.row()];
    switch (index.column()) {
        case 0: return rooms.value(g.room_id());
        case 1: {
            QDateTime then;
            then.setTime_t(g.start_time());
            unsigned int secs = then.secsTo(QDateTime::currentDateTime());

            switch (role) {
                case Qt::DisplayRole: return prettyPrintSecsAgo(secs);
                case SORT_ROLE: return QVariant(secs);
                default: {
                    qDebug() << "Returning data for col 1 of games model when role != display, role != sort";
                    return QVariant(); // Shouldn't ever be reached.
                }
            }
        }
        case 2: return QString::fromStdString(g.description());
        case 3: return QString::fromStdString(g.creator_info().name());
        case 4: {
            QStringList result;
            GameTypeMap gameTypeMap = gameTypes.value(g.room_id());
            for (int i = g.game_types_size() - 1; i >= 0; --i)
                result.append(gameTypeMap.value(g.game_types(i)));
            return result.join(", ");
        }
        case 5: return g.with_password() ? ((g.spectators_need_password() || !g.spectators_allowed()) ? tr("yes") : tr("yes, free for spectators")) : tr("no");
        case 6: {
            QStringList result;
            if (g.only_buddies())
                result.append(tr("buddies only"));
            if (g.only_registered())
                result.append(tr("reg. users only"));
            return result.join(", ");
        }
        case 7: return QString("%1/%2").arg(g.player_count()).arg(g.max_players());
        case 8: return g.spectators_allowed() ? QVariant(g.spectators_count()) : QVariant(tr("not allowed"));
        default: return QVariant();
    }
}
Ejemplo n.º 3
0
QVariant GamesModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();
    if (role == Qt::UserRole)
        return index.row();
    if (role != Qt::DisplayRole)
        return QVariant();
    if ((index.row() >= gameList.size()) || (index.column() >= columnCount()))
        return QVariant();
    
    const ServerInfo_Game &g = gameList[index.row()];
    switch (index.column()) {
        case 0: return QString::fromStdString(g.description());
        case 1: return rooms.value(g.room_id());
        case 2: return QString::fromStdString(g.creator_info().name());
        case 3: {
            QStringList result;
            GameTypeMap gameTypeMap = gameTypes.value(g.room_id());
            for (int i = g.game_types_size() - 1; i >= 0; --i)
                result.append(gameTypeMap.value(g.game_types(i)));
            return result.join(", ");
        }
        case 4: return g.with_password() ? ((g.spectators_need_password() || !g.spectators_allowed()) ? tr("yes") : tr("yes, free for spectators")) : tr("no");
        case 5: {
            QStringList result;
            if (g.only_buddies())
                result.append(tr("buddies only"));
            if (g.only_registered())
                result.append(tr("reg. users only"));
            return result.join(", ");
        }
        case 6: return QString("%1/%2").arg(g.player_count()).arg(g.max_players());
        case 7: return g.spectators_allowed() ? QVariant(g.spectators_count()) : QVariant(tr("not allowed"));
        default: return QVariant();
    }
}