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"
|
|
|
|
#include "src/friend.h"
|
|
|
|
#include "src/friendlist.h"
|
|
|
|
#include "src/group.h"
|
|
|
|
#include "src/grouplist.h"
|
|
|
|
#include "src/persistence/settings.h"
|
|
|
|
#include "src/widget/about/aboutuser.h"
|
|
|
|
#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
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
FriendWidget::FriendWidget(int FriendId, QString id)
|
2014-10-01 02:10:42 +08:00
|
|
|
: friendId(FriendId)
|
|
|
|
, isDefaultAvatar{true}
|
2015-01-07 20:16:09 +08:00
|
|
|
, historyLoaded{false}
|
2014-06-25 04:11:11 +08:00
|
|
|
{
|
2016-01-21 11:47:26 +08:00
|
|
|
avatar->setPixmap(QPixmap(":/img/contact.svg"));
|
2015-11-10 04:55:11 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":/img/status/dot_offline.svg"));
|
2015-03-18 07:45:57 +08:00
|
|
|
statusPic.setMargin(3);
|
2014-10-01 17:13:49 +08:00
|
|
|
nameLabel->setText(id);
|
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
|
|
|
|
*/
|
|
|
|
void FriendWidget::onContextMenuCalled(QContextMenuEvent *event)
|
2014-06-25 04:11:11 +08:00
|
|
|
{
|
2015-06-11 00:11:50 +08:00
|
|
|
if (!active)
|
|
|
|
setBackgroundRole(QPalette::Highlight);
|
|
|
|
|
|
|
|
installEventFilter(this); // Disable leave event.
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
QPoint pos = event->globalPos();
|
2016-12-30 06:14:48 +08:00
|
|
|
ToxPk id = FriendList::findFriend(friendId)->getPublicKey();
|
2014-10-18 11:59:59 +08:00
|
|
|
QString dir = Settings::getInstance().getAutoAcceptDir(id);
|
2014-06-25 04:11:11 +08:00
|
|
|
QMenu menu;
|
2015-06-23 02:01:50 +08:00
|
|
|
QAction* openChatWindow = nullptr;
|
|
|
|
QAction* removeChatWindow = nullptr;
|
|
|
|
|
2015-06-27 04:13:20 +08:00
|
|
|
ContentDialog* contentDialog = ContentDialog::getFriendDialog(friendId);
|
|
|
|
bool notAlone = contentDialog != nullptr && contentDialog->chatroomWidgetCount() > 1;
|
2015-06-23 02:01:50 +08:00
|
|
|
|
2015-06-27 04:13:20 +08:00
|
|
|
if (contentDialog == nullptr || notAlone)
|
|
|
|
openChatWindow = menu.addAction(tr("Open chat in new window"));
|
2015-06-23 02:01:50 +08:00
|
|
|
|
2016-06-09 01:30:57 +08:00
|
|
|
if (contentDialog != nullptr && contentDialog->hasFriendWidget(friendId, this))
|
2015-06-27 04:13:20 +08:00
|
|
|
removeChatWindow = menu.addAction(tr("Remove chat from this window"));
|
2015-06-23 02:01:50 +08:00
|
|
|
|
2015-06-19 22:58:48 +08:00
|
|
|
menu.addSeparator();
|
2014-10-20 12:25:52 +08:00
|
|
|
QMenu* inviteMenu = menu.addMenu(tr("Invite to group","Menu to invite a friend to a groupchat"));
|
2016-02-21 05:32:57 +08:00
|
|
|
QAction* newGroupAction = inviteMenu->addAction(tr("To new group"));
|
|
|
|
inviteMenu->addSeparator();
|
2014-06-28 16:53:38 +08:00
|
|
|
QMap<QAction*, Group*> groupActions;
|
2015-05-29 06:36:21 +08:00
|
|
|
|
2014-11-20 17:13:13 +08:00
|
|
|
for (Group* group : GroupList::getAllGroups())
|
2014-06-28 16:53:38 +08:00
|
|
|
{
|
2016-04-26 01:40:51 +08:00
|
|
|
int maxNameLen = 30;
|
|
|
|
QString name = group->getGroupWidget()->getName();
|
|
|
|
if ( name.length() > maxNameLen )
|
|
|
|
{
|
|
|
|
name = name.left(maxNameLen).trimmed() + "..";
|
|
|
|
}
|
|
|
|
QAction* groupAction = inviteMenu->addAction(tr("Invite to group '%1'").arg(name));
|
2014-06-28 16:53:38 +08:00
|
|
|
groupActions[groupAction] = group;
|
|
|
|
}
|
2015-05-29 06:36:21 +08:00
|
|
|
|
2016-12-30 06:14:48 +08:00
|
|
|
int circleId = Settings::getInstance().getFriendCircleID(FriendList::findFriend(friendId)->getPublicKey());
|
2015-06-13 02:52:05 +08:00
|
|
|
CircleWidget *circleWidget = CircleWidget::getFromID(circleId);
|
2015-05-29 21:26:43 +08:00
|
|
|
|
2015-06-13 02:52:05 +08:00
|
|
|
QMenu* circleMenu = nullptr;
|
|
|
|
QAction* newCircleAction = nullptr;
|
|
|
|
QAction *removeCircleAction = nullptr;
|
|
|
|
QMap<QAction*, int> circleActions;
|
2015-05-29 06:36:21 +08:00
|
|
|
|
2015-05-29 21:26:43 +08:00
|
|
|
FriendListWidget *friendList;
|
2015-06-13 02:52:05 +08:00
|
|
|
|
2015-05-29 21:26:43 +08:00
|
|
|
if (circleWidget == nullptr)
|
2016-08-24 07:51:38 +08:00
|
|
|
friendList = qobject_cast<FriendListWidget*>(this->parentWidget());
|
2015-05-29 21:26:43 +08:00
|
|
|
else
|
2016-09-23 10:06:20 +08:00
|
|
|
friendList = qobject_cast<FriendListWidget*>(circleWidget->parentWidget());
|
2015-05-29 21:26:43 +08:00
|
|
|
|
2015-06-24 02:58:30 +08:00
|
|
|
circleMenu = menu.addMenu(tr("Move to circle...", "Menu to move a friend into a different circle"));
|
2015-05-29 21:26:43 +08:00
|
|
|
|
2015-06-24 02:58:30 +08:00
|
|
|
newCircleAction = circleMenu->addAction(tr("To new circle"));
|
2015-06-18 03:45:03 +08:00
|
|
|
|
2015-06-24 02:58:30 +08:00
|
|
|
if (circleId != -1)
|
|
|
|
removeCircleAction = circleMenu->addAction(tr("Remove from circle '%1'").arg(Settings::getInstance().getCircleName(circleId)));
|
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;
|
|
|
|
|
|
|
|
for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i)
|
|
|
|
{
|
|
|
|
if (i != circleId)
|
2015-05-31 03:10:43 +08:00
|
|
|
{
|
2015-06-24 02:58:30 +08:00
|
|
|
circleActionList.push_back(new QAction(tr("Move to circle \"%1\"").arg(Settings::getInstance().getCircleName(i)), circleMenu));
|
|
|
|
circleActions[circleActionList.back()] = i;
|
2015-05-31 03:10:43 +08:00
|
|
|
}
|
2015-06-24 02:58:30 +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;
|
|
|
|
});
|
|
|
|
|
|
|
|
circleMenu->addActions(circleActionList);
|
2015-05-29 21:26:43 +08:00
|
|
|
|
2014-11-08 00:02:10 +08:00
|
|
|
QAction* setAlias = menu.addAction(tr("Set alias..."));
|
|
|
|
|
2014-10-20 12:25:52 +08:00
|
|
|
menu.addSeparator();
|
2014-10-18 11:59:59 +08:00
|
|
|
QAction* autoAccept = menu.addAction(tr("Auto accept files from this friend", "context menu entry"));
|
2014-11-06 06:34:28 +08:00
|
|
|
autoAccept->setCheckable(true);
|
|
|
|
autoAccept->setChecked(!dir.isEmpty());
|
2014-07-02 05:58:26 +08:00
|
|
|
menu.addSeparator();
|
2015-05-29 06:36:21 +08:00
|
|
|
|
2015-07-03 02:38:18 +08:00
|
|
|
QAction* removeFriendAction = nullptr;
|
|
|
|
|
|
|
|
if (contentDialog == nullptr || !contentDialog->hasFriendWidget(friendId, this))
|
|
|
|
removeFriendAction = menu.addAction(tr("Remove friend", "Menu to remove the friend from our friendlist"));
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2015-11-10 04:55:11 +08:00
|
|
|
menu.addSeparator();
|
|
|
|
QAction* aboutWindow = menu.addAction(tr("Show details"));
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
QAction* selectedItem = menu.exec(pos);
|
2015-06-11 00:11:50 +08:00
|
|
|
|
|
|
|
removeEventFilter(this);
|
|
|
|
|
|
|
|
if (!active)
|
|
|
|
setBackgroundRole(QPalette::Window);
|
|
|
|
|
2016-08-24 07:51:38 +08:00
|
|
|
if (!selectedItem)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (selectedItem == setAlias)
|
2014-06-25 04:11:11 +08:00
|
|
|
{
|
2016-08-24 07:51:38 +08:00
|
|
|
nameLabel->editBegin();
|
|
|
|
}
|
|
|
|
else if (selectedItem == removeFriendAction)
|
|
|
|
{
|
|
|
|
emit removeFriend(friendId);
|
|
|
|
}
|
|
|
|
else if (selectedItem == openChatWindow)
|
|
|
|
{
|
|
|
|
emit chatroomWidgetClicked(this, true);
|
|
|
|
}
|
|
|
|
else if (selectedItem == removeChatWindow)
|
|
|
|
{
|
|
|
|
ContentDialog* contentDialog = ContentDialog::getFriendDialog(friendId);
|
|
|
|
contentDialog->removeFriend(friendId);
|
|
|
|
}
|
|
|
|
else if (selectedItem == autoAccept)
|
|
|
|
{
|
|
|
|
if (!autoAccept->isChecked())
|
2014-10-18 11:59:59 +08:00
|
|
|
{
|
2016-08-24 07:51:38 +08:00
|
|
|
qDebug() << "not checked";
|
|
|
|
dir = QDir::homePath();
|
|
|
|
autoAccept->setChecked(false);
|
|
|
|
Settings::getInstance().setAutoAcceptDir(id, "");
|
2014-10-18 11:59:59 +08:00
|
|
|
}
|
2016-08-24 07:51:38 +08:00
|
|
|
else if (autoAccept->isChecked())
|
2016-02-21 05:32:57 +08:00
|
|
|
{
|
2016-08-24 07:51:38 +08:00
|
|
|
dir = QFileDialog::getExistingDirectory(
|
|
|
|
0, tr("Choose an auto accept directory", "popup title"),
|
|
|
|
dir, QFileDialog::DontUseNativeDialog);
|
|
|
|
|
|
|
|
autoAccept->setChecked(true);
|
|
|
|
qDebug() << "Setting auto accept dir for" << friendId << "to" << dir;
|
|
|
|
Settings::getInstance().setAutoAcceptDir(id, dir);
|
2015-11-10 04:55:11 +08:00
|
|
|
}
|
2016-08-24 07:51:38 +08:00
|
|
|
}
|
|
|
|
else if (selectedItem == aboutWindow)
|
|
|
|
{
|
|
|
|
AboutUser *aboutUser = new AboutUser(id, Widget::getInstance());
|
|
|
|
aboutUser->setFriend(FriendList::findFriend(friendId));
|
|
|
|
aboutUser->show();
|
|
|
|
}
|
|
|
|
else if (selectedItem == newGroupAction)
|
|
|
|
{
|
|
|
|
int groupId = Core::getInstance()->createGroup();
|
|
|
|
Core::getInstance()->groupInviteFriend(friendId, groupId);
|
|
|
|
}
|
|
|
|
else if (selectedItem == newCircleAction)
|
|
|
|
{
|
|
|
|
if (circleWidget != nullptr)
|
|
|
|
circleWidget->updateStatus();
|
|
|
|
|
|
|
|
if (friendList != nullptr)
|
|
|
|
friendList->addCircleWidget(this);
|
|
|
|
else
|
|
|
|
Settings::getInstance().setFriendCircleID(id, Settings::getInstance().addCircle());
|
|
|
|
}
|
|
|
|
else if (groupActions.contains(selectedItem))
|
|
|
|
{
|
|
|
|
Group* group = groupActions[selectedItem];
|
|
|
|
Core::getInstance()->groupInviteFriend(friendId, group->getGroupId());
|
|
|
|
}
|
|
|
|
else if (removeCircleAction != nullptr && selectedItem == removeCircleAction)
|
|
|
|
{
|
|
|
|
if (friendList)
|
|
|
|
friendList->moveWidget(this, FriendList::findFriend(friendId)->getStatus(), true);
|
|
|
|
else
|
|
|
|
Settings::getInstance().setFriendCircleID(id, -1);
|
|
|
|
|
|
|
|
if (circleWidget)
|
2016-02-21 05:32:57 +08:00
|
|
|
{
|
2016-08-24 07:51:38 +08:00
|
|
|
circleWidget->updateStatus();
|
|
|
|
Widget::getInstance()->searchCircle(circleWidget);
|
2016-02-21 05:32:57 +08:00
|
|
|
}
|
2016-08-24 07:51:38 +08:00
|
|
|
}
|
|
|
|
else if (circleActions.contains(selectedItem))
|
|
|
|
{
|
|
|
|
CircleWidget* circle = CircleWidget::getFromID(circleActions[selectedItem]);
|
2015-06-03 21:51:23 +08:00
|
|
|
|
2016-08-24 07:51:38 +08:00
|
|
|
if (circle)
|
2014-06-28 16:53:38 +08:00
|
|
|
{
|
2016-08-24 07:51:38 +08:00
|
|
|
circle->addFriendWidget(this, FriendList::findFriend(friendId)->getStatus());
|
|
|
|
circle->setExpanded(true);
|
|
|
|
Widget::getInstance()->searchCircle(circle);
|
|
|
|
Settings::getInstance().savePersonal();
|
2014-06-28 16:53:38 +08:00
|
|
|
}
|
2016-08-24 07:51:38 +08:00
|
|
|
else
|
2015-05-29 21:26:43 +08:00
|
|
|
{
|
2016-08-24 07:51:38 +08:00
|
|
|
Settings::getInstance().setFriendCircleID(id, circleActions[selectedItem]);
|
2015-05-29 21:26:43 +08:00
|
|
|
}
|
2016-08-24 07:51:38 +08:00
|
|
|
|
|
|
|
if (circleWidget)
|
2015-05-29 21:26:43 +08:00
|
|
|
{
|
2016-08-24 07:51:38 +08:00
|
|
|
circleWidget->updateStatus();
|
|
|
|
Widget::getInstance()->searchCircle(circleWidget);
|
2015-05-29 21:26:43 +08:00
|
|
|
}
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
}
|
2014-06-27 07:35:30 +08:00
|
|
|
|
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
|
|
|
|
2014-10-01 02:10:42 +08:00
|
|
|
if (isDefaultAvatar)
|
2016-01-21 11:47:26 +08:00
|
|
|
avatar->setPixmap(QPixmap(":img/contact_dark.svg"));
|
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
|
|
|
|
2014-10-01 02:10:42 +08:00
|
|
|
if (isDefaultAvatar)
|
2016-01-21 11:47:26 +08:00
|
|
|
avatar->setPixmap(QPixmap(":img/contact.svg"));
|
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()
|
|
|
|
{
|
|
|
|
Friend* f = FriendList::findFriend(friendId);
|
2014-11-06 23:26:22 +08:00
|
|
|
Status status = f->getStatus();
|
2014-08-31 22:19:16 +08:00
|
|
|
|
2016-08-22 05:30:07 +08:00
|
|
|
if (status == Status::Online && !f->getEventFlag())
|
2015-02-12 20:18:04 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_online.svg"));
|
2016-08-22 05:30:07 +08:00
|
|
|
else if (status == Status::Online && f->getEventFlag())
|
2015-02-12 20:18:04 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.svg"));
|
2016-08-22 05:30:07 +08:00
|
|
|
else if (status == Status::Away && !f->getEventFlag())
|
2015-02-12 20:18:04 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_away.svg"));
|
2016-08-22 05:30:07 +08:00
|
|
|
else if (status == Status::Away && f->getEventFlag())
|
2015-02-12 20:18:04 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_away_notification.svg"));
|
2016-08-22 05:30:07 +08:00
|
|
|
else if (status == Status::Busy && !f->getEventFlag())
|
2015-02-12 20:18:04 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_busy.svg"));
|
2016-08-22 05:30:07 +08:00
|
|
|
else if (status == Status::Busy && f->getEventFlag())
|
2015-02-12 20:18:04 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_busy_notification.svg"));
|
2016-08-22 05:30:07 +08:00
|
|
|
else if (status == Status::Offline && !f->getEventFlag())
|
2015-02-12 20:18:04 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_offline.svg"));
|
2016-08-22 05:30:07 +08:00
|
|
|
else if (status == Status::Offline && f->getEventFlag())
|
2015-02-12 20:18:04 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_offline_notification.svg"));
|
2015-03-18 07:45:57 +08:00
|
|
|
|
2015-06-03 21:51:23 +08:00
|
|
|
if (f->getEventFlag())
|
|
|
|
{
|
2016-12-30 06:14:48 +08:00
|
|
|
CircleWidget* circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleID(FriendList::findFriend(friendId)->getPublicKey()));
|
2015-06-03 21:51:23 +08:00
|
|
|
if (circleWidget != nullptr)
|
2015-06-06 03:34:32 +08:00
|
|
|
circleWidget->setExpanded(true);
|
2015-06-13 00:52:41 +08:00
|
|
|
|
|
|
|
Widget::getInstance()->updateFriendActivity(FriendList::findFriend(friendId));
|
2015-06-03 21:51:23 +08:00
|
|
|
}
|
|
|
|
|
2015-03-18 07:51:22 +08:00
|
|
|
if (!f->getEventFlag())
|
2015-03-18 07:45:57 +08:00
|
|
|
statusPic.setMargin(3);
|
|
|
|
else
|
|
|
|
statusPic.setMargin(0);
|
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
|
|
|
{
|
|
|
|
Friend* f = FriendList::findFriend(friendId);
|
|
|
|
Status status = f->getStatus();
|
|
|
|
|
2016-08-22 05:30:07 +08:00
|
|
|
if (f->getEventFlag())
|
2015-03-26 03:08:46 +08:00
|
|
|
return tr("New message");
|
|
|
|
else if (status == Status::Online)
|
|
|
|
return tr("Online");
|
|
|
|
else if (status == Status::Away)
|
|
|
|
return tr("Away");
|
|
|
|
else if (status == Status::Busy)
|
|
|
|
return tr("Busy");
|
|
|
|
else if (status == Status::Offline)
|
|
|
|
return tr("Offline");
|
|
|
|
return QString::null;
|
|
|
|
}
|
|
|
|
|
2015-06-19 22:58:48 +08:00
|
|
|
Friend* FriendWidget::getFriend() const
|
|
|
|
{
|
|
|
|
return FriendList::findFriend(friendId);
|
|
|
|
}
|
|
|
|
|
2015-06-07 11:20:06 +08:00
|
|
|
void FriendWidget::search(const QString &searchString, bool hide)
|
|
|
|
{
|
|
|
|
searchName(searchString, hide);
|
2016-12-30 06:14:48 +08:00
|
|
|
CircleWidget* circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleID(FriendList::findFriend(friendId)->getPublicKey()));
|
2015-06-07 11:20:06 +08:00
|
|
|
if (circleWidget != nullptr)
|
|
|
|
circleWidget->search(searchString);
|
|
|
|
}
|
|
|
|
|
2015-06-23 02:01:50 +08:00
|
|
|
bool FriendWidget::chatFormIsSet(bool focus) const
|
2014-09-02 00:20:28 +08:00
|
|
|
{
|
|
|
|
Friend* f = FriendList::findFriend(friendId);
|
2015-06-23 02:01:50 +08:00
|
|
|
return ContentDialog::existsFriendWidget(friendId, focus) || f->getChatForm()->isVisible();
|
2015-06-17 02:25:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FriendWidget::setChatForm(ContentLayout* contentLayout)
|
|
|
|
{
|
|
|
|
Friend* f = FriendList::findFriend(friendId);
|
|
|
|
f->getChatForm()->show(contentLayout);
|
2014-09-02 00:20:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FriendWidget::resetEventFlags()
|
|
|
|
{
|
|
|
|
Friend* f = FriendList::findFriend(friendId);
|
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
|
|
|
|
|
|
|
void FriendWidget::onAvatarChange(int FriendId, const QPixmap& pic)
|
|
|
|
{
|
|
|
|
if (FriendId != friendId)
|
|
|
|
return;
|
|
|
|
|
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
|
|
|
|
2014-09-27 03:23:20 +08:00
|
|
|
void FriendWidget::onAvatarRemoved(int FriendId)
|
|
|
|
{
|
|
|
|
if (FriendId != friendId)
|
|
|
|
return;
|
|
|
|
|
|
|
|
isDefaultAvatar = true;
|
2014-10-05 20:22:28 +08:00
|
|
|
|
|
|
|
if (isActive())
|
2016-01-21 11:47:26 +08:00
|
|
|
avatar->setPixmap(QPixmap(":/img/contact_dark.svg"));
|
2014-10-05 20:22:28 +08:00
|
|
|
else
|
2016-01-21 11:47:26 +08:00
|
|
|
avatar->setPixmap(QPixmap(":/img/contact.svg"));
|
2014-09-27 03:23:20 +08:00
|
|
|
}
|
|
|
|
|
2014-09-26 00:03:25 +08:00
|
|
|
void FriendWidget::mousePressEvent(QMouseEvent *ev)
|
|
|
|
{
|
|
|
|
if (ev->button() == Qt::LeftButton)
|
|
|
|
dragStartPos = ev->pos();
|
2015-06-07 06:33:03 +08:00
|
|
|
|
|
|
|
GenericChatroomWidget::mousePressEvent(ev);
|
2014-09-26 00:03:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FriendWidget::mouseMoveEvent(QMouseEvent *ev)
|
|
|
|
{
|
|
|
|
if (!(ev->buttons() & Qt::LeftButton))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((dragStartPos - ev->pos()).manhattanLength() > QApplication::startDragDistance())
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2015-06-02 02:39:40 +08:00
|
|
|
QString alias = _alias.left(128); // same as TOX_MAX_NAME_LENGTH
|
2014-11-18 10:15:44 +08:00
|
|
|
Friend* f = FriendList::findFriend(friendId);
|
|
|
|
f->setAlias(alias);
|
2016-12-30 06:14:48 +08:00
|
|
|
Settings::getInstance().setFriendAlias(f->getPublicKey(), alias);
|
2015-06-06 21:54:58 +08:00
|
|
|
Settings::getInstance().savePersonal();
|
2014-11-18 10:15:44 +08:00
|
|
|
}
|