21 #include "responder.h"
22 #include <tqapplication.h>
23 #include <tqeventloop.h>
24 #include <kstaticdeleter.h>
28 #include <avahi-tqt/qt-watch.h>
34 static KStaticDeleter<Responder> responder_sd;
35 Responder* Responder::m_self = 0;
38 void client_callback(AvahiClient *, AvahiClientState s,
void* u)
40 Responder *r =
reinterpret_cast<Responder*
>(u);
41 emit (r->stateChanged(s));
46 Responder::Responder()
50 const AvahiPoll* poll = avahi_qt_poll_get();
52 m_client = avahi_client_new(poll, AVAHI_CLIENT_IGNORE_USER_CONFIG,client_callback,
this, &error);
54 m_client = avahi_client_new(poll, client_callback,
this, &error);
56 if (!m_client) kdWarning() <<
"Failed to create avahi client" << endl;
60 Responder::~Responder()
63 if (m_client) avahi_client_free(m_client);
67 Responder& Responder::self()
69 if (!m_self) responder_sd.setObject(m_self,
new Responder);
73 void Responder::process()
75 tqApp->eventLoop()->processEvents(TQEventLoop::ExcludeUserInput);
79 AvahiClientState Responder::state()
const
82 return (m_client) ? (avahi_client_get_state(m_client)) : AVAHI_CLIENT_FAILURE;
84 return (m_client) ? (avahi_client_get_state(m_client)) : AVAHI_CLIENT_DISCONNECTED;
89 bool domainIsLocal(
const TQString& domain)
91 return TQString(domain.section(
'.',-1,-1)).lower()==
"local";
94 TQCString domainToDNS(
const TQString &domain)
96 if (domainIsLocal(domain))
return domain.utf8();
97 else return KIDNA::toAsciiCString(domain);
100 TQString DNSToDomain(
const char* domain)
102 if (domainIsLocal(domain))
return TQString::fromUtf8(domain);
103 else return KIDNA::toUnicode(domain);
108 #include "responder.moc"