mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-12-02 15:36:29 +00:00
Replace C-style casts with C++ ones
This commit is contained in:
parent
e3671050d1
commit
74cecb1b6c
@ -22,7 +22,7 @@ macro(qbt_set_compiler_options)
|
||||
# "-Weffc++"
|
||||
"-Werror -Wno-error=cpp"
|
||||
# we should modify code to make these ones obsolete
|
||||
"-Wno-error=old-style-cast -Wno-error=sign-conversion -Wno-error=float-equal"
|
||||
"-Wno-error=sign-conversion -Wno-error=float-equal"
|
||||
)
|
||||
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
|
||||
|
@ -33,7 +33,7 @@ static inline void print_stacktrace(FILE *out = stderr, unsigned int max_frames
|
||||
|
||||
// allocate string which will be filled with the demangled function name
|
||||
size_t funcnamesize = 256;
|
||||
char *funcname = (char *)malloc(funcnamesize);
|
||||
char *funcname = static_cast<char *>(malloc(funcnamesize));
|
||||
|
||||
int functionNamesFound = 0;
|
||||
// iterate over the returned symbol lines. skip the first, it is the
|
||||
|
@ -41,7 +41,7 @@ InfoHash::InfoHash(const libtorrent::sha1_hash &nativeHash)
|
||||
, m_nativeHash(nativeHash)
|
||||
{
|
||||
char out[(libtorrent::sha1_hash::size * 2) + 1];
|
||||
libtorrent::to_hex((char const*)&m_nativeHash[0], libtorrent::sha1_hash::size, out);
|
||||
libtorrent::to_hex(reinterpret_cast<const char*>(&m_nativeHash[0]), libtorrent::sha1_hash::size, out);
|
||||
m_hashString = QString(out);
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ InfoHash::InfoHash(const QString &hashString)
|
||||
{
|
||||
QByteArray raw = m_hashString.toLatin1();
|
||||
if (raw.size() == 40)
|
||||
m_valid = libtorrent::from_hex(raw.constData(), 40, (char*)&m_nativeHash[0]);
|
||||
m_valid = libtorrent::from_hex(raw.constData(), 40, reinterpret_cast<char*>(&m_nativeHash[0]));
|
||||
}
|
||||
|
||||
|
||||
|
@ -417,7 +417,7 @@ int FilterParserThread::parseP2BFilterFile()
|
||||
unsigned char version;
|
||||
if (!stream.readRawData(buf, sizeof(buf))
|
||||
|| memcmp(buf, "\xFF\xFF\xFF\xFFP2B", 7)
|
||||
|| !stream.readRawData((char*)&version, sizeof(version))) {
|
||||
|| !stream.readRawData(reinterpret_cast<char*>(&version), sizeof(version))) {
|
||||
LogMsg(tr("Parsing Error: The filter file is not a valid PeerGuardian P2B file."), Log::CRITICAL);
|
||||
return ruleCount;
|
||||
}
|
||||
@ -428,8 +428,8 @@ int FilterParserThread::parseP2BFilterFile()
|
||||
|
||||
std::string name;
|
||||
while(getlineInStream(stream, name, '\0') && !m_abort) {
|
||||
if (!stream.readRawData((char*)&start, sizeof(start))
|
||||
|| !stream.readRawData((char*)&end, sizeof(end))) {
|
||||
if (!stream.readRawData(reinterpret_cast<char*>(&start), sizeof(start))
|
||||
|| !stream.readRawData(reinterpret_cast<char*>(&end), sizeof(end))) {
|
||||
LogMsg(tr("Parsing Error: The filter file is not a valid PeerGuardian P2B file."), Log::CRITICAL);
|
||||
return ruleCount;
|
||||
}
|
||||
@ -450,7 +450,7 @@ int FilterParserThread::parseP2BFilterFile()
|
||||
else if (version == 3) {
|
||||
qDebug ("p2b version 3");
|
||||
unsigned int namecount;
|
||||
if (!stream.readRawData((char*)&namecount, sizeof(namecount))) {
|
||||
if (!stream.readRawData(reinterpret_cast<char*>(&namecount), sizeof(namecount))) {
|
||||
LogMsg(tr("Parsing Error: The filter file is not a valid PeerGuardian P2B file."), Log::CRITICAL);
|
||||
return ruleCount;
|
||||
}
|
||||
@ -469,7 +469,7 @@ int FilterParserThread::parseP2BFilterFile()
|
||||
|
||||
// Reading the ranges
|
||||
unsigned int rangecount;
|
||||
if (!stream.readRawData((char*)&rangecount, sizeof(rangecount))) {
|
||||
if (!stream.readRawData(reinterpret_cast<char*>(&rangecount), sizeof(rangecount))) {
|
||||
LogMsg(tr("Parsing Error: The filter file is not a valid PeerGuardian P2B file."), Log::CRITICAL);
|
||||
return ruleCount;
|
||||
}
|
||||
@ -477,9 +477,9 @@ int FilterParserThread::parseP2BFilterFile()
|
||||
rangecount = ntohl(rangecount);
|
||||
unsigned int name, start, end;
|
||||
for (unsigned int i = 0; i < rangecount; ++i) {
|
||||
if (!stream.readRawData((char*)&name, sizeof(name))
|
||||
|| !stream.readRawData((char*)&start, sizeof(start))
|
||||
|| !stream.readRawData((char*)&end, sizeof(end))) {
|
||||
if (!stream.readRawData(reinterpret_cast<char*>(&name), sizeof(name))
|
||||
|| !stream.readRawData(reinterpret_cast<char*>(&start), sizeof(start))
|
||||
|| !stream.readRawData(reinterpret_cast<char*>(&end), sizeof(end))) {
|
||||
LogMsg(tr("Parsing Error: The filter file is not a valid PeerGuardian P2B file."), Log::CRITICAL);
|
||||
return ruleCount;
|
||||
}
|
||||
|
@ -555,7 +555,7 @@ qreal TorrentHandle::progress() const
|
||||
if (m_nativeStatus.total_wanted_done == m_nativeStatus.total_wanted)
|
||||
return 1.;
|
||||
|
||||
float progress = (float) m_nativeStatus.total_wanted_done / (float) m_nativeStatus.total_wanted;
|
||||
float progress = static_cast<float>(m_nativeStatus.total_wanted_done) / m_nativeStatus.total_wanted;
|
||||
Q_ASSERT((progress >= 0.f) && (progress <= 1.f));
|
||||
return progress;
|
||||
}
|
||||
|
@ -224,7 +224,9 @@ bool FileSystemWatcher::isNetworkFileSystem(QString path)
|
||||
// XXX: should we make sure HAVE_STRUCT_FSSTAT_F_FSTYPENAME is defined?
|
||||
return ((strcmp(buf.f_fstypename, "nfs") == 0) || (strcmp(buf.f_fstypename, "cifs") == 0) || (strcmp(buf.f_fstypename, "smbfs") == 0));
|
||||
#else
|
||||
return ((buf.f_type == (long)CIFS_MAGIC_NUMBER) || (buf.f_type == (long)NFS_SUPER_MAGIC) || (buf.f_type == (long)SMB_SUPER_MAGIC));
|
||||
return ((buf.f_type == static_cast<long>(CIFS_MAGIC_NUMBER))
|
||||
|| (buf.f_type == static_cast<long>(NFS_SUPER_MAGIC))
|
||||
|| (buf.f_type == static_cast<long>(SMB_SUPER_MAGIC)));
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
|
@ -105,7 +105,7 @@ GeoIPDatabase *GeoIPDatabase::load(const QString &filename, QString &error)
|
||||
|
||||
db = new GeoIPDatabase(file.size());
|
||||
|
||||
if (file.read((char *)db->m_data, db->m_size) != db->m_size) {
|
||||
if (file.read(reinterpret_cast<char *>(db->m_data), db->m_size) != db->m_size) {
|
||||
error = file.errorString();
|
||||
delete db;
|
||||
return 0;
|
||||
@ -130,7 +130,7 @@ GeoIPDatabase *GeoIPDatabase::load(const QByteArray &data, QString &error)
|
||||
|
||||
db = new GeoIPDatabase(data.size());
|
||||
|
||||
memcpy((char *)db->m_data, data.constData(), db->m_size);
|
||||
memcpy(reinterpret_cast<char *>(db->m_data), data.constData(), db->m_size);
|
||||
|
||||
if (!db->parseMetadata(db->readMetadata(), error) || !db->loadDB(error)) {
|
||||
delete db;
|
||||
|
@ -406,12 +406,12 @@ void Preferences::setSchedulerEndTime(const QTime &time)
|
||||
|
||||
scheduler_days Preferences::getSchedulerDays() const
|
||||
{
|
||||
return (scheduler_days)value("Preferences/Scheduler/days", EVERY_DAY).toInt();
|
||||
return static_cast<scheduler_days>(value("Preferences/Scheduler/days", EVERY_DAY).toInt());
|
||||
}
|
||||
|
||||
void Preferences::setSchedulerDays(scheduler_days days)
|
||||
{
|
||||
setValue("Preferences/Scheduler/days", (int)days);
|
||||
setValue("Preferences/Scheduler/days", static_cast<int>(days));
|
||||
}
|
||||
|
||||
// Search
|
||||
|
@ -56,7 +56,7 @@ uint32_t Utils::Random::rand(const uint32_t min, const uint32_t max)
|
||||
static thread_local std::mt19937 generator{
|
||||
hasTrueRandomDevice
|
||||
? std::random_device{}()
|
||||
: (std::random_device::result_type) std::chrono::system_clock::now().time_since_epoch().count()
|
||||
: static_cast<std::random_device::result_type>(std::chrono::system_clock::now().time_since_epoch().count())
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -1092,7 +1092,7 @@ bool MainWindow::event(QEvent *e)
|
||||
if (isMinimized()) {
|
||||
qDebug("minimisation");
|
||||
if (m_systrayIcon && Preferences::instance()->minimizeToTray()) {
|
||||
qDebug("Has active window: %d", (int)(qApp->activeWindow() != 0));
|
||||
qDebug() << "Has active window:" << (qApp->activeWindow() != nullptr);
|
||||
// Check if there is a modal window
|
||||
bool hasModalWindow = false;
|
||||
foreach (QWidget *widget, QApplication::allWidgets()) {
|
||||
|
@ -37,7 +37,7 @@ MessageBoxRaised::MessageBoxRaised(QMessageBox::Icon icon, const QString &title,
|
||||
QMessageBox::StandardButton MessageBoxRaised::impl(const QMessageBox::Icon &icon, QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) {
|
||||
MessageBoxRaised dlg(icon, title, text, buttons, parent);
|
||||
dlg.setDefaultButton(defaultButton);
|
||||
return (QMessageBox::StandardButton)dlg.exec();
|
||||
return static_cast<QMessageBox::StandardButton>(dlg.exec());
|
||||
}
|
||||
|
||||
QMessageBox::StandardButton MessageBoxRaised::critical(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) {
|
||||
|
@ -577,7 +577,7 @@ void OptionsDialog::saveOptions()
|
||||
session->setBandwidthSchedulerEnabled(m_ui->check_schedule->isChecked());
|
||||
pref->setSchedulerStartTime(m_ui->schedule_from->time());
|
||||
pref->setSchedulerEndTime(m_ui->schedule_to->time());
|
||||
pref->setSchedulerDays((scheduler_days)m_ui->schedule_days->currentIndex());
|
||||
pref->setSchedulerDays(static_cast<scheduler_days>(m_ui->schedule_days->currentIndex()));
|
||||
|
||||
auto proxyConfigManager = Net::ProxyConfigurationManager::instance();
|
||||
Net::ProxyConfiguration proxyConf;
|
||||
@ -967,7 +967,7 @@ void OptionsDialog::loadOptions()
|
||||
m_ui->check_schedule->setChecked(session->isBandwidthSchedulerEnabled());
|
||||
m_ui->schedule_from->setTime(pref->getSchedulerStartTime());
|
||||
m_ui->schedule_to->setTime(pref->getSchedulerEndTime());
|
||||
m_ui->schedule_days->setCurrentIndex((int)pref->getSchedulerDays());
|
||||
m_ui->schedule_days->setCurrentIndex(static_cast<int>(pref->getSchedulerDays()));
|
||||
// End Speed preferences
|
||||
|
||||
// Bittorrent preferences
|
||||
@ -1024,7 +1024,7 @@ void OptionsDialog::loadOptions()
|
||||
m_ui->checkBypassLocalAuth->setChecked(!pref->isWebUiLocalAuthEnabled());
|
||||
|
||||
m_ui->checkDynDNS->setChecked(pref->isDynDNSEnabled());
|
||||
m_ui->comboDNSService->setCurrentIndex((int)pref->getDynDNSService());
|
||||
m_ui->comboDNSService->setCurrentIndex(static_cast<int>(pref->getDynDNSService()));
|
||||
m_ui->domainNameTxt->setText(pref->getDynDomainName());
|
||||
m_ui->DNSUsernameTxt->setText(pref->getDynDNSUsername());
|
||||
m_ui->DNSPasswordTxt->setText(pref->getDynDNSPassword());
|
||||
|
@ -117,9 +117,9 @@ void PowerManagementInhibitor::RequestBusy()
|
||||
|
||||
QList<QVariant> args;
|
||||
args << "qBittorrent";
|
||||
if (m_use_gsm) args << (uint)0;
|
||||
if (m_use_gsm) args << 0u;
|
||||
args << "Active torrents are presented";
|
||||
if (m_use_gsm) args << (uint)8;
|
||||
if (m_use_gsm) args << 8u;
|
||||
call.setArguments(args);
|
||||
|
||||
QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000);
|
||||
|
@ -67,7 +67,7 @@ class PreviewListDelegate: public QItemDelegate {
|
||||
qreal progress = index.data().toDouble()*100.;
|
||||
newopt.rect = opt.rect;
|
||||
newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%");
|
||||
newopt.progress = (int)progress;
|
||||
newopt.progress = static_cast<int>(progress);
|
||||
newopt.maximum = 100;
|
||||
newopt.minimum = 0;
|
||||
newopt.state |= QStyle::State_Enabled;
|
||||
|
@ -44,7 +44,7 @@ QVector<float> PieceAvailabilityBar::intToFloatVector(const QVector<int> &vecin,
|
||||
QVector<float> result(reqSize, 0.0);
|
||||
if (vecin.isEmpty()) return result;
|
||||
|
||||
const float ratio = vecin.size() / (float)reqSize;
|
||||
const float ratio = static_cast<float>(vecin.size()) / reqSize;
|
||||
|
||||
const int maxElement = *std::max_element(vecin.begin(), vecin.end());
|
||||
|
||||
@ -112,7 +112,7 @@ QVector<float> PieceAvailabilityBar::intToFloatVector(const QVector<int> &vecin,
|
||||
value /= ratio * maxElement;
|
||||
|
||||
// float precision sometimes gives > 1, because in not possible to store irrational numbers
|
||||
value = qMin(value, (float)1.0);
|
||||
value = qMin(value, 1.0f);
|
||||
|
||||
result[x] = value;
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ void StatsDialog::update()
|
||||
// Global ratio
|
||||
m_ui->labelGlobalRatio->setText(
|
||||
((atd > 0) && (atu > 0))
|
||||
? Utils::String::fromDouble((qreal)atu / (qreal)atd, 2)
|
||||
? Utils::String::fromDouble(static_cast<qreal>(atu) / atd, 2)
|
||||
: "-");
|
||||
// Cache hits
|
||||
qreal readRatio = cs.readRatio;
|
||||
|
@ -82,9 +82,9 @@ void TorrentContentModel::updateFilesProgress(const QVector<qreal> &fp)
|
||||
|
||||
void TorrentContentModel::updateFilesPriorities(const QVector<int> &fprio)
|
||||
{
|
||||
Q_ASSERT(m_filesIndex.size() == (int)fprio.size());
|
||||
Q_ASSERT(m_filesIndex.size() == fprio.size());
|
||||
// XXX: Why is this necessary?
|
||||
if (m_filesIndex.size() != (int)fprio.size())
|
||||
if (m_filesIndex.size() != fprio.size())
|
||||
return;
|
||||
|
||||
emit layoutAboutToBeChanged();
|
||||
|
@ -162,7 +162,7 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem
|
||||
qreal progress = index.data().toDouble() * 100.;
|
||||
newopt.rect = opt.rect;
|
||||
newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%");
|
||||
newopt.progress = (int)progress;
|
||||
newopt.progress = static_cast<int>(progress);
|
||||
newopt.maximum = 100;
|
||||
newopt.minimum = 0;
|
||||
newopt.state |= QStyle::State_Enabled;
|
||||
|
@ -449,7 +449,7 @@ void TransferListWidget::setDlLimitSelectedTorrents()
|
||||
if (!ok) return;
|
||||
|
||||
foreach (BitTorrent::TorrentHandle *const torrent, TorrentsList) {
|
||||
qDebug("Applying download speed limit of %ld Kb/s to torrent %s", (long) (newLimit / 1024.), qPrintable(torrent->hash()));
|
||||
qDebug("Applying download speed limit of %ld Kb/s to torrent %s", (newLimit / 1024l), qPrintable(torrent->hash()));
|
||||
torrent->setDownloadLimit(newLimit);
|
||||
}
|
||||
}
|
||||
@ -474,7 +474,7 @@ void TransferListWidget::setUpLimitSelectedTorrents()
|
||||
if (!ok) return;
|
||||
|
||||
foreach (BitTorrent::TorrentHandle *const torrent, TorrentsList) {
|
||||
qDebug("Applying upload speed limit of %ld Kb/s to torrent %s", (long) (newLimit / 1024.), qPrintable(torrent->hash()));
|
||||
qDebug("Applying upload speed limit of %ld Kb/s to torrent %s", (newLimit / 1024l), qPrintable(torrent->hash()));
|
||||
torrent->setUploadLimit(newLimit);
|
||||
}
|
||||
}
|
||||
|
@ -373,7 +373,7 @@ QByteArray btjson::getSyncMainData(int acceptedResponseId, QVariantMap &lastData
|
||||
if (lastData.contains("torrents") && lastData["torrents"].toHash().contains(torrent->hash()) &&
|
||||
lastData["torrents"].toHash()[torrent->hash()].toMap().contains(KEY_TORRENT_LAST_ACTIVITY_TIME)) {
|
||||
uint lastValue = lastData["torrents"].toHash()[torrent->hash()].toMap()[KEY_TORRENT_LAST_ACTIVITY_TIME].toUInt();
|
||||
if (qAbs((int)(lastValue - map[KEY_TORRENT_LAST_ACTIVITY_TIME].toUInt())) < 15)
|
||||
if (qAbs(static_cast<int>(lastValue - map[KEY_TORRENT_LAST_ACTIVITY_TIME].toUInt())) < 15)
|
||||
map[KEY_TORRENT_LAST_ACTIVITY_TIME] = lastValue;
|
||||
}
|
||||
|
||||
@ -595,8 +595,8 @@ QByteArray btjson::getPropertiesForTorrent(const QString& hash)
|
||||
dataDict[KEY_PROP_CREATED_BY] = torrent->creator();
|
||||
dataDict[KEY_PROP_ADDITION_DATE] = torrent->addedTime().toTime_t();
|
||||
if (torrent->hasMetadata()) {
|
||||
dataDict[KEY_PROP_LAST_SEEN] = torrent->lastSeenComplete().isValid() ? (int)torrent->lastSeenComplete().toTime_t() : -1;
|
||||
dataDict[KEY_PROP_COMPLETION_DATE] = torrent->completedTime().isValid() ? (int)torrent->completedTime().toTime_t() : -1;
|
||||
dataDict[KEY_PROP_LAST_SEEN] = torrent->lastSeenComplete().isValid() ? static_cast<int>(torrent->lastSeenComplete().toTime_t()) : -1;
|
||||
dataDict[KEY_PROP_COMPLETION_DATE] = torrent->completedTime().isValid() ? static_cast<int>(torrent->completedTime().toTime_t()) : -1;
|
||||
dataDict[KEY_PROP_CREATION_DATE] = torrent->creationDate().toTime_t();
|
||||
}
|
||||
else {
|
||||
@ -743,7 +743,7 @@ QVariantMap getTranserInfoMap()
|
||||
map[KEY_TRANSFER_ALLTIME_DL] = atd;
|
||||
map[KEY_TRANSFER_ALLTIME_UL] = atu;
|
||||
map[KEY_TRANSFER_TOTAL_WASTE_SESSION] = sessionStatus.totalWasted;
|
||||
map[KEY_TRANSFER_GLOBAL_RATIO] = ( atd > 0 && atu > 0 ) ? Utils::String::fromDouble((qreal)atu / (qreal)atd, 2) : "-";
|
||||
map[KEY_TRANSFER_GLOBAL_RATIO] = ( atd > 0 && atu > 0 ) ? Utils::String::fromDouble(static_cast<qreal>(atu) / atd, 2) : "-";
|
||||
map[KEY_TRANSFER_TOTAL_PEER_CONNECTIONS] = sessionStatus.peersCount;
|
||||
|
||||
qreal readRatio = cacheStatus.readRatio;
|
||||
|
Loading…
Reference in New Issue
Block a user