From 59748886de1a983259594f73dcdb4b73ef7d682a Mon Sep 17 00:00:00 2001 From: apprb Date: Fri, 7 Nov 2014 00:26:22 +0900 Subject: [PATCH 1/7] struct Friend refactoring --- src/friend.cpp | 67 +++++++++++++++++++--- src/friend.h | 32 ++++++++--- src/friendlist.cpp | 6 +- src/widget/form/chatform.cpp | 80 +++++++++++++------------- src/widget/friendwidget.cpp | 22 +++---- src/widget/widget.cpp | 108 +++++++++++++++++------------------ 6 files changed, 191 insertions(+), 124 deletions(-) diff --git a/src/friend.cpp b/src/friend.cpp index b9cf74a3b..8dd56893d 100644 --- a/src/friend.cpp +++ b/src/friend.cpp @@ -20,12 +20,13 @@ #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); } Friend::~Friend() @@ -36,8 +37,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 +60,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; } diff --git a/src/friend.h b/src/friend.h index bbb152d54..899b9c9cb 100644 --- a/src/friend.h +++ b/src/friend.h @@ -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 diff --git a/src/friendlist.cpp b/src/friendlist.cpp index 1c16c77d4..11c1769f7 100644 --- a/src/friendlist.cpp +++ b/src/friendlist.cpp @@ -24,7 +24,7 @@ QList FriendList::friendList; Friend* FriendList::addFriend(int friendId, const QString& userId) { for (Friend* f : friendList) - if (f->friendId == friendId) + if (f->getFriendID() == friendId) qWarning() << "FriendList::addFriend: friendId already taken"; Friend* newfriend = new Friend(friendId, userId); friendList.append(newfriend); @@ -34,7 +34,7 @@ Friend* FriendList::addFriend(int friendId, const QString& userId) Friend* FriendList::findFriend(int friendId) { for (Friend* f : friendList) - if (f->friendId == friendId) + if (f->getFriendID() == friendId) return f; return nullptr; } @@ -43,7 +43,7 @@ void FriendList::removeFriend(int friendId) { for (int i=0; ifriendId == friendId) + if (friendList[i]->getFriendID() == friendId) { friendList.removeAt(i); return; diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 02fc86e44..4087fb686 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -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().toString(), 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().toString(), 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(); diff --git a/src/widget/friendwidget.cpp b/src/widget/friendwidget.cpp index 479f06d09..382f18ac8 100644 --- a/src/widget/friendwidget.cpp +++ b/src/widget/friendwidget.cpp @@ -132,36 +132,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) diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 89feba47e..b00d15ffe 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -603,46 +603,46 @@ 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()); + 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 +657,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 +677,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 +726,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().toString(), "/me " + message, f->getToxID().toString(), timestamp); else - HistoryKeeper::getInstance()->addChatEntry(f->userId, message, f->userId, timestamp); + HistoryKeeper::getInstance()->addChatEntry(f->getToxID().toString(), message, f->getToxID().toString(), timestamp); if (activeChatroomWidget != nullptr) { - if ((static_cast(f->widget) != activeChatroomWidget) || isMinimized() || !isActiveWindow()) + if ((static_cast(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 +800,11 @@ void Widget::onFriendRequestReceived(const QString& userId, const QString& messa void Widget::removeFriend(Friend* f) { - f->widget->setAsInactiveChatroom(); - if (static_cast(f->widget) == activeChatroomWidget) + f->getFriendWidget()->setAsInactiveChatroom(); + if (static_cast(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(); @@ -832,7 +832,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 +962,7 @@ bool Widget::isFriendWidgetCurActiveWidget(Friend* f) if (!f) return false; - return (activeChatroomWidget == static_cast(f->widget)); + return (activeChatroomWidget == static_cast(f->getFriendWidget())); } bool Widget::event(QEvent * e) @@ -1033,7 +1033,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) From b316f6e13fffa5771158f7f997a1ab687e8a7030 Mon Sep 17 00:00:00 2001 From: apprb Date: Fri, 7 Nov 2014 14:29:23 +0900 Subject: [PATCH 2/7] only public key is necessary --- src/widget/form/chatform.cpp | 4 ++-- src/widget/widget.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 4087fb686..e76973c37 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -98,7 +98,7 @@ void ChatForm::onSendTriggered() return; QDateTime timestamp = QDateTime::currentDateTime(); - HistoryKeeper::getInstance()->addChatEntry(f->getToxID().toString(), msg, Core::getInstance()->getSelfId().publicKey, timestamp); + HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, msg, Core::getInstance()->getSelfId().publicKey, timestamp); if (msg.startsWith("/me ")) { @@ -711,7 +711,7 @@ void ChatForm::onLoadHistory() } } - auto msgs = HistoryKeeper::getInstance()->getChatHistory(HistoryKeeper::ctSingle, f->getToxID().toString(), fromTime, toTime); + auto msgs = HistoryKeeper::getInstance()->getChatHistory(HistoryKeeper::ctSingle, f->getToxID().publicKey, fromTime, toTime); ToxID storedPrevId; std::swap(storedPrevId, previousId); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index b00d15ffe..2ef989865 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -729,9 +729,9 @@ void Widget::onFriendMessageReceived(int friendId, const QString& message, bool f->getChatForm()->addMessage(f->getToxID(), message, isAction, timestamp); if (isAction) - HistoryKeeper::getInstance()->addChatEntry(f->getToxID().toString(), "/me " + message, f->getToxID().toString(), timestamp); + HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, "/me " + message, f->getToxID().publicKey, timestamp); else - HistoryKeeper::getInstance()->addChatEntry(f->getToxID().toString(), message, f->getToxID().toString(), timestamp); + HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, message, f->getToxID().publicKey, timestamp); if (activeChatroomWidget != nullptr) { From af8df8e7077d7d23e825990837da6c2f56f4ca13 Mon Sep 17 00:00:00 2001 From: apprb Date: Fri, 7 Nov 2014 23:55:32 +0900 Subject: [PATCH 3/7] possiblity to setup alias --- src/friendlist.cpp | 62 +++++++++++++++++++++-------- src/friendlist.h | 9 ++++- src/widget/form/genericchatform.cpp | 11 ++++- src/widget/friendwidget.cpp | 10 +++++ src/widget/friendwidget.h | 3 ++ src/widget/widget.cpp | 10 +++-- 6 files changed, 81 insertions(+), 24 deletions(-) diff --git a/src/friendlist.cpp b/src/friendlist.cpp index 11c1769f7..49c1a283c 100644 --- a/src/friendlist.cpp +++ b/src/friendlist.cpp @@ -18,35 +18,65 @@ #include "friendlist.h" #include #include +#include -QList FriendList::friendList; +QHash FriendList::friendList; +QHash FriendList::tox2id; Friend* FriendList::addFriend(int friendId, const QString& userId) { - for (Friend* f : friendList) - if (f->getFriendID() == 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->getFriendID() == 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; igetFriendID() == 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 FriendList::getAllFriends() +{ + QList res; + + for (auto it : friendList) + res.append(it); + + return res; } diff --git a/src/friendlist.h b/src/friendlist.h index bde30526d..fd0c63a20 100644 --- a/src/friendlist.h +++ b/src/friendlist.h @@ -18,6 +18,7 @@ #define FRIENDLIST_H template class QList; +template 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 getAllFriends(); static void removeFriend(int friendId); + static void clear(); -public: - static QList friendList; +private: + static QHash friendList; + static QHash tox2id; }; #endif // FRIENDLIST_H diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index d082b8551..27266bb54 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -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(); diff --git a/src/widget/friendwidget.cpp b/src/widget/friendwidget.cpp index 382f18ac8..c04560b47 100644 --- a/src/widget/friendwidget.cpp +++ b/src/widget/friendwidget.cpp @@ -42,6 +42,10 @@ FriendWidget::FriendWidget(int FriendId, QString id) avatar->setPixmap(QPixmap(":img/contact.png"), Qt::transparent); statusPic.setPixmap(QPixmap(":img/status/dot_away.png")); 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) @@ -210,3 +214,9 @@ void FriendWidget::mouseMoveEvent(QMouseEvent *ev) drag->exec(Qt::CopyAction | Qt::MoveAction); } } + +void FriendWidget::onFriendAliasChange(QString newText, QString) +{ + Friend* f = FriendList::findFriend(friendId); + f->setAlias(newText); +} diff --git a/src/widget/friendwidget.h b/src/widget/friendwidget.h index a04a5e76e..eeb13e86c 100644 --- a/src/widget/friendwidget.h +++ b/src/widget/friendwidget.h @@ -45,6 +45,9 @@ public slots: void onAvatarChange(int FriendId, const QPixmap& pic); void onAvatarRemoved(int FriendId); +private slots: + void onFriendAliasChange(QString newText, QString oldText); + protected: void mousePressEvent(QMouseEvent* ev); void mouseMoveEvent(QMouseEvent* ev); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 2ef989865..a9bec5718 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -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(); @@ -604,6 +602,9 @@ void Widget::addFriend(int friendId, const QString &userId) Friend* newfriend = FriendList::addFriend(friendId, userId); QLayout* layout = contactListWidget->getFriendLayout(Status::Offline); layout->addWidget(newfriend->getFriendWidget()); + + newfriend->setAlias(""); + 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))); @@ -820,7 +821,8 @@ void Widget::removeFriend(int friendId) void Widget::clearContactsList() { - for (Friend* f : FriendList::friendList) + QList friends = FriendList::getAllFriends(); + for (Friend* f : friends) removeFriend(f); for (Group* g : GroupList::groupList) removeGroup(g); From 58eebcb2a6a0a1e9db720abc694fe611682f6290 Mon Sep 17 00:00:00 2001 From: apprb Date: Sat, 8 Nov 2014 01:02:10 +0900 Subject: [PATCH 4/7] load/save aliases from the settings file --- src/core.cpp | 20 +++-------- src/misc/settings.cpp | 71 +++++++++++++++++++++++++++++++++---- src/misc/settings.h | 17 ++++++++- src/widget/friendwidget.cpp | 25 +++++++++---- src/widget/friendwidget.h | 4 +-- src/widget/widget.cpp | 3 +- 6 files changed, 106 insertions(+), 34 deletions(-) diff --git a/src/core.cpp b/src/core.cpp index d0b735441..b3b677f99 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -722,18 +722,7 @@ void Core::requestFriendship(const QString& friendAddress, const QString& messag emit failedToAddFriend(userId); } else { // Update our friendAddresses - bool found=false; - QList& 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& 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; } diff --git a/src/misc/settings.cpp b/src/misc/settings.cpp index 066adde4a..97a4a18d3 100644 --- a/src/misc/settings.cpp +++ b/src/misc/settings.cpp @@ -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; + } +} diff --git a/src/misc/settings.h b/src/misc/settings.h index 90650bed5..e278f307b 100644 --- a/src/misc/settings.h +++ b/src/misc/settings.h @@ -21,6 +21,8 @@ #include #include +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 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 friendLst; + signals: //void dataChanged(); void dhtServerListChanged(); diff --git a/src/widget/friendwidget.cpp b/src/widget/friendwidget.cpp index c04560b47..24b1974bb 100644 --- a/src/widget/friendwidget.cpp +++ b/src/widget/friendwidget.cpp @@ -34,6 +34,7 @@ #include #include #include +#include FriendWidget::FriendWidget(int FriendId, QString id) : friendId(FriendId) @@ -42,10 +43,6 @@ FriendWidget::FriendWidget(int FriendId, QString id) avatar->setPixmap(QPixmap(":img/contact.png"), Qt::transparent); statusPic.setPixmap(QPixmap(":img/status/dot_away.png")); 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) @@ -67,6 +64,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); @@ -82,6 +81,9 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event) { emit copyFriendIdToClipboard(friendId); return; + } else if (selectedItem == setAlias) + { + setFriendAlias(); } else if (selectedItem == removeFriendAction) { @@ -215,8 +217,19 @@ void FriendWidget::mouseMoveEvent(QMouseEvent *ev) } } -void FriendWidget::onFriendAliasChange(QString newText, QString) +void FriendWidget::setFriendAlias() { + bool ok; Friend* f = FriendList::findFriend(friendId); - f->setAlias(newText); + + QString alias = QInputDialog::getText(nullptr, tr("User alias"), tr("Alias:"), QLineEdit::Normal, + f->getDisplayedName(), &ok); + + if (ok) + { + f->setAlias(alias); + Settings::getInstance().setFriendAlias(f->getToxID(), alias); + hide(); + show(); + } } diff --git a/src/widget/friendwidget.h b/src/widget/friendwidget.h index eeb13e86c..1aa2840a5 100644 --- a/src/widget/friendwidget.h +++ b/src/widget/friendwidget.h @@ -45,12 +45,10 @@ public slots: void onAvatarChange(int FriendId, const QPixmap& pic); void onAvatarRemoved(int FriendId); -private slots: - void onFriendAliasChange(QString newText, QString oldText); - protected: void mousePressEvent(QMouseEvent* ev); void mouseMoveEvent(QMouseEvent* ev); + void setFriendAlias(); public: int friendId; diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index a9bec5718..9f7b800cb 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -603,7 +603,8 @@ void Widget::addFriend(int friendId, const QString &userId) QLayout* layout = contactListWidget->getFriendLayout(Status::Offline); layout->addWidget(newfriend->getFriendWidget()); - newfriend->setAlias(""); + 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))); From c1ef9115d0ff5bef5b929421fb06656b9cc57e7f Mon Sep 17 00:00:00 2001 From: apprb Date: Sat, 8 Nov 2014 01:40:22 +0900 Subject: [PATCH 5/7] Alias: remove unnecessary symbols + size limit --- src/widget/friendwidget.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/widget/friendwidget.cpp b/src/widget/friendwidget.cpp index 24b1974bb..9d42f9707 100644 --- a/src/widget/friendwidget.cpp +++ b/src/widget/friendwidget.cpp @@ -227,6 +227,9 @@ void FriendWidget::setFriendAlias() 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(); From 9947a34465690c9d3a2c4d906cf4a19db8b3db3f Mon Sep 17 00:00:00 2001 From: apprb Date: Sat, 8 Nov 2014 01:50:39 +0900 Subject: [PATCH 6/7] main window title proper updating --- src/widget/friendwidget.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/widget/friendwidget.cpp b/src/widget/friendwidget.cpp index 9d42f9707..3fa4f0f6b 100644 --- a/src/widget/friendwidget.cpp +++ b/src/widget/friendwidget.cpp @@ -26,6 +26,7 @@ #include "croppinglabel.h" #include "src/misc/style.h" #include "src/misc/settings.h" +#include "src/widget/widget.h" #include #include #include @@ -234,5 +235,8 @@ void FriendWidget::setFriendAlias() Settings::getInstance().setFriendAlias(f->getToxID(), alias); hide(); show(); + + if (f->getFriendWidget()->isActive()) + Widget::getInstance()->setWindowTitle(f->getFriendWidget()->getName() + " - qTox"); } } From bc0f0a9416aed26bfb2ddfa106754b79f416fdd8 Mon Sep 17 00:00:00 2001 From: apprb Date: Sat, 8 Nov 2014 02:15:42 +0900 Subject: [PATCH 7/7] default friend name --- src/friend.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/friend.cpp b/src/friend.cpp index 8dd56893d..c0da31901 100644 --- a/src/friend.cpp +++ b/src/friend.cpp @@ -27,6 +27,7 @@ Friend::Friend(int FriendId, QString UserId) hasNewEvents = 0; friendStatus = Status::Offline; userID = ToxID::fromString(UserId); + userName = UserId; } Friend::~Friend()