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"
|
2010-04-28 07:25:12 -04:00
|
|
|
#include "../RsAutoUpdatePage.h"
|
2010-07-23 14:52:58 -04:00
|
|
|
#include "gui/msgs/MessageComposer.h"
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2010-08-06 05:40:23 -04:00
|
|
|
#include <retroshare/rsmsgs.h>
|
|
|
|
#include <retroshare/rspeers.h>
|
2008-06-20 08:43:23 -04:00
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
2008-07-09 05:53:47 -04:00
|
|
|
/*****
|
|
|
|
* #define DEBUG_ITEM 1
|
|
|
|
****/
|
2008-06-20 08:43:23 -04:00
|
|
|
|
|
|
|
/** Constructor */
|
|
|
|
PeerItem::PeerItem(FeedHolder *parent, uint32_t feedId, std::string peerId, uint32_t type, bool isHome)
|
|
|
|
:QWidget(NULL), mParent(parent), mFeedId(feedId),
|
|
|
|
mPeerId(peerId), mType(type), mIsHome(isHome)
|
|
|
|
{
|
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
setupUi(this);
|
|
|
|
|
|
|
|
/* general ones */
|
|
|
|
connect( expandButton, SIGNAL( clicked( void ) ), this, SLOT( toggle ( void ) ) );
|
|
|
|
connect( clearButton, SIGNAL( clicked( void ) ), this, SLOT( removeItem ( void ) ) );
|
2008-07-04 10:41:24 -04:00
|
|
|
//connect( gotoButton, SIGNAL( clicked( void ) ), this, SLOT( gotoHome ( void ) ) );
|
2008-06-20 08:43:23 -04:00
|
|
|
|
|
|
|
/* specific ones */
|
|
|
|
connect( chatButton, SIGNAL( clicked( void ) ), this, SLOT( openChat ( void ) ) );
|
|
|
|
connect( msgButton, SIGNAL( clicked( void ) ), this, SLOT( sendMsg ( void ) ) );
|
2010-08-12 11:07:09 -04:00
|
|
|
//connect( addButton, SIGNAL( clicked( void ) ), this, SLOT( addFriend ( void ) ) );
|
|
|
|
//connect( removeButton, SIGNAL( clicked( void ) ), this, SLOT( removeFriend ( void ) ) );
|
2008-06-20 08:43:23 -04:00
|
|
|
|
|
|
|
small();
|
|
|
|
updateItemStatic();
|
|
|
|
updateItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PeerItem::updateItemStatic()
|
|
|
|
{
|
|
|
|
if (!rsPeers)
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
/* fill in */
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "PeerItem::updateItemStatic()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
RsPeerDetails details;
|
|
|
|
if (rsPeers->getPeerDetails(mPeerId, details))
|
|
|
|
{
|
|
|
|
QString title;
|
|
|
|
|
|
|
|
switch(mType)
|
|
|
|
{
|
|
|
|
case PEER_TYPE_STD:
|
|
|
|
title = "Friend: ";
|
|
|
|
break;
|
|
|
|
case PEER_TYPE_CONNECT:
|
2010-08-12 11:07:09 -04:00
|
|
|
title = "Friend Connected";
|
2008-06-20 08:43:23 -04:00
|
|
|
break;
|
|
|
|
case PEER_TYPE_HELLO:
|
|
|
|
title = "Connect Attempt: ";
|
|
|
|
break;
|
|
|
|
case PEER_TYPE_NEW_FOF:
|
|
|
|
title = "Friend of Friend: ";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
title = "Peer: ";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
titleLabel->setText(title);
|
2010-05-21 20:23:13 -04:00
|
|
|
|
|
|
|
/* set textcolor for peername */
|
|
|
|
QString nameStr("<span style=\"font-size:14pt; font-weight:500;"
|
2010-08-12 11:07:09 -04:00
|
|
|
"color:#990033;\">%1</span>");
|
2010-05-21 20:23:13 -04:00
|
|
|
|
|
|
|
/* set Blog name */
|
|
|
|
QString peername = QString::fromStdString(details.name);
|
|
|
|
peernameLabel->setText(nameStr.arg(peername));
|
2008-06-20 08:43:23 -04:00
|
|
|
|
|
|
|
/* expanded Info */
|
|
|
|
nameLabel->setText(QString::fromStdString(details.name));
|
|
|
|
idLabel->setText(QString::fromStdString(details.id));
|
|
|
|
orgLabel->setText(QString::fromStdString(details.org));
|
|
|
|
locLabel->setText(QString::fromStdString(details.location));
|
|
|
|
countryLabel->setText("");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
statusLabel->setText("Unknown Peer");
|
|
|
|
titleLabel->setText("Unknown Peer");
|
|
|
|
trustLabel->setText("Unknown Peer");
|
|
|
|
nameLabel->setText("Unknown Peer");
|
|
|
|
idLabel->setText("Unknown Peer");
|
|
|
|
orgLabel->setText("Unknown Peer");
|
|
|
|
locLabel->setText("Unknown Peer");
|
|
|
|
countryLabel->setText("Unknown Peer");
|
|
|
|
ipLabel->setText("Unknown Peer");
|
|
|
|
connLabel->setText("Unknown Peer");
|
|
|
|
lastLabel->setText("Unknown Peer");
|
|
|
|
|
|
|
|
chatButton->setEnabled(false);
|
2010-08-12 11:07:09 -04:00
|
|
|
//addButton->setEnabled(false);
|
|
|
|
//removeButton->setEnabled(false);
|
2008-06-20 08:43:23 -04:00
|
|
|
msgButton->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mIsHome)
|
|
|
|
{
|
|
|
|
/* disable buttons */
|
|
|
|
clearButton->setEnabled(false);
|
2008-07-04 10:41:24 -04:00
|
|
|
//gotoButton->setEnabled(false);
|
|
|
|
|
|
|
|
/* disable buttons */
|
|
|
|
clearButton->hide();
|
2008-06-20 08:43:23 -04:00
|
|
|
}
|
2010-08-12 11:07:09 -04:00
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2010-04-28 07:25:12 -04:00
|
|
|
/* top Level info */
|
|
|
|
QString status = QString::fromStdString(RsPeerStateString(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);
|
|
|
|
trustLabel->setText(QString::fromStdString(
|
|
|
|
RsPeerTrustString(details.trustLvl)));
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2010-04-28 07:25:12 -04:00
|
|
|
{
|
|
|
|
std::ostringstream out;
|
|
|
|
out << details.localAddr << ":";
|
|
|
|
out << details.localPort << "/";
|
|
|
|
out << details.extAddr << ":";
|
|
|
|
out << details.extPort;
|
|
|
|
ipLabel->setText(QString::fromStdString(out.str()));
|
|
|
|
}
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2010-04-28 07:25:12 -04:00
|
|
|
connLabel->setText(QString::fromStdString(details.autoconnect));
|
|
|
|
QDateTime date = QDateTime::fromTime_t(details.lastConnect);
|
|
|
|
QString stime = date.toString(Qt::LocalDate);
|
|
|
|
lastLabel-> setText(stime);
|
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-08-12 11:07:09 -04:00
|
|
|
//addButton->setEnabled(false);
|
|
|
|
//removeButton->setEnabled(true);
|
2010-04-28 07:25:12 -04:00
|
|
|
msgButton->setEnabled(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-12 11:07:09 -04:00
|
|
|
//addButton->setEnabled(true);
|
|
|
|
//removeButton->setEnabled(false);
|
2010-04-28 07:25:12 -04:00
|
|
|
msgButton->setEnabled(false);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
loadAvatar();
|
2008-06-20 08:43:23 -04:00
|
|
|
|
|
|
|
QTimer::singleShot( msec_rate, this, SLOT(updateItem( void ) ));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PeerItem::small()
|
|
|
|
{
|
|
|
|
expandFrame->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeerItem::toggle()
|
|
|
|
{
|
|
|
|
if (expandFrame->isHidden())
|
|
|
|
{
|
|
|
|
expandFrame->show();
|
2008-08-17 10:13:09 -04:00
|
|
|
expandButton->setIcon(QIcon(QString(":/images/edit_remove24.png")));
|
|
|
|
expandButton->setToolTip("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")));
|
|
|
|
expandButton->setToolTip("Expand");
|
2008-06-20 08:43:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PeerItem::removeItem()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "PeerItem::removeItem()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
hide();
|
|
|
|
if (mParent)
|
|
|
|
{
|
|
|
|
mParent->deleteFeedItem(this, mFeedId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PeerItem::gotoHome()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "PeerItem::gotoHome()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********** 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
|
|
|
|
|
|
|
|
if (mParent)
|
|
|
|
{
|
2010-05-21 19:49:01 -04:00
|
|
|
//mParent->openMsg(FEEDHOLDER_MSG_MESSAGE, mPeerId, "");
|
|
|
|
|
2010-05-25 05:32:14 -04:00
|
|
|
MessageComposer *nMsgDialog = new MessageComposer();
|
2010-05-21 19:49:01 -04:00
|
|
|
nMsgDialog->newMsg();
|
|
|
|
|
|
|
|
nMsgDialog->addRecipient( mPeerId ) ;
|
|
|
|
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-08-12 11:07:09 -04:00
|
|
|
void PeerItem::loadAvatar()
|
|
|
|
{
|
|
|
|
|
|
|
|
unsigned char *data = NULL;
|
|
|
|
int size = 0 ;
|
|
|
|
|
|
|
|
rsMsgs->getAvatarData(mPeerId,data,size);
|
|
|
|
|
|
|
|
|
|
|
|
if(size != 0)
|
|
|
|
{
|
|
|
|
// set the image
|
|
|
|
QPixmap pix ;
|
|
|
|
pix.loadFromData(data,size,"PNG") ;
|
|
|
|
avatar_label->setPixmap(pix);
|
|
|
|
delete[] data ;
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
avatar_label->setPixmap(QPixmap(":/images/user/personal64.png"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|