void
  operator <<= (SensorDescriptionIDL& sensor, const QDomNode& node)
  {
    if (!node.isNull()) {
      QDomNode n1 = node.firstChild();
      while(!n1.isNull() ) {
	QDomNode n2 = n1.firstChild();
	if (!n2.isNull()) {
	  QDomText t = n2.toText(); // try to convert the node to a text
	  if(!t.isNull() ) {       // the node was really a text element.
	    if (n1.nodeName() == "minrange") {
	      sensor.minRange = t.data().toInt();
	    }
	    else if (n1.nodeName() == "maxrange") {
	      sensor.maxRange = t.data().toInt();
	    }
	    else if (n1.nodeName() == "focus") {
	      sensor.focus = deg2Rad(t.data().toDouble());
	    }
	  }
	}
	n1 = n1.nextSibling();
      }
    }
  }
  void
  operator <<= (ScanDescriptionIDL& description, const QDomNode& node)
  {
    description.group.length(0);

    if (!node.isNull()) {
      QDomNode n1 = node.firstChild();
      while(!n1.isNull() ) {
	if (n1.nodeName() == "sensorgroup") {
	  description.group.length(description.group.length() + 1);
	  description.group[description.group.length() - 1].sensor.length(0);
	  description.group[description.group.length() - 1] <<= n1;
	} 
	else if (n1.nodeName() == "scantype") {
	  QDomNode n2 = n1.firstChild();
	  if (!n2.isNull()) {
	    QDomText t = n2.toText(); // try to convert the node to a text
	    description.scanType = t.data().toInt();
	  }
	}
	else if (n1.nodeName() == "eventname") {
	  QDomNode n2 = n1.firstChild();
	  if (!n2.isNull()) {
	    QDomText t = n2.toText(); // try to convert the node to a text
	    description.eventName = CORBA::string_dup(t.data());
	  }
	}
	n1 = n1.nextSibling();
      }
    }
  }
void QgsProjectBadLayerHandler::setDataSource( QDomNode &layerNode, const QString &dataSource )
{
  QDomNode dataSourceNode = layerNode.namedItem( QStringLiteral( "datasource" ) );
  QDomElement dataSourceElement = dataSourceNode.toElement();
  QDomText dataSourceText = dataSourceElement.firstChild().toText();

  QgsDebugMsg( "datasource changed from " + dataSourceText.data() );

  dataSourceText.setData( dataSource );

  QgsDebugMsg( "to " + dataSourceText.data() );
}
Beispiel #4
0
static QString parseInstrName(const QString& name)
      {
      QString sName;
      QDomDocument dom;
      int line, column;
      QString err;
      if (!dom.setContent(name, false, &err, &line, &column)) {
            QString col, ln;
            col.setNum(column);
            ln.setNum(line);
            QString error = err + "\n at line " + ln + " column " + col;
            qDebug("error: %s\n", qPrintable(error));
            qDebug("   data:<%s>\n", qPrintable(name));
            return QString();
            }

      for (QDomNode e = dom.documentElement(); !e.isNull(); e = e.nextSiblingElement()) {
            for (QDomNode ee = e.firstChild(); !ee.isNull(); ee = ee.nextSibling()) {
                  QDomElement el = ee.toElement();
                  const QString& tag(el.tagName());
                  if (tag == "symbol") {
                        QString name = el.attribute(QString("name"));
                        if (name == "flat")
                              sName += "b";
                        else if (name == "sharp")
                              sName += "#";
                        }
                  QDomText t = ee.toText();
                  if (!t.isNull())
                        sName += t.data();
                  }
            }
      return sName;
      }
