bool ChatChannelManager::tryNewPublicChannel(const std::string &name)
{
    if (!stringFilter->filterContent(name))
    {
        return false;
    }

    // Checking strings for length and double quotes
    unsigned maxNameLength = Configuration::getValue("chat_maxChannelNameLength", 150);
    if (name.empty() ||
        name.length() > maxNameLength ||
        stringFilter->findDoubleQuotes(name))
    {
        return false;
    }
    else if (guildManager->doesExist(name) ||
             channelExists(name))
    {
        // Channel already exists
        return false;
    }
    else
    {
        // We attempt to create a new channel
        short id = createNewChannel(name, "", "", true);
        return id ? true : false;
    }
}
Exemple #2
0
bool checkChannelPresets(QString *probs)
{
    bool problemFound = false;

    MSqlQuery query(MSqlQuery::InitCon());

    query.prepare("SELECT cardid, startchan, sourceid, inputname"
                  " FROM cardinput;");

    if (!query.exec() || !query.isActive())
    {
        MythContext::DBError("checkChannelPresets", query);
        return false;
    }

    while (query.next())
    {
        int cardid    = query.value(0).toInt();
        QString startchan = query.value(1).toString();
        int sourceid  = query.value(2).toInt();

        if (query.value(1).toString() == "")    // Logic from tv_rec.cpp
            startchan = "3";

        MSqlQuery channelExists(MSqlQuery::InitCon());
        QString   channelQuery;
        channelQuery = QString("SELECT chanid FROM channel"
                               " WHERE channum='%1' AND sourceid=%2;")
                              .arg(startchan).arg(sourceid);
        channelExists.prepare(channelQuery);

        if (!channelExists.exec() || !channelExists.isActive())
        {
            MythContext::DBError("checkChannelPresets", channelExists);
            return problemFound;
        }

        if (channelExists.size() == 0)
        {
            probs->append(QObject::tr("Card"));
            probs->append(QString(" %1 (").arg(cardid));
            probs->append(QObject::tr("type"));
            probs->append(QString(" %1) ").arg(query.value(3).toString()));
            probs->append(QObject::tr("is set to start on channel"));
            probs->append(QString(" %1, ").arg(startchan));
            probs->append(QObject::tr("which does not exist"));
            probs->append(".\n");
            problemFound = true;
        }
    }

    return problemFound;
}