void HuggleFeedProviderWiki::Process(QString data)
{
    //QStringList lines = data.split("\n");
    QDomDocument d;
    d.setContent(data);
    QDomNodeList l = d.elementsByTagName("rc");
    int CurrentNode = l.count();
    if (l.count() == 0)
    {
        Huggle::Syslog::HuggleLogs->Log("Error, wiki provider returned: " + data);
        return;
    }
    // recursively scan all RC changes
    QDateTime t = this->LatestTime;
    bool Changed = false;
    while (CurrentNode > 0)
    {
        CurrentNode--;
        // get a time of rc change
        QDomElement item = l.at(CurrentNode).toElement();
        if (!item.attributes().contains("timestamp"))
        {
            Huggle::Syslog::HuggleLogs->Log(_l("rc-timestamp-missing", item.toElement().nodeName()));
            continue;
        }
        QDateTime time = MediaWiki::FromMWTimestamp(item.attribute("timestamp"));
        if (time < t)
        {
            // this record is older than latest parsed record, so we don't want to parse it
            continue;
        } else
        {
            Changed = true;
            t = time;
        }
        if (!item.attributes().contains("type"))
        {
            Huggle::Syslog::HuggleLogs->Log(_l("rc-type-missing", item.text()));
            continue;
        }
        if (!item.attributes().contains("title"))
        {
            Huggle::Syslog::HuggleLogs->Log(_l("rc-title-missing", item.text()));
            continue;
        }
        QString type = item.attribute("type");
        if (type == "edit" || type == "new")
        {
            ProcessEdit(item);
        }
        else if (type == "log")
        {
            ProcessLog(item);
        }
    }
    if (Changed)
    {
        this->LatestTime = t.addSecs(1);
    }
}
QString cDefinable::getNodeValue( const QDomElement &Tag )
{
	QString Value = QString();
	
	if( !Tag.hasChildNodes() )
		return "";
	else
	{
		QDomNode childNode = Tag.firstChild();
		while( !childNode.isNull() )
		{
			if( !childNode.isElement() )
			{
				if( childNode.isText() )
					Value += childNode.toText().data();
				childNode = childNode.nextSibling();
				continue;
			}
			QDomElement childTag = childNode.toElement();
			if( childTag.nodeName() == "random" )
			{
				if( childTag.attributes().contains("min") && childTag.attributes().contains("max") )
					Value += QString("%1").arg( RandomNum( childTag.attributeNode("min").nodeValue().toInt(), childTag.attributeNode("max").nodeValue().toInt() ) );
				else if( childTag.attributes().contains("valuelist") )
				{
					QStringList RandValues = QStringList::split(",", childTag.attributeNode("list").nodeValue());
					Value += RandValues[ RandomNum(0,RandValues.size()-1) ];
				}
				else if( childTag.attributes().contains( "list" ) )
				{
					Value += DefManager->getRandomListEntry( childTag.attribute( "list" ) );
				}
				else if( childTag.attributes().contains("dice") )
					Value += QString("%1").arg(rollDice(childTag.attributeNode("dice").nodeValue()));
				else
					Value += QString("0");
			}

			// Process the childnodes
			QDomNodeList childNodes = childTag.childNodes();

			for( int i = 0; i < childNodes.count(); i++ )
			{
				if( !childNodes.item( i ).isElement() )
					continue;

				Value += this->getNodeValue( childNodes.item( i ).toElement() );
			}
			childNode = childNode.nextSibling();
		}
	}
	return hex2dec( Value );
}
// Method for processing one node
void WPDefManager::ProcessNode( QDomElement Node )
{
	if( Node.isNull() ) 
		return;

	QString NodeName = Node.nodeName();

	if( NodeName == "include" )
	{
		// Try to get the filename
		// <include file="data\npcs.xml" \>
		if( !Node.attributes().contains( "file" ) )
			return;

		// Get the filename and import it
		ImportSections( Node.attribute("file") );
		return;
	}

	// Get the Node ID
	if( !Node.attributes().contains( "id" ) )
		return;

	QString NodeID = Node.attribute("id");

	// IF's for all kind of nodes
	// <item id="xx">
	// <script id="xx">
	// <npc id="xx">
	if( NodeName == "item" )
		Items[ NodeID ] = Node;
	else if( NodeName == "script" )
		Scripts[ NodeID ] = Node;
	else if( NodeName == "npc" )
		NPCs[ NodeID ] = Node;
	else if( NodeName == "menu" )
		Menus[ NodeID ] = Node;
	else if( NodeName == "spell" )
		Spells[ NodeID ] = Node;
	else if( NodeName == "list" )
		StringLists[ NodeID ] = Node;
	else if( NodeName == "privlevel" )
		PrivLevels[ NodeID ] = Node;
	else if( NodeName == "spawnregion" )
		SpawnRegions[ NodeID ] = Node;
	else if( NodeName == "region" )
		Regions[ NodeID ] = Node;
	else if( NodeName == "multi" )
		Multis[ NodeID ] = Node;
	else if( NodeName == "text" )
		Texts[ NodeID ] = Node;
}
Example #4
0
void XdgMenuPrivate::appendChilds(QDomElement& srcElement, QDomElement& destElement)
{
    MutableDomElementIterator it(srcElement);

    while(it.hasNext())
        destElement.appendChild(it.next());

    if (srcElement.attributes().contains("deleted"))
        destElement.setAttribute("deleted", srcElement.attribute("deleted"));

    if (srcElement.attributes().contains("onlyUnallocated"))
        destElement.setAttribute("onlyUnallocated", srcElement.attribute("onlyUnallocated"));
}
void HuggleFeedProviderWiki::ProcessEdit(QDomElement item)
{
    WikiEdit *edit = new WikiEdit();
    edit->Page = new WikiPage(item.attribute("title"));
    QString type = item.attribute("type");
    if (type == "new")
        edit->NewPage = true;
    if (item.attributes().contains("newlen") && item.attributes().contains("oldlen"))
        edit->Size = item.attribute("newlen").toInt() - item.attribute("oldlen").toInt();
    if (item.attributes().contains("user"))
        edit->User = new WikiUser(item.attribute("user"));
    if (item.attributes().contains("comment"))
        edit->Summary = item.attribute("comment");
    if (item.attributes().contains("bot"))
        edit->Bot = true;
    if (item.attributes().contains("anon"))
        edit->User->ForceIP();
    if (item.attributes().contains("revid"))
    {
        edit->RevID = QString(item.attribute("revid")).toInt();
        if (edit->RevID == 0)
        {
            edit->RevID = WIKI_UNKNOWN_REVID;
        }
    }
    if (item.attributes().contains("minor"))
        edit->Minor = true;
    edit->IncRef();
    this->InsertEdit(edit);
}
		void MainWindow::loadWinProperties(QWidget *window, QDomElement *docElement)
		{
			QDomElement node = docElement->firstChildElement(window->objectName());
			if(!node.isNull())
			{
				window->setGeometry(node.attributes().namedItem("x").nodeValue().toInt(),
									node.attributes().namedItem("y").nodeValue().toInt(),
									node.attributes().namedItem("w").nodeValue().toInt(),
									node.attributes().namedItem("h").nodeValue().toInt());

				if(window != this)
					((SoSSubWindow*)window)->setAllowShow(node.attributes().namedItem("visible").nodeValue().toInt());
			}
		}
