00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "avahi-servicetypebrowser_p.h"
00023 #include <QtCore/QSet>
00024 #include "avahi_server_interface.h"
00025 #include "servicetypebrowser.h"
00026 #include "avahi_servicetypebrowser_interface.h"
00027
00028 #define UNSPEC -1
00029 #ifndef KDE_USE_FINAL
00030 Q_DECLARE_METATYPE(QList<QByteArray>)
00031 #endif
00032 namespace DNSSD
00033 {
00034
00035 ServiceTypeBrowser::ServiceTypeBrowser(const QString& domain, QObject *parent) : QObject(parent), d(new ServiceTypeBrowserPrivate(this))
00036 {
00037 d->m_domain=domain;
00038 d->m_timer.setSingleShot(true);
00039 }
00040
00041 ServiceTypeBrowser::~ServiceTypeBrowser()
00042 {
00043 delete d;
00044 }
00045
00046 void ServiceTypeBrowser::startBrowse()
00047 {
00048 if (d->m_started) return;
00049 d->m_started=true;
00050 org::freedesktop::Avahi::Server s("org.freedesktop.Avahi","/",QDBusConnection::systemBus());
00051 QDBusReply<QDBusObjectPath> rep=s.ServiceTypeBrowserNew(-1, -1, d->m_domain, 0);
00052
00053 if (!rep.isValid()) return;
00054 org::freedesktop::Avahi::ServiceTypeBrowser *b=new org::freedesktop::Avahi::ServiceTypeBrowser("org.freedesktop.Avahi",rep.value().path(),
00055 QDBusConnection::systemBus());
00056 connect(b,SIGNAL(ItemNew(int,int,const QString&,const QString&,uint)),d, SLOT(gotNewServiceType(int,int,const QString&,const QString&, uint)));
00057 connect(b,SIGNAL(ItemRemove(int,int,const QString&,const QString&,uint)),d, SLOT(gotRemoveServiceType(int,int,const QString&,const QString&, uint)));
00058 connect(b,SIGNAL(AllForNow()),d,SLOT(finished()));
00059 connect(&d->m_timer,SIGNAL(timeout()), d, SLOT(finished()));
00060 d->m_browser=b;
00061 d->m_timer.start(TIMEOUT_LAN);
00062 }
00063
00064 void ServiceTypeBrowserPrivate::finished()
00065 {
00066 m_timer.stop();
00067 emit m_parent->finished();
00068 }
00069
00070 void ServiceTypeBrowserPrivate::gotNewServiceType(int,int,const QString& type,const QString&,uint)
00071 {
00072 m_timer.start(TIMEOUT_LAN);
00073 m_servicetypes+=type;
00074 emit m_parent->serviceTypeAdded(type);
00075 }
00076
00077
00078
00079 void ServiceTypeBrowserPrivate::gotRemoveServiceType(int,int,const QString& type,const QString&,uint)
00080 {
00081 m_timer.start(TIMEOUT_LAN);
00082 m_servicetypes.removeAll(type);
00083 emit m_parent->serviceTypeRemoved(type);
00084 }
00085
00086
00087 QStringList ServiceTypeBrowser::serviceTypes() const
00088 {
00089 return d->m_servicetypes;
00090 }
00091
00092 bool ServiceTypeBrowser::isRunning() const
00093 {
00094 return d->m_started;
00095 }
00096
00097
00098 }
00099 #include "servicetypebrowser.moc"
00100 #include "avahi-servicetypebrowser_p.moc"