File indexing completed on 2024-04-28 15:22:06

0001 /*
0002     This file is part of the KDE project
0003 
0004     SPDX-FileCopyrightText: 2004 Jakub Stachowski <qbast@go2.pl>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef KDNSSDDOMAINBROWSER_H
0010 #define KDNSSDDOMAINBROWSER_H
0011 
0012 #include "remoteservice.h"
0013 #include <QObject>
0014 #include <QtContainerFwd>
0015 #include <memory>
0016 
0017 namespace KDNSSD
0018 {
0019 class DomainBrowserPrivate;
0020 
0021 /**
0022  * @class DomainBrowser domainbrowser.h KDNSSD/DomainBrowser
0023  * @short Browses recommended domains for browsing or publishing to.
0024  *
0025  * Usage of this class is very simple.  If you are interested in
0026  * browsing for services, simple do
0027  * @code
0028  * KDNSSD::DomainBrowser *browser =
0029  *     new KDNSSD::DomainBrowser(KDNSSD::DomainBrowser::Browsing, this);
0030  * connect(browser, SIGNAL(domainAdded(QString)),
0031  *         this, SLOT(browsingDomainAdded(QString));
0032  * connect(browser, SIGNAL(domainRemoved(QString)),
0033  *         this, SLOT(browsingDomainRemove(QString));
0034  * browser->startBrowse();
0035  * @endcode
0036  *
0037  * If you are interested in domains where you can register services,
0038  * usage is identical except that you should pass
0039  * <tt>KDNSSD::DomainBrowser::Registering</tt> to the constructor.
0040  *
0041  * @author Jakub Stachowski
0042  */
0043 class KDNSSD_EXPORT DomainBrowser : public QObject
0044 {
0045     Q_OBJECT
0046 public:
0047     /**
0048      * A type of domain recommendation
0049      */
0050     enum DomainType {
0051         /** Domains recommended for browsing for services on (using ServiceBrowser) */
0052         Browsing,
0053         /** Domains recommended for publishing to (using PublicService) */
0054         Publishing,
0055     };
0056     /**
0057      * Standard constructor
0058      *
0059      * The global DNS-SD configuration (for example, the global Avahi
0060      * configuration for the Avahi backend) will be used.
0061      *
0062      * @param type   the type of domain to search for
0063      * @param parent parent object (see QObject documentation)
0064      *
0065      * @see startBrowse() and ServiceBrowser::isAvailable()
0066      */
0067     explicit DomainBrowser(DomainType type, QObject *parent = nullptr);
0068 
0069     ~DomainBrowser() override;
0070 
0071     /**
0072      * The current known list of domains of the requested DomainType
0073      *
0074      * @return a list of currently known domain names
0075      */
0076     QStringList domains() const;
0077 
0078     /**
0079      * Starts browsing
0080      *
0081      * Only the first call to this function will have any effect.
0082      *
0083      * Browsing stops when the DomainBrowser object is destroyed.
0084      *
0085      * @warning The domainAdded() signal may be emitted before this
0086      *          function returns.
0087      *
0088      * @see domainAdded() and domainRemoved()
0089      */
0090     void startBrowse();
0091 
0092     /**
0093      * Whether the browsing has been started
0094      *
0095      * @return @c true if startBrowse() has been called, @c false otherwise
0096      */
0097     bool isRunning() const;
0098 
0099 Q_SIGNALS:
0100     /**
0101      * A domain has disappeared from the browsed list
0102      *
0103      * Emitted when domain has been removed from browsing list
0104      * or the publishing list (depending on which list was
0105      * requested in the constructor).
0106      *
0107      * @param domain the name of the domain
0108      *
0109      * @see domainAdded()
0110      */
0111     void domainRemoved(const QString &domain);
0112 
0113     /**
0114      * A new domain has been discovered
0115      *
0116      * If the requested DomainType is Browsing, this will
0117      * also be emitted for the domains specified in the
0118      * global configuration.
0119      *
0120      * @param domain the name of the domain
0121      *
0122      * @see domainRemoved()
0123      */
0124     void domainAdded(const QString &domain);
0125 
0126 private:
0127     friend class DomainBrowserPrivate;
0128     std::unique_ptr<DomainBrowserPrivate> const d;
0129     Q_DECLARE_PRIVATE_D(d, DomainBrowser)
0130 };
0131 
0132 }
0133 
0134 #endif