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

156 lines
3.3 KiB
C++
Raw Normal View History

2014-07-07 00:19:45 +08:00
/*
Copyright © 2014-2015 by The qTox Project
2014-07-07 00:19:45 +08:00
This file is part of qTox, a Qt-based graphical interface for Tox.
qTox is libre software: you can redistribute it and/or modify
2014-07-07 00:19:45 +08:00
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
qTox is distributed in the hope that it will be useful,
2014-07-07 00:19:45 +08:00
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
2014-07-07 00:19:45 +08:00
You should have received a copy of the GNU General Public License
along with qTox. If not, see <http://www.gnu.org/licenses/>.
2014-07-07 00:19:45 +08:00
*/
2014-06-25 04:11:11 +08:00
#include "friend.h"
#include "friendlist.h"
#include "widget/friendwidget.h"
2014-09-11 21:44:34 +08:00
#include "widget/form/chatform.h"
#include "widget/gui.h"
#include "src/core/core.h"
2015-06-06 07:44:47 +08:00
#include "src/persistence/settings.h"
#include "src/persistence/historykeeper.h"
2014-06-25 04:11:11 +08:00
Friend::Friend(uint32_t FriendId, const ToxId &UserId)
2015-01-30 04:23:33 +08:00
: userName{Core::getInstance()->getPeerName(UserId)},
userID{UserId}, friendId{FriendId}
2014-06-25 04:11:11 +08:00
{
hasNewEvents = 0;
friendStatus = Status::Offline;
if (userName.size() == 0)
userName = UserId.publicKey;
userAlias = Settings::getInstance().getFriendAlias(UserId);
widget = new FriendWidget(friendId, getDisplayedName());
chatForm = new ChatForm(this);
HistoryKeeper::getInstance()->importAvatar(UserId.publicKey);
2014-06-25 04:11:11 +08:00
}
Friend::~Friend()
{
delete chatForm;
delete widget;
}
void Friend::loadHistory()
{
if (Settings::getInstance().getEnableLogging())
{
chatForm->loadHistory(QDateTime::currentDateTime().addDays(-7), true);
widget->historyLoaded = true;
}
}
2014-06-25 04:11:11 +08:00
void Friend::setName(QString name)
{
2015-10-10 19:25:58 +08:00
if (name.isEmpty())
name = userID.publicKey;
2014-11-06 23:26:22 +08:00
userName = name;
if (userAlias.size() == 0)
{
widget->setName(name);
chatForm->setName(name);
2014-11-09 00:53:00 +08:00
if (widget->isActive())
GUI::setWindowTitle(name);
emit displayedNameChanged(getFriendWidget(), getStatus(), hasNewEvents);
2014-11-06 23:26:22 +08:00
}
}
void Friend::setAlias(QString name)
{
userAlias = name;
QString dispName = userAlias.size() == 0 ? userName : userAlias;
widget->setName(dispName);
chatForm->setName(dispName);
2014-11-15 08:28:44 +08:00
if (widget->isActive())
GUI::setWindowTitle(dispName);
emit displayedNameChanged(getFriendWidget(), getStatus(), hasNewEvents);
2014-06-25 04:11:11 +08:00
}
void Friend::setStatusMessage(QString message)
{
2014-10-01 17:13:49 +08:00
widget->setStatusMsg(message);
2014-06-25 04:11:11 +08:00
chatForm->setStatusMessage(message);
}
2014-11-06 23:26:22 +08:00
QString Friend::getDisplayedName() const
{
if (userAlias.size() == 0)
return userName;
2015-04-24 19:01:50 +08:00
2014-11-06 23:26:22 +08:00
return userAlias;
}
2015-09-15 02:25:16 +08:00
bool Friend::hasAlias() const
{
return !userAlias.isEmpty();
}
const ToxId &Friend::getToxId() const
2014-11-06 23:26:22 +08:00
{
return userID;
}
uint32_t Friend::getFriendID() const
2014-11-06 23:26:22 +08:00
{
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()
2014-06-25 04:11:11 +08:00
{
2014-11-06 23:26:22 +08:00
return chatForm;
2014-06-25 04:11:11 +08:00
}
2014-11-06 23:26:22 +08:00
FriendWidget *Friend::getFriendWidget()
{
2014-11-06 23:26:22 +08:00
return widget;
}
2015-06-09 03:31:40 +08:00
const FriendWidget *Friend::getFriendWidget() const
{
return widget;
}