예제 #1
0
void SessionListWidget::parseQstat(QString const& qstat)
{
   QStringList lines = qstat.split('\n');

   JobDefinition *job = NULL;
   QMap<QString, QString> jobSpec, jobVars;

   QRegExp rxJobId("[0-9]+\\.pbs01");
   QRegExp rxKey("[A-Za-z_\\.]+");
   QString key(""), value("");
   for(QStringList::const_iterator line = lines.begin();
       line != lines.end();
       line++)
   {
      if(line->isEmpty()) { /* empty */ }
      else if(line->startsWith("Job Id:")) {
         if(job != NULL) {
            job->update(jobSpec);
            sessions.append(*job);
            delete job;
            job = NULL;
            jobSpec.clear();
            jobVars.clear();
         }
         rxJobId.indexIn(*line);
         job = new JobDefinition(rxJobId.cap());
      }
      else if(line->startsWith("    ")) {  /* keys start with 4 spaces */
         if(key == "Variable_List") {
            QStringList vars(jobSpec[key].split(","));
            for(QStringList::const_iterator i = vars.begin();
                i != vars.end(); 
                i++)
            {
               int eq = i->indexOf('=');
               jobVars.insert(i->left(eq), i->mid(eq + 1));
            }
         }
         rxKey.indexIn(*line);
         key = rxKey.cap(0);
         value = line->mid(line->indexOf('=') + 2);
         jobSpec.insert(key, value);
      }
      else if(line->at(0) == '\t') {
         /* append to the previous key */
         jobSpec[key].append(line->mid(1));
      }
   }
   if(job) {
      job->update(jobSpec);
      sessions.append(*job);
   }

   qDebug() << sessions;
}
void MakefileFactory::setEnvironment(const QStringList &env)
{
    for (QStringList::const_iterator it = env.begin(); it != env.end(); ++it) {
        int idx = it->indexOf(QLatin1Char('='));
        if (idx >= 0)
            m_environment.insert(it->left(idx), it->mid(idx + 1));
    }
}
예제 #3
0
bool MercurialPlugin::parseStatus(DVcsJob *job) const
{
    if (job->status() != VcsJob::JobSucceeded) {
        mercurialDebug() << "Job failed: " << job->output();
        return false;
    }

    const QString dir = job->directory().absolutePath().append(QDir::separator());
    mercurialDebug() << "Job succeeded for " << dir;
    const QStringList output = job->output().split('\n', QString::SkipEmptyParts);
    QList<QVariant> filestatus;

    QSet<QUrl> conflictedFiles;

    QStringList::const_iterator it = output.constBegin();

    // FIXME: Revive this functionality and add tests for it!
    // conflicts first
//     for (; it != output.constEnd(); it++) {
//         QChar stCh = it->at(0);
//         if (stCh == '%') {
//             it++;
//             break;
//         }
// 
//         QUrl file = QUrl::fromLocalFile(it->mid(2).prepend(dir));
// 
//         VcsStatusInfo status;
//         status.setUrl(file);
//         // FIXME: conflicts resolved
//         status.setState(VcsStatusInfo::ItemHasConflicts);
// 
//         conflictedFiles.insert(file);
//         filestatus.append(qVariantFromValue(status));
//     }

    // standard statuses next
    for (; it != output.constEnd(); it++) {
        QChar stCh = it->at(0);

        QUrl file = QUrl::fromLocalFile(it->mid(2).prepend(dir));

        if (!conflictedFiles.contains(file)) {
            VcsStatusInfo status;
            status.setUrl(file);
            status.setState(charToState(stCh.toLatin1()));
            filestatus.append(qVariantFromValue(status));
        }
    }

    job->setResults(qVariantFromValue(filestatus));
    return true;
}
/*!
    Searches the arguments for the key specified by \a key. If it can find the
    key, it returns the value set for it. Otherwise, it returns \a defaultValue.
    Arguments are specified in the following form: \c{key=value}.
*/
QString UpdateOperation::argumentKeyValue(const QString &key, const QString &defaultValue) const
{
    const QString keySeparater(key + QLatin1String("="));
    const QStringList tArguments(arguments());
    QStringList::const_iterator it = std::find_if(tArguments.begin(), tArguments.end(),
        StartsWith(keySeparater));
    if (it == tArguments.end())
        return defaultValue;

    const QString value = it->mid(keySeparater.size());

    it = std::find_if(++it, tArguments.end(), StartsWith(keySeparater));
    if (it != tArguments.end()) {
        qWarning() << QString::fromLatin1("There are multiple keys in the arguments calling"
            " \"%1\". Only the first found \"%2\" is used: \"%3\"").arg(name(), key, arguments().join(
            QLatin1String("; ")));
    }
    return value;
}
void BackendGoogleMaps::slotHTMLEvents(const QStringList& events)
{
    // for some events, we just note that they appeared and then process them later on:
    bool centerProbablyChanged    = false;
    bool mapTypeChanged           = false;
    bool zoomProbablyChanged      = false;
    bool mapBoundsProbablyChanged = false;
    QIntList movedClusters;
    QList<QPersistentModelIndex> movedMarkers;
    QIntList clickedClusters;

    // TODO: verify that the order of the events is still okay
    //       or that the order does not matter
    for (QStringList::const_iterator it = events.constBegin(); it != events.constEnd(); ++it)
    {
        const QString eventCode           = it->left(2);
        const QString eventParameter      = it->mid(2);
        const QStringList eventParameters = eventParameter.split(QLatin1Char( '/' ));

        if (eventCode == QLatin1String("MT"))
        {
            // map type changed
            mapTypeChanged  = true;
            d->cacheMapType = eventParameter;
        }
        else if (eventCode == QLatin1String("MB"))
        {   // NOTE: event currently disabled in javascript part
            // map bounds changed
            centerProbablyChanged    = true;
            zoomProbablyChanged      = true;
            mapBoundsProbablyChanged = true;
        }
        else if (eventCode == QLatin1String("ZC"))
        {   // NOTE: event currently disabled in javascript part
            // zoom changed
            zoomProbablyChanged      = true;
            mapBoundsProbablyChanged = true;
        }
        else if (eventCode == QLatin1String("id"))
        {
            // idle after drastic map changes
            centerProbablyChanged    = true;
            zoomProbablyChanged      = true;
            mapBoundsProbablyChanged = true;
        }
        else if (eventCode == QLatin1String("cm"))
        {
            /// @todo buffer this event type!
            // cluster moved
            bool okay              = false;
            const int clusterIndex = eventParameter.toInt(&okay);
            KGEOMAP_ASSERT(okay);

            if (!okay)
                continue;

            KGEOMAP_ASSERT(clusterIndex >= 0);
            KGEOMAP_ASSERT(clusterIndex<s->clusterList.size());

            if ((clusterIndex<0)||(clusterIndex>s->clusterList.size()))
                continue;

            // re-read the marker position:
            GeoCoordinates clusterCoordinates;
            const bool isValid = d->htmlWidget->runScript2Coordinates(
                    QString::fromLatin1("kgeomapGetClusterPosition(%1);").arg(clusterIndex),
                    &clusterCoordinates
                );

            KGEOMAP_ASSERT(isValid);

            if (!isValid)
                continue;

            /// @todo this discards the altitude!
            /// @todo is this really necessary? clusters should be regenerated anyway...
            s->clusterList[clusterIndex].coordinates = clusterCoordinates;

            movedClusters << clusterIndex;
        }
        else if (eventCode == QLatin1String("cs"))
        {
            /// @todo buffer this event type!
            // cluster snapped
            bool okay = false;
            const int clusterIndex = eventParameters.first().toInt(&okay);
            KGEOMAP_ASSERT(okay);

            if (!okay)
                continue;

            KGEOMAP_ASSERT(clusterIndex >= 0);
            KGEOMAP_ASSERT(clusterIndex<s->clusterList.size());

            if ((clusterIndex<0)||(clusterIndex>s->clusterList.size()))
                continue;

            // determine to which marker we snapped:
            okay                  = false;
            const int snapModelId = eventParameters.at(1).toInt(&okay);
            KGEOMAP_ASSERT(okay);

            if (!okay)
                continue;

            okay                   = false;
            const int snapMarkerId = eventParameters.at(2).toInt(&okay);
            KGEOMAP_ASSERT(okay);

            if (!okay)
                continue;

            /// @todo emit signal here or later?
            ModelHelper* const modelHelper  = s->ungroupedModels.at(snapModelId);
            QAbstractItemModel* const model = modelHelper->model();
            QPair<int, QModelIndex> snapTargetIndex(snapModelId, model->index(snapMarkerId, 0));
            emit(signalClustersMoved(QIntList()<<clusterIndex, snapTargetIndex));
        }
        else if (eventCode == QLatin1String("cc"))
        {
            /// @todo buffer this event type!
            // cluster clicked
            bool okay              = false;
            const int clusterIndex = eventParameter.toInt(&okay);
            KGEOMAP_ASSERT(okay);

            if (!okay)
                continue;

            KGEOMAP_ASSERT(clusterIndex>=0);
            KGEOMAP_ASSERT(clusterIndex<s->clusterList.size());

            if ((clusterIndex<0)||(clusterIndex>s->clusterList.size()))
                continue;

            clickedClusters << clusterIndex;
        }
        else if (eventCode == QLatin1String("mm"))
        {
//             // TODO: buffer this event type!
//             // marker moved
//             bool okay           = false;
//             const int markerRow = eventParameter.toInt(&okay);
//             KGEOMAP_ASSERT(okay);
//
//             if (!okay)
//                 continue;
//
//             KGEOMAP_ASSERT(markerRow >= 0);
//             KGEOMAP_ASSERT(markerRow<s->specialMarkersModel->rowCount());
//
//             if ((markerRow<0)||(markerRow>=s->specialMarkersModel->rowCount()))
//                 continue;
//
//             // re-read the marker position:
//             GeoCoordinates markerCoordinates;
//             const bool isValid = d->htmlWidget->runScript2Coordinates(
//                     QString::fromLatin1("kgeomapGetMarkerPosition(%1);").arg(markerRow),
//                     &markerCoordinates
//                 );
//
//             KGEOMAP_ASSERT(isValid);
//
//             if (!isValid)
//                 continue;
//
//             // TODO: this discards the altitude!
//             const QModelIndex markerIndex = s->specialMarkersModel->index(markerRow, 0);
//             s->specialMarkersModel->setData(markerIndex, QVariant::fromValue(markerCoordinates), s->specialMarkersCoordinatesRole);
//
//             movedMarkers << QPersistentModelIndex(markerIndex);
        }
        else if (eventCode == QLatin1String("do"))
        {
            // debug output:
            kDebug() << QString::fromLatin1("javascript:%1").arg(eventParameter);
        }
    }

    if (!movedClusters.isEmpty())
    {
        kDebug()<<movedClusters;
        emit(signalClustersMoved(movedClusters, QPair<int, QModelIndex>(-1, QModelIndex())));
    }

    if (!movedMarkers.isEmpty())
    {
        kDebug()<<movedMarkers;
//         emit(signalSpecialMarkersMoved(movedMarkers));
    }

    if (!clickedClusters.isEmpty())
    {
        kDebug()<<clickedClusters;
        emit(signalClustersClicked(clickedClusters));
    }

    // now process the buffered events:
    if (mapTypeChanged)
    {
        updateZoomMinMaxCache();
    }

    if (zoomProbablyChanged)
    {
        d->cacheZoom = d->htmlWidget->runScript(QLatin1String("kgeomapGetZoom();")).toInt();
        emit(signalZoomChanged(QString::fromLatin1("googlemaps:%1").arg(d->cacheZoom)));
    }

    if (centerProbablyChanged)
    {
        // there is nothing we can do if the coordinates are invalid
        /*const bool isValid = */d->htmlWidget->runScript2Coordinates(QLatin1String("kgeomapGetCenter();"), &(d->cacheCenter));
    }

    // update the actions if necessary:
    if (zoomProbablyChanged || mapTypeChanged || centerProbablyChanged)
    {
        updateActionAvailability();
    }

    if (mapBoundsProbablyChanged)
    {
        const QString mapBoundsString = d->htmlWidget->runScript(QLatin1String("kgeomapGetBounds();")).toString();
        KGeoMapHelperParseBoundsString(mapBoundsString, &d->cacheBounds);
    }

    if (mapBoundsProbablyChanged||!movedClusters.isEmpty())
    {
        s->worldMapWidget->markClustersAsDirty();
        s->worldMapWidget->updateClusters();
    }
}
예제 #6
0
bool CliParser::init(const QStringList &args) {
    argsRaw = args;
    QStringList::const_iterator currentArg;
    for (currentArg = argsRaw.constBegin(); currentArg != argsRaw.constEnd(); ++currentArg) {
        if(currentArg->startsWith("--")) {
            // long
            QString name;
            if(currentArg->contains("=")) {
                // option
                QStringList tmp = currentArg->mid(2).split("=");
                name = tmp.at(0);
                QString value;
                // this is needed to allow --option=""
                if(tmp.at(1).isNull()) value = QString("");
                else value = tmp.at(1);
                if(!addLongArg(CliParserArg::CliArgOption, name, value)) return false;
            }
            else {
                // switch
                name = currentArg->mid(2);
                if(!addLongArg(CliParserArg::CliArgSwitch, name)) return false;
            }
        }
        else if(currentArg->startsWith("-")) {
            // short
            char name;
            QStringList::const_iterator nextArg = currentArg+1;
            // if next arg is a short/long option/switch the current arg is one too
            if(nextArg == argsRaw.constEnd() || nextArg->startsWith("-")) {
                // switch
                for (int i = 0; i < currentArg->mid(1).toAscii().size(); i++) {
                    name = currentArg->mid(1).toAscii().at(i);
                    if(!addShortArg(CliParserArg::CliArgSwitch, name)) return false;
                }
            }
            // if next arg is is no option/switch it's an argument to a shortoption
            else {
                // option
                // short options are not freely mixable with other shortargs
                if(currentArg->mid(1).toAscii().size() > 1) {
                    qWarning() << "Warning: Shortoptions may not be combined with other shortoptions or switches";
                    return false;
                }
                QString value;
                bool skipNext = false;
                if(nextArg != argsRaw.constEnd()) {
                    value = nextArg->toLocal8Bit();
                    skipNext = true;
                }
                else value = currentArg->toLocal8Bit();
                name = currentArg->mid(1).toAscii().at(0);
                // we took one argument as argument to an option so skip it next time
                if(skipNext) currentArg++;
                if(!addShortArg(CliParserArg::CliArgOption, name, value)) return false;
            }
        }
        else {
            // we don't support plain arguments without -/--
            if(currentArg->toLatin1() != argsRaw.at(0)) return false;
        }
    }
    return true;
}
예제 #7
0
void BackendOSM::slotHTMLEvents(const QStringList& events)
{
    // for some events, we just note that they appeared and then process them later on:
    bool centerProbablyChanged    = false;
    bool mapTypeChanged           = false;
    bool zoomProbablyChanged      = false;
    bool mapBoundsProbablyChanged = false;
    QIntList movedClusters;
    QList<QPersistentModelIndex> movedMarkers;

    for (QStringList::const_iterator it = events.constBegin(); it != events.constEnd(); ++it)
    {
        const QString eventCode           = it->left(2);
        const QString eventParameter      = it->mid(2);
        const QStringList eventParameters = eventParameter.split(QLatin1Char( '/' ));

        if (eventCode == "MB")
        {   // NOTE: event currently disabled in javascript part
            // map bounds changed
            centerProbablyChanged    = true;
            zoomProbablyChanged      = true;
            mapBoundsProbablyChanged = true;
        }
        else if (eventCode == "ZC")
        {   // NOTE: event currently disabled in javascript part
            // zoom changed
            zoomProbablyChanged      = true;
            mapBoundsProbablyChanged = true;
        }
        else if (eventCode == "id")
        {
            // idle after drastic map changes
            centerProbablyChanged    = true;
            zoomProbablyChanged      = true;
            mapBoundsProbablyChanged = true;
        }
        else if (eventCode == "cm")
        {
            // TODO: buffer this event type!
            // cluster moved
            bool okay              = false;
            const int clusterIndex = eventParameter.toInt(&okay);

            if (!okay)
                continue;

            if ((clusterIndex < 0) || (clusterIndex > s->clusterList.size()))
                continue;

            // re-read the marker position:
            GeoCoordinates clusterCoordinates;
            const bool isValid = d->htmlWidget->runScript2Coordinates(
                                     QString::fromLatin1("kgeomapGetClusterPosition(%1);").arg(clusterIndex),
                                     &clusterCoordinates);

            if (!isValid)
                continue;

            // TODO: this discards the altitude!
            s->clusterList[clusterIndex].coordinates = clusterCoordinates;

            movedClusters << clusterIndex;
        }
        else if (eventCode == "mm")
        {
            // TODO: buffer this event type!
            // marker moved
            bool okay           = false;
            const int markerRow = eventParameter.toInt(&okay);

            if (!okay)
                continue;

            if ((markerRow < 0) || (markerRow > s->specialMarkersModel->rowCount()))
                continue;

            // re-read the marker position:
            GeoCoordinates markerCoordinates;
            const bool isValid = d->htmlWidget->runScript2Coordinates(
                                     QString::fromLatin1("kgeomapGetMarkerPosition(%1);").arg(markerRow),
                                     &markerCoordinates
                                 );

            if (!isValid)
                continue;

            // TODO: this discards the altitude!
            const QModelIndex markerIndex = s->specialMarkersModel->index(markerRow, 0);
            s->specialMarkersModel->setData(markerIndex, QVariant::fromValue(markerCoordinates), s->specialMarkersCoordinatesRole);

            movedMarkers << QPersistentModelIndex(markerIndex);
        }
        else if (eventCode == "do")
        {
            // debug output:
            qCDebug(LIBKGEOMAP_LOG)<<QString::fromLatin1("javascript:%1").arg(eventParameter);
        }
    }

    if (!movedClusters.isEmpty())
    {
        qCDebug(LIBKGEOMAP_LOG) << movedClusters;
        emit(signalClustersMoved(movedClusters));
    }

    if (!movedMarkers.isEmpty())
    {
        qCDebug(LIBKGEOMAP_LOG) << movedMarkers;
        emit(signalSpecialMarkersMoved(movedMarkers));
    }

    // now process the buffered events:
    if (zoomProbablyChanged)
    {
        d->cacheZoom = d->htmlWidget->runScript(QLatin1String("kgeomapGetZoom();")).toInt();

        emit(signalZoomChanged(QString::fromLatin1("googlemaps:%1").arg(d->cacheZoom)));
    }
    if (centerProbablyChanged)
    {
        // there is nothing we can do if the coordinates are invalid
        /*const bool isValid = */d->htmlWidget->runScript2Coordinates("kgeomapGetCenter();", &(d->cacheCenter));
    }

    // update the actions if necessary:
    if (zoomProbablyChanged || mapTypeChanged || centerProbablyChanged)
    {
        updateActionsEnabled();
    }

    if (mapBoundsProbablyChanged)
    {
        const QString mapBoundsString = d->htmlWidget->runScript("kgeomapGetBounds();").toString();
        KGeoMapHelperParseBoundsString(mapBoundsString, &d->cacheBounds);
    }

    if (mapBoundsProbablyChanged || !movedClusters.isEmpty())
    {
        s->worldMapWidget->updateClusters();
    }
}