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
|
|
|
*/
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
#include "friendwidget.h"
|
2016-12-12 06:01:55 +08:00
|
|
|
|
2016-12-19 10:26:26 +08:00
|
|
|
#include "circlewidget.h"
|
|
|
|
#include "contentdialog.h"
|
|
|
|
#include "friendlistwidget.h"
|
|
|
|
#include "groupwidget.h"
|
|
|
|
#include "maskablepixmapwidget.h"
|
|
|
|
|
|
|
|
#include "src/core/core.h"
|
2017-07-30 01:39:14 +08:00
|
|
|
#include "src/model/friend.h"
|
2017-08-30 14:40:12 +08:00
|
|
|
#include "src/model/about/aboutfriend.h"
|
2016-12-19 10:26:26 +08:00
|
|
|
#include "src/friendlist.h"
|
2017-07-30 01:39:14 +08:00
|
|
|
#include "src/model/group.h"
|
2016-12-19 10:26:26 +08:00
|
|
|
#include "src/grouplist.h"
|
|
|
|
#include "src/persistence/settings.h"
|
2017-08-30 05:46:19 +08:00
|
|
|
#include "src/widget/about/aboutfriendform.h"
|
2016-12-19 10:26:26 +08:00
|
|
|
#include "src/widget/form/chatform.h"
|
|
|
|
#include "src/widget/style.h"
|
|
|
|
#include "src/widget/tool/croppinglabel.h"
|
|
|
|
#include "src/widget/widget.h"
|
2016-12-12 06:01:55 +08:00
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QBitmap>
|
|
|
|
#include <QCollator>
|
|
|
|
#include <QContextMenuEvent>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDrag>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QInputDialog>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QMimeData>
|
|
|
|
|
2016-12-19 10:26:26 +08:00
|
|
|
#include <cassert>
|
2015-05-29 21:26:43 +08:00
|
|
|
|
2018-02-09 14:18:14 +08:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
constexpr auto MAX_NAME_LENGTH = 30;
|
|
|
|
}
|
|
|
|
|
2016-08-24 07:51:38 +08:00
|
|
|
/**
|
|
|
|
* @class FriendWidget
|
|
|
|
*
|
|
|
|
* Widget, which displays brief information about friend.
|
|
|
|
* For example, used on friend list.
|
|
|
|
* When you click should open the chat with friend. Widget has a context menu.
|
|
|
|
*/
|
|
|
|
|
2017-07-26 18:02:32 +08:00
|
|
|
FriendWidget::FriendWidget(const Friend* f, bool compact)
|
2017-04-18 05:55:23 +08:00
|
|
|
: GenericChatroomWidget(compact)
|
2017-07-26 18:02:32 +08:00
|
|
|
, frnd{f}
|
2014-10-01 02:10:42 +08:00
|
|
|
, isDefaultAvatar{true}
|
2014-06-25 04:11:11 +08:00
|
|
|
{
|
2016-01-21 11:47:26 +08:00
|
|
|
avatar->setPixmap(QPixmap(":/img/contact.svg"));
|
2018-01-14 04:20:03 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":/img/status/offline.svg"));
|
2015-03-18 07:45:57 +08:00
|
|
|
statusPic.setMargin(3);
|
2017-07-26 18:02:32 +08:00
|
|
|
nameLabel->setText(f->getDisplayedName());
|
2015-02-27 22:05:03 +08:00
|
|
|
nameLabel->setTextFormat(Qt::PlainText);
|
2015-06-02 02:39:40 +08:00
|
|
|
connect(nameLabel, &CroppingLabel::editFinished, this, &FriendWidget::setAlias);
|
2015-02-27 22:05:03 +08:00
|
|
|
statusMessageLabel->setTextFormat(Qt::PlainText);
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
2016-08-24 07:51:38 +08:00
|
|
|
/**
|
|
|
|
* @brief FriendWidget::contextMenuEvent
|
|
|
|
* @param event Describe a context menu event
|
|
|
|
*
|
|
|
|
* Default context menu event handler.
|
|
|
|
* Redirect all event information to the signal.
|
|
|
|
*/
|
2017-01-06 19:02:54 +08:00
|
|
|
void FriendWidget::contextMenuEvent(QContextMenuEvent* event)
|
2016-08-24 07:51:38 +08:00
|
|
|
{
|
|
|
|
emit contextMenuCalled(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief FriendWidget::onContextMenuCalled
|
|
|
|
* @param event Redirected from native contextMenuEvent
|
|
|
|
*
|
|
|
|
* Context menu handler. Always should be called to FriendWidget from FriendList
|
|
|
|
*/
|
2017-02-26 19:52:45 +08:00
|
|
|
void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
|
2014-06-25 04:11:11 +08:00
|
|
|
{
|
2017-07-26 17:46:11 +08:00
|
|
|
if (!active) {
|
2015-06-11 00:11:50 +08:00
|
|
|
setBackgroundRole(QPalette::Highlight);
|
2017-07-26 17:46:11 +08:00
|
|
|
}
|
2015-06-11 00:11:50 +08:00
|
|
|
|
|
|
|
installEventFilter(this); // Disable leave event.
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
QMenu menu;
|
2015-06-23 02:01:50 +08:00
|
|
|
|
2018-02-09 14:18:14 +08:00
|
|
|
const auto friendId = frnd->getId();
|
2017-07-27 13:55:50 +08:00
|
|
|
const ContentDialog* contentDialog = ContentDialog::getFriendDialog(friendId);
|
2015-06-23 02:01:50 +08:00
|
|
|
|
2017-07-26 17:46:11 +08:00
|
|
|
if (!contentDialog || contentDialog->chatroomWidgetCount() > 1) {
|
2018-02-09 14:18:14 +08:00
|
|
|
const auto openChatWindow = menu.addAction(tr("Open chat in new window"));
|
|
|
|
connect(openChatWindow, &QAction::triggered, [=]() { emit newWindowOpened(this); });
|
2017-07-26 17:46:11 +08:00
|
|
|
}
|
2015-06-23 02:01:50 +08:00
|
|
|
|
2017-07-26 17:46:11 +08:00
|
|
|
if (contentDialog && contentDialog->hasFriendWidget(friendId, this)) {
|
2018-02-09 14:18:14 +08:00
|
|
|
const auto removeChatWindow = menu.addAction(tr("Remove chat from this window"));
|
|
|
|
connect(removeChatWindow, &QAction::triggered, this, &FriendWidget::removeChatWindow);
|
2017-07-26 17:46:11 +08:00
|
|
|
}
|
2015-06-23 02:01:50 +08:00
|
|
|
|
2015-06-19 22:58:48 +08:00
|
|
|
menu.addSeparator();
|
2017-07-26 17:46:11 +08:00
|
|
|
QMenu* inviteMenu = menu.addMenu(tr("Invite to group",
|
|
|
|
"Menu to invite a friend to a groupchat"));
|
|
|
|
inviteMenu->setEnabled(frnd->getStatus() != Status::Offline);
|
2018-02-09 14:18:14 +08:00
|
|
|
const auto newGroupAction = inviteMenu->addAction(tr("To new group"));
|
|
|
|
connect(newGroupAction, &QAction::triggered, this, &FriendWidget::moveToNewGroup);
|
2016-02-21 05:32:57 +08:00
|
|
|
inviteMenu->addSeparator();
|
2015-05-29 06:36:21 +08:00
|
|
|
|
2017-07-27 13:55:50 +08:00
|
|
|
for (const Group* group : GroupList::getAllGroups()) {
|
2018-02-09 14:18:14 +08:00
|
|
|
auto name = group->getName();
|
|
|
|
if (name.length() > MAX_NAME_LENGTH) {
|
|
|
|
name = name.left(MAX_NAME_LENGTH).trimmed() + "..";
|
2016-04-26 01:40:51 +08:00
|
|
|
}
|
2018-02-09 14:18:14 +08:00
|
|
|
const auto groupAction = inviteMenu->addAction(tr("Invite to group '%1'").arg(name));
|
|
|
|
connect(groupAction, &QAction::triggered, [=]() { inviteFriend(friendId, group); });
|
2014-06-28 16:53:38 +08:00
|
|
|
}
|
2015-05-29 06:36:21 +08:00
|
|
|
|
2018-02-09 14:18:14 +08:00
|
|
|
const auto& s = Settings::getInstance();
|
|
|
|
const auto circleId = s.getFriendCircleID(frnd->getPublicKey());
|
|
|
|
auto circleWidget = CircleWidget::getFromID(circleId);
|
|
|
|
auto w = circleWidget ? circleWidget : static_cast<QWidget*>(this);
|
|
|
|
auto friendList = qobject_cast<FriendListWidget*>(w->parentWidget());
|
2015-05-29 06:36:21 +08:00
|
|
|
|
2018-02-09 14:18:14 +08:00
|
|
|
auto circleMenu = menu.addMenu(tr("Move to circle...",
|
2017-07-26 17:46:11 +08:00
|
|
|
"Menu to move a friend into a different circle"));
|
2015-06-13 02:52:05 +08:00
|
|
|
|
2018-02-09 14:18:14 +08:00
|
|
|
const auto pk = frnd->getPublicKey();
|
|
|
|
const auto newCircleAction = circleMenu->addAction(tr("To new circle"));
|
|
|
|
connect(newCircleAction, &QAction::triggered, this, &FriendWidget::moveToNewCircle);
|
2015-05-29 21:26:43 +08:00
|
|
|
|
2017-07-26 17:46:11 +08:00
|
|
|
if (circleId != -1) {
|
2017-07-27 13:49:22 +08:00
|
|
|
const QString circleName = s.getCircleName(circleId);
|
2018-02-09 14:18:14 +08:00
|
|
|
const auto removeCircleAction = circleMenu->addAction(
|
|
|
|
tr("Remove from circle '%1'").arg(circleName));
|
|
|
|
connect(removeCircleAction, &QAction::triggered, this, &FriendWidget::removeFromCircle);
|
2017-07-26 17:46:11 +08:00
|
|
|
}
|
2015-06-18 03:45:03 +08:00
|
|
|
|
2015-06-24 02:58:30 +08:00
|
|
|
circleMenu->addSeparator();
|
2015-06-13 02:52:05 +08:00
|
|
|
|
2015-06-24 02:58:30 +08:00
|
|
|
QList<QAction*> circleActionList;
|
2017-07-27 13:49:22 +08:00
|
|
|
for (int i = 0; i < s.getCircleCount(); ++i) {
|
2017-07-26 17:46:11 +08:00
|
|
|
if (i == circleId) {
|
|
|
|
continue;
|
2015-05-31 03:10:43 +08:00
|
|
|
}
|
2017-07-26 17:46:11 +08:00
|
|
|
|
2018-02-09 14:18:14 +08:00
|
|
|
const auto name = s.getCircleName(i);
|
2017-07-26 17:46:11 +08:00
|
|
|
QAction* action = new QAction(tr("Move to circle \"%1\"").arg(name), circleMenu);
|
2018-02-09 14:18:14 +08:00
|
|
|
connect(action, &QAction::triggered, [=]() { moveToCircle(i); });
|
2017-07-26 17:46:11 +08:00
|
|
|
circleActionList.push_back(action);
|
2015-06-24 02:58:30 +08:00
|
|
|
}
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
std::sort(circleActionList.begin(), circleActionList.end(),
|
|
|
|
[](const QAction* lhs, const QAction* rhs) -> bool {
|
|
|
|
QCollator collator;
|
|
|
|
collator.setNumericMode(true);
|
|
|
|
return collator.compare(lhs->text(), rhs->text()) < 0;
|
|
|
|
});
|
2015-06-24 02:58:30 +08:00
|
|
|
|
|
|
|
circleMenu->addActions(circleActionList);
|
2015-05-29 21:26:43 +08:00
|
|
|
|
2018-02-09 14:18:14 +08:00
|
|
|
const auto setAlias = menu.addAction(tr("Set alias..."));
|
|
|
|
connect(setAlias, &QAction::triggered, [this]() { nameLabel->editBegin(); });
|
2014-11-08 00:02:10 +08:00
|
|
|
|
2014-10-20 12:25:52 +08:00
|
|
|
menu.addSeparator();
|
2018-02-09 14:18:14 +08:00
|
|
|
auto autoAccept = menu.addAction(tr("Auto accept files from this friend",
|
2017-07-26 17:46:11 +08:00
|
|
|
"context menu entry"));
|
2018-02-09 14:18:14 +08:00
|
|
|
const auto dir = s.getAutoAcceptDir(pk);
|
2014-11-06 06:34:28 +08:00
|
|
|
autoAccept->setCheckable(true);
|
|
|
|
autoAccept->setChecked(!dir.isEmpty());
|
2018-02-09 14:18:14 +08:00
|
|
|
connect(autoAccept, &QAction::triggered, this, &FriendWidget::changeAutoAccept);
|
2014-07-02 05:58:26 +08:00
|
|
|
menu.addSeparator();
|
2015-05-29 06:36:21 +08:00
|
|
|
|
2017-07-26 17:46:11 +08:00
|
|
|
if (!contentDialog || !contentDialog->hasFriendWidget(friendId, this)) {
|
2018-02-09 14:18:14 +08:00
|
|
|
const auto removeAction = menu.addAction(
|
|
|
|
tr("Remove friend", "Menu to remove the friend from our friendlist"));
|
|
|
|
connect(removeAction, &QAction::triggered, [=]() { emit removeFriend(friendId); });
|
2017-07-26 17:46:11 +08:00
|
|
|
}
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2015-11-10 04:55:11 +08:00
|
|
|
menu.addSeparator();
|
2018-02-09 14:18:14 +08:00
|
|
|
const auto aboutWindow = menu.addAction(tr("Show details"));
|
|
|
|
connect(aboutWindow, &QAction::triggered, this, &FriendWidget::showDetails);
|
2015-11-10 04:55:11 +08:00
|
|
|
|
2018-02-09 14:18:14 +08:00
|
|
|
const auto pos = event->globalPos();
|
|
|
|
menu.exec(pos);
|
2015-06-11 00:11:50 +08:00
|
|
|
|
|
|
|
removeEventFilter(this);
|
|
|
|
|
2017-05-28 17:39:11 +08:00
|
|
|
if (!active) {
|
2015-06-11 00:11:50 +08:00
|
|
|
setBackgroundRole(QPalette::Window);
|
2017-05-28 17:39:11 +08:00
|
|
|
}
|
2018-02-09 14:18:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FriendWidget::removeChatWindow()
|
|
|
|
{
|
|
|
|
const auto friendId = frnd->getId();
|
|
|
|
ContentDialog* contentDialog = ContentDialog::getFriendDialog(friendId);
|
|
|
|
contentDialog->removeFriend(friendId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FriendWidget::moveToNewGroup()
|
|
|
|
{
|
|
|
|
const auto friendId = frnd->getId();
|
|
|
|
const auto groupId = Core::getInstance()->createGroup();
|
|
|
|
Core::getInstance()->groupInviteFriend(friendId, groupId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FriendWidget::inviteFriend(uint32_t friendId, const Group* group)
|
|
|
|
{
|
|
|
|
Core::getInstance()->groupInviteFriend(friendId, group->getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
std::tuple<CircleWidget*, FriendListWidget*> getCircleAndFriendList(
|
|
|
|
const Friend* frnd, FriendWidget* fw)
|
|
|
|
{
|
|
|
|
const auto pk = frnd->getPublicKey();
|
|
|
|
const auto circleId = Settings::getInstance().getFriendCircleID(pk);
|
|
|
|
auto circleWidget = CircleWidget::getFromID(circleId);
|
|
|
|
auto w = circleWidget ? static_cast<QWidget*>(circleWidget) : static_cast<QWidget*>(fw);
|
|
|
|
auto friendList = qobject_cast<FriendListWidget*>(w->parentWidget());
|
|
|
|
return std::make_tuple(circleWidget, friendList);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void FriendWidget::moveToNewCircle()
|
|
|
|
{
|
|
|
|
CircleWidget* circleWidget;
|
|
|
|
FriendListWidget* friendList;
|
|
|
|
std::tie(circleWidget, friendList) = getCircleAndFriendList(frnd, this);
|
|
|
|
|
|
|
|
if (circleWidget != nullptr) {
|
|
|
|
circleWidget->updateStatus();
|
|
|
|
}
|
2015-06-11 00:11:50 +08:00
|
|
|
|
2018-02-09 14:18:14 +08:00
|
|
|
if (friendList != nullptr) {
|
|
|
|
friendList->addCircleWidget(this);
|
|
|
|
} else {
|
|
|
|
const auto pk = frnd->getPublicKey();
|
|
|
|
auto &s = Settings::getInstance();
|
|
|
|
auto circleId = s.addCircle();
|
|
|
|
s.setFriendCircleID(pk, circleId);
|
2017-05-28 17:39:11 +08:00
|
|
|
}
|
2018-02-09 14:18:14 +08:00
|
|
|
}
|
2016-08-24 07:51:38 +08:00
|
|
|
|
2018-02-09 14:18:14 +08:00
|
|
|
void FriendWidget::removeFromCircle()
|
|
|
|
{
|
|
|
|
CircleWidget* circleWidget;
|
|
|
|
FriendListWidget* friendList;
|
|
|
|
std::tie(circleWidget, friendList) = getCircleAndFriendList(frnd, this);
|
|
|
|
|
|
|
|
if (friendList != nullptr) {
|
|
|
|
friendList->moveWidget(this, frnd->getStatus(), true);
|
|
|
|
} else {
|
|
|
|
const auto pk = frnd->getPublicKey();
|
|
|
|
auto& s = Settings::getInstance();
|
|
|
|
s.setFriendCircleID(pk, -1);
|
|
|
|
}
|
2016-08-24 07:51:38 +08:00
|
|
|
|
2018-02-09 14:18:14 +08:00
|
|
|
if (circleWidget != nullptr) {
|
|
|
|
circleWidget->updateStatus();
|
|
|
|
Widget::getInstance()->searchCircle(circleWidget);
|
|
|
|
}
|
|
|
|
}
|
2016-08-24 07:51:38 +08:00
|
|
|
|
2018-02-09 14:18:14 +08:00
|
|
|
void FriendWidget::moveToCircle(int newCircleId)
|
|
|
|
{
|
|
|
|
const auto pk = frnd->getPublicKey();
|
|
|
|
const auto oldCircleId = Settings::getInstance().getFriendCircleID(pk);
|
|
|
|
auto& s = Settings::getInstance();
|
|
|
|
auto oldCircleWidget = CircleWidget::getFromID(oldCircleId);
|
|
|
|
auto newCircleWidget = CircleWidget::getFromID(newCircleId);
|
|
|
|
|
|
|
|
if (newCircleWidget) {
|
|
|
|
newCircleWidget->addFriendWidget(this, frnd->getStatus());
|
|
|
|
newCircleWidget->setExpanded(true);
|
|
|
|
Widget::getInstance()->searchCircle(newCircleWidget);
|
|
|
|
s.savePersonal();
|
|
|
|
} else {
|
|
|
|
s.setFriendCircleID(pk, newCircleId);
|
|
|
|
}
|
2016-08-24 07:51:38 +08:00
|
|
|
|
2018-02-09 14:18:14 +08:00
|
|
|
if (oldCircleWidget) {
|
|
|
|
oldCircleWidget->updateStatus();
|
|
|
|
Widget::getInstance()->searchCircle(oldCircleWidget);
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
}
|
2014-06-27 07:35:30 +08:00
|
|
|
|
2018-02-09 14:18:14 +08:00
|
|
|
void FriendWidget::changeAutoAccept(bool enable)
|
|
|
|
{
|
|
|
|
const auto pk = frnd->getPublicKey();
|
|
|
|
auto &s = Settings::getInstance();
|
|
|
|
if (enable) {
|
|
|
|
const auto oldDir = s.getAutoAcceptDir(pk);
|
|
|
|
const auto newDir = QFileDialog::getExistingDirectory(
|
|
|
|
Q_NULLPTR, tr("Choose an auto accept directory", "popup title"), oldDir);
|
|
|
|
|
|
|
|
const auto friendId = frnd->getId();
|
|
|
|
qDebug() << "Setting auto accept dir for" << friendId << "to" << newDir;
|
|
|
|
s.setAutoAcceptDir(pk, newDir);
|
|
|
|
} else {
|
|
|
|
qDebug() << "not checked";
|
|
|
|
s.setAutoAcceptDir(pk, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void FriendWidget::showDetails()
|
|
|
|
{
|
|
|
|
const QPointer<IAboutFriend> about = new AboutFriend(frnd, &Settings::getInstance());
|
|
|
|
auto aboutUser = new AboutFriendForm(about, Widget::getInstance());
|
|
|
|
aboutUser->show();
|
|
|
|
}
|
|
|
|
|
2014-06-27 09:47:16 +08:00
|
|
|
void FriendWidget::setAsActiveChatroom()
|
2014-06-27 07:35:30 +08:00
|
|
|
{
|
2014-10-01 02:10:42 +08:00
|
|
|
setActive(true);
|
2014-06-28 02:11:32 +08:00
|
|
|
|
2017-07-26 17:46:11 +08:00
|
|
|
if (isDefaultAvatar) {
|
2016-01-21 11:47:26 +08:00
|
|
|
avatar->setPixmap(QPixmap(":img/contact_dark.svg"));
|
2017-07-26 17:46:11 +08:00
|
|
|
}
|
2014-06-27 07:35:30 +08:00
|
|
|
}
|
|
|
|
|
2014-06-27 09:47:16 +08:00
|
|
|
void FriendWidget::setAsInactiveChatroom()
|
2014-06-27 07:35:30 +08:00
|
|
|
{
|
2014-10-01 02:10:42 +08:00
|
|
|
setActive(false);
|
2014-06-28 02:11:32 +08:00
|
|
|
|
2017-07-26 17:46:11 +08:00
|
|
|
if (isDefaultAvatar) {
|
2016-01-21 11:47:26 +08:00
|
|
|
avatar->setPixmap(QPixmap(":img/contact.svg"));
|
2017-07-26 17:46:11 +08:00
|
|
|
}
|
2014-06-27 07:35:30 +08:00
|
|
|
}
|
2014-08-22 23:19:16 +08:00
|
|
|
|
2014-08-31 22:19:16 +08:00
|
|
|
void FriendWidget::updateStatusLight()
|
|
|
|
{
|
2017-07-26 17:46:11 +08:00
|
|
|
static const QString statuses[] = {
|
2018-01-14 04:20:03 +08:00
|
|
|
":img/status/online.svg",
|
|
|
|
":img/status/online_notification.svg",
|
|
|
|
":img/status/away.svg",
|
|
|
|
":img/status/away_notification.svg",
|
|
|
|
":img/status/busy.svg",
|
|
|
|
":img/status/busy_notification.svg",
|
|
|
|
":img/status/offline.svg",
|
|
|
|
":img/status/offline_notification.svg",
|
2017-07-26 17:46:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const bool event = frnd->getEventFlag();
|
2017-07-30 00:38:34 +08:00
|
|
|
const int index = static_cast<int>(frnd->getStatus()) * 2 + event;
|
2017-07-26 17:46:11 +08:00
|
|
|
statusPic.setPixmap(QPixmap(statuses[index]));
|
|
|
|
|
|
|
|
if (event) {
|
|
|
|
const Settings& s = Settings::getInstance();
|
|
|
|
const uint32_t circleId = s.getFriendCircleID(frnd->getPublicKey());
|
|
|
|
CircleWidget* circleWidget = CircleWidget::getFromID(circleId);
|
|
|
|
if (circleWidget) {
|
2015-06-06 03:34:32 +08:00
|
|
|
circleWidget->setExpanded(true);
|
2017-07-26 17:46:11 +08:00
|
|
|
}
|
2015-06-13 00:52:41 +08:00
|
|
|
|
2017-07-26 17:46:11 +08:00
|
|
|
Widget::getInstance()->updateFriendActivity(frnd);
|
2015-06-03 21:51:23 +08:00
|
|
|
}
|
|
|
|
|
2017-07-26 17:46:11 +08:00
|
|
|
statusPic.setMargin(event ? 0 : 3);
|
2014-08-31 22:19:16 +08:00
|
|
|
}
|
2014-09-02 00:20:28 +08:00
|
|
|
|
2015-06-23 02:01:50 +08:00
|
|
|
QString FriendWidget::getStatusString() const
|
2015-03-26 03:08:46 +08:00
|
|
|
{
|
2017-07-26 17:46:11 +08:00
|
|
|
const int status = static_cast<int>(frnd->getStatus());
|
|
|
|
const bool event = frnd->getEventFlag();
|
|
|
|
|
|
|
|
static const QVector<QString> names = {
|
|
|
|
tr("Online"),
|
|
|
|
tr("Away"),
|
|
|
|
tr("Busy"),
|
|
|
|
tr("Offline"),
|
|
|
|
};
|
|
|
|
|
|
|
|
return event ? tr("New message") : names.value(status);
|
2015-03-26 03:08:46 +08:00
|
|
|
}
|
|
|
|
|
2017-07-26 18:02:32 +08:00
|
|
|
const Friend* FriendWidget::getFriend() const
|
2015-06-19 22:58:48 +08:00
|
|
|
{
|
2017-07-26 17:46:11 +08:00
|
|
|
return frnd;
|
2015-06-19 22:58:48 +08:00
|
|
|
}
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
void FriendWidget::search(const QString& searchString, bool hide)
|
2015-06-07 11:20:06 +08:00
|
|
|
{
|
|
|
|
searchName(searchString, hide);
|
2017-07-26 17:46:11 +08:00
|
|
|
const Settings& s = Settings::getInstance();
|
|
|
|
const uint32_t circleId = s.getFriendCircleID(frnd->getPublicKey());
|
|
|
|
CircleWidget* circleWidget = CircleWidget::getFromID(circleId);
|
|
|
|
if (circleWidget) {
|
2015-06-07 11:20:06 +08:00
|
|
|
circleWidget->search(searchString);
|
2017-07-26 17:46:11 +08:00
|
|
|
}
|
2015-06-07 11:20:06 +08:00
|
|
|
}
|
|
|
|
|
2014-09-02 00:20:28 +08:00
|
|
|
void FriendWidget::resetEventFlags()
|
|
|
|
{
|
2017-07-26 18:02:32 +08:00
|
|
|
// Hack to avoid edit const Friend. TODO: Repalce on emit
|
2017-08-02 13:39:37 +08:00
|
|
|
Friend* f = FriendList::findFriend(frnd->getId());
|
2014-11-06 23:26:22 +08:00
|
|
|
f->setEventFlag(false);
|
2014-09-02 00:20:28 +08:00
|
|
|
}
|
2014-09-24 23:28:38 +08:00
|
|
|
|
2017-10-27 19:52:06 +08:00
|
|
|
void FriendWidget::onAvatarChange(uint32_t friendId, const QPixmap& pic)
|
2014-09-24 23:28:38 +08:00
|
|
|
{
|
2017-08-02 13:39:37 +08:00
|
|
|
if (friendId != frnd->getId()) {
|
2014-09-24 23:28:38 +08:00
|
|
|
return;
|
2017-07-26 17:46:11 +08:00
|
|
|
}
|
2014-09-24 23:28:38 +08:00
|
|
|
|
2014-09-24 23:35:24 +08:00
|
|
|
isDefaultAvatar = false;
|
2014-09-26 22:39:29 +08:00
|
|
|
avatar->setPixmap(pic);
|
2014-09-24 23:28:38 +08:00
|
|
|
}
|
2014-09-26 00:03:25 +08:00
|
|
|
|
2017-10-27 19:52:06 +08:00
|
|
|
void FriendWidget::onAvatarRemoved(uint32_t friendId)
|
2014-09-27 03:23:20 +08:00
|
|
|
{
|
2017-08-02 13:39:37 +08:00
|
|
|
if (friendId != frnd->getId()) {
|
2014-09-27 03:23:20 +08:00
|
|
|
return;
|
2017-07-26 17:46:11 +08:00
|
|
|
}
|
2014-09-27 03:23:20 +08:00
|
|
|
|
|
|
|
isDefaultAvatar = true;
|
2014-10-05 20:22:28 +08:00
|
|
|
|
2017-09-07 09:08:54 +08:00
|
|
|
const QString path = QString(":/img/contact%1.svg").arg(isActive() ? "_dark" : "");
|
2017-07-26 17:46:11 +08:00
|
|
|
avatar->setPixmap(QPixmap(path));
|
2014-09-27 03:23:20 +08:00
|
|
|
}
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
void FriendWidget::mousePressEvent(QMouseEvent* ev)
|
2014-09-26 00:03:25 +08:00
|
|
|
{
|
2017-07-26 17:46:11 +08:00
|
|
|
if (ev->button() == Qt::LeftButton) {
|
2014-09-26 00:03:25 +08:00
|
|
|
dragStartPos = ev->pos();
|
2017-07-26 17:46:11 +08:00
|
|
|
}
|
2015-06-07 06:33:03 +08:00
|
|
|
|
|
|
|
GenericChatroomWidget::mousePressEvent(ev);
|
2014-09-26 00:03:25 +08:00
|
|
|
}
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
void FriendWidget::mouseMoveEvent(QMouseEvent* ev)
|
2014-09-26 00:03:25 +08:00
|
|
|
{
|
2017-07-26 17:46:11 +08:00
|
|
|
if (!(ev->buttons() & Qt::LeftButton)) {
|
2014-09-26 00:03:25 +08:00
|
|
|
return;
|
2017-07-26 17:46:11 +08:00
|
|
|
}
|
2014-09-26 00:03:25 +08:00
|
|
|
|
2017-07-26 17:46:11 +08:00
|
|
|
const int distance = (dragStartPos - ev->pos()).manhattanLength();
|
|
|
|
if (distance > QApplication::startDragDistance()) {
|
2014-09-26 00:03:25 +08:00
|
|
|
QMimeData* mdata = new QMimeData;
|
2016-12-30 06:14:48 +08:00
|
|
|
mdata->setText(getFriend()->getPublicKey().toString());
|
2014-09-26 00:03:25 +08:00
|
|
|
|
2016-08-07 03:28:40 +08:00
|
|
|
QDrag* drag = new QDrag(this);
|
2014-09-26 00:03:25 +08:00
|
|
|
drag->setMimeData(mdata);
|
2014-09-26 22:39:29 +08:00
|
|
|
drag->setPixmap(avatar->getPixmap());
|
2014-09-26 00:03:25 +08:00
|
|
|
drag->exec(Qt::CopyAction | Qt::MoveAction);
|
|
|
|
}
|
|
|
|
}
|
2014-11-07 22:55:32 +08:00
|
|
|
|
2014-11-18 10:15:44 +08:00
|
|
|
void FriendWidget::setAlias(const QString& _alias)
|
|
|
|
{
|
2017-05-12 00:24:54 +08:00
|
|
|
QString alias = _alias.left(tox_max_name_length());
|
2017-07-26 18:02:32 +08:00
|
|
|
// Hack to avoid edit const Friend. TODO: Repalce on emit
|
2017-08-02 13:39:37 +08:00
|
|
|
Friend* f = FriendList::findFriend(frnd->getId());
|
2014-11-18 10:15:44 +08:00
|
|
|
f->setAlias(alias);
|
|
|
|
}
|