summaryrefslogtreecommitdiffstats
path: root/dnssd/domainbrowser.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-12-11 03:46:01 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-12-11 03:46:01 +0000
commit865f314dd5ed55508f45a32973b709b79a541e36 (patch)
treedc1a3a884bb2fc10a89a3c46313897d22c5771eb /dnssd/domainbrowser.cpp
parentce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (diff)
downloadtdelibs-865f314dd5ed55508f45a32973b709b79a541e36.tar.gz
tdelibs-865f314dd5ed55508f45a32973b709b79a541e36.zip
kdelibs update to Trinity v3.5.11
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1061230 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'dnssd/domainbrowser.cpp')
-rw-r--r--dnssd/domainbrowser.cpp75
1 files changed, 45 insertions, 30 deletions
diff --git a/dnssd/domainbrowser.cpp b/dnssd/domainbrowser.cpp
index cad3307dd..294ce2576 100644
--- a/dnssd/domainbrowser.cpp
+++ b/dnssd/domainbrowser.cpp
@@ -27,46 +27,56 @@
#include "query.h"
#include "servicebrowser.h"
#include <kapplication.h>
+#ifdef AVAHI_API_0_6
+#include <avahi-client/lookup.h>
+#endif
namespace DNSSD
{
-#ifdef HAVE_DNSSD
-void domain_callback(DNSServiceRef, DNSServiceFlags flags, uint32_t, DNSServiceErrorType errorCode,
- const char *replyDomain, void *context);
+#ifdef AVAHI_API_0_6
+void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event, const char* replyDomain,
+ AvahiLookupResultFlags, void* context);
+#else
+void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event, const char* replyDomain,
+ void* context);
#endif
-class DomainBrowserPrivate : public Responder
+
+class DomainBrowserPrivate
{
public:
- DomainBrowserPrivate(DomainBrowser* owner) : Responder(), m_browseLAN(false), m_started(false), m_owner(owner) {}
+ DomainBrowserPrivate(DomainBrowser* owner) : m_browseLAN(false), m_started(false),
+ m_browser(0), m_owner(owner) {}
+ ~DomainBrowserPrivate() { if (m_browser) avahi_domain_browser_free(m_browser); }
QStringList m_domains;
virtual void customEvent(QCustomEvent* event);
bool m_browseLAN;
bool m_started;
+ AvahiDomainBrowser* m_browser;
DomainBrowser* m_owner;
};
void DomainBrowserPrivate::customEvent(QCustomEvent* event)
{
- if (event->type()==QEvent::User+SD_ERROR) stop();
if (event->type()==QEvent::User+SD_ADDREMOVE) {
AddRemoveEvent *aev = static_cast<AddRemoveEvent*>(event);
if (aev->m_op==AddRemoveEvent::Add) m_owner->gotNewDomain(aev->m_domain);
else m_owner->gotRemoveDomain(aev->m_domain);
}
}
+
DomainBrowser::DomainBrowser(QObject *parent) : QObject(parent)
{
d = new DomainBrowserPrivate(this);
- d->m_domains = Configuration::domainList();
+ d->m_domains = Configuration::domainList();
if (Configuration::browseLocal()) {
d->m_domains+="local.";
d->m_browseLAN=true;
}
- connect(KApplication::kApplication(),SIGNAL(kipcMessage(int,int)),this,
- SLOT(domainListChanged(int,int)));
+ connect(KApplication::kApplication(),SIGNAL(kipcMessage(int,int)),this,
+ SLOT(domainListChanged(int,int)));
}
DomainBrowser::DomainBrowser(const QStringList& domains, bool recursive, QObject *parent) : QObject(parent)
@@ -88,14 +98,15 @@ void DomainBrowser::startBrowse()
if (d->m_started) return;
d->m_started=true;
if (ServiceBrowser::isAvailable()!=ServiceBrowser::Working) return;
- QStringList::const_iterator itEnd = d->m_domains.end();
+ QStringList::const_iterator itEnd = d->m_domains.end();
for (QStringList::const_iterator it=d->m_domains.begin(); it!=itEnd; ++it ) emit domainAdded(*it);
-#ifdef HAVE_DNSSD
- if (d->m_browseLAN) {
- DNSServiceRef ref;
- if (DNSServiceEnumerateDomains(&ref,kDNSServiceFlagsBrowseDomains,0,domain_callback,
- reinterpret_cast<void*>(d))==kDNSServiceErr_NoError) d->setRef(ref);
- }
+ if (d->m_browseLAN)
+#ifdef AVAHI_API_0_6
+ d->m_browser = avahi_domain_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
+ "local.", AVAHI_DOMAIN_BROWSER_BROWSE, (AvahiLookupFlags)0, domains_callback, this);
+#else
+ d->m_browser = avahi_domain_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
+ "local.", AVAHI_DOMAIN_BROWSER_BROWSE, domains_callback, this);
#endif
}
@@ -115,9 +126,14 @@ void DomainBrowser::gotRemoveDomain(const QString& domain)
void DomainBrowser::domainListChanged(int message,int)
{
if (message!=KIPCDomainsChanged) return;
+
bool was_started = d->m_started;
- if (d->isRunning()) d->stop(); // LAN query
+ if (d->m_browser) {
+ avahi_domain_browser_free(d->m_browser); // LAN query
+ d->m_browser=0;
+ }
d->m_started = false;
+
// remove all domains and resolvers
if (was_started) {
QStringList::const_iterator itEnd = d->m_domains.end();
@@ -129,7 +145,7 @@ void DomainBrowser::domainListChanged(int message,int)
Configuration::self()->readConfig();
d->m_browseLAN = Configuration::browseLocal();
d->m_domains = Configuration::domainList();
- if (Configuration::browseLocal()) d->m_domains+="local.";
+ if (Configuration::browseLocal()) d->m_domains+="local";
// this will emit domainAdded() for every domain if necessary
if (was_started) startBrowse();
}
@@ -147,22 +163,21 @@ bool DomainBrowser::isRunning() const
void DomainBrowser::virtual_hook(int, void*)
{}
-#ifdef HAVE_DNSSD
-void domain_callback(DNSServiceRef, DNSServiceFlags flags, uint32_t, DNSServiceErrorType errorCode,
- const char *replyDomain, void *context)
+#ifdef AVAHI_API_0_6
+void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event, const char* replyDomain,
+ AvahiLookupResultFlags,void* context)
+#else
+void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event, const char* replyDomain,
+ void* context)
+#endif
{
QObject *obj = reinterpret_cast<QObject*>(context);
- if (errorCode != kDNSServiceErr_NoError) {
- ErrorEvent err;
- QApplication::sendEvent(obj, &err);
- } else {
- AddRemoveEvent arev((flags & kDNSServiceFlagsAdd) ? AddRemoveEvent::Add :
+ AddRemoveEvent* arev=new AddRemoveEvent((event==AVAHI_BROWSER_NEW) ? AddRemoveEvent::Add :
AddRemoveEvent::Remove, QString::null, QString::null,
- DNSToDomain(replyDomain), !(flags & kDNSServiceFlagsMoreComing));
- QApplication::sendEvent(obj, &arev);
- }
+ DNSToDomain(replyDomain));
+ QApplication::postEvent(obj, arev);
}
-#endif
+
}
#include "domainbrowser.moc"