diff --git a/libguh/network/avahi/guhavahibrowser.cpp b/libguh/network/avahi/guhavahibrowser.cpp index 524e206d..2e95d9eb 100644 --- a/libguh/network/avahi/guhavahibrowser.cpp +++ b/libguh/network/avahi/guhavahibrowser.cpp @@ -1,7 +1,44 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2016 Simon Stürz * + * * + * This file is part of guh. * + * * + * Guh is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, version 2 of the License. * + * * + * Guh 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with guh. If not, see . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + #include "guhavahibrowser.h" +#include "loggingcategories.h" GuhAvahiBrowser::GuhAvahiBrowser(QObject *parent) : QObject(parent) { + m_browser = new ZConfServiceBrowser(this); + connect(m_browser, &ZConfServiceBrowser::serviceEntryAdded, this, &GuhAvahiBrowser::onSeviceAdded); + connect(m_browser, &ZConfServiceBrowser::serviceEntryRemoved, this, &GuhAvahiBrowser::onSeviceRemoved); + connect(m_browser, &ZConfServiceBrowser::serviceBrowsingFinished, this, &GuhAvahiBrowser::onSeviceBrowsingFinished); +} + +void GuhAvahiBrowser::browseService(const QString &serviceType) +{ + m_serviceEntries.clear(); + m_browser->browse(serviceType); +} + +void GuhAvahiBrowser::onSeviceBrowsingFinished() +{ + + emit avahiBrowseFinished(m_serviceEntries); } diff --git a/libguh/network/avahi/guhavahibrowser.h b/libguh/network/avahi/guhavahibrowser.h index f30c7f16..688c4fba 100644 --- a/libguh/network/avahi/guhavahibrowser.h +++ b/libguh/network/avahi/guhavahibrowser.h @@ -1,17 +1,50 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2016 Simon Stürz * + * * + * This file is part of guh. * + * * + * Guh is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, version 2 of the License. * + * * + * Guh 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with guh. If not, see . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + #ifndef GUHAVAHIBROWSER_H #define GUHAVAHIBROWSER_H #include +#include "zconfservicebrowser.h" + class GuhAvahiBrowser : public QObject { Q_OBJECT public: explicit GuhAvahiBrowser(QObject *parent = 0); -signals: + void browseService(const QString &serviceType); + +private: + ZConfServiceBrowser *m_browser; + QList m_serviceEntries; + +signals: + void avahiBrowseFinished(const QList &serviceEntries); + +private slots: + void onSeviceAdded(const QString &name); + void onSeviceRemoved(const QString &name); + void onSeviceBrowsingFinished(); -public slots: }; #endif // GUHAVAHIBROWSER_H diff --git a/libguh/network/avahi/zconfservicebrowser.cpp b/libguh/network/avahi/zconfservicebrowser.cpp index 2c1f8901..9eb43d70 100644 --- a/libguh/network/avahi/zconfservicebrowser.cpp +++ b/libguh/network/avahi/zconfservicebrowser.cpp @@ -53,6 +53,7 @@ public: switch (event) { case AVAHI_BROWSER_FAILURE: qDebug() << ("Avahi browser error: " % QString(avahi_strerror(avahi_client_errno(serviceBrowser->d_ptr->client->client)))); + emit serviceBrowser->serviceBrowsingFinished(); break; case AVAHI_BROWSER_NEW: qDebug() << ("New service '" % QString(name) % "' of type " % QString(type) % " in domain " % QString(domain) % "."); @@ -76,14 +77,13 @@ public: case AVAHI_BROWSER_REMOVE: serviceBrowser->d_ptr->entries.remove(name); emit serviceBrowser->serviceEntryRemoved(name); - qDebug() << "Service '" % QString(name) % "' removed from the network."; break; case AVAHI_BROWSER_ALL_FOR_NOW: + emit serviceBrowser->serviceBrowsingFinished(); + break; case AVAHI_BROWSER_CACHE_EXHAUSTED: - qDebug() << (AVAHI_BROWSER_ALL_FOR_NOW == event - ? "AVAHI_BROWSER_ALL_FOR_NOW" - : "AVAHI_BROWSER_CACHE_EXHAUSTED"); - } // end switch + break; + } } } diff --git a/libguh/network/avahi/zconfservicebrowser.h b/libguh/network/avahi/zconfservicebrowser.h index f952408b..3859a84b 100644 --- a/libguh/network/avahi/zconfservicebrowser.h +++ b/libguh/network/avahi/zconfservicebrowser.h @@ -43,6 +43,7 @@ public: signals: void serviceEntryAdded(const QString &name); void serviceEntryRemoved(const QString &name); + void serviceBrowsingFinished(); private slots: void createServiceBrowser();