|
|
@ -106,7 +106,7 @@ AdvancedSettings::AdvancedSettings(QWidget *parent) |
|
|
|
setEditTriggers(QAbstractItemView::NoEditTriggers); |
|
|
|
setEditTriggers(QAbstractItemView::NoEditTriggers); |
|
|
|
// Signals
|
|
|
|
// Signals
|
|
|
|
connect(&spin_cache, SIGNAL(valueChanged(int)), SLOT(updateCacheSpinSuffix(int))); |
|
|
|
connect(&spin_cache, SIGNAL(valueChanged(int)), SLOT(updateCacheSpinSuffix(int))); |
|
|
|
connect(&combo_iface, SIGNAL(currentIndexChanged(int)), SLOT(updateInterfaceAddressCombo(int))); |
|
|
|
connect(&combo_iface, SIGNAL(currentIndexChanged(int)), SLOT(updateInterfaceAddressCombo())); |
|
|
|
// Load settings
|
|
|
|
// Load settings
|
|
|
|
loadAdvancedSettings(); |
|
|
|
loadAdvancedSettings(); |
|
|
|
resizeColumnToContents(0); |
|
|
|
resizeColumnToContents(0); |
|
|
@ -156,11 +156,7 @@ void AdvancedSettings::saveAdvancedSettings() |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
QHostAddress ifaceAddr(combo_iface_address.currentText().trimmed()); |
|
|
|
QHostAddress ifaceAddr(combo_iface_address.currentText().trimmed()); |
|
|
|
if (ifaceAddr.isNull()) { |
|
|
|
ifaceAddr.isNull() ? pref->setNetworkInterfaceAddress(QString::null) : pref->setNetworkInterfaceAddress(ifaceAddr.toString()); |
|
|
|
pref->setNetworkInterfaceAddress(QString::null); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
pref->setNetworkInterfaceAddress(ifaceAddr.toString()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// Network Announce address
|
|
|
|
// Network Announce address
|
|
|
|
QHostAddress networkAddr(txt_network_address.text().trimmed()); |
|
|
|
QHostAddress networkAddr(txt_network_address.text().trimmed()); |
|
|
@ -197,41 +193,39 @@ void AdvancedSettings::updateCacheSpinSuffix(int value) |
|
|
|
spin_cache.setSuffix(tr(" MiB")); |
|
|
|
spin_cache.setSuffix(tr(" MiB")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void AdvancedSettings::updateInterfaceAddressCombo(int) { |
|
|
|
void AdvancedSettings::updateInterfaceAddressCombo() |
|
|
|
|
|
|
|
{ |
|
|
|
// Try to get the currently selected interface name
|
|
|
|
// Try to get the currently selected interface name
|
|
|
|
QString ifaceName; |
|
|
|
const QString ifaceName = combo_iface.itemData(combo_iface.currentIndex()).toString(); // Empty string for the first element
|
|
|
|
if (combo_iface.currentIndex() == 0) { |
|
|
|
const QString currentAddress = Preferences::instance()->getNetworkInterfaceAddress(); |
|
|
|
ifaceName = QString(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
ifaceName = combo_iface.itemData(combo_iface.currentIndex()).toString(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const QNetworkInterface iface = QNetworkInterface::interfaceFromName(ifaceName); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Clear all items and reinsert them, default to all
|
|
|
|
//Clear all items and reinsert them, default to all
|
|
|
|
combo_iface_address.clear(); |
|
|
|
combo_iface_address.clear(); |
|
|
|
combo_iface_address.addItem(tr("All Addresses")); |
|
|
|
combo_iface_address.addItem(tr("All addresses")); |
|
|
|
combo_iface_address.setCurrentIndex(0); |
|
|
|
combo_iface_address.setCurrentIndex(0); |
|
|
|
if (!iface.isValid()) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//Found a valid interface, try to get the addresses
|
|
|
|
|
|
|
|
const QList<QNetworkAddressEntry> addresses = iface.addressEntries(); |
|
|
|
|
|
|
|
const Preferences* const pref = Preferences::instance(); |
|
|
|
|
|
|
|
const QString currentAddress = pref->getNetworkInterfaceAddress(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (const QNetworkAddressEntry &entry, addresses) { |
|
|
|
auto populateCombo = [this, ¤tAddress](const QString &ip, const QAbstractSocket::NetworkLayerProtocol &protocol) |
|
|
|
QHostAddress ip = entry.ip(); |
|
|
|
{ |
|
|
|
QString ipString = ip.toString(); |
|
|
|
|
|
|
|
QAbstractSocket::NetworkLayerProtocol protocol = ip.protocol(); |
|
|
|
|
|
|
|
Q_ASSERT(protocol == QAbstractSocket::IPv4Protocol || protocol == QAbstractSocket::IPv6Protocol); |
|
|
|
Q_ASSERT(protocol == QAbstractSocket::IPv4Protocol || protocol == QAbstractSocket::IPv6Protocol); |
|
|
|
//Only take ipv4 for now?
|
|
|
|
//Only take ipv4 for now?
|
|
|
|
if (protocol != QAbstractSocket::IPv4Protocol) |
|
|
|
if (protocol != QAbstractSocket::IPv4Protocol && protocol != QAbstractSocket::IPv6Protocol) |
|
|
|
continue; |
|
|
|
return; |
|
|
|
combo_iface_address.addItem( ipString ); |
|
|
|
combo_iface_address.addItem(ip); |
|
|
|
//Try to select the last added one
|
|
|
|
//Try to select the last added one
|
|
|
|
if (ipString == currentAddress) { |
|
|
|
if (ip == currentAddress) |
|
|
|
combo_iface_address.setCurrentIndex(combo_iface_address.count() - 1); |
|
|
|
combo_iface_address.setCurrentIndex(combo_iface_address.count() - 1); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ifaceName.isEmpty()) { |
|
|
|
|
|
|
|
foreach (const QHostAddress &ip, QNetworkInterface::allAddresses()) |
|
|
|
|
|
|
|
populateCombo(ip.toString(), ip.protocol()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
const QNetworkInterface iface = QNetworkInterface::interfaceFromName(ifaceName); |
|
|
|
|
|
|
|
const QList<QNetworkAddressEntry> addresses = iface.addressEntries(); |
|
|
|
|
|
|
|
foreach (const QNetworkAddressEntry &entry, addresses) { |
|
|
|
|
|
|
|
const QHostAddress ip = entry.ip(); |
|
|
|
|
|
|
|
populateCombo(ip.toString(), ip.protocol()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -339,7 +333,7 @@ void AdvancedSettings::loadAdvancedSettings() |
|
|
|
} |
|
|
|
} |
|
|
|
addRow(NETWORK_IFACE, tr("Network Interface (requires restart)"), &combo_iface); |
|
|
|
addRow(NETWORK_IFACE, tr("Network Interface (requires restart)"), &combo_iface); |
|
|
|
// Network interface address
|
|
|
|
// Network interface address
|
|
|
|
updateInterfaceAddressCombo(combo_iface.currentIndex()); |
|
|
|
updateInterfaceAddressCombo(); |
|
|
|
addRow(NETWORK_IFACE_ADDRESS, tr("Optional IP Address to bind to (requires restart)"), &combo_iface_address); |
|
|
|
addRow(NETWORK_IFACE_ADDRESS, tr("Optional IP Address to bind to (requires restart)"), &combo_iface_address); |
|
|
|
// Listen on IPv6 address
|
|
|
|
// Listen on IPv6 address
|
|
|
|
cb_listen_ipv6.setChecked(pref->getListenIPv6()); |
|
|
|
cb_listen_ipv6.setChecked(pref->getListenIPv6()); |
|
|
|