Example #7
0
void Core::LoadDefs()
{
    QFile defs(Configuration::GetConfigurationPath() + "users.xml");
    if (QFile(Configuration::GetConfigurationPath() + "users.xml~").exists())
    {
        Huggle::Syslog::HuggleLogs->Log("WARNING: recovering definitions from last session");
        QFile(Configuration::GetConfigurationPath() + "users.xml").remove();
        if (QFile(Configuration::GetConfigurationPath() + "users.xml~").copy(Configuration::GetConfigurationPath() + "users.xml"))
        {
            QFile().remove(Configuration::GetConfigurationPath() + "users.xml~");
        } else
        {
            Huggle::Syslog::HuggleLogs->Log("WARNING: Unable to recover the definitions");
        }
    }
    if (!defs.exists())
    {
        return;
    }
    defs.open(QIODevice::ReadOnly);
    QString Contents(defs.readAll());
    QDomDocument list;
    list.setContent(Contents);
    QDomNodeList l = list.elementsByTagName("user");
    if (l.count() > 0)
    {
        int i=0;
        while (i<l.count())
        {
            WikiUser *user;
            QDomElement e = l.at(i).toElement();
            if (!e.attributes().contains("name"))
            {
                i++;
                continue;
            }
            user = new WikiUser();
            user->Username = e.attribute("name");
            if (e.attributes().contains("badness"))
            {
                // do not resync this user while we init the db, this is first time it's written to it so there is no point in that
                user->SetBadnessScore(e.attribute("badness").toInt(), false, false);
            }
            WikiUser::ProblematicUsers.append(user);
            i++;
        }
    }
    HUGGLE_DEBUG1("Loaded " + QString::number(WikiUser::ProblematicUsers.count()) + " records from last session");
    defs.close();
}
Example #8
0
static void helperToXmlAddDomElement(QXmlStreamWriter* stream, const QDomElement& element, const QStringList &omitNamespaces)
{
    stream->writeStartElement(element.tagName());

    /* attributes */
    QString xmlns = element.namespaceURI();
    if (!xmlns.isEmpty() && !omitNamespaces.contains(xmlns))
        stream->writeAttribute("xmlns", xmlns);
    QDomNamedNodeMap attrs = element.attributes();
    for (int i = 0; i < attrs.size(); i++)
    {
        QDomAttr attr = attrs.item(i).toAttr();
        stream->writeAttribute(attr.name(), attr.value());
    }

    /* children */
    QDomNode childNode = element.firstChild();
    while (!childNode.isNull())
    {
        if (childNode.isElement())
        {
            helperToXmlAddDomElement(stream, childNode.toElement(), QStringList() << xmlns);
        } else if (childNode.isText()) {
            stream->writeCharacters(childNode.toText().data());
        }
        childNode = childNode.nextSibling();
    }
    stream->writeEndElement();
}
Example #9
0
void cleanMathml(QDomElement pElement)
{
    // Clean up the current element
    // Note: the idea is to remove all the attributes that are not in the
    //       MathML namespace. Indeed, if we were to leave them in then the XSL
    //       transformation would either do nothing or, worst, crash OpenCOR...

    static const QString MathmlNamespace = "http://www.w3.org/1998/Math/MathML";

    QDomNamedNodeMap attributes = pElement.attributes();
    QList<QDomNode> nonMathmlAttributes = QList<QDomNode>();

    for (int i = 0, iMax = attributes.count(); i < iMax; ++i) {
        QDomNode attribute = attributes.item(i);

        if (attribute.namespaceURI().compare(MathmlNamespace))
            nonMathmlAttributes << attribute;
    }

    foreach (QDomNode nonMathmlAttribute, nonMathmlAttributes)
        pElement.removeAttributeNode(nonMathmlAttribute.toAttr());

    // Go through the element's child elements, if any, and clean them up

    for (QDomElement childElement = pElement.firstChildElement();
         !childElement.isNull(); childElement = childElement.nextSiblingElement()) {
        cleanMathml(childElement);
    }
}
Example #10
0
void FileWriter::writeElementChilds(const QDomElement &AParent)
{
	QDomNode node = AParent.firstChild();
	while (!node.isNull())
	{
		if (node.isElement())
		{
			QDomElement elem = node.toElement();
			if (elem.tagName() != "thread")
			{
				FXmlWriter->writeStartElement(elem.tagName());

				QString elemNs = elem.namespaceURI();
				if (!elemNs.isEmpty() && elem.parentNode().namespaceURI()!=elemNs)
					FXmlWriter->writeAttribute("xmlns",elem.namespaceURI());

				QDomNamedNodeMap attrMap = elem.attributes();
				for (uint i=0; i<attrMap.length(); i++)
				{
					QDomNode attrNode = attrMap.item(i);
					FXmlWriter->writeAttribute(attrNode.nodeName(), attrNode.nodeValue());
				}

				writeElementChilds(elem);
				FXmlWriter->writeEndElement();
			}
		}
		else if (node.isCharacterData())
		{
			FXmlWriter->writeCharacters(node.toCharacterData().data());
		}

		node = node.nextSibling();
	}
}
/** Construct an DrugDrugInteraction object using the XML QDomElement. */
DrugDrugInteraction::DrugDrugInteraction(const QDomElement &element)
{
    if (element.tagName()!="DDI") {
        LOG_ERROR_FOR("DrugDrugInteraction", "Wrong XML Element");
    } else {
        m_Data.insert(FirstInteractorName, Constants::correctedUid(Utils::removeAccents(element.attribute("i1"))));
        m_Data.insert(SecondInteractorName, Constants::correctedUid(Utils::removeAccents(element.attribute("i2"))));
        m_Data.insert(FirstInteractorRouteOfAdministrationIds, element.attribute("i1ra").split(";"));
        m_Data.insert(SecondInteractorRouteOfAdministrationIds, element.attribute("i2ra").split(";"));
        m_Data.insert(LevelCode, element.attribute("l"));
        m_Data.insert(LevelName, ::levelName(element.attribute("l")));
        m_Data.insert(DateCreation, QDate::fromString(element.attribute("a", QDate(2010,01,01).toString(Qt::ISODate)), Qt::ISODate));
        m_Data.insert(DateLastUpdate, QDate::fromString(element.attribute("lu", QDate(2010,01,01).toString(Qt::ISODate)), Qt::ISODate));
        m_Data.insert(IsValid, element.attribute("v", "1").toInt());
        m_Data.insert(IsReviewed, element.attribute("rv", "0").toInt());
        if (!element.attribute("p").isEmpty())
            m_Data.insert(PMIDsStringList, element.attribute("p").split(";"));
        m_Data.insert(IsDuplicated, false);
        // Read Risk
        QDomElement risk = element.firstChildElement("R");
        while (!risk.isNull()) {
            setRisk(risk.attribute("t"), risk.attribute("l"));
            risk = risk.nextSiblingElement("R");
        }
        // Read Management
        QDomElement management = element.firstChildElement("M");
        while (!management.isNull()) {
            setManagement(management.attribute("t"), management.attribute("l"));
            management = management.nextSiblingElement("M");
        }
        // Read Dose related interactions
        QDomElement dose = element.firstChildElement("D");
        while (!dose.isNull()) {
            DrugDrugInteractionDose *ddidose = 0;
            if (dose.attribute("i") == "1") {
                ddidose = &m_FirstDose;
            } else {
                ddidose = &m_SecondDose;
            }
            if (dose.attribute("uf").toInt()==1) {
                ddidose->setData(DrugDrugInteractionDose::UsesFrom, true);
                ddidose->setData(DrugDrugInteractionDose::FromValue , dose.attribute("fv"));
                ddidose->setData(DrugDrugInteractionDose::FromUnits, dose.attribute("fu"));
                ddidose->setData(DrugDrugInteractionDose::FromRepartition , dose.attribute("fr"));
            } else if (dose.attribute("ut").toInt()==1) {
                ddidose->setData(DrugDrugInteractionDose::UsesTo, true);
                ddidose->setData(DrugDrugInteractionDose::ToValue , dose.attribute("tv"));
                ddidose->setData(DrugDrugInteractionDose::ToUnits, dose.attribute("tu"));
                ddidose->setData(DrugDrugInteractionDose::ToRepartition , dose.attribute("tr"));
            }
            dose = dose.nextSiblingElement("D");
        }
        // Read formalized risk
        QDomElement form = element.firstChildElement("F");
        QDomNamedNodeMap attributeMap = form.attributes();
        for(int i=0; i < attributeMap.size(); ++i) {
            addFormalized(attributeMap.item(i).nodeName(), form.attribute(attributeMap.item(i).nodeName()));
        }
    }
}
Example #12
0
void GTest_RunCMDLine::setArgs(const QDomElement & el) {
    QString commandLine;
    QDomNamedNodeMap map = el.attributes();
    int mapSz = map.length();
    for( int i = 0; i < mapSz; ++i ) {
        QDomNode node = map.item(i);
        if(node.nodeName() == "message"){
            expectedMessage = node.nodeValue();
            continue;
        }
        if(node.nodeName() == "nomessage"){
            unexpectedMessage = node.nodeValue();
            continue;
        }
        if(node.nodeName() == WORKINK_DIR_ATTR){
            continue;
        }
        QString argument = "--" + node.nodeName() + "=" + getVal(node.nodeValue());
         if( argument.startsWith("--task") ) {
            args.prepend(argument);
            commandLine.prepend(argument + " ");
        } else {
            args.append(argument);
            commandLine.append(argument + " ");
        }
    }
    args.append("--log-level-details");
    args.append("--lang=en");
    args.append("--log-no-task-progress");
    commandLine.append(QString(" --log-level-details --lang=en --log-no-task-progress"));
    cmdLog.info(commandLine);
}
// function that scans the DOM for all 'attribute' elements
void
findAttributeElements(QDomElement e) {
    // in the mathml spec, e never has children
    if (!e.firstChild().isNull()) {
        err << "Hmm, I did not expect childeren." << endl;
    }
    // check that there are only two attributes: name and type
    if (e.attributes().length() != 2 || !e.hasAttribute("type")) {
        err << "Hmm, I expected two children for element elements."
            << endl;
    }
    QString type = e.attribute("type");
    // find the element with the name type
    QDomElement typee;
    findTypeElement(type, e.ownerDocument().documentElement(),
            typee);
    if (typee.isNull()) {
        err << "Hmm, no element with name=\""<<type<<"\" was found."
            << endl;
    }
    elements[e.attribute("name")].type = typee;
    collectAttributes(typee.firstChild(),
            elements[e.attribute("name")].atts);
    //pmrintAttributes(e, 10);
}
Example #14
0
bool OsisData::ProcessAttributes(QDomElement& xmlElement)
{
   // Parse and save attributes
   QDomNamedNodeMap attr = xmlElement.attributes();
   int size = attr.size();
   if (!size)
   {
      return false; // Error
   }

   for (int i = 0; i < size; i++)
   {
      QDomAttr at = attr.item(i).toAttr();
      QString value(at.value());
      int key = getEnumKey("OsisElementAttributes", at.name().toLocal8Bit().constData());

      if (key != -1)
      {
         if (Attribute.contains(key))
         {
            Attribute.remove(key);
         }
         Attribute[key] = value;
      }
      else
      {
         qCritical() << "<" << ElementName << ">:  Unknown attribute: " << at.name() << "=" << value << endl;
      }
   }

   return true;
}
Example #15
0
void  XML::XMLToVariables(MOVector<Variable> & variables,QDomElement &element)
{
    variables.clear();

    QDomElement e;
    QDomNode n = element.firstChild();

    QString fieldName;
    int iField;

    while( !n.isNull() )
    {
        e = n.toElement();
        if( !e.isNull() && (e.tagName()=="Variable"))
        {
            Variable* newVar = new Variable();
            QDomNamedNodeMap attributes = e.attributes();
            for(int i=0;i<attributes.count();i++)
            {
                iField = newVar->getFieldIndex(attributes.item(i).toAttr().name());
                if(iField>-1)
                    newVar->setFieldValue(iField,QVariant(attributes.item(i).toAttr().value()));
            }
            variables.addItem(newVar);
        }
        n = n.nextSibling();
    }
}
Example #16
0
void Configure::printTree(QDomElement element,QString indent) {
    QDomNode n = element.firstChild();
    if(n.isText()) {
        qDebug()<<element.tagName()<<":"<<n.nodeValue();
        widget.textEditConfiguration->append(indent+element.tagName()+": "+n.nodeValue());
        // save interesting information
        if(element.tagName()=="type") {
            serverType=n.nodeValue();
        } else if(element.tagName()=="samplerate") {
            sampleRate=n.nodeValue().toInt();
        } else if(element.tagName()=="minfrequency") {
            minFrequency=n.nodeValue().toLong();
        } else if(element.tagName()=="maxfrequency") {
            maxFrequency=n.nodeValue().toLong();
        }
    } else {
        qDebug()<<element.tagName();
        widget.textEditConfiguration->append(indent+element.tagName());
        while(!n.isNull()) {
            QDomElement e = n.toElement(); // try to convert the node to an element.
            if(!e.isNull()) {
                if(e.hasAttributes()) {
                    QDomNamedNodeMap attributes=e.attributes();
                    qDebug()<<"attributes:"<<attributes.count();
                    for(int i=0;i<attributes.count();i++) {
                        QDomNode a=attributes.item(i);
                        qDebug()<<"attribute: "<<a.nodeName()<<":"<<a.nodeValue();
                    }
                }
                printTree(e,indent+"    ");
            }
            n = n.nextSibling();
        }
    }
}
Example #17
0
void WAccount::fillStrings(QString &text, QString &html, const QDomElement &element, const QString &prefix)
{
	QString key = prefix + QLatin1Char('%');
	if (key != QLatin1String("%%")) {
		text.replace(key, element.text());
		html.replace(key, element.text().toHtmlEscaped());
		qDebug() << key;
	}
	key.chop(1);

	QDomNamedNodeMap attributes = element.attributes();
	for (int i = 0; i < attributes.count(); ++i) {
		QDomNode attribute = attributes.item(i);
		QString attributeKey = key
				% QLatin1Char('/')
				% attribute.nodeName()
				% QLatin1Char('%');
		qDebug() << attributeKey;
		text.replace(attributeKey, attribute.nodeValue());
		html.replace(attributeKey, attribute.nodeValue().toHtmlEscaped());
	}

	if (!key.endsWith(QLatin1Char('%')))
		key += QLatin1Char('/');
	QDomNodeList elementChildren = element.childNodes();
	for (int i = 0; i < elementChildren.count(); ++i) {
		QDomNode node = elementChildren.at(i);
		if (node.isElement())
			fillStrings(text, html, node.toElement(), key + node.nodeName());
	}
}
void ReportUser::On_DiffTick()
{
    if (this->qDiff == NULL)
    {
        return;
    }
    if (!this->qDiff->IsProcessed())
    {
        return;
    }
    if (this->qDiff->Result->Failed)
    {
        ui->webView->setHtml(_l("browser-fail", this->qDiff->Result->ErrorMessage));
        this->tPageDiff->stop();
        return;
    }
    QString Summary;
    QString Diff;
    QDomDocument d;
    d.setContent(this->qDiff->Result->Data);
    QDomNodeList l = d.elementsByTagName("rev");
    QDomNodeList diff = d.elementsByTagName("diff");
    if (diff.count() > 0)
    {
        QDomElement e = diff.at(0).toElement();
        if (e.nodeName() == "diff")
        {
            Diff = e.text();
        }
    } else
    {
        Huggle::Syslog::HuggleLogs->DebugLog(this->qDiff->Result->Data);
        this->ui->webView->setHtml("Unable to retrieve diff because api returned no data for it, debug information:<br><hr>" +
                                HuggleWeb::Encode(this->qDiff->Result->Data));
        this->tPageDiff->stop();
        return;
    }
    // get last id
    if (l.count() > 0)
    {
        QDomElement e = l.at(0).toElement();
        if (e.nodeName() == "rev")
        {
            if (e.attributes().contains("comment"))
            {
                Summary = e.attribute("comment");
            }
        }
    }

    if (!Summary.size())
        Summary = "<font color=red>" + _l("browser-miss-summ") + "</font>";
    else
        Summary = HuggleWeb::Encode(Summary);

    this->ui->webView->setHtml(Resources::GetHtmlHeader() + Resources::DiffHeader + "<tr></td colspan=2><b>" + _l("summary")
                               + ":</b> " + Summary + "</td></tr>" + Diff + Resources::DiffFooter + Resources::HtmlFooter);
    this->tPageDiff->stop();
}
Example #19
0
void DomConvenience::clearAttributes(QDomElement& e)
{
  QDomNamedNodeMap attrMap = e.attributes();
  QDomNode attrNode;

  for (uint i = attrMap.length(); i > 0; --i)
    e.removeAttributeNode(attrMap.item(i - 1).toAttr());
}
void TwitterClient::resultReceiver(QString data)
{
    bar.hide();
    qDebug() << data;
    QDomDocument xml;
    xml.setContent(data);
    QDomElement rsp = xml.firstChildElement("rsp");
    if (rsp.isNull())
    {
        QMessageBox::critical(NULL, tr("Error"),
                              tr("Could not post to twitter. Wrong server response."));
        emit errorHappened();
        return;
    }
    QDomElement error = rsp.firstChildElement("err");
    if (!error.isNull())
    {   /*
           1002 media not found
           2005 media is too big
           2001 invalid action specified
           2004 invalid developer key
           1001 empty/invalid username/password
           2002 failed to upload media
           2003 failed to update status*/
        QDomNode codex = error.attributes().namedItem("code");
        if (!codex.isNull())
        {
            QString code = codex.nodeValue();
            if (code == "1001")
            {
                QMessageBox::critical(NULL, tr("Error"),
                                      tr("Could not post to twitter. Wrong credentials."));
                emit errorHappened();
                return;
            }
            else if (code == "2003")
            {
                QMessageBox::critical(NULL, tr("Error"),
                                      tr("Failed to update twitter status."));
                emit errorHappened();
                return;
            }
        }
        QMessageBox::critical(NULL, tr("Error"),
                              tr("Could not post to twitter. Internal error."));
        return;
    }
    QDomElement statusid = rsp.firstChildElement("statusid");
    if (statusid.isNull())
    {
        QMessageBox::critical(NULL, tr("Error"),
                              tr("Could not post to twitter. Wrong server response."));
        return;
    }
    QString addr("http://twitter.com/%1/status/%2");
    addr = addr.arg(user, statusid.text());
    QDesktopServices().openUrl(QUrl(addr));
}
Example #21
0
void BlockUser::CheckToken()
{
    if (this->qTokenApi == nullptr || !this->qTokenApi->IsProcessed())
        return;
    if (this->qTokenApi->Result->Failed)
    {
        this->Failed(_l("block-token-e1", this->qTokenApi->Result->ErrorMessage));
        return;
    }
    QDomDocument d;
    d.setContent(this->qTokenApi->Result->Data);
    QDomNodeList l = d.elementsByTagName("page");
    if (l.count() == 0)
    {
        Huggle::Syslog::HuggleLogs->DebugLog(this->qTokenApi->Result->Data);
        this->Failed(_l("block-error-no-info"));
        return;
    }
    QDomElement element = l.at(0).toElement();
    if (!element.attributes().contains("blocktoken"))
    {
        this->Failed(_l("no-token"));
        return;
    }
    this->BlockToken = element.attribute("blocktoken");
    this->QueryPhase++;
    this->qTokenApi->DecRef();
    this->qTokenApi = nullptr;
    Huggle::Syslog::HuggleLogs->DebugLog("Block token for " + this->user->Username + ": " + this->BlockToken);

    // let's block them
    this->qUser = new ApiQuery();
    QString nocreate = "";
    if (this->ui->checkBox_4->isChecked())
        nocreate = "&nocreate=";
    QString anononly = "";
    if (this->ui->checkBox_5->isChecked())
        anononly = "&anononly=";
    QString noemail = "";
    if (this->ui->checkBox_2->isChecked())
        noemail = "&noemail=";
    QString autoblock = "";
    if (!this->ui->checkBox_3->isChecked())
        autoblock = "&autoblock=";
    QString allowusertalk = "";
    if (!this->ui->checkBox->isChecked())
        allowusertalk = "&allowusertalk=";
    this->qUser->SetAction(ActionQuery);
    this->qUser->Parameters = "action=block&user=" +  QUrl::toPercentEncoding(this->user->Username) + "&reason="
            + QUrl::toPercentEncoding(this->ui->comboBox->currentText()) + "&expiry="
            + QUrl::toPercentEncoding(this->ui->comboBox_2->currentText()) + nocreate + anononly
            + noemail + autoblock + allowusertalk + "&token=" + QUrl::toPercentEncoding(BlockToken);
    this->qUser->Target = _l("blocking", this->user->Username);
    this->qUser->UsingPOST = true;
    this->qUser->IncRef();
    QueryPool::HugglePool->AppendQuery(this->qUser);
    this->qUser->Process();
}
Example #22
0
KdmLabel::KdmLabel( QObject *parent, const QDomNode &node )
	: KdmItem( parent, node )
	, action( 0 )
{
	itemType = "label";

	// Set default values for label (note: strings are already Null)
	label.normal.font = label.active.font = label.prelight.font = style.font;
	label.normal.color = label.active.color = label.prelight.color =
		style.palette.isBrushSet( QPalette::Normal, QPalette::WindowText ) ?
			style.palette.color( QPalette::Normal, QPalette::WindowText ) :
			QColor( Qt::white );
	label.active.present = false;
	label.prelight.present = false;

	const QString locale = KGlobal::locale()->language();

	// Read LABEL TAGS
	QDomNodeList childList = node.childNodes();
	bool stockUsed = false;
	for (int nod = 0; nod < childList.count(); nod++) {
		QDomNode child = childList.item( nod );
		QDomElement el = child.toElement();
		QString tagName = el.tagName();

		if (tagName == "normal") {
			parseColor( el, label.normal.color );
			parseFont( el, label.normal.font );
		} else if (tagName == "active") {
			label.active.present = true;
			parseColor( el, label.active.color );
			parseFont( el, label.active.font );
		} else if (tagName == "prelight") {
			label.prelight.present = true;
			parseColor( el, label.prelight.color );
			parseFont( el, label.prelight.font );
		} else if (tagName == "text" && el.attributes().count() == 0 && !stockUsed) {
			label.text = el.text();
		} else if (tagName == "text" && !stockUsed) {
			QString lang = el.attribute( "xml:lang", "" );
			if (lang == locale)
				label.text = el.text();
		} else if (tagName == "stock") {
			label.text = lookupStock( el.attribute( "type", "" ) );
			stockUsed = true;
		}
	}

	// Check if this is a timer label
	label.isTimer = label.text.indexOf( "%c" ) >= 0;
	if (label.isTimer) {
		timer = new QTimer( this );
		timer->start( 1000 );
		connect( timer, SIGNAL(timeout()), SLOT(update()) );
	}
	label.text.replace( '\n', ' ' );
	setCText( lookupText( label.text ) );
}
void IDefReader::processScriptItemNode( P_ITEM madeItem, QDomElement &Node )
{
	for( UI16 k = 0; k < Node.childNodes().count(); k++ )
	{
		QDomElement currChild = Node.childNodes().item( k ).toElement();
		if( currChild.nodeName() == "amount" )
		{
			QString Value = QString();
			UI16 i = 0;
			if( currChild.hasChildNodes() ) // <random> i.e.
				for( i = 0; i < currChild.childNodes().count(); i++ )
				{
					if( currChild.childNodes().item( i ).isText() )
						Value += currChild.childNodes().item( i ).toText().data();
					else if( currChild.childNodes().item( i ).isElement() )
						Value += processNode( currChild.childNodes().item( i ).toElement() );
				}
			else
				Value = currChild.nodeValue();

			if( Value.toInt() < 1 )
				Value = QString("1");

			if( madeItem->isPileable() )
				madeItem->setAmount( Value.toInt() );
			else
				for( i = 1; i < Value.toInt(); i++ ) //dupe it n-1 times
					Commands->DupeItem(-1, madeItem, 1);
		}
		else if( currChild.nodeName() == "color" ) //process <color> tags
		{
			QString Value = QString();
			if( currChild.hasChildNodes() ) // colorlist or random i.e.
				for( UI16 i = 0; i < currChild.childNodes().count(); i++ )
				{
					if( currChild.childNodes().item( i ).isText() )
						Value += currChild.childNodes().item( i ).toText().data();
					else if( currChild.childNodes().item( i ).isElement() )
						Value += processNode( currChild.childNodes().item( i ).toElement() );
				}
			else
				Value = currChild.nodeValue();
			
			if( Value.toInt() < 0 )
				Value = QString("0");

			madeItem->setColor( Value.toInt() );
		}
		else if( currChild.nodeName() == "inherit" && currChild.attributes().contains("id") )
		{
			QDomElement* derivalSection = DefManager->getSection( WPDT_ITEM, currChild.attribute("id") );
			if( !derivalSection->isNull() )
				this->applyNodes( madeItem, derivalSection );
		}
	}
}
// debugging function that prints the attributes of an element
void
printAttributes(QDomElement e, uint level) {
    QDomNamedNodeMap m = e.attributes();
    for (uint i=0; i<m.length(); ++i) {
        for (uint j=0; j<level; ++j) out << ' ';
        QDomNode n = m.item(i);
        out << "+"<<n.nodeName() << ": "
            << n.nodeValue() << endl;
    }
}
Example #25
0
/**
 * @brief XmlEditWidgetPrivate::findDomNodeScan find the nearest match to a position
 * @param node
 * @param nodeTarget
 * @param lineSearched
 * @param columnSearched
 * @param lastKnownNode: last known "good" position
 * @return
 */
