void QmlProfilerDetailsRewriter::rewriteDetailsForLocation(QTextStream &textDoc,
        QmlJS::Document::Ptr doc, int requestId, const QmlDebug::QmlEventLocation &location)
{
    PropertyVisitor propertyVisitor;
    QmlJS::AST::Node *node = propertyVisitor(doc->ast(), location.line, location.column);

    if (!node)
        return;

    qint64 startPos = node->firstSourceLocation().begin();
    qint64 len = node->lastSourceLocation().end() - startPos;

    textDoc.seek(startPos);
    QString details = textDoc.read(len).replace(QLatin1Char('\n'), QLatin1Char(' ')).simplified();

    emit rewriteDetailsString(requestId, details);
}
Esempio n. 2
0
// ---------------------------------------------------
bool TextDoc::load ()
{
  
  QFile file (DocName);
  if (!file.open (QIODevice::ReadOnly))
    return false;
  setLanguage (DocName);

  QTextStream stream (&file);
  setText (stream.read ());
  setModified (false);
  slotSetChanged ();
  file.close ();
  lastSaved = QDateTime::currentDateTime ();
  loadSettings ();
  SimOpenDpl = simulation ? true : false;
  return true;
}
Esempio n. 3
0
FLTableMetaData *FLManager::createSystemTable(const QString &n)
{
#ifndef FL_QUICK_CLIENT
  if (!existsTable(n)) {
    QDomDocument doc(n);
    QDomElement docElem;
    QFile fi(AQ_DATA +
             QString::fromLatin1("/tables/") + n +
             QString::fromLatin1(".mtd"));
    if (!fi.open(IO_ReadOnly)) {
#ifdef FL_DEBUG
      qWarning("FLManager : " + QApplication::tr("Los metadatos para %1 no están definidos").arg(n));
#endif
    } else {
      QTextStream t;
      t.setDevice(&fi);
      t.setEncoding(QTextStream::Latin1);
      QString stream = t.read();

      if (!FLUtil::domDocumentSetContent(doc, stream)) {
#ifdef FL_DEBUG
        qWarning("FLManager::createSystemTable : " + QApplication::tr("Error al cargar los metadatos para la tabla %1").arg(n));
#endif

        return 0;
      } else {
        docElem = doc.documentElement();
        FLTableMetaData *mtd = createTable(metadata(&docElem, true));
        return mtd;
      }
    }
    fi.close();
  }

  return 0;
#else

  return metadata(n, true);
#endif //FL_QUICK_CLIENT
}
Esempio n. 4
0
bool CSVParser::parse(QTextStream& stream, qint64 nMaxRecords)
{
    m_vCSVData.clear();
    m_nColumns = 0;
    ParseStates state = StateNormal;
    QString fieldbuf;
    QStringList record;

    if(m_pCSVProgress)
        m_pCSVProgress->start();

    while(!stream.atEnd())
    {
        QString sBuffer = stream.read(m_nBufferSize);

        for(QString::iterator it = sBuffer.begin(); it != sBuffer.end(); ++it)
        {
            QChar c = *it;
            switch(state)
            {
            case StateNormal:
            {
                if(c == m_cFieldSeparator)
                {
                    addColumn(record, fieldbuf, m_bTrimFields);
                }
                else if(c == m_cQuoteChar)
                {
                    state = StateInQuote;
                }
                else if(c == '\r')
                {
                    // look ahead to check for linefeed
                    QString::iterator nit = it + 1;

                    // In order to check what the next byte is we must make sure that that byte is already loaded. Assume we're at an m_nBufferSize
                    // boundary but not at the end of the file when we hit a \r character. Now we're going to be at the end of the sBuffer string
                    // because of the m_nBufferSize boundary. But this means that the following check won't work properly because we can't check the
                    // next byte when we really should be able to do so because there's more data coming. To fix this we'll check for this particular
                    // case and, if this is what's happening, we'll just load an extra byte.
                    if(nit == sBuffer.end() && !stream.atEnd())
                    {
                        // Load one more byte
                        sBuffer.append(stream.read(1));

                        // Restore both iterators. sBuffer.end() points to the imagined char after the last one in the string. So the extra byte we've
                        // just loaded is the one before that, i.e. the actual last one, and the original last char is the one before that.
                        it = sBuffer.end() - 2;
                        nit = sBuffer.end() - 1;
                    }

                    // no linefeed, so assume that CR represents a newline
                    if(nit != sBuffer.end() && *nit != '\n')
                    {
                        addColumn(record, fieldbuf, m_bTrimFields);

                        addRow(record);
                    }
                }
                else if(c == '\n')
                {
                    addColumn(record, fieldbuf, m_bTrimFields);

                    addRow(record);
                }
                else
                {
                    fieldbuf.append(c);
                }
            }
            break;
            case StateInQuote:
            {
                if(c == m_cQuoteChar)
                {
                    state = StateEndQuote;
                }
                else
                {
                    fieldbuf.append(c);
                }
            }
            break;
            case StateEndQuote:
            {
                if(c == m_cQuoteChar)
                {
                    state = StateInQuote;
                    fieldbuf.append(c);
                }
                else if(c == m_cFieldSeparator)
                {
                    state = StateNormal;
                    addColumn(record, fieldbuf, m_bTrimFields);
                }
                else if(c == '\n')
                {
                    state = StateNormal;
                    addColumn(record, fieldbuf, m_bTrimFields);

                    addRow(record);
                }
                else if(c == '\r')
                {
                    // look ahead to check for linefeed
                    QString::iterator nit = it + 1;

                    // See above for details on this.
                    if(nit == sBuffer.end() && !stream.atEnd())
                    {
                        sBuffer.append(stream.read(1));
                        it = sBuffer.end() - 2;
                        nit = sBuffer.end() - 1;
                    }

                    // no linefeed, so assume that CR represents a newline
                    if(nit != sBuffer.end() && *nit != '\n')
                    {
                        addColumn(record, fieldbuf, m_bTrimFields);

                        addRow(record);
                    }
                }
                else
                {
                    state = StateNormal;
                    fieldbuf.append(c);
                }
            }
            break;
            }

            if(nMaxRecords != -1 && m_vCSVData.size() >= nMaxRecords)
                return true;
        }

        if(m_pCSVProgress && m_vCSVData.size() % 100 == 0)
        {
            if(!m_pCSVProgress->update(stream.pos()))
                return false;
        }
    }

    if(!record.isEmpty())
    {
        addColumn(record, fieldbuf, m_bTrimFields);

        addRow(record);
    }

    if(m_pCSVProgress)
        m_pCSVProgress->end();

    return state == StateNormal;
}
Esempio n. 5
0
void
CollectionScanner::doJob() //SLOT
{
    std::cout << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
    std::cout << "<scanner>";


    QStringList entries;

    if( m_restart ) {
        QFile logFile( m_logfile );
        QString lastFile;
        if ( !logFile.open( IO_ReadOnly ) )
            warning() << "Failed to open log file " << logFile.name() << " read-only"
            << endl;
        else {
            QTextStream logStream;
            logStream.setDevice(&logFile);
            logStream.setEncoding(QTextStream::UnicodeUTF8);
            lastFile = logStream.read();
            logFile.close();
        }

        QFile folderFile( Amarok::saveLocation( QString::null ) + "collection_scan.files"   );
        if ( !folderFile.open( IO_ReadOnly ) )
            warning() << "Failed to open folder file " << folderFile.name()
            << " read-only" << endl;
        else {
            QTextStream folderStream;
            folderStream.setDevice(&folderFile);
            folderStream.setEncoding(QTextStream::UnicodeUTF8);
            entries = QStringList::split( "\n", folderStream.read() );
        }

        for( int count = entries.findIndex( lastFile ) + 1; count; --count )
            entries.pop_front();

    }
    else {
        foreachType( QStringList, m_folders ) {
            if( (*it).isEmpty() )
                //apparently somewhere empty strings get into the mix
                //which results in a full-system scan! Which we can't allow
                continue;

            QString dir = *it;
            if( !dir.endsWith( "/" ) )
                dir += '/';

            readDir( dir, entries );
        }

        QFile folderFile( Amarok::saveLocation( QString::null ) + "collection_scan.files"   );
        if ( !folderFile.open( IO_WriteOnly ) )
            warning() << "Failed to open folder file " << folderFile.name()
            << " read-only" << endl;
        else {
            QTextStream stream( &folderFile );
            stream.setEncoding(QTextStream::UnicodeUTF8);
            stream << entries.join( "\n" );
            folderFile.close();
        }
    }

    if( !entries.isEmpty() ) {
        if( !m_restart ) {
            AttributeMap attributes;
            attributes["count"] = QString::number( entries.count() );
            writeElement( "itemcount", attributes );
        }

        scanFiles( entries );
    }

    std::cout << "</scanner>" << std::endl;

    quit();
}
Esempio n. 6
0
/*
 * Make use of the advanced apm interface of the ipaq
 */
