void GroupListEmoticons::CreateToolTips()
{
	int top = 0;

	for(int i = 0; i < num_groups; i++)
	{
		Group &group = groups[i];
		
		if (group.name[0] != '\0')
		{
			RECT rc = CalcRect(group.name, groupFont);
			top += HeightWithBorders(rc);
		}

		int index = 0;
		for (int j = group.start; j <= group.end; j++)
		{
			Emoticon *e = ssd->module->emoticons[j];
			if (e->IgnoreFor(ssd->module))
				continue;

			RECT rc = GetEmoticonRect(group, index);
			rc.top += top;
			rc.bottom += top;
			CreateEmoticonToolTip(e, rc);
			index++;
		}

		top += group.max_height * group.lines + (group.lines + 1) * BORDER;
	}
}
void SmileyPickerController::parse(const QString &page, int startingPosition) {
    m_Emoticons.clear();

	QRegExp smiley("<img src=\"([^\"]+)\" alt=\"([^\"]+)\".*/>");
	qDebug() << "start parsing";

	smiley.setCaseSensitivity(Qt::CaseSensitive);
	smiley.setMinimal(true);

	int nbSmileyPage = 0;
	int pos = startingPosition;
	while((pos = smiley.indexIn(page, pos)) != -1 && nbSmileyPage < 60) {
	    qDebug() << smiley.cap(2);
	    m_Mutex.lockForWrite();
	    Emoticon *e = new Emoticon;
	    e->setTag(smiley.cap(2));
	    e->setDistUrl(smiley.cap(1));
	    m_Emoticons.push_back(e);
	    m_Mutex.unlock();

	    WebResourceManager::get()->getImage(smiley.cap(1));


		pos += smiley.matchedLength();

		++nbSmileyPage;
	}
	qDebug() << "end parsing";


	// -------------------------------------------------------------
	// build index in file for next/previous nav.

	if(pos != -1) {
		bool indexFound = false;
		for(int i = 0 ; i < m_IndexSubpagesInFile.length() ; ++i)
			if(m_IndexSubpagesInFile[i] == pos) {
				indexFound = true;
				break;
			}

		if(!indexFound) {
			m_IndexSubpagesInFile.push_back(pos);
		}
	}

	emit complete();

}
示例#3
0
EmoticonLabel::EmoticonLabel(Emoticon emoticon, QWidget *parent)
  : QLabel(parent)
  , m_ready(false)
{
  QMovie *movie = new QMovie(emoticon->file(), QByteArray(), this);
  setMovie(movie);
  setAlignment(Qt::AlignCenter);

  m_text = emoticon->texts().first();
  setToolTip(LS("<span>") + m_text + LS("</span>"));

  movie->start();

  updateStyleSheet();
}
示例#4
0
QDomText EmoticonExpander::insertEmoticon(QDomText textNode, const Emoticon &emoticon, int index) const
{
    int emoticonLength = emoticon.triggerText().length();

    QDomText afterEmoticon = textNode.splitText(index + emoticonLength);
    textNode.setNodeValue(textNode.nodeValue().mid(0, index));

    QDomElement emoticonElement = textNode.ownerDocument().createElement("img");
    emoticonElement.setAttribute("emoticon", emoticon.triggerText());
    emoticonElement.setAttribute("title", emoticon.triggerText());
    emoticonElement.setAttribute("alt", emoticon.triggerText());
    emoticonElement.setAttribute("src", "file:///" + m_pathProvider->emoticonPath(emoticon));
    textNode.parentNode().insertBefore(emoticonElement, afterEmoticon);

    return afterEmoticon;
}
int GroupListEmoticons::GetIndex(Group &group, int line, int col)
{
	int desired = line * group.cols + col;
	int index = 0;
	for (int j = group.start; j <= group.end; j++)
	{	
		Emoticon *e = ssd->module->emoticons[j];
		if (e->IgnoreFor(ssd->module))
			continue;

		if (index == desired)
			return j;

		index++;
	}
	return -1;
}
void GroupListEmoticons::GetMaxEmoticonSize(Group &group)
{
	group.max_height = 4;
	group.max_width = 4;

	for(int i = group.start; i <= group.end; i++)
	{
		Emoticon *e = ssd->module->emoticons[i];
		if (e->IgnoreFor(ssd->module))
			continue;

		int height, width;
		GetEmoticonSize(e, width, height);

		group.max_height = max(group.max_height, height);
		group.max_width = max(group.max_width, width);
	}
}
int GroupListEmoticons::CountGroups()
{
	int groups = 1;
	char *current_group = ssd->module->emoticons[0]->group;
	for(int i = 1; i < ssd->module->emoticons.getCount(); i++)
	{
		Emoticon *e = ssd->module->emoticons[i];
		if (e->IgnoreFor(ssd->module))
			continue;

		if (stricmp(e->group, current_group) != 0)
		{
			current_group = e->group;
			groups++;
		}
	}
	return groups;
}
void SmileyPickerController::updateView() {
    // ----------------------------------------------------------------------------------------------
    // get the dataModel of the listview if not already available
    using namespace bb::cascades;

    if(m_ListView == NULL) {
        qWarning() << "did not received the listview. quit.";
        return;
    }

    GroupDataModel* dataModel = dynamic_cast<GroupDataModel*>(m_ListView->dataModel());
    if (dataModel) {
        dataModel->clear();
    } else {
        qDebug() << "create new model";
        dataModel = new GroupDataModel(
                QStringList() << "tag"
                              << "localUrl"
                 );
        m_ListView->setDataModel(dataModel);
    }

    // ----------------------------------------------------------------------------------------------
    // push data to the view

    QList<QObject*> datas;
    for(int i = 0 ; i < m_Emoticons.size() ; ++i) {

        Emoticon *e = new Emoticon;
        e->setLocalUrl(m_Emoticons.at(i)->getLocalUrl());
        e->setTag(m_Emoticons.at(i)->getTag());
        datas.push_back(e);

    }

    dataModel->clear();
    dataModel->insertList(datas);


}
示例#9
0
void EmoticonsFilter::make(QList<HtmlToken> &tokens, const QString &text) const
{
  Emoticon emoticon = m_emoticons->get(text);
  if (!emoticon) {
    tokens.append(HtmlToken(text));
    return;
  }

  m_count++;
  HtmlToken a(HtmlToken::Tag, HtmlATag(LS("emoticon:") + ChatId::toBase32(text.toUtf8()), text).toText());
  tokens.append(a);

  QString img = QString(LS("<img class=\"emoticon\" title=\"%1\" alt=\"%1\" src=\"%2\" width=\"%3\" height=\"%4\" />"))
      .arg(text)
      .arg(QUrl::fromLocalFile(emoticon->file()).toString())
      .arg(emoticon->width())
      .arg(emoticon->height());

  HtmlToken tag(img);
  tag.parent = LS("a");
  tokens.append(tag);
  tokens.append(a.toEndTag());
}
示例#10
0
void EmoticonPrefixTreeBuilder::addEmoticon(const Emoticon &emoticon)
{
    Q_ASSERT(Root);

    QString text = emoticon.triggerText().toLower();
    int length = text.length();

    EmoticonPrefixTree *node = Root.data();
    for (int i = 0; i < length; i++)
    {
        QChar c = extractLetter(text.at(i));

        EmoticonPrefixTree *child = node->child(c);
        if (!child)
            child = node->createChild(c);
        node = child;
    }

    if (node->nodeEmoticon().isNull())
        node->setNodeEmoticon(emoticon);
}
示例#11
0
QDomText EmoticonExpander::expandFirstEmoticon(QDomText textNode) const
{
    QString text = textNode.nodeValue().toLower();
    int textLength = text.length();

    if (0 == textLength)
        return QDomText();

    int currentEmoticonStart = -1;
    Emoticon currentEmoticon;

    EmoticonWalker walker(m_tree);

    for (int i = 0; i < textLength; i++)
    {
        Emoticon emoticon = walker.matchEmoticon(text.at(i), (i < textLength - 1) && text.at(i + 1).isLetter());
        if (emoticon.isNull())
            continue;

        // TODO: remove this dependency
        int emoticonStart = i - emoticon.triggerText().length() + 1;
        if (currentEmoticon.isNull() || currentEmoticonStart >= emoticonStart)
        {
            currentEmoticon = emoticon;
            currentEmoticonStart = emoticonStart;
            continue;
        }

        return insertEmoticon(textNode, currentEmoticon, currentEmoticonStart);
    }

    if (!currentEmoticon.isNull())
        insertEmoticon(textNode, currentEmoticon, currentEmoticonStart);

    return QDomText();
}
示例#12
0
void ChatCtrl::FormatEmoticonsAndLinks(tstring& sMsg, tstring& sMsgLower, LONG lSelBegin, bool bUseEmo) {
	if(!sMsg.size())
		return;
	LONG lSelEnd = lSelBegin + sMsg.size();

	// hightlight all URLs and make them clickable
	for(size_t i = 0; i < (sizeof(protocols) / sizeof(protocols[0])); ++i) {
		size_t linkStart = sMsgLower.find(protocols[i]);
		bool isMagnet = (protocols[i] == _T("magnet:?"));
		while(linkStart != tstring::npos) {
			size_t linkEnd = linkStart + protocols[i].size();
			
			try {
				// TODO: complete regexp for URLs
				std::tr1::wregex reg;
//[+]PPA Исправил регулярное выражение для коррктного поиска урлов в VC++ 2010 (пример урла - magnet:?xt=urn:tree:tiger:V3LVT4CSASPLNHRG6DOORAD2SDSBBANIKEI7XHI&xl=260524251&dn=cstrike_full_v.35_(4156).exe  )
				if(isMagnet) // magnet links have totally indifferent structure than classic URL // -/?%&=~#'\\w\\.\\+\\*\\(\\)
					reg.assign(_T("^(\\w)+=[:\\w]+(&(\\w)+=[\\S]*)*[^\\s<>{}\"']+"), std::tr1::regex_constants::icase);
				else
					reg.assign(_T("^([@\\w-]+(\\.)*)+(:[\\d]+)?(/[\\S]*)*[^\\s<>{}\"']+"), std::tr1::regex_constants::icase);
					
				tstring::const_iterator start = sMsg.begin();
				tstring::const_iterator end = sMsg.end();
				std::tr1::match_results<tstring::const_iterator> result;

				if(std::tr1::regex_search(start + linkEnd, end, result, reg, std::tr1::regex_constants::match_default)) {
					dcassert(!result.empty());
					
					 linkEnd += result.length(0);
					 SetSel(lSelBegin + linkStart, lSelBegin + linkEnd);
					if(isMagnet) {
						tstring cURL = ((tstring)(result[0]));
						tstring::size_type dn = cURL.find(_T("dn="));
						if(dn != tstring::npos) {
							string sFileName = Util::encodeURI(Text::fromT(cURL).substr(dn + 3), true);
							int64_t filesize = Util::toInt64(Text::fromT(cURL.substr(cURL.find(_T("xl=")) + 3, cURL.find(_T("&")) - cURL.find(_T("xl=")))));
							tstring shortLink = Text::toT(sFileName) + _T(" (") + Util::formatBytesW(filesize) + _T(")");

							sMsg.replace(linkStart, linkEnd - linkStart, shortLink.c_str());
							std::transform(&sMsgLower.replace(linkStart, linkEnd - linkStart, shortLink.c_str())[linkStart], &sMsgLower[linkEnd], &sMsgLower[linkStart], _totlower);

							setText(shortLink);
							linkEnd = linkStart + shortLink.size();
							SetSel(lSelBegin + linkStart, lSelBegin + linkEnd);
							magnets[shortLink] = _T("magnet:?") + cURL;
					}
				}
					SetSelectionCharFormat(WinUtil::m_TextStyleURL);
				}
			} catch(...) {
			}
			
			linkStart = sMsgLower.find(protocols[i], linkEnd);			
		}
	}

	// insert emoticons
	if(bUseEmo && emoticonsManager->getUseEmoticons()) {
		const Emoticon::List& emoticonsList = emoticonsManager->getEmoticonsList();
		tstring::size_type lastReplace = 0;
		uint8_t smiles = 0;

		while(true) {
			tstring::size_type curReplace = tstring::npos;
			Emoticon* foundEmoticon = NULL;

			for(Emoticon::Iter emoticon = emoticonsList.begin(); emoticon != emoticonsList.end(); ++emoticon) {
				tstring::size_type idxFound = sMsg.find((*emoticon)->getEmoticonText(), lastReplace);
				if(idxFound < curReplace || curReplace == tstring::npos) {
					curReplace = idxFound;
					foundEmoticon = (*emoticon);
				}
			}

			if(curReplace != tstring::npos && smiles < MAX_EMOTICONS) {
				CHARFORMAT2 cfSel;
				cfSel.cbSize = sizeof(cfSel);

				lSelBegin += (curReplace - lastReplace);
				lSelEnd = lSelBegin + foundEmoticon->getEmoticonText().size();
				SetSel(lSelBegin, lSelEnd);

				GetSelectionCharFormat(cfSel);
				if(!(cfSel.dwEffects & CFE_LINK)) {
					CImageDataObject::InsertBitmap(GetOleInterface(), foundEmoticon->getEmoticonBmp(cfSel.crBackColor));

					++smiles;
					++lSelBegin;
				} else lSelBegin = lSelEnd;
				lastReplace = curReplace + foundEmoticon->getEmoticonText().size();
			} else break;
		}
	}

}
QString AnimatedEmoticonPathProvider::emoticonPath(const Emoticon &emoticon)
{
	return emoticon.animatedFilePath();
}
示例#14
0
void SmileyPickerController::loadDefautSmiley() {
    m_Emoticons.clear();

    Emoticon *e;
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/smilies/pfff.gif"); e->setTag(":pfff:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/smile.gif");        e->setTag(":)");     m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/mad.gif");          e->setTag(":fou:");  m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/smilies/love.gif"); e->setTag(":love:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/ddr555.gif");       e->setTag("[:ddr555]"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/smilies/ange.gif"); e->setTag(":ange:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/frown.gif");        e->setTag(":("); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/confused.gif");     e->setTag(":??:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/smilies/heink.gif");e->setTag(":heink:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/biggrin.gif");      e->setTag(":D"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/tongue.gif");       e->setTag(":p"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/smilies/lol.gif");  e->setTag(":lol:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/smilies/cry.gif");  e->setTag(":cry:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/smilies/sleep.gif");e->setTag(":sleep:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/smilies/sweat.gif");e->setTag(":sweat:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/wink.gif");         e->setTag(";)"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/smilies/na.gif");   e->setTag(":na:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/smilies/wahoo.gif");e->setTag(":wahoo:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/smilies/bounce.gif");e->setTag(":bounce:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/smilies/ouch.gif");  e->setTag(":ouch:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/smilies/sarcastic.gif"); e->setTag(":sarcastic:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/smilies/kaola.gif");  e->setTag(":kaola:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/smilies/sol.gif");    e->setTag(":sol:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/smilies/hello.gif");  e->setTag(":hello:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/smilies/non.gif");    e->setTag(":non:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/smilies/pouah.gif");  e->setTag(":pouah:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/smilies/whistle.gif");e->setTag(":whistle:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/smilies/miam.gif");   e->setTag(":miam:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/hebe.gif");           e->setTag(":hebe:"); m_Emoticons.push_back(e);
    e = new Emoticon; e->setLocalUrl("asset:///images/smiley/redface.gif"); e->setTag(":o"); m_Emoticons.push_back(e);

    m_Mutex.lockForWrite();
    m_Pushing = false;
    m_Page = "";
    m_Mutex.unlock();

    updateView();
}
void GroupListEmoticons::Load()
{
	selection = -1;

	// Load fonts
	groupFont = mir_font_get(_T("Emoticons"), _T("Group Name"), &groupColor);
	emoticonFont = mir_font_get(_T("Emoticons"), _T("Emoticons Text"), &emoticonColor);
	groupBkgColor = mir_color_get(_T("Emoticons"), _T("Group Background"));
	ssd->background = mir_color_get(_T("Emoticons"), _T("Emoticons Background"));

	num_groups = CountGroups();
	groups = (Group *) malloc(num_groups * sizeof(Group));

	char *current_group = ssd->module->emoticons[0]->group;

	int current_id = -1;
	int i;
	for(i = 0; i < ssd->module->emoticons.getCount(); i++)
	{
		Emoticon *e = ssd->module->emoticons[i];
		if (e->IgnoreFor(ssd->module))
			continue;

		if (stricmp(e->group, current_group) != 0 || i == 0)
		{
			if (i != 0)
				groups[current_id].end = i - 1;

			current_group = e->group;
			current_id++;

			SetGroupName(groups[current_id], current_group);
			groups[current_id].start = i;
			groups[current_id].count = 1;
		}
		else 
		{
			groups[current_id].count++;
		}
	}
	groups[current_id].end = i - 1;

	// First calc the width
	window.width = 0;
	for(i = 0; i < num_groups; i++)
	{
		Group &group = groups[i];
		GetMaxEmoticonSize(group);
		group.cols = GetNumOfCols(group.count);

		if (group.name[0] != _T('\0'))
		{
			RECT rc = CalcRect(group.name, groupFont);
			window.width = max(window.width, rc.right - rc.left + 2 * BORDER + 1);
		}

		window.width = max(window.width, group.max_width * group.cols + (group.cols + 1) * BORDER);
	}

	// Now calc the height
	window.height = 0;
	for(i = 0; i < num_groups; i++)
	{
		Group &group = groups[i];
		group.top = window.height;

		int w = window.width - BORDER;

		// Recalc the num of cols
		group.lines = GetNumOfLines(group.count, group.cols);
		
		int new_cols = w / (group.max_width + BORDER);
		int new_lines = GetNumOfLines(group.count, new_cols);
		if (new_lines < group.lines)
		{
			group.cols = new_cols;
			group.lines = new_lines;
		}


		// If there is space left, put it into the emoticons
		group.max_width += (w - group.cols * (group.max_width + BORDER)) / group.cols;

		if (group.name[0] != '\0')
		{
			RECT rc = CalcRect(group.name, groupFont);
			window.height += HeightWithBorders(rc);
		}

		window.height += group.max_height * group.lines + (group.lines + 1) * BORDER;
	}
}
void GroupListEmoticons::Draw(HDC hdc)
{
	EraseBackground(hdc);

	RECT client_rc;
	GetClientRect(hwnd, &client_rc);

	COLORREF old_text_color = SetTextColor(hdc, emoticonColor);

	int top = 0;

	for(int i = 0; i < num_groups; i++)
	{
		Group &group = groups[i];
		
		if (group.name[0] != '\0')
		{
			RECT rc = CalcRect(group.name, groupFont);
			rc.top += top + BORDER;
			rc.bottom += top + BORDER;

			int width = rc.right - rc.left;
			rc.left = client_rc.left + (client_rc.right - client_rc.left - width) / 2;
			rc.right = rc.left + width;

			RECT title_rc = client_rc;
			title_rc.top = rc.top - BORDER;
			title_rc.bottom = rc.bottom + BORDER + 1;
			HBRUSH hB = CreateSolidBrush(groupBkgColor);
			FillRect(hdc, &title_rc, hB);
			DeleteObject(hB);

			SetTextColor(hdc, groupColor);

			DrawEmoticonText(hdc, group.name, rc, groupFont);

			SetTextColor(hdc, emoticonColor);

			top += HeightWithBorders(rc);
		}

		int index = 0;
		for (int j = group.start; j <= group.end; j++)
		{	
			Emoticon *e = ssd->module->emoticons[j];
			if (e->IgnoreFor(ssd->module))
				continue;

			RECT rc = GetEmoticonRect(group, index);
			rc.top += top;
			rc.bottom += top;

			DrawEmoticon(hdc, j, rc);

			index++;
		}

		top += group.max_height * group.lines + (group.lines + 1) * BORDER;
	}

	SetTextColor(hdc, old_text_color);
}