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"
|
2012-02-19 10:03:07 -05:00
|
|
|
#include "retroshare-gui/RsAutoUpdatePage.h"
|
2010-08-31 13:13:52 -04:00
|
|
|
#include "gui/msgs/MessageComposer.h"
|
2012-05-11 20:40:53 -04:00
|
|
|
#include "util/HandleRichText.h"
|
2012-11-15 16:35:37 -05:00
|
|
|
#include "util/DateTime.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>
|
|
|
|
|
|
|
|
/*****
|
|
|
|
* #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
|
|
|
|
2012-09-07 13:30:23 -04:00
|
|
|
messageFrame->setVisible(false);
|
2010-09-08 12:27:13 -04:00
|
|
|
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 Peer name */
|
2012-09-07 13:30:23 -04:00
|
|
|
peerNameLabel->setText(QString::fromUtf8(details.name.c_str()));
|
2010-08-31 13:13:52 -04:00
|
|
|
}
|
|
|
|
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
|
|
|
|
|
2012-11-15 16:35:37 -05:00
|
|
|
timestampLabel->setText(DateTime::formatLongDateTime(QDateTime::currentDateTime()));
|
2010-08-31 13:13:52 -04:00
|
|
|
|
2012-03-30 19:02:52 -04:00
|
|
|
QString formatMsg = QString::fromUtf8(message.c_str());
|
2010-09-04 10:23:30 -04:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-05-11 20:40:53 -04:00
|
|
|
formatMsg = RsHtml().formatText(NULL, 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
|
2012-10-08 19:06:34 -04:00
|
|
|
|
|
|
|
mParent->lockLayout(this, true);
|
2010-08-31 13:13:52 -04:00
|
|
|
hide();
|
2012-10-08 19:06:34 -04:00
|
|
|
mParent->lockLayout(this, false);
|
|
|
|
|
2010-08-31 13:13:52 -04:00
|
|
|
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()
|
|
|
|
{
|
2012-10-08 19:06:34 -04:00
|
|
|
mParent->lockLayout(this, true);
|
|
|
|
|
2012-09-07 13:30:23 -04:00
|
|
|
if (messageFrame->isHidden())
|
2010-09-08 12:27:13 -04:00
|
|
|
{
|
2012-09-07 13:30:23 -04:00
|
|
|
messageFrame->setVisible(true);
|
2010-09-08 12:27:13 -04:00
|
|
|
sendButton->show();
|
2010-09-08 18:46:26 -04:00
|
|
|
cancelButton->show();
|
2010-09-08 12:27:13 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-07 13:30:23 -04:00
|
|
|
messageFrame->setVisible(false);
|
2010-09-08 12:27:13 -04:00
|
|
|
sendButton->hide();
|
2010-09-08 18:46:26 -04:00
|
|
|
cancelButton->hide();
|
2010-09-08 12:27:13 -04:00
|
|
|
}
|
|
|
|
|
2012-10-08 19:06:34 -04:00
|
|
|
mParent->lockLayout(this, false);
|
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();
|
2012-09-07 13:30:23 -04:00
|
|
|
messageFrame->setVisible(false);
|
2010-09-08 12:27:13 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|