2014-07-07 00:19:45 +08:00
|
|
|
/*
|
2015-06-06 09:40:08 +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.
|
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
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.
|
2015-06-06 09:40:08 +08:00
|
|
|
|
|
|
|
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
|
2015-06-06 09:40:08 +08:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2014-07-07 00:19:45 +08:00
|
|
|
|
2015-06-06 09:40:08 +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
|
|
|
*/
|
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
#include "friend.h"
|
|
|
|
#include "friendlist.h"
|
2014-06-27 06:42:45 +08:00
|
|
|
#include "widget/friendwidget.h"
|
2014-09-11 21:44:34 +08:00
|
|
|
#include "widget/form/chatform.h"
|
2015-02-07 02:01:31 +08:00
|
|
|
#include "widget/gui.h"
|
2015-04-24 08:32:09 +08:00
|
|
|
#include "src/core/core.h"
|
2015-06-06 07:44:47 +08:00
|
|
|
#include "src/persistence/settings.h"
|
2015-10-18 21:50:00 +08:00
|
|
|
#include "src/persistence/historykeeper.h"
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2015-05-18 04:55:50 +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
|
|
|
{
|
2014-08-31 22:48:15 +08:00
|
|
|
hasNewEvents = 0;
|
2014-06-28 00:12:43 +08:00
|
|
|
friendStatus = Status::Offline;
|
2014-11-16 22:48:18 +08:00
|
|
|
if (userName.size() == 0)
|
|
|
|
userName = UserId.publicKey;
|
|
|
|
|
|
|
|
userAlias = Settings::getInstance().getFriendAlias(UserId);
|
|
|
|
|
|
|
|
widget = new FriendWidget(friendId, getDisplayedName());
|
2014-11-09 05:43:33 +08:00
|
|
|
chatForm = new ChatForm(this);
|
2015-10-18 21:50:00 +08:00
|
|
|
HistoryKeeper::getInstance()->importAvatar(UserId.publicKey);
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Friend::~Friend()
|
|
|
|
{
|
|
|
|
delete chatForm;
|
|
|
|
delete widget;
|
|
|
|
}
|
|
|
|
|
2015-04-26 20:40:07 +08:00
|
|
|
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())
|
2015-02-07 02:01:31 +08:00
|
|
|
GUI::setWindowTitle(name);
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-12 08:23:22 +08:00
|
|
|
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())
|
2015-02-07 02:01:31 +08:00
|
|
|
GUI::setWindowTitle(dispName);
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-12 08:23:22 +08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2015-05-24 02:58:41 +08:00
|
|
|
const ToxId &Friend::getToxId() const
|
2014-11-06 23:26:22 +08:00
|
|
|
{
|
|
|
|
return userID;
|
|
|
|
}
|
|
|
|
|
2015-04-20 05:12:44 +08:00
|
|
|
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-03 01:36:27 +08:00
|
|
|
|
2014-11-06 23:26:22 +08:00
|
|
|
FriendWidget *Friend::getFriendWidget()
|
2014-11-03 01:36:27 +08:00
|
|
|
{
|
2014-11-06 23:26:22 +08:00
|
|
|
return widget;
|
2014-11-03 01:36:27 +08:00
|
|
|
}
|
2015-06-09 03:31:40 +08:00
|
|
|
|
|
|
|
const FriendWidget *Friend::getFriendWidget() const
|
|
|
|
{
|
|
|
|
return widget;
|
|
|
|
}
|