Completely change the behavior of entering special keys (like Ctrl+Alt+Del). Do not...
[kdenetwork.git] / kdnssd / kdedmodule / dnssdwatcher.cpp
blob06ed1a661905ac97e99f0c2e5d14b445cd539091
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"
22 #include <kdebug.h>
23 #include <kglobal.h>
24 #include <klocale.h>
25 #include <dnssd/servicebrowser.h>
26 #include "watcher.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>&)
37 : KDEDModule(parent)
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();
52 // from ioslave
53 void DNSSDWatcher::dissect(const KUrl& url,QString& name,QString& type,QString& domain)
55 type = url.path().section("/",1,1);
56 domain = url.host();
57 name = url.path().section("/",2,-1);
62 void DNSSDWatcher::enteredDirectory(const QString& _dir)
64 KUrl dir(_dir);
65 if (dir.protocol()!="zeroconf") return;
66 if (watchers.contains(dir.url()))
67 watchers[dir.url()]->refcount++;
68 else
69 createNotifier(dir);
73 void DNSSDWatcher::leftDirectory(const QString& _dir)
75 KUrl dir(_dir);
76 if (dir.protocol()!="zeroconf") return;
77 Watcher* watcher = watchers.value(dir.url());
78 if (!watcher) return;
79 if (watcher->refcount==1) {
80 delete watcher;
81 watchers.remove(dir.url());
82 } else {
83 watcher->refcount--;
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"