qcp/libqcp/qcp.cpp

55 lines
1.3 KiB
C++
Raw Normal View History

2010-07-24 16:16:44 +00:00
#include "qcp.h"
#define SERVICETYPE "_qcp._tcp"
namespace QCP {
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) {
ShareDetails *details = createDetails(s);
if (!details) return;
2010-07-24 16:16:44 +00:00
ShareData *sd = new ShareData();
sd->details = details;
2010-07-24 16:16:44 +00:00
s.setData(sd);
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) {
emit lost(Share(s));
sd->data = 0;
2010-07-24 16:16:44 +00:00
delete sd;
}
}
}