Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace QString::fromAscii by QString::fromLatin1 #356

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix -WConversion warnings in SettingsDialog
Fix various conversion warnings, between long long, double, unsigned
short and so on...
howetuft committed Oct 13, 2019

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 71f29ff8c29cd1f533e3935612908df7d9936506
9 changes: 9 additions & 0 deletions src/MEGASync/control/Utilities.cpp
Original file line number Diff line number Diff line change
@@ -641,3 +641,12 @@ QString Utilities::getDefaultBasePath()
return QString();
}

int Utilities::percentage(long long val, long long total)
{
auto aval = abs(val);
auto atotal = abs(total);

return (aval >= atotal) ? 100 : static_cast<int>(aval / (total / 100));
// static_cast to int is always safe because, when applied, result is always lower than 100...

}
1 change: 1 addition & 0 deletions src/MEGASync/control/Utilities.h
Original file line number Diff line number Diff line change
@@ -69,6 +69,7 @@ class Utilities
static QString extractJSONString(QString json, QString name);
static long long extractJSONNumber(QString json, QString name);
static QString getDefaultBasePath();
static int percentage(long long val, long long total);

private:
Utilities() {}
26 changes: 13 additions & 13 deletions src/MEGASync/gui/SettingsDialog.cpp
Original file line number Diff line number Diff line change
@@ -1172,7 +1172,7 @@ void SettingsDialog::loadSettings()
}
else
{
double totalBandwidth = preferences->totalBandwidth();
auto totalBandwidth = preferences->totalBandwidth();
if (totalBandwidth == 0)
{
ui->gBandwidthQuota->hide();
@@ -1185,9 +1185,9 @@ void SettingsDialog::loadSettings()
{
ui->gBandwidthQuota->show();
ui->bSeparatorBandwidth->show();
int bandwidthPercentage = floor(100*((double)preferences->usedBandwidth()/preferences->totalBandwidth()));
auto bandwidthPercentage = Utilities::percentage(preferences->usedBandwidth(),preferences->totalBandwidth());
ui->pUsedBandwidth->show();
ui->pUsedBandwidth->setValue((bandwidthPercentage < 100) ? bandwidthPercentage : 100);
ui->pUsedBandwidth->setValue(bandwidthPercentage);
ui->lBandwidth->setText(tr("%1 (%2%) of %3 used")
.arg(Utilities::getSizeString(preferences->usedBandwidth()))
.arg(QString::number(bandwidthPercentage))
@@ -1291,11 +1291,11 @@ void SettingsDialog::refreshAccountDetails()
}
else
{
int percentage = floor(100*((double)preferences->usedStorage()/preferences->totalStorage()));
ui->pStorage->setValue((percentage < 100) ? percentage : 100);
auto percentage = Utilities::percentage(preferences->usedStorage(),preferences->totalStorage());
ui->pStorage->setValue(percentage);
ui->lStorage->setText(tr("%1 (%2%) of %3 used")
.arg(Utilities::getSizeString(preferences->usedStorage()))
.arg(QString::number(percentage > 100 ? 100 : percentage))
.arg(QString::number(percentage))
.arg(Utilities::getSizeString(preferences->totalStorage())));
}
}
@@ -1314,11 +1314,11 @@ void SettingsDialog::refreshAccountDetails()
}
else
{
int percentage = floor(100*((double)preferences->usedBandwidth()/preferences->totalBandwidth()));
ui->pUsedBandwidth->setValue((percentage < 100) ? percentage : 100);
auto percentage = Utilities::percentage(preferences->usedBandwidth(),preferences->totalBandwidth());
ui->pUsedBandwidth->setValue(percentage);
ui->lBandwidth->setText(tr("%1 (%2%) of %3 used")
.arg(Utilities::getSizeString(preferences->usedBandwidth()))
.arg(QString::number(percentage > 100 ? 100 : percentage))
.arg(QString::number(percentage))
.arg(Utilities::getSizeString(preferences->totalBandwidth())));
}
}
@@ -1677,7 +1677,7 @@ int SettingsDialog::saveSettings()
}

proxy.setHostName(ui->eProxyServer->text().trimmed());
proxy.setPort(ui->eProxyPort->text().trimmed().toInt());
proxy.setPort(ui->eProxyPort->text().trimmed().toUShort());
if (ui->cProxyRequiresPassword->isChecked())
{
proxy.setUser(ui->eProxyUsername->text());
@@ -1706,7 +1706,7 @@ int SettingsDialog::saveSettings()
if (arguments.size() == 2)
{
proxy.setHostName(arguments[0]);
proxy.setPort(arguments[1].toInt());
proxy.setPort(arguments[1].toUShort());
}
}
delete proxySettings;
@@ -2263,7 +2263,7 @@ QString SettingsDialog::getFormatString()

if (hasLowerLimit)
{
format += QString::fromUtf8("<") + Utilities::getSizeString(lowerLimit * pow((float)1024, lowerLimitUnit));
format += QString::fromUtf8("<") + Utilities::getSizeString(lowerLimit * (1 << (10 * lowerLimitUnit)));
}

if (hasLowerLimit && hasUpperLimit)
@@ -2273,7 +2273,7 @@ QString SettingsDialog::getFormatString()

if (hasUpperLimit)
{
format += QString::fromUtf8(">") + Utilities::getSizeString(upperLimit * pow((float)1024, upperLimitUnit));
format += QString::fromUtf8(">") + Utilities::getSizeString(upperLimit * (1 << (10 * upperLimitUnit)));
}

format += QString::fromUtf8(")");