2018-11-13 16:02:26 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
* gui/feeds/PeerItem.cpp *
|
|
|
|
* *
|
|
|
|
* Copyright (c) 2008, Robert Fernie <retroshare.project@gmail.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Affero General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2010-07-23 14:52:58 -04:00
|
|
|
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QTimer>
|
2008-06-20 08:43:23 -04:00
|
|
|
|
|
|
|
#include "PeerItem.h"
|
|
|
|
#include "FeedHolder.h"
|
2012-02-19 10:03:07 -05:00
|
|
|
#include "retroshare-gui/RsAutoUpdatePage.h"
|
2010-07-23 14:52:58 -04:00
|
|
|
#include "gui/msgs/MessageComposer.h"
|
2011-01-06 13:26:39 -05:00
|
|
|
#include "gui/common/StatusDefs.h"
|
2011-09-02 06:22:44 -04:00
|
|
|
#include "gui/common/AvatarDefs.h"
|
2012-11-15 16:35:37 -05:00
|
|
|
#include "util/DateTime.h"
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2010-08-31 18:42:40 -04:00
|
|
|
#include "gui/notifyqt.h"
|
|
|
|
|
2010-08-06 05:40:23 -04:00
|
|
|
#include <retroshare/rsmsgs.h>
|
|
|
|
#include <retroshare/rspeers.h>
|
2017-04-27 10:42:25 -04:00
|
|
|
#include <retroshare/rsrtt.h>
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2008-07-09 05:53:47 -04:00
|
|
|
/*****
|
|
|
|
* #define DEBUG_ITEM 1
|
|
|
|
****/
|
2008-06-20 08:43:23 -04:00
|
|
|
|
|
|
|
/** Constructor */
|
2014-11-15 12:24:49 -05:00
|
|
|
PeerItem::PeerItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &peerId, uint32_t type, bool isHome) :
|
|
|
|
FeedItem(NULL), mParent(parent), mFeedId(feedId),
|
|
|
|
mPeerId(peerId), mType(type), mIsHome(isHome)
|
2008-06-20 08:43:23 -04:00
|
|
|
{
|
2010-09-08 14:46:30 -04:00
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
setupUi(this);
|
|
|
|
|
2010-09-08 18:46:26 -04:00
|
|
|
sendmsgButton->setEnabled(false);
|
2010-09-08 14:46:30 -04:00
|
|
|
|
|
|
|
/* general ones */
|
|
|
|
connect( expandButton, SIGNAL( clicked( void ) ), this, SLOT( toggle ( void ) ) );
|
|
|
|
connect( clearButton, SIGNAL( clicked( void ) ), this, SLOT( removeItem ( void ) ) );
|
|
|
|
|
|
|
|
/* specific ones */
|
|
|
|
connect( chatButton, SIGNAL( clicked( void ) ), this, SLOT( openChat ( void ) ) );
|
2014-12-06 10:29:41 -05:00
|
|
|
connect( sendmsgButton, SIGNAL( clicked( ) ), this, SLOT( sendMsg() ) );
|
2010-09-08 14:46:30 -04:00
|
|
|
|
2011-08-21 18:28:19 -04:00
|
|
|
connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), this, SLOT(updateItem()));
|
|
|
|
|
2015-02-07 17:43:53 -05:00
|
|
|
avatar->setId(ChatId(mPeerId));// TODO: remove unnecesary converstation
|
2011-09-05 17:19:07 -04:00
|
|
|
|
2012-11-10 13:59:58 -05:00
|
|
|
expandFrame->hide();
|
|
|
|
|
2010-09-08 14:46:30 -04:00
|
|
|
updateItemStatic();
|
|
|
|
updateItem();
|
2008-06-20 08:43:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-27 10:42:25 -04:00
|
|
|
bool PeerItem::isSame(const RsPeerId &peerId, uint32_t type)
|
|
|
|
{
|
|
|
|
if ((mPeerId == peerId) && (mType == type))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
void PeerItem::updateItemStatic()
|
|
|
|
{
|
|
|
|
if (!rsPeers)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* fill in */
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "PeerItem::updateItemStatic()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2011-08-21 18:28:19 -04:00
|
|
|
QString title;
|
|
|
|
|
|
|
|
switch(mType)
|
2008-06-20 08:43:23 -04:00
|
|
|
{
|
2011-08-21 18:28:19 -04:00
|
|
|
case PEER_TYPE_STD:
|
2012-02-01 07:21:14 -05:00
|
|
|
title = tr("Friend");
|
2011-08-21 18:28:19 -04:00
|
|
|
break;
|
|
|
|
case PEER_TYPE_CONNECT:
|
2012-02-01 07:21:14 -05:00
|
|
|
title = tr("Friend Connected");
|
2011-08-21 18:28:19 -04:00
|
|
|
break;
|
|
|
|
case PEER_TYPE_HELLO:
|
2012-02-01 07:21:14 -05:00
|
|
|
title = tr("Connect Attempt");
|
2011-08-21 18:28:19 -04:00
|
|
|
break;
|
|
|
|
case PEER_TYPE_NEW_FOF:
|
2012-02-01 07:21:14 -05:00
|
|
|
title = tr("Friend of Friend");
|
2011-08-21 18:28:19 -04:00
|
|
|
break;
|
2017-04-27 10:42:25 -04:00
|
|
|
case PEER_TYPE_OFFSET:
|
|
|
|
title = tr("Friend Time Offset");
|
|
|
|
break;
|
2011-08-21 18:28:19 -04:00
|
|
|
default:
|
2012-02-01 07:21:14 -05:00
|
|
|
title = tr("Peer");
|
2011-08-21 18:28:19 -04:00
|
|
|
break;
|
|
|
|
}
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2011-08-21 18:28:19 -04:00
|
|
|
titleLabel->setText(title);
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2011-08-21 18:28:19 -04:00
|
|
|
RsPeerDetails details;
|
2014-03-17 16:56:06 -04:00
|
|
|
if (rsPeers->getPeerDetails(RsPeerId(mPeerId), details))
|
2011-08-21 18:28:19 -04:00
|
|
|
{
|
|
|
|
/* set peer name */
|
2012-09-07 13:30:23 -04:00
|
|
|
peerNameLabel->setText(QString::fromUtf8(details.name.c_str()));
|
2012-11-15 16:35:37 -05:00
|
|
|
lastLabel-> setText(DateTime::formatLongDateTime(details.lastConnect));
|
2010-11-06 15:13:33 -04:00
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
/* expanded Info */
|
2011-05-08 19:11:27 -04:00
|
|
|
nameLabel->setText(QString::fromUtf8(details.name.c_str()));
|
2017-04-27 10:42:25 -04:00
|
|
|
idLabel->setText(QString::fromStdString(details.id.toStdString()));
|
2011-05-08 19:11:27 -04:00
|
|
|
locLabel->setText(QString::fromUtf8(details.location.c_str()));
|
2017-04-27 10:42:25 -04:00
|
|
|
|
|
|
|
if (rsRtt)
|
|
|
|
{
|
|
|
|
double offset = rsRtt->getMeanOffset(RsPeerId(mPeerId));
|
|
|
|
offsetLabel->setText(QString::number(offset,'f',2).append(" s"));
|
|
|
|
}
|
2008-06-20 08:43:23 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-08-21 18:28:19 -04:00
|
|
|
statusLabel->setText(tr("Unknown Peer"));
|
|
|
|
titleLabel->setText(tr("Unknown Peer"));
|
|
|
|
trustLabel->setText(tr("Unknown Peer"));
|
|
|
|
nameLabel->setText(tr("Unknown Peer"));
|
|
|
|
idLabel->setText(tr("Unknown Peer"));
|
|
|
|
locLabel->setText(tr("Unknown Peer"));
|
|
|
|
ipLabel->setText(tr("Unknown Peer"));
|
|
|
|
connLabel->setText(tr("Unknown Peer"));
|
|
|
|
lastLabel->setText(tr("Unknown Peer"));
|
2008-06-20 08:43:23 -04:00
|
|
|
|
|
|
|
chatButton->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mIsHome)
|
|
|
|
{
|
|
|
|
/* disable buttons */
|
|
|
|
clearButton->setEnabled(false);
|
2008-07-04 10:41:24 -04:00
|
|
|
|
2011-08-21 18:28:19 -04:00
|
|
|
/* hide buttons */
|
2008-07-04 10:41:24 -04:00
|
|
|
clearButton->hide();
|
2008-06-20 08:43:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeerItem::updateItem()
|
|
|
|
{
|
|
|
|
if (!rsPeers)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* fill in */
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "PeerItem::updateItem()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2010-04-28 07:25:12 -04:00
|
|
|
if(!RsAutoUpdatePage::eventsLocked()) {
|
|
|
|
RsPeerDetails details;
|
|
|
|
if (!rsPeers->getPeerDetails(mPeerId, details))
|
|
|
|
{
|
2011-08-21 18:28:19 -04:00
|
|
|
chatButton->setEnabled(false);
|
2014-12-06 10:29:41 -05:00
|
|
|
sendmsgButton->setEnabled(false);
|
2011-08-21 18:28:19 -04:00
|
|
|
|
2010-04-28 07:25:12 -04:00
|
|
|
return;
|
|
|
|
}
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2010-04-28 07:25:12 -04:00
|
|
|
/* top Level info */
|
2011-01-06 13:26:39 -05:00
|
|
|
QString status = StatusDefs::peerStateString(details.state);
|
2008-06-20 08:43:23 -04:00
|
|
|
|
|
|
|
#if 0
|
2010-04-28 07:25:12 -04:00
|
|
|
/* Append additional status info from status service */
|
|
|
|
StatusInfo statusInfo;
|
|
|
|
if ((rsStatus) && (rsStatus->getStatus(*it, statusInfo)))
|
|
|
|
{
|
|
|
|
status.append(QString::fromStdString("/" + RsStatusString(statusInfo.status)));
|
|
|
|
}
|
2008-06-20 08:43:23 -04:00
|
|
|
#endif
|
2010-04-28 07:25:12 -04:00
|
|
|
statusLabel->setText(status);
|
2011-08-21 18:28:19 -04:00
|
|
|
trustLabel->setText(QString::fromStdString(RsPeerTrustString(details.trustLvl)));
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2012-03-28 14:02:49 -04:00
|
|
|
ipLabel->setText(QString("%1:%2/%3:%4").arg(QString::fromStdString(details.localAddr)).arg(details.localPort).arg(QString::fromStdString(details.extAddr)).arg(details.extPort));
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2011-01-06 13:26:39 -05:00
|
|
|
connLabel->setText(StatusDefs::connectStateString(details));
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2010-04-28 07:25:12 -04:00
|
|
|
/* do buttons */
|
|
|
|
chatButton->setEnabled(details.state & RS_PEER_STATE_CONNECTED);
|
|
|
|
if (details.state & RS_PEER_STATE_FRIEND)
|
|
|
|
{
|
2014-12-06 10:29:41 -05:00
|
|
|
sendmsgButton->setEnabled(true);
|
2010-04-28 07:25:12 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-06 10:29:41 -05:00
|
|
|
sendmsgButton->setEnabled(false);
|
2010-04-28 07:25:12 -04:00
|
|
|
}
|
2017-04-27 10:42:25 -04:00
|
|
|
|
|
|
|
if (rsRtt)
|
|
|
|
{
|
|
|
|
double offset = rsRtt->getMeanOffset(RsPeerId(mPeerId));
|
|
|
|
offsetLabel->setText(QString::number(offset,'f',2).append(" s"));
|
|
|
|
}
|
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
}
|
2010-04-28 07:25:12 -04:00
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
/* slow Tick */
|
|
|
|
int msec_rate = 10129;
|
2010-08-12 11:07:09 -04:00
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
QTimer::singleShot( msec_rate, this, SLOT(updateItem( void ) ));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeerItem::toggle()
|
|
|
|
{
|
2014-11-15 12:24:49 -05:00
|
|
|
expand(expandFrame->isHidden());
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:59:12 -04:00
|
|
|
void PeerItem::doExpand(bool open)
|
2014-11-15 12:24:49 -05:00
|
|
|
{
|
|
|
|
if (mParent) {
|
|
|
|
mParent->lockLayout(this, true);
|
|
|
|
}
|
2012-10-08 19:06:34 -04:00
|
|
|
|
2014-11-15 12:24:49 -05:00
|
|
|
if (open)
|
2008-06-20 08:43:23 -04:00
|
|
|
{
|
|
|
|
expandFrame->show();
|
2019-10-09 12:06:30 -04:00
|
|
|
expandButton->setIcon(QIcon(QString(":/icons/png/up-arrow.png")));
|
2011-08-21 18:28:19 -04:00
|
|
|
expandButton->setToolTip(tr("Hide"));
|
2008-06-20 08:43:23 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
expandFrame->hide();
|
2019-10-09 12:06:30 -04:00
|
|
|
expandButton->setIcon(QIcon(QString(":/icons/png/down-arrow.png")));
|
2011-08-21 18:28:19 -04:00
|
|
|
expandButton->setToolTip(tr("Expand"));
|
2008-06-20 08:43:23 -04:00
|
|
|
}
|
2012-10-08 19:06:34 -04:00
|
|
|
|
2014-11-15 12:24:49 -05:00
|
|
|
emit sizeChanged(this);
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2014-11-15 12:24:49 -05:00
|
|
|
if (mParent) {
|
|
|
|
mParent->lockLayout(this, false);
|
|
|
|
}
|
|
|
|
}
|
2008-06-20 08:43:23 -04:00
|
|
|
|
|
|
|
void PeerItem::removeItem()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "PeerItem::removeItem()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2012-10-08 19:06:34 -04:00
|
|
|
|
|
|
|
mParent->lockLayout(this, true);
|
2008-06-20 08:43:23 -04:00
|
|
|
hide();
|
2012-10-08 19:06:34 -04:00
|
|
|
mParent->lockLayout(this, false);
|
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
if (mParent)
|
|
|
|
{
|
|
|
|
mParent->deleteFeedItem(this, mFeedId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********** SPECIFIC FUNCTIOSN ***********************/
|
|
|
|
|
|
|
|
void PeerItem::addFriend()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "PeerItem::addFriend()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeerItem::removeFriend()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "PeerItem::removeFriend()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeerItem::sendMsg()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "PeerItem::sendMsg()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2010-11-02 17:11:11 -04:00
|
|
|
MessageComposer *nMsgDialog = MessageComposer::newMsg();
|
|
|
|
if (nMsgDialog == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2010-05-21 19:49:01 -04:00
|
|
|
|
2014-03-29 10:18:05 -04:00
|
|
|
nMsgDialog->addRecipient(MessageComposer::TO, mPeerId);
|
2010-05-21 19:49:01 -04:00
|
|
|
nMsgDialog->show();
|
|
|
|
nMsgDialog->activateWindow();
|
|
|
|
|
|
|
|
/* window will destroy itself! */
|
2008-06-20 08:43:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PeerItem::openChat()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "PeerItem::openChat()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
if (mParent)
|
|
|
|
{
|
|
|
|
mParent->openChat(mPeerId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|