1 /* This file is part of the KDE Project
2 Copyright (c) 2004 Jakub Stachowski <qbast@go2.pl>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #include "dnssdwatcher.h"
20 #include "kdnssdadaptor.h"
25 #include <dnssd/servicebrowser.h>
28 #include <kpluginfactory.h>
29 #include <kpluginloader.h>
31 K_PLUGIN_FACTORY(DNSSDWatcherFactory
,
32 registerPlugin
<DNSSDWatcher
>();
34 K_EXPORT_PLUGIN(DNSSDWatcherFactory("dnssdwatcher"))
36 DNSSDWatcher::DNSSDWatcher(QObject
* parent
, const QList
<QVariant
>&)
39 QDBusConnection::sessionBus().connect(QString(), QString(), "org.kde.KDirNotify",
40 "enteredDirectory", this, SLOT(enteredDirectory(QString
)));
41 QDBusConnection::sessionBus().connect(QString(), QString(), "org.kde.KDirNotify",
42 "leftDirectory", this, SLOT(leftDirectory(QString
)));
43 new KdnssdAdaptor( this );
46 QStringList
DNSSDWatcher::watchedDirectories()
48 return watchers
.keys();
53 void DNSSDWatcher::dissect(const KUrl
& url
,QString
& name
,QString
& type
,QString
& domain
)
55 type
= url
.path().section("/",1,1);
57 name
= url
.path().section("/",2,-1);
62 void DNSSDWatcher::enteredDirectory(const QString
& _dir
)
65 if (dir
.protocol()!="zeroconf") return;
66 if (watchers
.contains(dir
.url()))
67 watchers
[dir
.url()]->refcount
++;
73 void DNSSDWatcher::leftDirectory(const QString
& _dir
)
76 if (dir
.protocol()!="zeroconf") return;
77 Watcher
* watcher
= watchers
.value(dir
.url());
79 if (watcher
->refcount
==1) {
81 watchers
.remove(dir
.url());
88 void DNSSDWatcher::createNotifier(const KUrl
& url
)
90 QString domain
,type
,name
;
91 dissect(url
,name
,type
,domain
);
92 Watcher
*w
= new Watcher(type
,domain
);
93 watchers
.insert(url
.url(),w
);
96 DNSSDWatcher::~DNSSDWatcher()
98 qDeleteAll( watchers
);
101 #include "dnssdwatcher.moc"