1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #3741

bitok (1):
      refactor: fixes of static analyze warnings
This commit is contained in:
Diadlo 2016-09-25 00:57:04 +03:00
commit 7c4e9e6153
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
13 changed files with 35 additions and 27 deletions

View File

@ -351,7 +351,7 @@ void Nexus::updateWindowsArg(QWindow* closedWindow)
windowMenu->addSeparator();
QAction* dockLast;
if (dockMenu->actions().count() != 0)
if (!dockMenu->actions().isEmpty())
dockLast = dockMenu->actions().first();
else
dockLast = nullptr;

View File

@ -60,7 +60,7 @@ private:
struct Value
{
Value() : group{-2},array{-2},key{QString()},value{}{}
Value() : group{-2},array{-2},arrayIndex{-2},key{QString()},value{}{}
Value(qint64 group, qint64 array, int arrayIndex, QString key, QVariant value)
: group{group}, array{array}, arrayIndex{arrayIndex}, key{key}, value{value} {}
qint64 group;

View File

@ -80,7 +80,7 @@ QVector<QPair<QString,QString>> DirectShow::getDeviceList()
devIdString = wcharToUtf8(olestr);
// replace ':' with '_' since FFmpeg uses : to delimitate sources
for (unsigned i = 0; i < strlen(devIdString); i++)
for (size_t i = 0; i < strlen(devIdString); i++)
if (devIdString[i] == ':')
devIdString[i] = '_';
@ -146,7 +146,7 @@ static IBaseFilter* getDevFilter(QString devName)
devIdString = wcharToUtf8(olestr);
// replace ':' with '_' since FFmpeg uses : to delimitate sources
for (unsigned i = 0; i < strlen(devIdString); i++)
for (size_t i = 0; i < strlen(devIdString); i++)
if (devIdString[i] == ':')
devIdString[i] = '_';

View File

@ -163,13 +163,13 @@ bool CategoryWidget::cycleContacts(bool forward)
}
if (forward)
{
if (listLayout->getLayoutOnline()->count() != 0)
if (!listLayout->getLayoutOnline()->isEmpty())
{
setExpanded(true);
emitChatroomWidget(listLayout->getLayoutOnline(), 0);
return true;
}
else if (listLayout->getLayoutOffline()->count() != 0)
else if (!listLayout->getLayoutOffline()->isEmpty())
{
setExpanded(true);
emitChatroomWidget(listLayout->getLayoutOffline(), 0);
@ -178,13 +178,13 @@ bool CategoryWidget::cycleContacts(bool forward)
}
else
{
if (listLayout->getLayoutOffline()->count() != 0)
if (!listLayout->getLayoutOffline()->isEmpty())
{
setExpanded(true);
emitChatroomWidget(listLayout->getLayoutOffline(), listLayout->getLayoutOffline()->count() - 1);
return true;
}
else if (listLayout->getLayoutOnline()->count() != 0)
else if (!listLayout->getLayoutOnline()->isEmpty())
{
setExpanded(true);
emitChatroomWidget(listLayout->getLayoutOnline(), listLayout->getLayoutOnline()->count() - 1);

View File

@ -328,9 +328,9 @@ void ContentDialog::cycleContacts(bool forward, bool loop)
if (!loop && index == currentLayout->count() - 1)
{
bool groupsOnTop = Settings::getInstance().getGroupchatPosition();
bool offlineEmpty = friendLayout->getLayoutOffline()->count() == 0;
bool onlineEmpty = offlineEmpty && ((friendLayout->getLayoutOnline()->count() == 0 && groupsOnTop) || !groupsOnTop);
bool groupsEmpty = offlineEmpty && ((groupLayout.getLayout()->count() == 0 && !groupsOnTop) || groupsOnTop);
bool offlineEmpty = friendLayout->getLayoutOffline()->isEmpty();
bool onlineEmpty = offlineEmpty && (friendLayout->getLayoutOnline()->isEmpty() || !groupsOnTop);
bool groupsEmpty = offlineEmpty && (groupLayout.getLayout()->isEmpty() || groupsOnTop);
if ((currentLayout == friendLayout->getLayoutOffline())
|| (currentLayout == friendLayout->getLayoutOnline() && groupsEmpty)

View File

@ -65,6 +65,8 @@
#include "src/nexus.h"
#include "src/persistence/profile.h"
const QString ChatForm::ACTION_PREFIX = QStringLiteral("/me ");
ChatForm::ChatForm(Friend* chatFriend)
: f(chatFriend)
, isTyping(false)
@ -751,7 +753,7 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
// Show each messages
ToxId authorId = ToxId(it.sender);
QString authorStr = !it.dispName.isEmpty() ? it.dispName : (authorId.isSelf() ? Core::getInstance()->getUsername() : resolveToxId(authorId));
bool isAction = it.message.startsWith("/me ", Qt::CaseInsensitive);
bool isAction = it.message.startsWith(ACTION_PREFIX, Qt::CaseInsensitive);
bool needSending = !it.isSent && authorId.isSelf();
ChatMessage::Ptr msg = ChatMessage::createChatMessage(authorStr,
@ -972,9 +974,9 @@ void ChatForm::SendMessageStr(QString msg)
if (msg.isEmpty())
return;
bool isAction = msg.startsWith("/me ", Qt::CaseInsensitive);
bool isAction = msg.startsWith(ACTION_PREFIX, Qt::CaseInsensitive);
if (isAction)
msg = msg = msg.right(msg.length() - 4);
msg.remove(0, ACTION_PREFIX.length());
QList<CString> splittedMsg = Core::splitMessage(msg, TOX_MAX_MESSAGE_LENGTH);
QDateTime timestamp = QDateTime::currentDateTime();
@ -984,7 +986,7 @@ void ChatForm::SendMessageStr(QString msg)
QString qt_msg = CString::toString(c_msg.data(), c_msg.size());
QString qt_msg_hist = qt_msg;
if (isAction)
qt_msg_hist = "/me " + qt_msg;
qt_msg_hist = ACTION_PREFIX + qt_msg;
bool status = !Settings::getInstance().getFauxOfflineMessaging();

View File

@ -53,6 +53,8 @@ public:
virtual void show(ContentLayout* contentLayout) final override;
static const QString ACTION_PREFIX;
signals:
void sendFile(uint32_t friendId, QString, QString, long long);
void aliasChanged(const QString& alias);
@ -108,6 +110,7 @@ protected:
virtual void showEvent(QShowEvent* event) final override;
private:
CoreAV* coreav;
Friend* f;
CroppingLabel *statusMessageLabel;

View File

@ -412,12 +412,12 @@ void GenericChatForm::onSaveLogClicked()
Timestamp* rightCol = qobject_cast<Timestamp*>(l->getContent(2));
if (!rightCol)
return;
break;
ChatLineContent* middleCol = l->getContent(1);
ChatLineContent* leftCol = l->getContent(0);
QString timestamp = (!rightCol || rightCol->getTime().isNull()) ? tr("Not sent") : rightCol->getText();
QString timestamp = rightCol->getTime().isNull() ? tr("Not sent") : rightCol->getText();
QString nick = leftCol->getText();
QString msg = middleCol->getText();

View File

@ -29,6 +29,7 @@
#include "src/widget/style.h"
#include "src/widget/flowlayout.h"
#include "src/widget/translator.h"
#include "src/widget/form/chatform.h"
#include "src/video/groupnetcamview.h"
#include <QDebug>
#include <QTimer>
@ -153,9 +154,9 @@ void GroupChatForm::onSendTriggered()
if (group->getPeersCount() != 1)
{
if (msg.startsWith("/me ", Qt::CaseInsensitive))
if (msg.startsWith(ChatForm::ACTION_PREFIX, Qt::CaseInsensitive))
{
msg = msg.right(msg.length() - 4);
msg.remove(0, ChatForm::ACTION_PREFIX.length());
emit sendAction(group->getGroupId(), msg);
}
else
@ -165,8 +166,8 @@ void GroupChatForm::onSendTriggered()
}
else
{
if (msg.startsWith("/me ", Qt::CaseInsensitive))
addSelfMessage(msg.right(msg.length() - 4), true, QDateTime::currentDateTime(), true);
if (msg.startsWith(ChatForm::ACTION_PREFIX, Qt::CaseInsensitive))
addSelfMessage(msg.mid(ChatForm::ACTION_PREFIX.length()), true, QDateTime::currentDateTime(), true);
else
addSelfMessage(msg, false, QDateTime::currentDateTime(), true);
}

View File

@ -77,14 +77,14 @@ int FriendListLayout::indexOfFriendWidget(GenericChatItemWidget* widget, bool on
void FriendListLayout::moveFriendWidgets(FriendListWidget* listWidget)
{
while (friendOnlineLayout.getLayout()->count() != 0)
while (!friendOnlineLayout.getLayout()->isEmpty())
{
QWidget* getWidget = friendOnlineLayout.getLayout()->takeAt(0)->widget();
FriendWidget* friendWidget = qobject_cast<FriendWidget*>(getWidget);
listWidget->moveWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus(), true);
}
while (friendOfflineLayout.getLayout()->count() != 0)
while (!friendOfflineLayout.getLayout()->isEmpty())
{
QWidget* getWidget = friendOfflineLayout.getLayout()->takeAt(0)->widget();

View File

@ -308,11 +308,11 @@ void FriendListWidget::setMode(Mode mode)
listLayout->removeItem(listLayout->getLayoutOnline());
listLayout->removeItem(listLayout->getLayoutOffline());
listLayout->removeItem(circleLayout->getLayout());
listLayout->insertLayout(1, activityLayout);
if (circleLayout != nullptr)
{
listLayout->removeItem(circleLayout->getLayout());
QLayoutItem* item;
while ((item = circleLayout->getLayout()->takeAt(0)) != nullptr)
{
@ -323,6 +323,8 @@ void FriendListWidget::setMode(Mode mode)
circleLayout = nullptr;
}
listLayout->insertLayout(1, activityLayout);
reDraw();
}
}

View File

@ -41,7 +41,7 @@ void GenericChatItemLayout::addSortedWidget(GenericChatItemWidget* widget, int s
int GenericChatItemLayout::indexOfSortedWidget(GenericChatItemWidget* widget) const
{
if (layout->count() == 0)
if (layout->isEmpty())
return -1;
int index = indexOfClosestSortedWidget(widget);

View File

@ -1148,7 +1148,7 @@ void Widget::onFriendMessageReceived(int friendId, const QString& message, bool
Profile* profile = Nexus::getProfile();
if (profile->isHistoryEnabled())
profile->getHistory()->addNewMessage(f->getToxId().publicKey, isAction ? "/me " + f->getDisplayedName() + " " + message : message,
profile->getHistory()->addNewMessage(f->getToxId().publicKey, isAction ? ChatForm::ACTION_PREFIX + f->getDisplayedName() + " " + message : message,
f->getToxId().publicKey, timestamp, true, f->getDisplayedName());
newFriendMessageAlert(friendId);