2008-06-20 08:43:23 -04:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Robert Fernie
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
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>
|
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-03-17 16:56:06 -04:00
|
|
|
PeerItem::PeerItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &peerId, uint32_t type, bool isHome)
|
2008-06-20 08:43:23 -04:00
|
|
|
:QWidget(NULL), mParent(parent), mFeedId(feedId),
|
|
|
|
mPeerId(peerId), mType(type), mIsHome(isHome)
|
|
|
|
{
|
2010-09-08 14:46:30 -04:00
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
setupUi(this);
|
|
|
|
|
|
|
|
messageframe->setVisible(false);
|
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 ) ) );
|
2010-09-13 10:24:26 -04:00
|
|
|
connect( actionNew_Message, SIGNAL( triggered( ) ), this, SLOT( sendMsg ( void ) ) );
|
2010-09-08 14:46:30 -04:00
|
|
|
|
|
|
|
connect( quickmsgButton, SIGNAL( clicked( ) ), this, SLOT( togglequickmessage() ) );
|
2010-09-08 18:46:26 -04:00
|
|
|
connect( cancelButton, SIGNAL( clicked( ) ), this, SLOT( togglequickmessage() ) );
|
|
|
|
|
2010-09-08 14:46:30 -04:00
|
|
|
connect( sendmsgButton, SIGNAL( clicked( ) ), this, SLOT( sendMessage() ) );
|
|
|
|
|
2011-08-21 18:28:19 -04:00
|
|
|
connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), this, SLOT(updateItem()));
|
|
|
|
|
2010-09-13 10:24:26 -04:00
|
|
|
QMenu *msgmenu = new QMenu();
|
|
|
|
msgmenu->addAction(actionNew_Message);
|
|
|
|
|
|
|
|
quickmsgButton->setMenu(msgmenu);
|
2010-09-08 14:46:30 -04:00
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
avatar->setId(RsPeerId(mPeerId));
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
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()));
|
2014-03-17 16:56:06 -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()));
|
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);
|
|
|
|
quickmsgButton->setEnabled(false);
|
|
|
|
|
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)
|
|
|
|
{
|
2010-09-13 10:24:26 -04:00
|
|
|
quickmsgButton->setEnabled(true);
|
2010-04-28 07:25:12 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-13 10:24:26 -04:00
|
|
|
quickmsgButton->setEnabled(false);
|
2010-04-28 07:25:12 -04:00
|
|
|
}
|
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()
|
|
|
|
{
|
2012-10-08 19:06:34 -04:00
|
|
|
mParent->lockLayout(this, true);
|
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
if (expandFrame->isHidden())
|
|
|
|
{
|
|
|
|
expandFrame->show();
|
2008-08-17 10:13:09 -04:00
|
|
|
expandButton->setIcon(QIcon(QString(":/images/edit_remove24.png")));
|
2011-08-21 18:28:19 -04:00
|
|
|
expandButton->setToolTip(tr("Hide"));
|
2008-06-20 08:43:23 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
expandFrame->hide();
|
2008-08-17 10:13:09 -04:00
|
|
|
expandButton->setIcon(QIcon(QString(":/images/edit_add24.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
|
|
|
|
|
|
|
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
|
|
|
|
2010-09-27 17:05:52 -04:00
|
|
|
nMsgDialog->addRecipient(MessageComposer::TO, mPeerId, false);
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-08 14:46:30 -04:00
|
|
|
void PeerItem::togglequickmessage()
|
|
|
|
{
|
|
|
|
if (messageframe->isHidden())
|
|
|
|
{
|
2012-02-01 07:21:14 -05:00
|
|
|
messageframe->setVisible(true);
|
|
|
|
}
|
2010-09-08 14:46:30 -04:00
|
|
|
else
|
|
|
|
{
|
2012-02-01 07:21:14 -05:00
|
|
|
messageframe->setVisible(false);
|
|
|
|
}
|
2010-09-08 14:46:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void PeerItem::sendMessage()
|
|
|
|
{
|
|
|
|
/* construct a message */
|
|
|
|
MessageInfo mi;
|
|
|
|
|
2013-10-03 17:41:34 -04:00
|
|
|
mi.title = tr("Quick Message").toUtf8().constData();
|
|
|
|
mi.msg = quickmsgText->toHtml().toUtf8().constData();
|
2012-02-01 07:21:14 -05:00
|
|
|
mi.msgto.push_back(mPeerId);
|
2010-09-08 14:46:30 -04:00
|
|
|
|
|
|
|
rsMsgs->MessageSend(mi);
|
|
|
|
|
|
|
|
quickmsgText->clear();
|
|
|
|
messageframe->setVisible(false);
|
|
|
|
}
|
2010-08-12 11:07:09 -04:00
|
|
|
|
2010-09-08 18:46:26 -04:00
|
|
|
void PeerItem::on_quickmsgText_textChanged()
|
|
|
|
{
|
|
|
|
if (quickmsgText->toPlainText().isEmpty())
|
|
|
|
{
|
|
|
|
sendmsgButton->setEnabled(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sendmsgButton->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|