From ceac25855256b07afa8fc61121deaf37645d3a0b Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 28 Mar 2015 15:46:47 +0000 Subject: [PATCH] fixed naming and completion in recipient addresses in MessageComposer git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8090 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- .../src/gui/msgs/MessageComposer.cpp | 88 +++++++++++-------- retroshare-gui/src/gui/msgs/MessageComposer.h | 5 +- 2 files changed, 57 insertions(+), 36 deletions(-) diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.cpp b/retroshare-gui/src/gui/msgs/MessageComposer.cpp index a5a678547..d5fcd95f8 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.cpp +++ b/retroshare-gui/src/gui/msgs/MessageComposer.cpp @@ -730,19 +730,20 @@ void MessageComposer::buildCompleter() RsIdentityDetails detail; if(rsIdentity->getIdDetails(id, detail)) - completerList.append( getGxsRecipientName(id,detail)) ; + completerList.append( getRecipientEmailAddress(id,detail)) ; } - for (peerIt = peers.begin(); peerIt != peers.end(); ++peerIt) { + for (peerIt = peers.begin(); peerIt != peers.end(); ++peerIt) + { RsPeerDetails detail; - if (!rsPeers->getPeerDetails(*peerIt, detail)) { - continue; /* BAD */ - } - QString name = PeerDefs::nameWithLocation(detail); - if (completerList.indexOf(name) == -1) { - completerList.append(name); - } + if (rsPeers->getPeerDetails(*peerIt, detail)) + completerList.append( getRecipientEmailAddress(*peerIt,detail)) ; + +// QString name = PeerDefs::nameWithLocation(detail); +// if (completerList.indexOf(name) == -1) { +// completerList.append(name); +// } } completerList.sort(); @@ -1497,10 +1498,20 @@ bool MessageComposer::getRecipientFromRow(int row, enumType &type, destinationTy return true; } -QString MessageComposer::getGxsRecipientName(const RsGxsId& id,const RsIdentityDetails& detail) +QString MessageComposer::getRecipientEmailAddress(const RsGxsId& id,const RsIdentityDetails& detail) { - return QString("%2 <%2@%1>").arg(QString::fromStdString(id.toStdString())).arg(QString::fromUtf8(detail.mNickname.c_str())) ; + return (QString("%2 <")+tr("Distant identity:")+" %2@%1>").arg(QString::fromStdString(id.toStdString())).arg(QString::fromUtf8(detail.mNickname.c_str())) ; } + +QString MessageComposer::getRecipientEmailAddress(const RsPeerId& id,const RsPeerDetails& detail) +{ + QString location_name = detail.location.empty()?tr("[Missing]"):QString::fromUtf8(detail.location.c_str()) ; + + return (QString("%1 (")+tr("Friend node & location:")+" %2, %3)").arg(QString::fromUtf8(detail.name.c_str())) + .arg(location_name) + .arg(QString::fromUtf8(detail.id.toStdString().c_str())) ; +} + void MessageComposer::setRecipientToRow(int row, enumType type, destinationType dest_type, const std::string &id) { if (row + 1 > ui.recipientWidget->rowCount()) { @@ -1567,7 +1578,7 @@ void MessageComposer::setRecipientToRow(int row, enumType type, destinationType QList icons ; GxsIdDetails::getIcons(detail,icons,GxsIdDetails::ICON_TYPE_AVATAR) ; - name = getGxsRecipientName(gid,detail) ; + name = getRecipientEmailAddress(gid,detail) ; if(!icons.empty()) icon = icons.front() ; @@ -1582,7 +1593,7 @@ void MessageComposer::setRecipientToRow(int row, enumType type, destinationType std::cerr << "Can't get peer details from " << id << std::endl; return ; } - name = PeerDefs::nameWithLocation(details); + name = getRecipientEmailAddress(RsPeerId(id),details) ; StatusInfo peerStatusInfo; // No check of return value. Non existing status info is handled as offline. @@ -1655,24 +1666,21 @@ bool MessageComposer::eventFilter(QObject *obj, QEvent *event) void MessageComposer::editingRecipientFinished() { QLineEdit *lineEdit = dynamic_cast(QObject::sender()); - if (lineEdit == NULL) { + + if (lineEdit == NULL) return; - } lineEdit->setStyleSheet(QString(STYLE_NORMAL).arg(lineEdit->objectName())); // find row of the widget int rowCount = ui.recipientWidget->rowCount(); int row; - for (row = 0; row < rowCount; ++row) { - if (ui.recipientWidget->cellWidget(row, COLUMN_RECIPIENT_NAME) == lineEdit) { + for (row = 0; row < rowCount; ++row) + if (ui.recipientWidget->cellWidget(row, COLUMN_RECIPIENT_NAME) == lineEdit) break; - } - } - if (row >= rowCount) { - // not found + + if (row >= rowCount) // not found return; - } enumType type; std::string id; // dummy @@ -1690,22 +1698,31 @@ void MessageComposer::editingRecipientFinished() // start with peers std::list peers; rsPeers->getFriendList(peers); + RsPeerDetails details; - std::list::iterator peerIt; - for (peerIt = peers.begin(); peerIt != peers.end(); ++peerIt) { - RsPeerDetails details; - if (!rsPeers->getPeerDetails(*peerIt, details)) { - continue; /* BAD */ - } - - QString name = PeerDefs::nameWithLocation(details); - if (text.compare(name, Qt::CaseSensitive) == 0) { - // found it - setRecipientToRow(row, type, PEER_TYPE_SSL, details.id.toStdString()); - return; - } + for (std::list::iterator peerIt = peers.begin(); peerIt != peers.end(); ++peerIt) + if (rsPeers->getPeerDetails(*peerIt, details) && text == getRecipientEmailAddress(*peerIt,details)) + { + setRecipientToRow(row, type, PEER_TYPE_SSL, details.id.toStdString()); + return ; } + QList gxsitems ; + ui.friendSelectionWidget->items(gxsitems,FriendSelectionWidget::IDTYPE_GXS) ; + RsIdentityDetails detail; + + for (QList::const_iterator idIt = gxsitems.begin(); idIt != gxsitems.end(); ++idIt) + { + RsGxsId id ( ui.friendSelectionWidget->idFromItem( *idIt ) ); + + if(rsIdentity->getIdDetails(id, detail) && text == getRecipientEmailAddress(id,detail)) + { + setRecipientToRow(row, type, PEER_TYPE_GXS, id.toStdString()); + return ; + } + } + + // then groups std::list groupInfoList; rsPeers->getGroupInfoList(groupInfoList); @@ -1724,6 +1741,7 @@ void MessageComposer::editingRecipientFinished() lineEdit->setStyleSheet(QString(STYLE_FAIL).arg(lineEdit->objectName())); lineEdit->setText(text); } + void MessageComposer::addRecipient(enumType type, const RsPeerId& pid) { int rowCount = ui.recipientWidget->rowCount(); diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.h b/retroshare-gui/src/gui/msgs/MessageComposer.h index 046fb2d5b..81fb4ba31 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.h +++ b/retroshare-gui/src/gui/msgs/MessageComposer.h @@ -25,6 +25,7 @@ #include #include #include +#include #include "ui_MessageComposer.h" #include "gui/msgs/MessageInterface.h" @@ -165,7 +166,9 @@ private: void processSettings(bool bLoad); - QString getGxsRecipientName(const RsGxsId& id,const RsIdentityDetails& detail) ; + static QString getRecipientEmailAddress(const RsGxsId& id,const RsIdentityDetails& detail) ; + static QString getRecipientEmailAddress(const RsPeerId& id,const RsPeerDetails& detail) ; + void addContact(enumType type); void setTextColor(const QColor& col) ; void setupFileActions();