mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge branch 'pr662'
This commit is contained in:
commit
345fbc07ea
18
src/core.cpp
18
src/core.cpp
@ -722,18 +722,7 @@ void Core::requestFriendship(const QString& friendAddress, const QString& messag
|
|||||||
emit failedToAddFriend(userId);
|
emit failedToAddFriend(userId);
|
||||||
} else {
|
} else {
|
||||||
// Update our friendAddresses
|
// Update our friendAddresses
|
||||||
bool found=false;
|
Settings::getInstance().updateFriendAdress(friendAddress);
|
||||||
QList<QString>& friendAddresses = Settings::getInstance().friendAddresses;
|
|
||||||
for (QString& addr : friendAddresses)
|
|
||||||
{
|
|
||||||
if (addr.toUpper().contains(friendAddress))
|
|
||||||
{
|
|
||||||
addr = friendAddress;
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found)
|
|
||||||
friendAddresses.append(friendAddress);
|
|
||||||
emit friendAdded(friendId, userId);
|
emit friendAdded(friendId, userId);
|
||||||
}
|
}
|
||||||
saveConfiguration();
|
saveConfiguration();
|
||||||
@ -1612,9 +1601,8 @@ QString Core::getFriendAddress(int friendNumber) const
|
|||||||
QByteArray data((char*)rawid,TOX_CLIENT_ID_SIZE);
|
QByteArray data((char*)rawid,TOX_CLIENT_ID_SIZE);
|
||||||
QString id = data.toHex().toUpper();
|
QString id = data.toHex().toUpper();
|
||||||
|
|
||||||
QList<QString>& friendAddresses = Settings::getInstance().friendAddresses;
|
QString addr = Settings::getInstance().getFriendAdress(id);
|
||||||
for (QString addr : friendAddresses)
|
if (addr.size() > id.size())
|
||||||
if (addr.toUpper().contains(id))
|
|
||||||
return addr;
|
return addr;
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
|
@ -20,12 +20,14 @@
|
|||||||
#include "widget/form/chatform.h"
|
#include "widget/form/chatform.h"
|
||||||
|
|
||||||
Friend::Friend(int FriendId, QString UserId)
|
Friend::Friend(int FriendId, QString UserId)
|
||||||
: friendId(FriendId), userId(UserId)
|
: friendId(FriendId)
|
||||||
{
|
{
|
||||||
widget = new FriendWidget(friendId, userId);
|
widget = new FriendWidget(friendId, UserId);
|
||||||
chatForm = new ChatForm(this);
|
chatForm = new ChatForm(this);
|
||||||
hasNewEvents = 0;
|
hasNewEvents = 0;
|
||||||
friendStatus = Status::Offline;
|
friendStatus = Status::Offline;
|
||||||
|
userID = ToxID::fromString(UserId);
|
||||||
|
userName = UserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
Friend::~Friend()
|
Friend::~Friend()
|
||||||
@ -35,10 +37,23 @@ Friend::~Friend()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Friend::setName(QString name)
|
void Friend::setName(QString name)
|
||||||
|
{
|
||||||
|
userName = name;
|
||||||
|
if (userAlias.size() == 0)
|
||||||
{
|
{
|
||||||
widget->setName(name);
|
widget->setName(name);
|
||||||
chatForm->setName(name);
|
chatForm->setName(name);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Friend::setAlias(QString name)
|
||||||
|
{
|
||||||
|
userAlias = name;
|
||||||
|
QString dispName = userAlias.size() == 0 ? userName : userAlias;
|
||||||
|
|
||||||
|
widget->setName(dispName);
|
||||||
|
chatForm->setName(dispName);
|
||||||
|
}
|
||||||
|
|
||||||
void Friend::setStatusMessage(QString message)
|
void Friend::setStatusMessage(QString message)
|
||||||
{
|
{
|
||||||
@ -46,12 +61,49 @@ void Friend::setStatusMessage(QString message)
|
|||||||
chatForm->setStatusMessage(message);
|
chatForm->setStatusMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Friend::getName() const
|
QString Friend::getDisplayedName() const
|
||||||
{
|
{
|
||||||
return widget->getName();
|
if (userAlias.size() == 0)
|
||||||
|
return userName;
|
||||||
|
return userAlias;
|
||||||
}
|
}
|
||||||
|
|
||||||
ToxID Friend::getToxID() const
|
const ToxID &Friend::getToxID() const
|
||||||
{
|
{
|
||||||
return ToxID::fromString(userId);
|
return userID;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Friend::getFriendID() const
|
||||||
|
{
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
return chatForm;
|
||||||
|
}
|
||||||
|
|
||||||
|
FriendWidget *Friend::getFriendWidget()
|
||||||
|
{
|
||||||
|
return widget;
|
||||||
}
|
}
|
||||||
|
32
src/friend.h
32
src/friend.h
@ -28,18 +28,34 @@ struct Friend
|
|||||||
public:
|
public:
|
||||||
Friend(int FriendId, QString UserId);
|
Friend(int FriendId, QString UserId);
|
||||||
~Friend();
|
~Friend();
|
||||||
void setName(QString name);
|
|
||||||
void setStatusMessage(QString message);
|
|
||||||
QString getName() const;
|
|
||||||
ToxID getToxID() const;
|
|
||||||
|
|
||||||
public:
|
void setName(QString name);
|
||||||
FriendWidget* widget;
|
void setAlias(QString name);
|
||||||
|
QString getDisplayedName() const;
|
||||||
|
|
||||||
|
void setStatusMessage(QString message);
|
||||||
|
|
||||||
|
void setEventFlag(int f);
|
||||||
|
int getEventFlag() const;
|
||||||
|
|
||||||
|
const ToxID &getToxID() const;
|
||||||
|
int getFriendID() const;
|
||||||
|
|
||||||
|
void setStatus(Status s);
|
||||||
|
Status getStatus() const;
|
||||||
|
|
||||||
|
ChatForm *getChatForm();
|
||||||
|
FriendWidget *getFriendWidget();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString userAlias, userName;
|
||||||
|
ToxID userID;
|
||||||
int friendId;
|
int friendId;
|
||||||
QString userId;
|
|
||||||
ChatForm* chatForm;
|
|
||||||
int hasNewEvents;
|
int hasNewEvents;
|
||||||
Status friendStatus;
|
Status friendStatus;
|
||||||
|
|
||||||
|
FriendWidget* widget;
|
||||||
|
ChatForm* chatForm;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FRIEND_H
|
#endif // FRIEND_H
|
||||||
|
@ -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->friendId == 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->friendId == 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())
|
||||||
|
friendList.erase(f_it);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FriendList::clear()
|
||||||
{
|
{
|
||||||
if (friendList[i]->friendId == friendId)
|
for (auto friendptr : friendList)
|
||||||
|
delete friendptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Friend* FriendList::findFriend(QString userId)
|
||||||
{
|
{
|
||||||
friendList.removeAt(i);
|
auto id = tox2id.find(userId);
|
||||||
return;
|
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
|
||||||
|
@ -92,12 +92,16 @@ void Settings::load()
|
|||||||
useCustomDhtList=false;
|
useCustomDhtList=false;
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
|
||||||
friendAddresses.clear();
|
friendLst.clear();
|
||||||
s.beginGroup("Friends");
|
s.beginGroup("Friends");
|
||||||
int size = s.beginReadArray("fullAddresses");
|
int size = s.beginReadArray("fullAddresses");
|
||||||
for (int i = 0; i < size; i ++) {
|
for (int i = 0; i < size; i ++)
|
||||||
|
{
|
||||||
s.setArrayIndex(i);
|
s.setArrayIndex(i);
|
||||||
friendAddresses.append(s.value("addr").toString());
|
friendProp fp;
|
||||||
|
fp.addr = s.value("addr").toString();
|
||||||
|
fp.alias = s.value("alias").toString();
|
||||||
|
friendLst[ToxID::fromString(fp.addr).publicKey] = fp;
|
||||||
}
|
}
|
||||||
s.endArray();
|
s.endArray();
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
@ -219,10 +223,14 @@ void Settings::save(QString path)
|
|||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
|
||||||
s.beginGroup("Friends");
|
s.beginGroup("Friends");
|
||||||
s.beginWriteArray("fullAddresses", friendAddresses.size());
|
s.beginWriteArray("fullAddresses", friendLst.size());
|
||||||
for (int i = 0; i < friendAddresses.size(); i ++) {
|
int index = 0;
|
||||||
s.setArrayIndex(i);
|
for (auto &frnd : friendLst)
|
||||||
s.setValue("addr", friendAddresses[i]);
|
{
|
||||||
|
s.setArrayIndex(index);
|
||||||
|
s.setValue("addr", frnd.addr);
|
||||||
|
s.setValue("alias", frnd.alias);
|
||||||
|
index++;
|
||||||
}
|
}
|
||||||
s.endArray();
|
s.endArray();
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
@ -760,3 +768,52 @@ void Settings::setOutDev(const QString& deviceSpecifier)
|
|||||||
{
|
{
|
||||||
outDev = deviceSpecifier;
|
outDev = deviceSpecifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Settings::getFriendAdress(const QString &publicKey) const
|
||||||
|
{
|
||||||
|
QString key = ToxID::fromString(publicKey).publicKey;
|
||||||
|
auto it = friendLst.find(key);
|
||||||
|
if (it != friendLst.end())
|
||||||
|
{
|
||||||
|
return it->addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::updateFriendAdress(const QString &newAddr)
|
||||||
|
{
|
||||||
|
QString key = ToxID::fromString(newAddr).publicKey;
|
||||||
|
auto it = friendLst.find(key);
|
||||||
|
if (it != friendLst.end())
|
||||||
|
{
|
||||||
|
it->addr = newAddr;
|
||||||
|
} else {
|
||||||
|
friendProp fp;
|
||||||
|
fp.addr = newAddr;
|
||||||
|
fp.alias = "";
|
||||||
|
friendLst[newAddr] = fp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Settings::getFriendAlias(const ToxID &id) const
|
||||||
|
{
|
||||||
|
QString key = id.publicKey;
|
||||||
|
auto it = friendLst.find(key);
|
||||||
|
if (it != friendLst.end())
|
||||||
|
{
|
||||||
|
return it->alias;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::setFriendAlias(const ToxID &id, const QString &alias)
|
||||||
|
{
|
||||||
|
QString key = id.publicKey;
|
||||||
|
auto it = friendLst.find(key);
|
||||||
|
if (it != friendLst.end())
|
||||||
|
{
|
||||||
|
it->alias = alias;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
|
||||||
|
class ToxID;
|
||||||
|
|
||||||
class Settings : public QObject
|
class Settings : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -185,8 +187,13 @@ public:
|
|||||||
QByteArray getSplitterState() const;
|
QByteArray getSplitterState() const;
|
||||||
void setSplitterState(const QByteArray &value);
|
void setSplitterState(const QByteArray &value);
|
||||||
|
|
||||||
|
QString getFriendAdress(const QString &publicKey) const;
|
||||||
|
void updateFriendAdress(const QString &newAddr);
|
||||||
|
|
||||||
|
QString getFriendAlias(const ToxID &id) const;
|
||||||
|
void setFriendAlias(const ToxID &id, const QString &alias);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QList<QString> friendAddresses;
|
|
||||||
void save();
|
void save();
|
||||||
void save(QString path);
|
void save(QString path);
|
||||||
void load();
|
void load();
|
||||||
@ -258,6 +265,14 @@ private:
|
|||||||
QString inDev;
|
QString inDev;
|
||||||
QString outDev;
|
QString outDev;
|
||||||
|
|
||||||
|
struct friendProp
|
||||||
|
{
|
||||||
|
QString alias;
|
||||||
|
QString addr;
|
||||||
|
};
|
||||||
|
|
||||||
|
QHash<QString, friendProp> friendLst;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
//void dataChanged();
|
//void dataChanged();
|
||||||
void dhtServerListChanged();
|
void dhtServerListChanged();
|
||||||
|
@ -46,7 +46,7 @@ ChatForm::ChatForm(Friend* chatFriend)
|
|||||||
, audioOutputFlag(false)
|
, audioOutputFlag(false)
|
||||||
, callId(0)
|
, callId(0)
|
||||||
{
|
{
|
||||||
nameLabel->setText(f->getName());
|
nameLabel->setText(f->getDisplayedName());
|
||||||
|
|
||||||
avatar->setPixmap(QPixmap(":/img/contact_dark.png"), Qt::transparent);
|
avatar->setPixmap(QPixmap(":/img/contact_dark.png"), Qt::transparent);
|
||||||
|
|
||||||
@ -98,18 +98,18 @@ void ChatForm::onSendTriggered()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QDateTime timestamp = QDateTime::currentDateTime();
|
QDateTime timestamp = QDateTime::currentDateTime();
|
||||||
HistoryKeeper::getInstance()->addChatEntry(f->userId, msg, Core::getInstance()->getSelfId().publicKey, timestamp);
|
HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, msg, Core::getInstance()->getSelfId().publicKey, timestamp);
|
||||||
|
|
||||||
if (msg.startsWith("/me "))
|
if (msg.startsWith("/me "))
|
||||||
{
|
{
|
||||||
msg = msg.right(msg.length() - 4);
|
msg = msg.right(msg.length() - 4);
|
||||||
addSelfMessage(msg, true, timestamp);
|
addSelfMessage(msg, true, timestamp);
|
||||||
emit sendAction(f->friendId, msg);
|
emit sendAction(f->getFriendID(), msg);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
addSelfMessage(msg, false, timestamp);
|
addSelfMessage(msg, false, timestamp);
|
||||||
emit sendMessage(f->friendId, msg);
|
emit sendMessage(f->getFriendID(), msg);
|
||||||
}
|
}
|
||||||
msgEdit->clear();
|
msgEdit->clear();
|
||||||
}
|
}
|
||||||
@ -134,13 +134,13 @@ void ChatForm::onAttachClicked()
|
|||||||
file.close();
|
file.close();
|
||||||
QFileInfo fi(path);
|
QFileInfo fi(path);
|
||||||
|
|
||||||
emit sendFile(f->friendId, fi.fileName(), path, filesize);
|
emit sendFile(f->getFriendID(), fi.fileName(), path, filesize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::startFileSend(ToxFile file)
|
void ChatForm::startFileSend(ToxFile file)
|
||||||
{
|
{
|
||||||
if (file.friendId != f->friendId)
|
if (file.friendId != f->getFriendID())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FileTransferInstance* fileTrans = new FileTransferInstance(file);
|
FileTransferInstance* fileTrans = new FileTransferInstance(file);
|
||||||
@ -168,7 +168,7 @@ void ChatForm::startFileSend(ToxFile file)
|
|||||||
|
|
||||||
void ChatForm::onFileRecvRequest(ToxFile file)
|
void ChatForm::onFileRecvRequest(ToxFile file)
|
||||||
{
|
{
|
||||||
if (file.friendId != f->friendId)
|
if (file.friendId != f->getFriendID())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FileTransferInstance* fileTrans = new FileTransferInstance(file);
|
FileTransferInstance* fileTrans = new FileTransferInstance(file);
|
||||||
@ -186,22 +186,22 @@ void ChatForm::onFileRecvRequest(ToxFile file)
|
|||||||
if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow())
|
if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow())
|
||||||
{
|
{
|
||||||
w->newMessageAlert();
|
w->newMessageAlert();
|
||||||
f->hasNewEvents=true;
|
f->setEventFlag(true);
|
||||||
f->widget->updateStatusLight();
|
f->getFriendWidget()->updateStatusLight();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString name;
|
QString name;
|
||||||
ToxID friendId = f->getToxID();
|
ToxID friendId = f->getToxID();
|
||||||
if (friendId != previousId)
|
if (friendId != previousId)
|
||||||
{
|
{
|
||||||
name = f->getName();
|
name = f->getDisplayedName();
|
||||||
previousId = friendId;
|
previousId = friendId;
|
||||||
}
|
}
|
||||||
|
|
||||||
chatWidget->insertMessage(ChatActionPtr(new FileTransferAction(fileTrans, getElidedName(name),
|
chatWidget->insertMessage(ChatActionPtr(new FileTransferAction(fileTrans, getElidedName(name),
|
||||||
QTime::currentTime().toString("hh:mm"), false)));
|
QTime::currentTime().toString("hh:mm"), false)));
|
||||||
|
|
||||||
if (!Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->friendId)).isEmpty()
|
if (!Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->getFriendID())).isEmpty()
|
||||||
|| Settings::getInstance().getAutoSaveEnabled())
|
|| Settings::getInstance().getAutoSaveEnabled())
|
||||||
fileTrans->pressFromHtml("btnB");
|
fileTrans->pressFromHtml("btnB");
|
||||||
}
|
}
|
||||||
@ -209,7 +209,7 @@ void ChatForm::onFileRecvRequest(ToxFile file)
|
|||||||
void ChatForm::onAvInvite(int FriendId, int CallId, bool video)
|
void ChatForm::onAvInvite(int FriendId, int CallId, bool video)
|
||||||
{
|
{
|
||||||
qDebug() << "onAvInvite";
|
qDebug() << "onAvInvite";
|
||||||
if (FriendId != f->friendId)
|
if (FriendId != f->getFriendID())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
callId = CallId;
|
callId = CallId;
|
||||||
@ -232,21 +232,21 @@ void ChatForm::onAvInvite(int FriendId, int CallId, bool video)
|
|||||||
connect(callButton, SIGNAL(clicked()), this, SLOT(onAnswerCallTriggered()));
|
connect(callButton, SIGNAL(clicked()), this, SLOT(onAnswerCallTriggered()));
|
||||||
}
|
}
|
||||||
|
|
||||||
addSystemInfoMessage(tr("%1 calling").arg(f->getName()), "white", QDateTime::currentDateTime());
|
addSystemInfoMessage(tr("%1 calling").arg(f->getDisplayedName()), "white", QDateTime::currentDateTime());
|
||||||
|
|
||||||
Widget* w = Widget::getInstance();
|
Widget* w = Widget::getInstance();
|
||||||
if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow())
|
if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow())
|
||||||
{
|
{
|
||||||
w->newMessageAlert();
|
w->newMessageAlert();
|
||||||
f->hasNewEvents=true;
|
f->setEventFlag(true);
|
||||||
f->widget->updateStatusLight();
|
f->getFriendWidget()->updateStatusLight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onAvStart(int FriendId, int CallId, bool video)
|
void ChatForm::onAvStart(int FriendId, int CallId, bool video)
|
||||||
{
|
{
|
||||||
qDebug() << "onAvStart";
|
qDebug() << "onAvStart";
|
||||||
if (FriendId != f->friendId)
|
if (FriendId != f->getFriendID())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
audioInputFlag = true;
|
audioInputFlag = true;
|
||||||
@ -263,7 +263,7 @@ void ChatForm::onAvStart(int FriendId, int CallId, bool video)
|
|||||||
videoButton->style()->polish(videoButton);
|
videoButton->style()->polish(videoButton);
|
||||||
connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
|
||||||
|
|
||||||
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getName());
|
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getDisplayedName());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -281,7 +281,7 @@ void ChatForm::onAvCancel(int FriendId, int)
|
|||||||
{
|
{
|
||||||
qDebug() << "onAvCancel";
|
qDebug() << "onAvCancel";
|
||||||
|
|
||||||
if (FriendId != f->friendId)
|
if (FriendId != f->getFriendID())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
audioInputFlag = false;
|
audioInputFlag = false;
|
||||||
@ -301,14 +301,14 @@ void ChatForm::onAvCancel(int FriendId, int)
|
|||||||
|
|
||||||
netcam->hide();
|
netcam->hide();
|
||||||
|
|
||||||
addSystemInfoMessage(tr("%1 stopped calling").arg(f->getName()), "white", QDateTime::currentDateTime());
|
addSystemInfoMessage(tr("%1 stopped calling").arg(f->getDisplayedName()), "white", QDateTime::currentDateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onAvEnd(int FriendId, int)
|
void ChatForm::onAvEnd(int FriendId, int)
|
||||||
{
|
{
|
||||||
qDebug() << "onAvEnd";
|
qDebug() << "onAvEnd";
|
||||||
|
|
||||||
if (FriendId != f->friendId)
|
if (FriendId != f->getFriendID())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
audioInputFlag = false;
|
audioInputFlag = false;
|
||||||
@ -334,7 +334,7 @@ void ChatForm::onAvEnd(int FriendId, int)
|
|||||||
void ChatForm::onAvRinging(int FriendId, int CallId, bool video)
|
void ChatForm::onAvRinging(int FriendId, int CallId, bool video)
|
||||||
{
|
{
|
||||||
qDebug() << "onAvRinging";
|
qDebug() << "onAvRinging";
|
||||||
if (FriendId != f->friendId)
|
if (FriendId != f->getFriendID())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
callId = CallId;
|
callId = CallId;
|
||||||
@ -357,14 +357,14 @@ void ChatForm::onAvRinging(int FriendId, int CallId, bool video)
|
|||||||
connect(callButton, SIGNAL(clicked()), this, SLOT(onCancelCallTriggered()));
|
connect(callButton, SIGNAL(clicked()), this, SLOT(onCancelCallTriggered()));
|
||||||
}
|
}
|
||||||
|
|
||||||
addSystemInfoMessage(tr("Calling to %1").arg(f->getName()), "white", QDateTime::currentDateTime());
|
addSystemInfoMessage(tr("Calling to %1").arg(f->getDisplayedName()), "white", QDateTime::currentDateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onAvStarting(int FriendId, int CallId, bool video)
|
void ChatForm::onAvStarting(int FriendId, int CallId, bool video)
|
||||||
{
|
{
|
||||||
qDebug() << "onAvStarting";
|
qDebug() << "onAvStarting";
|
||||||
|
|
||||||
if (FriendId != f->friendId)
|
if (FriendId != f->getFriendID())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
callButton->disconnect();
|
callButton->disconnect();
|
||||||
@ -377,7 +377,7 @@ void ChatForm::onAvStarting(int FriendId, int CallId, bool video)
|
|||||||
videoButton->style()->polish(videoButton);
|
videoButton->style()->polish(videoButton);
|
||||||
connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
|
||||||
|
|
||||||
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getName());
|
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getDisplayedName());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -395,7 +395,7 @@ void ChatForm::onAvEnding(int FriendId, int)
|
|||||||
{
|
{
|
||||||
qDebug() << "onAvEnding";
|
qDebug() << "onAvEnding";
|
||||||
|
|
||||||
if (FriendId != f->friendId)
|
if (FriendId != f->getFriendID())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
audioInputFlag = false;
|
audioInputFlag = false;
|
||||||
@ -424,7 +424,7 @@ void ChatForm::onAvRequestTimeout(int FriendId, int)
|
|||||||
{
|
{
|
||||||
qDebug() << "onAvRequestTimeout";
|
qDebug() << "onAvRequestTimeout";
|
||||||
|
|
||||||
if (FriendId != f->friendId)
|
if (FriendId != f->getFriendID())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
audioInputFlag = false;
|
audioInputFlag = false;
|
||||||
@ -451,7 +451,7 @@ void ChatForm::onAvPeerTimeout(int FriendId, int)
|
|||||||
{
|
{
|
||||||
qDebug() << "onAvPeerTimeout";
|
qDebug() << "onAvPeerTimeout";
|
||||||
|
|
||||||
if (FriendId != f->friendId)
|
if (FriendId != f->getFriendID())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
audioInputFlag = false;
|
audioInputFlag = false;
|
||||||
@ -478,7 +478,7 @@ void ChatForm::onAvRejected(int FriendId, int)
|
|||||||
{
|
{
|
||||||
qDebug() << "onAvRejected";
|
qDebug() << "onAvRejected";
|
||||||
|
|
||||||
if (FriendId != f->friendId)
|
if (FriendId != f->getFriendID())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
audioInputFlag = false;
|
audioInputFlag = false;
|
||||||
@ -507,12 +507,12 @@ void ChatForm::onAvMediaChange(int FriendId, int CallId, bool video)
|
|||||||
{
|
{
|
||||||
qDebug() << "onAvMediaChange";
|
qDebug() << "onAvMediaChange";
|
||||||
|
|
||||||
if (FriendId != f->friendId || CallId != callId)
|
if (FriendId != f->getFriendID() || CallId != callId)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (video)
|
if (video)
|
||||||
{
|
{
|
||||||
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getName());
|
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getDisplayedName());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -550,7 +550,7 @@ void ChatForm::onCallTriggered()
|
|||||||
audioOutputFlag = true;
|
audioOutputFlag = true;
|
||||||
callButton->disconnect();
|
callButton->disconnect();
|
||||||
videoButton->disconnect();
|
videoButton->disconnect();
|
||||||
emit startCall(f->friendId);
|
emit startCall(f->getFriendID());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onVideoCallTriggered()
|
void ChatForm::onVideoCallTriggered()
|
||||||
@ -561,14 +561,14 @@ void ChatForm::onVideoCallTriggered()
|
|||||||
audioOutputFlag = true;
|
audioOutputFlag = true;
|
||||||
callButton->disconnect();
|
callButton->disconnect();
|
||||||
videoButton->disconnect();
|
videoButton->disconnect();
|
||||||
emit startVideoCall(f->friendId, true);
|
emit startVideoCall(f->getFriendID(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onAvCallFailed(int FriendId)
|
void ChatForm::onAvCallFailed(int FriendId)
|
||||||
{
|
{
|
||||||
qDebug() << "onAvCallFailed";
|
qDebug() << "onAvCallFailed";
|
||||||
|
|
||||||
if (FriendId != f->friendId)
|
if (FriendId != f->getFriendID())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
audioInputFlag = false;
|
audioInputFlag = false;
|
||||||
@ -601,7 +601,7 @@ void ChatForm::onCancelCallTriggered()
|
|||||||
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
||||||
|
|
||||||
netcam->hide();
|
netcam->hide();
|
||||||
emit cancelCall(callId, f->friendId);
|
emit cancelCall(callId, f->getFriendID());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onMicMuteToggle()
|
void ChatForm::onMicMuteToggle()
|
||||||
@ -646,7 +646,7 @@ void ChatForm::onFileTansBtnClicked(QString widgetName, QString buttonName)
|
|||||||
|
|
||||||
void ChatForm::onFileSendFailed(int FriendId, const QString &fname)
|
void ChatForm::onFileSendFailed(int FriendId, const QString &fname)
|
||||||
{
|
{
|
||||||
if (FriendId != f->friendId)
|
if (FriendId != f->getFriendID())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
addSystemInfoMessage("File: \"" + fname + "\" failed to send.", "red", QDateTime::currentDateTime());
|
addSystemInfoMessage("File: \"" + fname + "\" failed to send.", "red", QDateTime::currentDateTime());
|
||||||
@ -654,7 +654,7 @@ void ChatForm::onFileSendFailed(int FriendId, const QString &fname)
|
|||||||
|
|
||||||
void ChatForm::onAvatarChange(int FriendId, const QPixmap &pic)
|
void ChatForm::onAvatarChange(int FriendId, const QPixmap &pic)
|
||||||
{
|
{
|
||||||
if (FriendId != f->friendId)
|
if (FriendId != f->getFriendID())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
avatar->setPixmap(pic);
|
avatar->setPixmap(pic);
|
||||||
@ -675,14 +675,14 @@ void ChatForm::dropEvent(QDropEvent *ev)
|
|||||||
QFileInfo info(url.path());
|
QFileInfo info(url.path());
|
||||||
|
|
||||||
if (info.exists())
|
if (info.exists())
|
||||||
Core::getInstance()->sendFile(f->friendId, info.fileName(), info.absoluteFilePath(), info.size());
|
Core::getInstance()->sendFile(f->getFriendID(), info.fileName(), info.absoluteFilePath(), info.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onAvatarRemoved(int FriendId)
|
void ChatForm::onAvatarRemoved(int FriendId)
|
||||||
{
|
{
|
||||||
if (FriendId != f->friendId)
|
if (FriendId != f->getFriendID())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
avatar->setPixmap(QPixmap(":/img/contact_dark.png"), Qt::transparent);
|
avatar->setPixmap(QPixmap(":/img/contact_dark.png"), Qt::transparent);
|
||||||
@ -711,7 +711,7 @@ void ChatForm::onLoadHistory()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto msgs = HistoryKeeper::getInstance()->getChatHistory(HistoryKeeper::ctSingle, f->userId, fromTime, toTime);
|
auto msgs = HistoryKeeper::getInstance()->getChatHistory(HistoryKeeper::ctSingle, f->getToxID().publicKey, fromTime, toTime);
|
||||||
|
|
||||||
ToxID storedPrevId;
|
ToxID storedPrevId;
|
||||||
std::swap(storedPrevId, previousId);
|
std::swap(storedPrevId, previousId);
|
||||||
@ -752,7 +752,7 @@ void ChatForm::stopCounter()
|
|||||||
{
|
{
|
||||||
if(timer)
|
if(timer)
|
||||||
{
|
{
|
||||||
addSystemInfoMessage(tr("Call with %1 ended. %2").arg(f->getName(),
|
addSystemInfoMessage(tr("Call with %1 ended. %2").arg(f->getDisplayedName(),
|
||||||
secondsToDHMS(timeElapsed.elapsed()/1000)),
|
secondsToDHMS(timeElapsed.elapsed()/1000)),
|
||||||
"white", QDateTime::currentDateTime());
|
"white", QDateTime::currentDateTime());
|
||||||
timer->stop();
|
timer->stop();
|
||||||
|
@ -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();
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "croppinglabel.h"
|
#include "croppinglabel.h"
|
||||||
#include "src/misc/style.h"
|
#include "src/misc/style.h"
|
||||||
#include "src/misc/settings.h"
|
#include "src/misc/settings.h"
|
||||||
|
#include "src/widget/widget.h"
|
||||||
#include <QContextMenuEvent>
|
#include <QContextMenuEvent>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QDrag>
|
#include <QDrag>
|
||||||
@ -34,6 +35,7 @@
|
|||||||
#include <QBitmap>
|
#include <QBitmap>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QInputDialog>
|
||||||
|
|
||||||
FriendWidget::FriendWidget(int FriendId, QString id)
|
FriendWidget::FriendWidget(int FriendId, QString id)
|
||||||
: friendId(FriendId)
|
: friendId(FriendId)
|
||||||
@ -63,6 +65,8 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
|||||||
if (groupActions.isEmpty())
|
if (groupActions.isEmpty())
|
||||||
inviteMenu->setEnabled(false);
|
inviteMenu->setEnabled(false);
|
||||||
|
|
||||||
|
QAction* setAlias = menu.addAction(tr("Set alias..."));
|
||||||
|
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
QAction* autoAccept = menu.addAction(tr("Auto accept files from this friend", "context menu entry"));
|
QAction* autoAccept = menu.addAction(tr("Auto accept files from this friend", "context menu entry"));
|
||||||
autoAccept->setCheckable(true);
|
autoAccept->setCheckable(true);
|
||||||
@ -78,6 +82,9 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
|||||||
{
|
{
|
||||||
emit copyFriendIdToClipboard(friendId);
|
emit copyFriendIdToClipboard(friendId);
|
||||||
return;
|
return;
|
||||||
|
} else if (selectedItem == setAlias)
|
||||||
|
{
|
||||||
|
setFriendAlias();
|
||||||
}
|
}
|
||||||
else if (selectedItem == removeFriendAction)
|
else if (selectedItem == removeFriendAction)
|
||||||
{
|
{
|
||||||
@ -132,36 +139,36 @@ void FriendWidget::setAsInactiveChatroom()
|
|||||||
void FriendWidget::updateStatusLight()
|
void FriendWidget::updateStatusLight()
|
||||||
{
|
{
|
||||||
Friend* f = FriendList::findFriend(friendId);
|
Friend* f = FriendList::findFriend(friendId);
|
||||||
Status status = f->friendStatus;
|
Status status = f->getStatus();
|
||||||
|
|
||||||
if (status == Status::Online && f->hasNewEvents == 0)
|
if (status == Status::Online && f->getEventFlag() == 0)
|
||||||
statusPic.setPixmap(QPixmap(":img/status/dot_online.png"));
|
statusPic.setPixmap(QPixmap(":img/status/dot_online.png"));
|
||||||
else if (status == Status::Online && f->hasNewEvents == 1)
|
else if (status == Status::Online && f->getEventFlag() == 1)
|
||||||
statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
|
statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
|
||||||
else if (status == Status::Away && f->hasNewEvents == 0)
|
else if (status == Status::Away && f->getEventFlag() == 0)
|
||||||
statusPic.setPixmap(QPixmap(":img/status/dot_idle.png"));
|
statusPic.setPixmap(QPixmap(":img/status/dot_idle.png"));
|
||||||
else if (status == Status::Away && f->hasNewEvents == 1)
|
else if (status == Status::Away && f->getEventFlag() == 1)
|
||||||
statusPic.setPixmap(QPixmap(":img/status/dot_idle_notification.png"));
|
statusPic.setPixmap(QPixmap(":img/status/dot_idle_notification.png"));
|
||||||
else if (status == Status::Busy && f->hasNewEvents == 0)
|
else if (status == Status::Busy && f->getEventFlag() == 0)
|
||||||
statusPic.setPixmap(QPixmap(":img/status/dot_busy.png"));
|
statusPic.setPixmap(QPixmap(":img/status/dot_busy.png"));
|
||||||
else if (status == Status::Busy && f->hasNewEvents == 1)
|
else if (status == Status::Busy && f->getEventFlag() == 1)
|
||||||
statusPic.setPixmap(QPixmap(":img/status/dot_busy_notification.png"));
|
statusPic.setPixmap(QPixmap(":img/status/dot_busy_notification.png"));
|
||||||
else if (status == Status::Offline && f->hasNewEvents == 0)
|
else if (status == Status::Offline && f->getEventFlag() == 0)
|
||||||
statusPic.setPixmap(QPixmap(":img/status/dot_away.png"));
|
statusPic.setPixmap(QPixmap(":img/status/dot_away.png"));
|
||||||
else if (status == Status::Offline && f->hasNewEvents == 1)
|
else if (status == Status::Offline && f->getEventFlag() == 1)
|
||||||
statusPic.setPixmap(QPixmap(":img/status/dot_away_notification.png"));
|
statusPic.setPixmap(QPixmap(":img/status/dot_away_notification.png"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendWidget::setChatForm(Ui::MainWindow &ui)
|
void FriendWidget::setChatForm(Ui::MainWindow &ui)
|
||||||
{
|
{
|
||||||
Friend* f = FriendList::findFriend(friendId);
|
Friend* f = FriendList::findFriend(friendId);
|
||||||
f->chatForm->show(ui);
|
f->getChatForm()->show(ui);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendWidget::resetEventFlags()
|
void FriendWidget::resetEventFlags()
|
||||||
{
|
{
|
||||||
Friend* f = FriendList::findFriend(friendId);
|
Friend* f = FriendList::findFriend(friendId);
|
||||||
f->hasNewEvents = 0;
|
f->setEventFlag(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendWidget::onAvatarChange(int FriendId, const QPixmap& pic)
|
void FriendWidget::onAvatarChange(int FriendId, const QPixmap& pic)
|
||||||
@ -210,3 +217,26 @@ void FriendWidget::mouseMoveEvent(QMouseEvent *ev)
|
|||||||
drag->exec(Qt::CopyAction | Qt::MoveAction);
|
drag->exec(Qt::CopyAction | Qt::MoveAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FriendWidget::setFriendAlias()
|
||||||
|
{
|
||||||
|
bool ok;
|
||||||
|
Friend* f = FriendList::findFriend(friendId);
|
||||||
|
|
||||||
|
QString alias = QInputDialog::getText(nullptr, tr("User alias"), tr("Alias:"), QLineEdit::Normal,
|
||||||
|
f->getDisplayedName(), &ok);
|
||||||
|
|
||||||
|
if (ok)
|
||||||
|
{
|
||||||
|
alias = alias.trimmed();
|
||||||
|
alias.remove(QRegExp("[\t\n\v\f\r]"));
|
||||||
|
alias = alias.left(128); // same as TOX_MAX_NAME_LENGTH
|
||||||
|
f->setAlias(alias);
|
||||||
|
Settings::getInstance().setFriendAlias(f->getToxID(), alias);
|
||||||
|
hide();
|
||||||
|
show();
|
||||||
|
|
||||||
|
if (f->getFriendWidget()->isActive())
|
||||||
|
Widget::getInstance()->setWindowTitle(f->getFriendWidget()->getName() + " - qTox");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -48,6 +48,7 @@ public slots:
|
|||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent* ev);
|
void mousePressEvent(QMouseEvent* ev);
|
||||||
void mouseMoveEvent(QMouseEvent* ev);
|
void mouseMoveEvent(QMouseEvent* ev);
|
||||||
|
void setFriendAlias();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int friendId;
|
int friendId;
|
||||||
|
@ -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();
|
||||||
@ -603,46 +601,50 @@ void Widget::addFriend(int friendId, const QString &userId)
|
|||||||
//qDebug() << "Widget: Adding friend with id" << userId;
|
//qDebug() << "Widget: Adding friend with id" << 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->widget);
|
layout->addWidget(newfriend->getFriendWidget());
|
||||||
connect(newfriend->widget, SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
|
|
||||||
connect(newfriend->widget, SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
|
QString alias = Settings::getInstance().getFriendAlias(ToxID::fromString(userId));
|
||||||
connect(newfriend->widget, SIGNAL(copyFriendIdToClipboard(int)), this, SLOT(copyFriendIdToClipboard(int)));
|
newfriend->setAlias(alias);
|
||||||
connect(newfriend->widget, SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), newfriend->chatForm, SLOT(focusInput()));
|
|
||||||
connect(newfriend->chatForm, SIGNAL(sendMessage(int,QString)), core, SLOT(sendMessage(int,QString)));
|
connect(newfriend->getFriendWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
|
||||||
connect(newfriend->chatForm, &GenericChatForm::sendAction, core, &Core::sendAction);
|
connect(newfriend->getFriendWidget(), SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
|
||||||
connect(newfriend->chatForm, SIGNAL(sendFile(int32_t, QString, QString, long long)), core, SLOT(sendFile(int32_t, QString, QString, long long)));
|
connect(newfriend->getFriendWidget(), SIGNAL(copyFriendIdToClipboard(int)), this, SLOT(copyFriendIdToClipboard(int)));
|
||||||
connect(newfriend->chatForm, SIGNAL(answerCall(int)), core, SLOT(answerCall(int)));
|
connect(newfriend->getFriendWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), newfriend->getChatForm(), SLOT(focusInput()));
|
||||||
connect(newfriend->chatForm, SIGNAL(hangupCall(int)), core, SLOT(hangupCall(int)));
|
connect(newfriend->getChatForm(), SIGNAL(sendMessage(int,QString)), core, SLOT(sendMessage(int,QString)));
|
||||||
connect(newfriend->chatForm, SIGNAL(startCall(int)), core, SLOT(startCall(int)));
|
connect(newfriend->getChatForm(), &GenericChatForm::sendAction, core, &Core::sendAction);
|
||||||
connect(newfriend->chatForm, SIGNAL(startVideoCall(int,bool)), core, SLOT(startCall(int,bool)));
|
connect(newfriend->getChatForm(), SIGNAL(sendFile(int32_t, QString, QString, long long)), core, SLOT(sendFile(int32_t, QString, QString, long long)));
|
||||||
connect(newfriend->chatForm, SIGNAL(cancelCall(int,int)), core, SLOT(cancelCall(int,int)));
|
connect(newfriend->getChatForm(), SIGNAL(answerCall(int)), core, SLOT(answerCall(int)));
|
||||||
connect(newfriend->chatForm, SIGNAL(micMuteToggle(int)), core, SLOT(micMuteToggle(int)));
|
connect(newfriend->getChatForm(), SIGNAL(hangupCall(int)), core, SLOT(hangupCall(int)));
|
||||||
connect(newfriend->chatForm, SIGNAL(volMuteToggle(int)), core, SLOT(volMuteToggle(int)));
|
connect(newfriend->getChatForm(), SIGNAL(startCall(int)), core, SLOT(startCall(int)));
|
||||||
connect(core, &Core::fileReceiveRequested, newfriend->chatForm, &ChatForm::onFileRecvRequest);
|
connect(newfriend->getChatForm(), SIGNAL(startVideoCall(int,bool)), core, SLOT(startCall(int,bool)));
|
||||||
connect(core, &Core::avInvite, newfriend->chatForm, &ChatForm::onAvInvite);
|
connect(newfriend->getChatForm(), SIGNAL(cancelCall(int,int)), core, SLOT(cancelCall(int,int)));
|
||||||
connect(core, &Core::avStart, newfriend->chatForm, &ChatForm::onAvStart);
|
connect(newfriend->getChatForm(), SIGNAL(micMuteToggle(int)), core, SLOT(micMuteToggle(int)));
|
||||||
connect(core, &Core::avCancel, newfriend->chatForm, &ChatForm::onAvCancel);
|
connect(newfriend->getChatForm(), SIGNAL(volMuteToggle(int)), core, SLOT(volMuteToggle(int)));
|
||||||
connect(core, &Core::avEnd, newfriend->chatForm, &ChatForm::onAvEnd);
|
connect(core, &Core::fileReceiveRequested, newfriend->getChatForm(), &ChatForm::onFileRecvRequest);
|
||||||
connect(core, &Core::avRinging, newfriend->chatForm, &ChatForm::onAvRinging);
|
connect(core, &Core::avInvite, newfriend->getChatForm(), &ChatForm::onAvInvite);
|
||||||
connect(core, &Core::avStarting, newfriend->chatForm, &ChatForm::onAvStarting);
|
connect(core, &Core::avStart, newfriend->getChatForm(), &ChatForm::onAvStart);
|
||||||
connect(core, &Core::avEnding, newfriend->chatForm, &ChatForm::onAvEnding);
|
connect(core, &Core::avCancel, newfriend->getChatForm(), &ChatForm::onAvCancel);
|
||||||
connect(core, &Core::avRequestTimeout, newfriend->chatForm, &ChatForm::onAvRequestTimeout);
|
connect(core, &Core::avEnd, newfriend->getChatForm(), &ChatForm::onAvEnd);
|
||||||
connect(core, &Core::avPeerTimeout, newfriend->chatForm, &ChatForm::onAvPeerTimeout);
|
connect(core, &Core::avRinging, newfriend->getChatForm(), &ChatForm::onAvRinging);
|
||||||
connect(core, &Core::avMediaChange, newfriend->chatForm, &ChatForm::onAvMediaChange);
|
connect(core, &Core::avStarting, newfriend->getChatForm(), &ChatForm::onAvStarting);
|
||||||
connect(core, &Core::avCallFailed, newfriend->chatForm, &ChatForm::onAvCallFailed);
|
connect(core, &Core::avEnding, newfriend->getChatForm(), &ChatForm::onAvEnding);
|
||||||
connect(core, &Core::avRejected, newfriend->chatForm, &ChatForm::onAvRejected);
|
connect(core, &Core::avRequestTimeout, newfriend->getChatForm(), &ChatForm::onAvRequestTimeout);
|
||||||
connect(core, &Core::friendAvatarChanged, newfriend->chatForm, &ChatForm::onAvatarChange);
|
connect(core, &Core::avPeerTimeout, newfriend->getChatForm(), &ChatForm::onAvPeerTimeout);
|
||||||
connect(core, &Core::friendAvatarChanged, newfriend->widget, &FriendWidget::onAvatarChange);
|
connect(core, &Core::avMediaChange, newfriend->getChatForm(), &ChatForm::onAvMediaChange);
|
||||||
connect(core, &Core::friendAvatarRemoved, newfriend->chatForm, &ChatForm::onAvatarRemoved);
|
connect(core, &Core::avCallFailed, newfriend->getChatForm(), &ChatForm::onAvCallFailed);
|
||||||
connect(core, &Core::friendAvatarRemoved, newfriend->widget, &FriendWidget::onAvatarRemoved);
|
connect(core, &Core::avRejected, newfriend->getChatForm(), &ChatForm::onAvRejected);
|
||||||
|
connect(core, &Core::friendAvatarChanged, newfriend->getChatForm(), &ChatForm::onAvatarChange);
|
||||||
|
connect(core, &Core::friendAvatarChanged, newfriend->getFriendWidget(), &FriendWidget::onAvatarChange);
|
||||||
|
connect(core, &Core::friendAvatarRemoved, newfriend->getChatForm(), &ChatForm::onAvatarRemoved);
|
||||||
|
connect(core, &Core::friendAvatarRemoved, newfriend->getFriendWidget(), &FriendWidget::onAvatarRemoved);
|
||||||
|
|
||||||
// Try to get the avatar from the cache
|
// Try to get the avatar from the cache
|
||||||
QPixmap avatar = Settings::getInstance().getSavedAvatar(userId);
|
QPixmap avatar = Settings::getInstance().getSavedAvatar(userId);
|
||||||
if (!avatar.isNull())
|
if (!avatar.isNull())
|
||||||
{
|
{
|
||||||
//qWarning() << "Widget: loadded avatar for id" << userId;
|
//qWarning() << "Widget: loadded avatar for id" << userId;
|
||||||
newfriend->chatForm->onAvatarChange(friendId, avatar);
|
newfriend->getChatForm()->onAvatarChange(friendId, avatar);
|
||||||
newfriend->widget->onAvatarChange(friendId, avatar);
|
newfriend->getFriendWidget()->onAvatarChange(friendId, avatar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -657,17 +659,17 @@ void Widget::onFriendStatusChanged(int friendId, Status status)
|
|||||||
if (!f)
|
if (!f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
contactListWidget->moveWidget(f->widget, status);
|
contactListWidget->moveWidget(f->getFriendWidget(), status);
|
||||||
|
|
||||||
f->friendStatus = status;
|
f->setStatus(status);
|
||||||
f->widget->updateStatusLight();
|
f->getFriendWidget()->updateStatusLight();
|
||||||
|
|
||||||
//won't print the message if there were no messages before
|
//won't print the message if there were no messages before
|
||||||
if(f->chatForm->getNumberOfMessages() != 0
|
if(f->getChatForm()->getNumberOfMessages() != 0
|
||||||
&& Settings::getInstance().getStatusChangeNotificationEnabled() == true)
|
&& Settings::getInstance().getStatusChangeNotificationEnabled() == true)
|
||||||
{
|
{
|
||||||
QString fStatus = "";
|
QString fStatus = "";
|
||||||
switch(f->friendStatus){
|
switch(f->getStatus()){
|
||||||
case Status::Away:
|
case Status::Away:
|
||||||
fStatus = tr("away", "contact status"); break;
|
fStatus = tr("away", "contact status"); break;
|
||||||
case Status::Busy:
|
case Status::Busy:
|
||||||
@ -677,7 +679,7 @@ void Widget::onFriendStatusChanged(int friendId, Status status)
|
|||||||
default:
|
default:
|
||||||
fStatus = tr("online", "contact status"); break;
|
fStatus = tr("online", "contact status"); break;
|
||||||
}
|
}
|
||||||
f->chatForm->addSystemInfoMessage(tr("%1 is now %2", "e.g. \"Dubslow is now online\"").arg(f->getName()).arg(fStatus),
|
f->getChatForm()->addSystemInfoMessage(tr("%1 is now %2", "e.g. \"Dubslow is now online\"").arg(f->getDisplayedName()).arg(fStatus),
|
||||||
"white", QDateTime::currentDateTime());
|
"white", QDateTime::currentDateTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -726,28 +728,28 @@ void Widget::onFriendMessageReceived(int friendId, const QString& message, bool
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QDateTime timestamp = QDateTime::currentDateTime();
|
QDateTime timestamp = QDateTime::currentDateTime();
|
||||||
f->chatForm->addMessage(f->getToxID(), message, isAction, timestamp);
|
f->getChatForm()->addMessage(f->getToxID(), message, isAction, timestamp);
|
||||||
|
|
||||||
if (isAction)
|
if (isAction)
|
||||||
HistoryKeeper::getInstance()->addChatEntry(f->userId, "/me " + message, f->userId, timestamp);
|
HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, "/me " + message, f->getToxID().publicKey, timestamp);
|
||||||
else
|
else
|
||||||
HistoryKeeper::getInstance()->addChatEntry(f->userId, message, f->userId, timestamp);
|
HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, message, f->getToxID().publicKey, timestamp);
|
||||||
|
|
||||||
if (activeChatroomWidget != nullptr)
|
if (activeChatroomWidget != nullptr)
|
||||||
{
|
{
|
||||||
if ((static_cast<GenericChatroomWidget*>(f->widget) != activeChatroomWidget) || isMinimized() || !isActiveWindow())
|
if ((static_cast<GenericChatroomWidget*>(f->getFriendWidget()) != activeChatroomWidget) || isMinimized() || !isActiveWindow())
|
||||||
{
|
{
|
||||||
f->hasNewEvents = 1;
|
f->setEventFlag(true);
|
||||||
newMessageAlert();
|
newMessageAlert();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
f->hasNewEvents = 1;
|
f->setEventFlag(true);
|
||||||
newMessageAlert();
|
newMessageAlert();
|
||||||
}
|
}
|
||||||
|
|
||||||
f->widget->updateStatusLight();
|
f->getFriendWidget()->updateStatusLight();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::newMessageAlert()
|
void Widget::newMessageAlert()
|
||||||
@ -800,11 +802,11 @@ void Widget::onFriendRequestReceived(const QString& userId, const QString& messa
|
|||||||
|
|
||||||
void Widget::removeFriend(Friend* f)
|
void Widget::removeFriend(Friend* f)
|
||||||
{
|
{
|
||||||
f->widget->setAsInactiveChatroom();
|
f->getFriendWidget()->setAsInactiveChatroom();
|
||||||
if (static_cast<GenericChatroomWidget*>(f->widget) == activeChatroomWidget)
|
if (static_cast<GenericChatroomWidget*>(f->getFriendWidget()) == activeChatroomWidget)
|
||||||
activeChatroomWidget = nullptr;
|
activeChatroomWidget = nullptr;
|
||||||
FriendList::removeFriend(f->friendId);
|
FriendList::removeFriend(f->getFriendID());
|
||||||
core->removeFriend(f->friendId);
|
core->removeFriend(f->getFriendID());
|
||||||
delete f;
|
delete f;
|
||||||
if (ui->mainHead->layout()->isEmpty())
|
if (ui->mainHead->layout()->isEmpty())
|
||||||
onAddClicked();
|
onAddClicked();
|
||||||
@ -820,7 +822,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);
|
||||||
@ -832,7 +835,7 @@ void Widget::copyFriendIdToClipboard(int friendId)
|
|||||||
if (f != nullptr)
|
if (f != nullptr)
|
||||||
{
|
{
|
||||||
QClipboard *clipboard = QApplication::clipboard();
|
QClipboard *clipboard = QApplication::clipboard();
|
||||||
clipboard->setText(core->getFriendAddress(f->friendId), QClipboard::Clipboard);
|
clipboard->setText(core->getFriendAddress(f->getFriendID()), QClipboard::Clipboard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -962,7 +965,7 @@ bool Widget::isFriendWidgetCurActiveWidget(Friend* f)
|
|||||||
if (!f)
|
if (!f)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return (activeChatroomWidget == static_cast<GenericChatroomWidget*>(f->widget));
|
return (activeChatroomWidget == static_cast<GenericChatroomWidget*>(f->getFriendWidget()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Widget::event(QEvent * e)
|
bool Widget::event(QEvent * e)
|
||||||
@ -1033,7 +1036,7 @@ void Widget::onMessageSendResult(int friendId, const QString& message, int messa
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (!messageId)
|
if (!messageId)
|
||||||
f->chatForm->addSystemInfoMessage(tr("Message failed to send"), "red", QDateTime::currentDateTime());
|
f->getChatForm()->addSystemInfoMessage(tr("Message failed to send"), "red", QDateTime::currentDateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::onGroupSendResult(int groupId, const QString& message, int result)
|
void Widget::onGroupSendResult(int groupId, const QString& message, int result)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user