Exemplo n.º 1
0
 void ChromeWidget::getInitialSnippets()
 {
   //TODO: get the list of containers form m_dom (via new method to be added).
   QList <QWebElement> initialSnippets = m_dom->getInitialElements();
   foreach(QWebElement element, initialSnippets) {
     ChromeSnippet * s = getSnippet(element.attribute("id"));
     if (s && s->initiallyVisible())
       s->setVisible(true);
   }
Exemplo n.º 2
0
 void ChromeWidget::anchorTogether(ChromeSnippet* first, const QString& secondId, qreal x, qreal y)
 {
   ChromeSnippet* second = getSnippet(secondId);
   if (second){
     m_layout->anchorTogether(first, second, x, y);
   }
   else {
     qDebug() << "Chrome::anchorTogether: error, not found: " << secondId;
   }
 }
Exemplo n.º 3
0
/**
 * Parse the received XML, and search for title& snippet attributes.
 */
void MediaWiki::processSearchResults()
{
	/* for ex, try this request for "bear" in your browser:
	 *   http://en.wikipedia.org/w/api.php?action=query&format=xml&
	 *   list=search&srwhat=text&srsearch=bear
	 * the output looks like this:
	 * ...
	 * <search>
	 * <p ns="0" title="title1" snippet="text.." size="10283"
	 * wordcount="1324" timestamp="2011-04-12T14:25:24Z" />
	 * more paragraphs
	 * </search>
	 * ...
	 */

	// Search for each p paragraph, and get the title & snippet.
	MAUtil::String input = mBuffer;
	int openTag = input.find("<p ",0);

	while( openTag != -1 )
	{
		int closeTag = input.find("/>", openTag+1);
		if (closeTag != -1 && closeTag > openTag)
		{
			MAUtil::String  record = input.substr(
				openTag+2, closeTag - openTag +1);
			// A record, ex: <p ns="0" title="title1" snippet="text.."
			// size="10283" wordcount="1324" timestamp="2011-04-12T14:25:24Z" />
			// Add the title if it doesn't exist yet.
			MAUtil::String newRecord = getTitle(record);
			bool canAdd(true);
			for (int i=0; i < mWiki->titleResults.size(); i++)
			{
				if ( mWiki->titleResults[i] == newRecord )
				{
					canAdd = false;
				}
			}
			if (canAdd)
			{
				mWiki->titleResults.add(newRecord);
				mWiki->snippetResults.add(getSnippet(record));
			}
		}
		input.remove(0,closeTag);

		// Get the next tag.
		openTag = input.find("<p ",0);
	}
}