2010-08-31 13:13:52 -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.
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
#include "ChatMsgItem.h"
|
|
|
|
#include "FeedHolder.h"
|
|
|
|
#include "../RsAutoUpdatePage.h"
|
|
|
|
#include "gui/msgs/MessageComposer.h"
|
2010-12-30 12:09:32 -05:00
|
|
|
#include "gui/chat/HandleRichText.h"
|
2011-09-02 06:22:44 -04:00
|
|
|
#include "gui/common/AvatarDefs.h"
|
2010-09-04 10:23:30 -04:00
|
|
|
#include "gui/settings/rsharesettings.h"
|
2010-08-31 13:13:52 -04:00
|
|
|
|
2010-08-31 18:42:40 -04:00
|
|
|
#include "gui/notifyqt.h"
|
|
|
|
|
2010-08-31 13:13:52 -04:00
|
|
|
#include <retroshare/rsmsgs.h>
|
|
|
|
#include <retroshare/rspeers.h>
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
/*****
|
|
|
|
* #define DEBUG_ITEM 1
|
|
|
|
****/
|
|
|
|
|
|
|
|
/** Constructor */
|
2012-02-01 07:21:14 -05:00
|
|
|
ChatMsgItem::ChatMsgItem(FeedHolder *parent, uint32_t feedId, const std::string &peerId, const std::string &message)
|
|
|
|
:QWidget(NULL), mParent(parent), mFeedId(feedId), mPeerId(peerId)
|
2010-08-31 13:13:52 -04:00
|
|
|
{
|
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
setupUi(this);
|
2010-09-08 12:27:13 -04:00
|
|
|
|
|
|
|
messageframe->setVisible(false);
|
|
|
|
sendButton->hide();
|
2010-09-08 18:46:26 -04:00
|
|
|
cancelButton->hide();
|
|
|
|
sendButton->setEnabled(false);
|
2010-08-31 13:13:52 -04:00
|
|
|
|
|
|
|
/* general ones */
|
|
|
|
connect( clearButton, SIGNAL( clicked( void ) ), this, SLOT( removeItem ( void ) ) );
|
|
|
|
|
|
|
|
/* specific ones */
|
|
|
|
connect( chatButton, SIGNAL( clicked( void ) ), this, SLOT( openChat ( void ) ) );
|
|
|
|
connect( msgButton, SIGNAL( clicked( void ) ), this, SLOT( sendMsg ( void ) ) );
|
2010-09-08 12:27:13 -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 12:27:13 -04:00
|
|
|
connect( sendButton, SIGNAL( clicked( ) ), this, SLOT( sendMessage() ) );
|
|
|
|
|
2010-08-31 18:42:40 -04:00
|
|
|
connect(NotifyQt::getInstance(), SIGNAL(peerHasNewAvatar(const QString&)), this, SLOT(updateAvatar(const QString&)));
|
|
|
|
|
2011-09-05 17:19:07 -04:00
|
|
|
avatar->setId(mPeerId, false);
|
|
|
|
|
2010-08-31 13:13:52 -04:00
|
|
|
updateItemStatic();
|
|
|
|
updateItem();
|
|
|
|
insertChat(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatMsgItem::updateItemStatic()
|
|
|
|
{
|
|
|
|
if (!rsPeers)
|
|
|
|
return;
|
|
|
|
|
|
|
|
RsPeerDetails details;
|
|
|
|
if (rsPeers->getPeerDetails(mPeerId, details))
|
|
|
|
{
|
|
|
|
|
|
|
|
/* set textcolor for peername */
|
|
|
|
QString nameStr("<span style=\"font-size:14pt; font-weight:500;"
|
|
|
|
"color:#990033;\">%1</span>");
|
|
|
|
|
|
|
|
/* set Peer name */
|
2011-07-17 19:07:29 -04:00
|
|
|
QString peername = QString::fromUtf8(details.name.c_str());
|
2010-08-31 13:13:52 -04:00
|
|
|
peernameLabel->setText(nameStr.arg(peername));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
chatButton->setEnabled(false);
|
|
|
|
msgButton->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fill in */
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "ChatMsgItem::updateItemStatic()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatMsgItem::updateItem()
|
|
|
|
{
|
|
|
|
if (!rsPeers)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* fill in */
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "ChatMsgItem::updateItem()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(!RsAutoUpdatePage::eventsLocked()) {
|
|
|
|
RsPeerDetails details;
|
|
|
|
if (!rsPeers->getPeerDetails(mPeerId, details))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do buttons */
|
|
|
|
chatButton->setEnabled(details.state & RS_PEER_STATE_CONNECTED);
|
|
|
|
if (details.state & RS_PEER_STATE_FRIEND)
|
|
|
|
{
|
|
|
|
msgButton->setEnabled(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msgButton->setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
2010-09-08 12:27:13 -04:00
|
|
|
|
2010-08-31 13:13:52 -04:00
|
|
|
/* slow Tick */
|
|
|
|
int msec_rate = 10129;
|
|
|
|
|
|
|
|
QTimer::singleShot( msec_rate, this, SLOT(updateItem( void ) ));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-01 07:21:14 -05:00
|
|
|
void ChatMsgItem::insertChat(const std::string &message)
|
2010-08-31 13:13:52 -04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "ChatMsgItem::insertChat(): " << msg << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QString timestamp = QDateTime::currentDateTime().toString("hh:mm:ss");
|
2010-08-31 16:55:40 -04:00
|
|
|
timestampLabel->setText(timestamp);
|
2010-08-31 13:13:52 -04:00
|
|
|
|
2010-09-04 10:23:30 -04:00
|
|
|
QString formatMsg = QString::fromStdString(message);
|
|
|
|
|
2010-12-30 12:09:32 -05:00
|
|
|
unsigned int formatFlag = RSHTML_FORMATTEXT_EMBED_LINKS;
|
2010-09-04 10:23:30 -04:00
|
|
|
|
|
|
|
// embed smileys ?
|
|
|
|
if (Settings->valueFromGroup(QString("Chat"), QString::fromUtf8("Emoteicons_GroupChat"), true).toBool()) {
|
2010-12-30 12:09:32 -05:00
|
|
|
formatFlag |= RSHTML_FORMATTEXT_EMBED_SMILEYS;
|
2010-09-04 10:23:30 -04:00
|
|
|
}
|
|
|
|
|
2010-12-30 12:09:32 -05:00
|
|
|
formatMsg = RsHtml::formatText(formatMsg, formatFlag);
|
2010-09-04 10:23:30 -04:00
|
|
|
|
|
|
|
chatTextlabel->setText(formatMsg);
|
2010-08-31 13:13:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatMsgItem::removeItem()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "ChatMsgItem::removeItem()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
hide();
|
|
|
|
if (mParent)
|
|
|
|
{
|
|
|
|
mParent->deleteFeedItem(this, mFeedId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatMsgItem::gotoHome()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "ChatMsgItem::gotoHome()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********** SPECIFIC FUNCTIOSN ***********************/
|
|
|
|
|
|
|
|
|
|
|
|
void ChatMsgItem::sendMsg()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "ChatMsgItem::sendMsg()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (mParent)
|
|
|
|
{
|
|
|
|
|
2010-11-02 17:11:11 -04:00
|
|
|
MessageComposer *nMsgDialog = MessageComposer::newMsg();
|
|
|
|
if (nMsgDialog == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2010-08-31 13:13:52 -04:00
|
|
|
|
2010-09-27 17:05:52 -04:00
|
|
|
nMsgDialog->addRecipient(MessageComposer::TO, mPeerId, false);
|
2010-08-31 13:13:52 -04:00
|
|
|
nMsgDialog->show();
|
|
|
|
nMsgDialog->activateWindow();
|
|
|
|
|
|
|
|
/* window will destroy itself! */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ChatMsgItem::openChat()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "ChatMsgItem::openChat()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
if (mParent)
|
|
|
|
{
|
|
|
|
mParent->openChat(mPeerId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-08 12:27:13 -04:00
|
|
|
void ChatMsgItem::togglequickmessage()
|
|
|
|
{
|
|
|
|
if (messageframe->isHidden())
|
|
|
|
{
|
|
|
|
messageframe->setVisible(true);
|
|
|
|
sendButton->show();
|
2010-09-08 18:46:26 -04:00
|
|
|
cancelButton->show();
|
2010-09-08 12:27:13 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
messageframe->setVisible(false);
|
|
|
|
sendButton->hide();
|
2010-09-08 18:46:26 -04:00
|
|
|
cancelButton->hide();
|
2010-09-08 12:27:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatMsgItem::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);
|
|
|
|
sendButton->hide();
|
2010-09-08 18:46:26 -04:00
|
|
|
cancelButton->hide();
|
2010-09-08 15:04:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatMsgItem::on_quickmsgText_textChanged()
|
|
|
|
{
|
|
|
|
if (quickmsgText->toPlainText().isEmpty())
|
|
|
|
{
|
|
|
|
sendButton->setEnabled(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sendButton->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|