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

struct Friend refactoring

This commit is contained in:
apprb 2014-11-07 00:26:22 +09:00
parent f29305bb01
commit 59748886de
No known key found for this signature in database
GPG Key ID: B001911B5B22FB9B
6 changed files with 191 additions and 124 deletions

View File

@ -20,12 +20,13 @@
#include "widget/form/chatform.h"
Friend::Friend(int FriendId, QString UserId)
: friendId(FriendId), userId(UserId)
: friendId(FriendId)
{
widget = new FriendWidget(friendId, userId);
widget = new FriendWidget(friendId, UserId);
chatForm = new ChatForm(this);
hasNewEvents = 0;
friendStatus = Status::Offline;
userID = ToxID::fromString(UserId);
}
Friend::~Friend()
@ -36,8 +37,21 @@ Friend::~Friend()
void Friend::setName(QString name)
{
widget->setName(name);
chatForm->setName(name);
userName = name;
if (userAlias.size() == 0)
{
widget->setName(name);
chatForm->setName(name);
}
}
void Friend::setAlias(QString name)
{
userAlias = name;
QString dispName = userAlias.size() == 0 ? userName : userAlias;
widget->setName(dispName);
chatForm->setName(dispName);
}
void Friend::setStatusMessage(QString message)
@ -46,12 +60,49 @@ void Friend::setStatusMessage(QString message)
chatForm->setStatusMessage(message);
}
QString Friend::getName() const
QString Friend::getDisplayedName() const
{
return widget->getName();
if (userAlias.size() == 0)
return userName;
return userAlias;
}
ToxID Friend::getToxID() const
const ToxID &Friend::getToxID() const
{
return ToxID::fromString(userId);
return userID;
}
int Friend::getFriendID() const
{
return friendId;
}
void Friend::setEventFlag(int f)
{
hasNewEvents = f;
}
int Friend::getEventFlag() const
{
return hasNewEvents;
}
void Friend::setStatus(Status s)
{
friendStatus = s;
}
Status Friend::getStatus() const
{
return friendStatus;
}
ChatForm *Friend::getChatForm()
{
return chatForm;
}
FriendWidget *Friend::getFriendWidget()
{
return widget;
}

View File

@ -28,18 +28,34 @@ struct Friend
public:
Friend(int FriendId, QString UserId);
~Friend();
void setName(QString name);
void setStatusMessage(QString message);
QString getName() const;
ToxID getToxID() const;
public:
FriendWidget* widget;
void setName(QString name);
void setAlias(QString name);
QString getDisplayedName() const;
void setStatusMessage(QString message);
void setEventFlag(int f);
int getEventFlag() const;
const ToxID &getToxID() const;
int getFriendID() const;
void setStatus(Status s);
Status getStatus() const;
ChatForm *getChatForm();
FriendWidget *getFriendWidget();
private:
QString userAlias, userName;
ToxID userID;
int friendId;
QString userId;
ChatForm* chatForm;
int hasNewEvents;
Status friendStatus;
FriendWidget* widget;
ChatForm* chatForm;
};
#endif // FRIEND_H

View File

