• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

DNSSD

avahi-domainbrowser.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002  *
00003  * Copyright (C) 2004 Jakub Stachowski <qbast@go2.pl>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public License
00016  * along with this library; see the file COPYING.LIB.  If not, write to
00017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019  */
00020 
00021 
00022 #include "avahi-domainbrowser_p.h"
00023 #include <QtCore/QSet>
00024 #include <QtCore/QFile>
00025 #include <QtCore/QIODevice>
00026 #include <kstandarddirs.h>
00027 #include <avahi-common/defs.h>
00028 #include "avahi_server_interface.h"
00029 #include "domainbrowser.h"
00030 #include "avahi_domainbrowser_interface.h"
00031 
00032 
00033 
00034 #ifndef KDE_USE_FINAL
00035 Q_DECLARE_METATYPE(QList<QByteArray>)
00036 #endif
00037 namespace DNSSD
00038 {
00039 
00040 DomainBrowser::DomainBrowser(DomainType type, QObject *parent) : QObject(parent), d(new DomainBrowserPrivate(type,this))
00041 {}
00042 
00043 DomainBrowser::~DomainBrowser()
00044 {
00045     delete d;
00046 }
00047 
00048 
00049 void DomainBrowser::startBrowse()
00050 {
00051     if (d->m_started) return;
00052     d->m_started=true;
00053     org::freedesktop::Avahi::Server s("org.freedesktop.Avahi","/",QDBusConnection::systemBus());
00054     QDBusReply<QDBusObjectPath> rep=s.DomainBrowserNew(-1, -1, "", (d->m_type==Browsing) ? 
00055         AVAHI_DOMAIN_BROWSER_BROWSE : AVAHI_DOMAIN_BROWSER_REGISTER,0);
00056     
00057     if (!rep.isValid()) return;
00058     org::freedesktop::Avahi::DomainBrowser *b=new org::freedesktop::Avahi::DomainBrowser("org.freedesktop.Avahi",rep.value().path(),
00059         QDBusConnection::systemBus());
00060     connect(b,SIGNAL(ItemNew(int,int,const QString&,uint)),d, SLOT(gotNewDomain(int,int,const QString&, uint)));
00061     connect(b,SIGNAL(ItemRemove(int,int,const QString&,uint)),d, SLOT(gotRemoveDomain(int,int,const QString&, uint)));
00062     d->m_browser=b;
00063     if (d->m_type==Browsing) {  
00064             QString domains_evar=qgetenv("AVAHI_BROWSE_DOMAINS");
00065         if (!domains_evar.isEmpty()) {
00066         QStringList edomains=domains_evar.split(':');
00067         Q_FOREACH(const QString &s, edomains) d->gotNewDomain(-1,-1,s,0);
00068         }
00069         KStandardDirs dirs;
00070         //FIXME: watch this file and restart browser if it changes
00071         QFile domains_cfg(dirs.localxdgconfdir()+"/avahi/browse-domains");
00072         if (domains_cfg.open(QIODevice::ReadOnly | QIODevice::Text)) 
00073         while (!domains_cfg.atEnd()) d->gotNewDomain(-1,-1,QString::fromUtf8(domains_cfg.readLine().data()).trimmed(),0);
00074         
00075     }
00076                 
00077 }
00078 
00079 void DomainBrowserPrivate::gotNewDomain(int,int,const QString& domain,uint)
00080 {
00081     QString decoded=DNSToDomain(domain);
00082     if (m_domains.contains(decoded)) return;
00083     m_domains+=decoded;
00084     emit m_parent->domainAdded(decoded);
00085 }
00086 
00087 void DomainBrowserPrivate::gotRemoveDomain(int,int,const QString& domain,uint)
00088 {
00089     QString decoded=DNSToDomain(domain);
00090     if (!m_domains.contains(decoded)) return;
00091     emit m_parent->domainRemoved(decoded);
00092     m_domains.remove(decoded);
00093 }
00094 
00095 
00096 QStringList DomainBrowser::domains() const
00097 {
00098     return d->m_domains.values();
00099 }
00100 
00101 bool DomainBrowser::isRunning() const
00102 {
00103     return d->m_started;
00104 }
00105 
00106 
00107 }
00108 #include "domainbrowser.moc"
00109 #include "avahi-domainbrowser_p.moc"

DNSSD

Skip menu "DNSSD"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal