コード例 #1
0
void ProjectFile::SetAttribute(QString parentTag, QString childTag, QString attribute, QString value)
{
	QDomElement parentTagElement = documentElement().namedItem(parentTag).toElement();
	if (parentTagElement.isNull())
	{
		parentTagElement = createElement(parentTag);
		documentElement().appendChild(parentTagElement);
	}

	QDomElement childTagElement = parentTagElement.namedItem(childTag).toElement();
	if (childTagElement.isNull())
	{
		childTagElement = createElement(childTag);
		parentTagElement.appendChild(childTagElement);
	}

	QDomNode attributeNode = childTagElement.namedItem(value);
	if (!attributeNode.isNull())
	{
		childTagElement.removeChild(attributeNode);
	}

	QDomElement attributeElement = createElement(attribute);
	attributeElement.appendChild(createTextNode(value));
	childTagElement.appendChild(attributeElement);

	SaveProject();
}
コード例 #2
0
void ProjectFile::CreateEmptyProject()
{
	clear();
	appendChild(createElement(TAG_PROJECT));
	QDomElement fullDomainElement = createElement(TAG_FULL_DOMAIN);
	QDomElement subDomainElement = createElement(TAG_SUB_DOMAIN);
	QDomElement settingsElement = createElement(TAG_SETTINGS);
	documentElement().appendChild(fullDomainElement);
	documentElement().appendChild(subDomainElement);
	documentElement().appendChild(settingsElement);
}
コード例 #3
0
void ProjectFile::FileModified()
{
	lastModified = QDateTime::currentDateTime();

	QDomNode attributeNode = documentElement().namedItem(ATTR_LASTSAVE);
	if (!attributeNode.isNull())
	{
		documentElement().removeChild(attributeNode);
	}

	QDomElement attributeElement = createElement(ATTR_LASTSAVE);
	attributeElement.appendChild(createTextNode(lastModified.toString(Qt::ISODate)));
	documentElement().appendChild(attributeElement);
}
コード例 #4
0
void ProjectFile::SetAttribute(QString attribute, QString value)
{
	QDomNode attributeNode = documentElement().namedItem(attribute);
	if (!attributeNode.isNull())
	{
		documentElement().removeChild(attributeNode);
	}

	QDomElement attributeElement = createElement(attribute);
	attributeElement.appendChild(createTextNode(value));
	documentElement().appendChild(attributeElement);

	SaveProject();
}
コード例 #5
0
ファイル: dom_document.cpp プロジェクト: jcayzac/random-stuff
void DocumentImpl::Output(DOMString& output) const {
	output+=DOMString("<?xml version=\"1.0\" encoding=\"");
	switch(encoding()) {
	case text::ENCODING_LATIN9:			output+=DOMString("ISO-8859-15");	break;
	case text::ENCODING_UTF8:			output+=DOMString("UTF-8");			break;
	case text::ENCODING_WINDOWS_1252:	output+=DOMString("windows-1252");	break;
	case text::ENCODING_UCS2LE:
	case text::ENCODING_UTF16LE:
	case text::ENCODING_UCS2BE:
	case text::ENCODING_UTF16BE:		output+=DOMString("UTF-16");		break;
	default:							output+=DOMString("ISO-8859-1");	break;
	}
	output+=DOMString("\"");
	if (hasAttributes()) {
		Node child = m_pFirstAttribute;
		while (child) {
			const DOMString& attrName  = child->nodeName();
			if (attrName!="encoding" && attrName!="version")
				child->Output(output);
			child = child->nextSibling();
		}
	}
	output+=DOMString("?>\n");
	if (!docType().IsEmpty()) {
		output+=DOMString("<!DOCTYPE ");
		output+=docType();
		output+=DOMString(">\n");
	}
	Node root = documentElement();
	if (root) root->Output(output);
}
コード例 #6
0
QNetworkReply* Connection::checkConnection(Core::PMS::SimpleResultHandler handler)
{
    QUrl url(apiUrl_);
    QUrlQuery query;
    query.addQueryItem("check_if_alive", "1");
    url.setQuery(query);
    auto reply = client_->get(QNetworkRequest(url));

    QPointer<QObject> self = this;
    QObject::connect(reply, &QNetworkReply::finished, [self, reply, handler]()
    {
        if (!self)
            return;

        try
        {
            auto doc = checkReplyAndParseXml(reply);
            auto elem = doc.documentElement();
            if (elem.isNull() || elem.tagName() != "api_is_alive")
                throw Error(Error::Parse);

            handler(Error());
        }
        catch (const Error& err)
        {
            handler(err);
        }
    });
}
コード例 #7
0
/**
 * Returns a list with all the keywords inside the list type
 */
