Beispiel #1
0
static void
OnFlarmLockClicked()
{
  TeamCodeSettings &settings =
    CommonInterface::SetComputerSettings().team_code;
  TCHAR newTeamFlarmCNTarget[settings.team_flarm_callsign.MAX_SIZE];
  _tcscpy(newTeamFlarmCNTarget, settings.team_flarm_callsign.c_str());

  if (!dlgTextEntryShowModal(newTeamFlarmCNTarget, 4))
    return;

  if (StringIsEmpty(newTeamFlarmCNTarget)) {
    settings.team_flarm_id.Clear();
    settings.team_flarm_callsign.clear();
    return;
  }

  LoadFlarmDatabases();

  FlarmId ids[30];
  unsigned count =
    FlarmDetails::FindIdsByCallSign(newTeamFlarmCNTarget, ids, 30);

  if (count == 0) {
    ShowMessageBox(_("Unknown Competition Number"),
                   _("Not Found"), MB_OK | MB_ICONINFORMATION);
    return;
  }

  const FlarmId id = PickFlarmTraffic(_("Set new teammate"), ids, count);
  if (!id.IsDefined())
    return;

  TeamActions::TrackFlarm(id, newTeamFlarmCNTarget);
}
Beispiel #2
0
  /**
   * Find an existing item by its FLARM id.  This is a simple linear
   * search that doesn't scale well with a large list.
   */
  gcc_pure
  ItemList::iterator FindItem(FlarmId id) {
    assert(id.IsDefined());

    return std::find_if(items.begin(), items.end(),
                        [id](const Item &item) { return item.id == id; });
  }
Beispiel #3
0
void
InputEvents::eventFlarmDetails(gcc_unused const TCHAR *misc)
{
  LoadFlarmDatabases();

  StaticString<4> callsign;
  callsign.clear();
  if (!TextEntryDialog(CommonInterface::main_window, callsign,
                       _("Competition ID")) ||
      callsign.empty())
    return;

  FlarmId ids[30];
  unsigned count = FlarmDetails::FindIdsByCallSign(callsign, ids, 30);

  if (count > 0) {
    FlarmId id = dlgFlarmDetailsListShowModal(
        XCSoarInterface::main_window, _("Show details:"), ids, count);

    if (id.IsDefined())
      dlgFlarmTrafficDetailsShowModal(id);
  } else {
    ShowMessageBox(_("Unknown competition number"),
                _("Not found"), MB_OK | MB_ICONINFORMATION);
  }
}
Beispiel #4
0
bool
FlarmDetails::AddSecondaryItem(FlarmId id, const TCHAR *name)
{
  assert(id.IsDefined());
  assert(traffic_databases != nullptr);

  return traffic_databases->flarm_names.Set(id, name);
}
Beispiel #5
0
void
FlarmDatabase::Insert(const FlarmRecord &record)
{
  FlarmId id = record.GetId();
  if (!id.IsDefined())
    /* ignore malformed records */
    return;

  map.insert(std::make_pair(id, record));
}
Beispiel #6
0
    explicit Item(FlarmId _id)
      :id(_id),
#ifdef HAVE_SKYLINES_TRACKING_HANDLER
       skylines_id(0),
#endif
       color(FlarmColor::COUNT),
       loaded(false),
       location(GeoPoint::Invalid()),
       vector(GeoVector::Invalid()) {
      assert(id.IsDefined());
      assert(IsFlarm());
    }
Beispiel #7
0
/**
 * Checks whether the selection is still on the valid target and if not tries
 * to select the next one
 */
void
FlarmTrafficWindow::UpdateSelector(const FlarmId id, const RasterPoint pt)
{
  // Update #selection
  if (!id.IsDefined())
    SetTarget(-1);
  else
    SetTarget(id);

  // If we don't have a valid selection and we can't find
  // a target close to to the RasterPoint we select the next one
  // on the internal list
  if (selection < 0 && (
      pt.x < 0 || pt.y < 0 ||
      !SelectNearTarget(pt.x, pt.y, radius * 2)) )
    NextTarget();
}
Beispiel #8
0
FlarmId
TrafficDatabases::FindIdByName(const TCHAR *name) const
{
  assert(name != nullptr);
  assert(!StringIsEmpty(name));

  // try to find flarm from userFile
  const FlarmId id = flarm_names.Get(name);
  if (id.IsDefined())
    return id;

  // try to find flarm from FlarmNet.org File
  const FlarmNetRecord *record = flarm_net.FindFirstRecordByCallSign(name);
  if (record != NULL)
    return record->GetId();

  return FlarmId::Undefined();
}
Beispiel #9
0
void
LoadFlarmNameFile(TLineReader &reader, FlarmNameDatabase &db)
{
  TCHAR *line;
  while ((line = reader.ReadLine()) != NULL) {
    TCHAR *endptr;
    FlarmId id = FlarmId::Parse(line, &endptr);
    if (!id.IsDefined())
      /* ignore malformed records */
      continue;

    if (endptr > line && endptr[0] == _T('=') && endptr[1] != _T('\0')) {
      TCHAR *Name = endptr + 1;
      TrimRight(Name);
      if (!db.Set(id, Name))
        break; // cant add anymore items !
    }
  }
}
Beispiel #10
0
FlarmId
TrafficDatabases::FindIdByName(const TCHAR *name) const
{
#if !CLANG_CHECK_VERSION(3,6)
  /* disabled on clang due to -Wtautological-pointer-compare */
  assert(name != nullptr);
#endif
  assert(!StringIsEmpty(name));

  // try to find flarm from userFile
  const FlarmId id = flarm_names.Get(name);
  if (id.IsDefined())
    return id;

  // try to find flarm from FlarmNet.org File
  const FlarmNetRecord *record = flarm_net.FindFirstRecordByCallSign(name);
  if (record != NULL)
    return record->GetId();

  return FlarmId::Undefined();
}
Beispiel #11
0
static void
LoadColor(FlarmColorDatabase &db, const char *key, FlarmColor color)
{
  const char *ids = Profile::Get(key);
  if (ids == nullptr)
    return;

  const char *p = ids;
  while (true) {
    char *endptr;
    FlarmId id = FlarmId::Parse(p, &endptr);
    if (id.IsDefined())
      db.Set(id, color);

    p = strchr(endptr, ',');
    if (p == nullptr)
      break;

    ++p;
  }
}
Beispiel #12
0
void
FlarmFriends::LoadColor(const TCHAR *key, Color color)
{
  const TCHAR *ids = Profile::Get(key);
  if (ids == NULL || StringIsEmpty(ids))
    return;

  FlarmId id;
  TCHAR *endptr;

  const TCHAR *p = ids;
  while (p != NULL && *p) {
    id = FlarmId::Parse(p, &endptr);

    if (id.IsDefined()) {
      SetFriendColor(id, color);
      id.Clear();
    }

    p = _tcschr(endptr, _T(','));
    if (p != NULL)
      p++;
  }
}
Beispiel #13
0
 /**
  * Does this object describe a FLARM?
  */
 bool IsFlarm() const {
   return id.IsDefined();
 }