1
0
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:
Tux3 / Mlkj / !Lev.uXFMLA 2014-11-07 22:21:08 +01:00
commit 345fbc07ea
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
12 changed files with 373 additions and 169 deletions

View File

@ -722,18 +722,7 @@ void Core::requestFriendship(const QString& friendAddress, const QString& messag
emit failedToAddFriend(userId);
} else {
// Update our friendAddresses
bool found=false;
QList<QString>& friendAddresses = Settings::getInstance().friendAddresses;
for (QString& addr : friendAddresses)
{
if (addr.toUpper().contains(friendAddress))
{
addr = friendAddress;
found = true;
}
}
if (!found)
friendAddresses.append(friendAddress);
Settings::getInstance().updateFriendAdress(friendAddress);
emit friendAdded(friendId, userId);
}
saveConfiguration();
@ -1612,10 +1601,9 @@ QString Core::getFriendAddress(int friendNumber) const
QByteArray data((char*)rawid,TOX_CLIENT_ID_SIZE);
QString id = data.toHex().toUpper();
QList<QString>& friendAddresses = Settings::getInstance().friendAddresses;
for (QString addr : friendAddresses)
if (addr.toUpper().contains(id))
return addr;
QString addr = Settings::getInstance().getFriendAdress(id);
if (addr.size() > id.size())
return addr;
return id;
}

View File

@ -20,12 +20,14 @@
#include "widget/form/chatform.h"
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);
hasNewEvents = 0;
friendStatus = Status::Offline;
userID = ToxID::fromString(UserId);
userName = UserId;
}
Friend::~Friend()
@ -36,8 +38,21 @@ Friend::~Friend()
void Friend::setName(QString name)
{
widget->setName(name);
chatForm->setName(name);
userName = name;
if (userAlias.size() == 0)
{
widget->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)
@ -46,12 +61,49 @@ void Friend::setStatusMessage(QString 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;
}

View File

@ -28,18 +28,34 @@ struct Friend
public:
Friend(int FriendId, QString UserId);
~Friend();
void setName(QString name);
void setStatusMessage(QString message);
QString getName() const;
ToxID getToxID() const;
public:
FriendWidget* widget;
void setName(QString name);
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;
QString userId;
ChatForm* chatForm;
int hasNewEvents;
Status friendStatus;
FriendWidget* widget;
ChatForm* chatForm;
};
#endif // FRIEND_H

View File

@ -18,35 +18,65 @@
#include "friendlist.h"
#include <QMenu>
#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)
{
for (Friend* f : friendList)
if (f->friendId == friendId)
qWarning() << "FriendList::addFriend: friendId already taken";
auto friendChecker = friendList.find(friendId);
if (friendChecker != friendList.end())
qWarning() << "FriendList::addFriend: friendId already taken";
Friend* newfriend = new Friend(friendId, userId);
friendList.append(newfriend);
friendList[friendId] = newfriend;
tox2id[userId] = friendId;
return newfriend;
}
Friend* FriendList::findFriend(int friendId)
{
for (Friend* f : friendList)
if (f->friendId == friendId)
return f;
auto f_it = friendList.find(friendId);
if (f_it != friendList.end())
return *f_it;
return nullptr;
}
void FriendList::removeFriend(int friendId)
{
for (int i=0; i<friendList.size(); i++)
{
if (friendList[i]->friendId == friendId)
{
friendList.removeAt(i);
return;
}
}
auto f_it = friendList.find(friendId);
if (f_it != friendList.end())
friendList.erase(f_it);
}
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;
}

View File

@ -18,6 +18,7 @@
#define FRIENDLIST_H
template <class T> class QList;
template <class A, class B> class QHash;
struct Friend;
class QString;
@ -27,10 +28,14 @@ public:
FriendList();
static Friend* addFriend(int friendId, const QString& userId);
static Friend* findFriend(int friendId);
static Friend* findFriend(QString userId);
static QList<Friend*> getAllFriends();
static void removeFriend(int friendId);
static void clear();
public:
static QList<Friend*> friendList;
private:
static QHash<int, Friend*> friendList;
static QHash<QString, int> tox2id;
};
#endif // FRIENDLIST_H

View File

