improved alignment of IPs in friend list

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8258 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2015-05-15 14:45:44 +00:00
parent 1560da7ad9
commit 76fdbce10d
2 changed files with 341 additions and 338 deletions

View File

@ -725,401 +725,402 @@ void FriendList::insertPeers()
} }
// iterate through gpg friends // iterate through gpg friends
for (gpgIt = gpgFriends.begin(); gpgIt != gpgFriends.end(); ++gpgIt) { for (gpgIt = gpgFriends.begin(); gpgIt != gpgFriends.end(); ++gpgIt)
RsPgpId gpgId = *gpgIt; {
RsPgpId gpgId = *gpgIt;
if (mShowGroups) { if (mShowGroups) {
if (groupInfo) { if (groupInfo) {
// we fill a group, check if gpg id is assigned // we fill a group, check if gpg id is assigned
if (std::find(groupInfo->peerIds.begin(), groupInfo->peerIds.end(), gpgId) == groupInfo->peerIds.end()) { if (std::find(groupInfo->peerIds.begin(), groupInfo->peerIds.end(), gpgId) == groupInfo->peerIds.end()) {
continue; continue;
} }
} else { } else {
// we fill the not assigned gpg ids // we fill the not assigned gpg ids
if (std::find(fillGpgIds.begin(), fillGpgIds.end(), gpgId) != fillGpgIds.end()) { if (std::find(fillGpgIds.begin(), fillGpgIds.end(), gpgId) != fillGpgIds.end()) {
continue; continue;
}
} }
// add equal too, its no problem
fillGpgIds.push_back(gpgId);
} }
//add the gpg friends // add equal too, its no problem
fillGpgIds.push_back(gpgId);
}
//add the gpg friends
#ifdef FRIENDS_DEBUG #ifdef FRIENDS_DEBUG
std::cerr << "FriendList::insertPeers() inserting gpg_id : " << gpgId << std::endl; std::cerr << "FriendList::insertPeers() inserting gpg_id : " << gpgId << std::endl;
#endif #endif
/* make a widget per friend */ /* make a widget per friend */
QTreeWidgetItem *gpgItem = NULL; QTreeWidgetItem *gpgItem = NULL;
QTreeWidgetItem *gpgItemLoop = NULL; QTreeWidgetItem *gpgItemLoop = NULL;
// search existing gpg item // search existing gpg item
int itemCount = groupItem ? groupItem->childCount() : peerTreeWidget->topLevelItemCount(); int itemCount = groupItem ? groupItem->childCount() : peerTreeWidget->topLevelItemCount();
for (int index = 0; index < itemCount; ++index) { for (int index = 0; index < itemCount; ++index) {
gpgItemLoop = groupItem ? groupItem->child(index) : peerTreeWidget->topLevelItem(index); gpgItemLoop = groupItem ? groupItem->child(index) : peerTreeWidget->topLevelItem(index);
if (gpgItemLoop->type() == TYPE_GPG && getRsId(gpgItemLoop) == gpgId.toStdString()) { if (gpgItemLoop->type() == TYPE_GPG && getRsId(gpgItemLoop) == gpgId.toStdString()) {
gpgItem = gpgItemLoop; gpgItem = gpgItemLoop;
break;
}
}
RsPeerDetails detail;
if ((!rsPeers->getGPGDetails(gpgId, detail) || !detail.accept_connection) && detail.gpg_id != ownId) {
// don't accept anymore connection, remove from the view
if (gpgItem) {
if (groupItem) {
delete(groupItem->takeChild(groupItem->indexOfChild(gpgItem)));
} else {
delete (peerTreeWidget->takeTopLevelItem(peerTreeWidget->indexOfTopLevelItem(gpgItem)));
}
}
continue;
}
if (gpgItem == NULL) {
// create gpg item and add it to tree
gpgItem = new RSTreeWidgetItem(m_compareRole, TYPE_GPG); //set type to 0 for custom popup menu
/* Add gpg item to the list. Add here, because for setHidden the item must be added */
if (groupItem) {
groupItem->addChild(gpgItem);
} else {
peerTreeWidget->addTopLevelItem(gpgItem);
}
gpgItem->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless);
gpgItem->setTextAlignment(COLUMN_NAME, Qt::AlignLeft | Qt::AlignVCenter);
/* not displayed, used to find back the item */
gpgItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(detail.gpg_id.toStdString()));
}
if (mBigName && !mHideState && isStatusColumnHidden) {
gpgItem->setSizeHint(COLUMN_NAME, QSize(40, 40));
} else {
gpgItem->setSizeHint(COLUMN_NAME, QSize(26, 26));
}
++availableCount;
QString gpgItemText = QString::fromUtf8(detail.name.c_str());
// remove items that are not friends anymore
int childCount = gpgItem->childCount();
int childIndex = 0;
while (childIndex < childCount) {
std::string ssl_id = getRsId(gpgItem->child(childIndex));
if (!rsPeers->isFriend(RsPeerId(ssl_id))) {
delete (gpgItem->takeChild(childIndex));
// count again
childCount = gpgItem->childCount();
} else {
++childIndex;
}
}
// update the childs (ssl certs)
bool gpg_connected = false;
bool gpg_online = false;
bool gpg_hasPrivateChat = false;
int bestPeerState = 0; // for gpg item
unsigned int bestRSState = 0; // for gpg item
RsPeerId bestSslId; // for gpg item
QString bestCustomStateString;// for gpg item
std::list<RsPeerId> sslContacts;
QDateTime lastContact;
QString itemIP;
rsPeers->getAssociatedSSLIds(detail.gpg_id, sslContacts);
for (std::list<RsPeerId>::iterator sslIt = sslContacts.begin(); sslIt != sslContacts.end(); ++sslIt) {
QTreeWidgetItem *sslItem = NULL;
RsPeerId sslId = *sslIt;
//find the corresponding sslItem child item of the gpg item
bool newChild = true;
childCount = gpgItem->childCount();
for (int childIndex = 0; childIndex < childCount; ++childIndex) {
// we assume, that only ssl items are child of the gpg item, so we don't need to test the type
if (getRsId(gpgItem->child(childIndex)) == sslId.toStdString()) {
sslItem = gpgItem->child(childIndex);
newChild = false;
break; break;
} }
} }
RsPeerDetails detail; RsPeerDetails sslDetail;
if ((!rsPeers->getGPGDetails(gpgId, detail) || !detail.accept_connection) && detail.gpg_id != ownId) { if (!rsPeers->getPeerDetails(sslId, sslDetail) || !rsPeers->isFriend(sslId)) {
// don't accept anymore connection, remove from the view #ifdef FRIENDS_DEBUG
if (gpgItem) { std::cerr << "Removing widget from the view : id : " << sslId << std::endl;
if (groupItem) { #endif
delete(groupItem->takeChild(groupItem->indexOfChild(gpgItem))); //child has disappeared, remove it from the gpg_item
} else { if (sslItem) {
delete (peerTreeWidget->takeTopLevelItem(peerTreeWidget->indexOfTopLevelItem(gpgItem))); gpgItem->removeChild(sslItem);
}
} }
continue; continue;
} }
if (gpgItem == NULL) { if (newChild) {
// create gpg item and add it to tree sslItem = new RSTreeWidgetItem(m_compareRole, TYPE_SSL); //set type to 1 for custom popup menu
gpgItem = new RSTreeWidgetItem(m_compareRole, TYPE_GPG); //set type to 0 for custom popup menu
/* Add gpg item to the list. Add here, because for setHidden the item must be added */ #ifdef FRIENDS_DEBUG
if (groupItem) { std::cerr << "FriendList::insertPeers() inserting sslItem." << std::endl;
groupItem->addChild(gpgItem); #endif
} else {
peerTreeWidget->addTopLevelItem(gpgItem);
}
gpgItem->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless); /* Add ssl child to the list. Add here, because for setHidden the item must be added */
gpgItem->setTextAlignment(COLUMN_NAME, Qt::AlignLeft | Qt::AlignVCenter); gpgItem->addChild(sslItem);
/* not displayed, used to find back the item */
gpgItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(detail.gpg_id.toStdString()));
} }
if (mBigName && !mHideState && isStatusColumnHidden) { /* not displayed, used to find back the item */
gpgItem->setSizeHint(COLUMN_NAME, QSize(40, 40)); sslItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(sslDetail.id.toStdString()));
QString sText;
QString customStateString;
if (sslDetail.state & RS_PEER_STATE_CONNECTED) {
customStateString = QString::fromUtf8(rsMsgs->getCustomStateString(sslDetail.id).c_str());
}
sText = QString::fromUtf8(sslDetail.location.c_str());
if (customStateString.isEmpty() == false) {
sText += " - " + customStateString;
}
QString connectStateString = StatusDefs::connectStateWithoutTransportTypeString(sslDetail);
if (!isStatusColumnHidden) {
sslItem->setText(COLUMN_STATE, connectStateString);
} else if (!mHideState && connectStateString.isEmpty() == false) {
sText += " [" + connectStateString + "]";
}
sslItem->setText( COLUMN_NAME, sText);
if (isStatusColumnHidden == true && mHideState == true) {
/* Show the state as tooltip */
sslItem->setToolTip(COLUMN_NAME, connectStateString);
} else { } else {
gpgItem->setSizeHint(COLUMN_NAME, QSize(26, 26)); sslItem->setToolTip(COLUMN_NAME, "");
} }
++availableCount; // sort node
sslItem->setData(COLUMN_STATE, ROLE_SORT, sText);
QString gpgItemText = QString::fromUtf8(detail.name.c_str()); /* last contact */
QDateTime sslLastContact = QDateTime::fromTime_t(sslDetail.lastConnect);
// remove items that are not friends anymore sslItem->setData(COLUMN_LAST_CONTACT, Qt::DisplayRole, QVariant(sslLastContact));
int childCount = gpgItem->childCount(); sslItem->setData(COLUMN_LAST_CONTACT, ROLE_SORT, sslLastContact);
int childIndex = 0; if (sslLastContact > lastContact) {
while (childIndex < childCount) { lastContact = sslLastContact;
std::string ssl_id = getRsId(gpgItem->child(childIndex));
if (!rsPeers->isFriend(RsPeerId(ssl_id))) {
delete (gpgItem->takeChild(childIndex));
// count again
childCount = gpgItem->childCount();
} else {
++childIndex;
}
} }
// update the childs (ssl certs) /* IP */
bool gpg_connected = false;
bool gpg_online = false;
bool gpg_hasPrivateChat = false;
int bestPeerState = 0; // for gpg item
unsigned int bestRSState = 0; // for gpg item
RsPeerId bestSslId; // for gpg item
QString bestCustomStateString;// for gpg item
std::list<RsPeerId> sslContacts;
QDateTime lastContact;
QString itemIP;
rsPeers->getAssociatedSSLIds(detail.gpg_id, sslContacts); QString sslItemIP = (sslDetail.state & RS_PEER_STATE_CONNECTED) ? StatusDefs::connectStateIpString(sslDetail) : QString("---");
for (std::list<RsPeerId>::iterator sslIt = sslContacts.begin(); sslIt != sslContacts.end(); ++sslIt) {
QTreeWidgetItem *sslItem = NULL;
RsPeerId sslId = *sslIt;
//find the corresponding sslItem child item of the gpg item sslItem->setData(COLUMN_IP, Qt::DisplayRole, QVariant(sslItemIP));
bool newChild = true; sslItem->setData(COLUMN_IP, ROLE_SORT, sslItemIP);
childCount = gpgItem->childCount(); if (sslItemIP != itemIP) {
for (int childIndex = 0; childIndex < childCount; ++childIndex) { itemIP = sslItemIP;
// we assume, that only ssl items are child of the gpg item, so we don't need to test the type }
if (getRsId(gpgItem->child(childIndex)) == sslId.toStdString()) {
sslItem = gpgItem->child(childIndex);
newChild = false;
break;
}
}
RsPeerDetails sslDetail; /* change color and icon */
if (!rsPeers->getPeerDetails(sslId, sslDetail) || !rsPeers->isFriend(sslId)) { QIcon sslIcon;
#ifdef FRIENDS_DEBUG QFont sslFont;
std::cerr << "Removing widget from the view : id : " << sslId << std::endl; QColor sslColor;
#endif if (sslDetail.state & RS_PEER_STATE_CONNECTED) {
//child has disappeared, remove it from the gpg_item // get the status info for this ssl id
if (sslItem) { int peerState = 0;
gpgItem->removeChild(sslItem); int rsState = 0;
} std::list<StatusInfo>::iterator it;
continue; for(it = statusInfo.begin(); it != statusInfo.end(); ++it) {
} if(it->id == sslId){
rsState = it->status;
switch (rsState) {
case RS_STATUS_INACTIVE:
peerState = PEER_STATE_INACTIVE;
break;
if (newChild) { case RS_STATUS_ONLINE:
sslItem = new RSTreeWidgetItem(m_compareRole, TYPE_SSL); //set type to 1 for custom popup menu peerState = PEER_STATE_ONLINE;
break;
#ifdef FRIENDS_DEBUG case RS_STATUS_AWAY:
std::cerr << "FriendList::insertPeers() inserting sslItem." << std::endl; peerState = PEER_STATE_AWAY;
#endif break;
/* Add ssl child to the list. Add here, because for setHidden the item must be added */ case RS_STATUS_BUSY:
gpgItem->addChild(sslItem); peerState = PEER_STATE_BUSY;
} break;
}
/* not displayed, used to find back the item */ /* find the best ssl contact for the gpg item */
sslItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(sslDetail.id.toStdString())); if (bestPeerState == 0 || peerState < bestPeerState) {
/* first ssl contact or higher state */
QString sText; bestPeerState = peerState;
QString customStateString; bestSslId = sslId;
if (sslDetail.state & RS_PEER_STATE_CONNECTED) { bestRSState = rsState;
customStateString = QString::fromUtf8(rsMsgs->getCustomStateString(sslDetail.id).c_str()); bestCustomStateString = customStateString;
} } else if (peerState == bestPeerState) {
sText = QString::fromUtf8(sslDetail.location.c_str()); /* equal state */
if (customStateString.isEmpty() == false) { if (mBigName && bestCustomStateString.isEmpty() && !customStateString.isEmpty()) {
sText += " - " + customStateString; /* when customStateString is shown in name item, use sslId with customStateString.
} second with a custom state string ... use second */
QString connectStateString = StatusDefs::connectStateWithoutTransportTypeString(sslDetail);
if (!isStatusColumnHidden) {
sslItem->setText(COLUMN_STATE, connectStateString);
} else if (!mHideState && connectStateString.isEmpty() == false) {
sText += " [" + connectStateString + "]";
}
sslItem->setText( COLUMN_NAME, sText);
if (isStatusColumnHidden == true && mHideState == true) {
/* Show the state as tooltip */
sslItem->setToolTip(COLUMN_NAME, connectStateString);
} else {
sslItem->setToolTip(COLUMN_NAME, "");
}
// sort node
sslItem->setData(COLUMN_STATE, ROLE_SORT, sText);
/* last contact */
QDateTime sslLastContact = QDateTime::fromTime_t(sslDetail.lastConnect);
sslItem->setData(COLUMN_LAST_CONTACT, Qt::DisplayRole, QVariant(sslLastContact));
sslItem->setData(COLUMN_LAST_CONTACT, ROLE_SORT, sslLastContact);
if (sslLastContact > lastContact) {
lastContact = sslLastContact;
}
/* IP */
QString sslItemIP = (sslDetail.state & RS_PEER_STATE_CONNECTED) ? StatusDefs::connectStateIpString(sslDetail) : QString("---");
sslItem->setData(COLUMN_IP, Qt::DisplayRole, QVariant(sslItemIP));
sslItem->setData(COLUMN_IP, ROLE_SORT, sslItemIP);
if (sslItemIP != itemIP) {
itemIP = sslItemIP;
}
/* change color and icon */
QIcon sslIcon;
QFont sslFont;
QColor sslColor;
if (sslDetail.state & RS_PEER_STATE_CONNECTED) {
// get the status info for this ssl id
int peerState = 0;
int rsState = 0;
std::list<StatusInfo>::iterator it;
for(it = statusInfo.begin(); it != statusInfo.end(); ++it) {
if(it->id == sslId){
rsState = it->status;
switch (rsState) {
case RS_STATUS_INACTIVE:
peerState = PEER_STATE_INACTIVE;
break;
case RS_STATUS_ONLINE:
peerState = PEER_STATE_ONLINE;
break;
case RS_STATUS_AWAY:
peerState = PEER_STATE_AWAY;
break;
case RS_STATUS_BUSY:
peerState = PEER_STATE_BUSY;
break;
}
/* find the best ssl contact for the gpg item */
if (bestPeerState == 0 || peerState < bestPeerState) {
/* first ssl contact or higher state */
bestPeerState = peerState; bestPeerState = peerState;
bestSslId = sslId; bestSslId = sslId;
bestRSState = rsState; bestRSState = rsState;
bestCustomStateString = customStateString; bestCustomStateString = customStateString;
} else if (peerState == bestPeerState) {
/* equal state */
if (mBigName && bestCustomStateString.isEmpty() && !customStateString.isEmpty()) {
/* when customStateString is shown in name item, use sslId with customStateString.
second with a custom state string ... use second */
bestPeerState = peerState;
bestSslId = sslId;
bestRSState = rsState;
bestCustomStateString = customStateString;
}
} }
break;
} }
break;
} }
}
sslItem->setHidden(false); sslItem->setHidden(false);
gpg_connected = true; gpg_connected = true;
sslIcon = QIcon(":/images/connect_established.png"); sslIcon = QIcon(":/images/connect_established.png");
if (rsState == 0) {
sslFont.setBold(true);
sslColor = mTextColorStatus[RS_STATUS_ONLINE];
} else {
sslFont = StatusDefs::font(rsState);
sslColor = mTextColorStatus[rsState];
}
} else if (sslDetail.state & RS_PEER_STATE_ONLINE) {
sslItem->setHidden(mHideUnconnected);
gpg_online = true;
if (sslDetail.connectState) {
sslIcon = QIcon(":/images/connect_creating.png");
} else {
sslIcon = QIcon(":/images/connect_no.png");
}
if (rsState == 0) {
sslFont.setBold(true); sslFont.setBold(true);
sslColor = mTextColorStatus[RS_STATUS_ONLINE]; sslColor = mTextColorStatus[RS_STATUS_ONLINE];
} else { } else {
sslItem->setHidden(mHideUnconnected); sslFont = StatusDefs::font(rsState);
if (sslDetail.connectState) { sslColor = mTextColorStatus[rsState];
sslIcon = QIcon(":/images/connect_creating.png"); }
} else { } else if (sslDetail.state & RS_PEER_STATE_ONLINE) {
sslIcon = QIcon(":/images/connect_no.png"); sslItem->setHidden(mHideUnconnected);
} gpg_online = true;
sslFont.setBold(false); if (sslDetail.connectState) {
sslColor = mTextColorStatus[RS_STATUS_OFFLINE]; sslIcon = QIcon(":/images/connect_creating.png");
} else {
sslIcon = QIcon(":/images/connect_no.png");
} }
if (std::find(privateChatIds.begin(), privateChatIds.end(), sslDetail.id) != privateChatIds.end()) { sslFont.setBold(true);
// private chat is available sslColor = mTextColorStatus[RS_STATUS_ONLINE];
sslIcon = QIcon(":/images/chat.png");
gpg_hasPrivateChat = true;
}
sslItem -> setIcon(COLUMN_NAME, sslIcon);
for (int i = 0; i < COLUMN_COUNT; ++i) {
sslItem -> setTextColor(i, sslColor);
sslItem -> setFont(i, sslFont);
}
}
QIcon gpgIcon;
if (gpg_connected) {
gpgItem->setHidden(false);
++onlineCount;
if (bestPeerState == 0) {
// show as online
bestPeerState = PEER_STATE_ONLINE;
bestRSState = RS_STATUS_ONLINE;
}
QColor textColor = mTextColorStatus[bestRSState];
QFont font = StatusDefs::font(bestRSState);
for(int i = 0; i < COLUMN_COUNT; ++i) {
gpgItem->setTextColor(i, textColor);
gpgItem->setFont(i, font);
}
gpgIcon = QIcon(StatusDefs::imageStatus(bestRSState));
if (!isStatusColumnHidden) {
gpgItem->setText(COLUMN_STATE, StatusDefs::name(bestRSState));
}
if (isStatusColumnHidden && mBigName && !mHideState) {
if (bestCustomStateString.isEmpty()) {
gpgItemText += "\n" + StatusDefs::name(bestRSState);
} else {
gpgItemText += "\n" + bestCustomStateString;
}
} else if (isStatusColumnHidden && !mHideState){
gpgItemText += " - " + StatusDefs::name(bestRSState);
}
} else if (gpg_online) {
if (!isStatusColumnHidden) {
gpgItem->setText(COLUMN_STATE, tr("Available"));
} else if (!mHideState && !mBigName) {
gpgItemText += " - " + tr("Available") ;
}
bestPeerState = PEER_STATE_AVAILABLE;
++onlineCount;
gpgItem->setHidden(mHideUnconnected);
gpgIcon = QIcon(IMAGE_AVAILABLE);
QFont font;
font.setBold(true);
QColor textColor = mTextColorStatus[RS_STATUS_ONLINE];
for(int i = 0; i < COLUMN_COUNT; ++i) {
gpgItem->setTextColor(i, textColor);
gpgItem->setFont(i,font);
}
} else { } else {
if (!isStatusColumnHidden) { sslItem->setHidden(mHideUnconnected);
gpgItem->setText(COLUMN_STATE, StatusDefs::name(RS_STATUS_OFFLINE)); if (sslDetail.connectState) {
} else if (!mHideState && !mBigName) { sslIcon = QIcon(":/images/connect_creating.png");
gpgItemText += " - " + StatusDefs::name(RS_STATUS_OFFLINE) ; } else {
sslIcon = QIcon(":/images/connect_no.png");
} }
bestPeerState = PEER_STATE_OFFLINE; sslFont.setBold(false);
gpgItem->setHidden(mHideUnconnected); sslColor = mTextColorStatus[RS_STATUS_OFFLINE];
gpgIcon = QIcon(StatusDefs::imageStatus(RS_STATUS_OFFLINE));
QColor textColor = mTextColorStatus[RS_STATUS_OFFLINE];
QFont font = StatusDefs::font(RS_STATUS_OFFLINE);
for(int i = 0; i < COLUMN_COUNT; ++i) {
gpgItem->setTextColor(i, textColor);
gpgItem->setFont(i, font);
}
} }
if (gpg_hasPrivateChat) { if (std::find(privateChatIds.begin(), privateChatIds.end(), sslDetail.id) != privateChatIds.end()) {
gpgIcon = QIcon(":/images/chat.png"); // private chat is available
sslIcon = QIcon(":/images/chat.png");
gpg_hasPrivateChat = true;
} }
sslItem -> setIcon(COLUMN_NAME, sslIcon);
if (!isAvatarColumnHidden && gpgItem->icon(COLUMN_AVATAR).isNull()) { for (int i = 0; i < COLUMN_COUNT; ++i) {
// only set the avatar image the first time, or when it changed sslItem -> setTextColor(i, sslColor);
// otherwise getAvatarFromSslId sends request packages to peers. sslItem -> setFont(i, sslFont);
QPixmap avatar;
AvatarDefs::getAvatarFromSslId(bestSslId, avatar);
QIcon avatar_icon(avatar);
gpgItem->setIcon(COLUMN_AVATAR, avatar_icon);
}
gpgItem->setText(COLUMN_NAME, gpgItemText);
gpgItem->setData(COLUMN_NAME, ROLE_SORT, "2 " + gpgItemText);
gpgItem->setData(COLUMN_STATE, ROLE_SORT, "2 " + BuildStateSortString(true, gpgItemText, bestPeerState));
gpgItem->setIcon(COLUMN_NAME, gpgIcon);
gpgItem->setData(COLUMN_LAST_CONTACT, Qt::DisplayRole, QVariant(lastContact));
gpgItem->setData(COLUMN_LAST_CONTACT, ROLE_SORT, "2 " + lastContact.toString("yyyyMMdd_hhmmss"));
gpgItem->setData(COLUMN_IP, Qt::DisplayRole, QVariant());
gpgItem->setData(COLUMN_IP, ROLE_SORT, "2 " + itemIP);
if (openPeers != NULL && openPeers->find(gpgId.toStdString()) != openPeers->end()) {
gpgItem->setExpanded(true);
} }
} }
QIcon gpgIcon;
if (gpg_connected) {
gpgItem->setHidden(false);
++onlineCount;
if (bestPeerState == 0) {
// show as online
bestPeerState = PEER_STATE_ONLINE;
bestRSState = RS_STATUS_ONLINE;
}
QColor textColor = mTextColorStatus[bestRSState];
QFont font = StatusDefs::font(bestRSState);
for(int i = 0; i < COLUMN_COUNT; ++i) {
gpgItem->setTextColor(i, textColor);
gpgItem->setFont(i, font);
}
gpgIcon = QIcon(StatusDefs::imageStatus(bestRSState));
if (!isStatusColumnHidden) {
gpgItem->setText(COLUMN_STATE, StatusDefs::name(bestRSState));
}
if (isStatusColumnHidden && mBigName && !mHideState) {
if (bestCustomStateString.isEmpty()) {
gpgItemText += "\n" + StatusDefs::name(bestRSState);
} else {
gpgItemText += "\n" + bestCustomStateString;
}
} else if (isStatusColumnHidden && !mHideState){
gpgItemText += " - " + StatusDefs::name(bestRSState);
}
} else if (gpg_online) {
if (!isStatusColumnHidden) {
gpgItem->setText(COLUMN_STATE, tr("Available"));
} else if (!mHideState && !mBigName) {
gpgItemText += " - " + tr("Available") ;
}
bestPeerState = PEER_STATE_AVAILABLE;
++onlineCount;
gpgItem->setHidden(mHideUnconnected);
gpgIcon = QIcon(IMAGE_AVAILABLE);
QFont font;
font.setBold(true);
QColor textColor = mTextColorStatus[RS_STATUS_ONLINE];
for(int i = 0; i < COLUMN_COUNT; ++i) {
gpgItem->setTextColor(i, textColor);
gpgItem->setFont(i,font);
}
} else {
if (!isStatusColumnHidden) {
gpgItem->setText(COLUMN_STATE, StatusDefs::name(RS_STATUS_OFFLINE));
} else if (!mHideState && !mBigName) {
gpgItemText += " - " + StatusDefs::name(RS_STATUS_OFFLINE) ;
}
bestPeerState = PEER_STATE_OFFLINE;
gpgItem->setHidden(mHideUnconnected);
gpgIcon = QIcon(StatusDefs::imageStatus(RS_STATUS_OFFLINE));
QColor textColor = mTextColorStatus[RS_STATUS_OFFLINE];
QFont font = StatusDefs::font(RS_STATUS_OFFLINE);
for(int i = 0; i < COLUMN_COUNT; ++i) {
gpgItem->setTextColor(i, textColor);
gpgItem->setFont(i, font);
}
}
if (gpg_hasPrivateChat) {
gpgIcon = QIcon(":/images/chat.png");
}
if (!isAvatarColumnHidden && gpgItem->icon(COLUMN_AVATAR).isNull()) {
// only set the avatar image the first time, or when it changed
// otherwise getAvatarFromSslId sends request packages to peers.
QPixmap avatar;
AvatarDefs::getAvatarFromSslId(bestSslId, avatar);
QIcon avatar_icon(avatar);
gpgItem->setIcon(COLUMN_AVATAR, avatar_icon);
}
gpgItem->setText(COLUMN_NAME, gpgItemText);
gpgItem->setData(COLUMN_NAME, ROLE_SORT, "2 " + gpgItemText);
gpgItem->setData(COLUMN_STATE, ROLE_SORT, "2 " + BuildStateSortString(true, gpgItemText, bestPeerState));
gpgItem->setIcon(COLUMN_NAME, gpgIcon);
gpgItem->setData(COLUMN_LAST_CONTACT, Qt::DisplayRole, QVariant(lastContact));
gpgItem->setData(COLUMN_LAST_CONTACT, ROLE_SORT, "2 " + lastContact.toString("yyyyMMdd_hhmmss"));
gpgItem->setData(COLUMN_IP, Qt::DisplayRole, QVariant());
gpgItem->setData(COLUMN_IP, ROLE_SORT, "2 " + itemIP);
if (openPeers != NULL && openPeers->find(gpgId.toStdString()) != openPeers->end()) {
gpgItem->setExpanded(true);
}
}
if (groupInfo && groupItem) { if (groupInfo && groupItem) {
if ((groupInfo->flag & RS_GROUP_FLAG_STANDARD) && groupItem->childCount() == 0) { if ((groupInfo->flag & RS_GROUP_FLAG_STANDARD) && groupItem->childCount() == 0) {
// there are some dead id's assigned // there are some dead id's assigned

View File

@ -228,7 +228,7 @@ QString StatusDefs::connectStateWithoutTransportTypeString(RsPeerDetails &detail
QString StatusDefs::connectStateIpString(RsPeerDetails &details) QString StatusDefs::connectStateIpString(RsPeerDetails &details)
{ {
QString stateString = QString(details.connectAddr.c_str()) + QString(" ["); QString stateString = QString("");
switch (details.connectState) { switch (details.connectState) {
case 0: case 0:
@ -249,7 +249,9 @@ QString StatusDefs::connectStateIpString(RsPeerDetails &details)
stateString += qApp->translate("StatusDefs", "unkown"); stateString += qApp->translate("StatusDefs", "unkown");
break; break;
} }
stateString += QString("]"); stateString += QString(" : ");
stateString += QString(details.connectAddr.c_str()) ;
return stateString; return stateString;
} }