24 m_comboBox = std::make_unique<juce::ComboBox>(
"ZeroconfServices");
25 m_comboBox->setTextWhenNothingSelected(
"Searching for OCA/OCP.1 devices...");
26 m_comboBox->setSelectedId(0, juce::dontSendNotification);
27 m_comboBox->setEnabled(
false);
28 addAndMakeVisible(m_comboBox.get());
30 m_comboBox->onChange = [
this]() {
31 auto idx = m_comboBox->getSelectedId() - 2;
36 m_searcher = std::make_unique<ZeroconfSearcher::ZeroconfSearcher>(
"OCA",
"_oca._tcp");
37 m_searcher->AddListener(
this);
38 m_searcher->StartSearching();
44 m_searcher->StopSearching();
49 m_comboBox->setBounds(getLocalBounds());
54 if (
auto* parent = getParentComponent())
55 setSize(juce::roundToInt(parent->getWidth() * 0.8f), getHeight());
60 juce::MessageManager::callAsync([
this]() { updateComboBox(); });
63void UmsciZeroconfDiscoverComboComponent::updateComboBox()
68 m_services = m_searcher->GetServices();
70 m_comboBox->clear(juce::dontSendNotification);
72 if (m_services.empty())
74 m_comboBox->setTextWhenNothingSelected(
"Searching for OCA/OCP.1 devices...");
75 m_comboBox->setSelectedId(0, juce::dontSendNotification);
76 m_comboBox->setEnabled(
false);
80 m_comboBox->setEnabled(
true);
81 m_comboBox->setTextWhenNothingSelected(juce::String(m_services.size()) +
" OCA/OCP.1 devices available...");
82 for (
int i = 0; i < static_cast<int>(m_services.size()); ++i)
84 auto& s = m_services[
static_cast<size_t>(i)];
85 auto displayName = juce::String(s.name).upToFirstOccurrenceOf(
"._oca._tcp",
false,
true);
86 auto label = displayName +
" (" + juce::String(s.ip) +
":" + juce::String(s.port) +
")";
87 m_comboBox->addItem(label, i + 2);
89 m_comboBox->setSelectedId(0, juce::dontSendNotification);
std::function< void(const ZeroconfSearcher::ZeroconfSearcher::ServiceInfo &)> onServiceSelected
Fired when the user selects a device from the combo box. The ServiceInfo contains the resolved hostna...
void parentSizeChanged() override
Resizes the component to 80 % of the parent's width whenever the parent (AlertWindow) is resized,...
~UmsciZeroconfDiscoverComboComponent() override
UmsciZeroconfDiscoverComboComponent()
void handleServicesChanged(std::string serviceName) override
ZeroconfSearcherListener callback — called when devices appear or disappear.