diff options
Diffstat (limited to 'kdnssd/kdedmodule')
-rw-r--r-- | kdnssd/kdedmodule/Makefile.am | 13 | ||||
-rw-r--r-- | kdnssd/kdedmodule/dnssdwatcher.cpp | 94 | ||||
-rw-r--r-- | kdnssd/kdedmodule/dnssdwatcher.desktop | 94 | ||||
-rw-r--r-- | kdnssd/kdedmodule/dnssdwatcher.h | 49 | ||||
-rw-r--r-- | kdnssd/kdedmodule/watcher.cpp | 72 | ||||
-rw-r--r-- | kdnssd/kdedmodule/watcher.h | 50 |
6 files changed, 372 insertions, 0 deletions
diff --git a/kdnssd/kdedmodule/Makefile.am b/kdnssd/kdedmodule/Makefile.am new file mode 100644 index 00000000..c01297db --- /dev/null +++ b/kdnssd/kdedmodule/Makefile.am @@ -0,0 +1,13 @@ +kde_module_LTLIBRARIES = kded_dnssdwatcher.la + +METASOURCES = AUTO +INCLUDES = $(all_includes) + +kded_dnssdwatcher_la_SOURCES = dnssdwatcher.cpp dnssdwatcher.skel watcher.cpp +kded_dnssdwatcher_la_LDFLAGS = $(all_libraries) -module -avoid-version +kded_dnssdwatcher_la_LIBADD = $(LIB_KDNSSD) $(LIB_KIO) + + +servicesdir = $(kde_servicesdir)/kded +services_DATA = dnssdwatcher.desktop + diff --git a/kdnssd/kdedmodule/dnssdwatcher.cpp b/kdnssd/kdedmodule/dnssdwatcher.cpp new file mode 100644 index 00000000..5647d29c --- /dev/null +++ b/kdnssd/kdedmodule/dnssdwatcher.cpp @@ -0,0 +1,94 @@ +/* This file is part of the KDE Project + Copyright (c) 2004 Jakub Stachowski <qbast@go2.pl> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include "dnssdwatcher.h" + +#include <kdebug.h> +#include <kglobal.h> +#include <klocale.h> +#include <dnssd/servicebrowser.h> +#include <kdirnotify_stub.h> +#include "watcher.h" + + +DNSSDWatcher::DNSSDWatcher(const QCString& obj) + : KDEDModule(obj) +{ + connectDCOPSignal("","KDirNotify","enteredDirectory(KURL)","enteredDirectory(KURL)",false); + connectDCOPSignal("","KDirNotify","leftDirectory(KURL)","leftDirectory(KURL)",false); + watchers.setAutoDelete(true); +} + +QStringList DNSSDWatcher::watchedDirectories() +{ +//TODO +// return watchers.keys(); + QStringList keys; + for (QDictIterator<Watcher> it(watchers) ; it.current(); ++it ) { + keys << it.currentKey(); + kdDebug() << it.currentKey() << " " << (*it)->refcount << "\n"; + } +return keys; +} + + +// from ioslave +void DNSSDWatcher::dissect(const KURL& url,QString& name,QString& type,QString& domain) +{ + type = url.path().section("/",1,1); + domain = url.host(); + name = url.path().section("/",2,-1); +} + + + +void DNSSDWatcher::enteredDirectory(const KURL& dir) +{ + if (dir.protocol()!="zeroconf") return; + if (watchers[dir.url()]) watchers[dir.url()]->refcount++; + else createNotifier(dir); +} + + +void DNSSDWatcher::leftDirectory(const KURL& dir) +{ + if (dir.protocol()!="zeroconf") return; + if (!watchers[dir.url()]) return; + if ((watchers[dir.url()])->refcount==1) watchers.remove(dir.url()); + else watchers[dir.url()]->refcount--; +} + + +void DNSSDWatcher::createNotifier(const KURL& url) +{ + QString domain,type,name; + dissect(url,name,type,domain); + if (type.isEmpty()) type = DNSSD::ServiceBrowser::AllServices; + Watcher *w = new Watcher(type,domain); + watchers.insert(url.url(),w); +} + +extern "C" { + KDE_EXPORT KDEDModule *create_dnssdwatcher(const QCString &obj) + { + KGlobal::locale()->insertCatalogue("dnssdwatcher"); + return new DNSSDWatcher(obj); + } +} + +#include "dnssdwatcher.moc" diff --git a/kdnssd/kdedmodule/dnssdwatcher.desktop b/kdnssd/kdedmodule/dnssdwatcher.desktop new file mode 100644 index 00000000..31e7640e --- /dev/null +++ b/kdnssd/kdedmodule/dnssdwatcher.desktop @@ -0,0 +1,94 @@ +[Desktop Entry] +Type=Service +Name=DNS-SD Services Watcher +Name[be]=Аглядальнік сервісаў DNS-SD +Name[bn]=ডিএনএস-এসডি সার্ভিস পর্যবেক্ষক +Name[bs]=Nadzor DNS-SD servisa +Name[ca]=Vigilant de serveis DNS-SD +Name[cs]=Sledování DNS-SD služeb +Name[da]=DNS-SD overvågning af tjenester +Name[de]=Überwachung von DNS-SD-Diensten +Name[el]=Παρατηρητής υπηρεσιών DNS-SD +Name[es]=Observador de servicios DNS-SD +Name[et]=DNS-SD teenuste jälgija +Name[eu]=DNS-SD zerbitzu jarraitzailea +Name[fa]=پایندۀ خدمات DNS-SD +Name[fi]=DNS-SD-palvelujen tarkkailija +Name[fr]=Surveillance des services DNS-SD +Name[gl]=Observador de Servicios DNS-SD +Name[hu]=DNS-SD szolgáltatásfigyelő +Name[is]=DNS-SD þjónustuvaktari +Name[it]=Sentinella dei servizi DNS-SD +Name[ja]=DNS-SD サービス監視 +Name[ka]=DNS-SD სერვისების მეთვალყურე +Name[kk]=DNS-SD қызметтер бақылаушысы +Name[km]=កម្មវិធីឃ្លាំមើលសេវា DNS-SD +Name[lt]=DNS-SD tarnybos stebėjimas +Name[nb]=Overvåker for DNS-SD-tjenester +Name[nds]=DNS-SD-Deenstkieker +Name[ne]=DNS-SD सेवा दर्शक +Name[nl]=DNS-SD-diensten observatie +Name[nn]=DNS-SD-tenesteovervakar +Name[pa]=DNS-SD ਸੇਵਾਵਾਂ ਵਾਂਚਰ +Name[pl]=Nadzorca usług DNS-SD +Name[pt]=Vigia de Serviços DNS-SD +Name[pt_BR]=Monitor dos Serviços DNS-SD +Name[ru]=Служба DNS-SD +Name[sk]=Sledovač DNS-SD služieb +Name[sl]=Opazovalec storitev DNS-SD +Name[sr]=Пратилац DNS-SD сервиса +Name[sr@Latn]=Pratilac DNS-SD servisa +Name[sv]=DNS-SD tjänstbevakning +Name[tr]=DNS-SD Servisi İzleyicisi +Name[uk]=Спостереження за службами DNS-SD +Name[zh_CN]=DNS-SD 服务监视器 +Name[zh_HK]=DNS-SD 服務監察器 +Name[zh_TW]=DNS-SD 服務監看器 +Comment=Keeps track of DNS-SD services and updates directory listings +Comment[be]=Назірае за спісам сервісаў DNS-SD і абнаўляе выгляд дырэкторыяў +Comment[bn]=ডিএনএস-এসডি সার্ভিসের খোঁজ রাখে এবং ডিরেক্টরী তালিকা আপডেট করে +Comment[bs]=Prati DNS-SD servise i ažurira spiskove direktorija +Comment[ca]=Segueix els serveis DNS-SD i actualitza les llistes de directoris +Comment[cs]=Udržuje přehled o DNS-SD službách a aktualizuje výpisy adresářů +Comment[da]=Holder styr på DNS-SD-tjenester og opdaterer lister med mapper +Comment[de]=Überwacht DNS-SD-Dienste und aktualisiert Verzeichniseinträge +Comment[el]=Διατηρεί το ίχνος των υπηρεσιών του DNS-SD και ενημερώνει τις λίστες του καταλόγου +Comment[es]=Vigila los servicios DNS-SD y actualiza los listados de directorio +Comment[et]=Jälgib DNS-SD teenuseid ja uuendab kataloogide nimekirju +Comment[eu]=DNS-SD zerbitzuak jarraitu eta direktorio zerrendak eguneratzen ditu +Comment[fa]=رد خدمات DNS-SD را نگهداری میکند و فهرست برنامههای فهرست راهنما را بهروزرسانی میکند +Comment[fi]=Pitää kirjaa DNS-SD-palveluista ja päivittää kansiolistaukset +Comment[fr]=Conserve une trace des services DNS-SD et actualise les listes de dossiers +Comment[gl]=Deixa constancia dos servicios DNS-SD e anova as listaxes de directorios +Comment[hu]=Követi a DNS-SD szolgáltatások állapotát és frissíti a hálózati listákat +Comment[is]=Fylgist með DNS-SD þjónustum og uppfærir möppulista +Comment[it]=Mantiene traccia dei servizi DNS-SD e aggiorna le liste delle directory +Comment[ja]=DNS-SD サービスの管理とディレクトリ一覧の更新 +Comment[ka]=DNS-SD სერვისების ჩანაწერების შენახვა და დირექტორიის ჩამონათვლის განახლება +Comment[kk]=DNS-SD қызметтердің протоколын жүргізіп, каталогын жаңарту +Comment[km]=តាមដានសេវា DNS-SD និងធ្វើឲ្យការរាយថតទាន់សម័យ +Comment[lt]=Seka DNS-SD tarnybas ir atnaujina aplankų sąrašus +Comment[nb]=Holder øye med DNS-SD-tjenester og oppdaterer katalogoppføringer +Comment[nds]=Kiekt na DNS-SD-Deensten un frischt Orneroplisten op +Comment[ne]=DNS-SD सेवाको ट्रयाक राख्दछ र डाइरेक्टरी सूची अद्यावधिक गर्दछ +Comment[nl]=Houdt de DNS-SD-diensten bij en actualiseert mappenweergaven +Comment[nn]=Held auge med DNS-SD-tenester og oppdaterer katalogar +Comment[pl]=Śledzi usługi DNS-SD services i uaktualnia zawartość katalogu +Comment[pt]=Vigia os serviços DNS-SD e actualiza listas de pastas +Comment[pt_BR]=Monitora os serviços DNS-SD +Comment[ru]=Обновление каталогов DNS-SD +Comment[sk]=Sleduje DNS-SD služby a aktualizuje výpisy priečinku +Comment[sl]=Spremlja storitve DNS-SD in posodablja sezname imenikov +Comment[sr]=Надгледа DNS-SD сервисе и ажурира листинге директоријума +Comment[sr@Latn]=Nadgleda DNS-SD servise i ažurira listinge direktorijuma +Comment[sv]=Håller ordning på DNS-SD tjänster och uppdaterar kataloglistor +Comment[tr]=DNS-SD servisi ve klasör listesini güncelleyisi +Comment[uk]=Спостерігає за службами DNS-SD та оновлює списки каталогів +Comment[zh_CN]=跟踪 DNS-SD 服务并更新目录列表 +Comment[zh_HK]=監察 DNS-SD 服務並更新目錄清單 +Comment[zh_TW]=追蹤 DNS-SD 服務並更新目錄清單 +ServiceTypes=KDEDModule +X-KDE-ModuleType=Library +X-KDE-Library=dnssdwatcher +X-KDE-FactoryName=dnssdwatcher +X-KDE-Kded-autoload=true diff --git a/kdnssd/kdedmodule/dnssdwatcher.h b/kdnssd/kdedmodule/dnssdwatcher.h new file mode 100644 index 00000000..e624532a --- /dev/null +++ b/kdnssd/kdedmodule/dnssdwatcher.h @@ -0,0 +1,49 @@ +/* This file is part of the KDE Project + Copyright (c) 2004 Jakub Stachowski <qbast@go2.pl> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef _DNSSDWATCHER_H_ +#define _DNSSDWATCHER_H_ + +#include <qdict.h> +#include <kdedmodule.h> +#include <qstring.h> +#include <qstringlist.h> +#include <kurl.h> + +class Watcher; +class DNSSDWatcher : public KDEDModule +{ +Q_OBJECT +K_DCOP +public: + DNSSDWatcher(const QCString& obj); + +k_dcop: + QStringList watchedDirectories(); + void enteredDirectory(const KURL& dir); + void leftDirectory(const KURL& dir); + +private: + QDict<Watcher> watchers; + + void createNotifier(const KURL& url); + void dissect(const KURL& url,QString& name,QString& type,QString& domain); + +}; + +#endif diff --git a/kdnssd/kdedmodule/watcher.cpp b/kdnssd/kdedmodule/watcher.cpp new file mode 100644 index 00000000..9fc32b14 --- /dev/null +++ b/kdnssd/kdedmodule/watcher.cpp @@ -0,0 +1,72 @@ +/* This file is part of the KDE Project + Copyright (c) 2004 Jakub Stachowski <qbast@go2.pl> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include "watcher.h" + +#include <kdebug.h> + +#include <kdirnotify_stub.h> +#include <qstringlist.h> + + + +Watcher::Watcher(const QString& type, const QString& domain) + : refcount(1), updateNeeded(false), m_type(type), m_domain(domain) +{ + if (domain.isEmpty()) browser = new ServiceBrowser(type); + else browser = new ServiceBrowser(type,domain); + connect(browser,SIGNAL(serviceAdded(DNSSD::RemoteService::Ptr)), + SLOT(serviceAdded(DNSSD::RemoteService::Ptr))); + connect(browser,SIGNAL(serviceRemoved(DNSSD::RemoteService::Ptr)), + SLOT(serviceRemoved(DNSSD::RemoteService::Ptr))); + connect(browser,SIGNAL(finished()),SLOT(finished())); + browser->startBrowse(); +} + +Watcher::~Watcher() +{ + delete browser; +} + +void Watcher::serviceAdded(DNSSD::RemoteService::Ptr) +{ + updateNeeded=true; +} + +void Watcher::serviceRemoved(DNSSD::RemoteService::Ptr srv) +{ + if (!updateNeeded) removed << srv; +} + + +void Watcher::finished() +{ + KDirNotify_stub st("*","*"); + kdDebug() << "Finished for " << m_type << "@" << m_domain << "\n"; + if (updateNeeded || removed.count()) { + QString url = "zeroconf:/"; + if (!m_domain.isEmpty()) url+="/"+m_domain+"/"; + if (m_type!=ServiceBrowser::AllServices) url+=m_type; + kdDebug() << "Sending update: " << url << "\n"; + st.FilesAdded(url); + } + removed.clear(); + updateNeeded=false; +} + +#include "watcher.moc" diff --git a/kdnssd/kdedmodule/watcher.h b/kdnssd/kdedmodule/watcher.h new file mode 100644 index 00000000..703680fc --- /dev/null +++ b/kdnssd/kdedmodule/watcher.h @@ -0,0 +1,50 @@ +/* This file is part of the KDE Project + Copyright (c) 2004 Jakub Stachowski <qbast@go2.pl> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef _WATCHER_H_ +#define _WATCHER_H_ + +#include <qstring.h> +#include <dnssd/servicebrowser.h> +#include <dnssd/remoteservice.h> + +using namespace DNSSD; + +class Watcher : public QObject +{ +Q_OBJECT +public: + Watcher(const QString& type, const QString& domain); + ~Watcher(); + + unsigned int refcount; +private: + ServiceBrowser* browser; + bool updateNeeded; + QString m_type; + QString m_domain; + QValueList<DNSSD::RemoteService::Ptr> removed; + +private slots: + void serviceRemoved(DNSSD::RemoteService::Ptr srv); + void serviceAdded(DNSSD::RemoteService::Ptr); + void finished(); + +}; + +#endif |