fixed up nickname completion in chat lobbies

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8092 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2015-03-28 16:33:33 +00:00
parent 1991d6992d
commit 50caf89655

View File

@ -31,12 +31,12 @@
#include <QTextCodec> #include <QTextCodec>
#include <QTimer> #include <QTimer>
#include <QTextDocumentFragment> #include <QTextDocumentFragment>
#include <QToolTip> #include <QToolTip>
#include <QStringListModel> #include <QStringListModel>
#include "ChatWidget.h" #include "ChatWidget.h"
#include "ui_ChatWidget.h" #include "ui_ChatWidget.h"
#include "gui/MainWindow.h" #include "gui/MainWindow.h"
#include "gui/notifyqt.h" #include "gui/notifyqt.h"
#include "gui/RetroShareLink.h" #include "gui/RetroShareLink.h"
#include "gui/settings/rsharesettings.h" #include "gui/settings/rsharesettings.h"
@ -46,11 +46,11 @@
#include "gui/common/StatusDefs.h" #include "gui/common/StatusDefs.h"
#include "gui/common/FilesDefs.h" #include "gui/common/FilesDefs.h"
#include "gui/common/Emoticons.h" #include "gui/common/Emoticons.h"
#include "gui/chat/ChatLobbyDialog.h" #include "gui/chat/ChatLobbyDialog.h"
#include "util/misc.h" #include "util/misc.h"
#include "util/HandleRichText.h" #include "util/HandleRichText.h"
#include "gui/chat/ChatUserNotify.h"//For BradCast #include "gui/chat/ChatUserNotify.h"//For BradCast
#include "util/DateTime.h" #include "util/DateTime.h"
#include <retroshare/rsstatus.h> #include <retroshare/rsstatus.h>
#include <retroshare/rsidentity.h> #include <retroshare/rsidentity.h>
@ -66,7 +66,7 @@
*****/ *****/
ChatWidget::ChatWidget(QWidget *parent) : ChatWidget::ChatWidget(QWidget *parent) :
QWidget(parent), sendingBlocked(false), ui(new Ui::ChatWidget) QWidget(parent), sendingBlocked(false), ui(new Ui::ChatWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -108,9 +108,9 @@ ChatWidget::ChatWidget(QWidget *parent) :
connect(ui->searchButton, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuSearchButton(QPoint))); connect(ui->searchButton, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuSearchButton(QPoint)));
connect(ui->actionSearch_History, SIGNAL(triggered()), this, SLOT(searchHistory())); connect(ui->actionSearch_History, SIGNAL(triggered()), this, SLOT(searchHistory()));
notify=NULL; notify=NULL;
ui->notifyButton->setVisible(false); ui->notifyButton->setVisible(false);
ui->markButton->setToolTip(tr("<b>Mark this selected text</b><br><i>Ctrl+M</i>")); ui->markButton->setToolTip(tr("<b>Mark this selected text</b><br><i>Ctrl+M</i>"));
connect(ui->sendButton, SIGNAL(clicked()), this, SLOT(sendChat())); connect(ui->sendButton, SIGNAL(clicked()), this, SLOT(sendChat()));
@ -142,8 +142,8 @@ ChatWidget::ChatWidget(QWidget *parent) :
ui->infoFrame->setVisible(false); ui->infoFrame->setVisible(false);
ui->statusMessageLabel->hide(); ui->statusMessageLabel->hide();
ui->actionSearch_History->setChecked(Settings->getChatSearchShowBarByDefault()); ui->actionSearch_History->setChecked(Settings->getChatSearchShowBarByDefault());
searchHistory(); searchHistory();
setAcceptDrops(true); setAcceptDrops(true);
ui->chatTextEdit->setAcceptDrops(false); ui->chatTextEdit->setAcceptDrops(false);
@ -165,10 +165,10 @@ ChatWidget::ChatWidget(QWidget *parent) :
ui->pushtoolsButton->setMenu(menu); ui->pushtoolsButton->setMenu(menu);
ui->textBrowser->installEventFilter(this); ui->textBrowser->installEventFilter(this);
ui->textBrowser->viewport()->installEventFilter(this); ui->textBrowser->viewport()->installEventFilter(this);
ui->chatTextEdit->installEventFilter(this); ui->chatTextEdit->installEventFilter(this);
//ui->textBrowser->setMouseTracking(true); //ui->textBrowser->setMouseTracking(true);
//ui->chatTextEdit->setMouseTracking(true); //ui->chatTextEdit->setMouseTracking(true);
#if QT_VERSION < 0x040700 #if QT_VERSION < 0x040700
// embedded images are not supported before QT 4.7.0 // embedded images are not supported before QT 4.7.0
@ -228,16 +228,16 @@ void ChatWidget::addVOIPBarWidget(QWidget *w)
ui->titleBarFrame->layout()->addWidget(w) ; ui->titleBarFrame->layout()->addWidget(w) ;
} }
RSButtonOnText* ChatWidget::getNewButtonOnTextBrowser() RSButtonOnText* ChatWidget::getNewButtonOnTextBrowser()
{ {
return new RSButtonOnText(ui->textBrowser); return new RSButtonOnText(ui->textBrowser);
} }
RSButtonOnText* ChatWidget::getNewButtonOnTextBrowser(QString text) RSButtonOnText* ChatWidget::getNewButtonOnTextBrowser(QString text)
{ {
return new RSButtonOnText(text, ui->textBrowser); return new RSButtonOnText(text, ui->textBrowser);
} }
void ChatWidget::init(const ChatId &chat_id, const QString &title) void ChatWidget::init(const ChatId &chat_id, const QString &title)
{ {
@ -276,7 +276,7 @@ void ChatWidget::init(const ChatId &chat_id, const QString &title)
} }
uint32_t hist_chat_type = 0xFFFF; // a value larger than the biggest RS_HISTORY_TYPE_* value uint32_t hist_chat_type = 0xFFFF; // a value larger than the biggest RS_HISTORY_TYPE_* value
int messageCount=0; int messageCount=0;
if (chatType() == CHATTYPE_LOBBY) { if (chatType() == CHATTYPE_LOBBY) {
hist_chat_type = RS_HISTORY_TYPE_LOBBY; hist_chat_type = RS_HISTORY_TYPE_LOBBY;
@ -386,8 +386,8 @@ void ChatWidget::processSettings(bool load)
bool ChatWidget::eventFilter(QObject *obj, QEvent *event) bool ChatWidget::eventFilter(QObject *obj, QEvent *event)
{ {
if (obj == ui->textBrowser || obj == ui->textBrowser->viewport() if (obj == ui->textBrowser || obj == ui->textBrowser->viewport()
|| obj == ui->leSearch || obj == ui->chatTextEdit) { || obj == ui->leSearch || obj == ui->chatTextEdit) {
if (event->type() == QEvent::KeyPress) { if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
@ -431,109 +431,109 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event)
} }
} }
if (chatType() == CHATTYPE_LOBBY) { if (chatType() == CHATTYPE_LOBBY) {
if ((event->type() == QEvent::KeyPress) if ((event->type() == QEvent::KeyPress)
|| (event->type() == QEvent::MouseMove) || (event->type() == QEvent::MouseMove)
|| (event->type() == QEvent::Enter) || (event->type() == QEvent::Enter)
|| (event->type() == QEvent::Leave) || (event->type() == QEvent::Leave)
|| (event->type() == QEvent::Wheel) || (event->type() == QEvent::Wheel)
|| (event->type() == QEvent::ToolTip) ) { || (event->type() == QEvent::ToolTip) ) {
QTextCursor cursor = ui->textBrowser->cursorForPosition(QPoint(0, 0)); QTextCursor cursor = ui->textBrowser->cursorForPosition(QPoint(0, 0));
QPoint bottom_right(ui->textBrowser->viewport()->width() - 1, ui->textBrowser->viewport()->height() - 1); QPoint bottom_right(ui->textBrowser->viewport()->width() - 1, ui->textBrowser->viewport()->height() - 1);
int end_pos = ui->textBrowser->cursorForPosition(bottom_right).position(); int end_pos = ui->textBrowser->cursorForPosition(bottom_right).position();
cursor.setPosition(end_pos, QTextCursor::KeepAnchor); cursor.setPosition(end_pos, QTextCursor::KeepAnchor);
if (!cursor.selectedText().isEmpty()){ if (!cursor.selectedText().isEmpty()){
QRegExp rx("<a\\s+name\\s*=\\s*\"(.*)\"",Qt::CaseInsensitive, QRegExp::RegExp2); QRegExp rx("<a\\s+name\\s*=\\s*\"(.*)\"",Qt::CaseInsensitive, QRegExp::RegExp2);
rx.setMinimal(true); rx.setMinimal(true);
QString sel=cursor.selection().toHtml(); QString sel=cursor.selection().toHtml();
QStringList anchors; QStringList anchors;
int pos=0; int pos=0;
while ((pos = rx.indexIn(sel,pos)) != -1) { while ((pos = rx.indexIn(sel,pos)) != -1) {
anchors << rx.cap(1); anchors << rx.cap(1);
pos += rx.matchedLength(); pos += rx.matchedLength();
} }
if (!anchors.isEmpty()){ if (!anchors.isEmpty()){
for (QStringList::iterator it=anchors.begin();it!=anchors.end();++it) { for (QStringList::iterator it=anchors.begin();it!=anchors.end();++it) {
QByteArray bytArray=it->toUtf8(); QByteArray bytArray=it->toUtf8();
std::string stdString=std::string(bytArray.begin(),bytArray.end()); std::string stdString=std::string(bytArray.begin(),bytArray.end());
if (notify) notify->chatLobbyCleared(chatId.toLobbyId() if (notify) notify->chatLobbyCleared(chatId.toLobbyId()
,QString::fromUtf8(stdString.c_str()) ,QString::fromUtf8(stdString.c_str())
,obj != ui->textBrowser && obj != ui->textBrowser->viewport());//, true); ,obj != ui->textBrowser && obj != ui->textBrowser->viewport());//, true);
} }
} }
} }
} }
} }
} }
if (obj == ui->textBrowser) { if (obj == ui->textBrowser) {
if (event->type() == QEvent::KeyPress) { if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
if (keyEvent) { if (keyEvent) {
if (keyEvent->key() == Qt::Key_Delete ) { if (keyEvent->key() == Qt::Key_Delete ) {
// Delete key pressed // Delete key pressed
if (ui->textBrowser->textCursor().selectedText().length() > 0) { if (ui->textBrowser->textCursor().selectedText().length() > 0) {
if (chatType() == CHATTYPE_LOBBY) { if (chatType() == CHATTYPE_LOBBY) {
QRegExp rx("<a\\s+name\\s*=\\s*\"(.*)\"",Qt::CaseInsensitive, QRegExp::RegExp2); QRegExp rx("<a\\s+name\\s*=\\s*\"(.*)\"",Qt::CaseInsensitive, QRegExp::RegExp2);
rx.setMinimal(true); rx.setMinimal(true);
QString sel=ui->textBrowser->textCursor().selection().toHtml(); QString sel=ui->textBrowser->textCursor().selection().toHtml();
QStringList anchors; QStringList anchors;
int pos=0; int pos=0;
while ((pos = rx.indexIn(sel,pos)) != -1) { while ((pos = rx.indexIn(sel,pos)) != -1) {
anchors << rx.cap(1); anchors << rx.cap(1);
pos += rx.matchedLength(); pos += rx.matchedLength();
} }
for (QStringList::iterator it=anchors.begin();it!=anchors.end();++it) { for (QStringList::iterator it=anchors.begin();it!=anchors.end();++it) {
QByteArray bytArray=it->toUtf8(); QByteArray bytArray=it->toUtf8();
std::string stdString=std::string(bytArray.begin(),bytArray.end()); std::string stdString=std::string(bytArray.begin(),bytArray.end());
if (notify) notify->chatLobbyCleared(chatId.toLobbyId(), QString::fromUtf8(stdString.c_str())); if (notify) notify->chatLobbyCleared(chatId.toLobbyId(), QString::fromUtf8(stdString.c_str()));
} }
} }
ui->textBrowser->textCursor().deleteChar(); ui->textBrowser->textCursor().deleteChar();
} }
} }
if (keyEvent->key() == Qt::Key_M && keyEvent->modifiers() == Qt::ControlModifier) if (keyEvent->key() == Qt::Key_M && keyEvent->modifiers() == Qt::ControlModifier)
{ {
on_markButton_clicked(!ui->markButton->isChecked()); on_markButton_clicked(!ui->markButton->isChecked());
} }
} }
} }
if (event->type() == QEvent::ToolTip) { if (event->type() == QEvent::ToolTip) {
QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event); QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event);
QTextCursor cursor = ui->textBrowser->cursorForPosition(helpEvent->pos()); QTextCursor cursor = ui->textBrowser->cursorForPosition(helpEvent->pos());
cursor.select(QTextCursor::WordUnderCursor); cursor.select(QTextCursor::WordUnderCursor);
QString toolTipText = ""; QString toolTipText = "";
if (!cursor.selectedText().isEmpty()){ if (!cursor.selectedText().isEmpty()){
QRegExp rx("<a\\s+name\\s*=\\s*\"(.*)\"",Qt::CaseInsensitive, QRegExp::RegExp2); QRegExp rx("<a\\s+name\\s*=\\s*\"(.*)\"",Qt::CaseInsensitive, QRegExp::RegExp2);
rx.setMinimal(true); rx.setMinimal(true);
QString sel=cursor.selection().toHtml(); QString sel=cursor.selection().toHtml();
QStringList anchors; QStringList anchors;
int pos=0; int pos=0;
while ((pos = rx.indexIn(sel,pos)) != -1) { while ((pos = rx.indexIn(sel,pos)) != -1) {
anchors << rx.cap(1); anchors << rx.cap(1);
pos += rx.matchedLength(); pos += rx.matchedLength();
} }
if (!anchors.isEmpty()){ if (!anchors.isEmpty()){
toolTipText = anchors.at(0); toolTipText = anchors.at(0);
} }
} }
if (!toolTipText.isEmpty()){ if (!toolTipText.isEmpty()){
QToolTip::showText(helpEvent->globalPos(), toolTipText); QToolTip::showText(helpEvent->globalPos(), toolTipText);
return true; return true;
} else { } else {
QToolTip::hideText(); QToolTip::hideText();
} }
} }
} else if (obj == ui->chatTextEdit) { } else if (obj == ui->chatTextEdit) {
if (event->type() == QEvent::KeyPress) { if (event->type() == QEvent::KeyPress) {
@ -667,8 +667,12 @@ void ChatWidget::completeNickname(bool reverse)
if (word.length() > 0) { if (word.length() > 0) {
// Sort participants list // Sort participants list
std::list<QString> participants; std::list<QString> participants;
for ( std::map<RsGxsId,time_t>::const_iterator it = lobby.gxs_ids.begin(); it != lobby.gxs_ids.end(); ++it) { RsIdentityDetails details ;
participants.push_front(QString::fromUtf8(it->first.toStdString().c_str()));
for ( std::map<RsGxsId,time_t>::const_iterator it = lobby.gxs_ids.begin(); it != lobby.gxs_ids.end(); ++it)
{
if(rsIdentity->getIdDetails(it->first,details))
participants.push_front(QString::fromUtf8(details.mNickname.c_str()));
} }
participants.sort(caseInsensitiveCompare); participants.sort(caseInsensitiveCompare);
@ -788,35 +792,35 @@ void ChatWidget::focusDialog()
ui->chatTextEdit->setFocus(); ui->chatTextEdit->setFocus();
} }
QToolButton* ChatWidget::getNotifyButton() QToolButton* ChatWidget::getNotifyButton()
{ {
if (ui) if (ui->notifyButton) return ui->notifyButton; if (ui) if (ui->notifyButton) return ui->notifyButton;
return NULL; return NULL;
} }
void ChatWidget::setNotify(ChatLobbyUserNotify *clun) void ChatWidget::setNotify(ChatLobbyUserNotify *clun)
{ {
if(clun) notify=clun; if(clun) notify=clun;
} }
void ChatWidget::on_notifyButton_clicked() void ChatWidget::on_notifyButton_clicked()
{ {
if(!notify) return; if(!notify) return;
if (chatType() != CHATTYPE_LOBBY) return; if (chatType() != CHATTYPE_LOBBY) return;
QMenu* menu = new QMenu(MainWindow::getInstance()); QMenu* menu = new QMenu(MainWindow::getInstance());
QIcon icoLobby=(ui->notifyButton->icon()); QIcon icoLobby=(ui->notifyButton->icon());
notify->makeSubMenu(menu, icoLobby, title, chatId.toLobbyId()); notify->makeSubMenu(menu, icoLobby, title, chatId.toLobbyId());
menu->exec(ui->notifyButton->mapToGlobal(ui->notifyButton->geometry().bottomLeft())); menu->exec(ui->notifyButton->mapToGlobal(ui->notifyButton->geometry().bottomLeft()));
} }
void ChatWidget::scrollToAnchor(QString anchor) void ChatWidget::scrollToAnchor(QString anchor)
{ {
ui->textBrowser->scrollToAnchor(anchor); ui->textBrowser->scrollToAnchor(anchor);
} }
void ChatWidget::setWelcomeMessage(QString &text) void ChatWidget::setWelcomeMessage(QString &text)
{ {
ui->textBrowser->setText(text); ui->textBrowser->setText(text);
@ -878,12 +882,12 @@ void ChatWidget::addChatMsg(bool incoming, const QString &name, const QDateTime
} }
QString formattedMessage = RsHtml().formatText(ui->textBrowser->document(), message, formatTextFlag, backgroundColor, desiredContrast); QString formattedMessage = RsHtml().formatText(ui->textBrowser->document(), message, formatTextFlag, backgroundColor, desiredContrast);
QDateTime dtTimestamp=incoming ? sendTime : recvTime; QDateTime dtTimestamp=incoming ? sendTime : recvTime;
QString formatMsg = chatStyle.formatMessage(type, name, dtTimestamp, formattedMessage, formatFlag); QString formatMsg = chatStyle.formatMessage(type, name, dtTimestamp, formattedMessage, formatFlag);
QString timeStamp = dtTimestamp.toString(Qt::ISODate); QString timeStamp = dtTimestamp.toString(Qt::ISODate);
formatMsg.prepend(QString("<a name=\"%1_%2\"/>").arg(timeStamp).arg(name)); formatMsg.prepend(QString("<a name=\"%1_%2\"/>").arg(timeStamp).arg(name));
//To call this anchor do: ui->textBrowser->scrollToAnchor(QString("%1_%2").arg(timeStamp).arg(name)); //To call this anchor do: ui->textBrowser->scrollToAnchor(QString("%1_%2").arg(timeStamp).arg(name));
ui->textBrowser->textCursor().setBlockFormat(QTextBlockFormat ()); ui->textBrowser->textCursor().setBlockFormat(QTextBlockFormat ());
ui->textBrowser->append(formatMsg); ui->textBrowser->append(formatMsg);
@ -1204,13 +1208,13 @@ bool ChatWidget::findText(const QString& qsStringToFind, bool bBackWard, bool bF
qtcCurrent=qtcHighLight; qtcCurrent=qtcHighLight;
if (bMoveToCursor || bForceMove) ui->textBrowser->setTextCursor(qtcHighLight); if (bMoveToCursor || bForceMove) ui->textBrowser->setTextCursor(qtcHighLight);
} }
if (uiFoundCount<UINT_MAX) if (uiFoundCount<UINT_MAX)
uiFoundCount+=1; uiFoundCount+=1;
} }
} }
if (bFound) if (bFound)
{ {
@ -1348,9 +1352,9 @@ void ChatWidget::clearChatHistory()
ui->textBrowser->clear(); ui->textBrowser->clear();
on_searchButton_clicked(false); on_searchButton_clicked(false);
ui->markButton->setChecked(false); ui->markButton->setChecked(false);
if (chatType() == CHATTYPE_LOBBY) { if (chatType() == CHATTYPE_LOBBY) {
if (notify) notify->chatLobbyCleared(chatId.toLobbyId(),""); if (notify) notify->chatLobbyCleared(chatId.toLobbyId(),"");
} }
} }
void ChatWidget::deleteChatHistory() void ChatWidget::deleteChatHistory()
@ -1567,7 +1571,7 @@ void ChatWidget::updateTitle()
ui->titleLabel->setText(RsHtml::plainText(name) + "@" + RsHtml::plainText(title)); ui->titleLabel->setText(RsHtml::plainText(name) + "@" + RsHtml::plainText(title));
} }
void ChatWidget::updatePeersCustomStateString(const QString& /*peer_id*/, const QString& /*status_string*/) void ChatWidget::updatePeersCustomStateString(const QString& /*peer_id*/, const QString& /*status_string*/)
{ {
QString status_text; QString status_text;