mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor: Use const Friend pointer
This commit is contained in:
parent
1a0a1d6949
commit
238f10c44f
|
@ -119,7 +119,7 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event)
|
|||
qobject_cast<FriendWidget*>(friendOnlineLayout()->itemAt(i)->widget());
|
||||
|
||||
if (friendWidget != nullptr) {
|
||||
Friend* f = friendWidget->getFriend();
|
||||
const Friend* f = friendWidget->getFriend();
|
||||
dialog->addFriend(f);
|
||||
}
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event)
|
|||
qobject_cast<FriendWidget*>(friendOfflineLayout()->itemAt(i)->widget());
|
||||
|
||||
if (friendWidget != nullptr) {
|
||||
Friend* f = friendWidget->getFriend();
|
||||
const Friend* f = friendWidget->getFriend();
|
||||
dialog->addFriend(f);
|
||||
}
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ void CircleWidget::onExpand()
|
|||
|
||||
void CircleWidget::onAddFriendWidget(FriendWidget* w)
|
||||
{
|
||||
Friend* f = w->getFriend();
|
||||
const Friend* f = w->getFriend();
|
||||
ToxPk toxId = f->getPublicKey();
|
||||
Settings::getInstance().setFriendCircleID(toxId, id);
|
||||
}
|
||||
|
|
|
@ -161,12 +161,11 @@ ContentDialog::~ContentDialog()
|
|||
Translator::unregister(this);
|
||||
}
|
||||
|
||||
FriendWidget* ContentDialog::addFriend(Friend* frnd)
|
||||
FriendWidget* ContentDialog::addFriend(const Friend* frnd)
|
||||
{
|
||||
bool compact = Settings::getInstance().getCompactLayout();
|
||||
uint32_t friendId = frnd->getFriendId();
|
||||
QString name = frnd->getDisplayedName();
|
||||
FriendWidget* friendWidget = new FriendWidget(friendId, name, compact);
|
||||
FriendWidget* friendWidget = new FriendWidget(frnd, compact);
|
||||
friendLayout->addFriendWidget(friendWidget, frnd->getStatus());
|
||||
|
||||
ChatForm* form = frnd->getChatForm();
|
||||
|
@ -561,7 +560,7 @@ bool ContentDialog::event(QEvent* event)
|
|||
|
||||
updateTitleAndStatusIcon();
|
||||
|
||||
Friend* frnd = activeChatroomWidget->getFriend();
|
||||
const Friend* frnd = activeChatroomWidget->getFriend();
|
||||
Group* group = activeChatroomWidget->getGroup();
|
||||
|
||||
if (frnd) {
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
ContentDialog(SettingsWidget* settingsWidget, QWidget* parent = 0);
|
||||
~ContentDialog();
|
||||
|
||||
FriendWidget* addFriend(Friend* f);
|
||||
FriendWidget* addFriend(const Friend* f);
|
||||
GroupWidget* addGroup(int groupId, const QString& name);
|
||||
void removeFriend(int friendId);
|
||||
void removeGroup(int groupId);
|
||||
|
@ -80,7 +80,7 @@ public:
|
|||
static ContentDialog* getGroupDialog(int groupId);
|
||||
|
||||
signals:
|
||||
void friendDialogShown(Friend* f);
|
||||
void friendDialogShown(const Friend* f);
|
||||
void groupDialogShown(Group* g);
|
||||
void activated();
|
||||
|
||||
|
|
|
@ -80,14 +80,14 @@ void FriendListLayout::moveFriendWidgets(FriendListWidget* listWidget)
|
|||
QWidget* getWidget = friendOnlineLayout.getLayout()->takeAt(0)->widget();
|
||||
|
||||
FriendWidget* friendWidget = qobject_cast<FriendWidget*>(getWidget);
|
||||
Friend* f = FriendList::findFriend(friendWidget->friendId);
|
||||
const Friend* f = friendWidget->getFriend();
|
||||
listWidget->moveWidget(friendWidget, f->getStatus(), true);
|
||||
}
|
||||
while (!friendOfflineLayout.getLayout()->isEmpty()) {
|
||||
QWidget* getWidget = friendOfflineLayout.getLayout()->takeAt(0)->widget();
|
||||
|
||||
FriendWidget* friendWidget = qobject_cast<FriendWidget*>(getWidget);
|
||||
Friend* f = FriendList::findFriend(friendWidget->friendId);
|
||||
const Friend* f = friendWidget->getFriend();
|
||||
listWidget->moveWidget(friendWidget, f->getStatus(), true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ Time getTime(const QDate& date)
|
|||
return Time::LongAgo;
|
||||
}
|
||||
|
||||
QDate getDateFriend(Friend* contact)
|
||||
QDate getDateFriend(const Friend* contact)
|
||||
{
|
||||
return Settings::getInstance().getFriendActivity(contact->getPublicKey());
|
||||
}
|
||||
|
@ -260,8 +260,7 @@ void FriendListWidget::moveFriends(QLayout* layout)
|
|||
if (circleWidget) {
|
||||
circleWidget->moveFriendWidgets(this);
|
||||
} else if (friendWidget) {
|
||||
int friendId = friendWidget->friendId;
|
||||
Friend* contact = FriendList::findFriend(friendId);
|
||||
const Friend* contact = friendWidget->getFriend();
|
||||
QDate activityDate = getDateFriend(contact);
|
||||
int time = static_cast<int>(getTime(activityDate));
|
||||
|
||||
|
@ -294,7 +293,7 @@ void FriendListWidget::addFriendWidget(FriendWidget* w, Status s, int circleInde
|
|||
|
||||
void FriendListWidget::removeFriendWidget(FriendWidget* w)
|
||||
{
|
||||
Friend* contact = FriendList::findFriend(w->friendId);
|
||||
const Friend* contact = w->getFriend();
|
||||
if (mode == Activity) {
|
||||
QDate activityDate = getDateFriend(contact);
|
||||
int time = static_cast<int>(getTime(activityDate));
|
||||
|
@ -322,7 +321,7 @@ void FriendListWidget::addCircleWidget(FriendWidget* friendWidget)
|
|||
CircleWidget* circleWidget = createCircleWidget();
|
||||
if (circleWidget != nullptr) {
|
||||
if (friendWidget != nullptr) {
|
||||
Friend* f = FriendList::findFriend(friendWidget->friendId);
|
||||
const Friend* f = friendWidget->getFriend();
|
||||
ToxPk toxPk = f->getPublicKey();
|
||||
int circleId = Settings::getInstance().getFriendCircleID(toxPk);
|
||||
CircleWidget* circleOriginal = CircleWidget::getFromID(circleId);
|
||||
|
@ -403,23 +402,26 @@ void FriendListWidget::onGroupchatPositionChanged(bool top)
|
|||
|
||||
void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget, bool forward)
|
||||
{
|
||||
if (activeChatroomWidget == nullptr)
|
||||
if (!activeChatroomWidget) {
|
||||
return;
|
||||
}
|
||||
|
||||
int index = -1;
|
||||
FriendWidget* friendWidget = qobject_cast<FriendWidget*>(activeChatroomWidget);
|
||||
|
||||
if (mode == Activity) {
|
||||
if (friendWidget == nullptr)
|
||||
if (!friendWidget) {
|
||||
return;
|
||||
}
|
||||
|
||||
QDate activityDate = getDateFriend(FriendList::findFriend(friendWidget->friendId));
|
||||
QDate activityDate = getDateFriend(friendWidget->getFriend());
|
||||
index = static_cast<int>(getTime(activityDate));
|
||||
QWidget* widget = activityLayout->itemAt(index)->widget();
|
||||
CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(widget);
|
||||
|
||||
if (categoryWidget == nullptr || categoryWidget->cycleContacts(friendWidget, forward))
|
||||
if (categoryWidget == nullptr || categoryWidget->cycleContacts(friendWidget, forward)) {
|
||||
return;
|
||||
}
|
||||
|
||||
index += forward ? 1 : -1;
|
||||
|
||||
|
@ -454,11 +456,13 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget
|
|||
CircleWidget* circleWidget = nullptr;
|
||||
|
||||
if (friendWidget != nullptr) {
|
||||
circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleID(
|
||||
FriendList::findFriend(friendWidget->friendId)->getPublicKey()));
|
||||
const ToxPk& pk = friendWidget->getFriend()->getPublicKey();
|
||||
uint32_t circleId = Settings::getInstance().getFriendCircleID(pk);
|
||||
circleWidget = CircleWidget::getFromID(circleId);
|
||||
if (circleWidget != nullptr) {
|
||||
if (circleWidget->cycleContacts(friendWidget, forward))
|
||||
if (circleWidget->cycleContacts(friendWidget, forward)) {
|
||||
return;
|
||||
}
|
||||
|
||||
index = circleLayout->indexOfSortedWidget(circleWidget);
|
||||
currentLayout = circleLayout->getLayout();
|
||||
|
@ -566,7 +570,7 @@ void FriendListWidget::dayTimeout()
|
|||
void FriendListWidget::moveWidget(FriendWidget* widget, Status s, bool add)
|
||||
{
|
||||
if (mode == Name) {
|
||||
Friend* f = FriendList::findFriend(widget->friendId);
|
||||
const Friend* f = widget->getFriend();
|
||||
int circleId = Settings::getInstance().getFriendCircleID(f->getPublicKey());
|
||||
CircleWidget* circleWidget = CircleWidget::getFromID(circleId);
|
||||
|
||||
|
@ -580,7 +584,7 @@ void FriendListWidget::moveWidget(FriendWidget* widget, Status s, bool add)
|
|||
|
||||
circleWidget->addFriendWidget(widget, s);
|
||||
} else {
|
||||
Friend* contact = FriendList::findFriend(widget->friendId);
|
||||
const Friend* contact = widget->getFriend();
|
||||
QDate activityDate = getDateFriend(contact);
|
||||
int time = static_cast<int>(getTime(activityDate));
|
||||
QWidget* w = activityLayout->itemAt(time)->widget();
|
||||
|
|
|
@ -56,16 +56,16 @@
|
|||
* When you click should open the chat with friend. Widget has a context menu.
|
||||
*/
|
||||
|
||||
FriendWidget::FriendWidget(int friendId, const QString& id, bool compact)
|
||||
FriendWidget::FriendWidget(const Friend* f, bool compact)
|
||||
: GenericChatroomWidget(compact)
|
||||
, friendId(friendId)
|
||||
, frnd{f}
|
||||
, isDefaultAvatar{true}
|
||||
, historyLoaded{false}
|
||||
{
|
||||
avatar->setPixmap(QPixmap(":/img/contact.svg"));
|
||||
statusPic.setPixmap(QPixmap(":/img/status/dot_offline.svg"));
|
||||
statusPic.setMargin(3);
|
||||
nameLabel->setText(id);
|
||||
nameLabel->setText(f->getDisplayedName());
|
||||
nameLabel->setTextFormat(Qt::PlainText);
|
||||
connect(nameLabel, &CroppingLabel::editFinished, this, &FriendWidget::setAlias);
|
||||
statusMessageLabel->setTextFormat(Qt::PlainText);
|
||||
|
@ -349,7 +349,7 @@ QString FriendWidget::getStatusString() const
|
|||
return QString::null;
|
||||
}
|
||||
|
||||
Friend* FriendWidget::getFriend() const
|
||||
const Friend* FriendWidget::getFriend() const
|
||||
{
|
||||
return FriendList::findFriend(friendId);
|
||||
}
|
||||
|
@ -371,7 +371,8 @@ void FriendWidget::setChatForm(ContentLayout* contentLayout)
|
|||
|
||||
void FriendWidget::resetEventFlags()
|
||||
{
|
||||
Friend* f = FriendList::findFriend(friendId);
|
||||
// Hack to avoid edit const Friend. TODO: Repalce on emit
|
||||
Friend* f = FriendList::findFriend(frnd->getFriendId());
|
||||
f->setEventFlag(false);
|
||||
}
|
||||
|
||||
|
@ -424,8 +425,9 @@ void FriendWidget::mouseMoveEvent(QMouseEvent* ev)
|
|||
void FriendWidget::setAlias(const QString& _alias)
|
||||
{
|
||||
QString alias = _alias.left(tox_max_name_length());
|
||||
Friend* f = FriendList::findFriend(friendId);
|
||||
// Hack to avoid edit const Friend. TODO: Repalce on emit
|
||||
Friend* f = FriendList::findFriend(frnd->getFriendId());
|
||||
f->setAlias(alias);
|
||||
Settings::getInstance().setFriendAlias(f->getPublicKey(), alias);
|
||||
Settings::getInstance().setFriendAlias(frnd->getPublicKey(), alias);
|
||||
Settings::getInstance().savePersonal();
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ class FriendWidget : public GenericChatroomWidget
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FriendWidget(int friendId, const QString& id, bool compact);
|
||||
FriendWidget(const Friend* f, bool compact);
|
||||
void contextMenuEvent(QContextMenuEvent* event) override final;
|
||||
void setAsActiveChatroom() override final;
|
||||
void setAsInactiveChatroom() override final;
|
||||
|
@ -35,7 +35,7 @@ public:
|
|||
void setChatForm(ContentLayout* contentLayout) override final;
|
||||
void resetEventFlags() override final;
|
||||
QString getStatusString() const override final;
|
||||
Friend* getFriend() const override final;
|
||||
const Friend* getFriend() const override final;
|
||||
|
||||
void search(const QString& searchString, bool hide = false);
|
||||
|
||||
|
@ -57,6 +57,7 @@ protected:
|
|||
void setFriendAlias();
|
||||
|
||||
public:
|
||||
const Friend* frnd;
|
||||
int friendId;
|
||||
bool isDefaultAvatar;
|
||||
bool historyLoaded;
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
virtual void setChatForm(ContentLayout* contentLayout) = 0;
|
||||
virtual void resetEventFlags() = 0;
|
||||
virtual QString getStatusString() const = 0;
|
||||
virtual Friend* getFriend() const
|
||||
virtual const Friend* getFriend() const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -961,10 +961,9 @@ void Widget::onCallEnd(uint32_t friendId)
|
|||
void Widget::addFriend(int friendId, const ToxPk& friendPk)
|
||||
{
|
||||
Friend* newfriend = FriendList::addFriend(friendId, friendPk);
|
||||
QString name = newfriend->getDisplayedName();
|
||||
bool compact = Settings::getInstance().getCompactLayout();
|
||||
FriendWidget* widget = new FriendWidget(newfriend, compact);
|
||||
|
||||
FriendWidget* widget = new FriendWidget(friendId, name, compact);
|
||||
ChatForm* friendForm = newfriend->getChatForm();
|
||||
|
||||
friendWidgets[friendId] = widget;
|
||||
|
@ -1120,7 +1119,7 @@ void Widget::openDialog(GenericChatroomWidget* widget, bool newWindow)
|
|||
uint32_t id;
|
||||
GenericChatForm* form;
|
||||
if (widget->getFriend()) {
|
||||
Friend* f = widget->getFriend();
|
||||
const Friend* f = widget->getFriend();
|
||||
form = f->getChatForm();
|
||||
id = f->getFriendId();
|
||||
} else {
|
||||
|
@ -1147,7 +1146,7 @@ void Widget::openDialog(GenericChatroomWidget* widget, bool newWindow)
|
|||
}
|
||||
|
||||
dialog->show();
|
||||
Friend* frnd = widget->getFriend();
|
||||
const Friend* frnd = widget->getFriend();
|
||||
|
||||
if (frnd != nullptr) {
|
||||
addFriendDialog(frnd, dialog);
|
||||
|
@ -1198,7 +1197,7 @@ void Widget::onReceiptRecieved(int friendId, int receipt)
|
|||
f->getChatForm()->getOfflineMsgEngine()->dischargeReceipt(receipt);
|
||||
}
|
||||
|
||||
void Widget::addFriendDialog(Friend* frnd, ContentDialog* dialog)
|
||||
void Widget::addFriendDialog(const Friend* frnd, ContentDialog* dialog)
|
||||
{
|
||||
ContentDialog* contentDialog = ContentDialog::getFriendDialog(frnd->getFriendId());
|
||||
bool isSeparate = Settings::getInstance().getSeparateWindow();
|
||||
|
@ -1425,7 +1424,7 @@ void Widget::onFriendRequestReceived(const ToxPk& friendPk, const QString& messa
|
|||
}
|
||||
}
|
||||
|
||||
void Widget::updateFriendActivity(Friend* frnd)
|
||||
void Widget::updateFriendActivity(const Friend* frnd)
|
||||
{
|
||||
const ToxPk& pk = frnd->getPublicKey();
|
||||
QDate date = Settings::getInstance().getFriendActivity(pk);
|
||||
|
@ -1510,7 +1509,7 @@ void Widget::onDialogShown(GenericChatroomWidget* widget)
|
|||
resetIcon();
|
||||
}
|
||||
|
||||
void Widget::onFriendDialogShown(Friend* f)
|
||||
void Widget::onFriendDialogShown(const Friend* f)
|
||||
{
|
||||
int friendId = f->getFriendId();
|
||||
onDialogShown(friendWidgets[friendId]);
|
||||
|
@ -2425,7 +2424,7 @@ void Widget::retranslateUi()
|
|||
void Widget::focusChatInput()
|
||||
{
|
||||
if (activeChatroomWidget) {
|
||||
if (Friend* f = activeChatroomWidget->getFriend()) {
|
||||
if (const Friend* f = activeChatroomWidget->getFriend()) {
|
||||
f->getChatForm()->focusInput();
|
||||
} else if (Group* g = activeChatroomWidget->getGroup()) {
|
||||
g->getChatForm()->focusInput();
|
||||
|
|
|
@ -103,7 +103,7 @@ public:
|
|||
Camera* getCamera();
|
||||
static Widget* getInstance();
|
||||
void showUpdateDownloadProgress();
|
||||
void addFriendDialog(Friend* frnd, ContentDialog* dialog);
|
||||
void addFriendDialog(const Friend* frnd, ContentDialog* dialog);
|
||||
void addGroupDialog(Group* group, ContentDialog* dialog);
|
||||
bool newFriendMessageAlert(int friendId, bool sound = true);
|
||||
bool newGroupMessageAlert(int groupId, bool notify);
|
||||
|
@ -155,7 +155,7 @@ public slots:
|
|||
void onFriendAliasChanged(uint32_t friendId, const QString& alias);
|
||||
void onFriendMessageReceived(int friendId, const QString& message, bool isAction);
|
||||
void onFriendRequestReceived(const ToxPk& friendPk, const QString& message);
|
||||
void updateFriendActivity(Friend* frnd);
|
||||
void updateFriendActivity(const Friend* frnd);
|
||||
void onMessageSendResult(uint32_t friendId, const QString& message, int messageId);
|
||||
void onReceiptRecieved(int friendId, int receipt);
|
||||
void onEmptyGroupCreated(int groupId);
|
||||
|
@ -169,7 +169,7 @@ public slots:
|
|||
void onFriendTypingChanged(int friendId, bool isTyping);
|
||||
void nextContact();
|
||||
void previousContact();
|
||||
void onFriendDialogShown(Friend* f);
|
||||
void onFriendDialogShown(const Friend* f);
|
||||
void onGroupDialogShown(Group* g);
|
||||
void toggleFullscreen();
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user