Improve coding style

This commit is contained in:
Vladimir Golovnev (Glassez) 2020-11-16 10:02:11 +03:00
parent acad35c5bc
commit c41df9ffbd
No known key found for this signature in database
GPG key ID: 52A2C7DEE2DFA6F7
147 changed files with 4454 additions and 2227 deletions

View file

@ -168,7 +168,8 @@ void AdvancedSettings::saveAdvancedSettings()
#if defined(Q_OS_WIN)
BitTorrent::OSMemoryPriority prio = BitTorrent::OSMemoryPriority::Normal;
switch (m_comboBoxOSMemoryPriority.currentIndex()) {
switch (m_comboBoxOSMemoryPriority.currentIndex())
{
case 0:
default:
prio = BitTorrent::OSMemoryPriority::Normal;
@ -248,12 +249,14 @@ void AdvancedSettings::saveAdvancedSettings()
pref->resolvePeerCountries(m_checkBoxResolveCountries.isChecked());
pref->resolvePeerHostNames(m_checkBoxResolveHosts.isChecked());
// Network interface
if (m_comboBoxInterface.currentIndex() == 0) {
if (m_comboBoxInterface.currentIndex() == 0)
{
// All interfaces (default)
session->setNetworkInterface(QString());
session->setNetworkInterfaceName(QString());
}
else {
else
{
session->setNetworkInterface(m_comboBoxInterface.itemData(m_comboBoxInterface.currentIndex()).toString());
session->setNetworkInterfaceName(m_comboBoxInterface.currentText());
}
@ -336,21 +339,25 @@ void AdvancedSettings::updateInterfaceAddressCombo()
const auto populateCombo = [this](const QHostAddress &addr)
{
if (addr.protocol() == QAbstractSocket::IPv4Protocol) {
if (addr.protocol() == QAbstractSocket::IPv4Protocol)
{
const QString str = addr.toString();
m_comboBoxInterfaceAddress.addItem(str, str);
}
else if (addr.protocol() == QAbstractSocket::IPv6Protocol) {
else if (addr.protocol() == QAbstractSocket::IPv6Protocol)
{
const QString str = Utils::Net::canonicalIPv6Addr(addr).toString();
m_comboBoxInterfaceAddress.addItem(str, str);
}
};
if (ifaceName.isEmpty()) {
if (ifaceName.isEmpty())
{
for (const QHostAddress &addr : asConst(QNetworkInterface::allAddresses()))
populateCombo(addr);
}
else {
else
{
const QNetworkInterface iface = QNetworkInterface::interfaceFromName(ifaceName);
const QList<QNetworkAddressEntry> addresses = iface.addressEntries();
for (const QNetworkAddressEntry &entry : addresses)
@ -386,7 +393,8 @@ void AdvancedSettings::loadAdvancedSettings()
#if defined(Q_OS_WIN)
m_comboBoxOSMemoryPriority.addItems({tr("Normal"), tr("Below normal"), tr("Medium"), tr("Low"), tr("Very low")});
int OSMemoryPriorityIndex = 0;
switch (session->getOSMemoryPriority()) {
switch (session->getOSMemoryPriority())
{
default:
case BitTorrent::OSMemoryPriority::Normal:
OSMemoryPriorityIndex = 0;
@ -580,16 +588,19 @@ void AdvancedSettings::loadAdvancedSettings()
const QString currentInterface = session->networkInterface();
bool interfaceExists = currentInterface.isEmpty();
int i = 1;
for (const QNetworkInterface &iface : asConst(QNetworkInterface::allInterfaces())) {
for (const QNetworkInterface &iface : asConst(QNetworkInterface::allInterfaces()))
{
m_comboBoxInterface.addItem(iface.humanReadableName(), iface.name());
if (!currentInterface.isEmpty() && (iface.name() == currentInterface)) {
if (!currentInterface.isEmpty() && (iface.name() == currentInterface))
{
m_comboBoxInterface.setCurrentIndex(i);
interfaceExists = true;
}
++i;
}
// Saved interface does not exist, show it anyway
if (!interfaceExists) {
if (!interfaceExists)
{
m_comboBoxInterface.addItem(session->networkInterfaceName(), currentInterface);
m_comboBoxInterface.setCurrentIndex(i);
}