Commit 120dfc8e authored by Ronan's avatar Ronan

feat(app): replace some static_cast to functional cast (for simple types like int)

parent 0f09a0b5
......@@ -276,7 +276,7 @@ void Cli::Command::executeUri (const shared_ptr<linphone::Address> &address) con
// TODO: check if there is too much headers.
for (const auto &argName : mArgsScheme.keys()) {
const string header = address->getHeader(::Utils::appStringToCoreString(argName));
args[argName] = QByteArray::fromBase64(QByteArray(header.c_str(), static_cast<int>(header.length())));
args[argName] = QByteArray::fromBase64(QByteArray(header.c_str(), int(header.length())));
}
address->clean();
args["sip-address"] = ::Utils::coreStringToAppString(address->asStringUriOnly());
......
......@@ -43,7 +43,7 @@ static void removeAttribute (QXmlStreamAttributes &readerAttributes, const QStri
return name == attribute.name() && !attribute.prefix().length();
});
if (it != readerAttributes.cend())
readerAttributes.remove(static_cast<int>(distance(readerAttributes.cbegin(), it)));
readerAttributes.remove(int(distance(readerAttributes.cbegin(), it)));
}
static QByteArray buildByteArrayAttribute (const QByteArray &name, const QByteArray &value) {
......@@ -280,8 +280,8 @@ QImage ImageProvider::requestImage (const QString &id, QSize *size, const QSize
const int width = requestedSize.width();
const int height = requestedSize.height();
QImage image(
width > 0 ? width : static_cast<int>(viewBox.width()),
height > 0 ? height : static_cast<int>(viewBox.height()),
width > 0 ? width : int(viewBox.width()),
height > 0 ? height : int(viewBox.height()),
QImage::Format_ARGB32
);
if (Q_UNLIKELY(image.isNull())) {
......
......@@ -213,7 +213,7 @@ void SingleApplicationPrivate::connectToPrimary (int msecs, char connectionType)
initMsg.append(connectionType);
initMsg.append(reinterpret_cast<const char *>(&instanceNumber), sizeof(quint32));
initMsg.append(QByteArray::number(qChecksum(initMsg.constData(), static_cast<uint>(initMsg.length())), 256));
initMsg.append(QByteArray::number(qChecksum(initMsg.constData(), uint(initMsg.length())), 256));
socket->write(initMsg);
socket->flush();
......@@ -304,11 +304,11 @@ void SingleApplicationPrivate::slotConnectionEstablished () {
initMsg += connectionType;
tmp = nextConnSocket->read(sizeof(quint32));
const char *data = tmp.constData();
instanceId = static_cast<quint32>(*data);
instanceId = quint32(*data);
initMsg += tmp;
// Verify the checksum of the initMsg
QByteArray checksum = QByteArray::number(
qChecksum(initMsg.constData(), static_cast<uint>(initMsg.length())),
qChecksum(initMsg.constData(), uint(initMsg.length())),
256
);
tmp = nextConnSocket->read(checksum.length());
......
......@@ -30,21 +30,23 @@
#include "CallsListModel.hpp"
/* Delay before removing call in ms. */
#define DELAY_BEFORE_REMOVE_CALL 3000
using namespace std;
// =============================================================================
namespace {
/* Delay before removing call in ms. */
constexpr int cDelayBeforeRemoveCall = 3000;
}
static inline int findCallIndex (QList<CallModel *> &list, const shared_ptr<linphone::Call> &call) {
auto it = find_if(list.begin(), list.end(), [call](CallModel *callModel) {
return call == callModel->getCall();
});
return call == callModel->getCall();
});
Q_ASSERT(it != list.end());
return static_cast<int>(distance(list.begin(), it));
return int(distance(list.begin(), it));
}
static inline int findCallIndex (QList<CallModel *> &list, const CallModel &callModel) {
......@@ -253,7 +255,7 @@ void CallsListModel::removeCall (const shared_ptr<linphone::Call> &call) {
return;
}
QTimer::singleShot(DELAY_BEFORE_REMOVE_CALL, this, [this, callModel] {
QTimer::singleShot(cDelayBeforeRemoveCall, this, [this, callModel] {
removeCallCb(callModel);
});
}
......
......@@ -30,12 +30,14 @@
#include "Camera.hpp"
#define MAX_FPS 30
using namespace std;
// =============================================================================
namespace {
constexpr int cMaxFps = 30;
}
struct ContextInfo {
GLuint width;
GLuint height;
......@@ -77,8 +79,8 @@ QOpenGLFramebufferObject *CameraRenderer::createFramebufferObject (const QSize &
// It's not the same thread as render.
coreManager->lockVideoRender();
mContextInfo->width = static_cast<GLuint>(size.width());
mContextInfo->height = static_cast<GLuint>(size.height());
mContextInfo->width = GLuint(size.width());
mContextInfo->height = GLuint(size.height());
mContextInfo->functions = MSFunctions::getInstance()->getFunctions();
mUpdateContextInfo = true;
......@@ -179,7 +181,7 @@ Camera::Camera (QQuickItem *parent) : QQuickFramebufferObject(parent) {
setMirrorVertically(true);
mRefreshTimer = new QTimer(this);
mRefreshTimer->setInterval(1000 / MAX_FPS);
mRefreshTimer->setInterval(1000 / cMaxFps);
QObject::connect(
mRefreshTimer, &QTimer::timeout,
......
......@@ -30,12 +30,14 @@
#include "CameraPreview.hpp"
#define MAX_FPS 30
using namespace std;
// =============================================================================
namespace {
constexpr int cMaxFps = 30;
}
struct ContextInfo {
GLuint width;
GLuint height;
......@@ -72,8 +74,8 @@ QOpenGLFramebufferObject *CameraPreviewRenderer::createFramebufferObject (const
// It's not the same thread as render.
coreManager->lockVideoRender();
mContextInfo->width = static_cast<GLuint>(size.width());
mContextInfo->height = static_cast<GLuint>(size.height());
mContextInfo->width = GLuint(size.width());
mContextInfo->height = GLuint(size.height());
mContextInfo->functions = MSFunctions::getInstance()->getFunctions();
mUpdateContextInfo = true;
......@@ -142,7 +144,7 @@ CameraPreview::CameraPreview (QQuickItem *parent) : QQuickFramebufferObject(pare
setMirrorVertically(true);
mRefreshTimer = new QTimer(this);
mRefreshTimer->setInterval(1000 / MAX_FPS);
mRefreshTimer->setInterval(1000 / cMaxFps);
QObject::connect(
mRefreshTimer, &QTimer::timeout,
......
......@@ -85,7 +85,7 @@ static inline void createThumbnail (const shared_ptr<linphone::ChatMessage> &mes
int rotation = 0;
QExifImageHeader exifImageHeader;
if (exifImageHeader.loadFromJpeg(thumbnailPath))
rotation = static_cast<int>(exifImageHeader.value(QExifImageHeader::ImageTag::Orientation).toShort());
rotation = int(exifImageHeader.value(QExifImageHeader::ImageTag::Orientation).toShort());
QImage thumbnail = image.scaled(
THUMBNAIL_IMAGE_FILE_WIDTH, THUMBNAIL_IMAGE_FILE_HEIGHT,
......@@ -148,7 +148,7 @@ private:
}
void signalDataChanged (const QList<ChatEntryData>::iterator &it) {
int row = static_cast<int>(distance(mChatModel->mEntries.begin(), it));
int row = int(distance(mChatModel->mEntries.begin(), it));
emit mChatModel->dataChanged(mChatModel->index(row, 0), mChatModel->index(row, 0));
}
......@@ -175,7 +175,7 @@ private:
if (it == mChatModel->mEntries.end())
return;
(*it).first["fileOffset"] = static_cast<quint64>(offset);
(*it).first["fileOffset"] = quint64(offset);
signalDataChanged(it);
}
......@@ -411,7 +411,7 @@ void ChatModel::sendFileMessage (const QString &path) {
content->setSubtype(::Utils::appStringToCoreString(mimeType[1]));
}
content->setSize(static_cast<size_t>(fileSize));
content->setSize(size_t(fileSize));
content->setName(::Utils::appStringToCoreString(QFileInfo(file).fileName()));
shared_ptr<linphone::ChatMessage> message = mChatRoom->createFileTransferMessage(content);
......@@ -534,7 +534,7 @@ void ChatModel::fillMessageEntry (QVariantMap &dest, const shared_ptr<linphone::
shared_ptr<const linphone::Content> content = message->getFileTransferInformation();
if (content) {
dest["fileSize"] = static_cast<quint64>(content->getSize());
dest["fileSize"] = quint64(content->getSize());
dest["fileName"] = ::Utils::coreStringToAppString(content->getName());
dest["wasDownloaded"] = ::fileWasDownloaded(message);
......@@ -587,7 +587,7 @@ void ChatModel::removeEntry (ChatEntryData &pair) {
});
if (it != mEntries.end())
removeEntry(static_cast<int>(distance(mEntries.begin(), it)));
removeEntry(int(distance(mEntries.begin(), it)));
});
}
......@@ -626,7 +626,7 @@ void ChatModel::insertCall (const shared_ptr<linphone::CallLog> &callLog) {
return a.first["timestamp"] < b.first["timestamp"];
});
int row = static_cast<int>(distance(mEntries.begin(), it));
int row = int(distance(mEntries.begin(), it));
beginInsertRows(QModelIndex(), row, row);
it = mEntries.insert(it, pair);
......
......@@ -74,7 +74,7 @@ bool ContactsListProxyModel::filterAcceptsRow (
const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
const ContactModel *contact = index.data().value<ContactModel *>();
mWeights[contact] = static_cast<unsigned int>(round(computeContactWeight(contact)));
mWeights[contact] = uint(round(computeContactWeight(contact)));
return mWeights[contact] > 0 && (
!mUseConnectedFilter ||
......@@ -129,7 +129,7 @@ float ContactsListProxyModel::computeContactWeight (const ContactModel *contact)
// Get all contact's addresses.
const list<shared_ptr<linphone::Address> > addresses = contact->mLinphoneFriend->getAddresses();
float size = static_cast<float>(addresses.size());
float size = float(addresses.size());
for (auto it = addresses.cbegin(); it != addresses.cend(); ++it)
weight += computeStringWeight(
::Utils::coreStringToAppString((*it)->asStringUriOnly()),
......
......@@ -241,7 +241,7 @@ void Notifier::notifyReceivedFileMessage (const shared_ptr<linphone::ChatMessage
QVariantMap map;
map["fileUri"] = ::Utils::coreStringToAppString(message->getFileTransferFilepath());
map["fileSize"] = static_cast<quint64>(message->getFileTransferInformation()->getSize());
map["fileSize"] = quint64(message->getFileTransferInformation()->getSize());
SHOW_NOTIFICATION(map);
}
......
......@@ -28,7 +28,7 @@ Units::Units (QObject *parent) : QObject(parent) {}
float Units::getDp () const {
#ifdef Q_OS_MACOS
return static_cast<float>(96.0 / 72.0);
return float(96.0 / 72.0);
#endif // ifdef Q_OS_MACOS
return 1.0;
......
......@@ -164,7 +164,7 @@ bool AccountSettingsModel::addOrUpdateProxyConfig (
proxyConfig->setPublishExpires(data["registrationDuration"].toInt());
proxyConfig->setRoute(::Utils::appStringToCoreString(data["route"].toString()));
proxyConfig->setContactParameters(::Utils::appStringToCoreString(data["contactParams"].toString()));
proxyConfig->setAvpfRrInterval(static_cast<uint8_t>(data["avpfInterval"].toInt()));
proxyConfig->setAvpfRrInterval(uint8_t(data["avpfInterval"].toInt()));
proxyConfig->enableRegister(data["registerEnabled"].toBool());
proxyConfig->enablePublish(data["publishPresence"].toBool());
proxyConfig->setAvpfMode(data["avpfEnabled"].toBool()
......
......@@ -29,14 +29,14 @@
#include "SettingsModel.hpp"
#ifndef DEFAULT_RLS_URI
#define DEFAULT_RLS_URI "sips:rls@sip.linphone.org"
#endif // ifndef RLS_URI
using namespace std;
// =============================================================================
namespace {
constexpr char cDefaultRlsUri[] = "sips:rls@sip.linphone.org";
}
const string SettingsModel::UI_SECTION("ui");
SettingsModel::SettingsModel (QObject *parent) : QObject(parent) {
......@@ -190,11 +190,11 @@ void SettingsModel::setVideoPreset (const QString &preset) {
// -----------------------------------------------------------------------------
int SettingsModel::getVideoFramerate () const {
return static_cast<int>(CoreManager::getInstance()->getCore()->getPreferredFramerate());
return int(CoreManager::getInstance()->getCore()->getPreferredFramerate());
}
void SettingsModel::setVideoFramerate (int framerate) {
CoreManager::getInstance()->getCore()->setPreferredFramerate(static_cast<float>(framerate));
CoreManager::getInstance()->getCore()->setPreferredFramerate(float(framerate));
emit videoFramerateChanged(framerate);
}
......@@ -660,7 +660,7 @@ bool SettingsModel::getRlsUriEnabled () const {
void SettingsModel::setRlsUriEnabled (bool status) {
mConfig->setInt(UI_SECTION, "rls_uri_enabled", status);
mConfig->setString("sip", "rls_uri", status ? DEFAULT_RLS_URI : "");
mConfig->setString("sip", "rls_uri", status ? cDefaultRlsUri : "");
emit rlsUriEnabledChanged(status);
}
......@@ -669,7 +669,7 @@ static string getRlsUriDomain () {
if (!domain.empty())
return domain;
shared_ptr<linphone::Address> linphoneAddress = CoreManager::getInstance()->getCore()->createAddress(DEFAULT_RLS_URI);
shared_ptr<linphone::Address> linphoneAddress = CoreManager::getInstance()->getCore()->createAddress(cDefaultRlsUri);
Q_CHECK_PTR(linphoneAddress);
domain = linphoneAddress->getDomain();
return domain;
......@@ -686,7 +686,7 @@ void SettingsModel::configureRlsUri () {
const string domain = getRlsUriDomain();
for (const auto &proxyConfig : CoreManager::getInstance()->getCore()->getProxyConfigList())
if (proxyConfig->getDomain() == domain) {
mConfig->setString("sip", "rls_uri", DEFAULT_RLS_URI);
mConfig->setString("sip", "rls_uri", cDefaultRlsUri);
return;
}
......@@ -701,7 +701,7 @@ void SettingsModel::configureRlsUri (const shared_ptr<const linphone::ProxyConfi
const string domain = getRlsUriDomain();
if (proxyConfig->getDomain() == domain) {
mConfig->setString("sip", "rls_uri", DEFAULT_RLS_URI);
mConfig->setString("sip", "rls_uri", cDefaultRlsUri);
return;
}
......
......@@ -293,5 +293,5 @@ int TelephoneNumbersModel::getDefaultIndex () const {
return country == pair.first;
}
);
return it != mCountryCodes.cend() ? static_cast<int>(distance(mCountryCodes.cbegin(), it)) : 0;
return it != mCountryCodes.cend() ? int(distance(mCountryCodes.cbegin(), it)) : 0;
}
......@@ -35,7 +35,7 @@
void TestUtils::executeKeySequence (QQuickWindow *window, QKeySequence sequence) {
for (int i = 0; i < sequence.count(); ++i) {
uint key = static_cast<uint>(sequence[static_cast<uint>(i)]);
uint key = uint(sequence[uint(i)]);
QTest::keyClick(
window,
Qt::Key(key & ~Qt::KeyboardModifierMask),
......
......@@ -540,7 +540,7 @@ quint32 QExifValue::toLong () const {
case Long:
return static_cast<const QExifLongValuePrivate *>(d.constData())->value.at(0);
case SignedLong:
return static_cast<quint32>(static_cast<const QExifSignedLongValuePrivate *>(d.constData())->value.at(0));
return quint32(static_cast<const QExifSignedLongValuePrivate *>(d.constData())->value.at(0));
}
}
return 0;
......@@ -598,7 +598,7 @@ qint32 QExifValue::toSignedLong () const {
case Short:
return static_cast<const QExifShortValuePrivate *>(d.constData())->value.at(0);
case Long:
return static_cast<qint32>(static_cast<const QExifLongValuePrivate *>(d.constData())->value.at(0));
return qint32(static_cast<const QExifLongValuePrivate *>(d.constData())->value.at(0));
case SignedLong:
return static_cast<const QExifSignedLongValuePrivate *>(d.constData())->value.at(0);
}
......@@ -1030,13 +1030,13 @@ quint32 QExifImageHeader::sizeOf (const QExifValue &value) const {
case QExifValue::Ascii:
return value.count() > 4 ? 12 + value.count() : 12;
case QExifValue::Short:
return value.count() > 2 ? static_cast<quint32>(12 + value.count() * sizeof(quint16)) : 12;
return value.count() > 2 ? quint32(12 + value.count() * sizeof(quint16)) : 12;
case QExifValue::Long:
case QExifValue::SignedLong:
return value.count() > 1 ? static_cast<quint32>(12 + value.count() * sizeof(quint32)) : 12;
return value.count() > 1 ? quint32(12 + value.count() * sizeof(quint32)) : 12;
case QExifValue::Rational:
case QExifValue::SignedRational:
return value.count() > 0 ? static_cast<quint32>(12 + value.count() * sizeof(quint32) * 2) : 12;
return value.count() > 0 ? quint32(12 + value.count() * sizeof(quint32) * 2) : 12;
default:
return 0;
}
......@@ -1352,7 +1352,7 @@ QExifValue QExifImageHeader::readIfdValue (QDataStream &stream, int startPos, co
return QExifValue(QString::fromUtf8(header.offsetAscii, header.count - 1));
}
case QExifValue::Short: {
QVector<quint16> value(static_cast<quint16>(header.count));
QVector<quint16> value(quint16(header.count));
if (header.count > 2) {
stream.device()->seek(startPos + header.offset);
......@@ -1366,7 +1366,7 @@ QExifValue QExifImageHeader::readIfdValue (QDataStream &stream, int startPos, co
return QExifValue(value);
}
case QExifValue::Long: {
QVector<quint32> value(static_cast<quint32>(header.count));
QVector<quint32> value(quint32(header.count));
if (header.count > 1) {
stream.device()->seek(startPos + header.offset);
......@@ -1462,7 +1462,7 @@ QMap<T, QExifValue> QExifImageHeader::readIfdValues (
bool QExifImageHeader::read (QIODevice *device) {
clear();
int startPos = static_cast<int>(device->pos());
int startPos = int(device->pos());
QDataStream stream(device);
......@@ -1544,7 +1544,7 @@ quint32 QExifImageHeader::writeExifHeader (QDataStream &stream, quint16 tag, con
} else {
stream << offset;
offset += static_cast<quint32>(value.count());
offset += quint32(value.count());
}
break;
case QExifValue::Undefined:
......@@ -1556,7 +1556,7 @@ quint32 QExifImageHeader::writeExifHeader (QDataStream &stream, quint16 tag, con
} else {
stream << offset;
offset += static_cast<quint32>(value.count());
offset += quint32(value.count());
}
break;
case QExifValue::Ascii:
......@@ -1569,7 +1569,7 @@ quint32 QExifImageHeader::writeExifHeader (QDataStream &stream, quint16 tag, con
} else {
stream << offset;
offset += static_cast<quint32>(value.count());
offset += quint32(value.count());
}
break;
case QExifValue::Short:
......@@ -1581,7 +1581,7 @@ quint32 QExifImageHeader::writeExifHeader (QDataStream &stream, quint16 tag, con
} else {
stream << offset;
offset += static_cast<quint32>(value.count() * sizeof(quint16));
offset += quint32(value.count() * sizeof(quint16));
}
break;
case QExifValue::Long:
......@@ -1592,7 +1592,7 @@ quint32 QExifImageHeader::writeExifHeader (QDataStream &stream, quint16 tag, con
} else {
stream << offset;
offset += static_cast<quint32>(value.count() * sizeof(quint32));
offset += quint32(value.count() * sizeof(quint32));
}
break;
case QExifValue::SignedLong:
......@@ -1603,7 +1603,7 @@ quint32 QExifImageHeader::writeExifHeader (QDataStream &stream, quint16 tag, con
} else {
stream << offset;
offset += static_cast<quint32>(value.count() * sizeof(qint32));
offset += quint32(value.count() * sizeof(qint32));
}
break;
case QExifValue::Rational:
......@@ -1612,7 +1612,7 @@ quint32 QExifImageHeader::writeExifHeader (QDataStream &stream, quint16 tag, con
} else {
stream << offset;
offset += static_cast<quint32>(value.count() * sizeof(quint32) * 2);
offset += quint32(value.count() * sizeof(quint32) * 2);
}
break;
case QExifValue::SignedRational:
......@@ -1621,7 +1621,7 @@ quint32 QExifImageHeader::writeExifHeader (QDataStream &stream, quint16 tag, con
} else {
stream << offset;
offset += static_cast<quint32>(value.count() * sizeof(qint32) * 2);
offset += quint32(value.count() * sizeof(qint32) * 2);
}
break;
default:
......@@ -1730,7 +1730,7 @@ qint64 QExifImageHeader::write (QIODevice *device) const {
device->write("\x00\x00\x00\x08", 4);
}
quint16 count = static_cast<quint16>(d->imageIfdValues.count() + 1);
quint16 count = quint16(d->imageIfdValues.count() + 1);
quint32 offset = 26;
if (!d->gpsIfdValues.isEmpty()) {
......
......@@ -42,7 +42,7 @@
namespace Utils {
inline QString coreStringToAppString (const std::string &string) {
return QString::fromLocal8Bit(string.c_str(), static_cast<int>(string.size()));
return QString::fromLocal8Bit(string.c_str(), int(string.size()));
}
inline std::string appStringToCoreString (const QString &string) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment