21 #include <tqstringlist.h>
22 #include "domainbrowser.h"
25 #include "responder.h"
26 #include "remoteservice.h"
28 #include "servicebrowser.h"
29 #include <tdeapplication.h>
32 #include <avahi-client/lookup.h>
41 void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event,
const char* replyDomain,
42 AvahiLookupResultFlags,
void* context);
44 void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event,
const char* replyDomain,
50 class DomainBrowserPrivate
54 DomainBrowserPrivate(DomainBrowser* owner) : m_browseLAN(false), m_started(false), m_browser(0), m_owner(owner) {}
56 DomainBrowserPrivate(DomainBrowser* owner) : m_browseLAN(false), m_started(false) {}
59 ~DomainBrowserPrivate() {
if (m_browser) avahi_domain_browser_free(m_browser); }
61 TQStringList m_domains;
62 virtual void customEvent(TQCustomEvent* event);
66 AvahiDomainBrowser* m_browser;
68 DomainBrowser* m_owner;
71 void DomainBrowserPrivate::customEvent(TQCustomEvent* event)
73 if (event->type()==TQEvent::User+SD_ADDREMOVE) {
74 AddRemoveEvent *aev =
static_cast<AddRemoveEvent*
>(event);
75 if (aev->m_op==AddRemoveEvent::Add) m_owner->gotNewDomain(aev->m_domain);
76 else m_owner->gotRemoveDomain(aev->m_domain);
83 d =
new DomainBrowserPrivate(
this);
84 d->m_domains = Configuration::domainList();
85 if (Configuration::browseLocal()) {
86 d->m_domains+=
"local.";
89 connect(TDEApplication::kApplication(),TQ_SIGNAL(kipcMessage(
int,
int)),
this,
90 TQ_SLOT(domainListChanged(
int,
int)));
95 d =
new DomainBrowserPrivate(
this);
96 d->m_browseLAN = recursive;
101 DomainBrowser::~DomainBrowser()
109 if (d->m_started)
return;
112 TQStringList::const_iterator itEnd = d->m_domains.end();
113 for (TQStringList::const_iterator it=d->m_domains.begin(); it!=itEnd; ++it ) emit
domainAdded(*it);
117 d->m_browser = avahi_domain_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
118 "local.", AVAHI_DOMAIN_BROWSER_BROWSE, (AvahiLookupFlags)0, domains_callback,
this);
120 d->m_browser = avahi_domain_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
121 "local.", AVAHI_DOMAIN_BROWSER_BROWSE, domains_callback,
this);
126 void DomainBrowser::gotNewDomain(
const TQString& domain)
128 if (d->m_domains.contains(domain))
return;
129 d->m_domains.append(domain);
133 void DomainBrowser::gotRemoveDomain(
const TQString& domain)
135 d->m_domains.remove(domain);
139 void DomainBrowser::domainListChanged(
int message,
int)
141 if (message!=KIPCDomainsChanged)
return;
143 bool was_started = d->m_started;
146 avahi_domain_browser_free(d->m_browser);
150 d->m_started =
false;
154 TQStringList::const_iterator itEnd = d->m_domains.end();
155 for (TQStringList::const_iterator it=d->m_domains.begin(); it!=itEnd; ++it )
158 d->m_domains.clear();
160 Configuration::self()->readConfig();
161 d->m_browseLAN = Configuration::browseLocal();
162 d->m_domains = Configuration::domainList();
163 if (Configuration::browseLocal()) d->m_domains+=
"local";
178 void DomainBrowser::virtual_hook(
int,
void*)
183 void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event,
const char* replyDomain,
184 AvahiLookupResultFlags,
void* context)
186 void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event,
const char* replyDomain,
190 TQObject *obj =
reinterpret_cast<TQObject*
>(context);
191 AddRemoveEvent* arev=
new AddRemoveEvent((event==AVAHI_BROWSER_NEW) ? AddRemoveEvent::Add :
192 AddRemoveEvent::Remove, TQString::null, TQString::null,
193 DNSToDomain(replyDomain));
194 TQApplication::postEvent(obj, arev);
199 #include "domainbrowser.moc"
void startBrowse()
Starts browsing.
DomainBrowser(TQObject *parent=0)
Standard constructor.
bool isRunning() const
Returns true when browse has already started.
const TQStringList & domains() const
Current list of domains to browse.
void domainRemoved(const TQString &)
Emitted when domain has been removed from browsing list.
void domainAdded(const TQString &)
New domain has been discovered.
static const State isAvailable()
Checks availability of DNS-SD services (this also covers publishing).