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(); windowMenu->addSeparator();
QAction* dockLast; QAction* dockLast;
if (dockMenu->actions().count() != 0) if (!dockMenu->actions().isEmpty())
dockLast = dockMenu->actions().first(); dockLast = dockMenu->actions().first();
else else
dockLast = nullptr; dockLast = nullptr;

View File

@ -60,7 +60,7 @@ private:
struct Value 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) Value(qint64 group, qint64 array, int arrayIndex, QString key, QVariant value)
: group{group}, array{array}, arrayIndex{arrayIndex}, key{key}, value{value} {} : group{group}, array{array}, arrayIndex{arrayIndex}, key{key}, value{value} {}
qint64 group; qint64 group;

View File

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

View File

@ -163,13 +163,13 @@ bool CategoryWidget::cycleContacts(bool forward)
} }
if (forward) if (forward)
{ {
if (listLayout->getLayoutOnline()->count() != 0) if (!listLayout->getLayoutOnline()->isEmpty())
{ {
setExpanded(true); setExpanded(true);
emitChatroomWidget(listLayout->getLayoutOnline(), 0); emitChatroomWidget(listLayout->getLayoutOnline(), 0);
return true; return true;
} }
else if (listLayout->getLayoutOffline()->count() != 0) else if (!listLayout->getLayoutOffline()->isEmpty())
{ {
setExpanded(true); setExpanded(true);
emitChatroomWidget(listLayout->getLayoutOffline(), 0); emitChatroomWidget(listLayout->getLayoutOffline(), 0);
@ -178,13 +178,13 @@ bool CategoryWidget::cycleContacts(bool forward)
} }
else else
{ {
if (listLayout->getLayoutOffline()->count() != 0) if (!listLayout->getLayoutOffline()->isEmpty())
{ {
setExpanded(true); setExpanded(true);
emitChatroomWidget(listLayout->getLayoutOffline(), listLayout->getLayoutOffline()->count() - 1); emitChatroomWidget(listLayout->getLayoutOffline(), listLayout->getLayoutOffline()->count() - 1);
return true; return true;
} }
else if (listLayout->getLayoutOnline()->count() != 0) else if (!listLayout->getLayoutOnline()->isEmpty())
{ {
setExpanded(true); setExpanded(true);
emitChatroomWidget(listLayout->getLayoutOnline(), listLayout->getLayoutOnline()->count() - 1); 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) if (!loop && index == currentLayout->count() - 1)
{ {
bool groupsOnTop = Settings::getInstance().getGroupchatPosition(); bool groupsOnTop = Settings::getInstance().getGroupchatPosition();
bool offlineEmpty = friendLayout->getLayoutOffline()->count() == 0; bool offlineEmpty = friendLayout->getLayoutOffline()->isEmpty();
bool onlineEmpty = offlineEmpty && ((friendLayout->getLayoutOnline()->count() == 0 && groupsOnTop) || !groupsOnTop); bool onlineEmpty = offlineEmpty && (friendLayout->getLayoutOnline()->isEmpty() || !groupsOnTop);
bool groupsEmpty = offlineEmpty && ((groupLayout.getLayout()->count() == 0 && !groupsOnTop) || groupsOnTop); bool groupsEmpty = offlineEmpty && (groupLayout.getLayout()->isEmpty() || groupsOnTop);
if ((currentLayout == friendLayout->getLayoutOffline()) if ((currentLayout == friendLayout->getLayoutOffline())
|| (currentLayout == friendLayout->getLayoutOnline() && groupsEmpty) || (currentLayout == friendLayout->getLayoutOnline() && groupsEmpty)

View File

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

View File

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

View File

@ -412,12 +412,12 @@ void GenericChatForm::onSaveLogClicked()
Timestamp* rightCol = qobject_cast<Timestamp*>(l->getContent(2)); Timestamp* rightCol = qobject_cast<Timestamp*>(l->getContent(2));
if (!rightCol) if (!rightCol)
return; break;
ChatLineContent* middleCol = l->getContent(1); ChatLineContent* middleCol = l->getContent(1);
ChatLineContent* leftCol = l->getContent(0); 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 nick = leftCol->getText();
QString msg = middleCol->getText(); QString msg = middleCol->getText();

View File

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

View File

@ -77,14 +77,14 @@ int FriendListLayout::indexOfFriendWidget(GenericChatItemWidget* widget, bool on
void FriendListLayout::moveFriendWidgets(FriendListWidget* listWidget) void FriendListLayout::moveFriendWidgets(FriendListWidget* listWidget)
{ {
while (friendOnlineLayout.getLayout()->count() != 0) while (!friendOnlineLayout.getLayout()->isEmpty())
{ {
QWidget* getWidget = friendOnlineLayout.getLayout()->takeAt(0)->widget(); QWidget* getWidget = friendOnlineLayout.getLayout()->takeAt(0)->widget();
FriendWidget* friendWidget = qobject_cast<FriendWidget*>(getWidget); FriendWidget* friendWidget = qobject_cast<FriendWidget*>(getWidget);
listWidget->moveWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus(), true); 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(); 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->getLayoutOnline());
listLayout->removeItem(listLayout->getLayoutOffline()); listLayout->removeItem(listLayout->getLayoutOffline());
listLayout->removeItem(circleLayout->getLayout());
listLayout->insertLayout(1, activityLayout);
if (circleLayout != nullptr) if (circleLayout != nullptr)
{ {
listLayout->removeItem(circleLayout->getLayout());
QLayoutItem* item; QLayoutItem* item;
while ((item = circleLayout->getLayout()->takeAt(0)) != nullptr) while ((item = circleLayout->getLayout()->takeAt(0)) != nullptr)
{ {
@ -323,6 +323,8 @@ void FriendListWidget::setMode(Mode mode)
circleLayout = nullptr; circleLayout = nullptr;
} }
listLayout->insertLayout(1, activityLayout);
reDraw(); reDraw();
} }
} }

View File

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

View File

@ -1148,7 +1148,7 @@ void Widget::onFriendMessageReceived(int friendId, const QString& message, bool
Profile* profile = Nexus::getProfile(); Profile* profile = Nexus::getProfile();
if (profile->isHistoryEnabled()) 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()); f->getToxId().publicKey, timestamp, true, f->getDisplayedName());
newFriendMessageAlert(friendId); newFriendMessageAlert(friendId);