From 189cf89d20254bbc8c48cab02f6b7def9567d2e3 Mon Sep 17 00:00:00 2001 From: iphydf Date: Mon, 18 Nov 2024 00:22:16 +0000 Subject: [PATCH] cleanup: Avoid implicit bool conversions. ```sh run-clang-tidy -p _build -fix \ $(find . -name "*.h" -or -name "*.cpp" -or -name "*.c" | grep -v "/_build/") \ -checks="-*,readability-implicit-bool-conversion"` ``` --- audio/src/backend/openal.cpp | 36 +++++----- src/appmanager.cpp | 16 ++--- src/chatlog/chatline.cpp | 14 ++-- src/chatlog/chatmessage.cpp | 6 +- src/chatlog/chatwidget.cpp | 38 +++++------ src/chatlog/content/notificationicon.cpp | 2 +- src/chatlog/content/spinner.cpp | 2 +- src/chatlog/content/text.cpp | 26 ++++---- src/chatlog/content/timestamp.cpp | 2 +- src/chatlog/documentcache.cpp | 2 +- src/chatlog/textformatter.cpp | 2 +- src/core/core.cpp | 45 ++++++------- src/core/coreav.cpp | 44 ++++++------- src/core/coreext.cpp | 4 +- src/core/corefile.cpp | 22 +++---- src/core/toxcall.cpp | 2 +- src/core/toxencrypt.cpp | 2 +- src/core/toxfileprogress.cpp | 6 +- src/core/toxoptions.cpp | 2 +- src/ipc.cpp | 16 ++--- src/model/about/aboutfriend.cpp | 4 +- src/model/chathistory.cpp | 2 +- src/model/chatroom/friendchatroom.cpp | 6 +- src/model/chatroom/groupchatroom.cpp | 4 +- src/model/exiftransform.cpp | 12 ++-- src/model/group.cpp | 4 +- src/model/notificationgenerator.cpp | 2 +- src/model/sessionchatlog.cpp | 2 +- src/nexus.cpp | 4 +- src/persistence/db/rawdatabase.cpp | 18 ++--- src/persistence/history.cpp | 4 +- src/persistence/settings.cpp | 4 +- src/persistence/settingsserializer.cpp | 17 ++--- src/platform/camera/v4l2.cpp | 18 ++--- src/platform/capslock_x11.cpp | 2 +- src/platform/posixsignalnotifier.cpp | 4 +- src/platform/timer_x11.cpp | 6 +- src/platform/x11_display.cpp | 2 +- src/video/cameradevice.cpp | 24 +++---- src/video/camerasource.cpp | 22 +++---- src/video/corevideosource.cpp | 2 +- src/video/netcamview.cpp | 2 +- src/video/videoframe.cpp | 4 +- src/video/videomode.cpp | 2 +- src/video/videosurface.cpp | 4 +- src/widget/chatformheader.cpp | 4 +- src/widget/circlewidget.cpp | 10 +-- src/widget/contentdialog.cpp | 30 ++++----- src/widget/contentdialogmanager.cpp | 6 +- src/widget/emoticonswidget.cpp | 4 +- src/widget/form/chatform.cpp | 16 ++--- src/widget/form/genericchatform.cpp | 16 ++--- src/widget/form/groupchatform.cpp | 12 ++-- src/widget/form/groupinviteform.cpp | 2 +- src/widget/form/searchsettingsform.cpp | 2 +- src/widget/form/settings/advancedform.cpp | 2 +- src/widget/form/settings/avform.cpp | 10 +-- src/widget/form/settings/genericsettings.cpp | 4 +- .../form/settings/userinterfaceform.cpp | 4 +- .../form/settings/verticalonlyscroller.cpp | 4 +- src/widget/friendlistwidget.cpp | 12 ++-- src/widget/friendwidget.cpp | 8 +-- src/widget/groupwidget.cpp | 2 +- src/widget/passwordedit.cpp | 4 +- src/widget/qrwidget.cpp | 2 +- src/widget/searchform.cpp | 2 +- src/widget/style.cpp | 2 +- src/widget/tool/adjustingscrollarea.cpp | 2 +- src/widget/tool/callconfirmwidget.cpp | 4 +- src/widget/tool/chattextedit.cpp | 6 +- src/widget/tool/movablewidget.cpp | 28 ++++---- src/widget/tool/screenshotgrabber.cpp | 2 +- src/widget/translator.cpp | 4 +- src/widget/widget.cpp | 66 +++++++++---------- test/model/friendlistmanager_test.cpp | 4 +- 75 files changed, 371 insertions(+), 367 deletions(-) diff --git a/audio/src/backend/openal.cpp b/audio/src/backend/openal.cpp index 2a543af8da..1e92ad2e2e 100644 --- a/audio/src/backend/openal.cpp +++ b/audio/src/backend/openal.cpp @@ -100,7 +100,7 @@ void OpenAL::checkAlError() noexcept void OpenAL::checkAlcError(ALCdevice* device) noexcept { const ALCenum alc_err = alcGetError(device); - if (alc_err) + if (alc_err != 0) qWarning("OpenAL error: %d", alc_err); } @@ -248,7 +248,7 @@ void OpenAL::destroySink(AlSink& sink) const uint sid = sink.getSourceId(); - if (alIsSource(sid)) { + if (alIsSource(sid) != 0) { // stop playing, marks all buffers as processed alSourceStop(sid); cleanupBuffers(sid); @@ -319,7 +319,7 @@ void OpenAL::destroySource(AlSource& source) */ bool OpenAL::autoInitInput() { - return alInDev ? true : initInput(settings.getInDev()); + return alInDev != nullptr ? true : initInput(settings.getInDev()); } /** @@ -329,7 +329,7 @@ bool OpenAL::autoInitInput() */ bool OpenAL::autoInitOutput() { - return alOutDev ? true : initOutput(settings.getOutDev()); + return alOutDev != nullptr ? true : initOutput(settings.getOutDev()); } bool OpenAL::initInput(const QString& deviceName) @@ -360,7 +360,7 @@ bool OpenAL::initInput(const QString& deviceName, uint32_t channels) alInDev = alcCaptureOpenDevice(tmpDevName, AUDIO_SAMPLE_RATE, stereoFlag, ringBufSize); // Restart the capture if necessary - if (!alInDev) { + if (alInDev == nullptr) { qWarning() << "Failed to initialize audio input device:" << deviceName; return false; } @@ -394,7 +394,7 @@ bool OpenAL::initOutput(const QString& deviceName) const ALchar* tmpDevName = qDevName.isEmpty() ? nullptr : qDevName.constData(); alOutDev = alcOpenDevice(tmpDevName); - if (!alOutDev) { + if (alOutDev == nullptr) { qWarning() << "Cannot open audio output device" << deviceName; return false; } @@ -403,7 +403,7 @@ bool OpenAL::initOutput(const QString& deviceName) alOutContext = alcCreateContext(alOutDev, nullptr); checkAlcError(alOutDev); - if (!alcMakeContextCurrent(alOutContext)) { + if (alcMakeContextCurrent(alOutContext) == 0) { qWarning() << "Cannot create audio output context"; return false; } @@ -487,7 +487,7 @@ void OpenAL::playAudioBuffer(uint sourceId, const int16_t* data, int samples, un assert(channels == 1 || channels == 2); QMutexLocker locker(&audioLock); - if (!(alOutDev && outputInitialized)) + if (!((alOutDev != nullptr) && outputInitialized)) return; ALuint bufids[BUFFER_COUNT]; @@ -526,7 +526,7 @@ void OpenAL::playAudioBuffer(uint sourceId, const int16_t* data, int samples, un */ void OpenAL::cleanupInput() { - if (!alInDev) + if (alInDev == nullptr) return; qDebug() << "Closing audio input"; @@ -547,8 +547,8 @@ void OpenAL::cleanupOutput() { outputInitialized = false; - if (alOutDev) { - if (!alcMakeContextCurrent(nullptr)) { + if (alOutDev != nullptr) { + if (alcMakeContextCurrent(nullptr) == 0) { qWarning("Failed to clear audio context"); } @@ -556,7 +556,7 @@ void OpenAL::cleanupOutput() alOutContext = nullptr; qDebug() << "Closing audio output"; - if (alcCloseDevice(alOutDev)) { + if (alcCloseDevice(alOutDev) != 0) { alOutDev = nullptr; } else { qWarning("Failed to close output"); @@ -648,7 +648,7 @@ void OpenAL::doAudio() // Output section does nothing // Input section - if (alInDev && !sources.empty()) { + if ((alInDev != nullptr) && !sources.empty()) { doInput(); } } @@ -664,7 +664,7 @@ void OpenAL::captureSamples(ALCdevice* device, int16_t* buffer, ALCsizei samples bool OpenAL::isOutputReady() const { QMutexLocker locker(&audioLock); - return alOutDev && outputInitialized; + return (alOutDev != nullptr) && outputInitialized; } QStringList OpenAL::outDeviceNames() @@ -674,8 +674,8 @@ QStringList OpenAL::outDeviceNames() ? alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER) : alcGetString(nullptr, ALC_DEVICE_SPECIFIER); - if (pDeviceList) { - while (*pDeviceList) { + if (pDeviceList != nullptr) { + while (*pDeviceList != 0) { auto len = strlen(pDeviceList); list << QString::fromUtf8(pDeviceList, len); pDeviceList += len + 1; @@ -690,8 +690,8 @@ QStringList OpenAL::inDeviceNames() QStringList list; const ALchar* pDeviceList = alcGetString(nullptr, ALC_CAPTURE_DEVICE_SPECIFIER); - if (pDeviceList) { - while (*pDeviceList) { + if (pDeviceList != nullptr) { + while (*pDeviceList != 0) { auto len = strlen(pDeviceList); list << QString::fromUtf8(pDeviceList, len); pDeviceList += len + 1; diff --git a/src/appmanager.cpp b/src/appmanager.cpp index 2adc1a7072..769587c20f 100644 --- a/src/appmanager.cpp +++ b/src/appmanager.cpp @@ -104,15 +104,15 @@ void logMessageHandler(QtMsgType type, const QMessageLogContext& ctxt, const QSt #ifdef LOG_TO_FILE FILE* logFilePtr = logFileFile.loadRelaxed(); // atomically load the file pointer - if (!logFilePtr) { + if (logFilePtr == nullptr) { logBufferMutex->lock(); - if (logBuffer) + if (logBuffer != nullptr) logBuffer->append(LogMsgBytes); logBufferMutex->unlock(); } else { logBufferMutex->lock(); - if (logBuffer) { + if (logBuffer != nullptr) { // empty logBuffer to file foreach (QByteArray bufferedMsg, *logBuffer) fwrite(bufferedMsg.constData(), 1, bufferedMsg.size(), logFilePtr); @@ -135,7 +135,7 @@ bool toxURIEventHandler(const QByteArray& eventData, void* userData) return false; } - if (!uriDialog) { + if (uriDialog == nullptr) { return false; } @@ -233,7 +233,7 @@ int AppManager::run() qDebug() << "Log file over 1MB, rotating..."; // close old logfile (need for windows) - if (mainLogFilePtr) + if (mainLogFilePtr != nullptr) fclose(mainLogFilePtr); QDir dir(logFileDir); @@ -251,7 +251,7 @@ int AppManager::run() mainLogFilePtr = fopen(logfile.toLocal8Bit().constData(), "a"); } - if (!mainLogFilePtr) + if (mainLogFilePtr == nullptr) qCritical() << "Couldn't open logfile" << logfile; logFileFile.storeRelaxed(mainLogFilePtr); // atomically set the logFile @@ -336,11 +336,11 @@ int AppManager::run() && !Profile::isEncrypted(profileName, settings->getPaths())) { profile = Profile::loadProfile(profileName, QString(), *settings, &parser, *cameraSource, *messageBoxManager); - if (!profile) { + if (profile == nullptr) { QMessageBox::information(nullptr, tr("Error"), tr("Failed to load profile automatically.")); } } - if (profile) { + if (profile != nullptr) { nexus->bootstrapWithProfile(profile); } else { nexus->setParser(&parser); diff --git a/src/chatlog/chatline.cpp b/src/chatlog/chatline.cpp index 736bbd9508..284b911167 100644 --- a/src/chatlog/chatline.cpp +++ b/src/chatlog/chatline.cpp @@ -14,7 +14,7 @@ ChatLine::ChatLine() {} ChatLine::~ChatLine() { for (ChatLineContent* c : content) { - if (c->scene()) + if (c->scene() != nullptr) c->scene()->removeItem(c); delete c; @@ -52,14 +52,14 @@ ChatLineContent* ChatLine::getContent(QPointF scenePos) const void ChatLine::removeFromScene() { for (ChatLineContent* c : content) { - if (c->scene()) + if (c->scene() != nullptr) c->scene()->removeItem(c); } } void ChatLine::addToScene(QGraphicsScene* scene) { - if (!scene) + if (scene == nullptr) return; for (ChatLineContent* c : content) @@ -119,7 +119,7 @@ QRectF ChatLine::sceneBoundingRect() const void ChatLine::addColumn(ChatLineContent* item, ColumnFormat fmt) { - if (!item) + if (item == nullptr) return; format.push_back(fmt); @@ -129,14 +129,14 @@ void ChatLine::addColumn(ChatLineContent* item, ColumnFormat fmt) void ChatLine::replaceContent(int col, ChatLineContent* lineContent) { - if (col >= 0 && col < content.size() && lineContent) { + if (col >= 0 && col < content.size() && (lineContent != nullptr)) { QGraphicsScene* scene = content[col]->scene(); delete content[col]; content[col] = lineContent; lineContent->setIndex(row, col); - if (scene) + if (scene != nullptr) scene->addItem(content[col]); layout(width, bbox.topLeft()); @@ -147,7 +147,7 @@ void ChatLine::replaceContent(int col, ChatLineContent* lineContent) void ChatLine::layout(qreal w, QPointF scenePos) { - if (!content.size()) + if (content.size() == 0) return; width = w; diff --git a/src/chatlog/chatmessage.cpp b/src/chatlog/chatmessage.cpp index 8bf1faa146..0a8776b4e5 100644 --- a/src/chatlog/chatmessage.cpp +++ b/src/chatlog/chatmessage.cpp @@ -252,7 +252,7 @@ void ChatMessage::markAsBroken() QString ChatMessage::toString() const { ChatLineContent* c = getContent(1); - if (c) + if (c != nullptr) return c->getText(); return QString(); @@ -271,14 +271,14 @@ void ChatMessage::setAsAction() void ChatMessage::hideSender() { ChatLineContent* c = getContent(0); - if (c) + if (c != nullptr) c->hide(); } void ChatMessage::hideDate() { ChatLineContent* c = getContent(2); - if (c) + if (c != nullptr) c->hide(); } diff --git a/src/chatlog/chatwidget.cpp b/src/chatlog/chatwidget.cpp index 092f824c54..34943a0bd1 100644 --- a/src/chatlog/chatwidget.cpp +++ b/src/chatlog/chatwidget.cpp @@ -91,7 +91,7 @@ void renderMessageRaw(const QString& displayName, bool isSelf, bool colorizeName // ChatLine a QObject which I didn't think was worth it. auto chatMessage = static_cast(chatLine.get()); - if (chatMessage) { + if (chatMessage != nullptr) { if (chatLogMessage.state == MessageState::complete) { chatMessage->markAsDelivered(chatLogMessage.message.timestamp); } else if (chatLogMessage.state == MessageState::broken) { @@ -134,7 +134,7 @@ ChatMessage::SystemMessageType getChatMessageType(const SystemMessage& systemMes ChatLogIdx firstItemAfterDate(QDate date, const IChatLog& chatLog) { auto idxs = chatLog.getDateIdxs(date, 1); - if (idxs.size()) { + if (idxs.size() != 0u) { return idxs[0].idx; } else { return chatLog.getNextIdx(); @@ -396,7 +396,7 @@ void ChatWidget::mouseMoveEvent(QMouseEvent* ev) QPointF scenePos = mapToScene(ev->pos()); - if (ev->buttons() & Qt::LeftButton) { + if ((ev->buttons() & Qt::LeftButton) != 0u) { // autoscroll if (ev->pos().y() < 0) selectionScrollDir = AutoScrollDirection::Up; @@ -412,7 +412,7 @@ void ChatWidget::mouseMoveEvent(QMouseEvent* ev) ChatLine::Ptr line = findLineByPosY(scenePos.y()); ChatLineContent* content = getContentFromPos(sceneClickPos); - if (content) { + if (content != nullptr) { selClickedRow = line; selClickedCol = content->getColumn(); selFirstRow = line; @@ -423,9 +423,9 @@ void ChatWidget::mouseMoveEvent(QMouseEvent* ev) selectionMode = SelectionMode::Precise; // ungrab mouse grabber - if (scene->mouseGrabberItem()) + if (scene->mouseGrabberItem() != nullptr) scene->mouseGrabberItem()->ungrabMouse(); - } else if (line.get()) { + } else if (line.get() != nullptr) { selClickedRow = line; selFirstRow = selClickedRow; selLastRow = selClickedRow; @@ -438,7 +438,7 @@ void ChatWidget::mouseMoveEvent(QMouseEvent* ev) ChatLineContent* content = getContentFromPos(scenePos); ChatLine::Ptr line = findLineByPosY(scenePos.y()); - if (content) { + if (content != nullptr) { int col = content->getColumn(); if (line == selClickedRow && col == selClickedCol) { @@ -451,7 +451,7 @@ void ChatWidget::mouseMoveEvent(QMouseEvent* ev) line->selectionCleared(); } - } else if (line.get()) { + } else if (line.get() != nullptr) { if (line != selClickedRow) { selectionMode = SelectionMode::Multi; line->selectionCleared(); @@ -496,7 +496,7 @@ bool ChatWidget::isOverSelection(QPointF scenePos) const if (selectionMode == SelectionMode::Precise) { ChatLineContent* content = getContentFromPos(scenePos); - if (content) + if (content != nullptr) return content->isOverSelection(scenePos); } else if (selectionMode == SelectionMode::Multi) { if (selGraphItem->rect().contains(scenePos)) @@ -626,7 +626,7 @@ void ChatWidget::mouseDoubleClickEvent(QMouseEvent* ev) ChatLineContent* content = getContentFromPos(scenePos); ChatLine::Ptr line = findLineByPosY(scenePos.y()); - if (content) { + if (content != nullptr) { content->selectionDoubleClick(scenePos); selClickedCol = content->getColumn(); selClickedRow = line; @@ -724,13 +724,13 @@ void ChatWidget::copySelectedText(bool toSelectionBuffer) const QString text = getSelectedText(); QClipboard* clipboard = QApplication::clipboard(); - if (clipboard && !text.isNull()) + if ((clipboard != nullptr) && !text.isNull()) clipboard->setText(text, toSelectionBuffer ? QClipboard::Selection : QClipboard::Clipboard); } void ChatWidget::setTypingNotificationVisible(bool visible) { - if (typingNotification.get()) { + if (typingNotification.get() != nullptr) { typingNotification->setVisible(visible); updateTypingNotification(); } @@ -738,7 +738,7 @@ void ChatWidget::setTypingNotificationVisible(bool visible) void ChatWidget::setTypingNotificationName(const QString& displayName) { - if (!typingNotification.get()) { + if (typingNotification.get() == nullptr) { setTypingNotification(); } @@ -751,7 +751,7 @@ void ChatWidget::setTypingNotificationName(const QString& displayName) void ChatWidget::scrollToLine(ChatLine::Ptr line) { - if (!line.get()) + if (line.get() == nullptr) return; updateSceneRect(); @@ -968,7 +968,7 @@ void ChatWidget::updateMultiSelectionRect() void ChatWidget::updateTypingNotification() { ChatLine* notification = typingNotification.get(); - if (!notification) + if (notification == nullptr) return; qreal posY = 0.0; @@ -1181,7 +1181,7 @@ void ChatWidget::onRenderFinished() auto renderCompletionFnsLocal = renderCompletionFns; renderCompletionFns.clear(); - while (renderCompletionFnsLocal.size()) { + while (renderCompletionFnsLocal.size() != 0u) { renderCompletionFnsLocal.back()(); renderCompletionFnsLocal.pop_back(); } @@ -1270,7 +1270,7 @@ void ChatWidget::handleMultiClickEvent() ChatLineContent* content = getContentFromPos(scenePos); ChatLine::Ptr line = findLineByPosY(scenePos.y()); - if (content) { + if (content != nullptr) { content->selectionTripleClick(scenePos); selClickedCol = content->getColumn(); selClickedRow = line; @@ -1366,12 +1366,12 @@ bool ChatWidget::isActiveFileTransfer(ChatLine::Ptr l) for (int i = 0; i < count; ++i) { ChatLineContent* content = l->getContent(i); ChatLineContentProxy* proxy = qobject_cast(content); - if (!proxy) + if (proxy == nullptr) continue; QWidget* widget = proxy->getWidget(); FileTransferWidget* transferWidget = qobject_cast(widget); - if (transferWidget && transferWidget->isActive()) + if ((transferWidget != nullptr) && transferWidget->isActive()) return true; } diff --git a/src/chatlog/content/notificationicon.cpp b/src/chatlog/content/notificationicon.cpp index 1f0b9e88c2..495d822a49 100644 --- a/src/chatlog/content/notificationicon.cpp +++ b/src/chatlog/content/notificationicon.cpp @@ -73,7 +73,7 @@ void NotificationIcon::updateGradient() grad.setColorAt(qMin(1.0, alpha + dotWidth), Qt::lightGray); grad.setColorAt(1, Qt::lightGray); - if (scene() && isVisible()) { + if ((scene() != nullptr) && isVisible()) { scene()->invalidate(sceneBoundingRect()); } } diff --git a/src/chatlog/content/spinner.cpp b/src/chatlog/content/spinner.cpp index de522677fb..a3667bd841 100644 --- a/src/chatlog/content/spinner.cpp +++ b/src/chatlog/content/spinner.cpp @@ -78,7 +78,7 @@ void Spinner::timeout() // limit to the range [0.0 - 360.0] curRot = remainderf(angle, 360.0f); - if (scene()) { + if (scene() != nullptr) { scene()->invalidate(sceneBoundingRect()); } } diff --git a/src/chatlog/content/text.cpp b/src/chatlog/content/text.cpp index cd76b38999..48e9c2940b 100644 --- a/src/chatlog/content/text.cpp +++ b/src/chatlog/content/text.cpp @@ -45,7 +45,7 @@ Text::Text(DocumentCache& documentCache_, Settings& settings_, Style& style_, co Text::~Text() { - if (doc) + if (doc != nullptr) documentCache.push(doc); } @@ -59,7 +59,7 @@ void Text::selectText(const QString& txt, const std::pair& point) { regenerate(); - if (!doc) { + if (doc == nullptr) { return; } @@ -72,7 +72,7 @@ void Text::selectText(const QRegularExpression& exp, const std::pair& { regenerate(); - if (!doc) { + if (doc == nullptr) { return; } @@ -98,7 +98,7 @@ void Text::setWidth(float w) void Text::selectionMouseMove(QPointF scenePos) { - if (!doc) + if (doc == nullptr) return; int cur = cursorFromPos(scenePos); @@ -132,7 +132,7 @@ void Text::selectionCleared() void Text::selectionDoubleClick(QPointF scenePos) { - if (!doc) + if (doc == nullptr) return; int cur = cursorFromPos(scenePos); @@ -153,7 +153,7 @@ void Text::selectionDoubleClick(QPointF scenePos) void Text::selectionTripleClick(QPointF scenePos) { - if (!doc) + if (doc == nullptr) return; int cur = cursorFromPos(scenePos); @@ -210,7 +210,7 @@ void Text::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWid std::ignore = option; std::ignore = widget; - if (!doc) + if (doc == nullptr) return; painter->setClipRect(boundingRect()); @@ -266,7 +266,7 @@ void Text::mousePressEvent(QGraphicsSceneMouseEvent* event) void Text::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) { - if (!doc) + if (doc == nullptr) return; QString anchor = doc->documentLayout()->anchorAt(event->pos()); @@ -278,7 +278,7 @@ void Text::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) void Text::hoverMoveEvent(QGraphicsSceneHoverEvent* event) { - if (!doc) + if (doc == nullptr) return; QString anchor = doc->documentLayout()->anchorAt(event->pos()); @@ -311,7 +311,7 @@ QString Text::getLinkAt(QPointF scenePos) const void Text::regenerate() { - if (!doc) { + if (doc == nullptr) { doc = documentCache.pop(); dirty = true; } @@ -365,7 +365,7 @@ void Text::freeResources() QSizeF Text::idealSize() { - if (doc) + if (doc != nullptr) return doc->size(); return size; @@ -373,7 +373,7 @@ QSizeF Text::idealSize() int Text::cursorFromPos(QPointF scenePos, bool fuzzy) const { - if (doc) + if (doc != nullptr) return doc->documentLayout()->hitTest(mapFromScene(scenePos), fuzzy ? Qt::FuzzyHit : Qt::ExactHit); @@ -397,7 +397,7 @@ bool Text::hasSelection() const QString Text::extractSanitizedText(int from, int to) const { - if (!doc) + if (doc == nullptr) return ""; QString txt; diff --git a/src/chatlog/content/timestamp.cpp b/src/chatlog/content/timestamp.cpp index 555faaee99..6177e2c243 100644 --- a/src/chatlog/content/timestamp.cpp +++ b/src/chatlog/content/timestamp.cpp @@ -20,7 +20,7 @@ QDateTime Timestamp::getTime() QSizeF Timestamp::idealSize() { - if (doc) { + if (doc != nullptr) { return QSizeF(qMin(doc->idealWidth(), width), doc->size().height()); } return size; diff --git a/src/chatlog/documentcache.cpp b/src/chatlog/documentcache.cpp index ac6177cab7..d81202c232 100644 --- a/src/chatlog/documentcache.cpp +++ b/src/chatlog/documentcache.cpp @@ -27,7 +27,7 @@ QTextDocument* DocumentCache::pop() void DocumentCache::push(QTextDocument* doc) { - if (doc) { + if (doc != nullptr) { doc->clear(); documents.push(doc); } diff --git a/src/chatlog/textformatter.cpp b/src/chatlog/textformatter.cpp index 036460a9a7..842dd5f36a 100644 --- a/src/chatlog/textformatter.cpp +++ b/src/chatlog/textformatter.cpp @@ -227,7 +227,7 @@ QString TextFormatter::applyMarkdown(const QString& message, bool showFormatting int offset = 0; while (iter.hasNext()) { const QRegularExpressionMatch match = iter.next(); - QString captured = match.captured(!showFormattingSymbols); + QString captured = match.captured(static_cast(!showFormattingSymbols)); if (isTagIntersection(captured)) { continue; } diff --git a/src/core/core.cpp b/src/core/core.cpp index 6688145087..ca9bc45cfa 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -122,7 +122,7 @@ ToxCorePtr Core::makeToxCore(const QByteArray& savedata, const ICoreSettings& se auto toxOptions = ToxOptions::makeToxOptions(savedata, settings); if (toxOptions == nullptr) { qCritical() << "Could not allocate ToxOptions data structure"; - if (err) { + if (err != nullptr) { *err = ToxCoreErrors::ERROR_ALLOC; } return {}; @@ -130,7 +130,7 @@ ToxCorePtr Core::makeToxCore(const QByteArray& savedata, const ICoreSettings& se ToxCorePtr core(new Core(thread, bootstrapNodes, settings)); if (core == nullptr) { - if (err) { + if (err != nullptr) { *err = ToxCoreErrors::ERROR_ALLOC; } return {}; @@ -145,7 +145,7 @@ ToxCorePtr Core::makeToxCore(const QByteArray& savedata, const ICoreSettings& se case TOX_ERR_NEW_LOAD_BAD_FORMAT: qCritical() << "Failed to parse Tox save data"; - if (err) { + if (err != nullptr) { *err = ToxCoreErrors::BAD_PROXY; } return {}; @@ -162,7 +162,7 @@ ToxCorePtr Core::makeToxCore(const QByteArray& savedata, const ICoreSettings& se } qCritical() << "Can't to bind the port"; - if (err) { + if (err != nullptr) { *err = ToxCoreErrors::FAILED_TO_START; } return {}; @@ -171,42 +171,42 @@ ToxCorePtr Core::makeToxCore(const QByteArray& savedata, const ICoreSettings& se case TOX_ERR_NEW_PROXY_BAD_PORT: case TOX_ERR_NEW_PROXY_BAD_TYPE: qCritical() << "Bad proxy, error code:" << tox_err; - if (err) { + if (err != nullptr) { *err = ToxCoreErrors::BAD_PROXY; } return {}; case TOX_ERR_NEW_PROXY_NOT_FOUND: qCritical() << "Proxy not found"; - if (err) { + if (err != nullptr) { *err = ToxCoreErrors::BAD_PROXY; } return {}; case TOX_ERR_NEW_LOAD_ENCRYPTED: qCritical() << "Attempted to load encrypted Tox save data"; - if (err) { + if (err != nullptr) { *err = ToxCoreErrors::INVALID_SAVE; } return {}; case TOX_ERR_NEW_MALLOC: qCritical() << "Memory allocation failed"; - if (err) { + if (err != nullptr) { *err = ToxCoreErrors::ERROR_ALLOC; } return {}; case TOX_ERR_NEW_NULL: qCritical() << "A parameter was null"; - if (err) { + if (err != nullptr) { *err = ToxCoreErrors::FAILED_TO_START; } return {}; default: qCritical() << "Toxcore failed to start, unknown error code:" << tox_err; - if (err) { + if (err != nullptr) { *err = ToxCoreErrors::FAILED_TO_START; } return {}; @@ -219,7 +219,7 @@ ToxCorePtr Core::makeToxCore(const QByteArray& savedata, const ICoreSettings& se core->file = CoreFile::makeCoreFile(core.get(), core->tox.get(), core->coreLoopLock); if (!core->file) { qCritical() << "CoreFile failed to start"; - if (err) { + if (err != nullptr) { *err = ToxCoreErrors::FAILED_TO_START; } return {}; @@ -333,7 +333,7 @@ void Core::process() // TODO(sudden6): recheck if this is still necessary if (checkConnection()) { tolerance = CORE_DISCONNECT_TOLERANCE; - } else if (!(--tolerance)) { + } else if ((--tolerance) == 0) { bootstrapDht(); tolerance = 3 * CORE_DISCONNECT_TOLERANCE; } @@ -795,7 +795,7 @@ void Core::removeGroup(int groupId) * we don't change av at runtime. */ - if (av) { + if (av != nullptr) { av->leaveGroupCall(groupId); } } @@ -814,7 +814,7 @@ QString Core::getUsername() const } int size = tox_self_get_name_size(tox.get()); - if (!size) { + if (size == 0) { return {}; } std::vector nameBuf(size); @@ -896,7 +896,7 @@ QString Core::getStatusMessage() const assert(tox != nullptr); size_t size = tox_self_get_status_message_size(tox.get()); - if (!size) { + if (size == 0u) { return {}; } std::vector nameBuf(size); @@ -998,7 +998,7 @@ void Core::loadFriends() emit friendUsernameChanged(ids[i], getFriendUsername(ids[i])); Tox_Err_Friend_Query queryError; size_t statusMessageSize = tox_friend_get_status_message_size(tox.get(), ids[i], &queryError); - if (PARSE_ERR(queryError) && statusMessageSize) { + if (PARSE_ERR(queryError) && (statusMessageSize != 0u)) { std::vector messageData(statusMessageSize); tox_friend_get_status_message(tox.get(), ids[i], messageData.data(), &queryError); QString friendStatusMessage = @@ -1028,7 +1028,7 @@ void Core::loadGroups() size_t titleSize = tox_conference_get_title_size(tox.get(), groupNumber, &error); const GroupId persistentId = getGroupPersistentId(groupNumber); const QString defaultName = tr("Groupchat %1").arg(persistentId.toString().left(8)); - if (PARSE_ERR(error) || !titleSize) { + if (PARSE_ERR(error) || (titleSize == 0u)) { std::vector nameBuf(titleSize); tox_conference_get_title(tox.get(), groupNumber, nameBuf.data(), &error); if (PARSE_ERR(error)) { @@ -1040,7 +1040,8 @@ void Core::loadGroups() name = defaultName; } if (getGroupAvEnabled(groupNumber)) { - if (toxav_groupchat_enable_av(tox.get(), groupNumber, CoreAV::groupCallCallback, this)) { + if (toxav_groupchat_enable_av(tox.get(), groupNumber, CoreAV::groupCallCallback, this) + != 0) { qCritical() << "Failed to enable audio on loaded group" << groupNumber; } } @@ -1111,7 +1112,7 @@ QString Core::getGroupPeerName(int groupId, int peerId) const Tox_Err_Conference_Peer_Query error; size_t length = tox_conference_peer_get_name_size(tox.get(), groupId, peerId, &error); - if (!PARSE_ERR(error) || !length) { + if (!PARSE_ERR(error) || (length == 0u)) { return QString{}; } @@ -1161,7 +1162,7 @@ QStringList Core::getGroupPeerNames(int groupId) const Tox_Err_Conference_Peer_Query error; size_t length = tox_conference_peer_get_name_size(tox.get(), groupId, i, &error); - if (!PARSE_ERR(error) || !length) { + if (!PARSE_ERR(error) || (length == 0u)) { names.append(QString()); continue; } @@ -1333,7 +1334,7 @@ QString Core::getFriendUsername(uint32_t friendnumber) const Tox_Err_Friend_Query error; size_t nameSize = tox_friend_get_name_size(tox.get(), friendnumber, &error); - if (!PARSE_ERR(error) || !nameSize) { + if (!PARSE_ERR(error) || (nameSize == 0u)) { return QString(); } @@ -1373,7 +1374,7 @@ QString Core::getPeerName(const ToxPk& id) const Tox_Err_Friend_Query queryError; const size_t nameSize = tox_friend_get_name_size(tox.get(), friendId, &queryError); - if (!PARSE_ERR(queryError) || !nameSize) { + if (!PARSE_ERR(queryError) || (nameSize == 0u)) { return {}; } diff --git a/src/core/coreav.cpp b/src/core/coreav.cpp index c8e27c7bdf..df952a7da9 100644 --- a/src/core/coreav.cpp +++ b/src/core/coreav.cpp @@ -189,7 +189,7 @@ void CoreAV::process() bool CoreAV::isCallStarted(const Friend* f) const { QReadLocker locker{&callsLock}; - return f && (calls.find(f->getId()) != calls.end()); + return (f != nullptr) && (calls.find(f->getId()) != calls.end()); } /** @@ -200,7 +200,7 @@ bool CoreAV::isCallStarted(const Friend* f) const bool CoreAV::isCallStarted(const Group* g) const { QReadLocker locker{&callsLock}; - return g && (groupCalls.find(g->getId()) != groupCalls.end()); + return (g != nullptr) && (groupCalls.find(g->getId()) != groupCalls.end()); } /** @@ -346,7 +346,7 @@ bool CoreAV::sendCallAudio(uint32_t callId, const int16_t* pcm, size_t samples, ToxFriendCall const& call = *it->second; if (call.getMuteMic() || !call.isActive() - || !(call.getState() & TOXAV_FRIEND_CALL_STATE_ACCEPTING_A)) { + || ((call.getState() & TOXAV_FRIEND_CALL_STATE_ACCEPTING_A) == 0)) { return true; } @@ -384,7 +384,7 @@ void CoreAV::sendCallVideo(uint32_t callId, std::shared_ptr vframe) ToxFriendCall& call = *it->second; if (!call.getVideoEnabled() || !call.isActive() - || !(call.getState() & TOXAV_FRIEND_CALL_STATE_ACCEPTING_V)) { + || ((call.getState() & TOXAV_FRIEND_CALL_STATE_ACCEPTING_V) == 0)) { return; } @@ -434,7 +434,7 @@ void CoreAV::toggleMuteCallInput(const Friend* f) QWriteLocker locker{&callsLock}; auto it = calls.find(f->getId()); - if (f && (it != calls.end())) { + if ((f != nullptr) && (it != calls.end())) { ToxCall& call = *it->second; call.setMuteMic(!call.getMuteMic()); } @@ -449,7 +449,7 @@ void CoreAV::toggleMuteCallOutput(const Friend* f) QWriteLocker locker{&callsLock}; auto it = calls.find(f->getId()); - if (f && (it != calls.end())) { + if ((f != nullptr) && (it != calls.end())) { ToxCall& call = *it->second; call.setMuteVol(!call.getMuteVol()); } @@ -610,7 +610,7 @@ void CoreAV::muteCallInput(const Group* g, bool mute) QWriteLocker locker{&callsLock}; auto it = groupCalls.find(g->getId()); - if (g && (it != groupCalls.end())) { + if ((g != nullptr) && (it != groupCalls.end())) { it->second->setMuteMic(mute); } } @@ -625,7 +625,7 @@ void CoreAV::muteCallOutput(const Group* g, bool mute) QWriteLocker locker{&callsLock}; auto it = groupCalls.find(g->getId()); - if (g && (it != groupCalls.end())) { + if ((g != nullptr) && (it != groupCalls.end())) { it->second->setMuteVol(mute); } } @@ -639,7 +639,7 @@ bool CoreAV::isGroupCallInputMuted(const Group* g) const { QReadLocker locker{&callsLock}; - if (!g) { + if (g == nullptr) { return false; } @@ -657,7 +657,7 @@ bool CoreAV::isGroupCallOutputMuted(const Group* g) const { QReadLocker locker{&callsLock}; - if (!g) { + if (g == nullptr) { return false; } @@ -675,7 +675,7 @@ bool CoreAV::isCallInputMuted(const Friend* f) const { QReadLocker locker{&callsLock}; - if (!f) { + if (f == nullptr) { return false; } const uint32_t friendId = f->getId(); @@ -692,7 +692,7 @@ bool CoreAV::isCallOutputMuted(const Friend* f) const { QReadLocker locker{&callsLock}; - if (!f) { + if (f == nullptr) { return false; } const uint32_t friendId = f->getId(); @@ -775,40 +775,40 @@ void CoreAV::stateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t state, voi ToxFriendCall& call = *it->second; - if (state & TOXAV_FRIEND_CALL_STATE_ERROR) { + if ((state & TOXAV_FRIEND_CALL_STATE_ERROR) != 0u) { qWarning() << "Call with friend" << friendNum << "died of unnatural causes!"; self->calls.erase(friendNum); locker.unlock(); emit self->avEnd(friendNum, true); - } else if (state & TOXAV_FRIEND_CALL_STATE_FINISHED) { + } else if ((state & TOXAV_FRIEND_CALL_STATE_FINISHED) != 0u) { qDebug() << "Call with friend" << friendNum << "finished quietly"; self->calls.erase(friendNum); locker.unlock(); emit self->avEnd(friendNum); } else { // If our state was null, we started the call and were still ringing - if (!call.getState() && state) { + if ((call.getState() == 0u) && (state != 0u)) { call.setActive(true); bool videoEnabled = call.getVideoEnabled(); call.setState(static_cast(state)); locker.unlock(); emit self->avStart(friendNum, videoEnabled); - } else if ((call.getState() & TOXAV_FRIEND_CALL_STATE_SENDING_V) - && !(state & TOXAV_FRIEND_CALL_STATE_SENDING_V)) { + } else if (((call.getState() & TOXAV_FRIEND_CALL_STATE_SENDING_V) != 0) + && ((state & TOXAV_FRIEND_CALL_STATE_SENDING_V) == 0u)) { qDebug() << "Friend" << friendNum << "stopped sending video"; - if (call.getVideoSource()) { + if (call.getVideoSource() != nullptr) { call.getVideoSource()->stopSource(); } call.setState(static_cast(state)); - } else if (!(call.getState() & TOXAV_FRIEND_CALL_STATE_SENDING_V) - && (state & TOXAV_FRIEND_CALL_STATE_SENDING_V)) { + } else if (((call.getState() & TOXAV_FRIEND_CALL_STATE_SENDING_V) == 0) + && ((state & TOXAV_FRIEND_CALL_STATE_SENDING_V) != 0u)) { // Workaround toxav sometimes firing callbacks for "send last frame" -> "stop sending // video" // out of orders (even though they were sent in order by the other end). // We simply stop the videoSource from emitting anything while the other end says it's // not sending - if (call.getVideoSource()) { + if (call.getVideoSource() != nullptr) { call.getVideoSource()->restartSource(); } @@ -889,7 +889,7 @@ void CoreAV::videoFrameCallback(ToxAV* toxAV, uint32_t friendNum, uint16_t w, ui } CoreVideoSource* videoSource = it->second->getVideoSource(); - if (!videoSource) { + if (videoSource == nullptr) { return; } diff --git a/src/core/coreext.cpp b/src/core/coreext.cpp index 4ec35689ee..b2797b7901 100644 --- a/src/core/coreext.cpp +++ b/src/core/coreext.cpp @@ -22,7 +22,7 @@ extern "C" std::unique_ptr CoreExt::makeCoreExt(Tox* core) { auto toxExtPtr = toxext_init(core); - if (!toxExtPtr) { + if (toxExtPtr == nullptr) { return nullptr; } @@ -93,7 +93,7 @@ uint64_t CoreExt::Packet::addExtendedMessage(QString message) assert(false); qCritical() << "addExtendedMessage called with message of size:" << size << "when max is:" << maxSize << ". Ignoring."; - return false; + return 0u; } ToxString toxString(message); diff --git a/src/core/corefile.cpp b/src/core/corefile.cpp index 00583a8db6..c68b30452d 100644 --- a/src/core/corefile.cpp +++ b/src/core/corefile.cpp @@ -159,7 +159,7 @@ void CoreFile::pauseResumeFile(uint32_t friendId, uint32_t fileId) QMutexLocker locker{coreLoopLock}; ToxFile* file = findFile(friendId, fileId); - if (!file) { + if (file == nullptr) { qWarning("pauseResumeFileSend: No such file in queue"); return; } @@ -194,7 +194,7 @@ void CoreFile::cancelFileSend(uint32_t friendId, uint32_t fileId) QMutexLocker locker{coreLoopLock}; ToxFile* file = findFile(friendId, fileId); - if (!file) { + if (file == nullptr) { qWarning("cancelFileSend: No such file in queue"); return; } @@ -214,7 +214,7 @@ void CoreFile::cancelFileRecv(uint32_t friendId, uint32_t fileId) QMutexLocker locker{coreLoopLock}; ToxFile* file = findFile(friendId, fileId); - if (!file) { + if (file == nullptr) { qWarning("cancelFileRecv: No such file in queue"); return; } @@ -233,7 +233,7 @@ void CoreFile::rejectFileRecvRequest(uint32_t friendId, uint32_t fileId) QMutexLocker locker{coreLoopLock}; ToxFile* file = findFile(friendId, fileId); - if (!file) { + if (file == nullptr) { qWarning("rejectFileRecvRequest: No such file in queue"); return; } @@ -252,7 +252,7 @@ void CoreFile::acceptFileRecvRequest(uint32_t friendId, uint32_t fileId, QString QMutexLocker locker{coreLoopLock}; ToxFile* file = findFile(friendId, fileId); - if (!file) { + if (file == nullptr) { qWarning("acceptFileRecvRequest: No such file in queue"); return; } @@ -324,7 +324,7 @@ void CoreFile::onFileReceiveCallback(Tox* tox, uint32_t friendId, uint32_t fileI const ToxPk friendPk = core->getFriendPublicKey(friendId); if (kind == TOX_FILE_KIND_AVATAR) { - if (!filesize) { + if (filesize == 0u) { qDebug() << QString("Received empty avatar request %1:%2").arg(friendId).arg(fileId); // Avatars of size 0 means explicitely no avatar Tox_Err_File_Control err; @@ -424,7 +424,7 @@ void CoreFile::onFileControlCallback(Tox* tox, uint32_t friendId, uint32_t fileI Core* core = static_cast(vCore); CoreFile* coreFile = core->getCoreFile(); ToxFile* file = coreFile->findFile(friendId, fileId); - if (!file) { + if (file == nullptr) { qWarning("onFileControlCallback: No such file in queue"); return; } @@ -460,13 +460,13 @@ void CoreFile::onFileDataCallback(Tox* tox, uint32_t friendId, uint32_t fileId, Core* core = static_cast(vCore); CoreFile* coreFile = core->getCoreFile(); ToxFile* file = coreFile->findFile(friendId, fileId); - if (!file) { + if (file == nullptr) { qWarning("onFileDataCallback: No such file in queue"); return; } // If we reached EOF, ack and cleanup the transfer - if (!length) { + if (length == 0u) { file->status = ToxFile::FINISHED; if (file->fileKind != TOX_FILE_KIND_AVATAR) { emit coreFile->fileTransferFinished(*file); @@ -520,7 +520,7 @@ void CoreFile::onFileRecvChunkCallback(Tox* tox, uint32_t friendId, uint32_t fil Core* core = static_cast(vCore); CoreFile* coreFile = core->getCoreFile(); ToxFile* file = coreFile->findFile(friendId, fileId); - if (!file) { + if (file == nullptr) { qWarning("onFileRecvChunkCallback: No such file in queue"); Tox_Err_File_Control err; tox_file_control(tox, friendId, fileId, TOX_FILE_CONTROL_CANCEL, &err); @@ -541,7 +541,7 @@ void CoreFile::onFileRecvChunkCallback(Tox* tox, uint32_t friendId, uint32_t fil return; } - if (!length) { + if (length == 0u) { file->status = ToxFile::FINISHED; if (file->fileKind == TOX_FILE_KIND_AVATAR) { QPixmap pic; diff --git a/src/core/toxcall.cpp b/src/core/toxcall.cpp index afb5a1f887..7eeaf2dca3 100644 --- a/src/core/toxcall.cpp +++ b/src/core/toxcall.cpp @@ -135,7 +135,7 @@ ToxFriendCall::ToxFriendCall(uint32_t friendNum, bool VideoEnabled, CoreAV& av_, [&av_, friendNum](std::shared_ptr frame) { av_.sendCallVideo(friendNum, frame); }); - if (!videoInConn) { + if (videoInConn == nullptr) { qDebug() << "Video connection not working"; } } diff --git a/src/core/toxencrypt.cpp b/src/core/toxencrypt.cpp index a966113a28..d9e43e29a3 100644 --- a/src/core/toxencrypt.cpp +++ b/src/core/toxencrypt.cpp @@ -291,7 +291,7 @@ std::unique_ptr ToxEncrypt::makeToxEncrypt(const QString& password, */ QByteArray ToxEncrypt::encrypt(const QByteArray& plaintext) const { - if (!passKey) { + if (passKey == nullptr) { qCritical() << "The passkey is invalid."; return QByteArray{}; } diff --git a/src/core/toxfileprogress.cpp b/src/core/toxfileprogress.cpp index a14317fe4a..90423895bb 100644 --- a/src/core/toxfileprogress.cpp +++ b/src/core/toxfileprogress.cpp @@ -30,7 +30,7 @@ bool ToxFileProgress::addSample(uint64_t bytesSent, QTime now) } auto* active = &samples[activeSample]; - auto* inactive = &samples[!activeSample]; + auto* inactive = &samples[activeSample == 0 ? 1 : 0]; if (bytesSent < active->bytesSent || bytesSent < inactive->bytesSent) { qWarning("Bytes sent has decreased since last sample, ignoring sample"); @@ -55,7 +55,7 @@ bool ToxFileProgress::addSample(uint64_t bytesSent, QTime now) if (active->timestamp.msecsTo(now) >= samplePeriodMs) { // Swap samples and set the newly active sample - activeSample = !activeSample; + activeSample = activeSample == 0 ? 1 : 0; std::swap(active, inactive); } @@ -99,7 +99,7 @@ double ToxFileProgress::getSpeed() const } const auto& active = samples[activeSample]; - const auto& inactive = samples[!activeSample]; + const auto& inactive = samples[activeSample == 0 ? 1 : 0]; return (active.bytesSent - inactive.bytesSent) / double(inactive.timestamp.msecsTo(active.timestamp)) * 1000.0; diff --git a/src/core/toxoptions.cpp b/src/core/toxoptions.cpp index 9adb2ed374..aacc32f8cd 100644 --- a/src/core/toxoptions.cpp +++ b/src/core/toxoptions.cpp @@ -60,7 +60,7 @@ std::unique_ptr ToxOptions::makeToxOptions(const QByteArray& savedat Tox_Err_Options_New err; Tox_Options* tox_opts = tox_options_new(&err); - if (!PARSE_ERR(err) || !tox_opts) { + if (!PARSE_ERR(err) || (tox_opts == nullptr)) { qWarning() << "Failed to create Tox_Options"; return {}; } diff --git a/src/ipc.cpp b/src/ipc.cpp index ce30f14318..05dd476284 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -33,7 +33,7 @@ const char* getCurUsername() QString getIpcKey() { auto* user = getCurUsername(); - if (!user) { + if (user == nullptr) { qWarning() << "Failed to get current username. Will use a global IPC."; user = ""; } @@ -151,13 +151,13 @@ time_t IPC::postEvent(const QString& name, const QByteArray& data, uint32_t dest IPCMemory* mem = global(); time_t result = 0; - for (uint32_t i = 0; !evt && i < EVENT_QUEUE_SIZE; ++i) { + for (uint32_t i = 0; (evt == nullptr) && i < EVENT_QUEUE_SIZE; ++i) { if (mem->events[i].posted == 0) { evt = &mem->events[i]; } } - if (evt) { + if (evt != nullptr) { memset(evt, 0, sizeof(IPCEvent)); memcpy(evt->name, binName.constData(), binName.length()); memcpy(evt->data, data.constData(), data.length()); @@ -218,7 +218,7 @@ bool IPC::isEventAccepted(time_t time) if (difftime(global()->lastProcessed, time) > 0) { IPCMemory* mem = global(); for (uint32_t i = 0; i < EVENT_QUEUE_SIZE; ++i) { - if (mem->events[i].posted == time && mem->events[i].processed) { + if (mem->events[i].posted == time && (mem->events[i].processed != 0)) { result = mem->events[i].accepted; break; } @@ -274,12 +274,12 @@ IPC::IPCEvent* IPC::fetchEvent() // Garbage-collect events that were not processed in EVENT_GC_TIMEOUT // and events that were processed and EVENT_GC_TIMEOUT passed after // so sending instance has time to react to those events. - if ((evt->processed && difftime(time(nullptr), evt->processed) > EVENT_GC_TIMEOUT) - || (!evt->processed && difftime(time(nullptr), evt->posted) > EVENT_GC_TIMEOUT)) { + if (((evt->processed != 0) && difftime(time(nullptr), evt->processed) > EVENT_GC_TIMEOUT) + || ((evt->processed == 0) && difftime(time(nullptr), evt->posted) > EVENT_GC_TIMEOUT)) { memset(evt, 0, sizeof(IPCEvent)); } - if (evt->posted && !evt->processed && evt->sender != getpid() + if ((evt->posted != 0) && (evt->processed == 0) && evt->sender != getpid() && (evt->dest == profileId || (evt->dest == 0 && isCurrentOwnerNoLock()))) { return evt; } @@ -371,7 +371,7 @@ bool IPC::isCurrentOwnerNoLock() return false; #else const void* const data = globalMemory.data(); - if (!data) { + if (data == nullptr) { qWarning() << "isCurrentOwnerNoLock failed to access the memory, returning false"; return false; } diff --git a/src/model/about/aboutfriend.cpp b/src/model/about/aboutfriend.cpp index 4b20030b24..ea99a1325c 100644 --- a/src/model/about/aboutfriend.cpp +++ b/src/model/about/aboutfriend.cpp @@ -112,7 +112,7 @@ bool AboutFriend::clearHistory() { const ToxPk pk = f->getPublicKey(); History* const history = profile.getHistory(); - if (history) { + if (history != nullptr) { history->removeChatHistory(pk); return true; } @@ -123,7 +123,7 @@ bool AboutFriend::clearHistory() bool AboutFriend::isHistoryExistence() { History* const history = profile.getHistory(); - if (history) { + if (history != nullptr) { const ToxPk pk = f->getPublicKey(); return history->historyExists(pk); } diff --git a/src/model/chathistory.cpp b/src/model/chathistory.cpp index dcf540bbdd..5e6cc1a936 100644 --- a/src/model/chathistory.cpp +++ b/src/model/chathistory.cpp @@ -500,7 +500,7 @@ void ChatHistory::breakMessage(DispatchedMessageId id, BrokenMessageReason reaso bool ChatHistory::canUseHistory() const { - return history && settings.getEnableLogging(); + return (history != nullptr) && settings.getEnableLogging(); } /** diff --git a/src/model/chatroom/friendchatroom.cpp b/src/model/chatroom/friendchatroom.cpp index 378b0eeca1..b72e2149e2 100644 --- a/src/model/chatroom/friendchatroom.cpp +++ b/src/model/chatroom/friendchatroom.cpp @@ -157,21 +157,21 @@ bool FriendChatroom::possibleToOpenInNewWindow() const { const auto friendPk = frnd->getPublicKey(); const auto dialogs = dialogsManager->getFriendDialogs(friendPk); - return !dialogs || dialogs->chatroomCount() > 1; + return (dialogs == nullptr) || dialogs->chatroomCount() > 1; } bool FriendChatroom::canBeRemovedFromWindow() const { const auto friendPk = frnd->getPublicKey(); const auto dialogs = dialogsManager->getFriendDialogs(friendPk); - return dialogs && dialogs->hasChat(friendPk); + return (dialogs != nullptr) && dialogs->hasChat(friendPk); } bool FriendChatroom::friendCanBeRemoved() const { const auto friendPk = frnd->getPublicKey(); const auto dialogs = dialogsManager->getFriendDialogs(friendPk); - return !dialogs || !dialogs->hasChat(friendPk); + return (dialogs == nullptr) || !dialogs->hasChat(friendPk); } void FriendChatroom::removeFriendFromDialogs() diff --git a/src/model/chatroom/groupchatroom.cpp b/src/model/chatroom/groupchatroom.cpp index 374937a4dc..8a350b33ae 100644 --- a/src/model/chatroom/groupchatroom.cpp +++ b/src/model/chatroom/groupchatroom.cpp @@ -65,14 +65,14 @@ bool GroupChatroom::possibleToOpenInNewWindow() const { const auto groupId = group->getPersistentId(); const auto dialogs = dialogsManager->getGroupDialogs(groupId); - return !dialogs || dialogs->chatroomCount() > 1; + return (dialogs == nullptr) || dialogs->chatroomCount() > 1; } bool GroupChatroom::canBeRemovedFromWindow() const { const auto groupId = group->getPersistentId(); const auto dialogs = dialogsManager->getGroupDialogs(groupId); - return dialogs && dialogs->hasChat(groupId); + return (dialogs != nullptr) && dialogs->hasChat(groupId); } void GroupChatroom::removeGroupFromDialogs() diff --git a/src/model/exiftransform.cpp b/src/model/exiftransform.cpp index 04e38a2c55..c73c03b023 100644 --- a/src/model/exiftransform.cpp +++ b/src/model/exiftransform.cpp @@ -17,14 +17,14 @@ Orientation getOrientation(QByteArray imageData) ExifData* exifData = exif_data_new_from_data(reinterpret_cast(data), size); - if (!exifData) { + if (exifData == nullptr) { return Orientation::TopLeft; } const ExifByteOrder byteOrder = exif_data_get_byte_order(exifData); const ExifEntry* const exifEntry = exif_data_get_entry(exifData, EXIF_TAG_ORIENTATION); - if (!exifEntry) { + if (exifEntry == nullptr) { exif_data_free(exifData); return Orientation::TopLeft; } @@ -62,24 +62,24 @@ QImage applyTransformation(QImage image, Orientation orientation) case Orientation::TopLeft: break; case Orientation::TopRight: - image = image.mirrored(1, 0); + image = image.mirrored(true, false); break; case Orientation::BottomRight: exifTransform.rotate(180); break; case Orientation::BottomLeft: - image = image.mirrored(0, 1); + image = image.mirrored(false, true); break; case Orientation::LeftTop: exifTransform.rotate(-90); - image = image.mirrored(1, 0); + image = image.mirrored(true, false); break; case Orientation::RightTop: exifTransform.rotate(90); break; case Orientation::RightBottom: exifTransform.rotate(90); - image = image.mirrored(1, 0); + image = image.mirrored(true, false); break; case Orientation::LeftBottom: exifTransform.rotate(-90); diff --git a/src/model/group.cpp b/src/model/group.cpp index 4c97e657e1..474e54c9a5 100644 --- a/src/model/group.cpp +++ b/src/model/group.cpp @@ -33,8 +33,8 @@ Group::Group(int groupId_, const GroupId persistentGroupId, const QString& name, // in groupchats, we only notify on messages containing your name <-- dumb // sound notifications should be on all messages, but system popup notification // on naming is appropriate - hasNewMessages = 0; - userWasMentioned = 0; + hasNewMessages = false; + userWasMentioned = false; regeneratePeerList(); } diff --git a/src/model/notificationgenerator.cpp b/src/model/notificationgenerator.cpp index 9b31c38c39..166d1546d0 100644 --- a/src/model/notificationgenerator.cpp +++ b/src/model/notificationgenerator.cpp @@ -118,7 +118,7 @@ QString generateContent(const QHash& friendNotifications, QPixmap getSenderAvatar(Profile* profile, const ToxPk& sender) { - return profile ? profile->loadAvatar(sender) : QPixmap(); + return profile != nullptr ? profile->loadAvatar(sender) : QPixmap(); } } // namespace diff --git a/src/model/sessionchatlog.cpp b/src/model/sessionchatlog.cpp index 4eb3a17c7d..2a9f3d2a7a 100644 --- a/src/model/sessionchatlog.cpp +++ b/src/model/sessionchatlog.cpp @@ -94,7 +94,7 @@ firstItemAfterDate(QDate date, const std::map& items) QString resolveToxPk(FriendList& friendList, GroupList& groupList, const ToxPk& pk) { Friend* f = friendList.findFriend(pk); - if (f) { + if (f != nullptr) { return f->getDisplayedName(); } diff --git a/src/nexus.cpp b/src/nexus.cpp index e2e957a90d..ffafda71d6 100644 --- a/src/nexus.cpp +++ b/src/nexus.cpp @@ -179,7 +179,7 @@ void Nexus::bootstrapWithProfile(Profile* p) profile = p; - if (profile) { + if (profile != nullptr) { audioControl = std::unique_ptr(Audio::makeAudio(settings)); assert(audioControl != nullptr); profile->getCore().getAv()->setAudio(*audioControl); @@ -271,7 +271,7 @@ void Nexus::onLoadProfile(const QString& name, const QString& pass) */ void Nexus::setProfile(Profile* p) { - if (!p) { + if (p == nullptr) { emit profileLoadFailed(); // Warnings are issued during respective createNew/load calls return; diff --git a/src/persistence/db/rawdatabase.cpp b/src/persistence/db/rawdatabase.cpp index 9c821c43e9..7974785043 100644 --- a/src/persistence/db/rawdatabase.cpp +++ b/src/persistence/db/rawdatabase.cpp @@ -149,14 +149,16 @@ bool RawDatabase::open(const QString& path_, const QString& hexKey) } if (sqlite3_create_function(sqlite, "regexp", 2, SQLITE_UTF8, nullptr, - &RawDatabase::regexpInsensitive, nullptr, nullptr)) { + &RawDatabase::regexpInsensitive, nullptr, nullptr) + != 0) { qWarning() << "Failed to create function regexp"; close(); return false; } if (sqlite3_create_function(sqlite, "regexpsensitive", 2, SQLITE_UTF8, nullptr, - &RawDatabase::regexpSensitive, nullptr, nullptr)) { + &RawDatabase::regexpSensitive, nullptr, nullptr) + != 0) { qWarning() << "Failed to create function regexpsensitive"; close(); return false; @@ -411,7 +413,7 @@ bool RawDatabase::execNow(const RawDatabase::Query& statement) */ bool RawDatabase::execNow(const QVector& statements) { - if (!sqlite) { + if (sqlite == nullptr) { qWarning() << "Trying to exec, but the database is not open"; return false; } @@ -453,7 +455,7 @@ void RawDatabase::execLater(const RawDatabase::Query& statement) void RawDatabase::execLater(const QVector& statements) { - if (!sqlite) { + if (sqlite == nullptr) { qWarning() << "Trying to exec, but the database is not open"; return; } @@ -484,7 +486,7 @@ void RawDatabase::sync() */ bool RawDatabase::setPassword(const QString& password) { - if (!sqlite) { + if (sqlite == nullptr) { qWarning() << "Trying to change the password, but the database is not open"; return false; } @@ -603,7 +605,7 @@ bool RawDatabase::commitDbSwap(const QString& hexKey) */ bool RawDatabase::rename(const QString& newPath) { - if (!sqlite) { + if (sqlite == nullptr) { qWarning() << "Trying to change the password, but the database is not open"; return false; } @@ -637,7 +639,7 @@ bool RawDatabase::rename(const QString& newPath) */ bool RawDatabase::remove() { - if (!sqlite) { + if (sqlite == nullptr) { qWarning() << "Trying to remove the database, but it is not open"; return false; } @@ -730,7 +732,7 @@ void RawDatabase::process() { assert(QThread::currentThread() == workerThread.get()); - if (!sqlite) + if (sqlite == nullptr) return; forever diff --git a/src/persistence/history.cpp b/src/persistence/history.cpp index 677e1678d9..85e0412dd6 100644 --- a/src/persistence/history.cpp +++ b/src/persistence/history.cpp @@ -400,7 +400,7 @@ RawDatabase::Query History::generateFileFinished(RowId id, bool success, const Q const QByteArray& fileHash) { auto file_state = success ? ToxFile::FINISHED : ToxFile::CANCELED; - if (filePath.length()) { + if (filePath.length() != 0) { return RawDatabase::Query(QStringLiteral("UPDATE file_transfers " "SET file_state = %1, file_path = ?, file_hash = ?" "WHERE id = %2") @@ -835,7 +835,7 @@ QList History::getNumMessagesForChatBeforeDateBoundaries(const "WHERE chats.uuid = ?" // filter this conversation "AND countHistory.id <= history.id"); // and filter that our unfiltered table history id only has elements up to history.id - auto limitString = (maxNum) ? QString("LIMIT %1").arg(maxNum) : QString(""); + auto limitString = (maxNum) != 0u ? QString("LIMIT %1").arg(maxNum) : QString(""); auto query = RawDatabase::Query(QStringLiteral("SELECT (%1), (timestamp / 1000 / 60 / 60 / 24) AS day " diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index 4415861567..9ac48e60ed 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -264,7 +264,7 @@ void Settings::updateProfileData(Profile* profile, const QCommandLineParser* par setCurrentProfile(profile->getName()); saveGlobal(); loadPersonal(*profile, newProfile); - if (parser) { + if (parser != nullptr) { applyCommandLineOptions(*parser); } } @@ -736,7 +736,7 @@ void Settings::saveGlobal() */ void Settings::savePersonal() { - if (!loadedProfile) { + if (loadedProfile == nullptr) { qDebug() << "Could not save personal settings because there is no active profile"; return; } diff --git a/src/persistence/settingsserializer.cpp b/src/persistence/settingsserializer.cpp index eb462eee66..a0ab2972b0 100644 --- a/src/persistence/settingsserializer.cpp +++ b/src/persistence/settingsserializer.cpp @@ -159,7 +159,7 @@ void SettingsSerializer::setArrayIndex(int i) void SettingsSerializer::setValue(const QString& key, const QVariant& value) { Value* v = findValue(key); - if (v) { + if (v != nullptr) { v->value = value; } else { Value nv{group, array, arrayIndex, key, value}; @@ -172,7 +172,7 @@ void SettingsSerializer::setValue(const QString& key, const QVariant& value) QVariant SettingsSerializer::value(const QString& key, const QVariant& defaultValue) const { const Value* v = findValue(key); - if (v) + if (v != nullptr) return v->value; else return defaultValue; @@ -217,7 +217,8 @@ bool SettingsSerializer::isSerializedFormat(QString filePath) char fmagic[8]; if (f.read(fmagic, sizeof(fmagic)) != sizeof(fmagic)) return false; - return !memcmp(fmagic, magic, 4) || tox_is_data_encrypted(reinterpret_cast(fmagic)); + return (memcmp(fmagic, magic, 4) == 0) + || tox_is_data_encrypted(reinterpret_cast(fmagic)); } /** @@ -286,7 +287,7 @@ void SettingsSerializer::save() } // Encrypt - if (passKey) { + if (passKey != nullptr) { data = passKey->encrypt(data); } @@ -313,7 +314,7 @@ void SettingsSerializer::readSerialized() // Decrypt if (ToxEncrypt::isEncrypted(data)) { - if (!passKey) { + if (passKey == nullptr) { qCritical() << "The settings file is encrypted, but we don't have a passkey!"; return; } @@ -324,11 +325,11 @@ void SettingsSerializer::readSerialized() return; } } else { - if (passKey) + if (passKey != nullptr) qWarning() << "We have a password, but the settings file is not encrypted"; } - if (memcmp(data.data(), magic, 4)) { + if (memcmp(data.data(), magic, 4) != 0) { qWarning() << "Bad magic!"; return; } @@ -503,7 +504,7 @@ void SettingsSerializer::readIni() std::sort(std::begin(groupsToKill), std::end(groupsToKill), std::greater_equal()); for (int g : groupsToKill) { - if (groupSizes[static_cast(g)]) + if (groupSizes[static_cast(g)] != 0) continue; removeGroup(g); diff --git a/src/platform/camera/v4l2.cpp b/src/platform/camera/v4l2.cpp index 26b7329a99..76cf1d915b 100644 --- a/src/platform/camera/v4l2.cpp +++ b/src/platform/camera/v4l2.cpp @@ -63,12 +63,12 @@ int deviceOpen(QString devName, int* error) goto fail; } - if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { + if ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0u) { *error = ENODEV; goto fail; } - if (!(cap.capabilities & V4L2_CAP_STREAMING)) { + if ((cap.capabilities & V4L2_CAP_STREAMING) == 0u) { *error = ENOSYS; goto fail; } @@ -88,7 +88,7 @@ QVector getDeviceModeFramerates(int fd, unsigned w, unsigned h, uint32_t vfve.height = h; vfve.width = w; - while (!ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &vfve)) { + while (ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &vfve) == 0) { float rate; switch (vfve.type) { case V4L2_FRMSIZE_TYPE_DISCRETE: @@ -122,13 +122,13 @@ QVector v4l2::getDeviceModes(QString devName) v4l2_fmtdesc vfd{}; vfd.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - while (!ioctl(fd, VIDIOC_ENUM_FMT, &vfd)) { + while (ioctl(fd, VIDIOC_ENUM_FMT, &vfd) == 0) { vfd.index++; v4l2_frmsizeenum vfse{}; vfse.pixel_format = vfd.pixelformat; - while (!ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &vfse)) { + while (ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &vfse) == 0) { VideoMode mode; mode.pixel_format = vfse.pixel_format; switch (vfse.type) { @@ -174,12 +174,12 @@ QVector> v4l2::getDeviceList() QStringList deviceFiles; DIR* dir = opendir("/dev"); - if (!dir) + if (dir == nullptr) return devices; dirent* e; - while ((e = readdir(dir))) - if (!strncmp(e->d_name, "video", 5) || !strncmp(e->d_name, "vbi", 3)) + while ((e = readdir(dir)) != nullptr) + if ((strncmp(e->d_name, "video", 5) == 0) || (strncmp(e->d_name, "vbi", 3) == 0)) deviceFiles += QString("/dev/") + QString::fromUtf8(e->d_name); closedir(dir); @@ -194,7 +194,7 @@ QVector> v4l2::getDeviceList() ioctl(fd, VIDIOC_QUERYCAP, &caps); close(fd); - if (caps.device_caps & V4L2_CAP_VIDEO_CAPTURE) + if ((caps.device_caps & V4L2_CAP_VIDEO_CAPTURE) != 0u) devices += {file, QString::fromUtf8(reinterpret_cast(caps.card))}; } return devices; diff --git a/src/platform/capslock_x11.cpp b/src/platform/capslock_x11.cpp index ffe5a53ab9..d362152039 100644 --- a/src/platform/capslock_x11.cpp +++ b/src/platform/capslock_x11.cpp @@ -16,7 +16,7 @@ bool Platform::capsLockEnabled() { Display* d = X11Display::lock(); bool caps_state = false; - if (d) { + if (d != nullptr) { unsigned n; XkbGetIndicatorState(d, XkbUseCoreKbd, &n); caps_state = (n & 0x01) == 1; diff --git a/src/platform/posixsignalnotifier.cpp b/src/platform/posixsignalnotifier.cpp index d2fc2d0502..2bbca2989a 100644 --- a/src/platform/posixsignalnotifier.cpp +++ b/src/platform/posixsignalnotifier.cpp @@ -74,7 +74,7 @@ void PosixSignalNotifier::watchSignal(int signum) action.sa_handler = signalHandler; action.sa_mask = blockMask; // allow old signal to finish before new is raised - if (::sigaction(signum, &action, nullptr)) { + if (::sigaction(signum, &action, nullptr) != 0) { qFatal("Failed to setup signal %d, error = %d", signum, errno); } } @@ -110,7 +110,7 @@ void PosixSignalNotifier::onSignalReceived() PosixSignalNotifier::PosixSignalNotifier() { - if (::socketpair(AF_UNIX, SOCK_STREAM, 0, g_signalSocketPair.data())) { + if (::socketpair(AF_UNIX, SOCK_STREAM, 0, g_signalSocketPair.data()) != 0) { qFatal("Failed to create socket pair, error = %d", errno); } diff --git a/src/platform/timer_x11.cpp b/src/platform/timer_x11.cpp index bf09f9ee02..5030d3cdb7 100644 --- a/src/platform/timer_x11.cpp +++ b/src/platform/timer_x11.cpp @@ -14,7 +14,7 @@ uint32_t Platform::getIdleTime() uint32_t idleTime = 0; Display* display = X11Display::lock(); - if (!display) { + if (display == nullptr) { qDebug() << "XOpenDisplay failed"; X11Display::unlock(); return 0; @@ -22,9 +22,9 @@ uint32_t Platform::getIdleTime() int32_t x11event = 0, x11error = 0; static int32_t hasExtension = XScreenSaverQueryExtension(display, &x11event, &x11error); - if (hasExtension) { + if (hasExtension != 0) { XScreenSaverInfo* info = XScreenSaverAllocInfo(); - if (info) { + if (info != nullptr) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wold-style-cast" XScreenSaverQueryInfo(display, DefaultRootWindow(display), info); diff --git a/src/platform/x11_display.cpp b/src/platform/x11_display.cpp index 6fff0229ce..30eff4042d 100644 --- a/src/platform/x11_display.cpp +++ b/src/platform/x11_display.cpp @@ -21,7 +21,7 @@ struct X11DisplayPrivate } ~X11DisplayPrivate() { - if (display) { + if (display != nullptr) { XCloseDisplay(display); } } diff --git a/src/video/cameradevice.cpp b/src/video/cameradevice.cpp index 07bb52b400..ed3f9f6ce6 100644 --- a/src/video/cameradevice.cpp +++ b/src/video/cameradevice.cpp @@ -79,7 +79,7 @@ CameraDevice* CameraDevice::open(QString devName, AVDictionary** options) CameraDevice* dev = openDevices.value(devName); int aduration; std::string devString; - if (dev) { + if (dev != nullptr) { goto out; } @@ -161,12 +161,12 @@ CameraDevice* CameraDevice::open(QString devName, VideoMode mode) #endif AVDictionary* options = nullptr; - if (!iformat) + if (iformat == nullptr) ; #if USING_V4L else if (devName.startsWith("x11grab#")) { QSize screen; - if (mode.width && mode.height) { + if ((mode.width != 0) && (mode.height != 0)) { screen.setWidth(mode.width); screen.setHeight(mode.height); } else { @@ -228,7 +228,7 @@ CameraDevice* CameraDevice::open(QString devName, VideoMode mode) } CameraDevice* dev = open(devName, &options); - if (options) { + if (options != nullptr) { av_dict_free(&options); } @@ -276,10 +276,10 @@ QVector> CameraDevice::getRawDeviceListGeneric() // Alloc an input device context AVFormatContext* s; - if (!(s = avformat_alloc_context())) + if ((s = avformat_alloc_context()) == nullptr) return devices; - if (!iformat->priv_class || !AV_IS_INPUT_DEVICE(iformat->priv_class->category)) { + if ((iformat->priv_class == nullptr) || !AV_IS_INPUT_DEVICE(iformat->priv_class->category)) { avformat_free_context(s); return devices; } @@ -313,7 +313,7 @@ QVector> CameraDevice::getRawDeviceListGeneric() avdevice_list_devices(s, &devlist); av_dict_free(&tmp); avformat_free_context(s); - if (!devlist) { + if (devlist == nullptr) { qWarning() << "avdevice_list_devices failed"; return devices; } @@ -343,7 +343,7 @@ QVector> CameraDevice::getDeviceList() if (!getDefaultInputFormat()) return devices; - if (!iformat) + if (iformat == nullptr) ; #ifdef Q_OS_WIN else if (QString::fromUtf8(iformat->name) == QString("dshow")) @@ -360,7 +360,7 @@ QVector> CameraDevice::getDeviceList() else devices += getRawDeviceListGeneric(); - if (idesktopFormat) { + if (idesktopFormat != nullptr) { if (QString::fromUtf8(idesktopFormat->name) == QString("x11grab")) { QString dev = "x11grab#"; QByteArray display = qgetenv("DISPLAY"); @@ -446,7 +446,7 @@ QVector CameraDevice::getVideoModes(QString devName) { std::ignore = devName; - if (!iformat) + if (iformat == nullptr) ; else if (isScreen(devName)) return getScreenModes(); @@ -508,7 +508,7 @@ bool CameraDevice::betterPixelFormat(uint32_t a, uint32_t b) bool CameraDevice::getDefaultInputFormat() { QMutexLocker locker(&iformatLock); - if (iformat) { + if (iformat != nullptr) { return true; } @@ -524,7 +524,7 @@ bool CameraDevice::getDefaultInputFormat() // Webcam input formats #if USING_V4L - if ((iformat = av_find_input_format("v4l2"))) + if ((iformat = av_find_input_format("v4l2")) != nullptr) return true; #endif diff --git a/src/video/camerasource.cpp b/src/video/camerasource.cpp index 1472a7c351..efea2f2487 100644 --- a/src/video/camerasource.cpp +++ b/src/video/camerasource.cpp @@ -143,7 +143,7 @@ void CameraSource::setupDevice(const QString& deviceName_, const VideoMode& mode return; } - if (subscriptions) { + if (subscriptions != 0) { // To force close, ignoring optimization int subs = subscriptions; subscriptions = 0; @@ -155,7 +155,7 @@ void CameraSource::setupDevice(const QString& deviceName_, const VideoMode& mode mode = mode_; isNone_ = (deviceName == "none"); - if (subscriptions && !isNone_) { + if ((subscriptions != 0) && !isNone_) { openDevice(); } } @@ -182,7 +182,7 @@ CameraSource::~CameraSource() // Free all remaining VideoFrame VideoFrame::untrackFrames(id, true); - if (cctx) { + if (cctx != nullptr) { avcodec_free_context(&cctx); } #if LIBAVCODEC_VERSION_INT < 3747941 @@ -191,7 +191,7 @@ CameraSource::~CameraSource() } #endif - if (device) { + if (device != nullptr) { for (int i = 0; i < subscriptions; ++i) device->close(); @@ -241,7 +241,7 @@ void CameraSource::openDevice() qDebug() << "Opening device" << deviceName << "subscriptions:" << subscriptions; - if (device) { + if (device != nullptr) { device->open(); emit openFailed(); return; @@ -250,7 +250,7 @@ void CameraSource::openDevice() // We need to create a new CameraDevice device = CameraDevice::open(deviceName, mode); - if (!device) { + if (device == nullptr) { qWarning() << "Failed to open device!"; emit openFailed(); return; @@ -292,7 +292,7 @@ void CameraSource::openDevice() codecId = cparams->codec_id; #endif const AVCodec* codec = avcodec_find_decoder(codecId); - if (!codec) { + if (codec == nullptr) { qWarning() << "Codec not found"; emit openFailed(); return; @@ -367,7 +367,7 @@ void CameraSource::closeDevice() avcodec_close(cctxOrig); cctxOrig = nullptr; #endif - while (device && !device->close()) { + while ((device != nullptr) && !device->close()) { } device = nullptr; } @@ -406,11 +406,11 @@ void CameraSource::stream() // Forward packets to the decoder and grab the decoded frame bool isVideo = packet.stream_index == videoStreamIndex; - bool readyToRecive = isVideo && !avcodec_send_packet(cctx, &packet); + bool readyToRecive = isVideo && (avcodec_send_packet(cctx, &packet) == 0); if (readyToRecive) { AVFrame* frame = av_frame_alloc(); - if (frame && !avcodec_receive_frame(cctx, frame)) { + if ((frame != nullptr) && (avcodec_receive_frame(cctx, frame) == 0)) { VideoFrame* vframe = new VideoFrame(id, frame); emit frameAvailable(vframe->trackFrame()); } else { @@ -427,7 +427,7 @@ void CameraSource::stream() QReadLocker locker{&streamMutex}; // Exit if device is no longer valid - if (!device) { + if (device == nullptr) { break; } diff --git a/src/video/corevideosource.cpp b/src/video/corevideosource.cpp index dbed5941df..06ee58f566 100644 --- a/src/video/corevideosource.cpp +++ b/src/video/corevideosource.cpp @@ -59,7 +59,7 @@ void CoreVideoSource::pushFrame(const vpx_image_t* vpxframe) return; AVFrame* avframe = av_frame_alloc(); - if (!avframe) + if (avframe == nullptr) return; avframe->width = width; diff --git a/src/video/netcamview.cpp b/src/video/netcamview.cpp index bd0cadb5c2..9d19ac8c9d 100644 --- a/src/video/netcamview.cpp +++ b/src/video/netcamview.cpp @@ -166,7 +166,7 @@ void NetCamView::hide() setSource(nullptr); selfVideoSurface->setSource(nullptr); - if (selfFrame) + if (selfFrame != nullptr) selfFrame->deleteLater(); selfFrame = nullptr; diff --git a/src/video/videoframe.cpp b/src/video/videoframe.cpp index c28eb156c4..1f28ab22a9 100644 --- a/src/video/videoframe.cpp +++ b/src/video/videoframe.cpp @@ -549,7 +549,7 @@ AVFrame* VideoFrame::generateAVFrame(const QSize& dimensions, const int pixelFor { AVFrame* ret = av_frame_alloc(); - if (!ret) { + if (ret == nullptr) { return nullptr; } @@ -590,7 +590,7 @@ AVFrame* VideoFrame::generateAVFrame(const QSize& dimensions, const int pixelFor dimensions.height(), static_cast(pixelFormat), resizeAlgo, nullptr, nullptr, nullptr); - if (!swsCtx) { + if (swsCtx == nullptr) { av_freep(&ret->data[0]); #if LIBAVCODEC_VERSION_INT < 3747941 av_frame_unref(ret); diff --git a/src/video/videomode.cpp b/src/video/videomode.cpp index 79d08d0aa2..b3fe4f3b7c 100644 --- a/src/video/videomode.cpp +++ b/src/video/videomode.cpp @@ -66,5 +66,5 @@ uint32_t VideoMode::tolerance() const */ VideoMode::operator bool() const { - return width || height || static_cast(FPS); + return (width != 0) || (height != 0) || (static_cast(FPS) != 0); } diff --git a/src/video/videosurface.cpp b/src/video/videosurface.cpp index 1284f70995..cdfd63e188 100644 --- a/src/video/videosurface.cpp +++ b/src/video/videosurface.cpp @@ -97,7 +97,7 @@ QPixmap VideoSurface::getAvatar() const void VideoSurface::subscribe() { - if (source && hasSubscribed++ == 0) { + if ((source != nullptr) && hasSubscribed++ == 0) { source->subscribe(); connect(source, &VideoSource::frameAvailable, this, &VideoSurface::onNewFrameAvailable); connect(source, &VideoSource::sourceStopped, this, &VideoSurface::onSourceStopped); @@ -106,7 +106,7 @@ void VideoSurface::subscribe() void VideoSurface::unsubscribe() { - if (!source || hasSubscribed == 0) + if ((source == nullptr) || hasSubscribed == 0) return; if (--hasSubscribed != 0) diff --git a/src/widget/chatformheader.cpp b/src/widget/chatformheader.cpp index 0a26d24976..ee3a872352 100644 --- a/src/widget/chatformheader.cpp +++ b/src/widget/chatformheader.cpp @@ -229,8 +229,8 @@ void ChatFormHeader::updateExtensionSupport(ExtensionSet extensions) void ChatFormHeader::updateCallButtons(bool online, bool audio, bool video) { - const bool audioAvaliable = online && (mode & Mode::Audio); - const bool videoAvaliable = online && (mode & Mode::Video); + const bool audioAvaliable = online && ((mode & Mode::Audio) != 0); + const bool videoAvaliable = online && ((mode & Mode::Video) != 0); if (!audioAvaliable) { callState = CallButtonState::Disabled; } else if (video) { diff --git a/src/widget/circlewidget.cpp b/src/widget/circlewidget.cpp index e45b6f549d..631008c2a8 100644 --- a/src/widget/circlewidget.cpp +++ b/src/widget/circlewidget.cpp @@ -89,7 +89,7 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event) QAction* selectedItem = menu.exec(mapToGlobal(event->pos())); - if (selectedItem) { + if (selectedItem != nullptr) { if (selectedItem == renameAction) { editName(); } else if (selectedItem == removeAction) { @@ -162,7 +162,7 @@ void CircleWidget::dropEvent(QDropEvent* event) // Check, that the element is dropped from qTox QObject* o = event->source(); FriendWidget* widget = qobject_cast(o); - if (!widget) + if (widget == nullptr) return; if (!event->mimeData()->hasFormat("toxPk")) { @@ -171,7 +171,7 @@ void CircleWidget::dropEvent(QDropEvent* event) // Check, that the user has a friend with the same ToxId ToxPk toxPk{event->mimeData()->data("toxPk")}; Friend* f = friendList.findFriend(toxPk); - if (!f) + if (f == nullptr) return; // Save CircleWidget before changing the Id @@ -222,7 +222,7 @@ void CircleWidget::updateID(int index) const QWidget* w = friendOnlineLayout()->itemAt(i)->widget(); const FriendWidget* friendWidget = qobject_cast(w); - if (friendWidget) { + if (friendWidget != nullptr) { const Friend* f = friendWidget->getFriend(); settings.setFriendCircleID(f->getPublicKey(), id); } @@ -232,7 +232,7 @@ void CircleWidget::updateID(int index) const QWidget* w = friendOfflineLayout()->itemAt(i)->widget(); const FriendWidget* friendWidget = qobject_cast(w); - if (friendWidget) { + if (friendWidget != nullptr) { const Friend* f = friendWidget->getFriend(); settings.setFriendCircleID(f->getPublicKey(), id); } diff --git a/src/widget/contentdialog.cpp b/src/widget/contentdialog.cpp index 756a63798b..05393e5af1 100644 --- a/src/widget/contentdialog.cpp +++ b/src/widget/contentdialog.cpp @@ -297,7 +297,7 @@ void ContentDialog::cycleChats(bool forward, bool inverse) { QLayout* currentLayout; int index = getCurrentLayout(currentLayout); - if (!currentLayout || index == -1) { + if ((currentLayout == nullptr) || index == -1) { return; } @@ -338,7 +338,7 @@ void ContentDialog::cycleChats(bool forward, bool inverse) QWidget* widget = currentLayout->itemAt(index)->widget(); GenericChatroomWidget* chatWidget = qobject_cast(widget); - if (chatWidget && chatWidget != activeChatroomWidget) { + if ((chatWidget != nullptr) && chatWidget != activeChatroomWidget) { // FIXME: emit should be removed emit chatWidget->chatroomWidgetClicked(chatWidget); } @@ -374,7 +374,7 @@ void ContentDialog::onVideoHide() */ void ContentDialog::updateTitleAndStatusIcon() { - if (!activeChatroomWidget) { + if (activeChatroomWidget == nullptr) { setWindowTitle(username); return; } @@ -436,7 +436,7 @@ bool ContentDialog::event(QEvent* event) { switch (event->type()) { case QEvent::WindowActivate: - if (activeChatroomWidget) { + if (activeChatroomWidget != nullptr) { activeChatroomWidget->resetEventFlags(); activeChatroomWidget->updateStatusLight(); @@ -445,9 +445,9 @@ bool ContentDialog::event(QEvent* event) const Friend* frnd = activeChatroomWidget->getFriend(); Group* group = activeChatroomWidget->getGroup(); - if (frnd) { + if (frnd != nullptr) { emit friendDialogShown(frnd); - } else if (group) { + } else if (group != nullptr) { emit groupDialogShown(group); } } @@ -465,11 +465,11 @@ void ContentDialog::dragEnterEvent(QDragEnterEvent* event) QObject* o = event->source(); FriendWidget* frnd = qobject_cast(o); GroupWidget* group = qobject_cast(o); - if (frnd) { + if (frnd != nullptr) { assert(event->mimeData()->hasFormat("toxPk")); ToxPk toxPk{event->mimeData()->data("toxPk")}; Friend* contact = friendList.findFriend(toxPk); - if (!contact) { + if (contact == nullptr) { return; } @@ -479,11 +479,11 @@ void ContentDialog::dragEnterEvent(QDragEnterEvent* event) if (!hasChat(friendId)) { event->acceptProposedAction(); } - } else if (group) { + } else if (group != nullptr) { assert(event->mimeData()->hasFormat("groupId")); GroupId groupId = GroupId{event->mimeData()->data("groupId")}; Group* contact = groupList.findGroup(groupId); - if (!contact) { + if (contact == nullptr) { return; } @@ -498,21 +498,21 @@ void ContentDialog::dropEvent(QDropEvent* event) QObject* o = event->source(); FriendWidget* frnd = qobject_cast(o); GroupWidget* group = qobject_cast(o); - if (frnd) { + if (frnd != nullptr) { assert(event->mimeData()->hasFormat("toxPk")); const ToxPk toxId(event->mimeData()->data("toxPk")); Friend* contact = friendList.findFriend(toxId); - if (!contact) { + if (contact == nullptr) { return; } emit addFriendDialog(contact, this); ensureSplitterVisible(); - } else if (group) { + } else if (group != nullptr) { assert(event->mimeData()->hasFormat("groupId")); const GroupId groupId(event->mimeData()->data("groupId")); Group* contact = groupList.findGroup(groupId); - if (!contact) { + if (contact == nullptr) { return; } @@ -580,7 +580,7 @@ void ContentDialog::activate(GenericChatroomWidget* widget) contentLayout->clear(); - if (activeChatroomWidget) { + if (activeChatroomWidget != nullptr) { activeChatroomWidget->setAsInactiveChatroom(); } diff --git a/src/widget/contentdialogmanager.cpp b/src/widget/contentdialogmanager.cpp index fe96b1e29d..9ca94042ae 100644 --- a/src/widget/contentdialogmanager.cpp +++ b/src/widget/contentdialogmanager.cpp @@ -56,7 +56,7 @@ FriendWidget* ContentDialogManager::addFriendToDialog(ContentDialog* dialog, const auto& friendPk = friendWidget->getFriend()->getPublicKey(); ContentDialog* lastDialog = getFriendDialog(friendPk); - if (lastDialog) { + if (lastDialog != nullptr) { lastDialog->removeFriend(friendPk); } @@ -72,7 +72,7 @@ GroupWidget* ContentDialogManager::addGroupToDialog(ContentDialog* dialog, const auto& groupId = groupWidget->getGroup()->getPersistentId(); ContentDialog* lastDialog = getGroupDialog(groupId); - if (lastDialog) { + if (lastDialog != nullptr) { lastDialog->removeGroup(groupId); } @@ -103,7 +103,7 @@ ContentDialog* ContentDialogManager::focusDialog( } ContentDialog* dialog = *iter; - if (dialog->windowState() & Qt::WindowMinimized) { + if ((dialog->windowState() & Qt::WindowMinimized) != 0u) { dialog->showNormal(); } diff --git a/src/widget/emoticonswidget.cpp b/src/widget/emoticonswidget.cpp index 5d0f10f650..2f25f3eac1 100644 --- a/src/widget/emoticonswidget.cpp +++ b/src/widget/emoticonswidget.cpp @@ -114,7 +114,7 @@ void EmoticonsWidget::onSmileyClicked() { // emit insert emoticon QWidget* sender = qobject_cast(QObject::sender()); - if (sender) { + if (sender != nullptr) { QString sequence = sender->property("sequence").toString().replace("<", "<").replace(">", ">"); emit insertEmoticon(sequence); @@ -124,7 +124,7 @@ void EmoticonsWidget::onSmileyClicked() void EmoticonsWidget::onPageButtonClicked() { QWidget* sender = qobject_cast(QObject::sender()); - if (sender) { + if (sender != nullptr) { int page = sender->property("pageIndex").toInt(); stack.setCurrentIndex(page); } diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 29115bfa1d..3cb2469031 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -76,15 +76,15 @@ QString secondsToDHMS(quint32 duration) quint32 days = duration / 24; // I assume no one will ever have call longer than a month - if (days) { + if (days != 0u) { return cD + res.asprintf("%dd%02dh %02dm %02ds", days, hours, minutes, seconds); } - if (hours) { + if (hours != 0u) { return cD + res.asprintf("%02dh %02dm %02ds", hours, minutes, seconds); } - if (minutes) { + if (minutes != 0u) { return cD + res.asprintf("%02dm %02ds", minutes, seconds); } @@ -637,7 +637,7 @@ void ChatForm::onCopyStatusMessage() // make sure to copy not truncated text directly from the friend QString text = f->getStatusMessage(); QClipboard* clipboard = QApplication::clipboard(); - if (clipboard) { + if (clipboard != nullptr) { clipboard->setText(text, QClipboard::Clipboard); } } @@ -666,7 +666,7 @@ void ChatForm::updateMuteVolButton() void ChatForm::startCounter() { - if (callDurationTimer) { + if (callDurationTimer != nullptr) { return; } callDurationTimer = new QTimer(); @@ -678,7 +678,7 @@ void ChatForm::startCounter() void ChatForm::stopCounter(bool error) { - if (!callDurationTimer) { + if (callDurationTimer == nullptr) { return; } QString dhms = secondsToDHMS(timeElapsed.elapsed() / 1000); @@ -752,7 +752,7 @@ void ChatForm::showNetcam() QSize minSize = netcam->getSurfaceMinSize(); ContentDialog* current = contentDialogManager.current(); - if (current) { + if (current != nullptr) { current->onVideoShow(minSize); } } @@ -764,7 +764,7 @@ void ChatForm::hideNetcam() } ContentDialog* current = contentDialogManager.current(); - if (current) { + if (current != nullptr) { current->onVideoHide(); } diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index e3aa1eb39c..1bc60c1848 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -83,7 +83,7 @@ QString fontToCss(const QFont& font, const QString& name) QString GenericChatForm::resolveToxPk(const ToxPk& pk) { Friend* f = friendList.findFriend(pk); - if (f) { + if (f != nullptr) { return f->getDisplayedName(); } @@ -422,7 +422,7 @@ void GenericChatForm::onChatContextMenuRequested(QPoint pos) // If we right-clicked on a link, give the option to copy it bool clickedOnLink = false; Text* clickedText = qobject_cast(chatWidget->getContentFromGlobalPos(pos)); - if (clickedText) { + if (clickedText != nullptr) { QPointF scenePos = chatWidget->mapToScene(chatWidget->mapFromGlobal(pos)); QString linkTarget = clickedText->getLinkAt(scenePos); if (!linkTarget.isEmpty()) { @@ -466,7 +466,7 @@ void GenericChatForm::onEmoteButtonClicked() widget.installEventFilter(this); QWidget* sender = qobject_cast(QObject::sender()); - if (sender) { + if (sender != nullptr) { QPoint pos = -QPoint(widget.sizeHint().width() / 2, widget.sizeHint().height()) - QPoint(0, 10); widget.exec(sender->mapToGlobal(pos)); @@ -477,7 +477,7 @@ void GenericChatForm::onEmoteInsertRequested(QString str) { // insert the emoticon QWidget* sender = qobject_cast(QObject::sender()); - if (sender) + if (sender != nullptr) msgEdit->insertPlainText(str); msgEdit->setFocus(); // refocus so that we can continue typing @@ -523,7 +523,7 @@ QDateTime GenericChatForm::getTime(const ChatLine::Ptr& chatLine) const if (chatLine) { Timestamp* const timestamp = qobject_cast(chatLine->getContent(2)); - if (timestamp) { + if (timestamp != nullptr) { return timestamp->getTime(); } else { return QDateTime(); @@ -577,7 +577,7 @@ void GenericChatForm::resizeEvent(QResizeEvent* event) bool GenericChatForm::eventFilter(QObject* object, QEvent* event) { EmoticonsWidget* ev = qobject_cast(object); - if (ev && event->type() == QEvent::KeyPress) { + if ((ev != nullptr) && event->type() == QEvent::KeyPress) { QKeyEvent* key = static_cast(event); msgEdit->sendKeyEvent(key); msgEdit->setFocus(); @@ -588,7 +588,7 @@ bool GenericChatForm::eventFilter(QObject* object, QEvent* event) return false; auto wObject = qobject_cast(object); - if (!wObject || !wObject->isEnabled()) + if ((wObject == nullptr) || !wObject->isEnabled()) return false; switch (event->type()) { @@ -662,7 +662,7 @@ void GenericChatForm::searchFormShow() void GenericChatForm::onLoadHistory() { LoadHistoryDialog dlg(&chatLog); - if (dlg.exec()) { + if (dlg.exec() != 0) { chatWidget->jumpToDate(dlg.getFromDate().date()); } } diff --git a/src/widget/form/groupchatform.cpp b/src/widget/form/groupchatform.cpp index 41992edef8..c15a720b6a 100644 --- a/src/widget/form/groupchatform.cpp +++ b/src/widget/form/groupchatform.cpp @@ -169,7 +169,7 @@ void GroupChatForm::onAttachClicked() void GroupChatForm::updateUserNames() { QLayoutItem* child; - while ((child = namesListLayout->takeAt(0))) { + while ((child = namesListLayout->takeAt(0)) != nullptr) { child->widget()->hide(); delete child->widget(); delete child; @@ -261,7 +261,7 @@ void GroupChatForm::peerAudioPlaying(ToxPk peerPk) peerLabels[peerPk]->style()->unpolish(peerLabels[peerPk]); peerLabels[peerPk]->style()->polish(peerLabels[peerPk]); // TODO(sudden6): check if this can ever be false, cause [] default constructs - if (!peerAudioTimers[peerPk]) { + if (peerAudioTimers[peerPk] == nullptr) { peerAudioTimers[peerPk] = new QTimer(this); peerAudioTimers[peerPk]->setSingleShot(true); connect(peerAudioTimers[peerPk], &QTimer::timeout, [this, peerPk] { @@ -287,7 +287,7 @@ void GroupChatForm::dragEnterEvent(QDragEnterEvent* ev) } ToxPk toxPk{ev->mimeData()->data("toxPk")}; Friend* frnd = friendList.findFriend(toxPk); - if (frnd) + if (frnd != nullptr) ev->acceptProposedAction(); } @@ -298,7 +298,7 @@ void GroupChatForm::dropEvent(QDropEvent* ev) } ToxPk toxPk{ev->mimeData()->data("toxPk")}; Friend* frnd = friendList.findFriend(toxPk); - if (!frnd) + if (frnd == nullptr) return; int friendId = frnd->getId(); @@ -352,7 +352,7 @@ void GroupChatForm::onCallClicked() void GroupChatForm::keyPressEvent(QKeyEvent* ev) { // Push to talk (CTRL+P) - if (ev->key() == Qt::Key_P && (ev->modifiers() & Qt::ControlModifier) && inCall) { + if (ev->key() == Qt::Key_P && ((ev->modifiers() & Qt::ControlModifier) != 0u) && inCall) { onMicMuteToggle(); } @@ -363,7 +363,7 @@ void GroupChatForm::keyPressEvent(QKeyEvent* ev) void GroupChatForm::keyReleaseEvent(QKeyEvent* ev) { // Push to talk (CTRL+P) - if (ev->key() == Qt::Key_P && (ev->modifiers() & Qt::ControlModifier) && inCall) { + if (ev->key() == Qt::Key_P && ((ev->modifiers() & Qt::ControlModifier) != 0u) && inCall) { onMicMuteToggle(); } diff --git a/src/widget/form/groupinviteform.cpp b/src/widget/form/groupinviteform.cpp index eb8ccd010e..0ddeba070d 100644 --- a/src/widget/form/groupinviteform.cpp +++ b/src/widget/form/groupinviteform.cpp @@ -152,7 +152,7 @@ void GroupInviteForm::deleteInviteWidget(const GroupInvite& inviteInfo) void GroupInviteForm::retranslateUi() { headLabel->setText(tr("Groups")); - if (createButton) { + if (createButton != nullptr) { createButton->setText(tr("Create new group")); } inviteBox->setTitle(tr("Group invites")); diff --git a/src/widget/form/searchsettingsform.cpp b/src/widget/form/searchsettingsform.cpp index d636c33e4b..2465fd085b 100644 --- a/src/widget/form/searchsettingsform.cpp +++ b/src/widget/form/searchsettingsform.cpp @@ -157,7 +157,7 @@ void SearchSettingsForm::onChoiceDate() LoadHistoryDialog dlg; dlg.setTitle(tr("Select Date Dialog")); dlg.setInfoLabel(tr("Select a date")); - if (dlg.exec()) { + if (dlg.exec() != 0) { startDate = dlg.getFromDate().date(); updateStartDateLabel(); } diff --git a/src/widget/form/settings/advancedform.cpp b/src/widget/form/settings/advancedform.cpp index 3f67ca2552..1e0d4dd1f8 100644 --- a/src/widget/form/settings/advancedform.cpp +++ b/src/widget/form/settings/advancedform.cpp @@ -125,7 +125,7 @@ void AdvancedForm::on_btnCopyDebug_clicked() } QClipboard* clipboard = QApplication::clipboard(); - if (clipboard) { + if (clipboard != nullptr) { QString debugtext; if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream in(&file); diff --git a/src/widget/form/settings/avform.cpp b/src/widget/form/settings/avform.cpp index 34995e090a..eff8b821b6 100644 --- a/src/widget/form/settings/avform.cpp +++ b/src/widget/form/settings/avform.cpp @@ -106,7 +106,7 @@ void AVForm::hideEvent(QHideEvent* event) audioSink.reset(); audioSrc.reset(); - if (camVideoSurface) { + if (camVideoSurface != nullptr) { camVideoSurface->setSource(nullptr); killVideoSurface(); } @@ -296,7 +296,7 @@ void AVForm::fillCameraModesComboBox() qDebug("width: %d, height: %d, FPS: %f, pixel format: %s", mode.width, mode.height, static_cast(mode.FPS), pixelFormat.c_str()); - if (mode.height && mode.width) { + if ((mode.height != 0) && (mode.width != 0)) { str += QString("%1p").arg(mode.height); } else { str += tr("Default resolution"); @@ -339,7 +339,7 @@ void AVForm::fillScreenModesComboBox() static_cast(mode.FPS), pixelFormat.c_str()); QString name; - if (mode.width && mode.height) + if ((mode.width != 0) && (mode.height != 0)) name = tr("Screen %1").arg(i + 1); else name = tr("Select region"); @@ -598,7 +598,7 @@ void AVForm::on_audioThresholdSlider_valueChanged(int sliderSteps) } void AVForm::createVideoSurface() { - if (camVideoSurface) + if (camVideoSurface != nullptr) return; camVideoSurface = new VideoSurface(QPixmap(), CamFrame); @@ -610,7 +610,7 @@ void AVForm::createVideoSurface() void AVForm::killVideoSurface() { - if (!camVideoSurface) + if (camVideoSurface == nullptr) return; QLayoutItem* child; diff --git a/src/widget/form/settings/genericsettings.cpp b/src/widget/form/settings/genericsettings.cpp index 657ff3fe82..f7d84a1765 100644 --- a/src/widget/form/settings/genericsettings.cpp +++ b/src/widget/form/settings/genericsettings.cpp @@ -62,8 +62,8 @@ void GenericForm::eventsInit() bool GenericForm::eventFilter(QObject* o, QEvent* e) { if ((e->type() == QEvent::Wheel) - && (qobject_cast(o) || qobject_cast(o) - || qobject_cast(o))) { + && ((qobject_cast(o) != nullptr) || (qobject_cast(o) != nullptr) + || (qobject_cast(o) != nullptr))) { e->ignore(); return true; } diff --git a/src/widget/form/settings/userinterfaceform.cpp b/src/widget/form/settings/userinterfaceform.cpp index 65f9b3b269..054d06f038 100644 --- a/src/widget/form/settings/userinterfaceform.cpp +++ b/src/widget/form/settings/userinterfaceform.cpp @@ -377,10 +377,10 @@ void UserInterfaceForm::on_txtChatFontSize_valueChanged(int px) void UserInterfaceForm::on_useNameColors_stateChanged(int value) { - settings.setEnableGroupChatsColor(value); + settings.setEnableGroupChatsColor(value != 0); } void UserInterfaceForm::on_notifyHide_stateChanged(int value) { - settings.setNotifyHide(value); + settings.setNotifyHide(value != 0); } diff --git a/src/widget/form/settings/verticalonlyscroller.cpp b/src/widget/form/settings/verticalonlyscroller.cpp index 4e5114cd99..1d8e5025dd 100644 --- a/src/widget/form/settings/verticalonlyscroller.cpp +++ b/src/widget/form/settings/verticalonlyscroller.cpp @@ -16,13 +16,13 @@ VerticalOnlyScroller::VerticalOnlyScroller(QWidget* parent) void VerticalOnlyScroller::resizeEvent(QResizeEvent* event) { QScrollArea::resizeEvent(event); - if (widget()) + if (widget() != nullptr) widget()->setMaximumWidth(event->size().width()); } void VerticalOnlyScroller::showEvent(QShowEvent* event) { QScrollArea::showEvent(event); - if (widget()) + if (widget() != nullptr) widget()->setMaximumWidth(size().width()); } diff --git a/src/widget/friendlistwidget.cpp b/src/widget/friendlistwidget.cpp index 08fccf73f3..4c4330a009 100644 --- a/src/widget/friendlistwidget.cpp +++ b/src/widget/friendlistwidget.cpp @@ -437,7 +437,7 @@ void FriendListWidget::onGroupchatPositionChanged(bool top) void FriendListWidget::cycleChats(GenericChatroomWidget* activeChatroomWidget, bool forward) { - if (!activeChatroomWidget) { + if (activeChatroomWidget == nullptr) { return; } @@ -445,7 +445,7 @@ void FriendListWidget::cycleChats(GenericChatroomWidget* activeChatroomWidget, b FriendWidget* friendWidget = qobject_cast(activeChatroomWidget); if (mode == SortingMode::Activity) { - if (!friendWidget) { + if (friendWidget == nullptr) { return; } @@ -516,7 +516,7 @@ void FriendListWidget::dragEnterEvent(QDragEnterEvent* event) } ToxPk toxPk(event->mimeData()->data("toxPk")); Friend* frnd = friendList.findFriend(toxPk); - if (frnd) + if (frnd != nullptr) event->acceptProposedAction(); } @@ -525,14 +525,14 @@ void FriendListWidget::dropEvent(QDropEvent* event) // Check, that the element is dropped from qTox QObject* o = event->source(); FriendWidget* widget = qobject_cast(o); - if (!widget) + if (widget == nullptr) return; // Check, that the user has a friend with the same ToxPk assert(event->mimeData()->hasFormat("toxPk")); const ToxPk toxPk{event->mimeData()->data("toxPk")}; Friend* f = friendList.findFriend(toxPk); - if (!f) + if (f == nullptr) return; // Save CircleWidget before changing the Id @@ -541,7 +541,7 @@ void FriendListWidget::dropEvent(QDropEvent* event) moveWidget(widget, f->getStatus(), true); - if (circleWidget) + if (circleWidget != nullptr) circleWidget->updateStatus(); } diff --git a/src/widget/friendwidget.cpp b/src/widget/friendwidget.cpp index b178bd791a..7c86dd0f49 100644 --- a/src/widget/friendwidget.cpp +++ b/src/widget/friendwidget.cpp @@ -188,7 +188,7 @@ getCircleAndFriendList(const Friend* frnd, FriendWidget* fw, Settings& settings) const auto pk = frnd->getPublicKey(); const auto circleId = settings.getFriendCircleID(pk); auto circleWidget = CircleWidget::getFromID(circleId); - auto w = circleWidget ? static_cast(circleWidget) : static_cast(fw); + auto w = circleWidget != nullptr ? static_cast(circleWidget) : static_cast(fw); auto friendList = qobject_cast(w->parentWidget()); return std::make_tuple(circleWidget, friendList); } @@ -245,7 +245,7 @@ void FriendWidget::moveToCircle(int newCircleId) auto oldCircleWidget = CircleWidget::getFromID(oldCircleId); auto newCircleWidget = CircleWidget::getFromID(newCircleId); - if (newCircleWidget) { + if (newCircleWidget != nullptr) { newCircleWidget->addFriendWidget(this, frnd->getStatus()); newCircleWidget->setExpanded(true); s.savePersonal(); @@ -253,7 +253,7 @@ void FriendWidget::moveToCircle(int newCircleId) s.setFriendCircleID(pk, newCircleId); } - if (oldCircleWidget) { + if (oldCircleWidget != nullptr) { oldCircleWidget->updateStatus(); } } @@ -312,7 +312,7 @@ void FriendWidget::updateStatusLight() const Settings& s = settings; const uint32_t circleId = s.getFriendCircleID(frnd->getPublicKey()); CircleWidget* circleWidget = CircleWidget::getFromID(circleId); - if (circleWidget) { + if (circleWidget != nullptr) { circleWidget->setExpanded(true); } diff --git a/src/widget/groupwidget.cpp b/src/widget/groupwidget.cpp index a04db15fe3..227cc34a00 100644 --- a/src/widget/groupwidget.cpp +++ b/src/widget/groupwidget.cpp @@ -93,7 +93,7 @@ void GroupWidget::contextMenuEvent(QContextMenuEvent* event) setBackgroundRole(QPalette::Window); } - if (!selectedItem) { + if (selectedItem == nullptr) { return; } diff --git a/src/widget/passwordedit.cpp b/src/widget/passwordedit.cpp index fd61ec7208..f89ba71262 100644 --- a/src/widget/passwordedit.cpp +++ b/src/widget/passwordedit.cpp @@ -37,7 +37,7 @@ PasswordEdit::~PasswordEdit() void PasswordEdit::registerHandler() { #ifdef ENABLE_CAPSLOCK_INDICATOR - if (!eventHandler) + if (eventHandler == nullptr) eventHandler = new EventHandler(); if (!eventHandler->actions.contains(action)) eventHandler->actions.append(action); @@ -49,7 +49,7 @@ void PasswordEdit::unregisterHandler() #ifdef ENABLE_CAPSLOCK_INDICATOR int idx; - if (eventHandler && (idx = eventHandler->actions.indexOf(action)) >= 0) { + if ((eventHandler != nullptr) && (idx = eventHandler->actions.indexOf(action)) >= 0) { eventHandler->actions.remove(idx); if (eventHandler->actions.isEmpty()) { delete eventHandler; diff --git a/src/widget/qrwidget.cpp b/src/widget/qrwidget.cpp index de65a55a55..26434fc2f5 100644 --- a/src/widget/qrwidget.cpp +++ b/src/widget/qrwidget.cpp @@ -93,7 +93,7 @@ void QRWidget::paintImage() for (int x = 0; x < s; ++x) { const int xx = yy + x; const unsigned char b = qr->data[xx]; - if (b & 0x01) { + if ((b & 0x01) != 0) { const double rx1 = x * scale, ry1 = y * scale; QRectF r(rx1, ry1, scale, scale); painter.drawRects(&r, 1); diff --git a/src/widget/searchform.cpp b/src/widget/searchform.cpp index 4e8d6507d1..29d289da1c 100644 --- a/src/widget/searchform.cpp +++ b/src/widget/searchform.cpp @@ -306,7 +306,7 @@ void LineEdit::keyPressEvent(QKeyEvent* event) int key = event->key(); if ((key == Qt::Key_Enter || key == Qt::Key_Return)) { - if ((event->modifiers() & Qt::ShiftModifier)) { + if ((event->modifiers() & Qt::ShiftModifier) != 0u) { emit clickShiftEnter(); } else { emit clickEnter(); diff --git a/src/widget/style.cpp b/src/widget/style.cpp index b78351e06d..bd594de12b 100644 --- a/src/widget/style.cpp +++ b/src/widget/style.cpp @@ -302,7 +302,7 @@ void Style::repolish(QWidget* w) for (QObject* o : w->children()) { QWidget* c = qobject_cast(o); - if (c) { + if (c != nullptr) { c->style()->unpolish(c); c->style()->polish(c); } diff --git a/src/widget/tool/adjustingscrollarea.cpp b/src/widget/tool/adjustingscrollarea.cpp index 54381a11a5..d19b3fe425 100644 --- a/src/widget/tool/adjustingscrollarea.cpp +++ b/src/widget/tool/adjustingscrollarea.cpp @@ -29,7 +29,7 @@ void AdjustingScrollArea::resizeEvent(QResizeEvent* ev) QSize AdjustingScrollArea::sizeHint() const { - if (widget()) { + if (widget() != nullptr) { int scrollbarWidth = verticalScrollBar()->isVisible() ? verticalScrollBar()->width() : 0; return widget()->sizeHint() + QSize(scrollbarWidth, 0); } diff --git a/src/widget/tool/callconfirmwidget.cpp b/src/widget/tool/callconfirmwidget.cpp index 970c454c82..394684c0f9 100644 --- a/src/widget/tool/callconfirmwidget.cpp +++ b/src/widget/tool/callconfirmwidget.cpp @@ -101,7 +101,7 @@ CallConfirmWidget::CallConfirmWidget(Settings& settings, Style& style, const QWi */ void CallConfirmWidget::reposition() { - if (parentWidget()) + if (parentWidget() != nullptr) parentWidget()->removeEventFilter(this); setParent(anchor->window()); @@ -154,7 +154,7 @@ void CallConfirmWidget::showEvent(QShowEvent* event) void CallConfirmWidget::hideEvent(QHideEvent* event) { std::ignore = event; - if (parentWidget()) + if (parentWidget() != nullptr) parentWidget()->removeEventFilter(this); setParent(nullptr); diff --git a/src/widget/tool/chattextedit.cpp b/src/widget/tool/chattextedit.cpp index df28e5ba22..3abd941d10 100644 --- a/src/widget/tool/chattextedit.cpp +++ b/src/widget/tool/chattextedit.cpp @@ -39,7 +39,7 @@ void ChatTextEdit::keyPressEvent(QKeyEvent* event) return; } if (key == Qt::Key_Tab) { - if (event->modifiers()) + if (event->modifiers() != 0u) event->ignore(); else { emit tabPressed(); @@ -79,12 +79,12 @@ bool ChatTextEdit::pasteIfImage(QKeyEvent* event) { std::ignore = event; const QClipboard* const clipboard = QApplication::clipboard(); - if (!clipboard) { + if (clipboard == nullptr) { return false; } const QMimeData* const mimeData = clipboard->mimeData(); - if (!mimeData || !mimeData->hasImage()) { + if ((mimeData == nullptr) || !mimeData->hasImage()) { return false; } diff --git a/src/widget/tool/movablewidget.cpp b/src/widget/tool/movablewidget.cpp index c257b3b59c..340ed20a2b 100644 --- a/src/widget/tool/movablewidget.cpp +++ b/src/widget/tool/movablewidget.cpp @@ -85,8 +85,8 @@ void MovableWidget::setRatio(float r) void MovableWidget::mousePressEvent(QMouseEvent* event) { - if (event->buttons() & Qt::LeftButton) { - if (!(mode & Resize)) + if ((event->buttons() & Qt::LeftButton) != 0u) { + if ((mode & Resize) == 0) mode |= Moving; lastPoint = event->globalPosition().toPoint(); @@ -95,7 +95,7 @@ void MovableWidget::mousePressEvent(QMouseEvent* event) void MovableWidget::mouseMoveEvent(QMouseEvent* event) { - if (mode & Moving) { + if ((mode & Moving) != 0) { QPoint moveTo = pos() - (lastPoint - event->globalPosition().toPoint()); checkBoundary(moveTo); @@ -126,7 +126,7 @@ void MovableWidget::mouseMoveEvent(QMouseEvent* event) mode &= ~ResizeDown; } - if (mode & Resize) { + if ((mode & Resize) != 0) { const Modes ResizeUpRight = ResizeUp | ResizeRight; const Modes ResizeUpLeft = ResizeUp | ResizeLeft; const Modes ResizeDownRight = ResizeDown | ResizeRight; @@ -136,18 +136,18 @@ void MovableWidget::mouseMoveEvent(QMouseEvent* event) setCursor(Qt::SizeBDiagCursor); else if ((mode & ResizeUpLeft) == ResizeUpLeft || (mode & ResizeDownRight) == ResizeDownRight) setCursor(Qt::SizeFDiagCursor); - else if (mode & (ResizeLeft | ResizeRight)) + else if ((mode & (ResizeLeft | ResizeRight)) != 0) setCursor(Qt::SizeHorCursor); else setCursor(Qt::SizeVerCursor); - if (event->buttons() & Qt::LeftButton) { + if ((event->buttons() & Qt::LeftButton) != 0u) { QPoint lastPosition = pos(); QPoint displacement = lastPoint - event->globalPosition().toPoint(); QSize lastSize = size(); - if (mode & ResizeUp) { + if ((mode & ResizeUp) != 0) { lastSize.setHeight(height() + displacement.y()); if (lastSize.height() > maximumHeight()) @@ -157,7 +157,7 @@ void MovableWidget::mouseMoveEvent(QMouseEvent* event) lastPosition.setY(y() - displacement.y()); } - if (mode & ResizeLeft) { + if ((mode & ResizeLeft) != 0) { lastSize.setWidth(width() + displacement.x()); if (lastSize.width() > maximumWidth()) lastPosition.setX(x() - displacement.x() + (lastSize.width() - maximumWidth())); @@ -165,10 +165,10 @@ void MovableWidget::mouseMoveEvent(QMouseEvent* event) lastPosition.setX(x() - displacement.x()); } - if (mode & ResizeRight) + if ((mode & ResizeRight) != 0) lastSize.setWidth(width() - displacement.x()); - if (mode & ResizeDown) + if ((mode & ResizeDown) != 0) lastSize.setHeight(height() - displacement.y()); if (lastSize.height() > maximumHeight()) @@ -177,11 +177,11 @@ void MovableWidget::mouseMoveEvent(QMouseEvent* event) if (lastSize.width() > maximumWidth()) lastSize.setWidth(maximumWidth()); - if (mode & (ResizeLeft | ResizeRight)) { - if (mode & (ResizeUp | ResizeDown)) { + if ((mode & (ResizeLeft | ResizeRight)) != 0) { + if ((mode & (ResizeUp | ResizeDown)) != 0) { int height = lastSize.width() / getRatio(); - if (!(mode & ResizeDown)) + if ((mode & ResizeDown) == 0) lastPosition.setY(lastPosition.y() - (height - lastSize.height())); resize(lastSize.width(), height); @@ -225,7 +225,7 @@ void MovableWidget::mouseDoubleClickEvent(QMouseEvent* event) if (!(event->buttons() & Qt::LeftButton)) return; - if (!graphicsEffect()) { + if (graphicsEffect() == nullptr) { QGraphicsOpacityEffect* opacityEffect = new QGraphicsOpacityEffect(this); opacityEffect->setOpacity(0.5); setGraphicsEffect(opacityEffect); diff --git a/src/widget/tool/screenshotgrabber.cpp b/src/widget/tool/screenshotgrabber.cpp index cbc3f4ed11..68d1875a75 100644 --- a/src/widget/tool/screenshotgrabber.cpp +++ b/src/widget/tool/screenshotgrabber.cpp @@ -228,7 +228,7 @@ void ScreenshotGrabber::hideVisibleWindows() void ScreenshotGrabber::restoreHiddenWindows() { foreach (QWidget* w, mHiddenWindows) { - if (w) + if (w != nullptr) w->setVisible(true); } diff --git a/src/widget/translator.cpp b/src/widget/translator.cpp index 9ea235dc68..94be53f492 100644 --- a/src/widget/translator.cpp +++ b/src/widget/translator.cpp @@ -26,10 +26,10 @@ void Translator::translate(const QString& localeName) { QMutexLocker locker{&lock}; - if (!core_translator) + if (core_translator == nullptr) core_translator = new QTranslator(); - if (!app_translator) + if (app_translator == nullptr) app_translator = new QTranslator(); // Remove old translations diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index baf11bee97..f6d321779d 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -472,7 +472,7 @@ void Widget::init() ui->transferButton->setCheckable(true); ui->settingsButton->setCheckable(true); - if (contentLayout) { + if (contentLayout != nullptr) { onAddClicked(); } @@ -530,7 +530,7 @@ bool Widget::eventFilter(QObject* obj, QEvent* event) case QEvent::WindowStateChange: ce = static_cast(event); - if (state.testFlag(Qt::WindowMinimized) && obj) { + if (state.testFlag(Qt::WindowMinimized) && (obj != nullptr)) { wasMaximized = ce->oldState().testFlag(Qt::WindowMaximized); } @@ -827,12 +827,12 @@ void Widget::onSeparateWindowChanged(bool separate, bool clicked) QSize size; QPoint pos; - if (contentLayout) { + if (contentLayout != nullptr) { pos = mapToGlobal(ui->mainSplitter->widget(1)->pos()); size = ui->mainSplitter->widget(1)->size(); } - if (contentLayout) { + if (contentLayout != nullptr) { contentLayout->clear(); contentLayout->parentWidget()->setParent(nullptr); // Remove from splitter. contentLayout->parentWidget()->hide(); @@ -847,7 +847,7 @@ void Widget::onSeparateWindowChanged(bool separate, bool clicked) showNormal(); resize(width, height()); - if (settingsWidget) { + if (settingsWidget != nullptr) { ContentLayout* contentLayout_ = createContentDialog((DialogType::SettingDialog)); contentLayout_->parentWidget()->resize(size); contentLayout_->parentWidget()->move(pos); @@ -1096,7 +1096,7 @@ void Widget::dispatchFile(ToxFile file) { const auto& friendId = friendList->id2Key(file.friendId); Friend* f = friendList->findFriend(friendId); - if (!f) { + if (f == nullptr) { return; } @@ -1249,7 +1249,7 @@ void Widget::onCoreFriendStatusChanged(int friendId, Status::Status status) { const auto& friendPk = friendList->id2Key(friendId); Friend* f = friendList->findFriend(friendPk); - if (!f) { + if (f == nullptr) { return; } @@ -1295,7 +1295,7 @@ void Widget::onFriendStatusMessageChanged(int friendId, const QString& message) { const auto& friendPk = friendList->id2Key(friendId); Friend* f = friendList->findFriend(friendPk); - if (!f) { + if (f == nullptr) { return; } @@ -1329,7 +1329,7 @@ void Widget::onFriendUsernameChanged(int friendId, const QString& username) { const auto& friendPk = friendList->id2Key(friendId); Friend* f = friendList->findFriend(friendPk); - if (!f) { + if (f == nullptr) { return; } @@ -1363,7 +1363,7 @@ void Widget::openDialog(GenericChatroomWidget* widget, bool newWindow) const Friend* frnd = widget->getFriend(); const Group* group = widget->getGroup(); bool chatFormIsSet; - if (frnd) { + if (frnd != nullptr) { form = chatForms[frnd->getPublicKey()]; contentDialogManager->focusChat(frnd->getPersistentId()); chatFormIsSet = contentDialogManager->chatWidgetExists(frnd->getPersistentId()); @@ -1390,7 +1390,7 @@ void Widget::openDialog(GenericChatroomWidget* widget, bool newWindow) dialog->show(); - if (frnd) { + if (frnd != nullptr) { addFriendDialog(frnd, dialog); } else { addGroupDialog(group, dialog); @@ -1400,7 +1400,7 @@ void Widget::openDialog(GenericChatroomWidget* widget, bool newWindow) dialog->activateWindow(); } else { hideMainForms(widget); - if (frnd) { + if (frnd != nullptr) { chatForms[frnd->getPublicKey()]->show(contentLayout); } else { groupChatForms[group->getPersistentId()]->show(contentLayout); @@ -1414,7 +1414,7 @@ void Widget::onFriendMessageReceived(uint32_t friendnumber, const QString& messa { const auto& friendId = friendList->id2Key(friendnumber); Friend* f = friendList->findFriend(friendId); - if (!f) { + if (f == nullptr) { return; } @@ -1425,7 +1425,7 @@ void Widget::onReceiptReceived(int friendId, ReceiptNum receipt) { const auto& friendKey = friendList->id2Key(friendId); Friend* f = friendList->findFriend(friendKey); - if (!f) { + if (f == nullptr) { return; } @@ -1436,7 +1436,7 @@ void Widget::onExtendedMessageSupport(uint32_t friendNumber, bool supported) { const auto& friendKey = friendList->id2Key(friendNumber); Friend* f = friendList->findFriend(friendKey); - if (!f) { + if (f == nullptr) { return; } @@ -1462,7 +1462,7 @@ void Widget::addFriendDialog(const Friend* frnd, ContentDialog* dialog) bool isSeparate = settings.getSeparateWindow(); FriendWidget* widget = friendWidgets[friendPk]; bool isCurrent = activeChatroomWidget == widget; - if (!contentDialog && !isSeparate && isCurrent) { + if ((contentDialog == nullptr) && !isSeparate && isCurrent) { onAddClicked(); } @@ -1513,7 +1513,7 @@ void Widget::addGroupDialog(const Group* group, ContentDialog* dialog) bool separated = settings.getSeparateWindow(); GroupWidget* widget = groupWidgets[groupId]; bool isCurrentWindow = activeChatroomWidget == widget; - if (!groupDialog && !separated && isCurrentWindow) { + if ((groupDialog == nullptr) && !separated && isCurrentWindow) { onAddClicked(); } @@ -1563,7 +1563,7 @@ bool Widget::newFriendMessageAlert(const ToxPk& friendId, const QString& text, b contentDialog = createContentDialog(); } else { contentDialog = contentDialogManager->current(); - if (!contentDialog) { + if (contentDialog == nullptr) { contentDialog = createContentDialog(); } } @@ -1787,7 +1787,7 @@ void Widget::removeFriend(Friend* f, bool fake) delete chatForm; delete f; - if (contentLayout && contentLayout->mainHead->layout()->isEmpty()) { + if ((contentLayout != nullptr) && contentLayout->mainHead->layout()->isEmpty()) { onAddClicked(); } } @@ -2102,7 +2102,7 @@ void Widget::removeGroup(Group* g, bool fake) groupAlertConnections.remove(groupId); delete g; - if (contentLayout && contentLayout->mainHead->layout()->isEmpty()) { + if ((contentLayout != nullptr) && contentLayout->mainHead->layout()->isEmpty()) { onAddClicked(); } } @@ -2117,7 +2117,7 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId) assert(core != nullptr); Group* g = groupList->findGroup(groupId); - if (g) { + if (g != nullptr) { qWarning() << "Group already exists"; return g; } @@ -2195,7 +2195,7 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId) void Widget::onEmptyGroupCreated(uint32_t groupnumber, const GroupId& groupId, const QString& title) { Group* group = createGroup(groupnumber, groupId); - if (!group) { + if (group == nullptr) { return; } if (title.isEmpty()) { @@ -2234,7 +2234,7 @@ bool Widget::event(QEvent* e) ui->friendList->updateVisualTracking(); break; case QEvent::WindowActivate: - if (activeChatroomWidget) { + if (activeChatroomWidget != nullptr) { activeChatroomWidget->resetEventFlags(); activeChatroomWidget->updateStatusLight(); setWindowTitle(activeChatroomWidget->getTitle()); @@ -2266,7 +2266,7 @@ void Widget::onUserAwayCheck() uint32_t autoAwayTime = settings.getAutoAwayTime() * 60 * 1000; bool online = static_cast(ui->statusButton->property("status").toInt()) == Status::Status::Online; - bool away = autoAwayTime && Platform::getIdleTime() >= autoAwayTime; + bool away = (autoAwayTime != 0u) && Platform::getIdleTime() >= autoAwayTime; if (online && away) { qDebug() << "auto away activated at" << QTime::currentTime().toString(); @@ -2283,7 +2283,7 @@ void Widget::onUserAwayCheck() void Widget::onEventIconTick() { if (eventFlag) { - eventIcon ^= true; + eventIcon ^= 1; updateIcons(); } } @@ -2294,7 +2294,7 @@ void Widget::onTryCreateTrayIcon() { #ifndef XX_UBUNTU1604_XX static int32_t tries = 15; - if (!icon && tries--) { + if (!icon && ((tries--) != 0)) { if (QSystemTrayIcon::isSystemTrayAvailable()) { icon = std::unique_ptr(new QSystemTrayIcon); updateIcons(); @@ -2379,7 +2379,7 @@ void Widget::onFriendTypingChanged(uint32_t friendnumber, bool isTyping) { const auto& friendId = friendList->id2Key(friendnumber); Friend* f = friendList->findFriend(friendId); - if (!f) { + if (f == nullptr) { return; } @@ -2605,7 +2605,7 @@ void Widget::friendRequestsUpdate() if (unreadFriendRequests == 0) { delete friendRequestsButton; friendRequestsButton = nullptr; - } else if (!friendRequestsButton) { + } else if (friendRequestsButton == nullptr) { friendRequestsButton = new QPushButton(this); friendRequestsButton->setObjectName("green"); ui->statusLayout->insertWidget(2, friendRequestsButton); @@ -2616,7 +2616,7 @@ void Widget::friendRequestsUpdate() }); } - if (friendRequestsButton) { + if (friendRequestsButton != nullptr) { friendRequestsButton->setText(tr("%n new friend request(s)", "", unreadFriendRequests)); } } @@ -2626,7 +2626,7 @@ void Widget::groupInvitesUpdate() if (unreadGroupInvites == 0) { delete groupInvitesButton; groupInvitesButton = nullptr; - } else if (!groupInvitesButton) { + } else if (groupInvitesButton == nullptr) { groupInvitesButton = new QPushButton(this); groupInvitesButton->setObjectName("green"); ui->statusLayout->insertWidget(2, groupInvitesButton); @@ -2634,7 +2634,7 @@ void Widget::groupInvitesUpdate() connect(groupInvitesButton, &QPushButton::released, this, &Widget::onGroupClicked); } - if (groupInvitesButton) { + if (groupInvitesButton != nullptr) { groupInvitesButton->setText(tr("%n new group invite(s)", "", unreadGroupInvites)); } } @@ -2680,7 +2680,7 @@ void Widget::retranslateUi() actionQuit->setText(tr("Exit", "Tray action menu to exit Tox")); actionShow->setText(tr("Show", "Tray action menu to show qTox window")); - if (!settings.getSeparateWindow() && (settingsWidget && settingsWidget->isShown())) { + if (!settings.getSeparateWindow() && ((settingsWidget != nullptr) && settingsWidget->isShown())) { setWindowTitle(fromDialogType(DialogType::SettingDialog)); } @@ -2707,7 +2707,7 @@ void Widget::retranslateUi() void Widget::focusChatInput() { - if (activeChatroomWidget) { + if (activeChatroomWidget != nullptr) { if (const Friend* f = activeChatroomWidget->getFriend()) { chatForms[f->getPublicKey()]->focusInput(); } else if (Group* g = activeChatroomWidget->getGroup()) { diff --git a/test/model/friendlistmanager_test.cpp b/test/model/friendlistmanager_test.cpp index d8314c2757..8663c179eb 100644 --- a/test/model/friendlistmanager_test.cpp +++ b/test/model/friendlistmanager_test.cpp @@ -145,7 +145,7 @@ class FriendItemsBuilder "user with long nickname two"}; for (int i = 0; i < testNames.size(); ++i) { - int unsortedIndex = i % 2 ? i - 1 : testNames.size() - i - 1; // Mixes positions + int unsortedIndex = (i % 2) != 0 ? i - 1 : testNames.size() - i - 1; // Mixes positions int sortedByActivityIndex = testNames.size() - i - 1; unsortedAllFriends.append(testNames[unsortedIndex]); sortedByNameOfflineFriends.append(testNames[i]); @@ -169,7 +169,7 @@ class FriendItemsBuilder "user with long nickname two online"}; for (int i = 0; i < testNames.size(); ++i) { - int unsortedIndex = i % 2 ? i - 1 : testNames.size() - i - 1; + int unsortedIndex = (i % 2) != 0 ? i - 1 : testNames.size() - i - 1; int sortedByActivityIndex = testNames.size() - i - 1; unsortedAllFriends.append(testNames[unsortedIndex]); sortedByNameOnlineFriends.append(testNames[i]);