/**
   Get the project title

   XML in file has this form:
\verbatim
   <qgis projectname="default project">
   <title>a project title</title>
\endverbatim

   @todo XXX we should go with the attribute xor title, not both.
*/
static void _getTitle( QDomDocument const &doc, QString & title )
{
  QDomNodeList nl = doc.elementsByTagName( "title" );

  title = "";                 // by default the title will be empty

  if ( !nl.count() )
  {
    QgsDebugMsg( "unable to find title element" );
    return;
  }

  QDomNode titleNode = nl.item( 0 );  // there should only be one, so zeroth element ok

  if ( !titleNode.hasChildNodes() ) // if not, then there's no actual text
  {
    QgsDebugMsg( "unable to find title element" );
    return;
  }

  QDomNode titleTextNode = titleNode.firstChild();  // should only have one child

  if ( !titleTextNode.isText() )
  {
    QgsDebugMsg( "unable to find title element" );
    return;
  }

  QDomText titleText = titleTextNode.toText();

  title = titleText.data();

} // _getTitle
Beispiel #6
0
void Format::parseBlock( QTextCursor &cursor, const QDomElement &element )
{
//  dbg() << "Format::parseBlock()" << endl;

  QDomNode n;
  for( n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) {
    QDomElement e = n.toElement();
    if ( e.tagName() == "fragment" ) {
      QTextCharFormat format;
      if ( e.hasAttribute( "link" ) ) {
        format.setAnchor( true );
        QString href = e.attribute( "link" );
        format.setAnchorHref( href );
        format.setFontUnderline( true );
        if ( href.startsWith( "todoodle:" ) ) {
          format = TextFormats::topicLinkCharFormat( href );
        } else {
          format = TextFormats::hyperLinkCharFormat( href );
        }
      }
      if ( e.attribute( "bold" ) == "true" ) {
        format.setFontWeight( QFont::Bold );
      }
      if ( e.attribute( "italic" ) == "true" ) {
        format.setFontItalic( true );
      }
      int fontSize = 0;
      if ( e.hasAttribute( "fontsize" ) ) {
        fontSize = e.attribute( "fontsize" ).toInt();
      } else {
        fontSize = 10;
      }
      if ( fontSize > 0 ) format.setFontPointSize( fontSize );
      
      QDomNode n2;
      for( n2 = e.firstChild(); !n2.isNull(); n2 = n2.nextSibling() ) {
//        dbg() << "TICK" << endl;
        QDomText t = n2.toText();
        if ( !t.isNull() ) {
//          dbg() << "TEXT: '" << t.data() << "'" << endl;
          cursor.insertText( t.data(), format );
//          dbg() << "done" << endl;
        } else {
          QDomElement e2 = n2.toElement();
          if ( !e2.isNull() ) {
            if ( e2.tagName() == "todo" ) {
              QTextImageFormat f;
              if ( e2.attribute( "status" ) == "todo" ) {
                f.setName( ":/images/todo.png" );
              } else {
                f.setName( ":/images/tododone.png" );
              }
              cursor.insertImage( f );
            }
          }
        }
      }
    }
  }
}
Beispiel #7
0
QString KWDWriter::getText(const QDomElement &paragraph)
{
    QDomNode temp = paragraph.elementsByTagName("TEXT").item(0).firstChild();
    QDomText currentText = temp.toText();
    if (temp.isNull()) {
        kWarning(30503) << "no text";
    }
    return currentText.data();
}
Beispiel #8
0
static QString getFirstText(QDomElement element)
{
    for (QDomNode dname = element.firstChild(); !dname.isNull();
         dname = dname.nextSibling())
    {
        QDomText t = dname.toText();
        if (!t.isNull())
            return t.data();
    }
    return QString();
}
Beispiel #9
0
QString tagContent(const QDomElement &e)
{
	// look for some tag content
	for(QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) {
		QDomText i = n.toText();
		if(i.isNull())
			continue;
		return i.data();
	}

	return "";
}
Beispiel #10
0
/**
 * Loads the <UML:CheckConstraint> XMI element.
 */
