コード例 #1
0
void UnquoteParser::tag_start(const QString &tag, const list<QString> &options)
{
    if (tag == "br"){
        res += "\n";
    }else if (tag == "p"){
        if (m_bPar){
            res += "\n";
            m_bPar = false;
        }
    }else if (tag == "img"){
        QString src;
        for (list<QString>::const_iterator it = options.begin(); it != options.end(); ++it){
            QString opt   = *it;
            ++it;
            QString value = *it;
            if (opt == "src")
                src = value;
        }
        if (src.left(10) != "icon:smile")
            return;
        bool bOk;
        unsigned nSmile = src.mid(10).toUInt(&bOk, 16);
        if (!bOk)
            return;
        const smile *s = smiles(nSmile);
        if (s){
            res += s->paste;
            return;
        }
        s = defaultSmiles(nSmile);
        if (s)
            res += s->paste;
    }
}
コード例 #2
0
EXPORT const smile *smiles(unsigned n)
{
    if (pSmiles == NULL)
        return defaultSmiles(n);
    if (n < pSmiles->size())
        return &(*pSmiles)[n];
    return NULL;
}
コード例 #3
0
void UnquoteParser::tag_start(const QString &tag, const list<QString> &options)
{
    if (tag == "pre"){
        if (!m_bPre)
            res += "\n";
    }else if (tag == "br"){
        res += "\n";
    }else if (tag == "hr"){
        if (!res.isEmpty() && (res[(int)(res.length() - 1)] != '\n'))
            res += "\n";
        res += "---------------------------------------------------\n";
    }else if (tag == "td"){
        if (m_bTD){
            res += "\t";
            m_bTD = false;
        }
    }else if (tag == "tr"){
        if (m_bTR){
            res += "\n";
            m_bTR = false;
        }
    }else if (tag == "p"){
        if (m_bPar){
            res += "\n";
            m_bPar = false;
        }
    }else if (tag == "img"){
        QString src;
        for (list<QString>::const_iterator it = options.begin(); it != options.end(); ++it){
            QString opt   = *it;
            ++it;
            QString value = *it;
            if (opt == "src")
                src = value;
        }
        if (src.left(10) != "icon:smile")
            return;
        bool bOk;
        unsigned nSmile = src.mid(10).toUInt(&bOk, 16);
        if (!bOk)
            return;
        const smile *s = smiles(nSmile);
        if (s){
            res += s->paste;
            return;
        }
        s = defaultSmiles(nSmile);
        if (s)
            res += s->paste;
    }
}
コード例 #4
0
EXPORT void setSmiles(const char *p)
{
	if (p == NULL)
		p = _smiles;
	if (pSmiles){
		pSmiles->clear();
	}else{
		pSmiles = new vector<string>;
	}
	for (unsigned i = 0; i < 16; i++)
		pSmiles->push_back("");
	for (; *p; ){
		string s;
		unsigned index;
		for (index = 0; index < 16; index++){
			const char *dp = defaultSmiles(index);
			for (; *dp; dp += strlen(dp) + 1)
				if (strcmp(p, dp) == 0)
					break;
			if (*dp)
				break;
		}
		for (; *p; ){
			s += p;
			s += '\x00';
			p += strlen(p) + 1;
		}
		s += '\x00';
		if (index < 16){
			(*pSmiles)[index] = s;
		}else{
			pSmiles->push_back(s);
		}
		p++;
	}
}
コード例 #5
0
bool Smiles::load(const QString &file)
{
    clear();
    for (unsigned i = 0;; i++){
        const smile *s = defaultSmiles(i);
        if (s == NULL)
            break;
        SmileDef sd;
        sd.paste = s->paste;
        sd.icon  = NULL;
        m_smiles.push_back(sd);
    }
    QString fname = file;
    QFile f(fname);
    if (!f.open(IO_ReadOnly))
        return false;
#ifdef USE_EXPAT
    int pdot = fname.findRev(".");
    if ((pdot > 0) && (fname.mid(pdot + 1).lower() == "xep")){
        XepParser p;
        if (!p.parse(f))
            return false;
        for (list<xepRecord>::iterator it = p.m_rec.begin(); it != p.m_rec.end(); ++it){
            xepRecord &r = *it;
            QPixmap pict = p.pict(r.index);
            if (pict.isNull())
                continue;
            SmileDef sd;
            sd.title = getValue(r.title.c_str());
            sd.paste = sd.title;
            string exp   = getValue(r.smiles.c_str());
            for (const char *p = exp.c_str(); *p; p++){
                if (*p == '\\'){
                    if (*(++p) == 0)
                        break;
                    sd.exp += '\\';
                    sd.exp += *p;
                    continue;
                }
                if ((*p == '{') || (*p == '}'))
                    sd.exp += '\\';
                sd.exp += *p;
            }
            QIconSet *is = new QIconSet(pict);
            m_icons.push_back(is);
            sd.icon	 = is;
            unsigned index = (unsigned)(-1);
            for (index = 0;; index++){
                const smile *s = defaultSmiles(index);
                if (s == NULL)
                    break;
#if QT_VERSION < 300
                QString exp = s->exp;
                bool bMatch = false;
                while (!exp.isEmpty()){
                    QString e = getToken(exp, '|', false);
                    QRegExp re(e);
                    int len;
                    if ((re.match(sd.paste.c_str(), 0, &len) == 0) && (len == (int)(sd.paste.length()))){
                        bMatch = true;
                        break;
                    }
                }
                if (bMatch){
                    sd.title = s->title;
                    break;
                }
#else
                QRegExp re(s->exp);
                int len;
                if ((re.match(sd.paste.c_str(), 0, &len) == 0) && ((unsigned)len == sd.paste.length())){
                    sd.title = s->title;
                    break;
                }
#endif
            }
            if (index < 16){
                m_smiles[index] = sd;
            }else{
                m_smiles.push_back(sd);
            }
        }
        return true;
    }
#endif
#ifdef WIN32
    fname = fname.replace(QRegExp("\\"), "/");
#endif
    int pos = fname.findRev("/");
    if (pos >= 0){
        fname = fname.left(pos + 1);
    }else{
        fname = "";
    }
    string s;
    QRegExp start("^ *Smiley *= *");
    QRegExp num("^ *, *-[0-9]+ *, *");
    QRegExp nn("[0-9]+");
    QRegExp re("\\[\\]\\|\\(\\)\\{\\}\\.\\?\\*\\+");
    while (getLine(f, s)){
        QString line = QString::fromLocal8Bit(s.c_str());
        if (line[0] == ';')
            continue;
        int size;
        int pos = start.match(line, 0, &size);
        if (pos < 0)
            continue;
        line = line.mid(size);
        getToken(line, '\"');
        QString dll = getToken(line, '\"', false);
        if (dll.isEmpty())
            continue;
        dll = dll.replace(QRegExp("\\\\"), "/");
        pos = num.match(line, 0, &size);
        if (pos < 0)
            continue;
        QString num = line.left(size);
        line = line.mid(size);
        pos = nn.match(num, 0, &size);
        unsigned nIcon = num.mid(pos, size).toUInt();
        getToken(line, '\"');
        QString pattern = getToken(line, '\"', false);
        getToken(line, '\"');
        QString tip = getToken(line, '\"', false);
        QString dllName = fname + dll;
        dllName = dllName.replace(QRegExp("/\\./"), "/");
        string fn;
        fn = dllName.utf8();
        ICONS_MAP::iterator it = icons.find(fn.c_str());
        IconDLL *icon_dll = NULL;
        if (it == icons.end()){
            icon_dll = new IconDLL;
            if (!icon_dll->load(fn.c_str())){
                delete icon_dll;
                icon_dll = NULL;
            }
            icons.insert(ICONS_MAP::value_type(fn.c_str(), icon_dll));
        }else{
            icon_dll = (*it).second;
        }
        if (icon_dll == NULL)
            continue;
        const QIconSet *icon = icon_dll->get(nIcon);
        if (icon == NULL){
            log(L_DEBUG, "Icon empty %u", nIcon);
            continue;
        }
        QString p;
        QString paste;
        unsigned index = (unsigned)(-1);
        while (!pattern.isEmpty()){
            QString pat = getToken(pattern, ' ', false);
            if (index == (unsigned)(-1)){
                for (index = 0; index < 16; index++){
                    const smile *s = defaultSmiles(index);
                    if (pat == s->paste)
                        break;
                }
            }
            if (paste.isEmpty())
                paste = pat;
            QString res;
            while (!pat.isEmpty()){
                int pos = re.match(pat);
                if (pos < 0)
                    break;
                res += pat.left(pos);
                res += "\\";
                res += pat.mid(pos, 1);
                pat = pat.mid(pos + 1);
            }
            res += pat;
            if (!p.isEmpty())
                p += "|";
            p += res;
        }
        if (tip.isEmpty())
            tip = paste;
        SmileDef sd;
        sd.exp     = p.latin1();
        sd.paste   = paste.latin1();
        sd.title   = tip.latin1();
        sd.icon    = icon;
        if (index < 16){
            m_smiles[index] = sd;
        }else{
            m_smiles.push_back(sd);
        }
    }
    return true;
}