bool XmlEditWidgetPrivate::findDomNodeScan(QDomNode node, QDomNode nodeTarget, const int lineSearched, const int columnSearched, FindNodeWithLocationInfo &info)
{
    int row = node.lineNumber();
    int col = node.columnNumber();
    if(!node.isDocument()) {
        if((lineSearched == row) && (columnSearched == col)) {
            info.matchedNode = nodeTarget ;
            return true ;
        }

        if((lineSearched == row) && (columnSearched == col)) {
            info.matchedNode = nodeTarget ;
            return true ;
        }
        if((lineSearched == row) && (columnSearched < col)) {
            info.matchedNode = nodeTarget ;
            return true ;
        }
        if((lineSearched < row)) {
            info.matchedNode = nodeTarget ;
            return true ;
        }
        if((lineSearched <= row)) {
            info.lastKnownNode = nodeTarget ;
        }

        if(node.nodeType() == QDomNode::ElementNode) {
            QDomElement element = node.toElement();
            QDomNamedNodeMap attributes = element.attributes();
            int numAttrs = attributes.length();
            for(int i = 0 ; i < numAttrs ; i++) {
                QDomNode node = attributes.item(i);
                QDomAttr attr = node.toAttr();
                if(findDomNodeScan(attr, nodeTarget, lineSearched, columnSearched, info)) {
                    return true;
                }
            } // for
        }
    }

    int nodes = node.childNodes().count();
    for(int i = 0 ; i < nodes ; i ++) {
        QDomNode childNode = node.childNodes().item(i) ;
        if(childNode.isText() || childNode.isCDATASection()) {
            if(findDomNodeScan(childNode, nodeTarget, lineSearched, columnSearched, info)) {
                return true;
            }
        } else {
            if(findDomNodeScan(childNode, childNode, lineSearched, columnSearched, info)) {
                return true ;
            }
        }
    }
    return false ;
}
Example #26
0
void mafGUIManager::createToolbar(QDomElement node) {
    QDomNamedNodeMap attributes = node.attributes();
    QString title = attributes.namedItem("title").nodeValue();
    QString actions = attributes.namedItem("actionList").nodeValue();

    QToolBar *toolBar = m_MainWindow->addToolBar(tr(title.toAscii().constData()));

    QStringList actionList = actions.split(",");
    foreach (QString action, actionList) {
        toolBar->addAction((QAction*)menuItemByName(action));
    }
void GEN_xmlserializer::deserialize(QDomDocument xml, QString &sourceFile, QString &currBUS, SysError &sysErr)
{
    qDebug() << "DESERIALIZE";
    qDebug() << xml.toString();

    QDomElement myXml = xml.documentElement();

    QDomNodeList deviceAttributes = myXml.elementsByTagName( DEVATTRIBUTE );
    for(int index = 0; index < deviceAttributes.count() ; index++) {

        QDomElement element = deviceAttributes.item(index).toElement();
        if (element.attributes().namedItem(NAME).nodeValue().compare(SRCFILE) == 0) {
            sourceFile = element.attributes().namedItem(VALUE).nodeValue();
        } else if (element.attributes().namedItem(NAME).nodeValue().compare(BUS) == 0) {
            currBUS = element.attributes().namedItem(VALUE).nodeValue();
        }
    }

    sysErr = SysError();
}
Example #28
0
QDebug operator<<(QDebug dbg, const QDomElement &el)
{
    QDomNamedNodeMap map = el.attributes();

    QString args;
    for (int i=0; i<map.count(); ++i)
        args += " " + map.item(i).nodeName() + "='" + map.item(i).nodeValue() + "'";

    dbg.nospace() << QString("<%1%2>%3</%1>").arg(el.tagName()).arg(args).arg(el.text());
    return dbg.space();
}
Example #29
0
void XdgMenuPrivate::prependChilds(QDomElement& srcElement, QDomElement& destElement)
{
    MutableDomElementIterator it(srcElement);

    it.toBack();
    while(it.hasPrevious())
    {
        QDomElement n = it.previous();
        destElement.insertBefore(n, destElement.firstChild());
    }

    if (srcElement.attributes().contains("deleted") &&
        !destElement.attributes().contains("deleted")
       )
        destElement.setAttribute("deleted", srcElement.attribute("deleted"));

    if (srcElement.attributes().contains("onlyUnallocated") &&
        !destElement.attributes().contains("onlyUnallocated")
       )
        destElement.setAttribute("onlyUnallocated", srcElement.attribute("onlyUnallocated"));
}
Example #30
0
Language *Localizations::MakeLanguageUsingXML(QString text, QString name)
{
    Language *l = new Language(name);
    QDomDocument in_;
    in_.setContent(text);
    QDomNodeList keys = in_.elementsByTagName("string");
    int i = 0;
    while (i < keys.count())
    {
        QDomElement item = keys.at(i).toElement();
        i++;
        if (!item.attributes().contains("name"))
        {
            HUGGLE_DEBUG("Language " + name + " contains key with no name", 1);
            continue;
        }
        QString n_ = item.attribute("name");
        if (n_ == "isrtl")
        {
            l->IsRTL = Generic::SafeBool(item.text());
            continue;
        }
        if (l->Messages.contains(n_))
        {
            Syslog::HuggleLogs->WarningLog("Language " + name + " contains more than 1 definition for " + n_);
            continue;
        }
        if (!Configuration::HuggleConfiguration->Fuzzy && item.attributes().contains("fuzzy") && item.attribute("fuzzy") == "true")
        {
            HUGGLE_DEBUG("Fuzzy key ignored: " + name + " " + n_, 12);
            continue;
        }
        l->Messages.insert(item.attribute("name"), item.text());
    }
    if (l->Messages.contains("name"))
    {
        l->LanguageID = l->Messages["name"];
    }
    return l;
}