bool UMLCheckConstraint::load( QDomElement & element )
{
    QDomNode node = element.firstChild();

    QDomText checkConstraintText = node.toText();
    if ( checkConstraintText.isNull() )
        return false;

    m_CheckCondition = checkConstraintText.data();

    return true;
}
  void
  operator <<= (SensorPositionIDL& position, const QDomNode& node)
  {
    if (!node.isNull()) {
      QDomNode n1 = node.firstChild();
      while(!n1.isNull() ) {
	QDomNode n2 = n1.firstChild();
	if (!n2.isNull()) {
	  QDomText t = n2.toText(); // try to convert the node to a text
	  if(!t.isNull() ) {       // the node was really a text element.
	    if (n1.nodeName() == "height") {
	      position.height = t.data().toInt();
	    }
	    else if (n1.nodeName() == "distance") {
	      position.distance = t.data().toInt();
	    }
	    else if (n1.nodeName() == "alpha") {
	      position.alpha = deg2Rad(t.data().toDouble());
	    }
	    else if (n1.nodeName() == "beta") {
	      position.beta = deg2Rad(t.data().toDouble());
	    }
	    else if (n1.nodeName() == "gamma") {
	      position.gamma = deg2Rad(t.data().toDouble());
	    }
	    else if (n1.nodeName() == "masked") {
	      position.masked = (t.data() == "true");
	    }
	  }
	}
	n1 = n1.nextSibling();
      }
    }
  }
  void
  Parameters::operator <<= (const QDomNode& node)
  {
    Super::operator <<= (node);
    if (!node.isNull()) {
      QDomNode n1 = node.firstChild();
      while(!n1.isNull() ) {
	QDomNode n2 = n1.firstChild();
	if (!n2.isNull()) {
	  if (n1.nodeName() == "stdcrystal") {
	    QDomText t = n2.toText(); // try to convert the node to a text
	    if(!t.isNull() ) {        // the node was really a text element.
	      stdcrystal = (t.data() == "true");
	    }
	  } 
	  else if (n1.nodeName() == "continousmode") {
	    QDomText t = n2.toText(); // try to convert the node to a text
	    if(!t.isNull() ) {        // the node was really a text element.
	      continousmode = (t.data() == "true");
	    }
	  } 
	  else if (n1.nodeName() == "pollintervall") {
	    QDomText t = n2.toText(); // try to convert the node to a text
	    if(!t.isNull() ) {        // the node was really a text element.
	      pollintervall = t.data().toInt();
	    }
	  } 
	  else if (n1.nodeName() == "notify") {
	    QDomText t = n2.toText(); // try to convert the node to a text
	    if(!t.isNull() ) {        // the node was really a text element.
	      notify = (t.data() == "true");
	    }
	  } 
	  else if (n1.nodeName() == "positionstamps") {
	    QDomText t = n2.toText(); // try to convert the node to a text
	    if(!t.isNull() ) {        // the node was really a text element.
	      positionStamps = (t.data() == "true");
	    }
	  } 
	  else if (n1.nodeName() == "statistics") {
	    QDomText t = n2.toText(); // try to convert the node to a text
	    if(!t.isNull() ) {        // the node was really a text element.
	      statistics = (t.data() == "true");
	    }
	  } 
	  else if (n1.nodeName() == "laser") {
	    while (!n2.isNull()) {
	      if (n2.nodeName() == "scandescription") 
		laserDescription <<= n2;
	      n2 = n2.nextSibling();
	    }
	  }
	}
      n1 = n1.nextSibling();
      }
    }
  }
  void
  DifferentialMotionParameters::operator <<= (const QDomNode& _node)
  {
    Super::operator<<=(_node);

    QDomNode n = _node.firstChild();
    while( !n.isNull() ) {
      QDomElement e = n.toElement(); // try to convert the node to an element.
      if( !e.isNull() ) {            // the node was really an element.
	if (e.tagName()=="parameter") {
	  QDomAttr parameterName = e.attributeNode("name");
	  QString name;
	  QString value;

	  if (!parameterName.isNull()) {
	    name = parameterName.value();
	  }
	  else {
	    throw Exception("Parameter tag without name.");
	  }

	  QDomNode n2 = n.firstChild();
	  while (!n2.isNull()) {
	    QDomText t = n2.toText(); // try to convert the node to a text
	    if(!t.isNull() ) {        // the node was really a text element.
	      value = t.data();
	      break;
	    }
	    n2 = n2.nextSibling();
	  }
	  if (n2.isNull())
	    throw Exception("Parameter " + std::string(name) + "without value.");
	  
	  if (name == "MinLTranslation")
	    minLTranslation = value.toInt();
	  else if (name == "MaxLTranslation")
	    maxLTranslation = value.toInt();
	  else if (name == "MinRTranslation")
	    minRTranslation = value.toInt();
	  else if (name == "MaxRTranslation")
	    maxRTranslation = value.toInt();
	  else if (name == "WheelBase")
	    wheelBase = value.toInt();
	}
      }
      n = n.nextSibling();
    }
  }
  void
  DevParameters::operator <<= (const QDomNode& node)
  {
    if (!node.isNull()) {
      QDomNode n1 = node.firstChild();
      while(!n1.isNull() ) {
	if (n1.nodeName() == "device") {
	  QDomNode n2 = n1.firstChild();
	  QDomText t = n2.toText(); // try to convert the node to a text
	  if(!t.isNull() ) { // the node was really an element.
	    device = t.data();
	  }
	}
	n1 = n1.nextSibling();
      }
    }
  }
