mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-15 12:32:37 -04:00
Changed the chat service from a timer tick from the gui to a service tick.
Created a new notifier for new chat available - NOTIFY_LIST_CHAT. Removed the QTimer in PeersDialog and connect the signal. Created news feed for public chat (prework of defnax, need still some gui changes) git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3413 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
c7c6f6d36a
commit
b6b5fa5cd6
18 changed files with 832 additions and 175 deletions
261
retroshare-gui/src/gui/feeds/ChatMsgItem.cpp
Normal file
261
retroshare-gui/src/gui/feeds/ChatMsgItem.cpp
Normal file
|
@ -0,0 +1,261 @@
|
|||
/****************************************************************
|
||||
* 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"
|
||||
|
||||
#include <retroshare/rsmsgs.h>
|
||||
#include <retroshare/rspeers.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
/*****
|
||||
* #define DEBUG_ITEM 1
|
||||
****/
|
||||
|
||||
/** Constructor */
|
||||
ChatMsgItem::ChatMsgItem(FeedHolder *parent, uint32_t feedId, std::string peerId, std::string message, bool isHome)
|
||||
:QWidget(NULL), mParent(parent), mFeedId(feedId),
|
||||
mPeerId(peerId), 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 ) ) );
|
||||
|
||||
/* specific ones */
|
||||
connect( chatButton, SIGNAL( clicked( void ) ), this, SLOT( openChat ( void ) ) );
|
||||
connect( msgButton, SIGNAL( clicked( void ) ), this, SLOT( sendMsg ( void ) ) );
|
||||
|
||||
small();
|
||||
updateItemStatic();
|
||||
updateItem();
|
||||
insertChat(message);
|
||||
}
|
||||
|
||||
void ChatMsgItem::updateItemStatic()
|
||||
{
|
||||
if (!rsPeers)
|
||||
return;
|
||||
|
||||
RsPeerDetails details;
|
||||
if (rsPeers->getPeerDetails(mPeerId, details))
|
||||
{
|
||||
QString title;
|
||||
titleLabel->setText(title);
|
||||
|
||||
/* set textcolor for peername */
|
||||
QString nameStr("<span style=\"font-size:14pt; font-weight:500;"
|
||||
"color:#990033;\">%1</span>");
|
||||
|
||||
/* set Peer name */
|
||||
QString peername = QString::fromStdString(details.name);
|
||||
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
|
||||
|
||||
if (mIsHome)
|
||||
{
|
||||
/* disable buttons */
|
||||
clearButton->setEnabled(false);
|
||||
//gotoButton->setEnabled(false);
|
||||
|
||||
/* disable buttons */
|
||||
clearButton->hide();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/* slow Tick */
|
||||
int msec_rate = 10129;
|
||||
|
||||
loadAvatar();
|
||||
|
||||
QTimer::singleShot( msec_rate, this, SLOT(updateItem( void ) ));
|
||||
return;
|
||||
}
|
||||
|
||||
void ChatMsgItem::insertChat(std::string &message)
|
||||
{
|
||||
#ifdef DEBUG_ITEM
|
||||
std::cerr << "ChatMsgItem::insertChat(): " << msg << std::endl;
|
||||
#endif
|
||||
|
||||
QString timestamp = QDateTime::currentDateTime().toString("hh:mm:ss");
|
||||
lastLabel->setText(timestamp);
|
||||
|
||||
chatText_label->setText(QString::fromStdString(message));
|
||||
}
|
||||
|
||||
|
||||
void ChatMsgItem::small()
|
||||
{
|
||||
expandFrame->hide();
|
||||
}
|
||||
|
||||
void ChatMsgItem::toggle()
|
||||
{
|
||||
if (expandFrame->isHidden())
|
||||
{
|
||||
expandFrame->show();
|
||||
expandButton->setIcon(QIcon(QString(":/images/edit_remove24.png")));
|
||||
expandButton->setToolTip("Hide");
|
||||
}
|
||||
else
|
||||
{
|
||||
expandFrame->hide();
|
||||
expandButton->setIcon(QIcon(QString(":/images/edit_add24.png")));
|
||||
expandButton->setToolTip("Expand");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
//mParent->openMsg(FEEDHOLDER_MSG_MESSAGE, mPeerId, "");
|
||||
|
||||
MessageComposer *nMsgDialog = new MessageComposer();
|
||||
nMsgDialog->newMsg();
|
||||
|
||||
nMsgDialog->addRecipient( mPeerId ) ;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void ChatMsgItem::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"));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue