bool PublicService::publish() { publishAsync(); while(d->isRunning() && !d->m_published) d->process(); return d->m_published; }
void PublicService::setType(const QString &type) { m_type = type; if(d->isRunning()) { stop(); publishAsync(); } }
void PublicService::setDomain(const QString &domain) { m_domain = domain; if(d->isRunning()) { stop(); publishAsync(); } }
void PublicService::setServiceName(const QString &serviceName) { m_serviceName = serviceName; if(d->isRunning()) { stop(); publishAsync(); } }
void PublicService::setTextData(const QMap< QString, QString > &textData) { m_textData = textData; if(d->isRunning()) { stop(); publishAsync(); } }
void PublicService::setPort(unsigned short port) { m_port = port; if(d->isRunning()) { stop(); publishAsync(); } }
void PublicService::setSubTypes(const QStringList& subtypes) { K_D; d->m_subtypes = subtypes; if (d->isRunning()) { stop(); publishAsync(); } }
int ServerThread::startServer(const QString &title) { _startmutex.lock(); start(); _starter.wait(&_startmutex); _startmutex.unlock(); #ifdef HAVE_DNSSD // Publish this server via DNS-SD. // Note: this code runs in the main thread if(_port>0) { QSettings cfg; if(cfg.value("settings/server/dnssd", true).toBool()) { qDebug("Announcing server (port %d) via DNSSD", _port); auto dnssd = new KDNSSD::PublicService( QString(), "_drawpile._tcp", _port, "local" ); dnssd->setParent(this); QMap<QString,QByteArray> txt; txt["protocol"] = QStringLiteral(DRAWPILE_PROTO_STR).toUtf8(); txt["started"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate).toUtf8(); txt["title"] = title.toUtf8(); dnssd->setTextData(txt); dnssd->publishAsync(); } } #endif #ifdef HAVE_UPNP if(_port>0) { QSettings cfg; if(cfg.value("settings/server/upnp", true).toBool()) { QString myIp = WhatIsMyIp::localAddress(); if(WhatIsMyIp::isMyPrivateAddress(myIp)) { qDebug() << "UPnP enabled: trying to forward" << _port << "to" << myIp; UPnPClient::instance()->activateForward(_port); _portForwarded = true; } } } #endif return _port; }