bool BatteryStatus::getProcApmStatusIpaq() {

    bat2 = false;

    QFile procApmIpaq("/proc/hal/battery");

    if (procApmIpaq.open(IO_ReadOnly) ) {
        QStringList list;
        // since it is /proc we _must_ use QTextStream
        QTextStream stream ( &procApmIpaq);
        QString streamIn;
        streamIn = stream.read();
        list = QStringList::split("\n", streamIn);

        sec2 = sec1 = "";

        for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) {
            // not nice, need a rewrite later
            if( (*line).startsWith(" Percentage") ) {
                if (bat2 == true) {
                    perc2 = (*line).mid(((*line).find('(')) +1,(*line).find(')')-(*line).find('(')-2);
                } else {
                    perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2);
                }
            } else if( (*line).startsWith(" Life") ) {
                if (bat2 == true) {
                    sec2 = (*line).mid(((*line).find(':')+2), 5 );
                } else {
                    sec1 = (*line).mid(((*line).find(':')+2), 5 );
                }
            } else if( (*line).startsWith("Battery #1") ) {
                bat2 = true;
            } else if( (*line).startsWith(" Status") ) {
                if (bat2 == true) {
                    jackStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1);
                } else {
                    ipaqStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1);
                }
            } else if( (*line).startsWith(" Chemistry") ) {
                if (bat2 == true) {
                    jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
                } else {
                    ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
                }
            }
        }
	procApmIpaq.close();
    }

    jackPercent = perc2.toInt();
    ipaqPercent = perc1.toInt();

    if (perc2.isEmpty() || perc2 == "unknown" ) {
        perc2 = tr("no data");
    } else {
        perc2 += " %";
    }

    if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) {
        sec2 = tr("no data");
    } else {
        sec2 += " min";
    }

    jackStatus.prepend( " ( " );
    jackStatus.append( " )" );
    return true;
}