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

refactor(chatform): make ChatForm use signals for updateFriendActivity

This commit is contained in:
jenli669 2019-06-29 09:49:29 +02:00
parent cff845ffa7
commit 20979744c9
No known key found for this signature in database
GPG Key ID: 8267F9F7C2BF7E5E
6 changed files with 43 additions and 43 deletions

View File

@ -74,8 +74,7 @@ static constexpr int TYPING_NOTIFICATION_DURATION = 3000;
const QString ChatForm::ACTION_PREFIX = QStringLiteral("/me ");
namespace
{
namespace {
QString secondsToDHMS(quint32 duration)
{
QString res;
@ -155,9 +154,8 @@ ChatForm::ChatForm(Friend* chatFriend, IChatLog& chatLog, IMessageDispatcher& me
connect(headWidget, &ChatFormHeader::videoCallTriggered, this, &ChatForm::onVideoCallTriggered);
connect(headWidget, &ChatFormHeader::micMuteToggle, this, &ChatForm::onMicMuteToggle);
connect(headWidget, &ChatFormHeader::volMuteToggle, this, &ChatForm::onVolMuteToggle);
connect(sendButton, &QPushButton::pressed, this, &ChatForm::updateFriendActivity);
connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::updateFriendActivity);
connect(sendButton, &QPushButton::pressed, this, &ChatForm::callUpdateFriendActivity);
connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::callUpdateFriendActivity);
connect(msgEdit, &ChatTextEdit::textChanged, this, &ChatForm::onTextEditChanged);
connect(msgEdit, &ChatTextEdit::pasteImage, this, &ChatForm::sendImage);
connect(statusMessageLabel, &CroppingLabel::customContextMenuRequested, this,
@ -201,10 +199,9 @@ void ChatForm::setStatusMessage(const QString& newMessage)
statusMessageLabel->setToolTip(Qt::convertFromPlainText(newMessage, Qt::WhiteSpaceNormal));
}
void ChatForm::updateFriendActivity()
void ChatForm::callUpdateFriendActivity()
{
// TODO: Remove Widget::getInstance()
Widget::getInstance()->updateFriendActivity(f);
emit updateFriendActivity(*f);
}
void ChatForm::updateFriendActivityForFile(const ToxFile& file)
@ -212,9 +209,7 @@ void ChatForm::updateFriendActivityForFile(const ToxFile& file)
if (file.friendId != f->getId()) {
return;
}
// TODO: Remove Widget::getInstance()
Widget::getInstance()->updateFriendActivity(f);
emit updateFriendActivity(*f);
}
void ChatForm::onFileNameChanged(const ToxPk& friendPk)
@ -351,7 +346,7 @@ void ChatForm::showOutgoingCall(bool video)
addSystemInfoMessage(tr("Calling %1").arg(f->getDisplayedName()), ChatMessage::INFO,
QDateTime::currentDateTime());
emit outgoingNotification();
Widget::getInstance()->updateFriendActivity(f);
emit updateFriendActivity(*f);
}
void ChatForm::onAnswerCallTriggered(bool video)

View File

@ -65,6 +65,7 @@ signals:
void endCallNotification();
void rejectCall(uint32_t friendId);
void acceptCall(uint32_t friendId);
void updateFriendActivity(Friend& frnd);
public slots:
void onAvInvite(uint32_t friendId, bool video);
@ -75,7 +76,6 @@ public slots:
void clearChatArea();
private slots:
void updateFriendActivity();
void updateFriendActivityForFile(const ToxFile& file);
void onAttachClicked() override;
void onScreenshotClicked() override;
@ -97,6 +97,8 @@ private slots:
void doScreenshot();
void onCopyStatusMessage();
void callUpdateFriendActivity();
private:
void updateMuteMicButton();
void updateMuteVolButton();

View File

@ -326,7 +326,7 @@ void FriendWidget::updateStatusLight()
circleWidget->setExpanded(true);
}
Widget::getInstance()->updateFriendActivity(frnd);
emit updateFriendActivity(*frnd);
}
statusPic.setMargin(event ? 1 : 3);

View File

@ -55,6 +55,7 @@ signals:
void friendHistoryRemoved();
void friendWidgetRenamed(FriendWidget* friendWidget);
void searchCircle(CircleWidget& circleWidget);
void updateFriendActivity(Friend& frnd);
public slots:
void onAvatarSet(const ToxPk& friendPk, const QPixmap& pic);

View File

@ -1157,6 +1157,7 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
std::make_shared<ChatHistory>(*newfriend, history, *core, Settings::getInstance(),
*friendMessageDispatcher);
auto friendForm = new ChatForm(newfriend, *chatHistory, *friendMessageDispatcher);
connect(friendForm, &ChatForm::updateFriendActivity, this, &Widget::updateFriendActivity);
friendMessageDispatchers[friendPk] = friendMessageDispatcher;
friendChatLogs[friendPk] = chatHistory;
@ -1704,14 +1705,14 @@ void Widget::onFileReceiveRequested(const ToxFile& file)
true, true);
}
void Widget::updateFriendActivity(const Friend* frnd)
void Widget::updateFriendActivity(const Friend& frnd)
{
const ToxPk& pk = frnd->getPublicKey();
const ToxPk& pk = frnd.getPublicKey();
const auto oldTime = settings.getFriendActivity(pk);
const auto newTime = QDateTime::currentDateTime();
settings.setFriendActivity(pk, newTime);
FriendWidget* widget = friendWidgets[frnd->getPublicKey()];
contactListWidget->moveWidget(widget, frnd->getStatus());
FriendWidget* widget = friendWidgets[frnd.getPublicKey()];
contactListWidget->moveWidget(widget, frnd.getStatus());
contactListWidget->updateActivityTime(oldTime); // update old category widget
}
@ -1928,7 +1929,7 @@ void Widget::onGroupInviteReceived(const GroupInvite& inviteInfo)
const uint32_t friendId = inviteInfo.getFriendId();
const ToxPk& friendPk = FriendList::id2Key(friendId);
const Friend* f = FriendList::findFriend(friendPk);
updateFriendActivity(f);
updateFriendActivity(*f);
const uint8_t confType = inviteInfo.getType();
if (confType == TOX_CONFERENCE_TYPE_TEXT || confType == TOX_CONFERENCE_TYPE_AV) {
@ -2706,4 +2707,5 @@ void Widget::connectCircleWidget(CircleWidget& circleWidget)
void Widget::connectFriendWidget(FriendWidget& friendWidget)
{
connect(&friendWidget, &FriendWidget::searchCircle, this, &Widget::searchCircle);
connect(&friendWidget, &FriendWidget::updateFriendActivity, this, &Widget::updateFriendActivity);
}

View File

@ -174,7 +174,6 @@ public slots:
void onReceiptReceived(int friendId, ReceiptNum receipt);
void onFriendRequestReceived(const ToxPk& friendPk, const QString& message);
void onFileReceiveRequested(const ToxFile& file);
void updateFriendActivity(const Friend* frnd);
void onEmptyGroupCreated(uint32_t groupnumber, const GroupId& groupId, const QString& title);
void onGroupJoined(int groupNum, const GroupId& groupId);
void onGroupInviteReceived(const GroupInvite& inviteInfo);
@ -243,6 +242,7 @@ private slots:
void connectCircleWidget(CircleWidget& circleWidget);
void connectFriendWidget(FriendWidget& friendWidget);
void searchCircle(CircleWidget& circleWidget);
void updateFriendActivity(const Friend& frnd);
private:
// QMainWindow overrides