@ -24,7 +24,7 @@ QList<Friend*> FriendList::friendList;
Friend* FriendList::addFriend(int friendId, const QString& userId)
{
for (Friend* f : friendList)
if (f->friendId == friendId)
if (f->getFriendID() == friendId)
qWarning() << "FriendList::addFriend: friendId already taken";
Friend* newfriend = new Friend(friendId, userId);
friendList.append(newfriend);
@ -34,7 +34,7 @@ Friend* FriendList::addFriend(int friendId, const QString& userId)
Friend* FriendList::findFriend(int friendId)
{
for (Friend* f : friendList)
if (f->friendId == friendId)
if (f->getFriendID() == friendId)
return f;
return nullptr;
}
@ -43,7 +43,7 @@ void FriendList::removeFriend(int friendId)
{
for (int i=0; i<friendList.size(); i++)
{
if (friendList[i]->friendId == friendId)
if (friendList[i]->getFriendID() == friendId)
{
friendList.removeAt(i);
return;

View File

@ -46,7 +46,7 @@ ChatForm::ChatForm(Friend* chatFriend)
, audioOutputFlag(false)
, callId(0)
{
nameLabel->setText(f->getName());
nameLabel->setText(f->getDisplayedName());
avatar->setPixmap(QPixmap(":/img/contact_dark.png"), Qt::transparent);
@ -98,18 +98,18 @@ void ChatForm::onSendTriggered()
return;
QDateTime timestamp = QDateTime::currentDateTime();
HistoryKeeper::getInstance()->addChatEntry(f->userId, msg, Core::getInstance()->getSelfId().publicKey, timestamp);
HistoryKeeper::getInstance()->addChatEntry(f->getToxID().toString(), msg, Core::getInstance()->getSelfId().publicKey, timestamp);
if (msg.startsWith("/me "))
{
msg = msg.right(msg.length() - 4);
addSelfMessage(msg, true, timestamp);
emit sendAction(f->friendId, msg);
emit sendAction(f->getFriendID(), msg);
}
else
{
addSelfMessage(msg, false, timestamp);
emit sendMessage(f->friendId, msg);
emit sendMessage(f->getFriendID(), msg);
}
msgEdit->clear();
}
@ -134,13 +134,13 @@ void ChatForm::onAttachClicked()
file.close();
QFileInfo fi(path);
emit sendFile(f->friendId, fi.fileName(), path, filesize);
emit sendFile(f->getFriendID(), fi.fileName(), path, filesize);
}
}
void ChatForm::startFileSend(ToxFile file)
{
if (file.friendId != f->friendId)
if (file.friendId != f->getFriendID())
return;
FileTransferInstance* fileTrans = new FileTransferInstance(file);
@ -168,7 +168,7 @@ void ChatForm::startFileSend(ToxFile file)
void ChatForm::onFileRecvRequest(ToxFile file)
{
if (file.friendId != f->friendId)
if (file.friendId != f->getFriendID())
return;
FileTransferInstance* fileTrans = new FileTransferInstance(file);
@ -186,22 +186,22 @@ void ChatForm::onFileRecvRequest(ToxFile file)
if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow())
{
w->newMessageAlert();
f->hasNewEvents=true;
f->widget->updateStatusLight();
f->setEventFlag(true);
f->getFriendWidget()->updateStatusLight();
}
QString name;
ToxID friendId = f->getToxID();
if (friendId != previousId)
{
name = f->getName();
name = f->getDisplayedName();
previousId = friendId;
}
chatWidget->insertMessage(ChatActionPtr(new FileTransferAction(fileTrans, getElidedName(name),
QTime::currentTime().toString("hh:mm"), false)));
if (!Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->friendId)).isEmpty()
if (!Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->getFriendID())).isEmpty()
|| Settings::getInstance().getAutoSaveEnabled())
fileTrans->pressFromHtml("btnB");
}
@ -209,7 +209,7 @@ void ChatForm::onFileRecvRequest(ToxFile file)
void ChatForm::onAvInvite(int FriendId, int CallId, bool video)
{
qDebug() << "onAvInvite";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
callId = CallId;
@ -232,21 +232,21 @@ void ChatForm::onAvInvite(int FriendId, int CallId, bool video)
connect(callButton, SIGNAL(clicked()), this, SLOT(onAnswerCallTriggered()));
}
addSystemInfoMessage(tr("%1 calling").arg(f->getName()), "white", QDateTime::currentDateTime());
addSystemInfoMessage(tr("%1 calling").arg(f->getDisplayedName()), "white", QDateTime::currentDateTime());
Widget* w = Widget::getInstance();
if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow())
{
w->newMessageAlert();
f->hasNewEvents=true;
f->widget->updateStatusLight();
f->setEventFlag(true);
f->getFriendWidget()->updateStatusLight();
}
}
void ChatForm::onAvStart(int FriendId, int CallId, bool video)
{
qDebug() << "onAvStart";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
audioInputFlag = true;
@ -263,7 +263,7 @@ void ChatForm::onAvStart(int FriendId, int CallId, bool video)
videoButton->style()->polish(videoButton);
connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getName());
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getDisplayedName());
}
else
{
@ -281,7 +281,7 @@ void ChatForm::onAvCancel(int FriendId, int)
{
qDebug() << "onAvCancel";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
audioInputFlag = false;
@ -301,14 +301,14 @@ void ChatForm::onAvCancel(int FriendId, int)
netcam->hide();
addSystemInfoMessage(tr("%1 stopped calling").arg(f->getName()), "white", QDateTime::currentDateTime());
addSystemInfoMessage(tr("%1 stopped calling").arg(f->getDisplayedName()), "white", QDateTime::currentDateTime());
}
void ChatForm::onAvEnd(int FriendId, int)
{
qDebug() << "onAvEnd";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
audioInputFlag = false;
@ -334,7 +334,7 @@ void ChatForm::onAvEnd(int FriendId, int)
void ChatForm::onAvRinging(int FriendId, int CallId, bool video)
{
qDebug() << "onAvRinging";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
callId = CallId;
@ -357,14 +357,14 @@ void ChatForm::onAvRinging(int FriendId, int CallId, bool video)
connect(callButton, SIGNAL(clicked()), this, SLOT(onCancelCallTriggered()));
}
addSystemInfoMessage(tr("Calling to %1").arg(f->getName()), "white", QDateTime::currentDateTime());
addSystemInfoMessage(tr("Calling to %1").arg(f->getDisplayedName()), "white", QDateTime::currentDateTime());
}
void ChatForm::onAvStarting(int FriendId, int CallId, bool video)
{
qDebug() << "onAvStarting";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
callButton->disconnect();
@ -377,7 +377,7 @@ void ChatForm::onAvStarting(int FriendId, int CallId, bool video)
videoButton->style()->polish(videoButton);
connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getName());
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getDisplayedName());
}
else
{
@ -395,7 +395,7 @@ void ChatForm::onAvEnding(int FriendId, int)
{
qDebug() << "onAvEnding";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
audioInputFlag = false;
@ -424,7 +424,7 @@ void ChatForm::onAvRequestTimeout(int FriendId, int)
{
qDebug() << "onAvRequestTimeout";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
audioInputFlag = false;
@ -451,7 +451,7 @@ void ChatForm::onAvPeerTimeout(int FriendId, int)
{
qDebug() << "onAvPeerTimeout";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
audioInputFlag = false;
@ -478,7 +478,7 @@ void ChatForm::onAvRejected(int FriendId, int)
{
qDebug() << "onAvRejected";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
audioInputFlag = false;
@ -507,12 +507,12 @@ void ChatForm::onAvMediaChange(int FriendId, int CallId, bool video)
{
qDebug() << "onAvMediaChange";
if (FriendId != f->friendId || CallId != callId)
if (FriendId != f->getFriendID() || CallId != callId)
return;
if (video)
{
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getName());
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getDisplayedName());
}
else
{
@ -550,7 +550,7 @@ void ChatForm::onCallTriggered()
audioOutputFlag = true;
callButton->disconnect();
videoButton->disconnect();
emit startCall(f->friendId);
emit startCall(f->getFriendID());
}
void ChatForm::onVideoCallTriggered()
@ -561,14 +561,14 @@ void ChatForm::onVideoCallTriggered()
audioOutputFlag = true;
callButton->disconnect();
videoButton->disconnect();
emit startVideoCall(f->friendId, true);
emit startVideoCall(f->getFriendID(), true);
}
void ChatForm::onAvCallFailed(int FriendId)
{
qDebug() << "onAvCallFailed";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
audioInputFlag = false;
@ -601,7 +601,7 @@ void ChatForm::onCancelCallTriggered()
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
netcam->hide();
emit cancelCall(callId, f->friendId);
emit cancelCall(callId, f->getFriendID());
}
void ChatForm::onMicMuteToggle()
@ -646,7 +646,7 @@ void ChatForm::onFileTansBtnClicked(QString widgetName, QString buttonName)
void ChatForm::onFileSendFailed(int FriendId, const QString &fname)
{
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
addSystemInfoMessage("File: \"" + fname + "\" failed to send.", "red", QDateTime::currentDateTime());
@ -654,7 +654,7 @@ void ChatForm::onFileSendFailed(int FriendId, const QString &fname)
void ChatForm::onAvatarChange(int FriendId, const QPixmap &pic)
{
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
avatar->setPixmap(pic);
@ -675,14 +675,14 @@ void ChatForm::dropEvent(QDropEvent *ev)
QFileInfo info(url.path());
if (info.exists())
Core::getInstance()->sendFile(f->friendId, info.fileName(), info.absoluteFilePath(), info.size());
Core::getInstance()->sendFile(f->getFriendID(), info.fileName(), info.absoluteFilePath(), info.size());
}
}
}
void ChatForm::onAvatarRemoved(int FriendId)
{
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
avatar->setPixmap(QPixmap(":/img/contact_dark.png"), Qt::transparent);
@ -711,7 +711,7 @@ void ChatForm::onLoadHistory()
}
}
auto msgs = HistoryKeeper::getInstance()->getChatHistory(HistoryKeeper::ctSingle, f->userId, fromTime, toTime);
auto msgs = HistoryKeeper::getInstance()->getChatHistory(HistoryKeeper::ctSingle, f->getToxID().toString(), fromTime, toTime);
ToxID storedPrevId;
std::swap(storedPrevId, previousId);
@ -752,7 +752,7 @@ void ChatForm::stopCounter()
{
if(timer)
{
addSystemInfoMessage(tr("Call with %1 ended. %2").arg(f->getName(),
addSystemInfoMessage(tr("Call with %1 ended. %2").arg(f->getDisplayedName(),
secondsToDHMS(timeElapsed.elapsed()/1000)),
"white", QDateTime::currentDateTime());
timer->stop();

View File

@ -132,36 +132,36 @@ void FriendWidget::setAsInactiveChatroom()
void FriendWidget::updateStatusLight()
{
Friend* f = FriendList::findFriend(friendId);
Status status = f->friendStatus;
Status status = f->getStatus();
if (status == Status::Online && f->hasNewEvents == 0)
if (status == Status::Online && f->getEventFlag() == 0)
statusPic.setPixmap(QPixmap(":img/status/dot_online.png"));
else if (status == Status::Online && f->hasNewEvents == 1)
else if (status == Status::Online && f->getEventFlag() == 1)
statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
else if (status == Status::Away && f->hasNewEvents == 0)
else if (status == Status::Away && f->getEventFlag() == 0)
statusPic.setPixmap(QPixmap(":img/status/dot_idle.png"));
else if (status == Status::Away && f->hasNewEvents == 1)
else if (status == Status::Away && f->getEventFlag() == 1)
statusPic.setPixmap(QPixmap(":img/status/dot_idle_notification.png"));
else if (status == Status::Busy && f->hasNewEvents == 0)
else if (status == Status::Busy && f->getEventFlag() == 0)
statusPic.setPixmap(QPixmap(":img/status/dot_busy.png"));
else if (status == Status::Busy && f->hasNewEvents == 1)
else if (status == Status::Busy && f->getEventFlag() == 1)
statusPic.setPixmap(QPixmap(":img/status/dot_busy_notification.png"));
else if (status == Status::Offline && f->hasNewEvents == 0)
else if (status == Status::Offline && f->getEventFlag() == 0)
statusPic.setPixmap(QPixmap(":img/status/dot_away.png"));
else if (status == Status::Offline && f->hasNewEvents == 1)
else if (status == Status::Offline && f->getEventFlag() == 1)
statusPic.setPixmap(QPixmap(":img/status/dot_away_notification.png"));
}
void FriendWidget::setChatForm(Ui::MainWindow &ui)
{
Friend* f = FriendList::findFriend(friendId);
f->chatForm->show(ui);
f->getChatForm()->show(ui);
}
void FriendWidget::resetEventFlags()
{
Friend* f = FriendList::findFriend(friendId);
f->hasNewEvents = 0;
f->setEventFlag(false);
}
void FriendWidget::onAvatarChange(int FriendId, const QPixmap& pic)

View File

@ -603,46 +603,46 @@ void Widget::addFriend(int friendId, const QString &userId)
//qDebug() << "Widget: Adding friend with id" << userId;
Friend* newfriend = FriendList::addFriend(friendId, userId);
QLayout* layout = contactListWidget->getFriendLayout(Status::Offline);
layout->addWidget(newfriend->widget);
connect(newfriend->widget, SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
connect(newfriend->widget, SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
connect(newfriend->widget, SIGNAL(copyFriendIdToClipboard(int)), this, SLOT(copyFriendIdToClipboard(int)));
connect(newfriend->widget, SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), newfriend->chatForm, SLOT(focusInput()));
connect(newfriend->chatForm, SIGNAL(sendMessage(int,QString)), core, SLOT(sendMessage(int,QString)));
connect(newfriend->chatForm, &GenericChatForm::sendAction, core, &Core::sendAction);
connect(newfriend->chatForm, SIGNAL(sendFile(int32_t, QString, QString, long long)), core, SLOT(sendFile(int32_t, QString, QString, long long)));
connect(newfriend->chatForm, SIGNAL(answerCall(int)), core, SLOT(answerCall(int)));
connect(newfriend->chatForm, SIGNAL(hangupCall(int)), core, SLOT(hangupCall(int)));
connect(newfriend->chatForm, SIGNAL(startCall(int)), core, SLOT(startCall(int)));
connect(newfriend->chatForm, SIGNAL(startVideoCall(int,bool)), core, SLOT(startCall(int,bool)));
connect(newfriend->chatForm, SIGNAL(cancelCall(int,int)), core, SLOT(cancelCall(int,int)));
connect(newfriend->chatForm, SIGNAL(micMuteToggle(int)), core, SLOT(micMuteToggle(int)));
connect(newfriend->chatForm, SIGNAL(volMuteToggle(int)), core, SLOT(volMuteToggle(int)));
connect(core, &Core::fileReceiveRequested, newfriend->chatForm, &ChatForm::onFileRecvRequest);
connect(core, &Core::avInvite, newfriend->chatForm, &ChatForm::onAvInvite);
connect(core, &Core::avStart, newfriend->chatForm, &ChatForm::onAvStart);
connect(core, &Core::avCancel, newfriend->chatForm, &ChatForm::onAvCancel);
connect(core, &Core::avEnd, newfriend->chatForm, &ChatForm::onAvEnd);
connect(core, &Core::avRinging, newfriend->chatForm, &ChatForm::onAvRinging);
connect(core, &Core::avStarting, newfriend->chatForm, &ChatForm::onAvStarting);
connect(core, &Core::avEnding, newfriend->chatForm, &ChatForm::onAvEnding);
connect(core, &Core::avRequestTimeout, newfriend->chatForm, &ChatForm::onAvRequestTimeout);
connect(core, &Core::avPeerTimeout, newfriend->chatForm, &ChatForm::onAvPeerTimeout);
connect(core, &Core::avMediaChange, newfriend->chatForm, &ChatForm::onAvMediaChange);
connect(core, &Core::avCallFailed, newfriend->chatForm, &ChatForm::onAvCallFailed);
connect(core, &Core::avRejected, newfriend->chatForm, &ChatForm::onAvRejected);
connect(core, &Core::friendAvatarChanged, newfriend->chatForm, &ChatForm::onAvatarChange);
connect(core, &Core::friendAvatarChanged, newfriend->widget, &FriendWidget::onAvatarChange);
connect(core, &Core::friendAvatarRemoved, newfriend->chatForm, &ChatForm::onAvatarRemoved);
connect(core, &Core::friendAvatarRemoved, newfriend->widget, &FriendWidget::onAvatarRemoved);
layout->addWidget(newfriend->getFriendWidget());
connect(newfriend->getFriendWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
connect(newfriend->getFriendWidget(), SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
connect(newfriend->getFriendWidget(), SIGNAL(copyFriendIdToClipboard(int)), this, SLOT(copyFriendIdToClipboard(int)));
connect(newfriend->getFriendWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), newfriend->getChatForm(), SLOT(focusInput()));
connect(newfriend->getChatForm(), SIGNAL(sendMessage(int,QString)), core, SLOT(sendMessage(int,QString)));
connect(newfriend->getChatForm(), &GenericChatForm::sendAction, core, &Core::sendAction);
connect(newfriend->getChatForm(), SIGNAL(sendFile(int32_t, QString, QString, long long)), core, SLOT(sendFile(int32_t, QString, QString, long long)));
connect(newfriend->getChatForm(), SIGNAL(answerCall(int)), core, SLOT(answerCall(int)));
connect(newfriend->getChatForm(), SIGNAL(hangupCall(int)), core, SLOT(hangupCall(int)));
connect(newfriend->getChatForm(), SIGNAL(startCall(int)), core, SLOT(startCall(int)));
connect(newfriend->getChatForm(), SIGNAL(startVideoCall(int,bool)), core, SLOT(startCall(int,bool)));
connect(newfriend->getChatForm(), SIGNAL(cancelCall(int,int)), core, SLOT(cancelCall(int,int)));
connect(newfriend->getChatForm(), SIGNAL(micMuteToggle(int)), core, SLOT(micMuteToggle(int)));
connect(newfriend->getChatForm(), SIGNAL(volMuteToggle(int)), core, SLOT(volMuteToggle(int)));
connect(core, &Core::fileReceiveRequested, newfriend->getChatForm(), &ChatForm::onFileRecvRequest);
connect(core, &Core::avInvite, newfriend->getChatForm(), &ChatForm::onAvInvite);
connect(core, &Core::avStart, newfriend->getChatForm(), &ChatForm::onAvStart);
connect(core, &Core::avCancel, newfriend->getChatForm(), &ChatForm::onAvCancel);
connect(core, &Core::avEnd, newfriend->getChatForm(), &ChatForm::onAvEnd);
connect(core, &Core::avRinging, newfriend->getChatForm(), &ChatForm::onAvRinging);
connect(core, &Core::avStarting, newfriend->getChatForm(), &ChatForm::onAvStarting);
connect(core, &Core::avEnding, newfriend->getChatForm(), &ChatForm::onAvEnding);
connect(core, &Core::avRequestTimeout, newfriend->getChatForm(), &ChatForm::onAvRequestTimeout);
connect(core, &Core::avPeerTimeout, newfriend->getChatForm(), &ChatForm::onAvPeerTimeout);
connect(core, &Core::avMediaChange, newfriend->getChatForm(), &ChatForm::onAvMediaChange);
connect(core, &Core::avCallFailed, newfriend->getChatForm(), &ChatForm::onAvCallFailed);
connect(core, &Core::avRejected, newfriend->getChatForm(), &ChatForm::onAvRejected);
connect(core, &Core::friendAvatarChanged, newfriend->getChatForm(), &ChatForm::onAvatarChange);
connect(core, &Core::friendAvatarChanged, newfriend->getFriendWidget(), &FriendWidget::onAvatarChange);
connect(core, &Core::friendAvatarRemoved, newfriend->getChatForm(), &ChatForm::onAvatarRemoved);
connect(core, &Core::friendAvatarRemoved, newfriend->getFriendWidget(), &FriendWidget::onAvatarRemoved);
// Try to get the avatar from the cache
QPixmap avatar = Settings::getInstance().getSavedAvatar(userId);
if (!avatar.isNull())
{
//qWarning() << "Widget: loadded avatar for id" << userId;
newfriend->chatForm->onAvatarChange(friendId, avatar);
newfriend->widget->onAvatarChange(friendId, avatar);
newfriend->getChatForm()->onAvatarChange(friendId, avatar);
newfriend->getFriendWidget()->onAvatarChange(friendId, avatar);
}
}
@ -657,17 +657,17 @@ void Widget::onFriendStatusChanged(int friendId, Status status)
if (!f)
return;
contactListWidget->moveWidget(f->widget, status);
contactListWidget->moveWidget(f->getFriendWidget(), status);
f->friendStatus = status;
f->widget->updateStatusLight();
f->setStatus(status);
f->getFriendWidget()->updateStatusLight();
//won't print the message if there were no messages before
if(f->chatForm->getNumberOfMessages() != 0
if(f->getChatForm()->getNumberOfMessages() != 0
&& Settings::getInstance().getStatusChangeNotificationEnabled() == true)
{
QString fStatus = "";
switch(f->friendStatus){
switch(f->getStatus()){
case Status::Away:
fStatus = tr("away", "contact status"); break;
case Status::Busy:
@ -677,7 +677,7 @@ void Widget::onFriendStatusChanged(int friendId, Status status)
default:
fStatus = tr("online", "contact status"); break;
}
f->chatForm->addSystemInfoMessage(tr("%1 is now %2", "e.g. \"Dubslow is now online\"").arg(f->getName()).arg(fStatus),
f->getChatForm()->addSystemInfoMessage(tr("%1 is now %2", "e.g. \"Dubslow is now online\"").arg(f->getDisplayedName()).arg(fStatus),
"white", QDateTime::currentDateTime());
}
}
@ -726,28 +726,28 @@ void Widget::onFriendMessageReceived(int friendId, const QString& message, bool
return;
QDateTime timestamp = QDateTime::currentDateTime();
f->chatForm->addMessage(f->getToxID(), message, isAction, timestamp);
f->getChatForm()->addMessage(f->getToxID(), message, isAction, timestamp);
if (isAction)
HistoryKeeper::getInstance()->addChatEntry(f->userId, "/me " + message, f->userId, timestamp);
HistoryKeeper::getInstance()->addChatEntry(f->getToxID().toString(), "/me " + message, f->getToxID().toString(), timestamp);
else
HistoryKeeper::getInstance()->addChatEntry(f->userId, message, f->userId, timestamp);
HistoryKeeper::getInstance()->addChatEntry(f->getToxID().toString(), message, f->getToxID().toString(), timestamp);
if (activeChatroomWidget != nullptr)
{
if ((static_cast<GenericChatroomWidget*>(f->widget) != activeChatroomWidget) || isMinimized() || !isActiveWindow())
if ((static_cast<GenericChatroomWidget*>(f->getFriendWidget()) != activeChatroomWidget) || isMinimized() || !isActiveWindow())
{
f->hasNewEvents = 1;
f->setEventFlag(true);
newMessageAlert();
}
}
else
{
f->hasNewEvents = 1;
f->setEventFlag(true);
newMessageAlert();
}
f->widget->updateStatusLight();
f->getFriendWidget()->updateStatusLight();
}
void Widget::newMessageAlert()
@ -800,11 +800,11 @@ void Widget::onFriendRequestReceived(const QString& userId, const QString& messa
void Widget::removeFriend(Friend* f)
{
f->widget->setAsInactiveChatroom();
if (static_cast<GenericChatroomWidget*>(f->widget) == activeChatroomWidget)
f->getFriendWidget()->setAsInactiveChatroom();
if (static_cast<GenericChatroomWidget*>(f->getFriendWidget()) == activeChatroomWidget)
activeChatroomWidget = nullptr;
FriendList::removeFriend(f->friendId);
core->removeFriend(f->friendId);
FriendList::removeFriend(f->getFriendID());
core->removeFriend(f->getFriendID());
delete f;
if (ui->mainHead->layout()->isEmpty())
onAddClicked();
@ -832,7 +832,7 @@ void Widget::copyFriendIdToClipboard(int friendId)
if (f != nullptr)
{
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(core->getFriendAddress(f->friendId), QClipboard::Clipboard);
clipboard->setText(core->getFriendAddress(f->getFriendID()), QClipboard::Clipboard);
}
}
@ -962,7 +962,7 @@ bool Widget::isFriendWidgetCurActiveWidget(Friend* f)
if (!f)
return false;
return (activeChatroomWidget == static_cast<GenericChatroomWidget*>(f->widget));
return (activeChatroomWidget == static_cast<GenericChatroomWidget*>(f->getFriendWidget()));
}
bool Widget::event(QEvent * e)
@ -1033,7 +1033,7 @@ void Widget::onMessageSendResult(int friendId, const QString& message, int messa
return;
if (!messageId)
f->chatForm->addSystemInfoMessage(tr("Message failed to send"), "red", QDateTime::currentDateTime());
f->getChatForm()->addSystemInfoMessage(tr("Message failed to send"), "red", QDateTime::currentDateTime());
}
void Widget::onGroupSendResult(int groupId, const QString& message, int result)