Beispiel #15
0
bool Converter::convertTextNode(QTextCursor *cursor, const QDomText &element, const QTextCharFormat &format)
{
    QString text = element.data();
    if (text.startsWith("\n"))
    {
        text = text.trimmed();
        if (!text.isEmpty())
            cursor->insertText(text, format);
    }
    else
    {
        if (!text.isEmpty())
            cursor->insertText(text, format);
    }

    return true;
}
Beispiel #16
0
void makeTextNodeMod(KBookmark bk, const QString &m_nodename, const QString &m_newText) {
    QDomNode subnode = bk.internalElement().namedItem(m_nodename);
    if (subnode.isNull()) {
        subnode = bk.internalElement().ownerDocument().createElement(m_nodename);
        bk.internalElement().appendChild(subnode);
    }
    
    if (subnode.firstChild().isNull()) {
        QDomText domtext = subnode.ownerDocument().createTextNode("");
        subnode.appendChild(domtext);
    }
    
    QDomText domtext = subnode.firstChild().toText();
    
    QString m_oldText = domtext.data();
    domtext.setData(m_newText);
}
Beispiel #17
0
// Author & Date: Ehsan Azar       15 June 2010
// Purpose: Get current node value
// Inputs:
//   val - the default value
QVariant XmlFile::value(const QVariant & val)
{
    QVariant res = val;

    if (!m_nodes.isEmpty())
    {
        // Get the current node
        QDomElement node = m_nodes.last();
        if (!node.isNull())
        {
            // Array Type is how we distinguish lists
            if (node.attribute("Type").compare("Array", Qt::CaseInsensitive) == 0)
            {
                QVariantList varlist;
                QStringList keys = childKeys();
                for (int i = 0; i < keys.count(); ++i)
                {
                    QString key = keys[i];
                    if (i > 0 && key == keys[i - 1])
                        key = QString(key + "<%1>").arg(i);
                    // Recursively return the list
                    beginGroup(key);
                    QVariant nodevalue = value(QString());
                    endGroup();
                    // Make sure value is meaningful
                    if (nodevalue.isValid())
                        varlist += nodevalue; // add new value
                }
                if (!keys.isEmpty())
                    res = varlist;
            } else {
                QDomNode child = node.firstChild();
                if (!child.isNull())
                {
                    QDomText domText = child.toText();
                    if (!domText.isNull())
                        res = domText.data();
                    else
                        return toString();
                }
            }
        }
    }
    return res;
}
Beispiel #18
0
void VarList::fromXml(const QDomElement &e)
{
	clear();

	for(QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) {
		QDomElement i = n.toElement();
		if(i.isNull())
			continue;
		if(i.tagName() == "item") {
			QString var, val;
			var = i.attribute("name");
			QDomText t = i.firstChild().toText();
			if(!t.isNull())
				val = t.data();
			set(var, val);
		}
	}
}
Beispiel #19
0
bool TextRegExp::load( QDomElement top, const QString& /*version*/)
{
    Q_ASSERT( top.tagName() == QString::fromLocal8Bit( "Text" ) );
    if ( top.hasChildNodes() ) {
        QDomNode child = top.firstChild();
        if ( ! child.isText() ) {
            KMessageBox::sorry( 0, i18n("<p>Element <b>Text</b> did not contain any textual data.</p>"),
                                i18n("Error While Loading From XML File") ) ;
            return false;
        }
        QDomText txtNode = child.toText();
        _text = txtNode.data();
    } else {
        _text = QString::fromLatin1( "" );
    }

    return true;
}
Beispiel #20
0
static QTextDocumentFragment parseInstrName(const QString& name)
      {
      if (name.isEmpty())
            return QTextDocumentFragment();
      QTextDocument doc;
      QTextCursor cursor(&doc);
      QTextCharFormat f = cursor.charFormat();
      QTextCharFormat sf(f);

      QFont font("MScore1");
      sf.setFont(font);

      QDomDocument dom;
      int line, column;
      QString err;
      if (!dom.setContent(name, false, &err, &line, &column)) {
            QString col, ln;
            col.setNum(column);
            ln.setNum(line);
            QString error = err + "\n at line " + ln + " column " + col;
            qDebug("parse instrument name: %s\n", qPrintable(error));
            qDebug("   data:<%s>\n", qPrintable(name));
            return QTextDocumentFragment();
            }

      for (QDomNode e = dom.documentElement(); !e.isNull(); e = e.nextSibling()) {
            for (QDomNode ee = e.firstChild(); !ee.isNull(); ee = ee.nextSibling()) {
                  QDomElement de1 = ee.toElement();
                  QString tag(de1.tagName());
                  if (tag == "symbol") {
                        QString name = de1.attribute(QString("name"));
                        if (name == "flat")
                              cursor.insertText(QString(0xe10d), sf);
                        else if (name == "sharp")
                              cursor.insertText(QString(0xe10c), sf);
                        }
                  QDomText t = ee.toText();
                  if (!t.isNull())
                        cursor.insertText(t.data(), f);
                  }
            }
      return QTextDocumentFragment(&doc);
      }
  void
  Parameters::operator <<= (const QDomNode& node)
  {
    Super::operator <<= (node);

    if (!node.isNull()) {
      QDomNode n1 = node.firstChild();
      while(!n1.isNull() ) {
	if (n1.nodeName() == "DifferentialMotion")
	  motion <<= n1;
	else {
	  QDomNode n2 = n1.firstChild();
	  if (!n2.isNull()) {
	    QDomText t = n2.toText(); // try to convert the node to a text
	    if(!t.isNull() ) {        // the node was really a text element.
	      if (n1.nodeName() == "radius") {
		radius = t.data().toDouble();
	      }
	      if (n1.nodeName() == "maxTransVelocity") {
		maxTransVelocity = t.data().toInt();
	      }
	      if (n1.nodeName() == "maxTransAccel") {
		maxTransAccel = t.data().toInt();
	      }
	      if (n1.nodeName() == "maxRotVelocity") {
		maxRotVelocity = Miro::deg2Rad(t.data().toDouble());
	      }
	      if (n1.nodeName() == "maxRotAccel") {
		maxRotAccel = Miro::deg2Rad(t.data().toDouble());
	      }
	      if (n1.nodeName() == "voltWarn") {
		voltWarn = t.data().toInt();
	      }
	      if (n1.nodeName() == "voltPanic") {
		voltPanic = t.data().toInt();
	    }
	    }
	  }
	}
	n1 = n1.nextSibling();
      }
    }
  }
