5
5
6
6
#include " ConnectDialog.h"
7
7
8
- #ifdef USE_BONJOUR
9
- # include " BonjourClient.h"
10
- # include " BonjourServiceBrowser.h"
11
- # include " BonjourServiceResolver.h"
8
+ #ifdef USE_ZEROCONF
9
+ # include " Zeroconf.h"
12
10
#endif
13
11
14
12
#include " Channel.h"
@@ -102,7 +100,7 @@ ServerView::ServerView(QWidget *p) : QTreeWidget(p) {
102
100
siFavorite->setExpanded (true );
103
101
siFavorite->setHidden (true );
104
102
105
- #ifdef USE_BONJOUR
103
+ #ifdef USE_ZEROCONF
106
104
siLAN = new ServerItem (tr (" LAN" ), ServerItem::LANType);
107
105
addTopLevelItem (siLAN);
108
106
siLAN->setExpanded (true );
@@ -220,10 +218,10 @@ ServerItem::ServerItem(const FavoriteServer &fs) : QTreeWidgetItem(QTreeWidgetIt
220
218
qsUrl = fs.qsUrl ;
221
219
222
220
bCA = false ;
223
- #ifdef USE_BONJOUR
221
+ #ifdef USE_ZEROCONF
224
222
if (fs.qsHostname .startsWith (QLatin1Char (' @' ))) {
225
- qsBonjourHost = fs.qsHostname .mid (1 );
226
- brRecord = BonjourRecord (qsBonjourHost , QLatin1String (" _mumble._tcp." ), QLatin1String (" local." ));
223
+ zeroconfHost = fs.qsHostname .mid (1 );
224
+ zeroconfRecord = BonjourRecord (zeroconfHost , QLatin1String (" _mumble._tcp." ), QLatin1String (" local." ));
227
225
} else {
228
226
qsHostname = fs.qsHostname ;
229
227
}
@@ -261,10 +259,10 @@ ServerItem::ServerItem(const QString &name, const QString &host, unsigned short
261
259
qsPassword = password;
262
260
263
261
bCA = false ;
264
- #ifdef USE_BONJOUR
262
+ #ifdef USE_ZEROCONF
265
263
if (host.startsWith (QLatin1Char (' @' ))) {
266
- qsBonjourHost = host.mid (1 );
267
- brRecord = BonjourRecord (qsBonjourHost , QLatin1String (" _mumble._tcp." ), QLatin1String (" local." ));
264
+ zeroconfHost = host.mid (1 );
265
+ zeroconfRecord = BonjourRecord (zeroconfHost , QLatin1String (" _mumble._tcp." ), QLatin1String (" local." ));
268
266
} else {
269
267
qsHostname = host;
270
268
}
@@ -274,16 +272,16 @@ ServerItem::ServerItem(const QString &name, const QString &host, unsigned short
274
272
init ();
275
273
}
276
274
277
- #ifdef USE_BONJOUR
275
+ #ifdef USE_ZEROCONF
278
276
ServerItem::ServerItem (const BonjourRecord &br) : QTreeWidgetItem(QTreeWidgetItem::UserType) {
279
- siParent = nullptr ;
280
- bParent = false ;
281
- itType = LANType;
282
- qsName = br.serviceName ;
283
- qsBonjourHost = qsName;
284
- brRecord = br;
285
- usPort = 0 ;
286
- bCA = false ;
277
+ siParent = nullptr ;
278
+ bParent = false ;
279
+ itType = LANType;
280
+ qsName = br.serviceName ;
281
+ zeroconfHost = qsName;
282
+ zeroconfRecord = br;
283
+ usPort = 0 ;
284
+ bCA = false ;
287
285
288
286
init ();
289
287
}
@@ -314,9 +312,9 @@ ServerItem::ServerItem(const ServerItem *si) {
314
312
qsCountryCode = si->qsCountryCode ;
315
313
qsContinentCode = si->qsContinentCode ;
316
314
qsUrl = si->qsUrl ;
317
- #ifdef USE_BONJOUR
318
- qsBonjourHost = si->qsBonjourHost ;
319
- brRecord = si->brRecord ;
315
+ #ifdef USE_ZEROCONF
316
+ zeroconfHost = si->zeroconfHost ;
317
+ zeroconfRecord = si->zeroconfRecord ;
320
318
#endif
321
319
qlAddresses = si->qlAddresses ;
322
320
bCA = si->bCA ;
@@ -490,10 +488,10 @@ QVariant ServerItem::data(int column, int role) const {
490
488
.arg (ConnectDialog::tr (" Servername" ), qsName.toHtmlEscaped ())
491
489
+ QString::fromLatin1 (" <tr><th align=left>%1</th><td>%2</td></tr>" )
492
490
.arg (ConnectDialog::tr (" Hostname" ), qsHostname.toHtmlEscaped ());
493
- #ifdef USE_BONJOUR
494
- if (!qsBonjourHost .isEmpty ())
491
+ #ifdef USE_ZEROCONF
492
+ if (!zeroconfHost .isEmpty ())
495
493
qs += QString::fromLatin1 (" <tr><th align=left>%1</th><td>%2</td></tr>" )
496
- .arg (ConnectDialog::tr (" Bonjour name" ), qsBonjourHost .toHtmlEscaped ());
494
+ .arg (ConnectDialog::tr (" Bonjour name" ), zeroconfHost .toHtmlEscaped ());
497
495
#endif
498
496
qs += QString::fromLatin1 (" <tr><th align=left>%1</th><td>%2</td></tr>" )
499
497
.arg (ConnectDialog::tr (" Port" ))
@@ -592,9 +590,9 @@ void ServerItem::setDatas(double elapsed, quint32 users, quint32 maxusers) {
592
590
FavoriteServer ServerItem::toFavoriteServer () const {
593
591
FavoriteServer fs;
594
592
fs.qsName = qsName;
595
- #ifdef USE_BONJOUR
596
- if (!qsBonjourHost .isEmpty ())
597
- fs.qsHostname = QLatin1Char (' @' ) + qsBonjourHost ;
593
+ #ifdef USE_ZEROCONF
594
+ if (!zeroconfHost .isEmpty ())
595
+ fs.qsHostname = QLatin1Char (' @' ) + zeroconfHost ;
598
596
else
599
597
fs.qsHostname = qsHostname;
600
598
#else
@@ -944,7 +942,7 @@ ConnectDialog::ConnectDialog(QWidget *p, bool autoconnect) : QDialog(p), bAutoCo
944
942
945
943
bAllowPing = g.s .ptProxyType == Settings::NoProxy;
946
944
bAllowHostLookup = g.s .ptProxyType == Settings::NoProxy;
947
- bAllowBonjour = g.s .ptProxyType == Settings::NoProxy;
945
+ bAllowZeroconf = g.s .ptProxyType == Settings::NoProxy;
948
946
bAllowFilters = g.s .ptProxyType == Settings::NoProxy;
949
947
950
948
if (tPublicServers.elapsed () >= 60 * 24 * 1000000ULL ) {
@@ -1033,22 +1031,16 @@ ConnectDialog::ConnectDialog(QWidget *p, bool autoconnect) : QDialog(p), bAutoCo
1033
1031
startDns (si);
1034
1032
qtwServers->siFavorite ->addServerItem (si);
1035
1033
}
1034
+ #ifdef USE_ZEROCONF
1035
+ if (bAllowZeroconf && g.zeroconf && g.zeroconf ->isOk ()) {
1036
+ connect (g.zeroconf , &Zeroconf::recordsChanged, this , &ConnectDialog::onUpdateLanList);
1037
+ connect (g.zeroconf , &Zeroconf::recordResolved, this , &ConnectDialog::onResolved);
1038
+ connect (g.zeroconf , &Zeroconf::resolveError, this , &ConnectDialog::onLanResolveError);
1039
+ onUpdateLanList (g.zeroconf ->currentRecords ());
1036
1040
1037
- #ifdef USE_BONJOUR
1038
- // Make sure the we got the objects we need, then wire them up
1039
- if (bAllowBonjour && g.bc ->bsbBrowser && g.bc ->bsrResolver ) {
1040
- connect (g.bc ->bsbBrowser .data (), SIGNAL (error (DNSServiceErrorType)), this ,
1041
- SLOT (onLanBrowseError (DNSServiceErrorType)));
1042
- connect (g.bc ->bsbBrowser .data (), SIGNAL (currentBonjourRecordsChanged (const QList< BonjourRecord > &)), this ,
1043
- SLOT (onUpdateLanList (const QList< BonjourRecord > &)));
1044
- connect (g.bc ->bsrResolver .data (), SIGNAL (error (BonjourRecord, DNSServiceErrorType)), this ,
1045
- SLOT (onLanResolveError (BonjourRecord, DNSServiceErrorType)));
1046
- connect (g.bc ->bsrResolver .data (), SIGNAL (bonjourRecordResolved (BonjourRecord, QString, int )), this ,
1047
- SLOT (onResolved (BonjourRecord, QString, int )));
1048
- onUpdateLanList (g.bc ->bsbBrowser ->currentRecords ());
1041
+ g.zeroconf ->startBrowser (QLatin1String (" _mumble._tcp" ));
1049
1042
}
1050
1043
#endif
1051
-
1052
1044
qtPingTick = new QTimer (this );
1053
1045
connect (qtPingTick, SIGNAL (timeout ()), this , SLOT (timeTick ()));
1054
1046
@@ -1082,6 +1074,12 @@ ConnectDialog::ConnectDialog(QWidget *p, bool autoconnect) : QDialog(p), bAutoCo
1082
1074
}
1083
1075
1084
1076
ConnectDialog::~ConnectDialog () {
1077
+ #ifdef USE_ZEROCONF
1078
+ if (bAllowZeroconf && g.zeroconf && g.zeroconf ->isOk ()) {
1079
+ g.zeroconf ->stopBrowser ();
1080
+ g.zeroconf ->cleanupResolvers ();
1081
+ }
1082
+ #endif
1085
1083
ServerItem::qmIcons.clear ();
1086
1084
1087
1085
QList< FavoriteServer > ql;
@@ -1175,9 +1173,9 @@ void ConnectDialog::on_qaFavoriteEdit_triggered() {
1175
1173
return ;
1176
1174
1177
1175
QString host;
1178
- #ifdef USE_BONJOUR
1179
- if (!si->qsBonjourHost .isEmpty ())
1180
- host = QLatin1Char (' @' ) + si->qsBonjourHost ;
1176
+ #ifdef USE_ZEROCONF
1177
+ if (!si->zeroconfHost .isEmpty ())
1178
+ host = QLatin1Char (' @' ) + si->zeroconfHost ;
1181
1179
else
1182
1180
host = si->qsHostname ;
1183
1181
#else
@@ -1196,16 +1194,16 @@ void ConnectDialog::on_qaFavoriteEdit_triggered() {
1196
1194
si->reset ();
1197
1195
1198
1196
si->usPort = cde->usPort ;
1199
- #ifdef USE_BONJOUR
1197
+ #ifdef USE_ZEROCONF
1200
1198
if (cde->qsHostname .startsWith (QLatin1Char (' @' ))) {
1201
- si->qsHostname = QString ();
1202
- si->qsBonjourHost = cde->qsHostname .mid (1 );
1203
- si->brRecord =
1204
- BonjourRecord (si->qsBonjourHost , QLatin1String (" _mumble._tcp." ), QLatin1String (" local." ));
1199
+ si->qsHostname = QString ();
1200
+ si->zeroconfHost = cde->qsHostname .mid (1 );
1201
+ si->zeroconfRecord =
1202
+ BonjourRecord (si->zeroconfHost , QLatin1String (" _mumble._tcp." ), QLatin1String (" local." ));
1205
1203
} else {
1206
- si->qsHostname = cde->qsHostname ;
1207
- si->qsBonjourHost = QString ();
1208
- si->brRecord = BonjourRecord ();
1204
+ si->qsHostname = cde->qsHostname ;
1205
+ si->zeroconfHost = QString ();
1206
+ si->zeroconfRecord = BonjourRecord ();
1209
1207
}
1210
1208
#else
1211
1209
si->qsHostname = cde->qsHostname ;
@@ -1355,11 +1353,11 @@ void ConnectDialog::initList() {
1355
1353
WebFetch::fetch (QLatin1String (" publist" ), url, this , SLOT (fetched (QByteArray, QUrl, QMap< QString, QString >)));
1356
1354
}
1357
1355
1358
- #ifdef USE_BONJOUR
1359
- void ConnectDialog::onResolved (BonjourRecord record, QString host, int port) {
1356
+ #ifdef USE_ZEROCONF
1357
+ void ConnectDialog::onResolved (const BonjourRecord record, const QString host, const uint16_t port) {
1360
1358
qlBonjourActive.removeAll (record);
1361
1359
foreach (ServerItem *si, qlItems) {
1362
- if (si->brRecord == record) {
1360
+ if (si->zeroconfRecord == record) {
1363
1361
unsigned short usport = static_cast < unsigned short >(port);
1364
1362
if ((host != si->qsHostname ) || (usport != si->usPort )) {
1365
1363
stopDns (si);
@@ -1384,7 +1382,7 @@ void ConnectDialog::onUpdateLanList(const QList< BonjourRecord > &list) {
1384
1382
foreach (const BonjourRecord &record, list) {
1385
1383
bool found = false ;
1386
1384
foreach (ServerItem *si, old) {
1387
- if (si->brRecord == record) {
1385
+ if (si->zeroconfRecord == record) {
1388
1386
items.insert (si);
1389
1387
found = true ;
1390
1388
break ;
@@ -1393,7 +1391,7 @@ void ConnectDialog::onUpdateLanList(const QList< BonjourRecord > &list) {
1393
1391
if (!found) {
1394
1392
ServerItem *si = new ServerItem (record);
1395
1393
qlItems << si;
1396
- g.bc -> bsrResolver -> resolveBonjourRecord (record);
1394
+ g.zeroconf -> startResolver (record);
1397
1395
startDns (si);
1398
1396
qtwServers->siLAN ->addServerItem (si);
1399
1397
}
@@ -1406,13 +1404,8 @@ void ConnectDialog::onUpdateLanList(const QList< BonjourRecord > &list) {
1406
1404
}
1407
1405
}
1408
1406
1409
- void ConnectDialog::onLanBrowseError (DNSServiceErrorType err) {
1410
- qWarning () << " Bonjour reported browser error " << err;
1411
- }
1412
-
1413
- void ConnectDialog::onLanResolveError (BonjourRecord br, DNSServiceErrorType err) {
1414
- qlBonjourActive.removeAll (br);
1415
- qWarning () << " Bonjour reported resolver error " << err;
1407
+ void ConnectDialog::onLanResolveError (const BonjourRecord record) {
1408
+ qlBonjourActive.removeAll (record);
1416
1409
}
1417
1410
#endif
1418
1411
@@ -1627,17 +1620,15 @@ void ConnectDialog::startDns(ServerItem *si) {
1627
1620
foreach (const ServerAddress &addr, si->qlAddresses ) { qhPings[addr].insert (si); }
1628
1621
return ;
1629
1622
}
1630
-
1631
- #ifdef USE_BONJOUR
1632
- if (bAllowBonjour && si->qsHostname .isEmpty () && !si->brRecord .serviceName .isEmpty ()) {
1633
- if (!qlBonjourActive.contains (si->brRecord )) {
1634
- g.bc ->bsrResolver ->resolveBonjourRecord (si->brRecord );
1635
- qlBonjourActive.append (si->brRecord );
1623
+ #ifdef USE_ZEROCONF
1624
+ if (bAllowZeroconf && si->qsHostname .isEmpty () && !si->zeroconfRecord .serviceName .isEmpty ()) {
1625
+ if (!qlBonjourActive.contains (si->zeroconfRecord )) {
1626
+ g.zeroconf ->startResolver (si->zeroconfRecord );
1627
+ qlBonjourActive.append (si->zeroconfRecord );
1636
1628
}
1637
1629
return ;
1638
1630
}
1639
1631
#endif
1640
-
1641
1632
if (!qhDNSWait.contains (unresolved)) {
1642
1633
if (si->itType == ServerItem::PublicType)
1643
1634
qlDNSLookup.append (unresolved);
0 commit comments