Esempio n. 1
0
/**
 * \en
 * Deletes row, having section tag
 * \_en
 * \ru
 * Рекурсивная функция. Удаляет строки, содержащие тег секции
 * \_ru
* \param node - \en context \_en \ru узел из которого нужно удалить строки \_ru
 */
void
aMSOTemplate::clearRow(QDomNode node)
{
QDomNode n = node.lastChild();
	while( !n.isNull() )
	{	
		if(n.isText())
		{
			QString str = n.nodeValue();
			QRegExp re;
			re.setPattern(QString("%1.*%2").arg(open_token_section).arg(close_token_section));
			re.setMinimal(true);
			int pos = re.search(str,0);
			if(pos!=-1)
			{
				QDomNode tmp = n;
				while(!tmp.parentNode().isNull())
				{
					tmp = tmp.parentNode();
					if( tmp.nodeName()=="Row" ) 
					{
						tmp.parentNode().removeChild(tmp);
						break;
					}
				}
			}
		}
		else
		{
			clearRow(n);
		}
		n = n.previousSibling();
	}	
}
Esempio n. 2
0
/** 
 * \en
 * Added value to end tag with name `sname'. Don't deletes tag. 
 * \_en
 * \ru
 * Рекурсивная функция поиска и замены тегов на их значения в node.
 * Не заменяет теги, а дописывает значения в конец. 
 * Для удаления тэгов используйте функцию cleanUpTags()
 * \_ru
 * \param node - \en context for searching \_en \ru узел, с которого осуществляется поиск. \_ru
 * \param sname - \en tag name \_en \ru имя тега для поиска \_ru
 * \see cleanUpTags() getNodeTags() insertRowValues()
 */
