2010-07-24 16:16:44 +00:00
|
|
|
#include "qcp.h"
|
|
|
|
|
|
|
|
#define SERVICETYPE "_qcp._tcp"
|
|
|
|
|
|
|
|
namespace QCP {
|
2010-07-25 12:29:01 +00:00
|
|
|
|
|
|
|
class ShareFile : public QCP::ShareDetails {
|
|
|
|
public:
|
|
|
|
ShareFile(const Avahi::Service &s) : ShareDetails(s) {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual QString methodName() { return "File"; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
QCP::ShareDetails *createDetails(const Avahi::Service &s) {
|
|
|
|
QString methodName = s.txt("m");
|
|
|
|
|
|
|
|
if (methodName == "file") {
|
|
|
|
return new ShareFile(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "Unknown share method: " << methodName;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-07-24 16:16:44 +00:00
|
|
|
Browse::Browse(QObject *parent)
|
|
|
|
: QObject(parent), m_av_browse(new Avahi::Browse(SERVICETYPE, this)) {
|
|
|
|
connect(m_av_browse, SIGNAL(found(Avahi::Service)), this, SLOT(foundService(Avahi::Service)));
|
|
|
|
connect(m_av_browse, SIGNAL(lost(Avahi::Service)), this, SLOT(lostService(Avahi::Service)));
|
|
|
|
connect(m_av_browse, SIGNAL(started()), this, SIGNAL(started()));
|
|
|
|
connect(m_av_browse, SIGNAL(stopped()), this, SIGNAL(stopped()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Browse::foundService(Avahi::Service s) {
|
2010-07-25 12:29:01 +00:00
|
|
|
ShareDetails *details = createDetails(s);
|
|
|
|
if (!details) return;
|
|
|
|
|
2010-07-24 16:16:44 +00:00
|
|
|
ShareData *sd = new ShareData();
|
2010-07-25 12:29:01 +00:00
|
|
|
sd->details = details;
|
|
|
|
|
2010-07-24 16:16:44 +00:00
|
|
|
s.setData(sd);
|
2010-07-25 12:29:01 +00:00
|
|
|
emit found(Share(s));
|
2010-07-24 16:16:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Browse::lostService(Avahi::Service s) {
|
|
|
|
ShareData *sd = shareData(s);
|
|
|
|
if (0 != sd) {
|
2010-07-25 12:29:01 +00:00
|
|
|
emit lost(Share(s));
|
|
|
|
sd->data = 0;
|
2010-07-24 16:16:44 +00:00
|
|
|
delete sd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|