Example #1
0
void
StationsPluginLondon::handleInfos(const QByteArray & data)
{
  QRegExp re_stations("station\\=\\{(.*)\\}\\;");
  QRegExp re_items("\\s*(\\w+)\\s*:(.*),");
  int ofs = 0;

  re_stations.setMinimal(true);
  re_items.setMinimal(true);

  while ((ofs = re_stations.indexIn(data, ofs)) >= 0) {
    bool ok;
    int id;
    QPointF pos;
    Station *station;
    QMap<QString, QString> values;

    ofs += re_stations.matchedLength();

    int station_ofs = 0;
    QString station_data = re_stations.capturedTexts().at(1);

    while ((station_ofs = re_items.indexIn(station_data, station_ofs)) >= 0) {
      QStringList capt = re_items.capturedTexts();

      if (capt.size() < 3)
	continue ;

      station_ofs += re_items.matchedLength();
      values[capt.at(1)] = capt.at(2);
      values[capt.at(1)].replace("\"", "");
    }

    id = values["id"].toInt(&ok);
    pos = QPointF(values["lat"].toDouble(),
		  values["long"].toDouble());

    if (!ok)
      continue ;

    station = getOrCreateStation(id);

    if (station->name().isEmpty())
      station->setName(values["name"]);
    if (station->pos().isNull())
      station->setPos(pos);
    station->setBikes(values["nbBikes"].toInt());
    station->setFreeSlots(values["nbEmptyDocks"].toInt());
    station->setTotalSlots(station->bikes() + station->freeSlots());

    storeOrDropStation(station);
  }

  emit stationsCreated(stations.values());
  emit stationsUpdated(stations.values());
}
Example #2
0
void
StationsPluginWien::handleInfos(const QByteArray & data)
{
  QDomDocument doc;
  QDomNode node;

  doc.setContent(data);
  node = doc.firstChildElement("stations").firstChildElement("station");

  while (!node.isNull()) {
    Station *station;
    QDomNamedNodeMap attrs = node.attributes();
    int id;
    bool ok;
    qreal lat, lng;

    id = node.firstChildElement("id").text().toInt(&ok);

    if (!ok)
      continue ;

    station = getOrCreateStation(id);

    station->setData(node.firstChildElement("internal_id").text().toInt());

    if (station->name().isEmpty())
      station->setName(node.firstChildElement("name").text());
    if (station->description().isEmpty())
      station->setDescription(node.firstChildElement("description").text());

    lng = node.firstChildElement("longitude").text().toDouble();
    lat = node.firstChildElement("latitude").text().toDouble();

    if (station->pos().isNull())
      station->setPos(QPointF(lat, lng));

    station->setBikes(node.firstChildElement("free_bikes").text().toInt());
    station->setFreeSlots(node.firstChildElement("free_boxes").text().toInt());
    station->setTotalSlots(node.firstChildElement("boxes").text().toInt());

    storeOrDropStation(station);

    node = node.nextSiblingElement("station");
  }

  emit stationsCreated(stations.values());
  emit stationsUpdated(stations.values());
}
Example #3
0
QList<Station>
LastFmUserSettings::recentStations()
{
    MyQSettings s( this );

    s.beginGroup( "RecentStations" );
    QStringList const keys = s.childKeys();
    s.endGroup();

    QMap<int, Station> stations;
    foreach (QString key, keys) {
        Station station;
        station.setUrl( s.value( "RecentStations/" + key ).toString() );
        station.setName( s.value( "StationNames/" + station.url() ).toString() );
        stations[key.toInt()] = station;
    }
Example #4
0
Station* StationsReader::readStation()
{
    // Process the attributes
    if (! mReader.attributes().hasAttribute("id"))
        mReader.raiseError("station without id");
    QString tGuid = mReader.attributes().value("id").toString();
    Location tLocation;
    if (mReader.attributes().hasAttribute("location"))
    {
        QStringRef tLocationString = mReader.attributes().value("location");

        int tSeparator = tLocationString.toString().indexOf(" ");

        // TODO: when Qt 4.8 gets released, QStringRef
        //       will natively implement these
        //       convenience functionality
        //       http://qt.gitorious.org/qt/qt/merge_requests/625
        qreal tLongitude = tLocationString.toString().midRef(0, tSeparator).toString().toDouble();
        qreal tLatitude = tLocationString.toString().midRef(tSeparator+1).toString().toDouble();
        tLocation.setLongitude(tLongitude);
        tLocation.setLatitude(tLatitude);
    }

    // Process the contents
    QString tName = capitalize(mReader.readElementText());
    if (mReader.isEndElement())
        mReader.readNext();

    // Construct the object
    Station::Id tId;
    tId.guid = tGuid;
    Station* oStation = new Station(tId);
    oStation->setName(tName);
    oStation->setLocation(tLocation);
    return oStation;
}