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:
parent
cff845ffa7
commit
20979744c9
|
@ -74,34 +74,33 @@ static constexpr int TYPING_NOTIFICATION_DURATION = 3000;
|
|||
|
||||
const QString ChatForm::ACTION_PREFIX = QStringLiteral("/me ");
|
||||
|
||||
namespace
|
||||
namespace {
|
||||
QString secondsToDHMS(quint32 duration)
|
||||
{
|
||||
QString secondsToDHMS(quint32 duration)
|
||||
{
|
||||
QString res;
|
||||
QString cD = ChatForm::tr("Call duration: ");
|
||||
quint32 seconds = duration % 60;
|
||||
duration /= 60;
|
||||
quint32 minutes = duration % 60;
|
||||
duration /= 60;
|
||||
quint32 hours = duration % 24;
|
||||
quint32 days = duration / 24;
|
||||
QString res;
|
||||
QString cD = ChatForm::tr("Call duration: ");
|
||||
quint32 seconds = duration % 60;
|
||||
duration /= 60;
|
||||
quint32 minutes = duration % 60;
|
||||
duration /= 60;
|
||||
quint32 hours = duration % 24;
|
||||
quint32 days = duration / 24;
|
||||
|
||||
// I assume no one will ever have call longer than a month
|
||||
if (days) {
|
||||
return cD + res.sprintf("%dd%02dh %02dm %02ds", days, hours, minutes, seconds);
|
||||
}
|
||||
|
||||
if (hours) {
|
||||
return cD + res.sprintf("%02dh %02dm %02ds", hours, minutes, seconds);
|
||||
}
|
||||
|
||||
if (minutes) {
|
||||
return cD + res.sprintf("%02dm %02ds", minutes, seconds);
|
||||
}
|
||||
|
||||
return cD + res.sprintf("%02ds", seconds);
|
||||
// I assume no one will ever have call longer than a month
|
||||
if (days) {
|
||||
return cD + res.sprintf("%dd%02dh %02dm %02ds", days, hours, minutes, seconds);
|
||||
}
|
||||
|
||||
if (hours) {
|
||||
return cD + res.sprintf("%02dh %02dm %02ds", hours, minutes, seconds);
|
||||
}
|
||||
|
||||
if (minutes) {
|
||||
return cD + res.sprintf("%02dm %02ds", minutes, seconds);
|
||||
}
|
||||
|
||||
return cD + res.sprintf("%02ds", seconds);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
ChatForm::ChatForm(Friend* chatFriend, IChatLog& chatLog, IMessageDispatcher& messageDispatcher)
|
||||
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -326,7 +326,7 @@ void FriendWidget::updateStatusLight()
|
|||
circleWidget->setExpanded(true);
|
||||
}
|
||||
|
||||
Widget::getInstance()->updateFriendActivity(frnd);
|
||||
emit updateFriendActivity(*frnd);
|
||||
}
|
||||
|
||||
statusPic.setMargin(event ? 1 : 3);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user