mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
possiblity to setup alias
This commit is contained in:
parent
b316f6e13f
commit
af8df8e707
|
@ -18,35 +18,65 @@
|
||||||
#include "friendlist.h"
|
#include "friendlist.h"
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QHash>
|
||||||
|
|
||||||
QList<Friend*> FriendList::friendList;
|
QHash<int, Friend*> FriendList::friendList;
|
||||||
|
QHash<QString, int> FriendList::tox2id;
|
||||||
|
|
||||||
Friend* FriendList::addFriend(int friendId, const QString& userId)
|
Friend* FriendList::addFriend(int friendId, const QString& userId)
|
||||||
{
|
{
|
||||||
for (Friend* f : friendList)
|
auto friendChecker = friendList.find(friendId);
|
||||||
if (f->getFriendID() == friendId)
|
if (friendChecker != friendList.end())
|
||||||
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[friendId] = newfriend;
|
||||||
|
tox2id[userId] = friendId;
|
||||||
|
|
||||||
return newfriend;
|
return newfriend;
|
||||||
}
|
}
|
||||||
|
|
||||||
Friend* FriendList::findFriend(int friendId)
|
Friend* FriendList::findFriend(int friendId)
|
||||||
{
|
{
|
||||||
for (Friend* f : friendList)
|
auto f_it = friendList.find(friendId);
|
||||||
if (f->getFriendID() == friendId)
|
if (f_it != friendList.end())
|
||||||
return f;
|
return *f_it;
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendList::removeFriend(int friendId)
|
void FriendList::removeFriend(int friendId)
|
||||||
{
|
{
|
||||||
for (int i=0; i<friendList.size(); i++)
|
auto f_it = friendList.find(friendId);
|
||||||
{
|
if (f_it != friendList.end())
|
||||||
if (friendList[i]->getFriendID() == friendId)
|
friendList.erase(f_it);
|
||||||
{
|
}
|
||||||
friendList.removeAt(i);
|
|
||||||
return;
|
void FriendList::clear()
|
||||||
}
|
{
|
||||||
}
|
for (auto friendptr : friendList)
|
||||||
|
delete friendptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Friend* FriendList::findFriend(QString userId)
|
||||||
|
{
|
||||||
|
auto id = tox2id.find(userId);
|
||||||
|
if (id != tox2id.end())
|
||||||
|
{
|
||||||
|
Friend *f = findFriend(*id);
|
||||||
|
if (f->getToxID() == ToxID::fromString(userId))
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<Friend*> FriendList::getAllFriends()
|
||||||
|
{
|
||||||
|
QList<Friend*> res;
|
||||||
|
|
||||||
|
for (auto it : friendList)
|
||||||
|
res.append(it);
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#define FRIENDLIST_H
|
#define FRIENDLIST_H
|
||||||
|
|
||||||
template <class T> class QList;
|
template <class T> class QList;
|
||||||
|
template <class A, class B> class QHash;
|
||||||
struct Friend;
|
struct Friend;
|
||||||
class QString;
|
class QString;
|
||||||
|
|
||||||
|
@ -27,10 +28,14 @@ public:
|
||||||
FriendList();
|
FriendList();
|
||||||
static Friend* addFriend(int friendId, const QString& userId);
|
static Friend* addFriend(int friendId, const QString& userId);
|
||||||
static Friend* findFriend(int friendId);
|
static Friend* findFriend(int friendId);
|
||||||
|
static Friend* findFriend(QString userId);
|
||||||
|
static QList<Friend*> getAllFriends();
|
||||||
static void removeFriend(int friendId);
|
static void removeFriend(int friendId);
|
||||||
|
static void clear();
|
||||||
|
|
||||||
public:
|
private:
|
||||||
static QList<Friend*> friendList;
|
static QHash<int, Friend*> friendList;
|
||||||
|
static QHash<QString, int> tox2id;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FRIENDLIST_H
|
#endif // FRIENDLIST_H
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
#include "src/widget/tool/chattextedit.h"
|
#include "src/widget/tool/chattextedit.h"
|
||||||
#include "src/widget/maskablepixmapwidget.h"
|
#include "src/widget/maskablepixmapwidget.h"
|
||||||
#include "src/core.h"
|
#include "src/core.h"
|
||||||
|
#include "src/friendlist.h"
|
||||||
|
#include "src/friend.h"
|
||||||
|
|
||||||
GenericChatForm::GenericChatForm(QWidget *parent) :
|
GenericChatForm::GenericChatForm(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
|
@ -342,8 +344,13 @@ ChatActionPtr GenericChatForm::genMessageActionAction(const ToxID& author, QStri
|
||||||
QString authorStr;
|
QString authorStr;
|
||||||
if (isMe)
|
if (isMe)
|
||||||
authorStr = core->getUsername();
|
authorStr = core->getUsername();
|
||||||
|
else {
|
||||||
|
Friend *f = FriendList::findFriend(author.publicKey);
|
||||||
|
if (f)
|
||||||
|
authorStr = f->getDisplayedName();
|
||||||
else
|
else
|
||||||
authorStr = core->getPeerName(author);
|
authorStr = core->getPeerName(author);
|
||||||
|
}
|
||||||
|
|
||||||
if (authorStr.isEmpty()) // Fallback if we can't find a username
|
if (authorStr.isEmpty()) // Fallback if we can't find a username
|
||||||
authorStr = author.toString();
|
authorStr = author.toString();
|
||||||
|
|
|
@ -42,6 +42,10 @@ FriendWidget::FriendWidget(int FriendId, QString id)
|
||||||
avatar->setPixmap(QPixmap(":img/contact.png"), Qt::transparent);
|
avatar->setPixmap(QPixmap(":img/contact.png"), Qt::transparent);
|
||||||
statusPic.setPixmap(QPixmap(":img/status/dot_away.png"));
|
statusPic.setPixmap(QPixmap(":img/status/dot_away.png"));
|
||||||
nameLabel->setText(id);
|
nameLabel->setText(id);
|
||||||
|
nameLabel->setAttribute(Qt::WA_NoMousePropagation);
|
||||||
|
nameLabel->setEditable(true);
|
||||||
|
|
||||||
|
connect(nameLabel, SIGNAL(textChanged(QString,QString)), this, SLOT(onFriendAliasChange(QString,QString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||||
|
@ -210,3 +214,9 @@ void FriendWidget::mouseMoveEvent(QMouseEvent *ev)
|
||||||
drag->exec(Qt::CopyAction | Qt::MoveAction);
|
drag->exec(Qt::CopyAction | Qt::MoveAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FriendWidget::onFriendAliasChange(QString newText, QString)
|
||||||
|
{
|
||||||
|
Friend* f = FriendList::findFriend(friendId);
|
||||||
|
f->setAlias(newText);
|
||||||
|
}
|
||||||
|
|
|
@ -45,6 +45,9 @@ public slots:
|
||||||
void onAvatarChange(int FriendId, const QPixmap& pic);
|
void onAvatarChange(int FriendId, const QPixmap& pic);
|
||||||
void onAvatarRemoved(int FriendId);
|
void onAvatarRemoved(int FriendId);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onFriendAliasChange(QString newText, QString oldText);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent* ev);
|
void mousePressEvent(QMouseEvent* ev);
|
||||||
void mouseMoveEvent(QMouseEvent* ev);
|
void mouseMoveEvent(QMouseEvent* ev);
|
||||||
|
|
|
@ -276,9 +276,7 @@ Widget::~Widget()
|
||||||
delete addFriendForm;
|
delete addFriendForm;
|
||||||
delete filesForm;
|
delete filesForm;
|
||||||
|
|
||||||
for (Friend* f : FriendList::friendList)
|
FriendList::clear();
|
||||||
delete f;
|
|
||||||
FriendList::friendList.clear();
|
|
||||||
for (Group* g : GroupList::groupList)
|
for (Group* g : GroupList::groupList)
|
||||||
delete g;
|
delete g;
|
||||||
GroupList::groupList.clear();
|
GroupList::groupList.clear();
|
||||||
|
@ -604,6 +602,9 @@ void Widget::addFriend(int friendId, const QString &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->getFriendWidget());
|
layout->addWidget(newfriend->getFriendWidget());
|
||||||
|
|
||||||
|
newfriend->setAlias("");
|
||||||
|
|
||||||
connect(newfriend->getFriendWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
|
connect(newfriend->getFriendWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
|
||||||
connect(newfriend->getFriendWidget(), SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
|
connect(newfriend->getFriendWidget(), SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
|
||||||
connect(newfriend->getFriendWidget(), SIGNAL(copyFriendIdToClipboard(int)), this, SLOT(copyFriendIdToClipboard(int)));
|
connect(newfriend->getFriendWidget(), SIGNAL(copyFriendIdToClipboard(int)), this, SLOT(copyFriendIdToClipboard(int)));
|
||||||
|
@ -820,7 +821,8 @@ void Widget::removeFriend(int friendId)
|
||||||
|
|
||||||
void Widget::clearContactsList()
|
void Widget::clearContactsList()
|
||||||
{
|
{
|
||||||
for (Friend* f : FriendList::friendList)
|
QList<Friend*> friends = FriendList::getAllFriends();
|
||||||
|
for (Friend* f : friends)
|
||||||
removeFriend(f);
|
removeFriend(f);
|
||||||
for (Group* g : GroupList::groupList)
|
for (Group* g : GroupList::groupList)
|
||||||
removeGroup(g);
|
removeGroup(g);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user