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-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
|
|
|
|
|
|
|
#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)
|
|
|
|
{
|
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() ) );
|
|
|
|
|
|
|
|
connect(NotifyQt::getInstance(), SIGNAL(peerHasNewAvatar(const QString&)), this, SLOT(updateAvatar(const QString&)));
|
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
|
|
|
|
|
|
|
small();
|
|
|
|
updateItemStatic();
|
|
|
|
updateItem();
|
|
|
|
updateAvatar(QString::fromStdString(mPeerId));
|
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
|
|
|
|
|
|
|
|
RsPeerDetails details;
|
|
|
|
if (rsPeers->getPeerDetails(mPeerId, details))
|
|
|
|
{
|
|
|
|
QString title;
|
|
|
|
|
|
|
|
switch(mType)
|
|
|
|
{
|
|
|
|
case PEER_TYPE_STD:
|
2010-09-12 16:27:03 -04:00
|
|
|
title = tr("Friend");
|
2008-06-20 08:43:23 -04:00
|
|
|
break;
|
|
|
|
case PEER_TYPE_CONNECT:
|
2010-09-12 16:27:03 -04:00
|
|
|
title = tr("Friend Connected");
|
2008-06-20 08:43:23 -04:00
|
|
|
break;
|
|
|
|
case PEER_TYPE_HELLO:
|
2010-09-12 16:27:03 -04:00
|
|
|
title = tr("Connect Attempt");
|
2008-06-20 08:43:23 -04:00
|
|
|
break;
|
|
|
|
case PEER_TYPE_NEW_FOF:
|
2010-09-12 16:27:03 -04:00
|
|
|
title = tr("Friend of Friend");
|
2008-06-20 08:43:23 -04:00
|
|
|
break;
|
|
|
|
default:
|
2010-09-12 16:27:03 -04:00
|
|
|
title = tr("Peer");
|
2008-06-20 08:43:23 -04:00
|
|
|
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
|
|
|
|
2010-11-06 15:13:33 -04:00
|
|
|
QDateTime date = QDateTime::fromTime_t(details.lastConnect);
|
|
|
|
QString stime = date.toString(Qt::LocalDate);
|
|
|
|
lastLabel-> setText(stime);
|
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
/* expanded Info */
|
|
|
|
nameLabel->setText(QString::fromStdString(details.name));
|
|
|
|
idLabel->setText(QString::fromStdString(details.id));
|
|
|
|
locLabel->setText(QString::fromStdString(details.location));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-12 16:27:03 -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);
|
2010-09-13 10:24:26 -04:00
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
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-09-13 10:24:26 -04:00
|
|
|
quickmsgButton->setEnabled(true);
|
2010-04-28 07:25:12 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-12 11:07:09 -04:00
|
|
|
//addButton->setEnabled(true);
|
|
|
|
//removeButton->setEnabled(false);
|
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::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")));
|
2010-09-12 16:27:03 -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")));
|
2010-09-12 16:27:03 -04:00
|
|
|
expandButton->setToolTip(tr("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-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-08-31 18:42:40 -04:00
|
|
|
void PeerItem::updateAvatar(const QString &peer_id)
|
2010-08-12 11:07:09 -04:00
|
|
|
{
|
2010-08-31 18:42:40 -04:00
|
|
|
if (peer_id.toStdString() != mPeerId) {
|
|
|
|
/* it 's not me */
|
|
|
|
return;
|
|
|
|
}
|
2010-08-12 11:07:09 -04:00
|
|
|
|
|
|
|
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"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-09-08 14:46:30 -04:00
|
|
|
void PeerItem::togglequickmessage()
|
|
|
|
{
|
|
|
|
if (messageframe->isHidden())
|
|
|
|
{
|
|
|
|
messageframe->setVisible(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
messageframe->setVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeerItem::sendMessage()
|
|
|
|
{
|
|
|
|
/* construct a message */
|
|
|
|
MessageInfo mi;
|
|
|
|
|
|
|
|
mi.title = tr("Quick Message").toStdWString();
|
|
|
|
mi.msg = quickmsgText->toHtml().toStdWString();
|
|
|
|
mi.msgto.push_back(mPeerId);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|