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" #include "widget/form/chatform.h"
Friend::Friend(int FriendId, QString UserId) 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); chatForm = new ChatForm(this);
hasNewEvents = 0; hasNewEvents = 0;
friendStatus = Status::Offline; friendStatus = Status::Offline;
userID = ToxID::fromString(UserId);
} }
Friend::~Friend() Friend::~Friend()
@ -35,10 +36,23 @@ Friend::~Friend()
} }
void Friend::setName(QString name) void Friend::setName(QString name)
{
userName = name;
if (userAlias.size() == 0)
{ {
widget->setName(name); widget->setName(name);
chatForm->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) void Friend::setStatusMessage(QString message)
{ {
@ -46,12 +60,49 @@ void Friend::setStatusMessage(QString message)
chatForm->setStatusMessage(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: public:
Friend(int FriendId, QString UserId); Friend(int FriendId, QString UserId);
~Friend(); ~Friend();
void setName(QString name);
void setStatusMessage(QString message);
QString getName() const;
ToxID getToxID() const;
public: void setName(QString name);
FriendWidget* widget; 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; int friendId;
QString userId;
ChatForm* chatForm;
int hasNewEvents; int hasNewEvents;
Status friendStatus; Status friendStatus;
FriendWidget* widget;
ChatForm* chatForm;
}; };
#endif // FRIEND_H #endif // FRIEND_H

View File

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

View File

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

View File

@ -132,36 +132,36 @@ void FriendWidget::setAsInactiveChatroom()
void FriendWidget::updateStatusLight() void FriendWidget::updateStatusLight()
{ {
Friend* f = FriendList::findFriend(friendId); 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")); 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")); 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")); 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")); 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")); 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")); 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")); 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")); statusPic.setPixmap(QPixmap(":img/status/dot_away_notification.png"));
} }
void FriendWidget::setChatForm(Ui::MainWindow &ui) void FriendWidget::setChatForm(Ui::MainWindow &ui)
{ {
Friend* f = FriendList::findFriend(friendId); Friend* f = FriendList::findFriend(friendId);
f->chatForm->show(ui); f->getChatForm()->show(ui);
} }
void FriendWidget::resetEventFlags() void FriendWidget::resetEventFlags()
{ {
Friend* f = FriendList::findFriend(friendId); Friend* f = FriendList::findFriend(friendId);
f->hasNewEvents = 0; f->setEventFlag(false);
} }
void FriendWidget::onAvatarChange(int FriendId, const QPixmap& pic) 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; //qDebug() << "Widget: Adding friend with id" << userId;
Friend* newfriend = FriendList::addFriend(friendId, userId); Friend* newfriend = FriendList::addFriend(friendId, userId);
QLayout* layout = contactListWidget->getFriendLayout(Status::Offline); QLayout* layout = contactListWidget->getFriendLayout(Status::Offline);
layout->addWidget(newfriend->widget); layout->addWidget(newfriend->getFriendWidget());
connect(newfriend->widget, SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*))); connect(newfriend->getFriendWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
connect(newfriend->widget, SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int))); connect(newfriend->getFriendWidget(), SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
connect(newfriend->widget, SIGNAL(copyFriendIdToClipboard(int)), this, SLOT(copyFriendIdToClipboard(int))); connect(newfriend->getFriendWidget(), SIGNAL(copyFriendIdToClipboard(int)), this, SLOT(copyFriendIdToClipboard(int)));
connect(newfriend->widget, SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), newfriend->chatForm, SLOT(focusInput())); connect(newfriend->getFriendWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), newfriend->getChatForm(), SLOT(focusInput()));
connect(newfriend->chatForm, SIGNAL(sendMessage(int,QString)), core, SLOT(sendMessage(int,QString))); connect(newfriend->getChatForm(), SIGNAL(sendMessage(int,QString)), core, SLOT(sendMessage(int,QString)));
connect(newfriend->chatForm, &GenericChatForm::sendAction, core, &Core::sendAction); connect(newfriend->getChatForm(), &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->getChatForm(), 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->getChatForm(), SIGNAL(answerCall(int)), core, SLOT(answerCall(int)));
connect(newfriend->chatForm, SIGNAL(hangupCall(int)), core, SLOT(hangupCall(int))); connect(newfriend->getChatForm(), SIGNAL(hangupCall(int)), core, SLOT(hangupCall(int)));
connect(newfriend->chatForm, SIGNAL(startCall(int)), core, SLOT(startCall(int))); connect(newfriend->getChatForm(), SIGNAL(startCall(int)), core, SLOT(startCall(int)));
connect(newfriend->chatForm, SIGNAL(startVideoCall(int,bool)), core, SLOT(startCall(int,bool))); connect(newfriend->getChatForm(), SIGNAL(startVideoCall(int,bool)), core, SLOT(startCall(int,bool)));
connect(newfriend->chatForm, SIGNAL(cancelCall(int,int)), core, SLOT(cancelCall(int,int))); connect(newfriend->getChatForm(), SIGNAL(cancelCall(int,int)), core, SLOT(cancelCall(int,int)));
connect(newfriend->chatForm, SIGNAL(micMuteToggle(int)), core, SLOT(micMuteToggle(int))); connect(newfriend->getChatForm(), SIGNAL(micMuteToggle(int)), core, SLOT(micMuteToggle(int)));
connect(newfriend->chatForm, SIGNAL(volMuteToggle(int)), core, SLOT(volMuteToggle(int))); connect(newfriend->getChatForm(), SIGNAL(volMuteToggle(int)), core, SLOT(volMuteToggle(int)));
connect(core, &Core::fileReceiveRequested, newfriend->chatForm, &ChatForm::onFileRecvRequest); connect(core, &Core::fileReceiveRequested, newfriend->getChatForm(), &ChatForm::onFileRecvRequest);
connect(core, &Core::avInvite, newfriend->chatForm, &ChatForm::onAvInvite); connect(core, &Core::avInvite, newfriend->getChatForm(), &ChatForm::onAvInvite);
connect(core, &Core::avStart, newfriend->chatForm, &ChatForm::onAvStart); connect(core, &Core::avStart, newfriend->getChatForm(), &ChatForm::onAvStart);
connect(core, &Core::avCancel, newfriend->chatForm, &ChatForm::onAvCancel); connect(core, &Core::avCancel, newfriend->getChatForm(), &ChatForm::onAvCancel);
connect(core, &Core::avEnd, newfriend->chatForm, &ChatForm::onAvEnd); connect(core, &Core::avEnd, newfriend->getChatForm(), &ChatForm::onAvEnd);
connect(core, &Core::avRinging, newfriend->chatForm, &ChatForm::onAvRinging); connect(core, &Core::avRinging, newfriend->getChatForm(), &ChatForm::onAvRinging);
connect(core, &Core::avStarting, newfriend->chatForm, &ChatForm::onAvStarting); connect(core, &Core::avStarting, newfriend->getChatForm(), &ChatForm::onAvStarting);
connect(core, &Core::avEnding, newfriend->chatForm, &ChatForm::onAvEnding); connect(core, &Core::avEnding, newfriend->getChatForm(), &ChatForm::onAvEnding);
connect(core, &Core::avRequestTimeout, newfriend->chatForm, &ChatForm::onAvRequestTimeout); connect(core, &Core::avRequestTimeout, newfriend->getChatForm(), &ChatForm::onAvRequestTimeout);
connect(core, &Core::avPeerTimeout, newfriend->chatForm, &ChatForm::onAvPeerTimeout); connect(core, &Core::avPeerTimeout, newfriend->getChatForm(), &ChatForm::onAvPeerTimeout);
connect(core, &Core::avMediaChange, newfriend->chatForm, &ChatForm::onAvMediaChange); connect(core, &Core::avMediaChange, newfriend->getChatForm(), &ChatForm::onAvMediaChange);
connect(core, &Core::avCallFailed, newfriend->chatForm, &ChatForm::onAvCallFailed); connect(core, &Core::avCallFailed, newfriend->getChatForm(), &ChatForm::onAvCallFailed);
connect(core, &Core::avRejected, newfriend->chatForm, &ChatForm::onAvRejected); connect(core, &Core::avRejected, newfriend->getChatForm(), &ChatForm::onAvRejected);
connect(core, &Core::friendAvatarChanged, newfriend->chatForm, &ChatForm::onAvatarChange); connect(core, &Core::friendAvatarChanged, newfriend->getChatForm(), &ChatForm::onAvatarChange);
connect(core, &Core::friendAvatarChanged, newfriend->widget, &FriendWidget::onAvatarChange); connect(core, &Core::friendAvatarChanged, newfriend->getFriendWidget(), &FriendWidget::onAvatarChange);
connect(core, &Core::friendAvatarRemoved, newfriend->chatForm, &ChatForm::onAvatarRemoved); connect(core, &Core::friendAvatarRemoved, newfriend->getChatForm(), &ChatForm::onAvatarRemoved);
connect(core, &Core::friendAvatarRemoved, newfriend->widget, &FriendWidget::onAvatarRemoved); connect(core, &Core::friendAvatarRemoved, newfriend->getFriendWidget(), &FriendWidget::onAvatarRemoved);
// Try to get the avatar from the cache // Try to get the avatar from the cache
QPixmap avatar = Settings::getInstance().getSavedAvatar(userId); QPixmap avatar = Settings::getInstance().getSavedAvatar(userId);
if (!avatar.isNull()) if (!avatar.isNull())
{ {
//qWarning() << "Widget: loadded avatar for id" << userId; //qWarning() << "Widget: loadded avatar for id" << userId;
newfriend->chatForm->onAvatarChange(friendId, avatar); newfriend->getChatForm()->onAvatarChange(friendId, avatar);
newfriend->widget->onAvatarChange(friendId, avatar); newfriend->getFriendWidget()->onAvatarChange(friendId, avatar);
} }
} }
@ -657,17 +657,17 @@ void Widget::onFriendStatusChanged(int friendId, Status status)
if (!f) if (!f)
return; return;
contactListWidget->moveWidget(f->widget, status); contactListWidget->moveWidget(f->getFriendWidget(), status);
f->friendStatus = status; f->setStatus(status);
f->widget->updateStatusLight(); f->getFriendWidget()->updateStatusLight();
//won't print the message if there were no messages before //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) && Settings::getInstance().getStatusChangeNotificationEnabled() == true)
{ {
QString fStatus = ""; QString fStatus = "";
switch(f->friendStatus){ switch(f->getStatus()){
case Status::Away: case Status::Away:
fStatus = tr("away", "contact status"); break; fStatus = tr("away", "contact status"); break;
case Status::Busy: case Status::Busy:
@ -677,7 +677,7 @@ void Widget::onFriendStatusChanged(int friendId, Status status)
default: default:
fStatus = tr("online", "contact status"); break; 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()); "white", QDateTime::currentDateTime());
} }
} }
@ -726,28 +726,28 @@ void Widget::onFriendMessageReceived(int friendId, const QString& message, bool
return; return;
QDateTime timestamp = QDateTime::currentDateTime(); QDateTime timestamp = QDateTime::currentDateTime();
f->chatForm->addMessage(f->getToxID(), message, isAction, timestamp); f->getChatForm()->addMessage(f->getToxID(), message, isAction, timestamp);
if (isAction) 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 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 (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(); newMessageAlert();
} }
} }
else else
{ {
f->hasNewEvents = 1; f->setEventFlag(true);
newMessageAlert(); newMessageAlert();
} }
f->widget->updateStatusLight(); f->getFriendWidget()->updateStatusLight();
} }
void Widget::newMessageAlert() void Widget::newMessageAlert()
@ -800,11 +800,11 @@ void Widget::onFriendRequestReceived(const QString& userId, const QString& messa
void Widget::removeFriend(Friend* f) void Widget::removeFriend(Friend* f)
{ {
f->widget->setAsInactiveChatroom(); f->getFriendWidget()->setAsInactiveChatroom();
if (static_cast<GenericChatroomWidget*>(f->widget) == activeChatroomWidget) if (static_cast<GenericChatroomWidget*>(f->getFriendWidget()) == activeChatroomWidget)
activeChatroomWidget = nullptr; activeChatroomWidget = nullptr;
FriendList::removeFriend(f->friendId); FriendList::removeFriend(f->getFriendID());
core->removeFriend(f->friendId); core->removeFriend(f->getFriendID());
delete f; delete f;
if (ui->mainHead->layout()->isEmpty()) if (ui->mainHead->layout()->isEmpty())
onAddClicked(); onAddClicked();
@ -832,7 +832,7 @@ void Widget::copyFriendIdToClipboard(int friendId)
if (f != nullptr) if (f != nullptr)
{ {
QClipboard *clipboard = QApplication::clipboard(); 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) if (!f)
return false; return false;
return (activeChatroomWidget == static_cast<GenericChatroomWidget*>(f->widget)); return (activeChatroomWidget == static_cast<GenericChatroomWidget*>(f->getFriendWidget()));
} }
bool Widget::event(QEvent * e) bool Widget::event(QEvent * e)
@ -1033,7 +1033,7 @@ void Widget::onMessageSendResult(int friendId, const QString& message, int messa
return; return;
if (!messageId) 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) void Widget::onGroupSendResult(int groupId, const QString& message, int result)