1
/* This file is part of the KDE project
3
* Copyright (C) 2004 Jakub Stachowski <qbast@go2.pl>
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.
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.
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.
21
#include "avahi-domainbrowser_p.h"
22
#include <QtCore/QSet>
23
#include <QtCore/QFile>
24
#include <QtCore/QIODevice>
25
#include <QtCore/QStandardPaths>
26
#include <avahi-common/defs.h>
27
#include "avahi_server_interface.h"
28
#include "domainbrowser.h"
29
#include "avahi_domainbrowser_interface.h"
34
DomainBrowser::DomainBrowser(DomainType type, QObject *parent) : QObject(parent), d(new DomainBrowserPrivate(type, this))
37
DomainBrowser::~DomainBrowser()
42
void DomainBrowser::startBrowse()
48
org::freedesktop::Avahi::Server s("org.freedesktop.Avahi", "/", QDBusConnection::systemBus());
49
QDBusReply<QDBusObjectPath> rep = s.DomainBrowserNew(-1, -1, "", (d->m_type == Browsing) ?
50
AVAHI_DOMAIN_BROWSER_BROWSE : AVAHI_DOMAIN_BROWSER_REGISTER, 0);
55
org::freedesktop::Avahi::DomainBrowser *b = new org::freedesktop::Avahi::DomainBrowser("org.freedesktop.Avahi", rep.value().path(),
56
QDBusConnection::systemBus());
57
connect(b, SIGNAL(ItemNew(int,int,QString,uint)), d, SLOT(gotNewDomain(int,int,QString,uint)));
58
connect(b, SIGNAL(ItemRemove(int,int,QString,uint)), d, SLOT(gotRemoveDomain(int,int,QString,uint)));
60
if (d->m_type == Browsing) {
61
QString domains_evar = qgetenv("AVAHI_BROWSE_DOMAINS");
62
if (!domains_evar.isEmpty()) {
63
QStringList edomains = domains_evar.split(':');
64
Q_FOREACH (const QString &s, edomains) {
65
d->gotNewDomain(-1, -1, s, 0);
68
//FIXME: watch this file and restart browser if it changes
69
QString confDir = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
70
QFile domains_cfg(confDir + "/avahi/browse-domains");
71
if (domains_cfg.open(QIODevice::ReadOnly | QIODevice::Text))
72
while (!domains_cfg.atEnd()) {
73
d->gotNewDomain(-1, -1, QString::fromUtf8(domains_cfg.readLine().data()).trimmed(), 0);
80
void DomainBrowserPrivate::gotNewDomain(int, int, const QString &domain, uint)
82
QString decoded = DNSToDomain(domain);
83
if (m_domains.contains(decoded)) {
87
emit m_parent->domainAdded(decoded);
90
void DomainBrowserPrivate::gotRemoveDomain(int, int, const QString &domain, uint)
92
QString decoded = DNSToDomain(domain);
93
if (!m_domains.contains(decoded)) {
96
emit m_parent->domainRemoved(decoded);
97
m_domains.remove(decoded);
100
QStringList DomainBrowser::domains() const
102
return d->m_domains.values();
105
bool DomainBrowser::isRunning() const
111
#include "moc_domainbrowser.cpp"
112
#include "moc_avahi-domainbrowser_p.cpp"