QStringList& KateSyntaxDocument::finddata(const QString& mainGroup, const QString& type, bool clearList)
{
#ifdef KSD_OVER_VERBOSE
  kDebug(13010)<<"Create a list of keywords \""<<type<<"\" from \""<<mainGroup<<"\".";
#endif

  if (clearList)
    m_data.clear();

  for(QDomNode node = documentElement().firstChild(); !node.isNull(); node = node.nextSibling())
  {
    QDomElement elem = node.toElement();
    if (elem.tagName() == mainGroup)
    {
#ifdef KSD_OVER_VERBOSE
      kDebug(13010)<<"\""<<mainGroup<<"\" found.";
#endif

      QDomNodeList nodelist1 = elem.elementsByTagName("list");

      for (int l=0; l<nodelist1.count(); l++)
      {
        if (nodelist1.item(l).toElement().attribute("name") == type)
        {
#ifdef KSD_OVER_VERBOSE
          kDebug(13010)<<"List with attribute name=\""<<type<<"\" found.";
#endif

          QDomNodeList childlist = nodelist1.item(l).toElement().childNodes();

          for (int i=0; i<childlist.count(); i++)
          {
            QString element = childlist.item(i).toElement().text().trimmed();
            if (element.isEmpty())
              continue;

#ifdef KSD_OVER_VERBOSE
            if (i<6)
            {
              kDebug(13010)<<"\""<<element<<"\" added to the list \""<<type<<"\"";
            }
            else if(i==6)
            {
              kDebug(13010)<<"... The list continues ...";
            }
#endif

            m_data += element;
          }

          break;
        }
      }
      break;
    }
  }

  return m_data;
}
コード例 #8
0
ファイル: SVGDocument.cpp プロジェクト: 3163504123/phantomjs
SVGSVGElement* SVGDocument::rootElement() const
{
    Element* elem = documentElement();
    if (elem && elem->hasTagName(SVGNames::svgTag))
        return toSVGSVGElement(elem);

    return 0;
}
コード例 #9
0
void KTPaletteDocument::addColor(const QColor &color)
{
    QDomElement element = createElement("Color");
    
    element.setAttribute("colorName", color.name());
    element.setAttribute("alpha", QString::number(color.alpha()));
    
    documentElement().appendChild(element);
}
コード例 #10
0
QString ProjectFile::GetAttribute(QString attribute)
{
	QDomElement attributeElement = documentElement().namedItem(attribute).toElement();
	if (!attributeElement.isNull())
	{
		return attributeElement.text();
	}
	return QString();
}
コード例 #11
0
ファイル: SVGDocument.cpp プロジェクト: KDE/khtml
SVGSVGElement *SVGDocument::rootElement() const
{
    Element *elem = documentElement();
    if (elem && elem->hasTagName(SVGNames::svgTag)) {
        return static_cast<SVGSVGElement *>(elem);
    }

    return 0;
}
コード例 #12
0
void ListProjects::requestAll()
{
	QDomElement option = createElement("option");
	QDomText text = createTextNode("all");
	
	option.appendChild(text);
	
	documentElement().appendChild(option);
}
コード例 #13
0
ファイル: DataFile.cpp プロジェクト: AHudon/lmms
void DataFile::write( QTextStream & _strm )
{
	if( type() == SongProject || type() == SongProjectTemplate
					|| type() == InstrumentTrackSettings )
	{
		cleanMetaNodes( documentElement() );
	}

	save(_strm, 2);
}
コード例 #14
0
ファイル: documentxml.cpp プロジェクト: avieira/GM4-2
void DocumentXML::ajouterSommet(Sommet* sommet, QString id){
    //Création de l'élément dans le document Dom
    QDomElement qElmt=ownerDocument().createElement("Sommet");
    XMLElementSommet *elmt=new XMLElementSommet(sommet,qElmt,graphe);
    QDomElement listeDomSommets = documentElement().firstChildElement("Sommets");
    listeDomSommets.appendChild(*elmt);

    //On fixe la valeur affichée
    elmt->setAttribute(QString("id"),id);
}
コード例 #15
0
bool ProjectFile::AddSubdomain(QString newName)
{
	QDomElement currentSubdomain = documentElement().firstChildElement(TAG_SUB_DOMAIN);
	while (!currentSubdomain.isNull())
	{
		QDomElement nameElement = currentSubdomain.namedItem(ATTR_NAME).toElement();
		if (nameElement.text() == newName)
		{
			if (!WarnSubdomainExists(newName))
			{
				return false;
			} else {
				documentElement().removeChild(currentSubdomain);
				break;
			}
		}

		currentSubdomain = currentSubdomain.nextSiblingElement(TAG_SUB_DOMAIN);
//		{
//			QDomNode attributeNode = currentSubdomain.namedItem(attribute);
//			if (!attributeNode.isNull())
//			{
//				currentSubdomain.removeChild(attributeNode);
//			}

//			QDomElement attributeElement = createElement(attribute);
//			attributeElement.appendChild(createTextNode(value));
//			currentSubdomain.appendChild(attributeElement);
//			break;
//		}
	}

	QDomElement newSubdomain = createElement(TAG_SUB_DOMAIN);
	QDomElement newSubdomainName = createElement(ATTR_NAME);
	documentElement().appendChild(newSubdomain);
	newSubdomain.appendChild(newSubdomainName);
	newSubdomainName.appendChild(createTextNode(newName));

	SaveProject();

	return true;
}
コード例 #16
0
ファイル: kgamesvgdocument.cpp プロジェクト: jsj2008/kdegames
QDomNode KGameSvgDocument::elementByUniqueAttributeValue(const QString& attributeName, const QString& attributeValue)
{
    /* DOM is always "live", so there maybe a new root node.  We always have to ask for the
     * root node instead of keeping a pointer to it.
     */
    QDomElement docElem = documentElement();
    QDomNode n = docElem.firstChild();

    QDomNode node = d->findElementById(attributeName, attributeValue, n);
    setCurrentNode(node);
    return node;
}
コード例 #17
0
void KThemeDocument::addSelections(ThemeKey tk)
{
    QDomElement general = createElement("Selections");
    QStringList keys = tk.keys();
    QStringList values = tk.values();

    for (int i = 0; i < keys.count(); i++) {
         QDomElement e = createElement(keys[i]);
         e.setAttribute("color", values[i]);
         general.appendChild(e);
    }

    documentElement().appendChild(general);
}
コード例 #18
0
ファイル: documentxml.cpp プロジェクト: avieira/GM4-2
void DocumentXML::ajouterArc(Arete* arc){
    //Création de l'élément dans le document Dom
    XMLElementArete elmt(arc, createElement("Arc"));


    //Affichage départ et arrivée
    QDomElement listeDomSommets = documentElement().firstChildElement("Arcs");
    listeDomSommets.appendChild(elmt);

    QString depart=arc->getDepart()->getNom();
    QString arrivee=arc->getArrivee()->getNom();
    elmt.attribute(QString("Depart"),depart);
    elmt.attribute(QString("Arrivee"),arrivee);
}
コード例 #19
0
ファイル: documentxml.cpp プロジェクト: avieira/GM4-2
void DocumentXML::ajouterSommet(SommetColore* sommet, QString id)
{
    QDomElement qElmt=ownerDocument().createElement("Sommet");
    XMLElementSommet *elmt=new XMLElementSommet(sommet,qElmt,graphe);
    QDomElement listeDomSommets = documentElement().firstChildElement("Sommets");
    listeDomSommets.appendChild(*elmt);

    //On fixe la valeur affichée
    elmt->setAttribute(QString("id"),id);

    QDomElement couleurElmt=createElement("Couleur");
    elmt->appendChild(couleurElmt);
    string couleur="#"+sommet->getCouleur();
    couleurElmt.appendChild(createTextNode(QString(couleur.c_str())));
}
コード例 #20
0
QString ProjectFile::GetAttribute(QString parentTag, QString childTag, QString attribute)
{
	QDomElement parentTagElement = documentElement().namedItem(parentTag).toElement();
	if (!parentTagElement.isNull())
	{
		QDomElement childTagElement = parentTagElement.namedItem(childTag).toElement();
		if (!childTagElement.isNull())
		{
			QDomElement attributeElement = childTagElement.namedItem(attribute).toElement();
			if (!attributeElement.isNull())
			{
				return attributeElement.text();
			}
		}
	}
	return QString();
}
コード例 #21
0
QStringList ProjectFile::GetSubDomainNames()
{
	QStringList subdomainNames;

	QDomElement currentSubdomain = documentElement().firstChildElement(TAG_SUB_DOMAIN);
	while (!currentSubdomain.isNull())
	{
		QDomElement subdomainNameAttribute = currentSubdomain.namedItem(ATTR_NAME).toElement();
		if (!subdomainNameAttribute.isNull())
		{
			subdomainNames.append(subdomainNameAttribute.text());
		}
		currentSubdomain = currentSubdomain.nextSiblingElement(TAG_SUB_DOMAIN);
	}

	return subdomainNames;
}
コード例 #22
0
QString ProjectFile::GetAttributeSubdomain(QString subdomainName, QString attribute)
{
	QDomElement currentSubdomain = documentElement().firstChildElement(TAG_SUB_DOMAIN);
	while (!currentSubdomain.isNull())
	{
		QDomElement nameElement = currentSubdomain.namedItem(ATTR_NAME).toElement();
		if (nameElement.text() == subdomainName)
		{
			QDomElement attributeElement = currentSubdomain.namedItem(attribute).toElement();
			if (!attributeElement.isNull())
			{
				return attributeElement.text();
			}
			break;
		}
		currentSubdomain = currentSubdomain.nextSiblingElement(TAG_SUB_DOMAIN);
	}
	return QString();
}
コード例 #23
0
bool KateSyntaxDocument::getElement (QDomElement &element, const QString &mainGroupName, const QString &config)
{
#ifdef KSD_OVER_VERBOSE
  kDebug(13010) << "Looking for \"" << mainGroupName << "\" -> \"" << config << "\".";
#endif

  QDomNodeList nodes = documentElement().childNodes();

  // Loop over all these child nodes looking for mainGroupName
  for (int i=0; i<nodes.count(); i++)
  {
    QDomElement elem = nodes.item(i).toElement();
    if (elem.tagName() == mainGroupName)
    {
      // Found mainGroupName ...
      QDomNodeList subNodes = elem.childNodes();

      // ... so now loop looking for config
      for (int j=0; j<subNodes.count(); j++)
      {
        QDomElement subElem = subNodes.item(j).toElement();
        if (subElem.tagName() == config)
        {
          // Found it!
          element = subElem;
          return true;
        }
      }

#ifdef KSD_OVER_VERBOSE
      kDebug(13010) << "WARNING: \""<< config <<"\" wasn't found!";
#endif

      return false;
    }
  }

#ifdef KSD_OVER_VERBOSE
  kDebug(13010) << "WARNING: \""<< mainGroupName <<"\" wasn't found!";
#endif

  return false;
}
コード例 #24
0
ファイル: mmp.cpp プロジェクト: Orpheon/lmms
void multimediaProject::loadData( const QByteArray & _data,
					const QString & _sourceFile )
{
	QString errorMsg;
	int line = -1, col = -1;
	if( !setContent( _data, &errorMsg, &line, &col ) )
	{
		// parsing failed? then try to uncompress data
		QByteArray uncompressed = qUncompress( _data );
		if( !uncompressed.isEmpty() )
		{
			if( setContent( uncompressed, &errorMsg, &line, &col ) )
			{
				line = col = -1;
			}
		}
		if( line >= 0 && col >= 0 )
		{
			qWarning() << "at line" << line << "column" << errorMsg;
			QMessageBox::critical( NULL,
				songEditor::tr( "Error in file" ),
				songEditor::tr( "The file %1 seems to contain "
						"errors and therefore can't be "
						"loaded." ).
							arg( _sourceFile ) );
			return;
		}
	}

	QDomElement root = documentElement();
	m_type = type( root.attribute( "type" ) );
	m_head = root.elementsByTagName( "head" ).item( 0 ).toElement();

	if( root.hasAttribute( "creatorversion" ) &&
		root.attribute( "creatorversion" ) != LMMS_VERSION )
	{
		upgrade();
	}

	m_content = root.elementsByTagName( typeName( m_type ) ).
							item( 0 ).toElement();
}
コード例 #25
0
void MappingXMLParser::parse() {
    QDomNodeList modules = documentElement().elementsByTagName("module");
    for (int mi = 0; mi != modules.size(); mi++) {
        QDomElement mE = modules.item(mi).toElement();
        Q_ASSERT(mE.hasAttribute("name"));
        QString moduleName = nameAttribute(modules.item(mi));
        QDomNodeList classes = mE.elementsByTagName("class");
        for (int ci = 0; ci != classes.size(); ci++) {
            QDomElement cE = classes.item(ci).toElement();
            Q_ASSERT(cE.hasAttribute("name"));
            Q_ASSERT(cE.hasAttribute("table_name"));
            Q_ASSERT(cE.hasAttribute("manager_class_name"));

            QString qualifiedTableName = cE.attribute("table_name");
            QString schemaName = qualifiedTableName.split(".")[0];
            QString tableName = qualifiedTableName.split(".")[1];
            QString className = nameAttribute(classes.item(ci));
            QString managerClassName = cE.attribute("manager_class_name");

            DataManager* manager = createManager(getApp(), moduleName,
                    className,
                    schemaName,
                    tableName,
                    managerClassName);
            QDomNodeList pl = cE.elementsByTagName("property");
            Schema* schema = getApp()->databaseModel()->schema(schemaName);
            Q_CHECK_PTR(schema);
            Table* table = schema->table(tableName);
            Q_CHECK_PTR(table);
            for (int i = 0; i != pl.size(); i++) {
                QDomElement pe = pl.item(i).toElement();
                Q_ASSERT(pe.hasAttribute("property_name"));
                Q_ASSERT(pe.hasAttribute("column_name"));
                TableColumn* col = table->column(pe.attribute("column_name"));
                Q_CHECK_PTR(col);
                qDebug() << QString("'%1' --> '%2'").arg(pe.attribute("property_name")).arg(col->pathName());
                (void) new Property(manager->mapping(), pe.attribute("property_name"), col);
            }
        }
    }
}
コード例 #26
0
ファイル: mmp.cpp プロジェクト: Orpheon/lmms
bool multimediaProject::writeFile( const QString & _fn )
{
	if( type() == SongProject || type() == SongProjectTemplate
					|| type() == InstrumentTrackSettings )
	{
		cleanMetaNodes( documentElement() );
	}


	QString fn = nameWithExtension( _fn );
	QFile outfile( fn );
	if( !outfile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
	{
		QMessageBox::critical( NULL,
				songEditor::tr( "Could not write file" ),
					songEditor::tr( "Could not write file "
							"%1. You probably are "
							"not permitted to "
							"write to this file.\n"
							"Please make sure you "
							"have write-access to "
							"the file and try "
							"again."
						).arg( fn ) );
		return false;
	}
	QString xml = "<?xml version=\"1.0\"?>\n" + toString( 2 );
	if( fn.section( '.', -1 ) == "mmpz" )
	{
		outfile.write( qCompress( xml.toUtf8() ) );
	}
	else
	{
		QTextStream( &outfile ) << xml;
	}
	outfile.close();

	return true;
}
コード例 #27
0
void ProjectFile::SetAttributeSubdomain(QString subdomainName, QString attribute, QString value)
{
	QDomElement currentSubdomain = documentElement().firstChildElement(TAG_SUB_DOMAIN);
	while (!currentSubdomain.isNull())
	{
		QDomElement nameElement = currentSubdomain.namedItem(ATTR_NAME).toElement();
		if (nameElement.text() == subdomainName)
		{
			QDomNode attributeNode = currentSubdomain.namedItem(attribute);
			if (!attributeNode.isNull())
			{
				currentSubdomain.removeChild(attributeNode);
			}

			QDomElement attributeElement = createElement(attribute);
			attributeElement.appendChild(createTextNode(value));
			currentSubdomain.appendChild(attributeElement);
			break;
		}
		currentSubdomain = currentSubdomain.nextSiblingElement(TAG_SUB_DOMAIN);
	}

	SaveProject();
}
コード例 #28
0
ファイル: DataFile.cpp プロジェクト: AHudon/lmms
void DataFile::upgrade()
{
	projectVersion version =
		documentElement().attribute( "creatorversion" ).
							replace( "svn", "" );

	if( version < "0.2.1-20070501" )
	{
		QDomNodeList list = elementsByTagName( "arpandchords" );
		for( int i = 0; !list.item( i ).isNull(); ++i )
		{
			QDomElement el = list.item( i ).toElement();
			if( el.hasAttribute( "arpdir" ) )
			{
				int arpdir = el.attribute( "arpdir" ).toInt();
				if( arpdir > 0 )
				{
					el.setAttribute( "arpdir", arpdir - 1 );
				}
				else
				{
					el.setAttribute( "arpdisabled", "1" );
				}
			}
		}

		list = elementsByTagName( "sampletrack" );
		for( int i = 0; !list.item( i ).isNull(); ++i )
		{
			QDomElement el = list.item( i ).toElement();
			if( el.attribute( "vol" ) != "" )
			{
				el.setAttribute( "vol", el.attribute(
						"vol" ).toFloat() * 100.0f );
			}
			else
			{
				QDomNode node = el.namedItem(
							"automation-pattern" );
				if( !node.isElement() ||
					!node.namedItem( "vol" ).isElement() )
				{
					el.setAttribute( "vol", 100.0f );
				}
			}
		}

		list = elementsByTagName( "ladspacontrols" );
		for( int i = 0; !list.item( i ).isNull(); ++i )
		{
			QDomElement el = list.item( i ).toElement();
			QDomNode anode = el.namedItem( "automation-pattern" );
			QDomNode node = anode.firstChild();
			while( !node.isNull() )
			{
				if( node.isElement() )
				{
					QString name = node.nodeName();
					if( name.endsWith( "link" ) )
					{
						el.setAttribute( name,
							node.namedItem( "time" )
							.toElement()
							.attribute( "value" ) );
						QDomNode oldNode = node;
						node = node.nextSibling();
						anode.removeChild( oldNode );
						continue;
					}
				}
				node = node.nextSibling();
			}
		}

		QDomNode node = m_head.firstChild();
		while( !node.isNull() )
		{
			if( node.isElement() )
			{
				if( node.nodeName() == "bpm" )
				{
					int value = node.toElement().attribute(
							"value" ).toInt();
					if( value > 0 )
					{
						m_head.setAttribute( "bpm",
									value );
						QDomNode oldNode = node;
						node = node.nextSibling();
						m_head.removeChild( oldNode );
						continue;
					}
				}
				else if( node.nodeName() == "mastervol" )
				{
					int value = node.toElement().attribute(
							"value" ).toInt();
					if( value > 0 )
					{
						m_head.setAttribute(
							"mastervol", value );
						QDomNode oldNode = node;
						node = node.nextSibling();
						m_head.removeChild( oldNode );
						continue;
					}
				}
				else if( node.nodeName() == "masterpitch" )
				{
					m_head.setAttribute( "masterpitch",
						-node.toElement().attribute(
							"value" ).toInt() );
					QDomNode oldNode = node;
					node = node.nextSibling();
					m_head.removeChild( oldNode );
					continue;
				}
			}
			node = node.nextSibling();
		}
	}

	if( version < "0.2.1-20070508" )
	{
		QDomNodeList list = elementsByTagName( "arpandchords" );
		for( int i = 0; !list.item( i ).isNull(); ++i )
		{
			QDomElement el = list.item( i ).toElement();
			if( el.hasAttribute( "chorddisabled" ) )
			{
				el.setAttribute( "chord-enabled",
					!el.attribute( "chorddisabled" )
								.toInt() );
				el.setAttribute( "arp-enabled",
					!el.attribute( "arpdisabled" )
								.toInt() );
			}
			else if( !el.hasAttribute( "chord-enabled" ) )
			{
				el.setAttribute( "chord-enabled", true );
				el.setAttribute( "arp-enabled",
					el.attribute( "arpdir" ).toInt() != 0 );
			}
		}

		while( !( list = elementsByTagName( "channeltrack" ) ).isEmpty() )
		{
			QDomElement el = list.item( 0 ).toElement();
			el.setTagName( "instrumenttrack" );
		}

		list = elementsByTagName( "instrumenttrack" );
		for( int i = 0; !list.item( i ).isNull(); ++i )
		{
			QDomElement el = list.item( i ).toElement();
			if( el.hasAttribute( "vol" ) )
			{
				float value = el.attribute( "vol" ).toFloat();
				value = roundf( value * 0.585786438f );
				el.setAttribute( "vol", value );
			}
			else
			{
				QDomNodeList vol_list = el.namedItem(
							"automation-pattern" )
						.namedItem( "vol" ).toElement()
						.elementsByTagName( "time" );
				for( int j = 0; !vol_list.item( j ).isNull();
									++j )
				{
					QDomElement timeEl = list.item( j )
								.toElement();
					int value = timeEl.attribute( "value" )
								.toInt();
					value = (int)roundf( value *
								0.585786438f );
					timeEl.setAttribute( "value", value );
				}
			}
		}
	}


	if( version < "0.3.0-rc2" )
	{
		QDomNodeList list = elementsByTagName( "arpandchords" );
		for( int i = 0; !list.item( i ).isNull(); ++i )
		{
			QDomElement el = list.item( i ).toElement();
			if( el.attribute( "arpdir" ).toInt() > 0 )
			{
				el.setAttribute( "arpdir",
					el.attribute( "arpdir" ).toInt() - 1 );
			}
		}
	}

	if( version < "0.3.0" )
	{
		QDomNodeList list;
		while( !( list = elementsByTagName(
					"pluckedstringsynth" ) ).isEmpty() )
		{
			QDomElement el = list.item( 0 ).toElement();
			el.setTagName( "vibedstrings" );
			el.setAttribute( "active0", 1 );
		}

		while( !( list = elementsByTagName( "lb303" ) ).isEmpty() )
		{
			QDomElement el = list.item( 0 ).toElement();
			el.setTagName( "lb302" );
		}

		while( !( list = elementsByTagName( "channelsettings" ) ).
								isEmpty() )
		{
			QDomElement el = list.item( 0 ).toElement();
			el.setTagName( "instrumenttracksettings" );
		}
	}

	if( version < "0.4.0-20080104" )
	{
		QDomNodeList list = elementsByTagName( "fx" );
		for( int i = 0; !list.item( i ).isNull(); ++i )
		{
			QDomElement el = list.item( i ).toElement();
			if( el.hasAttribute( "fxdisabled" ) &&
				el.attribute( "fxdisabled" ).toInt() == 0 )
			{
				el.setAttribute( "enabled", 1 );
			}
		}
	}

	if( version < "0.4.0-20080118" )
	{
		QDomNodeList list;
		while( !( list = elementsByTagName( "fx" ) ).isEmpty() )
		{
			QDomElement fxchain = list.item( 0 ).toElement();
			fxchain.setTagName( "fxchain" );
			QDomNode rack = list.item( 0 ).firstChild();
			QDomNodeList effects = rack.childNodes();
			// move items one level up
			while( effects.count() )
			{
				fxchain.appendChild( effects.at( 0 ) );
			}
			fxchain.setAttribute( "numofeffects",
				rack.toElement().attribute( "numofeffects" ) );
			fxchain.removeChild( rack );
		}
	}

	if( version < "0.4.0-20080129" )
	{
		QDomNodeList list;
		while( !( list =
			elementsByTagName( "arpandchords" ) ).isEmpty() )
		{
			QDomElement aac = list.item( 0 ).toElement();
			aac.setTagName( "arpeggiator" );
			QDomNode cloned = aac.cloneNode();
			cloned.toElement().setTagName( "chordcreator" );
			aac.parentNode().appendChild( cloned );
		}
	}

	if( version < "0.4.0-20080409" )
	{
		QStringList s;
		s << "note" << "pattern" << "bbtco" << "sampletco" << "time";
		for( QStringList::iterator it = s.begin(); it < s.end(); ++it )
		{
			QDomNodeList list = elementsByTagName( *it );
			for( int i = 0; !list.item( i ).isNull(); ++i )
			{
				QDomElement el = list.item( i ).toElement();
				el.setAttribute( "pos",
					el.attribute( "pos" ).toInt()*3 );
				el.setAttribute( "len",
					el.attribute( "len" ).toInt()*3 );
			}
		}
		QDomNodeList list = elementsByTagName( "timeline" );
		for( int i = 0; !list.item( i ).isNull(); ++i )
		{
			QDomElement el = list.item( i ).toElement();
			el.setAttribute( "lp0pos",
				el.attribute( "lp0pos" ).toInt()*3 );
			el.setAttribute( "lp1pos",
				el.attribute( "lp1pos" ).toInt()*3 );
		}
		
	}

	if( version < "0.4.0-20080607" )
	{
		QDomNodeList list;
		while( !( list = elementsByTagName( "midi" ) ).isEmpty() )
		{
			QDomElement el = list.item( 0 ).toElement();
			el.setTagName( "midiport" );
		}
	}

	if( version < "0.4.0-20080622" )
	{
		QDomNodeList list;
		while( !( list = elementsByTagName(
					"automation-pattern" ) ).isEmpty() )
		{
			QDomElement el = list.item( 0 ).toElement();
			el.setTagName( "automationpattern" );
		}

		list = elementsByTagName( "bbtrack" );
		for( int i = 0; !list.item( i ).isNull(); ++i )
		{
			QDomElement el = list.item( i ).toElement();
			QString s = el.attribute( "name" );
			s.replace( QRegExp( "^Beat/Baseline " ),
							"Beat/Bassline " );
			el.setAttribute( "name", s );
		}
	}

	if( version < "0.4.0-beta1" )
	{
		// convert binary effect-key-blobs to XML
		QDomNodeList list;
		list = elementsByTagName( "effect" );
		for( int i = 0; !list.item( i ).isNull(); ++i )
		{
			QDomElement el = list.item( i ).toElement();
			QString k = el.attribute( "key" );
			if( !k.isEmpty() )
			{
				const QList<QVariant> l =
					base64::decode( k, QVariant::List ).toList();
				if( !l.isEmpty() )
				{
					QString name = l[0].toString();
					QVariant u = l[1];
					EffectKey::AttributeMap m;
					// VST-effect?
					if( u.type() == QVariant::String )
					{
						m["file"] = u.toString();
					}
					// LADSPA-effect?
					else if( u.type() == QVariant::StringList )
					{
						const QStringList sl = u.toStringList();
						m["plugin"] = sl.value( 0 );
						m["file"] = sl.value( 1 );
					}
					EffectKey key( NULL, name, m );
					el.appendChild( key.saveXML( *this ) );
				}
			}
		}
	}
	if( version < "0.4.0-rc2" )
	{
		QDomNodeList list = elementsByTagName( "audiofileprocessor" );
		for( int i = 0; !list.item( i ).isNull(); ++i )
		{
			QDomElement el = list.item( i ).toElement();
			QString s = el.attribute( "src" );
			s.replace( "drumsynth/misc ", "drumsynth/misc_" );
			s.replace( "drumsynth/r&b", "drumsynth/r_n_b" );
			s.replace( "drumsynth/r_b", "drumsynth/r_n_b" );
			el.setAttribute( "src", s );
		}
		list = elementsByTagName( "lb302" );
		for( int i = 0; !list.item( i ).isNull(); ++i )
		{
			QDomElement el = list.item( i ).toElement();
			int s = el.attribute( "shape" ).toInt();
			if( s >= 1 )
			{
				s--;
			}
			el.setAttribute( "shape", QString("%1").arg(s) );
		}

	}

	// new default colour for B&B tracks
	QDomNodeList list = elementsByTagName( "bbtco" );
	for( int i = 0; !list.item( i ).isNull(); ++i )
	{
		QDomElement el = list.item( i ).toElement();
		unsigned int rgb = el.attribute( "color" ).toUInt();
		if( rgb == qRgb( 64, 128, 255 ) )
		{
			el.setAttribute( "color", bbTCO::defaultColor() );
		}
	}

	// Time-signature
	if ( !m_head.hasAttribute( "timesig_numerator" ) )
	{
		m_head.setAttribute( "timesig_numerator", 4 );
		m_head.setAttribute( "timesig_denominator", 4 );
	}

	if( !m_head.hasAttribute( "mastervol" ) )
	{
		m_head.setAttribute( "mastervol", 100 );
	}
//printf("%s\n", toString( 2 ).toUtf8().constData());
}
コード例 #29
0
ファイル: DataFile.cpp プロジェクト: Skyh13/lmms
void DataFile::loadData( const QByteArray & _data, const QString & _sourceFile )
{
	QString errorMsg;
	int line = -1, col = -1;
	if( !setContent( _data, &errorMsg, &line, &col ) )
	{
		// parsing failed? then try to uncompress data
		QByteArray uncompressed = qUncompress( _data );
		if( !uncompressed.isEmpty() )
		{
			if( setContent( uncompressed, &errorMsg, &line, &col ) )
			{
				line = col = -1;
			}
		}
		if( line >= 0 && col >= 0 )
		{
			qWarning() << "at line" << line << "column" << errorMsg;
			if( Engine::hasGUI() )
			{
				QMessageBox::critical( NULL,
					SongEditor::tr( "Error in file" ),
					SongEditor::tr( "The file %1 seems to contain "
							"errors and therefore can't be "
							"loaded." ).
								arg( _sourceFile ) );
			}

			return;
		}
	}

	QDomElement root = documentElement();
	m_type = type( root.attribute( "type" ) );
	m_head = root.elementsByTagName( "head" ).item( 0 ).toElement();


	if( root.hasAttribute( "creatorversion" ) )
	{
		// compareType defaults to Build,so it doesn't have to be set here
		ProjectVersion createdWith = root.attribute( "creatorversion" );
		ProjectVersion openedWith = LMMS_VERSION;;

		if ( createdWith != openedWith )
		{
			// only one compareType needs to be set, and we can compare on one line because setCompareType returns ProjectVersion
			if ( createdWith.setCompareType(Minor) != openedWith)
			{
				if( Engine::hasGUI() && root.attribute( "type" ) == "song" ) //documentElement()
				{
					QMessageBox::information( NULL,
						SongEditor::tr( "Project Version Mismatch" ),
						SongEditor::tr( 
								"This project was created with "
								"LMMS version %1, but version %2 "
								"is installed")
								.arg( root.attribute( "creatorversion" ) )
								.arg( LMMS_VERSION ) );
				}
			}

			// the upgrade needs to happen after the warning as it updates the project version.
			if( createdWith.setCompareType(Build) < openedWith )
			{
				upgrade();
			}
		}
	}

	m_content = root.elementsByTagName( typeName( m_type ) ).
							item( 0 ).toElement();
}
コード例 #30
0
ファイル: udxfile.cpp プロジェクト: DarkHobbit/doublecontact
bool UDXFile::importRecords(const QString &url, ContactList &list, bool append)
{
    if (!openFile(url, QIODevice::ReadOnly))
        return false;
    // Read XML
    QString err_msg;
    int err_line, err_col;
    if (!setContent(&file, &err_msg, &err_line, &err_col)) {
        _errors << QObject::tr("Can't read content from file %1\n%2\nline %3, col %4\n")
            .arg(url).arg(err_msg).arg(err_line).arg(err_col);
        closeFile();
        return false;
    }
    closeFile();
    // Root element
    QDomElement root = documentElement();
    if (root.nodeName()!="DataExchangeInfo") {
        _errors << QObject::tr("Root node is not 'DataExchangeInfo' at file\n%1").arg(url);
        return false;
    }
    // Codepage, version, expected record count
    QDomElement recInfo = root.firstChildElement("RecordInfo");
    if (recInfo.isNull()) {
        _errors << QObject::tr("Can't find 'RecordInfo' tag at file\n%1").arg(url);
        return false;
    }
    QString charSet = recInfo.firstChildElement("Encoding").text();
    if (charSet.isEmpty()) {
        _errors << QObject::tr("Warning: codepage not found, trying use UTF-8...");
        charSet = "UTF-8";
    }
    QString udxVer = recInfo.firstChildElement("UdxVersion").text();
    if (udxVer.isEmpty()) {
        _errors << QObject::tr("Warning: udx version not found, treat as 1.0...");
        udxVer = "1.0";
    }
    QDomElement vcfInfo = recInfo.firstChildElement("RecordOfvCard");
    QString vcVer = vcfInfo.firstChildElement("vCardVersion").text();
    int expCount = vcfInfo.firstChildElement("vCardRecord").text().toInt();
    // vCard set
    QDomElement vCard = root.firstChildElement("vCard");
    if (vCard.isNull()) {
        _errors << QObject::tr("Can't find 'vCard' records at file\n%1").arg(url);
        return false;
    }
    // QTextCodec* codec = QTextCodec::codecForName(charSet.toLocal8Bit()); TODO not works on windows
    ContactItem item;
    if (!append)
        list.clear();
    QDomElement vCardInfo = vCard.firstChildElement("vCardInfo");
    while (!vCardInfo.isNull()) {
        item.clear();
        item.originalFormat = "UDX";
        item.version = udxVer;
        item.subVersion = vcVer;
        item.id = vCardInfo.firstChildElement("Sequence").text();
        QDomElement fields = vCardInfo.firstChildElement("vCardField");
        if (fields.isNull())
            _errors << QObject::tr("Can't find 'vCardField' at sequence %1").arg(item.id);
        QDomElement field = fields.firstChildElement();
        while (!field.isNull()) {
            QString fldName = field.nodeName().toUpper();
            QString fldValue = field.text(); // codec->toUnicode(field.text().toLocal8Bit()); TODO not works on windows
            if (fldName=="N") {
                fldValue.replace("\\;", " ");
                // In ALL known me udx files part before first ; was EMPTY
                fldValue.remove(";");
                item.names = fldValue.split(" ");
                // If empty parts not in-middle, remove it
                item.dropFinalEmptyNames();
            }
            else if (fldName.startsWith("TEL")) {
                Phone phone;
                phone.number = fldValue;
                if (fldName=="TEL")
                    phone.tTypes << "CELL";
                else if (fldName=="TELHOME")
                    phone.tTypes << "HOME";
                else if (fldName=="TELWORK")
                    phone.tTypes << "WORK";
                else if (fldName=="TELFAX")
                    phone.tTypes << "FAX";
                else
                    _errors << QObject::tr("Unknown phone type: %1 (%2)").arg(phone.number).arg(item.names[0]);
                item.phones.push_back(phone);
            }
            else if (fldName=="ORGNAME")
                item.organization = fldValue;
            else if (fldName=="BDAY")
                item.birthday.value = QDateTime::fromString(fldValue, "yyyyMMdd"); // TODO Maybe, use DateItem::fromString
            else if (fldName=="EMAIL") {
                Email email;
                email.address = fldValue;
                email.emTypes << "pref";
                item.emails.push_back(email);
            }
            else
                _errors << QObject::tr("Unknown 'vCardfield' type: %1").arg(fldName);
            field = field.nextSiblingElement();
        }
        item.calculateFields();
        list.push_back(item);
        vCardInfo = vCardInfo.nextSiblingElement();
    }
    if (list.count()!=expCount)
        _errors << QObject::tr("%1 records read, %2 expected").arg(list.count()).arg(expCount);
    // Unknown tags statistics
    int totalUnknownTags = 0;
    foreach (const ContactItem& _item, list)
        totalUnknownTags += _item.unknownTags.count();
    if (totalUnknownTags)
        _errors << QObject::tr("%1 unknown tags found").arg(totalUnknownTags);
    // Ready
    return (!list.isEmpty());
}