1 | /* This file is part of the KDE project |
2 | * |
3 | * Copyright (C) 2004,2007 Jakub Stachowski <qbast@go2.pl> |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Library General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the License, or (at your option) any later version. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Library General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Library General Public License |
16 | * along with this library; see the file COPYING.LIB. If not, write to |
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | * Boston, MA 02110-1301, USA. |
19 | */ |
20 | |
21 | |
22 | #include "avahi-servicetypebrowser_p.h" |
23 | #include <QtCore/QSet> |
24 | #include "avahi_server_interface.h" |
25 | #include "servicetypebrowser.h" |
26 | #include "avahi_servicetypebrowser_interface.h" |
27 | |
28 | #define UNSPEC -1 |
29 | #ifndef KDE_USE_FINAL |
30 | Q_DECLARE_METATYPE(QList<QByteArray>) |
31 | #endif |
32 | namespace DNSSD |
33 | { |
34 | |
35 | ServiceTypeBrowser::ServiceTypeBrowser(const QString& domain, QObject *parent) : QObject(parent), d(new ServiceTypeBrowserPrivate(this)) |
36 | { |
37 | d->m_domain=domain; |
38 | d->m_timer.setSingleShot(true); |
39 | } |
40 | |
41 | ServiceTypeBrowser::~ServiceTypeBrowser() |
42 | { |
43 | delete d; |
44 | } |
45 | |
46 | void ServiceTypeBrowser::startBrowse() |
47 | { |
48 | if (d->m_started) return; |
49 | d->m_started=true; |
50 | org::freedesktop::Avahi::Server s("org.freedesktop.Avahi" ,"/" ,QDBusConnection::systemBus()); |
51 | QDBusReply<QDBusObjectPath> rep=s.ServiceTypeBrowserNew(-1, -1, d->m_domain, 0); |
52 | |
53 | if (!rep.isValid()) return; |
54 | org::freedesktop::Avahi::ServiceTypeBrowser *b=new org::freedesktop::Avahi::ServiceTypeBrowser("org.freedesktop.Avahi" ,rep.value().path(), |
55 | QDBusConnection::systemBus()); |
56 | connect(b,SIGNAL(ItemNew(int,int,QString,QString,uint)),d, SLOT(gotNewServiceType(int,int,QString,QString,uint))); |
57 | connect(b,SIGNAL(ItemRemove(int,int,QString,QString,uint)),d, SLOT(gotRemoveServiceType(int,int,QString,QString,uint))); |
58 | connect(b,SIGNAL(AllForNow()),d,SLOT(finished())); |
59 | connect(&d->m_timer,SIGNAL(timeout()), d, SLOT(finished())); |
60 | d->m_browser=b; |
61 | d->m_timer.start(domainIsLocal(d->m_domain) ? TIMEOUT_LAST_SERVICE : TIMEOUT_START_WAN); |
62 | } |
63 | |
64 | void ServiceTypeBrowserPrivate::finished() |
65 | { |
66 | m_timer.stop(); |
67 | emit m_parent->finished(); |
68 | } |
69 | |
70 | void ServiceTypeBrowserPrivate::gotNewServiceType(int,int,const QString& type,const QString&,uint) |
71 | { |
72 | m_timer.start(TIMEOUT_LAST_SERVICE); |
73 | m_servicetypes+=type; |
74 | emit m_parent->serviceTypeAdded(type); |
75 | } |
76 | |
77 | |
78 | |
79 | void ServiceTypeBrowserPrivate::gotRemoveServiceType(int,int,const QString& type,const QString&,uint) |
80 | { |
81 | m_timer.start(TIMEOUT_LAST_SERVICE); |
82 | m_servicetypes.removeAll(type); |
83 | emit m_parent->serviceTypeRemoved(type); |
84 | } |
85 | |
86 | |
87 | QStringList ServiceTypeBrowser::serviceTypes() const |
88 | { |
89 | return d->m_servicetypes; |
90 | } |
91 | |
92 | #ifndef KDE_NO_DEPRECATED |
93 | bool ServiceTypeBrowser::isRunning() const |
94 | { |
95 | return d->m_started; |
96 | } |
97 | #endif |
98 | |
99 | |
100 | } |
101 | #include "servicetypebrowser.moc" |
102 | #include "avahi-servicetypebrowser_p.moc" |
103 | |