Ejemplo n.º 1
0
/**
 * Updates all the dialogs fields.
 * Should be called on dialog opening as it closes the dialog when the
 * target does not exist.
 */
static void
Update()
{
  TCHAR tmp[200], tmp_id[7];

  // Set the dialog caption
  _stprintf(tmp, _T("%s (%s)"),
            _("FLARM Traffic Details"), target_id.Format(tmp_id));
  wf->SetCaption(tmp);

  // Try to find the target in the FLARMnet database
  /// @todo: make this code a little more usable
  const FlarmRecord *record = FlarmDetails::LookupRecord(target_id);
  if (record) {
    // Fill the pilot name field
    SetFormValue(*wf, _T("prpPilot"), record->pilot);

    // Fill the frequency field
    if (!StringIsEmpty(record->frequency)) {
      _tcscpy(tmp, record->frequency);
      _tcscat(tmp, _T(" MHz"));
      SetFormValue(*wf, _T("prpFrequency"), tmp);
    } else
      SetFormValue(*wf, _T("prpFrequency"), _T("--"));

    // Fill the home airfield field
    SetFormValue(*wf, _T("prpAirport"), record->airfield);

    // Fill the plane type field
    SetFormValue(*wf, _T("prpPlaneType"), record->plane_type);
  } else {
    // Fill the pilot name field
    SetFormValue(*wf, _T("prpPilot"), _T("--"));

    // Fill the frequency field
    SetFormValue(*wf, _T("prpFrequency"), _T("--"));

    // Fill the home airfield field
    SetFormValue(*wf, _T("prpAirport"), _T("--"));

    // Fill the plane type field
    const FlarmTraffic* target =
        XCSoarInterface::Basic().flarm.traffic.FindTraffic(target_id);

    const TCHAR* actype;
    if (target == NULL ||
        (actype = FlarmTraffic::GetTypeString(target->type)) == NULL)
      actype = _T("--");

    SetFormValue(*wf, _T("prpPlaneType"), actype);
  }

  // Fill the callsign field (+ registration)
  // note: don't use target->Name here since it is not updated
  //       yet if it was changed
  const TCHAR* cs = FlarmDetails::LookupCallsign(target_id);
  if (cs != NULL && cs[0] != 0) {
    _tcscpy(tmp, cs);
    if (record) {
      _tcscat(tmp, _T(" ("));
      _tcscat(tmp, record->registration);
      _tcscat(tmp, _T(")"));
    }
  } else
    _tcscpy(tmp, _T("--"));
  SetFormValue(*wf, _T("prpCallsign"), tmp);

  // Update the frequently changing fields too
  UpdateChanging();
}
Ejemplo n.º 2
0
/**
 * Updates all the dialogs fields.
 * Should be called on dialog opening as it closes the dialog when the
 * target does not exist.
 */
void
FlarmTrafficDetailsWidget::Update()
{
  TCHAR tmp[200], tmp_id[7];
  const TCHAR *value;

  // Set the dialog caption
  StringFormatUnsafe(tmp, _T("%s (%s)"),
                     _("FLARM Traffic Details"), target_id.Format(tmp_id));
  dialog.SetCaption(tmp);

  // Try to find the target in the FLARMnet database
  /// @todo: make this code a little more usable
  const FlarmNetRecord *record = FlarmDetails::LookupRecord(target_id);
  if (record) {
    // Fill the pilot name field
    SetText(PILOT, record->pilot);

    // Fill the frequency field
    if (!StringIsEmpty(record->frequency))
      value = UnsafeBuildString(tmp, record->frequency.c_str(), _T(" MHz"));
    else
      value = _T("--");
    SetText(RADIO, value);

    // Fill the home airfield field
    SetText(AIRPORT, record->airfield);

    // Fill the plane type field
    SetText(PLANE, record->plane_type);
  } else {
    // Fill the pilot name field
    SetText(PILOT, _T("--"));

    // Fill the frequency field
    SetText(RADIO, _T("--"));

    // Fill the home airfield field
    SetText(AIRPORT, _T("--"));

    // Fill the plane type field
    const FlarmTraffic* target =
      CommonInterface::Basic().flarm.traffic.FindTraffic(target_id);

    const TCHAR* actype;
    if (target == nullptr ||
        (actype = FlarmTraffic::GetTypeString(target->type)) == nullptr)
      actype = _T("--");

    SetText(PLANE, actype);
  }

  // Fill the callsign field (+ registration)
  // note: don't use target->Name here since it is not updated
  //       yet if it was changed
  const TCHAR* cs = FlarmDetails::LookupCallsign(target_id);
  if (cs != nullptr && cs[0] != 0) {
    StringBuilder<TCHAR> builder(tmp, ARRAY_SIZE(tmp));
    builder.Append(cs);
    if (record)
      builder.Append(_T(" ("), record->registration.c_str(), _T(")"));
    value = tmp;
  } else
    value = _T("--");
  SetText(CALLSIGN, value);

  // Update the frequently changing fields too
  UpdateChanging(CommonInterface::Basic());
}
Ejemplo n.º 3
0
static void
PaintListItem(Canvas &canvas, const PixelRect rc, unsigned index)
{
  assert(array[index].IsDefined());

  const FlarmId id = array[index];

  const DialogLook &look = UIGlobals::GetDialogLook();
  const Font &name_font = *look.list.font;
  const Font &small_font = *look.small_font;

  canvas.SetTextColor(COLOR_BLACK);

  TCHAR tmp_id[10];
  id.Format(tmp_id);

  const FlarmRecord *record = FlarmNet::FindRecordById(id);
  const TCHAR *callsign = FlarmDetails::LookupCallsign(id);

  canvas.Select(name_font);

  StaticString<256> tmp;
  if (record != NULL)
    tmp.Format(_T("%s - %s - %s"), callsign, record->registration, tmp_id);
  else if (callsign != NULL)
    tmp.Format(_T("%s - %s"), callsign, tmp_id);
  else
    tmp.Format(_T("%s"), tmp_id);

  canvas.text_clipped(rc.left + Layout::FastScale(2),
                      rc.top + Layout::FastScale(2), rc, tmp);

  canvas.Select(small_font);

  tmp.clear();
  if (record != NULL) {
    if (!StringIsEmpty(record->pilot))
      tmp = record->pilot;

    if (!StringIsEmpty(record->plane_type)) {
      if (!tmp.empty())
        tmp.append(_T(" - "));

      tmp.append(record->plane_type);
    }

    if (!StringIsEmpty(record->airfield)) {
      if (!tmp.empty())
        tmp.append(_T(" - "));

      tmp.append(record->airfield);
    }
  }

  if (tmp.empty())
    tmp = _("No further information");

  canvas.text_clipped(rc.left + Layout::FastScale(2),
                      rc.top + name_font.GetHeight() + Layout::FastScale(4),
                      rc, tmp);
}