2007-11-14 22:18:48 -05:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006, crypton
|
|
|
|
*
|
|
|
|
* 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 <QtGui>
|
|
|
|
|
|
|
|
#include "rshare.h"
|
|
|
|
#include "ChatDialog.h"
|
|
|
|
|
|
|
|
#include "rsiface/rsiface.h"
|
2008-01-25 03:49:40 -05:00
|
|
|
#include "rsiface/rspeers.h"
|
2008-02-04 12:55:59 -05:00
|
|
|
#include "rsiface/rsmsgs.h"
|
2008-01-25 03:49:40 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
#include "chat/PopupChatDialog.h"
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include <QTextCodec>
|
|
|
|
#include <QTextEdit>
|
|
|
|
#include <QToolBar>
|
|
|
|
#include <QTextCursor>
|
|
|
|
#include <QTextList>
|
|
|
|
|
|
|
|
#include <QContextMenuEvent>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QCursor>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QHeaderView>
|
|
|
|
|
|
|
|
/** Constructor */
|
|
|
|
ChatDialog::ChatDialog(QWidget *parent)
|
|
|
|
: MainPage(parent)
|
|
|
|
{
|
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
|
|
|
connect(ui.lineEdit, SIGNAL(returnPressed( ) ), this, SLOT(sendMsg( ) ));
|
|
|
|
|
2007-11-27 19:45:16 -05:00
|
|
|
connect(ui.colorChatButton, SIGNAL(clicked()), this, SLOT(setColor()));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
connect( ui.msgSendList, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( msgSendListCostumPopupMenu( QPoint ) ) );
|
2008-03-23 08:58:28 -04:00
|
|
|
|
|
|
|
connect(ui.textboldChatButton, SIGNAL(clicked()), this, SLOT(insertBold()));
|
|
|
|
connect(ui.textunderlineChatButton, SIGNAL(clicked()), this, SLOT(insertUnderline()));
|
|
|
|
connect(ui.textitalicChatButton, SIGNAL(clicked()), this, SLOT(insertItalic()));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
// connect(ui.msgSendList, SIGNAL(itemChanged( QTreeWidgetItem *, int ) ),
|
|
|
|
// this, SLOT(toggleSendItem( QTreeWidgetItem *, int ) ));
|
|
|
|
|
|
|
|
loadInitMsg();
|
|
|
|
|
|
|
|
/* hide the Tree +/- */
|
|
|
|
ui.msgSendList -> setRootIsDecorated( false );
|
|
|
|
|
|
|
|
/* to hide the header */
|
|
|
|
ui.msgSendList->header()->hide();
|
2007-11-27 19:45:16 -05:00
|
|
|
|
|
|
|
textColor = Qt::black;
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* Hide platform specific features */
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatDialog::msgSendListCostumPopupMenu( QPoint point )
|
|
|
|
{
|
|
|
|
|
|
|
|
QMenu contextMnu( this );
|
|
|
|
QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier );
|
|
|
|
|
|
|
|
privchatAct = new QAction(QIcon(), tr( "Chat" ), this );
|
|
|
|
connect( privchatAct , SIGNAL( triggered() ), this, SLOT( privchat() ) );
|
|
|
|
|
|
|
|
contextMnu.clear();
|
|
|
|
contextMnu.addAction( privchatAct);
|
|
|
|
contextMnu.exec( mevent->globalPos() );
|
|
|
|
}
|
2008-01-26 08:08:28 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
int ChatDialog::loadInitMsg()
|
|
|
|
{
|
|
|
|
std::ostringstream out;
|
|
|
|
|
|
|
|
//out << std::endl;
|
|
|
|
//out << std::endl;
|
|
|
|
//out << std::endl;
|
|
|
|
out << " Welcome to:";
|
|
|
|
out << "<br>" << std::endl;
|
|
|
|
out << " Retroshare's group chat. <br>";
|
|
|
|
|
|
|
|
QString txt = QString::fromStdString(out.str());
|
|
|
|
ui.msgText->setHtml(txt);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ChatDialog::insertChat()
|
|
|
|
{
|
2008-02-04 12:55:59 -05:00
|
|
|
std::list<ChatInfo> newchat;
|
|
|
|
if (!rsMsgs->getNewChat(newchat))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-03-21 10:56:41 -04:00
|
|
|
QTextEdit *msgWidget = ui.msgText;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::list<ChatInfo>::iterator it;
|
2008-03-21 10:56:41 -04:00
|
|
|
|
2007-11-27 19:45:16 -05:00
|
|
|
//QString color = ci.messageColor.name();
|
|
|
|
//QString nickColor;
|
|
|
|
//QString font = ci.messageFont.family();
|
|
|
|
//QString fontSize = QString::number(ci.messageFont.pointSize());
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* add in lines at the bottom */
|
|
|
|
for(it = newchat.begin(); it != newchat.end(); it++)
|
|
|
|
{
|
|
|
|
/* are they private? */
|
|
|
|
if (it->chatflags & RS_CHAT_PRIVATE)
|
|
|
|
{
|
|
|
|
PopupChatDialog *pcd = getPrivateChat(it->rsid, it->name, true);
|
|
|
|
pcd->addChatMsg(&(*it));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostringstream out;
|
|
|
|
QString currenttxt = msgWidget->toHtml();
|
2008-01-26 08:08:28 -05:00
|
|
|
QString extraTxt;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-03-21 10:56:41 -04:00
|
|
|
QString timestamp = "[" + QDateTime::currentDateTime().toString("hh:mm:ss") + "]";
|
|
|
|
QString name = QString::fromStdString(it->name);
|
|
|
|
QString line = "<span style=\"color:#C00000\"><strong>" + timestamp + "</strong></span>" +
|
2008-02-26 11:14:13 -05:00
|
|
|
"<span style=\"color:#2D84C9\"><strong>" + " " + name + "</strong></span> <br>";
|
2008-03-21 10:56:41 -04:00
|
|
|
|
|
|
|
extraTxt += line;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-03-21 10:56:41 -04:00
|
|
|
extraTxt += QString::fromStdWString(it->msg);
|
|
|
|
|
|
|
|
/* add it everytime */
|
2008-01-26 08:08:28 -05:00
|
|
|
currenttxt += extraTxt;
|
2008-03-21 10:56:41 -04:00
|
|
|
|
|
|
|
msgWidget->setHtml(currenttxt);
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
QScrollBar *qsb = msgWidget->verticalScrollBar();
|
|
|
|
qsb -> setValue(qsb->maximum());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ChatDialog::sendMsg()
|
|
|
|
{
|
2007-11-27 19:45:16 -05:00
|
|
|
QLineEdit *lineWidget = ui.lineEdit;
|
|
|
|
|
2008-03-21 10:56:41 -04:00
|
|
|
QFont font = QFont("Comic Sans MS", 10);
|
|
|
|
font.setBold(ui.textboldChatButton->isChecked());
|
|
|
|
font.setUnderline(ui.textunderlineChatButton->isChecked());
|
|
|
|
font.setItalic(ui.textitalicChatButton->isChecked());
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
ChatInfo ci;
|
2008-01-26 08:08:28 -05:00
|
|
|
ci.msg = lineWidget->text().toStdWString();
|
2007-11-14 22:18:48 -05:00
|
|
|
ci.chatflags = RS_CHAT_PUBLIC;
|
2007-11-27 19:45:16 -05:00
|
|
|
//ci.messageFont = font;
|
|
|
|
//ci.messageColor = textColor;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-02-04 12:55:59 -05:00
|
|
|
rsMsgs -> ChatSend(ci);
|
2007-11-14 22:18:48 -05:00
|
|
|
lineWidget -> setText(QString(""));
|
|
|
|
|
|
|
|
/* redraw send list */
|
|
|
|
insertSendList();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatDialog::insertSendList()
|
|
|
|
{
|
2008-01-25 03:49:40 -05:00
|
|
|
std::list<std::string> peers;
|
|
|
|
std::list<std::string>::iterator it;
|
|
|
|
|
|
|
|
if (!rsPeers)
|
|
|
|
{
|
|
|
|
/* not ready yet! */
|
|
|
|
return;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-01-25 03:49:40 -05:00
|
|
|
rsPeers->getOnlineList(peers);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* get a link to the table */
|
|
|
|
QTreeWidget *sendWidget = ui.msgSendList;
|
2008-01-25 03:49:40 -05:00
|
|
|
QList<QTreeWidgetItem *> items;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-01-25 03:49:40 -05:00
|
|
|
for(it = peers.begin(); it != peers.end(); it++)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2008-01-25 03:49:40 -05:00
|
|
|
|
|
|
|
RsPeerDetails details;
|
|
|
|
if (!rsPeers->getPeerDetails(*it, details))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2008-01-25 03:49:40 -05:00
|
|
|
continue; /* BAD */
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* make a widget per friend */
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0);
|
|
|
|
|
|
|
|
/* add all the labels */
|
|
|
|
/* (0) Person */
|
2008-01-25 03:49:40 -05:00
|
|
|
item -> setText(0, QString::fromStdString(details.name));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-01-26 08:08:28 -05:00
|
|
|
item -> setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
|
|
|
|
//item -> setFlags(Qt::ItemIsUserCheckable);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
item -> setCheckState(0, Qt::Checked);
|
2008-02-04 12:55:59 -05:00
|
|
|
|
|
|
|
if (rsicontrol->IsInChat(*it))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
item -> setCheckState(0, Qt::Checked);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item -> setCheckState(0, Qt::Unchecked);
|
|
|
|
}
|
2008-02-04 12:55:59 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* add to the list */
|
|
|
|
items.append(item);
|
|
|
|
}
|
|
|
|
|
2008-01-25 03:49:40 -05:00
|
|
|
/* remove old items */
|
|
|
|
sendWidget->clear();
|
|
|
|
sendWidget->setColumnCount(1);
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* add the items in! */
|
|
|
|
sendWidget->insertTopLevelItems(0, items);
|
|
|
|
|
|
|
|
sendWidget->update(); /* update display */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* to toggle the state */
|
|
|
|
|
|
|
|
|
|
|
|
void ChatDialog::toggleSendItem( QTreeWidgetItem *item, int col )
|
|
|
|
{
|
|
|
|
std::cerr << "ToggleSendItem()" << std::endl;
|
|
|
|
|
|
|
|
/* extract id */
|
|
|
|
std::string id = (item -> text(4)).toStdString();
|
|
|
|
|
|
|
|
/* get state */
|
|
|
|
bool inChat = (Qt::Checked == item -> checkState(0)); /* alway column 0 */
|
|
|
|
|
|
|
|
/* call control fns */
|
|
|
|
|
|
|
|
rsicontrol -> SetInChat(id, inChat);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatDialog::setColor()
|
|
|
|
{
|
2007-11-27 19:45:16 -05:00
|
|
|
textColor = QColorDialog::getColor(Qt::black, this);
|
|
|
|
QPixmap pxm(24,24);
|
|
|
|
pxm.fill(textColor);
|
|
|
|
ui.colorChatButton->setIcon(pxm);
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ChatDialog::privchat()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PopupChatDialog *ChatDialog::getPrivateChat(std::string id, std::string name, bool show)
|
|
|
|
{
|
|
|
|
/* see if it exists already */
|
|
|
|
PopupChatDialog *popupchatdialog = NULL;
|
|
|
|
|
|
|
|
std::map<std::string, PopupChatDialog *>::iterator it;
|
|
|
|
if (chatDialogs.end() != (it = chatDialogs.find(id)))
|
|
|
|
{
|
|
|
|
/* exists already */
|
|
|
|
popupchatdialog = it->second;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
popupchatdialog = new PopupChatDialog(id, name);
|
|
|
|
chatDialogs[id] = popupchatdialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (show)
|
|
|
|
{
|
|
|
|
popupchatdialog->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
return popupchatdialog;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatDialog::clearOldChats()
|
|
|
|
{
|
|
|
|
/* nothing yet */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-03-23 08:58:28 -04:00
|
|
|
void ChatDialog::insertBold()
|
|
|
|
{
|
|
|
|
|
|
|
|
this->insertAutour(tr("<b>"), tr("</b>"));
|
|
|
|
this->ui.lineEdit->setFocus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatDialog::insertItalic()
|
|
|
|
{
|
|
|
|
|
|
|
|
this->insertAutour(tr("<i>"), tr("</i>"));
|
|
|
|
this->ui.lineEdit->setFocus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatDialog::insertUnderline()
|
|
|
|
{
|
|
|
|
|
|
|
|
this->insertAutour(tr("<u>"), tr("</u>"));
|
|
|
|
this->ui.lineEdit->setFocus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatDialog::insertStrike()
|
|
|
|
{
|
|
|
|
|
|
|
|
this->insertAutour(tr("<s>"), tr("</s>"));
|
|
|
|
this->ui.lineEdit->setFocus();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-03-23 08:58:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatDialog::insertAutour(QString leftTruc,QString rightTruc)
|
|
|
|
{
|
|
|
|
int p0 = ui.lineEdit->cursorPosition();
|
|
|
|
QString stringToInsert = leftTruc ;
|
|
|
|
stringToInsert.append(rightTruc);
|
|
|
|
ui.lineEdit->insert(stringToInsert);
|
|
|
|
ui.lineEdit->setCursorPosition(p0 + leftTruc.size());
|
|
|
|
|
|
|
|
}
|