void
aMSOTemplate::searchTags(QDomNode node, const QString &sname )
{
	QDomNode n = node.lastChild();
	while( !n.isNull() )
	{	
		bool res = getNodeTags(n, sname, false);
		if( res ) 
		{
			insertRowValues(n);
		}
		else
		{
			res = getNodeTags(n, sname, true);
			if(res)
			{
				insertTagsValues(n, sname);
			}
			else
			{
				searchTags(n, sname);
			}
		}
		n = n.previousSibling();
	}
}
Esempio n. 3
0
QDomNode QDomNodeProto:: lastChild() const
{
  QDomNode *item = qscriptvalue_cast<QDomNode*>(thisObject());
  if (item)
    return item->lastChild();
  return QDomNode();
}
Esempio n. 4
0
void PathMapper::addHistory(const QString &localpath, const QString &serverpath, bool saveinproject)
{
  bool exists = false;
  for (unsigned int cnt = 0; cnt < m_serverlist.count() && !exists; cnt++ )
    if(m_serverlist[cnt] == serverpath &&  m_locallist[cnt] == localpath)
      exists = true;

  if(!exists)
  {
    if(saveinproject)
    {
      QDomNode node = pathMapperNode();
      QDomNode newnode = Project::ref()->dom()->createElement("mapping");
  
      QDomAttr serverattr = Project::ref()->dom()->createAttribute("serverpath");
      serverattr.setValue(serverpath);
      QDomAttr localattr = Project::ref()->dom()->createAttribute("localpath");
      localattr.setValue(localpath);
  
      newnode.attributes().setNamedItem(serverattr);
      newnode.attributes().setNamedItem(localattr);
  
      node = node.namedItem("mappings");
      node.insertAfter(newnode, node.lastChild());
    }
    
    m_serverlist.append(serverpath);
    m_locallist.append(localpath);
  }

}
Esempio n. 5
0
void YoutubeModel::parseResults(KJob *job)
{
    if (!m_datas.contains(static_cast<KIO::Job*>(job))) {
        return;
    }

    QDomDocument document;
    document.setContent(m_datas[static_cast<KIO::Job*>(job)]);

    QDomNodeList entries = document.elementsByTagName("entry");
    for (int i = 0; i < entries.count(); i++) {
        QString id = entries.at(i).namedItem("id").toElement().text().split(':').last();
        QString title = entries.at(i).namedItem("title").toElement().text();
        QDomNode mediaNode = entries.at(i).namedItem("media:group");
        QString description = mediaNode.namedItem("media:description").toElement().text();
        QString keywords = mediaNode.namedItem("media:keywords").toElement().text();
        QString mediaUrl = mediaNode.namedItem("media:player").toElement().attribute("url");
	uint mediaDuration = mediaNode.namedItem("yt:duration").toElement().attribute("seconds").toInt();
        // FIXME: more than one media:thumbnail exists
        QString thumbnail = mediaNode.namedItem("media:thumbnail").toElement().attribute("url");

        QDomNode n = mediaNode.firstChild();
        QString MEDIA_CONTENT_URL;
        QString MEDIA_CONTENT_TYPE;
        do {
            if (n.nodeName() == "media:content" && n.toElement().attribute("yt:format") == "5") {
                MEDIA_CONTENT_URL = n.toElement().attribute("url");
                MEDIA_CONTENT_TYPE = n.toElement().attribute("type");
                break;
            }
            n = n.nextSibling();
        } while (n != mediaNode.lastChild());

        QString embeddedHTML = QString(
        "<object width=\"425\" height=\"350\">\n"
        "<param name=\"movie\" value=\"%1\"></param>\n"
        "<embed src=\"%2\"\n"
        "type=\"%3\" width=\"425\" height=\"350\">\n"
        "</embed>\n"
        "</object>\n").arg(MEDIA_CONTENT_URL, MEDIA_CONTENT_URL, MEDIA_CONTENT_TYPE);

        VideoPackage video;
        video.title = title;
        video.description = description;
        video.keywords = keywords.split(", ");
        video.id = id;
        video.duration = mediaDuration;
        video.embeddedHTML = embeddedHTML;
        video.thumbnail = thumbnail;
        video.url = mediaUrl;

        m_videos << video;
        reset();
    }
}
SyntaxHighlighter::SyntaxHighlighter( CodeEditor *parent, QDomNode& node)
	: QSyntaxHighlighter(parent->document()), m_pEditor(parent)
{
	// string list that holds the key words
	QStringList keys;

	// get first child
	QDomNode temp = node.lastChild();

	//////////////////////////////////////////////////////////////////////////
	// get key words
	while(!temp.isNull())
	{
		// get children
		QDomNodeList children = temp.childNodes();

		// get attributes
		QDomNamedNodeMap attributes = temp.toElement().attributes();

		// extract data
		for (int i = 0; i < children.length(); i++)
		{
			QString keyword = attributes.namedItem("StartTag").nodeValue() + 
								children.at(i).toElement().text() +
								attributes.namedItem("EndTag").nodeValue();

			keys.append(keyword);
		}	
			
		// rule 
		HighlightingRule rule;
		rule.format.setForeground(QColor(attributes.namedItem("Color").nodeValue()));
		rule.format.setFontItalic(attributes.namedItem("Italic").nodeValue().toInt());
		rule.format.setFontWeight(attributes.namedItem("Bold").nodeValue().toInt());

		// add to rule set
		foreach (const QString &pattern, keys)
		{			
			rule.pattern = QRegExp(pattern);
			highlightingRules.append(rule);
		}

		// clear keys
		keys.clear();

		// next
		temp = temp.previousSibling();
	}
Esempio n. 7
0
/**
 * \en
 * Deletes from node attribute
 * \_en
 * \ru
 * Рекурсивная функция. Удаляет из узла атрибут
 * \_ru
* \param node - \en context \_en \ru узел из которого нужно удалить атрибут \_ru
* \param nodename - \en node name \_en \ru имя узла \_ru
* \param attr - \en attribut name \_en \ru имя атрибута,который нужно удалить \_ru
 */
void
aMSOTemplate::clearAttributes(QDomNode node, const QString nodename, const QString attr)
{
	QDomNode n = node.lastChild();
	while( !n.isNull() )
	{
		if( n.parentNode().nodeName()==nodename ) 
		{	
			n.parentNode().toElement().removeAttribute(attr);		
			break;
		}	
		else
		{
			clearAttributes(n, nodename, attr);
		}
		n = n.previousSibling();
	}
}
Esempio n. 8
0
/**
 * \en
 * Deletes tags from \a node
 * \_en
 * \ru
 * Удаляет рекурсивно теги из \a node.
 * \_ru
 * \param node - \en context \_en \ru узел из которого нужно удалить теги \_ru
 * \param section - \ru true, если надо удалить тег секции \_ru
 */
void
aMSOTemplate::clearTags(QDomNode node, bool section )
{
	if(node.isNull()) return;
	
	QDomNode n = node.lastChild();
	while( !n.isNull() )
	{	
		if(n.isText())
		{
			QString str = n.nodeValue();
			QRegExp re;
			if(section)
			{
				re.setPattern(QString("%1.*%2").arg(open_token_section).arg(close_token_section));
			}
			else
			{
				re.setPattern(QString("%1.*%2").arg(open_token).arg(close_token));
			}
			re.setMinimal(true);
			int pos = re.search(str,0);
		
			while(pos != -1)
			{
				str = str.remove(re);
				pos = re.search(str,0);
			}
			n.setNodeValue(str);			
		}
		else
		{
			clearTags(n,section);
		}
		n = n.previousSibling();
	}	
}
Esempio n. 9
0
    /**
     * @brief parseCmd
     * @param cmd
     * @param ns
     * @return
     *
     * 解析客户端发送的数据流
     * 解析用户发送的命令,如果是报文,直接转发,返回值为0,否则返回1, ns 中存储命名空间列表
     *开始报文的格式为
     <start>
        <namespace/>
        <namespace/>
        <namespace/>
        <appname/>
        ..
     </start>
     */
    static int     parseCmd(const QString cmd, QList<QString> &ns)
{
    int pos = 0;

    pos = cmd.indexOf(QString("<CZXP"));

    if ( pos < 0)
        return CMD_ERROR;
    pos = cmd.indexOf(QString("iq"));
    if ( pos >= 0) return CMD_NORMAL;
    pos = cmd.indexOf(QString("message"));
    if (pos >= 0) return CMD_NORMAL;
    QDomDocument  dom;
    QDomElement   root;
    //QDomNode      root;
    QDomNodeList  nslist;

    if( !dom.setContent(cmd.toUtf8()))
        return CMD_ERROR;
    //如果没有start节点则认为是正常的报文
    root = dom.firstChild().toElement();
    if ( root.isNull())
        return CMD_NORMAL;
    nslist = root.elementsByTagName(QString("namespace"));
    int sz = nslist.size();
    if ( sz  == 0 )
        return CMD_NORMAL;
    ns.clear();
    for ( pos = 0; pos < sz; ++pos)
    {
        QDomNode    node = nslist.item(pos);
        QString     value = node.lastChild().nodeValue();
        ns.push_back(value);
    }
    return CMD_START;
}
Esempio n. 10
0
/**
 * Load XML file that OS X generates for us for Audio CDs, calculate checksum
 */
bool CdDecoder::initialize()
{
    QFile        TOCfile(devicename + "/.TOC.plist");
    QDomDocument TOC;
    uint         trk;

    m_tracks.clear();
    m_firstTrack = m_lastTrack = m_leadout = 0;

    if (!TOCfile.open(QIODevice::ReadOnly))
    {
        LOG(VB_GENERAL, LOG_ERR,
            "Unable to open Audio CD TOC file: " + TOCfile.fileName());
        return false;
    }

    if (!TOC.setContent(&TOCfile))
    {
        LOG(VB_GENERAL, LOG_ERR,
            "Unable to parse Audio CD TOC file: " + TOCfile.fileName());
        TOCfile.close();
        return false;
    }


    // HACK. This is a really bad example of XML parsing. No type checking,
    // it doesn't deal with comments. It only works because the TOC.plist
    // file is generated (i.e. a fixed format)

    QDomElement root = TOC.documentElement();
    QDomNode    node = root.firstChild()        // <dict>
                           .namedItem("array")  //   <key>Sessions</key><array>
                           .firstChild()        //     <dict>
                           .firstChild();
    while (!node.isNull())
    {
        if (node.nodeName() == "key")
        {
            QDomText t = node.firstChild().toText();  // <key>  t  </key>
            node       = node.nextSibling();          // <integer>i</integer>
            int      i = node.firstChild().toText()
                             .data().toInt();

            if (t.data() == "First Track")
                m_firstTrack = i;
            if (t.data() == "Last Track")
                m_lastTrack = i;
            if (t.data() == "Leadout Block")
                m_leadout = i;
        }
                                         // <key>Track Array</key>
        if (node.nodeName() == "array")  // <array>
        {
            node = node.firstChild();    // First track's <dict>

            for (trk = m_firstTrack; trk <= m_lastTrack; ++trk)
            {
                m_tracks.push_back(node.lastChild().firstChild()
                                       .toText().data().toInt());

                node = node.nextSibling();  // Look at next <dict> in <array>
            }
        }

        node = node.nextSibling();
    }
    TOCfile.close();


    // Calculate some stuff for later CDDB/FreeDB lookup

    m_lengthInSecs = (m_leadout - m_tracks[0]) / 75.0;

    int checkSum = 0;
    for (trk = 0; trk <= m_lastTrack - m_firstTrack; ++trk)
        checkSum += addDecimalDigits(m_tracks[trk] / 75);

    uint totalTracks = 1 + m_lastTrack - m_firstTrack;
    m_diskID = ((checkSum % 255) << 24) | (int)m_lengthInSecs << 8
                                        | totalTracks;

    QString hexID;
    hexID.setNum(m_diskID, 16);
    LOG(VB_MEDIA, LOG_INFO, QString("CD %1, ID=%2").arg(devicename).arg(hexID));


    // First erase any existing metadata:
    for (trk = 0; trk < m_mData.size(); ++trk)
        delete m_mData[trk];
    m_mData.clear();


    // Generate empty MetaData records.
    // We fill in the other details later (from CDDB if possible)

    m_tracks.push_back(m_leadout);  // This simplifies the loop

    for (trk = 1; trk <= totalTracks; ++trk)
    {
        QString file = fileForTrack(devicename, trk);
        uint    len  = 1000 * (m_tracks[trk] - m_tracks[trk-1]) / 75;

        m_mData.push_back(new Metadata(file, NULL, NULL, NULL,
                                       NULL, NULL, 0, trk, len));
    }


    // Try to fill in this MetaData from CDDB lookup:
    lookupCDDB(hexID, totalTracks);


    inited = true;
    return true;
}