void PeerItem::updateItem() { if (!rsPeers) return; /* fill in */ #ifdef DEBUG_ITEM std::cerr << "PeerItem::updateItem()"; std::cerr << std::endl; #endif if(!RsAutoUpdatePage::eventsLocked()) { RsPeerDetails details; if (!rsPeers->getPeerDetails(mPeerId, details)) { chatButton->setEnabled(false); quickmsgButton->setEnabled(false); return; } /* top Level info */ QString status = StatusDefs::peerStateString(details.state); #if 0 /* Append additional status info from status service */ StatusInfo statusInfo; if ((rsStatus) && (rsStatus->getStatus(*it, statusInfo))) { status.append(QString::fromStdString("/" + RsStatusString(statusInfo.status))); } #endif statusLabel->setText(status); trustLabel->setText(QString::fromStdString(RsPeerTrustString(details.trustLvl))); ipLabel->setText(QString("%1:%2/%3:%4").arg(QString::fromStdString(details.localAddr)).arg(details.localPort).arg(QString::fromStdString(details.extAddr)).arg(details.extPort)); connLabel->setText(StatusDefs::connectStateString(details)); /* do buttons */ chatButton->setEnabled(details.state & RS_PEER_STATE_CONNECTED); if (details.state & RS_PEER_STATE_FRIEND) { quickmsgButton->setEnabled(true); } else { quickmsgButton->setEnabled(false); } } /* slow Tick */ int msec_rate = 10129; QTimer::singleShot( msec_rate, this, SLOT(updateItem( void ) )); return; }
/* get the list of peers from the RsIface. */ void PeersDialog::insertPeers() { std::list<std::string> peers; std::list<std::string>::iterator it; if (!rsPeers) { /* not ready yet! */ return; } rsPeers->getFriendList(peers); /* get a link to the table */ QTreeWidget *peerWidget = ui.peertreeWidget; QTreeWidgetItem *oldSelect = getCurrentPeer(); QTreeWidgetItem *newSelect = NULL; time_t now = time(NULL); std::string oldId; if (oldSelect) { oldId = (oldSelect -> text(7)).toStdString(); } /* remove old items ??? */ peerWidget->clear(); peerWidget->setColumnCount(3); QList<QTreeWidgetItem *> items; for(it = peers.begin(); it != peers.end(); it++) { RsPeerDetails detail; if (!rsPeers->getPeerDetails(*it, detail)) { continue; /* BAD */ } /* make a widget per friend */ QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0); /* add all the labels */ /* First 5 (1-5) Key Items */ /* () Status Icon */ item -> setText(0, ""); /* (0) Status */ QString status = QString::fromStdString(RsPeerStateString(detail.state)); /* Append additional status info from status service */ StatusInfo statusInfo; if ((rsStatus) && (rsStatus->getStatus(*it, statusInfo))) { status.append(QString::fromStdString("/" + RsStatusString(statusInfo.status))); } //item -> setText(1, status); item -> setText(1, QString::fromStdString(detail.autoconnect)); item -> setTextAlignment(1, Qt::AlignCenter | Qt::AlignVCenter ); /* (1) Person */ item -> setText(2, QString::fromStdString(detail.name)); /* (2) Auto Connect */ //item -> setText(3, QString::fromStdString(detail.autoconnect)); item -> setText(3, status); /* (3) Trust Level */ item -> setText(4,QString::fromStdString( RsPeerTrustString(detail.trustLvl))); /* (4) Peer Address */ { std::ostringstream out; out << detail.localAddr << ":"; out << detail.localPort << "/"; out << detail.extAddr << ":"; out << detail.extPort; item -> setText(5, QString::fromStdString(out.str())); } /* less important ones */ /* () Last Contact */ item -> setText(6,QString::fromStdString( RsPeerLastConnectString(now - detail.lastConnect))); /* () Org */ //item -> setText(7, QString::fromStdString(detail.org)); /* () Location */ //item -> setText(8, QString::fromStdString(detail.location)); /* () Email */ //item -> setText(9, QString::fromStdString(detail.email)); /* Hidden ones: RsCertId */ { item -> setText(7, QString::fromStdString(detail.id)); if ((oldSelect) && (oldId == detail.id)) { newSelect = item; } } /* () AuthCode */ // item -> setText(11, QString::fromStdString(detail.authcode)); /* change background */ int i; if (detail.state & RS_PEER_STATE_CONNECTED) { /* bright green */ for(i = 1; i < 8; i++) { // CsoLer: I uncommented the color because it's really confortable // to be able to see at some distance that people are connected. // The blue/gray icons need a close look indeed. //item -> setBackground(i,QBrush(Qt::green)) item -> setTextColor(i,(Qt::darkBlue)); QFont font ; font.setBold(true); item -> setFont(i,font); item -> setIcon(0,(QIcon(IMAGE_ONLINE))); } } else if (detail.state & RS_PEER_STATE_UNREACHABLE) { /* bright green */ for(i = 1; i < 8; i++) { item -> setBackground(i,QBrush(Qt::red)); item -> setIcon(0,(QIcon(IMAGE_OFFLINE))); } } else if (detail.state & RS_PEER_STATE_ONLINE) { /* bright green */ for(i = 1; i < 8; i++) { //item -> setBackground(i,QBrush(Qt::cyan)); item -> setTextColor(i,(Qt::darkCyan)); QFont font ; font.setBold(true); item -> setFont(i,font); item -> setIcon(0,(QIcon(IMAGE_AVAIBLE))); } } else { if (now - detail.lastConnect < 3600) { for(i = 1; i < 8; i++) { //item -> setBackground(i,QBrush(Qt::lightGray)); item -> setIcon(0,(QIcon(IMAGE_OFFLINE))); } } else { for(i = 1; i < 8; i++) { //item -> setBackground(i,QBrush(Qt::gray)); item -> setIcon(0,(QIcon(IMAGE_OFFLINE2))); } } } /* add to the list */ items.append(item); } /* add the items in! */ peerWidget->insertTopLevelItems(0, items); if (newSelect) { peerWidget->setCurrentItem(newSelect); } peerWidget->update(); /* update display */ }
void SecurityItem::updateItem() { if (!rsPeers) return; /* fill in */ #ifdef DEBUG_ITEM std::cerr << "SecurityItem::updateItem()"; std::cerr << std::endl; #endif if(!RsAutoUpdatePage::eventsLocked()) { RsPeerDetails details; /* first try sslid */ if (!rsPeers->getPeerDetails(mSslId, details)) { /* then gpgid */ if(!rsPeers->getGPGDetails(mGpgId, details)) { /* it is very likely that we will end up here for some of the * Unknown peer cases.... so allow them here */ /* set peer name */ peerNameLabel->setText(QString("%1 (%2)").arg(tr("Unknown Peer"), QString::fromUtf8(mSslCn.c_str()))); nameLabel->setText(QString::fromUtf8(mSslCn.c_str()) + " (" + QString::fromStdString(mGpgId.toStdString()) + ")"); idLabel->setText(QString::fromStdString(mSslId.toStdString())); statusLabel->setText(tr("Unknown Peer")); trustLabel->setText(tr("Unknown Peer")); locLabel->setText(tr("Unknown Peer")); ipLabel->setText(QString::fromStdString(mIP)) ; //tr("Unknown Peer")); connLabel->setText(tr("Unknown Peer")); chatButton->hide(); //quickmsgButton->hide(); requestLabel->hide(); removeFriendButton->setEnabled(false); removeFriendButton->hide(); peerDetailsButton->setEnabled(false); return; } } /* set peer name */ peerNameLabel->setText(QString::fromUtf8(details.name.c_str())); /* expanded Info */ nameLabel->setText(QString::fromUtf8(details.name.c_str()) + " (" + QString::fromStdString(mGpgId.toStdString()) + ")"); //idLabel->setText(QString::fromStdString(details.id)); idLabel->setText(QString::fromStdString(mSslId.toStdString())); locLabel->setText(QString::fromUtf8(details.location.c_str())); /* top Level info */ QString status = StatusDefs::peerStateString(details.state); #if 0 /* Append additional status info from status service */ StatusInfo statusInfo; if ((rsStatus) && (rsStatus->getStatus(*it, statusInfo))) { status.append(QString::fromStdString("/" + RsStatusString(statusInfo.status))); } #endif statusLabel->setText(status); trustLabel->setText(QString::fromStdString(RsPeerTrustString(details.trustLvl))); ipLabel->setText(QString::fromStdString(mIP)) ; //QString("%1:%2/%3:%4").arg(QString::fromStdString(details.localAddr)).arg(details.localPort).arg(QString::fromStdString(details.extAddr)).arg(details.extPort)); connLabel->setText(StatusDefs::connectStateString(details)); /* do buttons */ peerDetailsButton->setEnabled(true); if (details.state & RS_PEER_STATE_CONNECTED) { chatButton->show(); } else { chatButton->hide(); } if (details.accept_connection) { friendRequesttoolButton->hide(); requestLabel->hide(); removeFriendButton->setEnabled(true); removeFriendButton->show(); } else { friendRequesttoolButton->show(); requestLabel->show(); removeFriendButton->setEnabled(false); removeFriendButton->hide(); } //quickmsgButton->show(); } /* slow Tick */ int msec_rate = 10129; QTimer::singleShot( msec_rate, this, SLOT(updateItem( void ) )); return; }
void SecurityItem::updateItem() { if (!rsPeers) return; /* fill in */ #ifdef DEBUG_ITEM std::cerr << "SecurityItem::updateItem()"; std::cerr << std::endl; #endif if(!RsAutoUpdatePage::eventsLocked()) { /* set textcolor for peer name */ QString nameStr("<span style=\"font-size:14pt; font-weight:500;color:#990033;\">%1</span>"); RsPeerDetails details; /* first try sslid */ if (!rsPeers->getPeerDetails(mSslId, details)) { /* then gpgid */ if (!rsPeers->getPeerDetails(mGpgId, details)) { /* it is very likely that we will end up here for some of the * Unknown peer cases.... so allow them here */ /* set peer name */ peernameLabel->setText(nameStr.arg(tr("Unknown Peer"))); nameLabel->setText(QString::fromStdString(mGpgId)); idLabel->setText(QString::fromStdString(mSslId)); statusLabel->setText(tr("Unknown Peer")); trustLabel->setText(tr("Unknown Peer")); locLabel->setText(tr("Unknown Peer")); ipLabel->setText(tr("Unknown Peer")); connLabel->setText(tr("Unknown Peer")); chatButton->setEnabled(false); quickmsgButton->setEnabled(false); addFriendButton->setEnabled(false); addFriendButton->show(); removeFriendButton->setEnabled(false); removeFriendButton->hide(); peerDetailsButton->setEnabled(false); return; } } /* set peer name */ QString peername = QString::fromUtf8(details.name.c_str()); peernameLabel->setText(nameStr.arg(peername)); /* expanded Info */ nameLabel->setText(QString::fromUtf8(details.name.c_str())); idLabel->setText(QString::fromStdString(details.id)); locLabel->setText(QString::fromUtf8(details.location.c_str())); /* top Level info */ QString status = StatusDefs::peerStateString(details.state); #if 0 /* Append additional status info from status service */ StatusInfo statusInfo; if ((rsStatus) && (rsStatus->getStatus(*it, statusInfo))) { status.append(QString::fromStdString("/" + RsStatusString(statusInfo.status))); } #endif statusLabel->setText(status); trustLabel->setText(QString::fromStdString(RsPeerTrustString(details.trustLvl))); { std::ostringstream out; out << details.localAddr << ":"; out << details.localPort << "/"; out << details.extAddr << ":"; out << details.extPort; ipLabel->setText(QString::fromStdString(out.str())); } connLabel->setText(StatusDefs::connectStateString(details)); /* do buttons */ chatButton->setEnabled(details.state & RS_PEER_STATE_CONNECTED); peerDetailsButton->setEnabled(true); if (details.accept_connection) { addFriendButton->setEnabled(false); addFriendButton->hide(); removeFriendButton->setEnabled(true); removeFriendButton->show(); } else { addFriendButton->setEnabled(true); addFriendButton->show(); removeFriendButton->setEnabled(false); removeFriendButton->hide(); } if (details.state & RS_PEER_STATE_FRIEND) { quickmsgButton->setEnabled(true); } else { quickmsgButton->setEnabled(false); } } /* slow Tick */ int msec_rate = 10129; QTimer::singleShot( msec_rate, this, SLOT(updateItem( void ) )); return; }