@ -92,12 +92,16 @@ void Settings::load()
useCustomDhtList=false;
s.endGroup();
friendAddresses.clear();
friendLst.clear();
s.beginGroup("Friends");
int size = s.beginReadArray("fullAddresses");
for (int i = 0; i < size; i ++) {
for (int i = 0; i < size; 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.endGroup();
@ -219,10 +223,14 @@ void Settings::save(QString path)
s.endGroup();
s.beginGroup("Friends");
s.beginWriteArray("fullAddresses", friendAddresses.size());
for (int i = 0; i < friendAddresses.size(); i ++) {
s.setArrayIndex(i);
s.setValue("addr", friendAddresses[i]);
s.beginWriteArray("fullAddresses", friendLst.size());
int index = 0;
for (auto &frnd : friendLst)
{
s.setArrayIndex(index);
s.setValue("addr", frnd.addr);
s.setValue("alias", frnd.alias);
index++;
}
s.endArray();
s.endGroup();
@ -760,3 +768,52 @@ void Settings::setOutDev(const QString& 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;
}
}

View File

@ -21,6 +21,8 @@
#include <QObject>
#include <QPixmap>
class ToxID;
class Settings : public QObject
{
Q_OBJECT
@ -185,8 +187,13 @@ public:
QByteArray getSplitterState() const;
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:
QList<QString> friendAddresses;
void save();
void save(QString path);
void load();
@ -258,6 +265,14 @@ private:
QString inDev;
QString outDev;
struct friendProp
{
QString alias;
QString addr;
};
QHash<QString, friendProp> friendLst;
signals:
//void dataChanged();
void dhtServerListChanged();

View File

@ -46,7 +46,7 @@ ChatForm::ChatForm(Friend* chatFriend)
, audioOutputFlag(false)
, callId(0)
{
nameLabel->setText(f->getName());
nameLabel->setText(f->getDisplayedName());
avatar->setPixmap(QPixmap(":/img/contact_dark.png"), Qt::transparent);
@ -98,18 +98,18 @@ void ChatForm::onSendTriggered()
return;
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 "))
{
msg = msg.right(msg.length() - 4);
addSelfMessage(msg, true, timestamp);
emit sendAction(f->friendId, msg);
emit sendAction(f->getFriendID(), msg);
}
else
{
addSelfMessage(msg, false, timestamp);
emit sendMessage(f->friendId, msg);
emit sendMessage(f->getFriendID(), msg);
}
msgEdit->clear();
}
@ -134,13 +134,13 @@ void ChatForm::onAttachClicked()
file.close();
QFileInfo fi(path);
emit sendFile(f->friendId, fi.fileName(), path, filesize);
emit sendFile(f->getFriendID(), fi.fileName(), path, filesize);
}
}
void ChatForm::startFileSend(ToxFile file)
{
if (file.friendId != f->friendId)
if (file.friendId != f->getFriendID())
return;
FileTransferInstance* fileTrans = new FileTransferInstance(file);
@ -168,7 +168,7 @@ void ChatForm::startFileSend(ToxFile file)
void ChatForm::onFileRecvRequest(ToxFile file)
{
if (file.friendId != f->friendId)
if (file.friendId != f->getFriendID())
return;
FileTransferInstance* fileTrans = new FileTransferInstance(file);
@ -186,22 +186,22 @@ void ChatForm::onFileRecvRequest(ToxFile file)
if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow())
{
w->newMessageAlert();
f->hasNewEvents=true;
f->widget->updateStatusLight();
f->setEventFlag(true);
f->getFriendWidget()->updateStatusLight();
}
QString name;
ToxID friendId = f->getToxID();
if (friendId != previousId)
{
name = f->getName();
name = f->getDisplayedName();
previousId = friendId;
}
chatWidget->insertMessage(ChatActionPtr(new FileTransferAction(fileTrans, getElidedName(name),
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())
fileTrans->pressFromHtml("btnB");
}
@ -209,7 +209,7 @@ void ChatForm::onFileRecvRequest(ToxFile file)
void ChatForm::onAvInvite(int FriendId, int CallId, bool video)
{
qDebug() << "onAvInvite";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
callId = CallId;
@ -232,21 +232,21 @@ void ChatForm::onAvInvite(int FriendId, int CallId, bool video)
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();
if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow())
{
w->newMessageAlert();
f->hasNewEvents=true;
f->widget->updateStatusLight();
f->setEventFlag(true);
f->getFriendWidget()->updateStatusLight();
}
}
void ChatForm::onAvStart(int FriendId, int CallId, bool video)
{
qDebug() << "onAvStart";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
audioInputFlag = true;
@ -263,7 +263,7 @@ void ChatForm::onAvStart(int FriendId, int CallId, bool video)
videoButton->style()->polish(videoButton);
connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getName());
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getDisplayedName());
}
else
{
@ -281,7 +281,7 @@ void ChatForm::onAvCancel(int FriendId, int)
{
qDebug() << "onAvCancel";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
audioInputFlag = false;
@ -301,14 +301,14 @@ void ChatForm::onAvCancel(int FriendId, int)
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)
{
qDebug() << "onAvEnd";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
audioInputFlag = false;
@ -334,7 +334,7 @@ void ChatForm::onAvEnd(int FriendId, int)
void ChatForm::onAvRinging(int FriendId, int CallId, bool video)
{
qDebug() << "onAvRinging";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
callId = CallId;
@ -357,14 +357,14 @@ void ChatForm::onAvRinging(int FriendId, int CallId, bool video)
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)
{
qDebug() << "onAvStarting";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
callButton->disconnect();
@ -377,7 +377,7 @@ void ChatForm::onAvStarting(int FriendId, int CallId, bool video)
videoButton->style()->polish(videoButton);
connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getName());
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getDisplayedName());
}
else
{
@ -395,7 +395,7 @@ void ChatForm::onAvEnding(int FriendId, int)
{
qDebug() << "onAvEnding";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
audioInputFlag = false;
@ -424,7 +424,7 @@ void ChatForm::onAvRequestTimeout(int FriendId, int)
{
qDebug() << "onAvRequestTimeout";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
audioInputFlag = false;
@ -451,7 +451,7 @@ void ChatForm::onAvPeerTimeout(int FriendId, int)
{
qDebug() << "onAvPeerTimeout";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
audioInputFlag = false;
@ -478,7 +478,7 @@ void ChatForm::onAvRejected(int FriendId, int)
{
qDebug() << "onAvRejected";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
audioInputFlag = false;
@ -507,12 +507,12 @@ void ChatForm::onAvMediaChange(int FriendId, int CallId, bool video)
{
qDebug() << "onAvMediaChange";
if (FriendId != f->friendId || CallId != callId)
if (FriendId != f->getFriendID() || CallId != callId)
return;
if (video)
{
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getName());
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getDisplayedName());
}
else
{
@ -550,7 +550,7 @@ void ChatForm::onCallTriggered()
audioOutputFlag = true;
callButton->disconnect();
videoButton->disconnect();
emit startCall(f->friendId);
emit startCall(f->getFriendID());
}
void ChatForm::onVideoCallTriggered()
@ -561,14 +561,14 @@ void ChatForm::onVideoCallTriggered()
audioOutputFlag = true;
callButton->disconnect();
videoButton->disconnect();
emit startVideoCall(f->friendId, true);
emit startVideoCall(f->getFriendID(), true);
}
void ChatForm::onAvCallFailed(int FriendId)
{
qDebug() << "onAvCallFailed";
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
audioInputFlag = false;
@ -601,7 +601,7 @@ void ChatForm::onCancelCallTriggered()
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
netcam->hide();
emit cancelCall(callId, f->friendId);
emit cancelCall(callId, f->getFriendID());
}
void ChatForm::onMicMuteToggle()
@ -646,7 +646,7 @@ void ChatForm::onFileTansBtnClicked(QString widgetName, QString buttonName)
void ChatForm::onFileSendFailed(int FriendId, const QString &fname)
{
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
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)
{
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
avatar->setPixmap(pic);
@ -675,14 +675,14 @@ void ChatForm::dropEvent(QDropEvent *ev)
QFileInfo info(url.path());
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)
{
if (FriendId != f->friendId)
if (FriendId != f->getFriendID())
return;
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;
std::swap(storedPrevId, previousId);
@ -752,7 +752,7 @@ void ChatForm::stopCounter()
{
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)),
"white", QDateTime::currentDateTime());
timer->stop();

View File

@ -31,6 +31,8 @@
#include "src/widget/tool/chattextedit.h"
#include "src/widget/maskablepixmapwidget.h"
#include "src/core.h"
#include "src/friendlist.h"
#include "src/friend.h"
GenericChatForm::GenericChatForm(QWidget *parent) :
QWidget(parent),
@ -342,8 +344,13 @@ ChatActionPtr GenericChatForm::genMessageActionAction(const ToxID& author, QStri
QString authorStr;
if (isMe)
authorStr = core->getUsername();
else
authorStr = core->getPeerName(author);
else {
Friend *f = FriendList::findFriend(author.publicKey);
if (f)
authorStr = f->getDisplayedName();
else
authorStr = core->getPeerName(author);
}
if (authorStr.isEmpty()) // Fallback if we can't find a username
authorStr = author.toString();

View File

@ -26,6 +26,7 @@
#include "croppinglabel.h"
#include "src/misc/style.h"
#include "src/misc/settings.h"
#include "src/widget/widget.h"
#include <QContextMenuEvent>
#include <QMenu>
#include <QDrag>
@ -34,6 +35,7 @@
#include <QBitmap>
#include <QFileDialog>
#include <QDebug>
#include <QInputDialog>
FriendWidget::FriendWidget(int FriendId, QString id)
: friendId(FriendId)
@ -63,6 +65,8 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
if (groupActions.isEmpty())
inviteMenu->setEnabled(false);
QAction* setAlias = menu.addAction(tr("Set alias..."));
menu.addSeparator();
QAction* autoAccept = menu.addAction(tr("Auto accept files from this friend", "context menu entry"));
autoAccept->setCheckable(true);
@ -78,6 +82,9 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
{
emit copyFriendIdToClipboard(friendId);
return;
} else if (selectedItem == setAlias)
{
setFriendAlias();
}
else if (selectedItem == removeFriendAction)
{
@ -132,36 +139,36 @@ void FriendWidget::setAsInactiveChatroom()
void FriendWidget::updateStatusLight()
{
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"));
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"));
else if (status == Status::Away && f->hasNewEvents == 0)
else if (status == Status::Away && f->getEventFlag() == 0)
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"));
else if (status == Status::Busy && f->hasNewEvents == 0)
else if (status == Status::Busy && f->getEventFlag() == 0)
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"));
else if (status == Status::Offline && f->hasNewEvents == 0)
else if (status == Status::Offline && f->getEventFlag() == 0)
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"));
}
void FriendWidget::setChatForm(Ui::MainWindow &ui)
{
Friend* f = FriendList::findFriend(friendId);
f->chatForm->show(ui);
f->getChatForm()->show(ui);
}
void FriendWidget::resetEventFlags()
{
Friend* f = FriendList::findFriend(friendId);
f->hasNewEvents = 0;
f->setEventFlag(false);
}
void FriendWidget::onAvatarChange(int FriendId, const QPixmap& pic)
@ -210,3 +217,26 @@ void FriendWidget::mouseMoveEvent(QMouseEvent *ev)
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");
}
}

View File

@ -48,6 +48,7 @@ public slots:
protected:
void mousePressEvent(QMouseEvent* ev);
void mouseMoveEvent(QMouseEvent* ev);
void setFriendAlias();
public:
int friendId;

View File

@ -276,9 +276,7 @@ Widget::~Widget()
delete addFriendForm;
delete filesForm;
for (Friend* f : FriendList::friendList)
delete f;
FriendList::friendList.clear();
FriendList::clear();
for (Group* g : GroupList::groupList)
delete g;
GroupList::groupList.clear();
@ -603,46 +601,50 @@ void Widget::addFriend(int friendId, const QString &userId)
//qDebug() << "Widget: Adding friend with id" << userId;
Friend* newfriend = FriendList::addFriend(friendId, userId);
QLayout* layout = contactListWidget->getFriendLayout(Status::Offline);
layout->addWidget(newfriend->widget);
connect(newfriend->widget, SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
connect(newfriend->widget, SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
connect(newfriend->widget, SIGNAL(copyFriendIdToClipboard(int)), this, SLOT(copyFriendIdToClipboard(int)));
connect(newfriend->widget, SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), newfriend->chatForm, SLOT(focusInput()));
connect(newfriend->chatForm, SIGNAL(sendMessage(int,QString)), core, SLOT(sendMessage(int,QString)));
connect(newfriend->chatForm, &GenericChatForm::sendAction, core, &Core::sendAction);
connect(newfriend->chatForm, SIGNAL(sendFile(int32_t, QString, QString, long long)), core, SLOT(sendFile(int32_t, QString, QString, long long)));
connect(newfriend->chatForm, SIGNAL(answerCall(int)), core, SLOT(answerCall(int)));
connect(newfriend->chatForm, SIGNAL(hangupCall(int)), core, SLOT(hangupCall(int)));
connect(newfriend->chatForm, SIGNAL(startCall(int)), core, SLOT(startCall(int)));
connect(newfriend->chatForm, SIGNAL(startVideoCall(int,bool)), core, SLOT(startCall(int,bool)));
connect(newfriend->chatForm, SIGNAL(cancelCall(int,int)), core, SLOT(cancelCall(int,int)));
connect(newfriend->chatForm, SIGNAL(micMuteToggle(int)), core, SLOT(micMuteToggle(int)));
connect(newfriend->chatForm, SIGNAL(volMuteToggle(int)), core, SLOT(volMuteToggle(int)));
connect(core, &Core::fileReceiveRequested, newfriend->chatForm, &ChatForm::onFileRecvRequest);
connect(core, &Core::avInvite, newfriend->chatForm, &ChatForm::onAvInvite);
connect(core, &Core::avStart, newfriend->chatForm, &ChatForm::onAvStart);
connect(core, &Core::avCancel, newfriend->chatForm, &ChatForm::onAvCancel);
connect(core, &Core::avEnd, newfriend->chatForm, &ChatForm::onAvEnd);
connect(core, &Core::avRinging, newfriend->chatForm, &ChatForm::onAvRinging);
connect(core, &Core::avStarting, newfriend->chatForm, &ChatForm::onAvStarting);
connect(core, &Core::avEnding, newfriend->chatForm, &ChatForm::onAvEnding);
connect(core, &Core::avRequestTimeout, newfriend->chatForm, &ChatForm::onAvRequestTimeout);
connect(core, &Core::avPeerTimeout, newfriend->chatForm, &ChatForm::onAvPeerTimeout);
connect(core, &Core::avMediaChange, newfriend->chatForm, &ChatForm::onAvMediaChange);
connect(core, &Core::avCallFailed, newfriend->chatForm, &ChatForm::onAvCallFailed);
connect(core, &Core::avRejected, newfriend->chatForm, &ChatForm::onAvRejected);
connect(core, &Core::friendAvatarChanged, newfriend->chatForm, &ChatForm::onAvatarChange);
connect(core, &Core::friendAvatarChanged, newfriend->widget, &FriendWidget::onAvatarChange);
connect(core, &Core::friendAvatarRemoved, newfriend->chatForm, &ChatForm::onAvatarRemoved);
connect(core, &Core::friendAvatarRemoved, newfriend->widget, &FriendWidget::onAvatarRemoved);
layout->addWidget(newfriend->getFriendWidget());
QString alias = Settings::getInstance().getFriendAlias(ToxID::fromString(userId));
newfriend->setAlias(alias);
connect(newfriend->getFriendWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
connect(newfriend->getFriendWidget(), SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
connect(newfriend->getFriendWidget(), SIGNAL(copyFriendIdToClipboard(int)), this, SLOT(copyFriendIdToClipboard(int)));
connect(newfriend->getFriendWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), newfriend->getChatForm(), SLOT(focusInput()));
connect(newfriend->getChatForm(), SIGNAL(sendMessage(int,QString)), core, SLOT(sendMessage(int,QString)));
connect(newfriend->getChatForm(), &GenericChatForm::sendAction, core, &Core::sendAction);
connect(newfriend->getChatForm(), SIGNAL(sendFile(int32_t, QString, QString, long long)), core, SLOT(sendFile(int32_t, QString, QString, long long)));
connect(newfriend->getChatForm(), SIGNAL(answerCall(int)), core, SLOT(answerCall(int)));
connect(newfriend->getChatForm(), SIGNAL(hangupCall(int)), core, SLOT(hangupCall(int)));
connect(newfriend->getChatForm(), SIGNAL(startCall(int)), core, SLOT(startCall(int)));
connect(newfriend->getChatForm(), SIGNAL(startVideoCall(int,bool)), core, SLOT(startCall(int,bool)));
connect(newfriend->getChatForm(), SIGNAL(cancelCall(int,int)), core, SLOT(cancelCall(int,int)));
connect(newfriend->getChatForm(), SIGNAL(micMuteToggle(int)), core, SLOT(micMuteToggle(int)));
connect(newfriend->getChatForm(), SIGNAL(volMuteToggle(int)), core, SLOT(volMuteToggle(int)));
connect(core, &Core::fileReceiveRequested, newfriend->getChatForm(), &ChatForm::onFileRecvRequest);
connect(core, &Core::avInvite, newfriend->getChatForm(), &ChatForm::onAvInvite);
connect(core, &Core::avStart, newfriend->getChatForm(), &ChatForm::onAvStart);
connect(core, &Core::avCancel, newfriend->getChatForm(), &ChatForm::onAvCancel);
connect(core, &Core::avEnd, newfriend->getChatForm(), &ChatForm::onAvEnd);
connect(core, &Core::avRinging, newfriend->getChatForm(), &ChatForm::onAvRinging);
connect(core, &Core::avStarting, newfriend->getChatForm(), &ChatForm::onAvStarting);
connect(core, &Core::avEnding, newfriend->getChatForm(), &ChatForm::onAvEnding);
connect(core, &Core::avRequestTimeout, newfriend->getChatForm(), &ChatForm::onAvRequestTimeout);
connect(core, &Core::avPeerTimeout, newfriend->getChatForm(), &ChatForm::onAvPeerTimeout);
connect(core, &Core::avMediaChange, newfriend->getChatForm(), &ChatForm::onAvMediaChange);
connect(core, &Core::avCallFailed, newfriend->getChatForm(), &ChatForm::onAvCallFailed);
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
QPixmap avatar = Settings::getInstance().getSavedAvatar(userId);
if (!avatar.isNull())
{
//qWarning() << "Widget: loadded avatar for id" << userId;
newfriend->chatForm->onAvatarChange(friendId, avatar);
newfriend->widget->onAvatarChange(friendId, avatar);
newfriend->getChatForm()->onAvatarChange(friendId, avatar);
newfriend->getFriendWidget()->onAvatarChange(friendId, avatar);
}
}
@ -657,17 +659,17 @@ void Widget::onFriendStatusChanged(int friendId, Status status)
if (!f)
return;
contactListWidget->moveWidget(f->widget, status);
contactListWidget->moveWidget(f->getFriendWidget(), status);
f->friendStatus = status;
f->widget->updateStatusLight();
f->setStatus(status);
f->getFriendWidget()->updateStatusLight();
//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)
{
QString fStatus = "";
switch(f->friendStatus){
switch(f->getStatus()){
case Status::Away:
fStatus = tr("away", "contact status"); break;
case Status::Busy:
@ -677,7 +679,7 @@ void Widget::onFriendStatusChanged(int friendId, Status status)
default:
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());
}
}
@ -726,28 +728,28 @@ void Widget::onFriendMessageReceived(int friendId, const QString& message, bool
return;
QDateTime timestamp = QDateTime::currentDateTime();
f->chatForm->addMessage(f->getToxID(), message, isAction, timestamp);
f->getChatForm()->addMessage(f->getToxID(), message, isAction, timestamp);
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
HistoryKeeper::getInstance()->addChatEntry(f->userId, message, f->userId, timestamp);
HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, message, f->getToxID().publicKey, timestamp);
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();
}
}
else
{
f->hasNewEvents = 1;
f->setEventFlag(true);
newMessageAlert();
}
f->widget->updateStatusLight();
f->getFriendWidget()->updateStatusLight();
}
void Widget::newMessageAlert()
@ -800,11 +802,11 @@ void Widget::onFriendRequestReceived(const QString& userId, const QString& messa
void Widget::removeFriend(Friend* f)
{
f->widget->setAsInactiveChatroom();
if (static_cast<GenericChatroomWidget*>(f->widget) == activeChatroomWidget)
f->getFriendWidget()->setAsInactiveChatroom();
if (static_cast<GenericChatroomWidget*>(f->getFriendWidget()) == activeChatroomWidget)
activeChatroomWidget = nullptr;
FriendList::removeFriend(f->friendId);
core->removeFriend(f->friendId);
FriendList::removeFriend(f->getFriendID());
core->removeFriend(f->getFriendID());
delete f;
if (ui->mainHead->layout()->isEmpty())
onAddClicked();
@ -820,7 +822,8 @@ void Widget::removeFriend(int friendId)
void Widget::clearContactsList()
{
for (Friend* f : FriendList::friendList)
QList<Friend*> friends = FriendList::getAllFriends();
for (Friend* f : friends)
removeFriend(f);
for (Group* g : GroupList::groupList)
removeGroup(g);
@ -832,7 +835,7 @@ void Widget::copyFriendIdToClipboard(int friendId)
if (f != nullptr)
{
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)
return false;
return (activeChatroomWidget == static_cast<GenericChatroomWidget*>(f->widget));
return (activeChatroomWidget == static_cast<GenericChatroomWidget*>(f->getFriendWidget()));
}
bool Widget::event(QEvent * e)
@ -1033,7 +1036,7 @@ void Widget::onMessageSendResult(int friendId, const QString& message, int messa
return;
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)