static bool DetectSerialPorts(DataFieldEnum &df) { TTYEnumerator enumerator; if (enumerator.HasFailed()) return false; unsigned sort_start = df.Count(); bool found = false; const char *path; while ((path = enumerator.Next()) != nullptr) { const char *display_string = path; if (memcmp(path, "/dev/", 5) == 0) display_string = path + 5; AddPort(df, DeviceConfig::PortType::SERIAL, path, display_string); found = true; } if (found) df.Sort(sort_start); return found; }
void InfoBoxManager::SetupFocused() { int i = GetFocused(); if (i < 0) return; const enum mode mode = GetCurrentMode(); int old_type = GetType(i, mode); /* create a fake WndProperty for dlgComboPicker() */ /* XXX reimplement properly */ DataFieldEnum *dfe = new DataFieldEnum(old_type, NULL); for (unsigned i = 0; i < InfoBoxFactory::NUM_TYPES; i++) dfe->addEnumText(gettext(GetTypeDescription(i))); dfe->Sort(0); dfe->Set(old_type); ComboList *list = dfe->CreateComboList(); delete dfe; /* let the user select */ info_box_combo_list = list; int result = ComboPicker(XCSoarInterface::main_window, _("InfoBox"), *list, OnInfoBoxHelp); if (result < 0) { delete list; return; } /* was there a modification? */ int new_type = (*list)[result].DataFieldIndex; delete list; if (new_type == old_type) return; /* yes: apply and save it */ SetType(i, new_type, mode); DisplayInfoBox(); Profile::SetInfoBoxes(i, GetTypes(i)); }
static bool DetectSerialPorts(DataFieldEnum &df) { PortEnumerator enumerator; if (enumerator.Error()) return false; unsigned sort_start = df.Count(); bool found = false; while (enumerator.Next()) { AddPort(df, DeviceConfig::PortType::SERIAL, enumerator.GetName(), enumerator.GetDisplayName()); found = true; } if (found) df.Sort(sort_start); return found; }
static bool DetectSerialPorts(DataFieldEnum &df) { DIR *dir = opendir("/dev"); if (dir == NULL) return false; unsigned sort_start = df.Count(); bool found = false; struct dirent *ent; while ((ent = readdir(dir)) != NULL) { /* filter "/dev/tty*" */ if (memcmp(ent->d_name, "tty", 3) == 0) { /* filter out "/dev/tty0", ... (valid integer after "tty") */ char *endptr; strtoul(ent->d_name + 3, &endptr, 10); if (*endptr == 0) continue; } else if (memcmp(ent->d_name, "rfcomm", 6) != 0) continue; char path[64]; snprintf(path, sizeof(path), "/dev/%s", ent->d_name); if (access(path, R_OK|W_OK) == 0 && access(path, X_OK) < 0) { AddPort(df, DeviceConfig::PortType::SERIAL, path); found = true; } } closedir(dir); if (found) df.Sort(sort_start); return found; }
void InfoBoxesConfigWidget::Prepare(ContainerWindow &parent, const PixelRect &rc) { const Layout layout(rc, geometry); AddText(_("Name"), nullptr, allow_name_change ? (const TCHAR *)data.name : gettext(data.name)); SetReadOnly(NAME, !allow_name_change); DataFieldEnum *dfe = new DataFieldEnum(this); for (unsigned i = 0; i < layout.info_boxes.count; ++i) { TCHAR label[32]; _stprintf(label, _T("%u"), i + 1); dfe->addEnumText(label, i); } Add(_("InfoBox"), nullptr, dfe); dfe = new DataFieldEnum(this); for (unsigned i = InfoBoxFactory::MIN_TYPE_VAL; i < InfoBoxFactory::NUM_TYPES; i++) { const TCHAR *name = InfoBoxFactory::GetName((InfoBoxFactory::Type) i); const TCHAR *desc = InfoBoxFactory::GetDescription((InfoBoxFactory::Type) i); if (name != NULL) dfe->addEnumText(gettext(name), i, desc != NULL ? gettext(desc) : NULL); } dfe->EnableItemHelp(true); dfe->Sort(0); Add(_("Content"), nullptr, dfe); ContainerWindow &form_parent = (ContainerWindow &)RowFormWidget::GetWindow(); AddRemaining(new WndFrame(form_parent, GetLook(), rc)); WindowStyle button_style; button_style.Hide(); button_style.TabStop(); const auto &button_look = GetLook().button; copy_button.Create(parent, button_look, _("Copy"), layout.copy_button, button_style, *this, COPY); paste_button.Create(parent, button_look, _("Paste"), layout.paste_button, button_style, *this, PASTE); close_button.Create(parent, button_look, _("Close"), layout.close_button, button_style, dialog, mrOK); WindowStyle preview_style; preview_style.EnableDoubleClicks(); preview_style.Hide(); previews.resize(layout.info_boxes.count); for (unsigned i = 0; i < layout.info_boxes.count; ++i) { previews[i].SetParent(*this, i); previews[i].Create(parent, layout.info_boxes.positions[i], preview_style); } current_preview = 0; RefreshEditContent(); RefreshPasteButton(); }
static void SetupDeviceFields(const DeviceConfig &config, WndProperty *port_field, WndProperty *speed_field, WndProperty *driver_field, WndButton *setup_button) { #ifndef ANDROID static const TCHAR *const COMMPort[] = { _T("COM1"), _T("COM2"), _T("COM3"), _T("COM4"), _T("COM5"), _T("COM6"), _T("COM7"), _T("COM8"), _T("COM9"), _T("COM10"), _T("COM0"), NULL }; static const TCHAR *const tSpeed[] = { _T("1200"), _T("2400"), _T("4800"), _T("9600"), _T("19200"), _T("38400"), _T("57600"), _T("115200"), NULL }; #endif if (port_field != NULL) { DataFieldEnum *dfe = (DataFieldEnum *)port_field->GetDataField(); for (unsigned i = 0; port_types[i].label != NULL; i++) { dfe->addEnumText(gettext(port_types[i].label)); if (port_types[i].type == config.port_type) dfe->Set(i); } #ifdef ANDROID JNIEnv *env = Java::GetEnv(); jobjectArray bonded = BluetoothHelper::list(env); if (bonded != NULL) { jsize n = env->GetArrayLength(bonded) / 2; for (jsize i = 0; i < n; ++i) { jstring address = (jstring)env->GetObjectArrayElement(bonded, i * 2); if (address == NULL) continue; const char *address2 = env->GetStringUTFChars(address, NULL); if (address2 == NULL) continue; jstring name = (jstring)env->GetObjectArrayElement(bonded, i * 2 + 1); const char *name2 = name != NULL ? env->GetStringUTFChars(name, NULL) : NULL; dfe->addEnumText(address2, name2); env->ReleaseStringUTFChars(address, address2); if (name2 != NULL) env->ReleaseStringUTFChars(name, name2); } env->DeleteLocalRef(bonded); if (config.port_type == DeviceConfig::RFCOMM && !config.bluetooth_mac.empty()) { if (!dfe->Exists(config.bluetooth_mac)) dfe->addEnumText(config.bluetooth_mac); dfe->SetAsString(config.bluetooth_mac); } } #else dfe->addEnumTexts(COMMPort); switch (config.port_type) { case DeviceConfig::SERIAL: dfe->Set(config.port_index + num_port_types); break; case DeviceConfig::DISABLED: case DeviceConfig::RFCOMM: case DeviceConfig::AUTO: case DeviceConfig::INTERNAL: case DeviceConfig::TCP_LISTENER: break; } #endif port_field->RefreshDisplay(); } if (speed_field != NULL) { #ifdef ANDROID speed_field->hide(); #else DataFieldEnum *dfe = (DataFieldEnum *)speed_field->GetDataField(); dfe->addEnumTexts(tSpeed); dfe->Set(config.speed_index); speed_field->RefreshDisplay(); #endif } if (driver_field) { DataFieldEnum *dfe = (DataFieldEnum *)driver_field->GetDataField(); const TCHAR *DeviceName; for (unsigned i = 0; (DeviceName = devRegisterGetName(i)) != NULL; i++) dfe->addEnumText(DeviceName); dfe->Sort(1); dfe->SetAsString(config.driver_name); driver_field->RefreshDisplay(); } if (setup_button != NULL) setup_button->set_visible(config.IsVega()); UpdateDeviceControlVisibility(*port_field, *speed_field, *driver_field); }
bool dlgConfigInfoboxesShowModal(SingleWindow &parent, const DialogLook &dialog_look, InfoBoxLayout::Geometry geometry, InfoBoxSettings::Panel &data_r, bool allow_name_change) { current_preview = 0; data = data_r; PixelRect rc = parent.get_client_rect(); wf = new WndForm(parent, dialog_look, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); #ifdef _WIN32_WCE if (is_altair()) wf->SetKeyDownNotify(OnKeyDown); #endif ContainerWindow &client_area = wf->GetClientAreaWindow(); rc = client_area.get_client_rect(); InflateRect(&rc, Layout::FastScale(-2), Layout::FastScale(-2)); info_box_layout = InfoBoxLayout::Calculate(rc, geometry); WindowStyle preview_style; preview_style.enable_double_clicks(); for (unsigned i = 0; i < info_box_layout.count; ++i) { rc = info_box_layout.positions[i]; previews[i].set(client_area, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, preview_style); } rc = info_box_layout.remaining; WindowStyle style; style.control_parent(); EditWindowStyle edit_style; edit_style.tab_stop(); if (is_embedded() || Layout::scale_1024 < 2048) /* sunken edge doesn't fit well on the tiny screen of an embedded device */ edit_style.border(); else edit_style.sunken_edge(); const int x = rc.left; const unsigned width = rc.right - rc.left - Layout::FastScale(2); const unsigned height = Layout::Scale(22); const unsigned caption_width = Layout::Scale(60); int y = rc.top; ButtonWindowStyle button_style; button_style.tab_stop(); buttonPanelName = new WndButton(client_area, dialog_look, _T(""), x, y, width, height, button_style, OnNameAccess); buttonPanelName->set_enabled(allow_name_change); UpdatePanelName(); y += height; edit_select = new WndProperty(client_area, dialog_look, _("InfoBox"), x, y, width, height, caption_width, style, edit_style, NULL); DataFieldEnum *dfe = new DataFieldEnum(OnSelectAccess); for (unsigned i = 0; i < info_box_layout.count; ++i) { TCHAR label[32]; _stprintf(label, _T("%u"), i + 1); dfe->addEnumText(label, i); } edit_select->SetDataField(dfe); y += height; edit_content = new WndProperty(client_area, dialog_look, _("Content"), x, y, width, height, caption_width, style, edit_style, NULL); dfe = new DataFieldEnum(OnContentAccess); for (unsigned i = 0; i < InfoBoxFactory::NUM_TYPES; ++i) { const TCHAR *name = InfoBoxFactory::GetName(i); if (name != NULL) dfe->addEnumText(gettext(name), i); } dfe->Sort(0); edit_content->SetDataField(dfe); edit_content->SetOnHelpCallback(OnContentHelp); RefreshEditContent(); const unsigned button_width = Layout::Scale(60); const unsigned button_height = Layout::Scale(28); const int button_y = rc.bottom - button_height; int button_x = rc.left; WndButton *close_button = new WndButton(client_area, dialog_look, _("Close"), button_x, button_y, button_width, button_height, button_style, OnCloseClicked); button_x += button_width + Layout::Scale(2); WndButton *copy_button = new WndButton(client_area, dialog_look, _("Copy"), button_x, button_y, button_width, button_height, button_style, OnCopy); button_x += button_width + Layout::Scale(2); buttonPaste = new WndButton(client_area, dialog_look, _("Paste"), button_x, button_y, button_width, button_height, button_style, OnPaste); RefreshPasteButton(); int result = wf->ShowModal(); delete wf; delete buttonPanelName; delete edit_select; delete edit_content; delete close_button; delete copy_button; delete buttonPaste; bool changed = false; if (result == mrOK) { for (unsigned i = 0; i < InfoBoxSettings::Panel::MAX_CONTENTS; ++i) if (data.contents[i] != data_r.contents[i]) changed = true; changed |= (_tcscmp(data.name, data_r.name) != 0); if (changed) data_r = data; } return changed; }
bool dlgConfigInfoboxesShowModal(SingleWindow &parent, const DialogLook &dialog_look, const InfoBoxLook &_look, InfoBoxSettings::Geometry geometry, InfoBoxSettings::Panel &data_r, bool allow_name_change) { current_preview = 0; look = &_look; data = data_r; PixelRect rc = parent.GetClientRect(); wf = new WndForm(parent, dialog_look, rc); #ifdef _WIN32_WCE if (IsAltair()) wf->SetKeyDownFunction(OnKeyDown); #endif ContainerWindow &client_area = wf->GetClientAreaWindow(); rc = client_area.GetClientRect(); rc.Grow(Layout::FastScale(-2)); info_box_layout = InfoBoxLayout::Calculate(rc, geometry); WindowStyle preview_style; preview_style.EnableDoubleClicks(); for (unsigned i = 0; i < info_box_layout.count; ++i) { rc = info_box_layout.positions[i]; previews[i].Create(client_area, rc, preview_style); } rc = info_box_layout.remaining; WindowStyle style; style.TabStop(); PixelRect control_rc = rc; control_rc.right -= Layout::FastScale(2); const UPixelScalar height = Layout::Scale(22); const UPixelScalar caption_width = Layout::Scale(60); ButtonWindowStyle button_style; button_style.TabStop(); control_rc.bottom = control_rc.top + height; edit_name = new WndProperty(client_area, dialog_look, _("Name"), control_rc, caption_width, style); DataFieldString *dfs = new DataFieldString(allow_name_change ? (const TCHAR *)data.name : gettext(data.name)); edit_name->SetDataField(dfs); edit_name->SetReadOnly(!allow_name_change); control_rc.top = control_rc.bottom; control_rc.bottom = control_rc.top + height; edit_select = new WndProperty(client_area, dialog_look, _("InfoBox"), control_rc, caption_width, style); DataFieldEnum *dfe = new DataFieldEnum(OnSelectAccess); for (unsigned i = 0; i < info_box_layout.count; ++i) { TCHAR label[32]; _stprintf(label, _T("%u"), i + 1); dfe->addEnumText(label, i); } edit_select->SetDataField(dfe); control_rc.top += height; control_rc.bottom += height; edit_content = new WndProperty(client_area, dialog_look, _("Content"), control_rc, caption_width, style); dfe = new DataFieldEnum(OnContentAccess); for (unsigned i = InfoBoxFactory::MIN_TYPE_VAL; i < InfoBoxFactory::NUM_TYPES; i++) { const TCHAR *name = InfoBoxFactory::GetName((InfoBoxFactory::Type) i); const TCHAR *desc = InfoBoxFactory::GetDescription((InfoBoxFactory::Type) i); if (name != NULL) dfe->addEnumText(gettext(name), i, desc != NULL ? gettext(desc) : NULL); } dfe->EnableItemHelp(true); dfe->Sort(0); edit_content->SetDataField(dfe); control_rc.top += height; control_rc.bottom += height * 5; edit_content_description = new WndFrame(client_area, dialog_look, control_rc, style); RefreshEditContent(); const UPixelScalar button_width = Layout::Scale(60); const UPixelScalar button_height = Layout::Scale(28); PixelRect button_rc = rc; button_rc.right = button_rc.left + button_width; button_rc.top = button_rc.bottom - button_height; WndButton *close_button = new WndButton(client_area, dialog_look.button, _("Close"), button_rc, button_style, *wf, mrOK); button_rc.left += button_width + Layout::Scale(2); button_rc.right += button_width + Layout::Scale(2); WndButton *copy_button = new WndButton(client_area, dialog_look.button, _("Copy"), button_rc, button_style, OnCopy); button_rc.left += button_width + Layout::Scale(2); button_rc.right += button_width + Layout::Scale(2); buttonPaste = new WndButton(client_area, dialog_look.button, _("Paste"), button_rc, button_style, OnPaste); RefreshPasteButton(); int result = wf->ShowModal(); if (result == mrOK && allow_name_change) data.name = edit_name->GetDataField()->GetAsString(); delete wf; delete edit_name; delete edit_select; delete edit_content; delete close_button; delete copy_button; delete buttonPaste; bool changed = false; if (result == mrOK) { for (unsigned i = 0; i < InfoBoxSettings::Panel::MAX_CONTENTS; ++i) if (data.contents[i] != data_r.contents[i]) changed = true; changed |= (_tcscmp(data.name, data_r.name) != 0); if (changed) data_r = data; } return changed; }