Beispiel #22
0
void KWDWriter::addText(const QDomElement &paragraph, const QString& _text, int format_id, bool keep_formatting)
{
    QString text = _text;

    QDomNode temp = paragraph.elementsByTagName("TEXT").item(0).firstChild();
    QDomText currentText = temp.toText();
    if (temp.isNull()) {
        kDebug(30503) << "no text"; return;
    }
    QString oldtext = currentText.data();
    int oldLength = oldtext.length();
    if (keep_formatting) {
        if (oldLength) {
            ++oldLength;
            oldtext.append('\n');
        }
    } else {
        if (oldLength)
            ++oldLength; // add new trailing space char
        text = text.simplified(); // drop all unprintable chars
    }
    QString newtext;
    if (keep_formatting)
        newtext = oldtext + text;
    else {
        newtext = oldtext + ' ' + text;
        newtext = newtext.simplified(); // strip possible new space at beginning.
    }
    currentText.setData(newtext);
    int newLength = text.length();
    QDomElement lastformat = currentFormat(paragraph, true);
    if (lastformat.attribute("id").isEmpty()) // keep old id value, e.g. for LINK URL
        lastformat.setAttribute("id", format_id);
    lastformat.setAttribute("pos", QString("%1").arg(oldLength));
    lastformat.setAttribute("len", QString("%1").arg(newLength));
}
Beispiel #23
0
void K3b::VcdJob::slotParseVcdxBuildOutput( const QString& line )
{
    QDomDocument xml_doc;
    QDomElement xml_root;

    QString str = line.trimmed();

    emit debuggingOutput( "vcdxbuild", str );

    xml_doc.setContent( QString( "<?xml version='1.0'?><vcdxbuild>" ) + str + "</vcdxbuild>" );

    xml_root = xml_doc.documentElement();

    // There should be only one... but ...
    for ( QDomNode node = xml_root.firstChild(); !node.isNull(); node = node.nextSibling() ) {
        QDomElement el = node.toElement();
        if ( el.isNull() )
            continue;

        const QString tagName = el.tagName().toLower();

        if ( tagName == "progress" ) {
            const QString oper = el.attribute( "operation" ).toLower();
            const unsigned long long pos = el.attribute( "position" ).toLong();
            const long long size = el.attribute( "size" ).toLong();

            if ( oper == "scan" ) {
                // Scan Video Files
                if ( m_stage == stageUnknown || pos < m_bytesFinished ) {
                    const uint index = el.attribute( "id" ).remove( QRegExp( "sequence-" ) ).toUInt();

                    m_currentWrittenTrack = m_doc->at( m_currentWrittenTrackNumber );
                    emit newSubTask( i18n( "Scanning video file %1 of %2 (%3)" , index + 1 , doc() ->numOfTracks() , m_currentWrittenTrack->fileName() ) );
                    m_bytesFinished = 0;

                    if ( !firstTrack ) {
                        m_bytesFinishedTracks += m_doc->at( m_currentWrittenTrackNumber ) ->size();
                        m_currentWrittenTrackNumber++;
                    } else
                        firstTrack = false;
                }
                emit subPercent( ( int ) ( 100.0 * ( double ) pos / ( double ) size ) );
                emit processedSubSize( pos / 1024 / 1024, size / 1024 / 1024 );

                // this is the first of three processes.
                double relOverallWritten = ( ( double ) m_bytesFinishedTracks + ( double ) pos ) / ( double ) doc() ->size();
                emit percent( ( int ) ( m_createimageonlypercent * relOverallWritten ) );

                m_bytesFinished = pos;
                m_stage = stageScan;

            } else if ( oper == "write" ) {
                emit subPercent( ( int ) ( 100.0 * ( double ) pos / ( double ) size ) );
                emit processedSubSize( ( pos * 2048 ) / 1024 / 1024, ( size * 2048 ) / 1024 / 1024 );
                emit percent( ( int ) ( m_createimageonlypercent + ( m_createimageonlypercent * ( double ) pos / ( double ) size ) ) );

                m_stage = stageWrite;
            } else {
                return ;
            }
        } else if ( tagName == "log" ) {
            QDomText tel = el.firstChild().toText();
            const QString level = el.attribute( "level" ).toLower();
            if ( tel.isText() ) {
                const QString text = tel.data();
                if ( m_stage == stageWrite && level == "information" )
                    qDebug() << QString( "(K3b::VcdJob) VcdxBuild information, %1" ).arg( text );
                if ( ( text ).startsWith( "writing track" ) )
                    emit newSubTask( i18n( "Creating Image for track %1" , ( text ).mid( 14 ) ) );
                else {
                    if ( level != "error" ) {
                        qDebug() << QString( "(K3b::VcdJob) vcdxbuild warning, %1" ).arg( text );
                        parseInformation( text );
                    } else {
                        qDebug() << QString( "(K3b::VcdJob) vcdxbuild error, %1" ).arg( text );
                        emit infoMessage( text, K3b::Job::MessageError );
                    }
                }
            }
        }
    }
}
Beispiel #24
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;
}
SimpleParameterEdit::SimpleParameterEdit(SimpleParameter::Type _type,
					 Miro::CFG::Parameter const& _parameter,
					 QDomNode& _parentNode, 
					 QDomNode& _node,
					 ItemXML * _parentItem, 
					 ItemXML * _item,
					 QWidget * _parent, 
					 const char * _name) :
  Super(_parameter, _parentNode, _node, 
	_parentItem, _item,
	_parent, _name),
  config_(ConfigFile::instance()),
  type_(_type),
  lineEdit_(NULL),
  textEdit_(NULL),
  typeBox_(NULL),
  listBox_(NULL),
  typeBoxModified_(false),
  listBoxModified_(false)
{
  if (parameter_.type_ == "Miro::Enumeration" || 
      parameter_.type_ == "Enumeration") {
    typeBox_ = new QComboBox(_parent, "type_box");
    editWidget_ = typeBox_;
  } else if (parameter_.type_ == "Miro::EnumerationMultiple" || 
	     parameter_.type_ == "EnumerationMultiple") {
    listBox_ = new Q3ListBox(_parent, "list_box");
    editWidget_ = listBox_;
  } else if (parameter_.type_ == "Miro::Text" ||
	     parameter_.type_ == "Text") {
    textEdit_ = new QTextEdit(_parent, "text_edit");
    textEdit_->setAcceptRichText(false);
    textEdit_->setAutoFormatting(false);
    editWidget_ = textEdit_;
  } else {
    lineEdit_ = new QLineEdit(_parent, "line_edit");
    editWidget_ = lineEdit_;
  }

  assert(!parentNode_.isNull());

  if (lineEdit_ != NULL) {
    // customize lineEdit for typesafe editing
    QValidator *  v = NULL;
    switch (_type) {
    case SimpleParameter::BOOL:
      v = new MyBoolValidator(this);
      lineEdit_->setValidator(v);
      break;
    case SimpleParameter::CHAR:
      lineEdit_->setMaxLength(1);
      break;
    case SimpleParameter::SHORT:
      v = new MyIntValidator(SHRT_MIN, SHRT_MAX, this);
      lineEdit_->setValidator(v);
      break;
    case SimpleParameter::USHORT:
      v = new MyIntValidator(0, USHRT_MAX, this);
      lineEdit_->setValidator(v);
      break;
    case SimpleParameter::INT:
      v = new MyIntValidator(INT_MIN + 1, INT_MAX - 1, this);
      lineEdit_->setValidator(v);
      break;
    case SimpleParameter::UINT:
      v = new MyIntValidator(0, INT_MAX - 1, this);
      lineEdit_->setValidator(v);
      break;
    case SimpleParameter::LONG:
      v = new MyIntValidator(INT_MIN + 1, INT_MAX - 1, this);
      lineEdit_->setValidator(v);
      break;
    case SimpleParameter::ULONG:
      v = new MyIntValidator(0, INT_MAX - 1, this);
      lineEdit_->setValidator(v);
      break;
    case SimpleParameter::FLOAT:
      v = new MyFloatValidator(this);
      lineEdit_->setValidator(v);
      break;
    case SimpleParameter::DOUBLE:
      v = new MyDoubleValidator(this);
      lineEdit_->setValidator(v);
      break;
    case SimpleParameter::ANGLE:
      v = new MyDoubleValidator(this);
      lineEdit_->setValidator(v);
      break;
    case SimpleParameter::MIRO_ANGLE:
      v = new MyDoubleValidator(-180., 180., 6, this);
      lineEdit_->setValidator(v);
      break;
    case SimpleParameter::STRING:
      break;
    case SimpleParameter::ACE_TIME_VALUE:
      v = new MyDoubleValidator(0, ULONG_MAX, 6, this);
      lineEdit_->setValidator(v);
      break;
    case SimpleParameter::ACE_INET_ADDR:
      break;
    default:
      break;
    }

    // connect validator, if we have one
    if (v) {
      QObject * p = _parent;
      while (p != NULL) {
	if (dynamic_cast<ParameterDialog *>(p) != NULL) {
	  connect(v, SIGNAL(acceptable(bool)), p, SLOT(accept(bool)));
	  break;
	}
	p = p->parent();
      }
    }

    // add default as tooltip
    if (!parameter_.default_.isEmpty()) {
      QToolTip::add(lineEdit_, QString("default: ") + parameter_.default_);
    }

    // set current value
    if (!node_.isNull()) {
      QDomElement e = node_.toElement();
      if (!e.isNull() && e.hasAttribute("value")) {
	lineEdit_->setText(e.attribute("value"));
      }
    }

    // set lineEdit to unedited
    lineEdit_->setEdited(false);
  }
  else if (textEdit_ != NULL) {
    QDomElement e = node_.toElement();
    if (!e.isNull()) {
      QDomNodeList l = e.childNodes();
      unsigned int i;
      for (i = 0; i < l.length(); ++i) {
	if (l.item(i).isText()) {
	  QDomText t = l.item(i).toText();
	  textEditText_ = t.data();
	  textEdit_->setPlainText(textEditText_);
	  break;
	}
      }
    }
  }
  else if (typeBox_ != NULL) {
    vector<string> stringvec;
    switch (_type) {

    case SimpleParameter::ENUMERATION:
      // init combo box
      typeBox_->setEditable(FALSE);
      stringvec = fullDef2StringVector(parameter_.fullDefault_);
      for (vector<string>::const_iterator i= stringvec.begin(); i!=stringvec.end(); ++i)
	typeBox_->insertItem(i->c_str());

      // set current value
      if (!node_.isNull()) {
	QDomElement e = node_.toElement();
	if (!e.isNull() && e.hasAttribute("value")) {
	  typeBox_->setCurrentText(e.attribute("value"));
	}
      } else {
	typeBox_->setCurrentText(parameter_.default_);
      }

      // connect to function, so we recognize, if value is changed
      connect(typeBox_, SIGNAL(activated(const QString&)), this, SLOT(typeBoxModified()));
      break;

    case SimpleParameter::ENUMERATIONMULTIPLE:
      // init list box
      listBox_->setSelectionMode(Q3ListBox::Multi);
      stringvec = fullDef2StringVector(parameter_.fullDefault_);
      for (vector<string>::const_iterator i= stringvec.begin(); i!=stringvec.end(); ++i)
	listBox_->insertItem(i->c_str());

      // set current value
      listBox_->clearSelection();
      if (!node_.isNull()) {
	QDomElement e = node_.toElement();
	if (!e.isNull() && e.hasAttribute("value")) {
	  QString tmp1 = e.attribute("value");
	  std::vector<std::string> tmp2 = tokenizer(std::string(tmp1.latin1()));
	  for (std::vector<std::string>::const_iterator i=tmp2.begin(); i!=tmp2.end(); ++i) {
	    for (unsigned int j=0; j!=listBox_->count(); ++j) {
	      if (listBox_->text(j) == QString(i->c_str()))
		listBox_->setSelected(j, TRUE);
	    }
	  }
	}
      } else {
	std::vector<std::string> tmp2 = tokenizer(std::string(parameter_.default_.latin1()));
	for (std::vector<std::string>::const_iterator i=tmp2.begin(); i!=tmp2.end(); ++i) {
	  for (unsigned int j=0; j!=listBox_->count(); ++j) {
	    if (listBox_->text(j) == QString(i->c_str()))
	      listBox_->setSelected(j, TRUE);
	  }
	}
      }

      // connect to function, so we recognize, if value is changed
      connect(listBox_, SIGNAL(selectionChanged()), this, SLOT(listBoxModified()));
      break;

    default:
      break;
    }
  }
Beispiel #26
0
bool Converter::convertTextNode( QTextCursor *cursor, const QDomText &element, const QTextCharFormat &format )
{
  cursor->insertText( element.data(), format );

  return true;
}
Beispiel #27
0
QString getChildText(const QDomElement& element) {
    QDomText text = element.firstChild().toText();
    return text.data();
}
  void
  CameraParameters::operator <<= (const QDomNode& node)
  {
    if (!node.isNull()) {
      QDomNode n1 = node.firstChild();
      while(!n1.isNull() ) {
	if (n1.nodeName() == "ncx") {
	  QDomNode n2 = n1.firstChild();
	  QDomText t = n2.toText(); // try to convert the node to a text
	  if(!t.isNull() ) { // the node was really an element.
	    ncx = t.data().toDouble();
	  }
	}
	else if (n1.nodeName() == "nfx") {
	  QDomNode n2 = n1.firstChild();
	  QDomText t = n2.toText(); // try to convert the node to a text
	  if(!t.isNull() ) { // the node was really an element.
	    nfx = t.data().toDouble();
	  }
	}
	else if (n1.nodeName() == "dx") {
	  QDomNode n2 = n1.firstChild();
	  QDomText t = n2.toText(); // try to convert the node to a text
	  if(!t.isNull() ) { // the node was really an element.
	    dx = t.data().toDouble();
	  }
	}
	else if (n1.nodeName() == "dy") {
	  QDomNode n2 = n1.firstChild();
	  QDomText t = n2.toText(); // try to convert the node to a text
	  if(!t.isNull() ) { // the node was really an element.
	    dy = t.data().toDouble();
	  }
	}
	else if (n1.nodeName() == "cx") {
	  QDomNode n2 = n1.firstChild();
	  QDomText t = n2.toText(); // try to convert the node to a text
	  if(!t.isNull() ) { // the node was really an element.
	    cx = t.data().toDouble();
	  }
	}
	else if (n1.nodeName() == "cy") {
	  QDomNode n2 = n1.firstChild();
	  QDomText t = n2.toText(); // try to convert the node to a text
	  if(!t.isNull() ) { // the node was really an element.
	    cy = t.data().toDouble();
	  }
	}
	else if (n1.nodeName() == "sx") {
	  QDomNode n2 = n1.firstChild();
	  QDomText t = n2.toText(); // try to convert the node to a text
	  if(!t.isNull() ) { // the node was really an element.
	    sx = t.data().toDouble();
	  }
	}
	else if (n1.nodeName() == "f") {
	  QDomNode n2 = n1.firstChild();
	  QDomText t = n2.toText(); // try to convert the node to a text
	  if(!t.isNull() ) { // the node was really an element.
	    f = t.data().toDouble();
	  }
	}
	else if (n1.nodeName() == "kappa") {
	  QDomNode n2 = n1.firstChild();
	  QDomText t = n2.toText(); // try to convert the node to a text
	  if(!t.isNull() ) { // the node was really an element.
	    kappa = t.data().toDouble();
	  }
	}
	else if (n1.nodeName() == "height") {
	  QDomNode n2 = n1.firstChild();
	  QDomText t = n2.toText(); // try to convert the node to a text
	  if(!t.isNull() ) { // the node was really an element.
	    height = t.data().toDouble();
	  }
	}
	else if (n1.nodeName() == "alpha") {
	  QDomNode n2 = n1.firstChild();
	  QDomText t = n2.toText(); // try to convert the node to a text
	  if(!t.isNull() ) { // the node was really an element.
	    alpha = deg2Rad(t.data().toDouble());
	  }
	}
	else if (n1.nodeName() == "latency") {
	  QDomNode n2 = n1.firstChild();
	  QDomText t = n2.toText(); // try to convert the node to a text
	  if(!t.isNull() ) { // the node was really an element.
	    double d = t.data().toDouble();
	    latency.sec((int)floor(d));
	    latency.usec((int)floor((d - floor(d)) * 1000000.));
	  }
	}
	n1 = n1.nextSibling();
      }
    }
  }